|
| 1 | +/* |
| 2 | + * Copyright 2017 GcsSloop |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * Last modified 2017-04-09 19:30:45 |
| 17 | + * |
| 18 | + * GitHub: https://github.com/GcsSloop |
| 19 | + * Website: http://www.gcssloop.com |
| 20 | + * Weibo: http://weibo.com/GcsSloop |
| 21 | + */ |
| 22 | + |
| 23 | +package com.gcssloop.diycode.fragment; |
| 24 | + |
| 25 | +import android.content.Context; |
| 26 | +import android.os.Bundle; |
| 27 | +import android.support.annotation.NonNull; |
| 28 | +import android.support.v7.widget.RecyclerView; |
| 29 | + |
| 30 | +import com.gcssloop.diycode.base.app.RefreshRecyclerFragment; |
| 31 | +import com.gcssloop.diycode.base.recyclerview.SpeedyLinearLayoutManager; |
| 32 | +import com.gcssloop.diycode.fragment.provider.TopicProvider; |
| 33 | +import com.gcssloop.diycode_sdk.api.topic.bean.Topic; |
| 34 | +import com.gcssloop.diycode_sdk.api.topic.event.GetTopicsListEvent; |
| 35 | +import com.gcssloop.recyclerview.adapter.multitype.HeaderFooterAdapter; |
| 36 | + |
| 37 | +public class NodeTopicListFragment extends RefreshRecyclerFragment<Topic, GetTopicsListEvent> { |
| 38 | + private static String Key_Node_ID = "Key_Node_ID"; |
| 39 | + private int mNodeId = 0; |
| 40 | + |
| 41 | + public static NodeTopicListFragment newInstance(int nodeId) { |
| 42 | + Bundle args = new Bundle(); |
| 43 | + args.putInt(Key_Node_ID, nodeId); |
| 44 | + NodeTopicListFragment fragment = new NodeTopicListFragment(); |
| 45 | + fragment.setArguments(args); |
| 46 | + return fragment; |
| 47 | + } |
| 48 | + |
| 49 | + @Override public void initData(HeaderFooterAdapter adapter) { |
| 50 | + mNodeId = getArguments().getInt(Key_Node_ID, 0); |
| 51 | + loadMore(); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected void setRecyclerViewAdapter(Context context, RecyclerView recyclerView, |
| 56 | + HeaderFooterAdapter adapter) { |
| 57 | + adapter.register(Topic.class, new TopicProvider(getContext())); |
| 58 | + } |
| 59 | + |
| 60 | + @NonNull @Override protected RecyclerView.LayoutManager getRecyclerViewLayoutManager() { |
| 61 | + return new SpeedyLinearLayoutManager(getContext()); |
| 62 | + } |
| 63 | + |
| 64 | + @NonNull @Override protected String request(int offset, int limit) { |
| 65 | + return mDiycode.getTopicsList(null, mNodeId, offset, limit); |
| 66 | + } |
| 67 | + |
| 68 | + @Override protected void onRefresh(GetTopicsListEvent event, HeaderFooterAdapter adapter) { |
| 69 | + adapter.clearDatas(); |
| 70 | + adapter.addDatas(event.getBean()); |
| 71 | + } |
| 72 | + |
| 73 | + @Override protected void onLoadMore(GetTopicsListEvent event, HeaderFooterAdapter adapter) { |
| 74 | + adapter.addDatas(event.getBean()); |
| 75 | + } |
| 76 | + |
| 77 | + @Override protected void onError(GetTopicsListEvent event, String postType) { |
| 78 | + toast("加载错误"); |
| 79 | + } |
| 80 | +} |
0 commit comments