Przeglądaj źródła

发现缓存相关

zengjiebin 7 lat temu
rodzic
commit
5f264d381b

+ 24 - 18
app/src/main/java/com/kfzs/duanduan/fragment/FgtFindChild.java

@@ -110,7 +110,7 @@ public class FgtFindChild extends BaseCompatFragment {
         refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
             @Override
             public void onRefresh() {
-                initData();
+                refreshData();
                 refresh.setRefreshing(false);
             }
         });
@@ -270,7 +270,16 @@ public class FgtFindChild extends BaseCompatFragment {
         }
     }
 
-    private void initData(){
+    public void initData(){
+        //先尝试获取缓存数据
+        List<FindItem> newList = DataUtil.getInstance().getCacheList(ApiKey.articles(type), FindItem.class);
+        if(loadList(newList))
+            refreshData();
+        else
+            notifyDataSetChanged();
+    }
+
+    public void refreshData(){
         empty_view.setVisibility(View.INVISIBLE);
         SysAppUtil.checkNet(new Action1<Integer>() {
             @Override
@@ -296,25 +305,22 @@ public class FgtFindChild extends BaseCompatFragment {
 
                             @Override
                             public void onError(BaseMessage baseMessage) {
-                                //无数据时尝试获取缓存数据
-                                List<FindItem> newList = DataUtil.getInstance().getCacheList(ApiKey.articles(type), FindItem.class);
-                                if(loadList(newList))
-                                    notifyDataSetChanged();
-                            }
-                            //没有添加数据返回true
-                            private boolean loadList(List<FindItem> newList){
-                                if(!ListUtil.isEmpty(newList)){
-                                    list.clear();
-                                    ListUtil.addAll(list, newList);
-                                    if(!list.isEmpty())
-                                        list.add(null);//底部部分----我是有底线的
-                                    notifyDataSetChanged();
-                                    return false;
-                                }
-                                return true;
+                                notifyDataSetChanged();
                             }
                         });
     }
+    //没有添加数据返回true
+    private boolean loadList(List<FindItem> newList){
+        if(!ListUtil.isEmpty(newList)){
+            list.clear();
+            ListUtil.addAll(list, newList);
+            if(!list.isEmpty())
+                list.add(null);//底部部分----我是有底线的
+            notifyDataSetChanged();
+            return false;
+        }
+        return true;
+    }
 
     private void notifyDataSetChanged(){
         CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());

+ 21 - 16
app/src/main/java/com/kfzs/duanduan/fragment/FgtPersonalCenter.java

@@ -28,6 +28,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
 import org.afinal.simplecache.ACache;
+import org.afinal.simplecache.ApiKey;
 
 import java.util.Locale;
 
@@ -173,25 +174,29 @@ public class FgtPersonalCenter extends BaseCompatFragment {
                 Jump2View.getInstance().goTaskList2View(activity, null);
                 break;
             case R.id.proxy_service_layout://代理
-                Object url_config = ACache.get(activity).getAsObject("url_config");
-                if(url_config instanceof JSONObject) {
-                    agentUrl = ((JSONObject) url_config).getString("agenturl");
-                    if (!TextUtils.isEmpty(agentUrl))
-                        Jump2View.getInstance().goWeb(activity, agentUrl, "代理服务");
-                    else
-                        G.showToast(R.string.loading_data);
-                }
+                CommonUtil.getInstance().initUrlConfigByNet("agenturl", new Action1<String>(){
+                    @Override
+                    public void call(String url) {
+                        agentUrl = url;
+                        if (!TextUtils.isEmpty(agentUrl))
+                            Jump2View.getInstance().goWeb(activity, agentUrl, "代理服务");
+                        else
+                            G.showToast(R.string.loading_data);
+                    }
+                });
                 USER_AGENT.onEvent();
                 break;
             case R.id.faq_layout://FAQ帮助
-                Object url_config1 = ACache.get(activity).getAsObject("url_config");
-                if(url_config1 instanceof JSONObject) {
-                    faqUrl = ((JSONObject) url_config1).getString("faqurl");
-                    if (!TextUtils.isEmpty(faqUrl))
-                        Jump2View.getInstance().goWeb(activity, faqUrl, "FAQ帮助");
-                    else
-                        Jump2View.getInstance().goWeb(activity, "http://smallstation.kfzs.com/h5_faq/#/faq", "FAQ帮助");
-                }
+                CommonUtil.getInstance().initUrlConfigByNet("faqurl", new Action1<String>(){
+                    @Override
+                    public void call(String url) {
+                        faqUrl = url;
+                        if (!TextUtils.isEmpty(faqUrl))
+                            Jump2View.getInstance().goWeb(activity, faqUrl, "FAQ帮助");
+                        else
+                            Jump2View.getInstance().goWeb(activity, "http://smallstation.kfzs.com/h5_faq/#/faq", "FAQ帮助");
+                    }
+                });
                 USER_FAQ.onEvent();
                 break;
             case R.id.reservation_layout://游戏预约

+ 0 - 6
app/src/main/java/com/kfzs/duanduan/fragment/FgtSmallSheep.java

@@ -426,9 +426,6 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
             adpHomeListListview.notifyDataSetChanged();
             home_list_gridview_listview.setVisibility(homeListEntitysListview.isEmpty() ? View.GONE : View.VISIBLE);
         }
-
-        //详情分享地址
-        CommonUtil.getInstance().initUrlConfigByNet(activity);
     }
     public void refreshData() {
         SysAppUtil.checkNet(new Action1<Integer>() {
@@ -465,9 +462,6 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
         pagePresenter.slideshow(null);//轮播
         pagePresenter.homeList();//首页list
 
-        //详情分享地址
-        CommonUtil.getInstance().initUrlConfigByNet(activity);
-
     }
 
     /**

+ 30 - 20
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -67,6 +67,7 @@ import com.umeng.socialize.media.UMImage;
 import com.umeng.socialize.media.UMWeb;
 
 import org.afinal.simplecache.ACache;
+import org.afinal.simplecache.ApiKey;
 import org.greenrobot.eventbus.EventBus;
 
 import java.io.File;
@@ -850,27 +851,36 @@ public class CommonUtil {
      * find_share_url;//发现详情分享
      * task_desc_url;//分享任务详情
      */
-    public void initUrlConfigByNet(final Context context){
-        SheepApp.get(context)
-                .getNetComponent()
-                .getApiService()
-                .getNameUrl()
-                .subscribeOn(Schedulers.io())
-                .observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
-                    @Override
-                    public void onError(BaseMessage baseMessage) {
-//                        G.showToast(baseMessage.getMsg() +"");
-
-                    }
+    public void initUrlConfigByNet(final String name, final Action1<String> action1){
+        JSONObject url_config = DataUtil.getInstance().getCacheResult(ApiKey.url, JSONObject.class);
+        if(url_config == null) {
+            SheepApp.get(SheepApp.getInstance())
+                    .getNetComponent()
+                    .getApiService()
+                    .getNameUrl()
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            action1.call(null);
+                        }
 
-                    @Override
-                    public void onNext(BaseMessage baseMessage) {
-                        Object urlConfig = baseMessage.getData();
-                        if(urlConfig instanceof JSONObject)
-                            ACache.get(context).put("url_config", (JSONObject) urlConfig);
-                    }
-                });
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            JSONObject urlConfig = baseMessage.getData(JSONObject.class);
+                            if(urlConfig == null) {
+                                action1.call(null);
+                            } else {
+                                String url = urlConfig.getString(name);
+                                action1.call(url);
+                            }
+                        }
+                    });
+        } else {
+            String url = url_config.getString(name);
+            action1.call(url);
+        }
     }
     /**
      * 获取详情地址

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/util/ConnectAddress.java

@@ -52,7 +52,7 @@ public enum ConnectAddress {
         public String getName() {
             return "测试服";
         }
-    },sheeptestnei {
+    },sheepfz {
 
         @Override
         public String getAppUrl() {

+ 8 - 7
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -1362,14 +1362,15 @@ public class Jump2View {
         activity.startActivity(intent);
     }
 
-    public void tryShare(Activity activity, String shareUrlKey, String idName, int id) {
+    public void tryShare(final Activity activity, String shareUrlKey, final String idName, final int id) {
         try{
-            Object url_config1 = ACache.get(SheepApp.getInstance()).getAsObject("url_config");
-            if(url_config1 instanceof JSONObject) {
-                String find_share_url = ((JSONObject) url_config1).getString(shareUrlKey);
-                String url = String.format(Locale.CHINA, "%s?authorization=%s&%s=%d&invitation_code=%s", find_share_url, SpUtils.getToken(activity), idName, id, DataUtil.getInstance().getInvitationCode());
-                CommonUtil.getInstance().popShare(activity, url, "all");
-            }
+            CommonUtil.getInstance().initUrlConfigByNet(shareUrlKey, new Action1<String>(){
+                @Override
+                public void call(String find_share_url) {
+                    String url = String.format(Locale.CHINA, "%s?authorization=%s&%s=%d&invitation_code=%s", find_share_url, SpUtils.getToken(activity), idName, id, DataUtil.getInstance().getInvitationCode());
+                    CommonUtil.getInstance().popShare(activity, url, "all");
+                }
+            });
         }catch (Exception e){
             e.printStackTrace();
         }

+ 13 - 1
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -12,6 +12,8 @@ import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.graphics.drawable.Drawable;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
 import android.os.Build;
 import android.provider.AlarmClock;
 import android.provider.Settings;
@@ -47,6 +49,9 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
@@ -57,6 +62,7 @@ import java.util.SortedMap;
 import java.util.TreeMap;
 
 import okhttp3.Call;
+import okhttp3.Response;
 import rx.Observable;
 import rx.android.schedulers.AndroidSchedulers;
 import rx.functions.Action1;
@@ -256,7 +262,13 @@ public class SysAppUtil {
 //                            e.printStackTrace();
 //                        }
 //                        return result;
-                        return 0;
+                        try {
+                            Response response = OkHttpUtils.get().url("http://www.baidu.com").build().execute();
+                            return response.isSuccessful() ? 0 : -1;
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                            return -2;
+                        }
                     }
                 })
                 .subscribeOn(Schedulers.io())

+ 11 - 23
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -333,11 +333,12 @@ public class TestUtil {
                                 Jump2View.getInstance().goGameSearch(activity, null);
                                 break;
                             case "测试代理页面":
-                                Object url_config1 = ACache.get(SheepApp.getInstance()).getAsObject("url_config");
-                                if(url_config1 instanceof JSONObject) {
-                                    String url = ((JSONObject) url_config1).getString("agenturl");
-                                    Jump2View.getInstance().goWeb(activity, url, "代理服务");
-                                }
+                                CommonUtil.getInstance().initUrlConfigByNet("agenturl", new Action1<String>(){
+                                    @Override
+                                    public void call(String url) {
+                                        Jump2View.getInstance().goWeb(activity, url, "代理服务");
+                                    }
+                                });
                                 break;
                             case "尝试开启第三方应用使用情况":
                                 AppUsageManager.getInstance().tryOpenLookAppUsageStatsPermisson(false);
@@ -459,25 +460,12 @@ public class TestUtil {
 
 
     private static void copyUrl(final String name) {
-        Object url_config1 = ACache.get(SheepApp.getInstance()).getAsObject("url_config");
-        if(url_config1 instanceof JSONObject) {
-            String url;
-            switch (name){
-                case "faqurl":
-                    url = ((JSONObject) url_config1).getString("faqurl");
-                    break;
-                case "agenturl":
-                    url = ((JSONObject) url_config1).getString("agenturl");
-                    break;
-                case "world_cup_url":
-                    url = ((JSONObject) url_config1).getString("world_cup_url");
-                    break;
-                default:
-                    url = ((JSONObject) url_config1).getString("find_share_url");
-                    break;
+        CommonUtil.getInstance().initUrlConfigByNet(name, new Action1<String>(){
+            @Override
+            public void call(String url) {
+                StringUtils.CopyText(ActWeb.addUrlToken(url));
             }
-            StringUtils.CopyText(ActWeb.addUrlToken(url));
-        }
+        });
     }
 
     private static void showHasInstallApkList(Activity activity) {

+ 92 - 67
app/src/main/java/com/sheep/gamegroup/view/activity/ActFindGame.java

@@ -34,6 +34,7 @@ import com.sheep.gamegroup.model.entity.MyFindAppCore;
 import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ListUtil;
@@ -45,6 +46,7 @@ import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
+import org.afinal.simplecache.ApiKey;
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 
@@ -199,85 +201,108 @@ public class ActFindGame extends BaseActivity {
 
     @Override
     public void initData() {
-        showProgress();
-        resetData();
-        SheepApp.getInstance().getNetComponent().getApiService().getAppDetail(id)
-                .subscribeOn(Schedulers.io())
-                .observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new SheepSubscriber<BaseMessage>(this) {
-                    @Override
-                    public void onNext(BaseMessage baseMessage) {
-                        FindApp findApp = baseMessage.getData(FindApp.class);
-                        if (findApp != null) {
-                            loadData(findApp);
-                            if(isShowAppScore) {
-                                initAppScoreNum();
-                                initMyAppScore();
-                            }
-                        } else {
-                            resetData();
+        FindApp findApp = DataUtil.getInstance().getCacheResult(ApiKey.applications(id), FindApp.class);
+        if(findApp != null){
+            loadApp(findApp);
+        } else {
+            showProgress();
+            SheepApp.getInstance().getNetComponent().getApiService().getAppDetail(id)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(this) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            FindApp findApp = baseMessage.getData(FindApp.class);
+                            loadApp(findApp);
+                            hideProgress();
                         }
-                        hideProgress();
-                    }
 
-                    @Override
-                    public void onError(BaseMessage baseMessage) {
-                        G.showToast(baseMessage);
-                        resetData();
-                        hideProgress();
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            G.showToast(baseMessage);
+                            resetData();
+                            hideProgress();
+                        }
+                    });
+        }
+        UserEntity userEntity = DataUtil.getInstance().getUserEntity();
+        if(userEntity == null) {
+            CommonUtil.getInstance().updateUserInfo(new Action1<UserEntity>() {
+                @Override
+                public void call(UserEntity userEntity) {
+                    if (userEntity != null) {
+                        loadUserInfo(userEntity);
+                    } else {
+                        resetUserInfo();
                     }
-                });
-        CommonUtil.getInstance().updateUserInfo(new Action1<UserEntity>() {
-            @Override
-            public void call(UserEntity userEntity) {
-                if (userEntity != null) {
-                    loadUserInfo(userEntity);
-                } else {
-                    resetUserInfo();
                 }
+            });
+        } else {
+            loadUserInfo(userEntity);
+        }
+    }
+
+    private void loadApp(FindApp findApp) {
+        if (findApp != null) {
+            loadData(findApp);
+            if(isShowAppScore) {
+                initAppScoreNum();
+                initMyAppScore();
             }
-        });
+        } else {
+            resetData();
+        }
     }
 
     private void initAppScoreNum() {
-        SheepApp.getInstance().getNetComponent().getApiService().getAppScoreNum(id)
-                .subscribeOn(Schedulers.io())
-                .observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                    @Override
-                    public void onNext(BaseMessage baseMessage) {
-                        List<FindAppScore> findAppScoreList = baseMessage.getDataList(FindAppScore.class);
-                        if (ListUtil.isEmpty(findAppScoreList))
-                            resetAppScoreNum();
-                        else
-                            loadAppScoreNum(findAppScoreList);
-                    }
+        List<FindAppScore> findAppScoreList = DataUtil.getInstance().getCacheList(ApiKey.score_num(id), FindAppScore.class);
+        if (findAppScoreList == null) {
+            SheepApp.getInstance().getNetComponent().getApiService().getAppScoreNum(id)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            List<FindAppScore> findAppScoreList = baseMessage.getDataList(FindAppScore.class);
+                            if (ListUtil.isEmpty(findAppScoreList))
+                                resetAppScoreNum();
+                            else
+                                loadAppScoreNum(findAppScoreList);
+                        }
 
-                    @Override
-                    public void onError(BaseMessage baseMessage) {
-                        G.showToast(baseMessage);
-                    }
-                });
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            G.showToast(baseMessage);
+                        }
+                    });
+        } else if(!findAppScoreList.isEmpty()) {
+            loadAppScoreNum(findAppScoreList);
+        }
     }
-
     private void initMyAppScore() {
-        SheepApp.getInstance().getNetComponent().getApiService().getMyAppScore(id)
-                .subscribeOn(Schedulers.io())
-                .observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                    @Override
-                    public void onNext(BaseMessage baseMessage) {
-                        MyFindAppCore myFindAppCore = baseMessage.getData(MyFindAppCore.class);
-                        if (myFindAppCore == null)
-                            resetMyAppScore();
-                        else
-                            loadMyAppScore(myFindAppCore);
-                    }
+        MyFindAppCore myFindAppCore = DataUtil.getInstance().getCacheResult(ApiKey.my_score(id), MyFindAppCore.class);
+        if (myFindAppCore == null) {
+            SheepApp.getInstance().getNetComponent().getApiService().getMyAppScore(id)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            MyFindAppCore myFindAppCore = baseMessage.getData(MyFindAppCore.class);
+                            if (myFindAppCore == null)
+                                resetMyAppScore();
+                            else
+                                loadMyAppScore(myFindAppCore);
+                        }
 
-                    @Override
-                    public void onError(BaseMessage baseMessage) {
-                    }
-                });
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            resetMyAppScore();
+                        }
+                    });
+        } else {
+            loadMyAppScore(myFindAppCore);
+        }
     }
 
     @BindView(R.id.find_game_iv)

+ 65 - 47
app/src/main/java/com/sheep/gamegroup/view/activity/ActFindInformation.java

@@ -24,6 +24,7 @@ import com.sheep.gamegroup.model.entity.FindApp;
 import com.sheep.gamegroup.model.entity.FindItem;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ListUtil;
@@ -40,6 +41,7 @@ import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
+import org.afinal.simplecache.ApiKey;
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 
@@ -212,57 +214,73 @@ public class ActFindInformation extends BaseActivity implements Action1<Integer>
                 }
             }
         });
-        SheepApp.getInstance().getNetComponent().getApiService().getFindDetail(id)
-                        .subscribeOn(Schedulers.io())
-                        .observeOn(AndroidSchedulers.mainThread())
-                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                            @Override
-                            public void onNext(BaseMessage baseMessage) {
-                                FindItem data = baseMessage.getData(FindItem.class);
-                                if(data != null && !TextUtils.equals(JSON.toJSONString(findItem), JSON.toJSONString(data))){
-                                    taskHelper.clear();
-                                    findItem = data;
-                                    list.clear();
-                                    list.add("top");
-                                    list.add("bottom");
-                                    notifyDataSetChanged();
-                                    if(findItem.getRelease_task_id() != 0){//包含任务
-                                        taskHelper.initAcceptedTask(ActFindInformation.this, findItem.getRelease_task_id());
-                                    }
-                                    if(findItem.getApplication_id() != 0){//包含游戏
-                                        initFindApp(findItem.getApplication_id());
-                                    }
-                                } else {
-                                    refresh.setRefreshing(false);
-                                }
-                            }
-
-                            @Override
-                            public void onError(BaseMessage baseMessage) {
-                                taskHelper.clear();
-                                notifyDataSetChanged();
-                            }
-                        });
+        FindItem data = DataUtil.getInstance().getCacheResult(ApiKey.articlesItem(id), FindItem.class);
+        if(data == null){
+            SheepApp.getInstance().getNetComponent().getApiService().getFindDetail(id)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            FindItem data = baseMessage.getData(FindItem.class);
+                            loadFindItem(data);
+                        }
+
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            taskHelper.clear();
+                            notifyDataSetChanged();
+                        }
+                    });
+        } else {
+            loadFindItem(data);
+        }
+    }
+
+    private void loadFindItem(FindItem data) {
+        if(data != null && !TextUtils.equals(JSON.toJSONString(findItem), JSON.toJSONString(data))){
+            taskHelper.clear();
+            findItem = data;
+            list.clear();
+            list.add("top");
+            list.add("bottom");
+            notifyDataSetChanged();
+            if(findItem.getRelease_task_id() != 0){//包含任务
+                taskHelper.initAcceptedTask(ActFindInformation.this, findItem.getRelease_task_id());
+            }
+            if(findItem.getApplication_id() != 0){//包含游戏
+                initFindApp(findItem.getApplication_id());
+            }
+        } else {
+            refresh.setRefreshing(false);
+        }
     }
 
     private FindApp findApp;
     private void initFindApp(int application_id) {
-        SheepApp.getInstance().getNetComponent().getApiService().getAppDetail(application_id)
-                        .subscribeOn(Schedulers.io())
-                        .observeOn(AndroidSchedulers.mainThread())
-                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                            @Override
-                            public void onNext(BaseMessage baseMessage) {
-                                findApp = baseMessage.getData(FindApp.class);
-                                notifyDataSetChanged();
-                            }
-
-                            @Override
-                            public void onError(BaseMessage baseMessage) {
-                                G.showToast(baseMessage);
-                                refresh.setRefreshing(false);
-                            }
-                        });
+
+        FindApp cacheResult = DataUtil.getInstance().getCacheResult(ApiKey.applications(id), FindApp.class);
+        if(cacheResult != null){
+            findApp = cacheResult;
+            notifyDataSetChanged();
+        } else {
+            SheepApp.getInstance().getNetComponent().getApiService().getAppDetail(application_id)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            findApp = baseMessage.getData(FindApp.class);
+                            notifyDataSetChanged();
+                        }
+
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            G.showToast(baseMessage);
+                            refresh.setRefreshing(false);
+                        }
+                    });
+        }
     }
 
     private FindItem findItem;

+ 1 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/SplashAct.java

@@ -203,9 +203,7 @@ public class SplashAct extends BaseActivity implements EasyPermissions.Permissio
 
     private void loadAdvertising() {
         if(advertising.isImage()) {
-            if(!TextUtils.equals("http://staticcdn.kuaifazs.com/upload/static/201807/25/16/76/L0Om90.jpg",advertising.getDisplay_src())) {
-                Glide.with(activity).load(advertising.getDisplay_src()).into(splash_bg);
-            }
+            Glide.with(activity).load(advertising.getDisplay_src()).into(splash_bg);
 //            btnJoin.setVisibility(View.GONE);
             splash_video_view.setVisibility(View.GONE);
         } else {

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailAct.java

@@ -873,6 +873,7 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                                     taskReleaseEty.setIs_running(true);
                                     taskReleaseEty.getTask().setRelease_task_id(taskReleaseEty.getId());
                                     CommonUtil.getInstance().setTAskEnty(taskReleaseEty.getTask());
+                                    DataUtil.getInstance().addAcceptedTask(gettaskAcceptedEty);
                                     empty_view.setVisibility(View.GONE);
                                     initWigget();
                                     isGetTaskDesc = false;

+ 20 - 33
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtMyGame.java

@@ -11,7 +11,6 @@ import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
 
-import com.alibaba.fastjson.JSON;
 import com.arialyy.annotations.Download;
 import com.arialyy.aria.core.download.DownloadTask;
 import com.kfzs.duanduan.utils.ApkUtils;
@@ -20,8 +19,9 @@ import com.sheep.gamegroup.model.entity.OrienteeringDetail;
 import com.sheep.gamegroup.model.entity.RecyleObj;
 import com.sheep.gamegroup.model.entity.RecyleType;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.ListUtil;
-import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp;
 import com.sheep.gamegroup.view.customview.SheepmSwipeRefreshLayout;
 import com.sheep.jiuyan.samllsheep.R;
@@ -29,6 +29,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.base.BaseFragment;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
+import org.afinal.simplecache.ApiKey;
 import org.greenrobot.eventbus.Subscribe;
 
 import java.util.List;
@@ -88,10 +89,7 @@ public class FgtMyGame extends BaseFragment {
 
         recyclerview.setLayoutManager(new LinearLayoutManager(activity));
         tryMakeMoneyAdp = new TryMakeMoneyAdp(activity);
-
-        for (int i = 0; i < 1; i++) {
-            tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.NONE, null));
-        }
+        tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.NONE, null));
         recyclerview.setAdapter(tryMakeMoneyAdp);
         initListener();
 
@@ -101,7 +99,7 @@ public class FgtMyGame extends BaseFragment {
         refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
             @Override
             public void onRefresh() {
-                initData();
+                refreshData();
             }
         });
         recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -122,26 +120,30 @@ public class FgtMyGame extends BaseFragment {
     }
 
     private void initData() {
-        list.clear();
-        for (int i = 0; i < 1; i++) {
-            tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.NONE, null));
+        refresh.setRefreshing(true);
+        List<OrienteeringDetail> newList = DataUtil.getInstance().getCacheList(ApiKey.my_games, OrienteeringDetail.class);
+        if(newList == null){
+            refreshData();
+        } else {
+            list = newList;
+            notifyDataSetChanged();
         }
+    }
+    private void refreshData() {
         SheepApp.getInstance().getNetComponent().getApiService().getMyGames(page, per_page)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
-                        List<OrienteeringDetail> newList = baseMessage.getDatas(OrienteeringDetail.class);
-                        if(newList != null && newList.size()>0){
-                            list.addAll(newList);
-                        }
+                        list = baseMessage.getDataList(OrienteeringDetail.class);
                         notifyDataSetChanged();
                     }
 
                     @Override
                     public void onError(BaseMessage baseMessage) {
                         G.showToast(baseMessage);
+                        list.clear();
                         notifyDataSetChanged();
                     }
                 });
@@ -154,21 +156,14 @@ public class FgtMyGame extends BaseFragment {
     }
     private void notifyDataSetChanged(){
         checkAndInitView();
-        tryMakeMoneyAdp.refreshAdapter();
-        if(tryMakeMoneyAdp.isEmpty() && list.isEmpty()){
-
-            empty_view.setVisibility(View.VISIBLE);
-        }else {
+        boolean isEmpty = tryMakeMoneyAdp.isEmpty() && list.isEmpty();
+        CommonUtil.getInstance().updateEmptyView(empty_view, isEmpty);
+        if(!isEmpty){
             tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.GAME_TASK, list),0);
-            empty_view.setVisibility(View.GONE);
         }
+        tryMakeMoneyAdp.refreshAdapter();
         refresh.setRefreshing(false);
     }
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-//        EventBus.getDefault().unregister(this);
-    }
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -191,10 +186,6 @@ public class FgtMyGame extends BaseFragment {
     @Override
     public void onResume() {
         super.onResume();
-        reFresh();
-    }
-    public void reFresh(){
-        refresh.setRefreshing(true);
         initData();
     }
 
@@ -211,7 +202,6 @@ public class FgtMyGame extends BaseFragment {
                 return;
             }
             tvProgress.setText(String.format(Locale.CHINA, "%d%%",Math.abs(p)));
-            tryMakeMoneyAdp.notifyDataSetChanged();
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -234,7 +224,6 @@ public class FgtMyGame extends BaseFragment {
                 return;
             }
             tvProgress.setText("已经取消");
-            tryMakeMoneyAdp.notifyDataSetChanged();
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -249,7 +238,6 @@ public class FgtMyGame extends BaseFragment {
                 return;
             }
             tvProgress.setText("下载失败");
-            tryMakeMoneyAdp.notifyDataSetChanged();
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -263,7 +251,6 @@ public class FgtMyGame extends BaseFragment {
                 return;
             }
             tvProgress.setText("开始安装");
-            tryMakeMoneyAdp.notifyDataSetChanged();
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 20 - 0
app/src/main/java/org/afinal/simplecache/ApiKey.java

@@ -30,10 +30,14 @@ public class ApiKey {
     public static final String slideshow = "app/slideshow?platform=1";
     //home_list
     public static final String home_list = "app/home_list";
+    //各种url配置
+    public static final String url = "app/url/";
     //用户信息
     public static final String get_info = "app/user/get_info/";
     //award_detail
     public static final String award_detail = "app/user/award_detail?page=0&per_page=100";
+    //游戏任务中的我的游戏
+    public static final String my_games = "app/game_consumption/my_games?page=1&per_page=100";
     //首页获取所有发布的热门任务(试玩任务、游戏任务、连续任务)
     public static final String release_task = "app/release_task?page=1&per_page=100&platform=1&is_hot=1&is_recommend=0&about_to_begin=0&task_type=-1&is_succession=3";
     public static String release_task(int type, String task_type, int is_succession){
@@ -50,6 +54,22 @@ public class ApiKey {
     public static String articles(int tag_id){
         return "app/find/articles/list?page=1&per_page=100&tag_id="+tag_id;
     }
+    //发现模块资讯
+    public static String articlesItem(int id){
+        return "app/find/articles?id="+id;
+    }
+    //发现模块游戏或应用详情
+    public static String applications(int id){
+        return "app/find/applications?id="+id;
+    }
+    //发现模块游戏或应用详情中的分数
+    public static String score_num(int id){
+        return "app/find/applications/score_num?id="+id;
+    }
+    //发现模块游戏或应用详情中我的评分
+    public static String my_score(int id){
+        return "app/find/applications/my_score?id="+id;
+    }
     //广告
     public static String advertisements(int type){
         return "app/advertising/advertisements?type="+type;

BIN
app/src/main/res/drawable-xxhdpi/splash_bg_img.webp


+ 84 - 75
app/src/main/res/layout/find_item.xml

@@ -1,99 +1,108 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:layout_marginEnd="@dimen/content_padding"
-    android:layout_marginStart="@dimen/content_padding"
-    android:background="@drawable/x_shap_shadow_bg_rectgangle_white"
-    android:orientation="vertical"
-    android:paddingTop="14dp"
-    android:paddingStart="@dimen/content_padding"
-    android:paddingEnd="@dimen/content_padding"
-    android:paddingBottom="15dp">
+    android:orientation="vertical">
+
     <View
         android:id="@+id/padding"
         android:layout_width="match_parent"
-        android:layout_height="@dimen/content_padding_10"/>
+        android:layout_height="@dimen/content_padding_10" />
+
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:gravity="center_vertical"
-        android:orientation="horizontal">
-
-        <TextView
-            android:id="@+id/find_item_name"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:text="@string/app_name"
-            android:textColor="@color/black_6_3"
-            android:textSize="15sp" />
+        android:layout_marginEnd="@dimen/content_padding"
+        android:layout_marginStart="@dimen/content_padding"
+        android:background="@drawable/x_shap_shadow_bg_rectgangle_white"
+        android:orientation="vertical"
+        android:paddingBottom="15dp"
+        android:paddingEnd="@dimen/content_padding"
+        android:paddingStart="@dimen/content_padding"
+        android:paddingTop="14dp">
 
-        <com.kfzs.android.view.tag.TagFlowLayout
-            android:id="@+id/find_item_tags"
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginStart="@dimen/dp_10" />
-    </LinearLayout>
-
-    <TextView
-        android:id="@+id/find_item_time"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="5dp"
-        android:text="@string/app_name"
-        android:textColor="#9B9B9B"
-        android:textSize="11sp" />
-
+            android:gravity="center_vertical"
+            android:orientation="horizontal">
 
-    <ImageView
-        android:id="@+id/find_item_iv"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/dp_10"
-        android:scaleType="fitXY"
-        android:adjustViewBounds="true"
-        android:src="@mipmap/icon" />
+            <TextView
+                android:id="@+id/find_item_name"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:text="@string/app_name"
+                android:textColor="@color/black_6_3"
+                android:textSize="15sp" />
 
-    <android.support.constraint.ConstraintLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="15dp">
+            <com.kfzs.android.view.tag.TagFlowLayout
+                android:id="@+id/find_item_tags"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="@dimen/dp_10" />
+        </LinearLayout>
 
         <TextView
-            android:id="@+id/find_item_des"
-            android:layout_width="0dp"
+            android:id="@+id/find_item_time"
+            android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            app:layout_constraintTop_toTopOf="parent"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintEnd_toStartOf="@+id/find_item_download"
-            android:maxLines="2"
-            android:ellipsize="end"
+            android:layout_marginTop="5dp"
             android:text="@string/app_name"
-            android:textColor="#646464"
-            android:textSize="14sp" />
-        <TextView
-            android:id="@+id/find_item_download"
-            style="@style/style_button_find"
-            android:layout_marginStart="5dp"
-            app:layout_constraintStart_toEndOf="@+id/find_item_des"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintTop_toTopOf="parent"
-            app:layout_constraintBottom_toBottomOf="parent"
-            android:text="下载游戏" />
+            android:textColor="#9B9B9B"
+            android:textSize="11sp" />
+
 
-<!--        <TextView
-            android:id="@+id/find_item_pf_label"
+        <ImageView
+            android:id="@+id/find_item_iv"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            app:layout_constraintTop_toBottomOf="@+id/find_item_des"
-            android:layout_marginTop="8dp"
-            android:text="评分:8.9"
-            android:textColor="#646464"
-            android:textSize="14sp" />-->
+            android:layout_marginTop="@dimen/dp_10"
+            android:adjustViewBounds="true"
+            android:scaleType="fitXY"
+            android:src="@mipmap/icon" />
 
-    </android.support.constraint.ConstraintLayout>
+        <android.support.constraint.ConstraintLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="15dp">
+
+            <TextView
+                android:id="@+id/find_item_des"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:ellipsize="end"
+                android:maxLines="2"
+                android:text="@string/app_name"
+                android:textColor="#646464"
+                android:textSize="14sp"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintEnd_toStartOf="@+id/find_item_download"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toTopOf="parent" />
+
+            <TextView
+                android:id="@+id/find_item_download"
+                style="@style/style_button_find"
+                android:layout_marginStart="5dp"
+                android:text="下载游戏"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toEndOf="@+id/find_item_des"
+                app:layout_constraintTop_toTopOf="parent" />
 
+            <!--        <TextView
+                        android:id="@+id/find_item_pf_label"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        app:layout_constraintTop_toBottomOf="@+id/find_item_des"
+                        android:layout_marginTop="8dp"
+                        android:text="评分:8.9"
+                        android:textColor="#646464"
+                        android:textSize="14sp" />-->
+
+        </android.support.constraint.ConstraintLayout>
+
+    </LinearLayout>
 </LinearLayout>