|
@@ -8,7 +8,12 @@ import com.sheep.gamegroup.model.entity.Article;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.GameEntity;
|
|
import com.sheep.gamegroup.model.entity.GameEntity;
|
|
|
import com.sheep.gamegroup.model.entity.GameInfoList;
|
|
import com.sheep.gamegroup.model.entity.GameInfoList;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.Release_task;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
|
|
+import com.sheep.gamegroup.module.game.adapter.AdpAllWelfare;
|
|
|
|
|
+import com.sheep.gamegroup.module.game.adapter.AdpGameWelfare;
|
|
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
import com.sheep.gamegroup.util.TestUtil;
|
|
import com.sheep.gamegroup.util.TestUtil;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
@@ -20,6 +25,8 @@ import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
|
|
|
|
|
+import org.afinal.simplecache.ApiKey;
|
|
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -27,9 +34,9 @@ import butterknife.BindView;
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
/**
|
|
/**
|
|
|
- * Created by realicing on 2019/1/22.
|
|
|
|
|
|
|
+ * Created by realicing on 2019/3/28.
|
|
|
* realicing@sina.com
|
|
* realicing@sina.com
|
|
|
- * 小绵羊3.4.10新增 -- 玩转游戏 礼包
|
|
|
|
|
|
|
+ * 小绵羊3.5.3 新增 -- 玩转游戏 福利
|
|
|
*/
|
|
*/
|
|
|
public class FgtGameWelfare extends BaseRefreshLoadMoreFragment {
|
|
public class FgtGameWelfare extends BaseRefreshLoadMoreFragment {
|
|
|
|
|
|
|
@@ -48,106 +55,128 @@ public class FgtGameWelfare extends BaseRefreshLoadMoreFragment {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- private ArrayList<GameInfoList> gameInfoListArrayList = ListUtil.emptyList();
|
|
|
|
|
|
|
+ private ArrayList<Release_task> list = ListUtil.emptyList();
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onViewCreated() {
|
|
public void onViewCreated() {
|
|
|
recyclerView.setHasFixedSize(true);
|
|
recyclerView.setHasFixedSize(true);
|
|
|
recyclerView.setNestedScrollingEnabled(false);
|
|
recyclerView.setNestedScrollingEnabled(false);
|
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
|
- AdpGcGameAppInfoList adpGcGameAppInfoList = new AdpGcGameAppInfoList(gameInfoListArrayList);
|
|
|
|
|
- adpGcGameAppInfoList.bindToRecyclerView(recyclerView);
|
|
|
|
|
- adpGcGameAppInfoList.setEmptyView(R.layout.include_empty_view);
|
|
|
|
|
|
|
+ AdpGameWelfare adapter = new AdpGameWelfare(list);
|
|
|
|
|
+ adapter.bindToRecyclerView(recyclerView);
|
|
|
|
|
+ adapter.setEmptyView(R.layout.include_empty_view);
|
|
|
|
|
+ initData();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- refreshData();
|
|
|
|
|
- if(gameEntity != null){
|
|
|
|
|
- loadGameData();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private int appId;
|
|
|
|
|
+
|
|
|
|
|
+ public void initListener() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //加载游戏数据
|
|
|
|
|
- private void loadGameData() {
|
|
|
|
|
- if (gameEntity.isGift()) {
|
|
|
|
|
- gameInfoListArrayList.add(new GameInfoList("礼包推荐", new AdpGcGameAppGiftBag(SheepApp.getInstance(), gameEntity.getHas_gift_bag(), gameEntity)).setSort(SORT_GIFT));
|
|
|
|
|
- }
|
|
|
|
|
- ViewUtil.notifyDataSetChanged(recyclerView);
|
|
|
|
|
|
|
+ private boolean isFirstCache = false;//是否首先尝试缓存
|
|
|
|
|
+
|
|
|
|
|
+ //先尝试缓存数据,无缓存数据时,再尝试获取网络数据
|
|
|
|
|
+ private void initData() {
|
|
|
|
|
+ isFirstCache = true;
|
|
|
|
|
+ setNoMore(false);
|
|
|
|
|
+ page = 1;
|
|
|
|
|
+ list.clear();
|
|
|
|
|
+ mInitData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //强制刷新数据
|
|
|
|
|
+ public void refreshData() {
|
|
|
|
|
+ isFirstCache = false;
|
|
|
|
|
+ setNoMore(false);
|
|
|
|
|
+ page = 1;
|
|
|
|
|
+ list.clear();
|
|
|
|
|
+ mInitData();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- private int appId;
|
|
|
|
|
|
|
|
|
|
|
|
+ public void loadMoreData() {
|
|
|
|
|
+ if (ListUtil.size(list) >= per_page * page) {
|
|
|
|
|
+ setNoMore(false);
|
|
|
|
|
+ page += 1;
|
|
|
|
|
+ //先加载缓存
|
|
|
|
|
+ getReleaseFromACache();
|
|
|
|
|
+ //再加载网络数据
|
|
|
|
|
+ getReleaseFromNetWork();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setNoMore(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ private int page = 1;
|
|
|
|
|
+ private int per_page = DataUtil.PER_PAGE;
|
|
|
|
|
+
|
|
|
|
|
+ public void mInitData() {
|
|
|
|
|
|
|
|
- private GameEntity gameEntity;
|
|
|
|
|
- public void loadData(final GameEntity gameEntity) {
|
|
|
|
|
- this.gameEntity = gameEntity;
|
|
|
|
|
- if(recyclerView != null) {
|
|
|
|
|
- loadGameData();
|
|
|
|
|
|
|
+ //先加载缓存
|
|
|
|
|
+ if(isFirstCache) {
|
|
|
|
|
+ getReleaseFromACache();
|
|
|
}
|
|
}
|
|
|
|
|
+ //再加载网络数据
|
|
|
|
|
+ getReleaseFromNetWork();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private int onResumeCount = 0;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
- public void refreshData() {
|
|
|
|
|
- ListUtil.removeItem(gameInfoListArrayList, new ListUtil.CallBack<GameInfoList, Boolean>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public Boolean call(GameInfoList gameInfoList) {
|
|
|
|
|
- return gameInfoList.getSort() == SORT_ACTIVITY || gameInfoList.getSort() == SORT_ARTICLE;
|
|
|
|
|
|
|
+ public void onResume() {
|
|
|
|
|
+ super.onResume();
|
|
|
|
|
+ if (onResumeCount > 0) {//直接全部刷新
|
|
|
|
|
+ initData();
|
|
|
|
|
+ }
|
|
|
|
|
+ onResumeCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //从ACache获取发布的任务列表
|
|
|
|
|
+ private void getReleaseFromACache() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<Release_task> cacheList = DataUtil.getInstance().getCacheList(getKey(), Release_task.class);
|
|
|
|
|
+ if(!ListUtil.isEmpty(cacheList)){
|
|
|
|
|
+ ListUtil.addAllItem(list, cacheList);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- ViewUtil.notifyDataSetChanged(recyclerView);
|
|
|
|
|
- //文章推荐
|
|
|
|
|
- SheepApp.getInstance().getNetComponent().getApiService().getDetailArticleRecommend(appId)
|
|
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
- List<Article> newList = baseMessage.getDatas(Article.class);
|
|
|
|
|
- if (!ListUtil.isEmpty(newList)) {
|
|
|
|
|
- gameInfoListArrayList.add(new GameInfoList("文章推荐", new AdpGcGameAppArticleRecommend(getContext(), newList)).setSort(SORT_ARTICLE));
|
|
|
|
|
- ViewUtil.notifyDataSetChanged(recyclerView);
|
|
|
|
|
- }
|
|
|
|
|
- refreshOrLoadMoreComplete();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
|
|
- if (TestUtil.isDev()) G.showToast(baseMessage);
|
|
|
|
|
- refreshOrLoadMoreComplete();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- //活动推荐
|
|
|
|
|
- SheepApp.getInstance().getNetComponent().getApiService().getDetailActivityRecommend(appId)
|
|
|
|
|
|
|
+ private String getKey() {
|
|
|
|
|
+ return ApiKey.pageKeyUrl(ApiKey.GET_ALL_WELFARE, page, per_page) + "&app_id="+appId;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //从网络获取发布的任务列表
|
|
|
|
|
+ private void getReleaseFromNetWork() {
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getAppWelfare(page, per_page, appId)
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
.subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
@Override
|
|
@Override
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
- List<Article> newList = baseMessage.getDatas(Article.class);
|
|
|
|
|
- if (!ListUtil.isEmpty(newList)) {
|
|
|
|
|
- gameInfoListArrayList.add(new GameInfoList("活动推荐", new AdpGcGameAppActivityRecommend(getContext(), newList)).setSort(SORT_ACTIVITY));
|
|
|
|
|
- ViewUtil.notifyDataSetChanged(recyclerView);
|
|
|
|
|
|
|
+ boolean isNewData = DataUtil.getInstance().isNewData(getKey());
|
|
|
|
|
+ if (isNewData || !isFirstCache) {
|
|
|
|
|
+ List<Release_task> cacheList = baseMessage.getDataList(Release_task.class);
|
|
|
|
|
+ if(!ListUtil.isEmpty(cacheList)){
|
|
|
|
|
+ ListUtil.addAllItem(list, cacheList);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- refreshOrLoadMoreComplete();
|
|
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
- if (TestUtil.isDev()) G.showToast(baseMessage);
|
|
|
|
|
- refreshOrLoadMoreComplete();
|
|
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void loadMoreData() {
|
|
|
|
|
- setNoMore(true);
|
|
|
|
|
|
|
+ private void notifyDataSetChanged() {
|
|
|
|
|
+ ViewUtil.notifyDataSetChanged(recyclerView);
|
|
|
refreshOrLoadMoreComplete();
|
|
refreshOrLoadMoreComplete();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //礼包推荐
|
|
|
|
|
- public static final int SORT_GIFT = 1;
|
|
|
|
|
- //文章推荐
|
|
|
|
|
- public static final int SORT_ARTICLE = 2;
|
|
|
|
|
- //活动推荐
|
|
|
|
|
- public static final int SORT_ACTIVITY = 3;
|
|
|
|
|
}
|
|
}
|