package com.example.wechat01.widght.swipe.adapters;

import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.example.wechat01.widght.swipe.SwipeLayout;
import com.example.wechat01.widght.swipe.implments.SwipeItemMangerImpl;
import com.example.wechat01.widght.swipe.interfaces.SwipeAdapterInterface;
import com.example.wechat01.widght.swipe.interfaces.SwipeItemMangerInterface;

public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter
		implements SwipeItemMangerInterface, SwipeAdapterInterface {

	private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);

	protected SimpleCursorSwipeAdapter(Context context, int layout, Cursor c,
			String[] from, int[] to, int flags) {
		super(context, layout, c, from, to, flags);
	}

	protected SimpleCursorSwipeAdapter(Context context, int layout, Cursor c,
			String[] from, int[] to) {
		super(context, layout, c, from, to);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		boolean convertViewIsNull = convertView == null;
		View v = super.getView(position, convertView, parent);
		if (convertViewIsNull) {
			mItemManger.initialize(v, position);
		} else {
			mItemManger.updateConvertView(v, position);
		}
		return v;
	}

	@Override
	public void openItem(int position) {
		mItemManger.openItem(position);
	}

	@Override
	public void closeItem(int position) {
		mItemManger.closeItem(position);
	}

	@Override
	public void closeAllExcept(SwipeLayout layout) {
		mItemManger.closeAllExcept(layout);
	}

	@Override
	public List<Integer> getOpenItems() {
		return mItemManger.getOpenItems();
	}

	@Override
	public List<SwipeLayout> getOpenLayouts() {
		return mItemManger.getOpenLayouts();
	}

	@Override
	public void removeShownLayouts(SwipeLayout layout) {
		mItemManger.removeShownLayouts(layout);
	}

	@Override
	public boolean isOpen(int position) {
		return mItemManger.isOpen(position);
	}

	@Override
	public SwipeItemMangerImpl.Mode getMode() {
		return mItemManger.getMode();
	}

	@Override
	public void setMode(SwipeItemMangerImpl.Mode mode) {
		mItemManger.setMode(mode);
	}
}