Search in sources :

Example 1 with ImageCard

use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.

the class AutoLoadMoreActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_auto_load_more);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new AutoLoadAdapter(this);
    recyclerView.setAdapter(mAdapter);
    final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
    mAdapter.setAlwaysShowHead(true);
    mAdapter.setAlwaysShowFoot(true);
    mAdapter.addHeadLayout(R.layout.item_head);
    mAdapter.addFootLayout(R.layout.item_foot2);
    // 模拟数据
    data = new ArrayList<>();
    for (int i = 0; i < mTitles.length; i++) {
        ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
        data.add(card);
    }
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            // 模拟刷新
            recyclerView.postDelayed(new Runnable() {

                @Override
                public void run() {
                    refreshLayout.setRefreshing(false);
                    mAdapter.setData(data);
                }
            }, 500);
        }
    });
    // 必须设置事件监听与开启auto
    mAdapter.openAutoLoadMore(true);
    mAdapter.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            Log.d("Sherlock", "加载更多");
            // 模拟加载更多
            recyclerView.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (mState == LOAD_ADD) {
                        mAdapter.addData(data);
                    } else if (mState == LOAD_COMPLETED) {
                        mAdapter.loadCompleted();
                    } else if (mState == LOAD_FAILED) {
                        mAdapter.loadFailed();
                    }
                }
            }, 800);
        }
    });
    findViewById(R.id.action_add).setOnClickListener(this);
    findViewById(R.id.action_failed).setOnClickListener(this);
    findViewById(R.id.action_completed).setOnClickListener(this);
    findViewById(R.id.action_empty).setOnClickListener(this);
    findViewById(R.id.action_close).setOnClickListener(this);
    mShowHead = (CheckBox) findViewById(R.id.cb_show_head);
    mShowFoot = (CheckBox) findViewById(R.id.cb_show_foot);
    mShowHead.setChecked(true);
    mShowFoot.setChecked(true);
    mShowHead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mAdapter.setAlwaysShowHead(isChecked);
        }
    });
    mShowFoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mAdapter.setAlwaysShowFoot(isChecked);
        }
    });
}
Also used : OnLoadMoreListener(xyz.zpayh.adapter.OnLoadMoreListener) AutoLoadAdapter(xyz.zpayh.myadapter.adapter.AutoLoadAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ImageCard(xyz.zpayh.myadapter.data.ImageCard) RecyclerView(android.support.v7.widget.RecyclerView) CompoundButton(android.widget.CompoundButton)

Example 2 with ImageCard

use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.

the class HeadAndFootActivity method refresh.

private void refresh() {
    if (mChangeOrder) {
        List<ImageCard> data = new ArrayList<>();
        for (int i = mTitles.length - 1; i >= 0; i--) {
            ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
            data.add(card);
        }
        mAdapter.setData(data);
    } else {
        List<ImageCard> data = new ArrayList<>();
        for (int i = 0; i < mTitles.length; i++) {
            ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
            data.add(card);
        }
        mAdapter.setData(data);
    }
    mChangeOrder = !mChangeOrder;
}
Also used : ArrayList(java.util.ArrayList) ImageCard(xyz.zpayh.myadapter.data.ImageCard)

Example 3 with ImageCard

use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.

the class ExpandableActivity method initData.

private void initData() {
    int width = getResources().getDisplayMetrics().widthPixels / mStaggeredGridLayoutManager.getSpanCount();
    List<IMultiItem> data = new ArrayList<>();
    for (int i = 0; i < mLabels.length; i++) {
        ImageLabel label = new ImageLabel(mLabels[i]);
        data.add(label);
    }
    // Add animals
    List<IMultiItem> animalData = new ArrayList<>(2);
    for (int i = 0; i < mAnimalIds.length; i++) {
        ImageCard cardData = new ImageCard(mAnimalIds[i], mAnimalTitles[i]);
        Card card = new Card(width, cardData);
        animalData.add(card);
    }
    ((DefaultExpandable) data.get(0)).addSubData(animalData);
    // Add beauties
    List<IMultiItem> beautyData = new ArrayList<>(mBeautyIds.length);
    for (int i = 0; i < mBeautyIds.length; i++) {
        ImageCard cardData = new ImageCard(mBeautyIds[i], mBeautyTitles[i]);
        Card card = new Card(width, cardData);
        beautyData.add(card);
    }
    ((DefaultExpandable) data.get(1)).addSubData(beautyData);
    // Add scenery
    List<IMultiItem> sceneryData = new ArrayList<>(mSceneryIds.length);
    for (int i = 0; i < mSceneryIds.length; i++) {
        ImageCard cardData = new ImageCard(mSceneryIds[i], mSceneryTitles[i]);
        Card card = new Card(width, cardData);
        sceneryData.add(card);
    }
    ((DefaultExpandable) data.get(2)).addSubData(sceneryData);
    // Add tranquil
    List<IMultiItem> tranquilData = new ArrayList<>(mTranquilIds.length);
    for (int i = 0; i < mTranquilIds.length; i++) {
        ImageCard cardData = new ImageCard(mTranquilIds[i], mTranquilTitles[i]);
        Card card = new Card(width, cardData);
        tranquilData.add(card);
    }
    ((DefaultExpandable) data.get(3)).addSubData(tranquilData);
    mAdapter.setData(data);
}
Also used : ImageLabel(xyz.zpayh.myadapter.data.ImageLabel) ArrayList(java.util.ArrayList) ImageCard(xyz.zpayh.myadapter.data.ImageCard) DefaultExpandable(xyz.zpayh.adapter.DefaultExpandable) IMultiItem(xyz.zpayh.adapter.IMultiItem) Card(xyz.zpayh.myadapter.data.Card) ImageCard(xyz.zpayh.myadapter.data.ImageCard)

Example 4 with ImageCard

use of xyz.zpayh.myadapter.data.ImageCard in project SherlockAdapter by EvilBT.

the class HeadAndFootActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_head_and_foot);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new HeadAndFootAdapter(this);
    recyclerView.setAdapter(mAdapter);
    mAdapter.addHeadLayout(R.layout.item_head);
    mAdapter.addFootLayout(R.layout.item_foot);
    mAdapter.addFootLayout(R.layout.item_foot2);
    List<ImageCard> data = new ArrayList<>();
    for (int i = 0; i < mTitles.length; i++) {
        ImageCard card = new ImageCard(mImageResId[i], mTitles[i]);
        data.add(card);
    }
    mAdapter.setData(data);
    final SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
    refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refresh();
            refresh.setRefreshing(false);
        }
    });
    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refresh();
        }
    });
}
Also used : HeadAndFootAdapter(xyz.zpayh.myadapter.adapter.HeadAndFootAdapter) ArrayList(java.util.ArrayList) ImageCard(xyz.zpayh.myadapter.data.ImageCard) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

ImageCard (xyz.zpayh.myadapter.data.ImageCard)4 ArrayList (java.util.ArrayList)3 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 DefaultExpandable (xyz.zpayh.adapter.DefaultExpandable)1 IMultiItem (xyz.zpayh.adapter.IMultiItem)1 OnLoadMoreListener (xyz.zpayh.adapter.OnLoadMoreListener)1 AutoLoadAdapter (xyz.zpayh.myadapter.adapter.AutoLoadAdapter)1 HeadAndFootAdapter (xyz.zpayh.myadapter.adapter.HeadAndFootAdapter)1 Card (xyz.zpayh.myadapter.data.Card)1 ImageLabel (xyz.zpayh.myadapter.data.ImageLabel)1