tomazsaraiva
7/31/2018 - 3:02 PM

Collections

public interface IListItem
{
    int Id
    {
        get;
    }

    void Select(bool select);
}
public class BaseListSelection
{
    // properties

#if __IOS__

public NSIndexPath IndexPath
{
	get;
	private set;
}

#elif __ANDROID__

public int Index
{
	get;
	private set;
}

#endif

    public IListItem Item
    {
        get;
        private set;
    }


    // ctor

#if __IOS__

    public BaseListSelection(NSIndexPath indexPath, IListItem item)
{
	IndexPath = indexPath;
	Item = item;
}

#elif __ANDROID__

    public BaseListSelection(int index, IListItem item)
{
	Index = index;
	Item = item;
}

#endif
}
public class BaseList : IDisposable
{
    // events

    public event EventHandler<BaseListSelection> OnItemSelected;


    // properties

    public int Length
    {
        get
        {
            return _items == null ? 0 : _items.Count;
        }
    }


    // fields

    protected List<IListItem> _items;

    protected int _selectedItem = -1;



    // IDisposable

    public void Dispose()
    {
        _items = null;

        _selectedItem = -1;

        OnItemSelected = null;
    }


    // BaseListSC

    public void SetItems(List<IListItem> items)
    {
        _items = items;
    }

    public virtual void SelectItem(int item)
    {
        _selectedItem = item;
    }


    protected bool HasItem(int index)
    {
        return _items != null && index >= 0 && index < _items.Count;
    }

    protected T GetItem<T>(int index)
    {
        if (!HasItem(index))
        {
            return default(T);
        }

        return (T)_items[index];
    }

    protected void ItemSelected(BaseListSelection selection)
    {
        if (OnItemSelected != null)
        {
            OnItemSelected.Invoke(this, selection);
        }
    }
}
public class BaseListCell
{
    public BaseListCell()
    {
    }
}