Explorar el Código

修改标签游戏列表中数据加载完成才显示

zengjiebin hace 7 años
padre
commit
9a3ce95deb

+ 16 - 14
app/src/main/java/com/sheep/gamegroup/module/game/fragment/FgtGameGroupMore.java

@@ -3,7 +3,6 @@ package com.sheep.gamegroup.module.game.fragment;
 import android.os.Bundle;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
-import android.util.SparseIntArray;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -71,6 +70,9 @@ public class FgtGameGroupMore extends BaseFragment {
 
 
     private void refreshData() {
+        if(count != 0){
+            return;
+        }
         initGameTagList();
     }
 
@@ -84,11 +86,7 @@ public class FgtGameGroupMore extends BaseFragment {
                 .subscribeOn(Schedulers.io())
                 .flatMap((Function<BaseMessage, Observable<GameListTag>>) baseMessage -> {
                     ArrayList<GameListTag> gameListTagList = baseMessage.getDataList(GameListTag.class);
-                    int i = 0;
-                    for (GameListTag item : gameListTagList) {
-                        sortSparseIntArray.put(i, item.getId());
-                        i ++;
-                    }
+                    gameTagListCount = ListUtil.size(gameListTagList);
                     return Observable.fromIterable(gameListTagList);
                 })
                 .filter(gameListTag -> gameListTag != null)
@@ -96,7 +94,7 @@ public class FgtGameGroupMore extends BaseFragment {
 
                     @Override
                     public void onNext(GameListTag gameListTag) {
-                        initGameList(play_game_list_x_rv, gameEntityListx, gameListTag.toGameListType());
+                        initGameList(gameEntityListx, gameListTag.toGameListType());
                     }
                 });
     }
@@ -121,9 +119,10 @@ public class FgtGameGroupMore extends BaseFragment {
         return rootView;
     }
 
-    private SparseIntArray sortSparseIntArray = new SparseIntArray();
-    private Comparator<ListTypeList<GameEntity, GameListType>> comparator = (item1, item2) -> sortSparseIntArray.get(item1.getType().getPort_type()) - sortSparseIntArray.get(item2.getType().getPort_type());
-    private void initGameList(final RecyclerView playGameListRv, final List<ListTypeList<GameEntity, GameListType>> gameEntityListList, final GameListType gameListType) {
+    private int gameTagListCount;
+    private int count;
+    private Comparator<ListTypeList<GameEntity, GameListType>> comparator = (item1, item2) -> item1.getType().getTag_id() - item2.getType().getTag_id();
+    private void initGameList(final List<ListTypeList<GameEntity, GameListType>> gameEntityListList, final GameListType gameListType) {
         if (gameListType == null) {
             return;
         }
@@ -136,8 +135,6 @@ public class FgtGameGroupMore extends BaseFragment {
                         List<GameEntity> newList = baseMessage.getDatas(GameEntity.class);
                         if (!ListUtil.isEmpty(newList)) {
                             gameEntityListList.add(new ListTypeList<>(gameListType, newList));
-                            Collections.sort(gameEntityListList, comparator);//排序
-                            ViewUtil.notifyDataSetChanged(playGameListRv);
                         }
                         notifyDataSetChanged();
                     }
@@ -150,8 +147,13 @@ public class FgtGameGroupMore extends BaseFragment {
     }
 
     private void notifyDataSetChanged() {
-        if (refresh != null) {
-            refresh.finishRefresh();
+        if(gameTagListCount == ++count) {
+            Collections.sort(gameEntityListx, comparator);//排序
+            ViewUtil.notifyDataSetChanged(play_game_list_x_rv);
+            if (refresh != null) {
+                refresh.finishRefresh();
+            }
+            count = 0;
         }
     }
 }