package com.luticate.utils.ui.fragments;

import android.view.View;
import android.widget.LinearLayout;

import com.luticate.utils.R;
import com.luticate.utils.dbo.LuDbo;

import java.util.List;
import java.util.Vector;

/**
 * Created by robin on 12/6/15.
 */
public abstract class ViewPaginationFragment<Dbo extends LuDbo, DboView extends View> extends AbstractPaginationFragment<Dbo> {

    protected List<DboView> _views = new Vector<>();

    @Override
    protected int getLoaderViewId() {
        return R.id.loadStatus;
    }

    @Override
    protected int getScrollViewId() {
        return R.id.mainScrollView;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.view_pagination_fragment_layout;
    }

    @Override
    protected int getPaginationViewId() {
        return R.id.paginationView;
    }

    @Override
    protected void onPageChanged() {
        View view = getView();
        LinearLayout layout = (LinearLayout) view.findViewById(R.id.itemsLayoutScrollView);
        layout.removeAllViews();
        _views.clear();
        for (Dbo item : _items.getData())
        {
            DboView v = getDboView(item);
            layout.addView(v);
            _views.add(v);
        }
    }

    protected abstract DboView getDboView(Dbo dbo);
}
