2525import android .content .Context ;
2626import android .os .Bundle ;
2727import android .support .annotation .NonNull ;
28- import android .support .annotation .Nullable ;
2928import android .support .v7 .widget .RecyclerView ;
3029import android .view .View ;
3130
3231import com .gcssloop .diycode .R ;
3332import com .gcssloop .diycode .base .recyclerview .SpeedyLinearLayoutManager ;
3433import com .gcssloop .diycode .fragment .provider .TopicProvider ;
35- import com .gcssloop .diycode .utils .Config ;
36- import com .gcssloop .diycode .utils .DataCache ;
37- import com .gcssloop .diycode_sdk .api .Diycode ;
3834import com .gcssloop .diycode_sdk .api .topic .bean .Topic ;
3935import com .gcssloop .diycode_sdk .api .topic .event .GetTopicsListEvent ;
4036import com .gcssloop .diycode_sdk .log .Logger ;
4642public class TopicListFragment extends RefreshRecyclerFragment <Topic , GetTopicsListEvent > {
4743
4844 private boolean isFirstLaunch = true ;
49- // 数据
50- private Config mConfig ; // 配置(状态信息)
51- private Diycode mDiycode ; // 在线(服务器)
52- private DataCache mDataCache ; // 缓存(本地)
5345
5446 public static TopicListFragment newInstance () {
5547 Bundle args = new Bundle ();
@@ -58,14 +50,6 @@ public static TopicListFragment newInstance() {
5850 return fragment ;
5951 }
6052
61- @ Override
62- public void onCreate (@ Nullable Bundle savedInstanceState ) {
63- super .onCreate (savedInstanceState );
64- mConfig = Config .getSingleInstance ();
65- mDiycode = Diycode .getSingleInstance ();
66- mDataCache = new DataCache (getContext ());
67- }
68-
6953 @ Override
7054 public void initData (HeaderFooterAdapter adapter ) {
7155 List <Topic > topics = mDataCache .getTopicsList ();
@@ -75,10 +59,7 @@ public void initData(HeaderFooterAdapter adapter) {
7559 adapter .addDatas (topics );
7660 if (isFirstLaunch ) {
7761 int lastPosition = mConfig .getTopicListLastPosition ();
78- int lastOffset = mConfig .getTopicListLastOffset ();
79- if (lastPosition != 0 ) {
80- mRecyclerView .getLayoutManager ().scrollToPosition (lastPosition );
81- }
62+ mRecyclerView .getLayoutManager ().scrollToPosition (lastPosition );
8263 isFirstAddFooter = false ;
8364 isFirstLaunch = false ;
8465 }
@@ -100,7 +81,6 @@ protected RecyclerView.LayoutManager getRecyclerViewLayoutManager() {
10081 return new SpeedyLinearLayoutManager (getContext ());
10182 }
10283
103-
10484 @ NonNull
10585 @ Override
10686 protected String request (int offset , int limit ) {
@@ -132,7 +112,6 @@ protected void onError(GetTopicsListEvent event, String postType) {
132112 }
133113 }
134114
135- @ SuppressWarnings ("unchecked" )
136115 public ArrayList <Topic > convert (List <Object > objects ) {
137116 ArrayList <Topic > topics = new ArrayList <>();
138117 for (Object obj : objects ) {
@@ -153,11 +132,8 @@ private void saveState() {
153132 // 存储 PageIndex
154133 mConfig .saveTopicListPageIndex (pageIndex );
155134 // 存储 RecyclerView 滚动位置
156- RecyclerView .LayoutManager layoutManager = mRecyclerView .getLayoutManager ();
157- View view = layoutManager .getChildAt (0 );
158- int lastPosition = layoutManager .getPosition (view );
159- int lastOffset = view .getTop ();
160- mConfig .saveTopicListState (lastPosition , lastOffset );
161- Logger .e ("onDestroyView" , lastPosition + " : " + lastOffset );
135+ View view = mRecyclerView .getLayoutManager ().getChildAt (0 );
136+ int lastPosition = mRecyclerView .getLayoutManager ().getPosition (view );
137+ mConfig .saveTopicListState (lastPosition , 0 );
162138 }
163139}
0 commit comments