Sfoglia il codice sorgente

2.9.5 代码提交

liujiangyao 7 anni fa
parent
commit
c9901125b7

+ 4 - 1
app/src/main/java/com/kfzs/duanduan/event/EventTypes.java

@@ -32,10 +32,13 @@ public enum EventTypes {
     DELETE_GAME_ACCOUNT_REFRESH,//游戏删除账号,刷新界面
     GENERATION_ACCOUNT_REFRESH,//游戏代充,刷新界面
     GENERATION_ACCOUNT_REFRESH_ADAPTER,//游戏代充,刷新界面(下载)
+    DOWNLOAD_STOP,//下载暂停
+    DOWNLOAD_COMPLETE,//下载完成
+    DOWNLOAD_FAIL,//下载失败
+    DOWNLOAD_CANCEL,//下载取消
 
     //幂动科技
     REFRESH_MING_DONG,//刷新界面
 
     REFRESH_XIAOMI_GAME_LIST,//刷新界面
-    UPDATE_BTN_STATUS,//更新小米游戏按钮状态
 }

+ 1 - 19
app/src/main/java/com/kfzs/duanduan/fragment/FgtGameAgencyRecharge.java

@@ -220,26 +220,8 @@ public class FgtGameAgencyRecharge extends BaseCompatFragment {
             case GENERATION_ACCOUNT_REFRESH:
                 initData();
                 break;
-            case GENERATION_ACCOUNT_REFRESH_ADAPTER:
-                if(event.getData() instanceof DownloadTask){
-                    DownloadTask task = (DownloadTask) event.getData();
-                    try {
-                        int p = task.getPercent();    //任务进度百分比
-                        String speed = task.getConvertSpeed();    //转换单位后的下载速度,单位转换需要在配置文件中打开
-                        System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
-                        String url = task.getKey();
-                        TextView tvProgress = recyclerview.findViewWithTag(TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
-                        if (tvProgress == null) {
-                            return;
-                        }
-                        tvProgress.setText(String.format(Locale.CHINA, "%d%%",Math.abs(p)));
-
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-                break;
         }
+        CommonUtil.getInstance().setEventResultViewStatus(event, recyclerview);
     }
     @Override
     public void onDestroy() {

+ 14 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/DialogConfig.java

@@ -19,6 +19,7 @@ public class DialogConfig {
     private View.OnClickListener btnLeftOnClickListener;
     private String btnRightText;
     private View.OnClickListener btnRightOnClickListener;
+    private View.OnClickListener btnCloseOnClickListener;
     private String msgMore;
     private int msgMoreColor;//颜色资源
     private String tip;
@@ -100,6 +101,19 @@ public class DialogConfig {
         return this;
     }
 
+    public View.OnClickListener getBtnCloseOnClickListener() {
+        return btnCloseOnClickListener;
+    }
+
+    public DialogConfig setBtnCloseOnClickListener(View.OnClickListener btnCloseOnClickListener) {
+        this.btnCloseOnClickListener = btnCloseOnClickListener;
+        return this;
+    }
+
+    public void setColorMsgMap(Map<String, String> colorMsgMap) {
+        this.colorMsgMap = colorMsgMap;
+    }
+
     public View.OnClickListener getBtnRightOnClickListener() {
         return btnRightOnClickListener;
     }

+ 9 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/FindApp.java

@@ -50,6 +50,15 @@ public class FindApp implements IDownload {
 
     private int record;//1:可记录 其他:不可记录
     private int receive_account;//integer($int64)0:未领取账号 1:已领取账号
+    private int available_receive;//0:可领取账号 1:不可领取账号
+
+    public int getAvailable_receive() {
+        return available_receive;
+    }
+
+    public void setAvailable_receive(int available_receive) {
+        this.available_receive = available_receive;
+    }
 
     public int getReceive_account() {
         return receive_account;

+ 53 - 3
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -26,6 +26,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.alipay.sdk.app.PayTask;
 import com.arialyy.aria.core.Aria;
 import com.arialyy.aria.core.download.DownloadTarget;
+import com.arialyy.aria.core.download.DownloadTask;
 import com.arialyy.aria.core.inf.IEntity;
 import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
 import com.kfzs.duanduan.event.BigEvent;
@@ -88,6 +89,7 @@ import rx.functions.Action1;
 import rx.schedulers.Schedulers;
 
 import static com.sheep.gamegroup.util.UMConfigUtils.Event.XIAOMI_GAME_RECEIVE;
+import static com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST;
 
 /**
  * 一些公用的class
@@ -1538,8 +1540,10 @@ public class CommonUtil {
                             public void onNext(BaseMessage baseMessage) {
                                 G.showToast(baseMessage.getMsg());
                                 ViewUtil.newInstance().hideProgress(activity);
-                                String text = String.format(activity.getResources().getString(R.string.get_xiaomi_game_success_dialog),"小米账号","等带服务器开发");
                                 final JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(baseMessage.getData()));
+                                String text = String.format(activity.getResources().getString(R.string.get_xiaomi_game_success_dialog),
+                                        jsonObject1!= null?jsonObject1.getString("account"):"*****",
+                                        jsonObject1!= null?jsonObject1.getString("password"):"*****");
 
                                 ViewUtil.showMsgDialog(activity,
                                         text,
@@ -1556,8 +1560,8 @@ public class CommonUtil {
                                                     intent.setData(uri);
                                                     activity.sendBroadcast(intent); // 发送广播通知相册
                                                 } else {
-                                                    if(jsonObject1 != null)
-                                                        ViewUtil.sysSaveImage((View) v.getParent().getParent(), jsonObject1.getString("account")+"", jsonObject1.getString("password")+"");
+                                                    if (jsonObject1 != null)
+                                                        ViewUtil.sysSaveImage((View) v.getParent().getParent(), "小绵羊-小米", "小绵羊-小米账号");
                                                 }
                                                 G.showToast("已保存");
                                                 EventBus.getDefault().post(BigEvent.get().setEventTypes(EventTypes.REFRESH_XIAOMI_GAME_LIST));
@@ -1569,6 +1573,12 @@ public class CommonUtil {
 
                                                 EventBus.getDefault().post(BigEvent.get().setEventTypes(EventTypes.REFRESH_XIAOMI_GAME_LIST));
                                             }
+                                        },
+                                        new View.OnClickListener() {
+                                            @Override
+                                            public void onClick(View v) {
+                                                EventBus.getDefault().post(BigEvent.get().setEventTypes(EventTypes.REFRESH_XIAOMI_GAME_LIST));
+                                            }
                                         });
 
                             }
@@ -1576,4 +1586,44 @@ public class CommonUtil {
             }
         });
     }
+
+    /**
+     * 下载回调 状态修改
+     */
+    public void setEventResultViewStatus(BigEvent event, View view){
+        if(event.getData() instanceof DownloadTask){
+            DownloadTask task = (DownloadTask) event.getData();
+            String url = task.getKey();
+            TextView tvProgress = view.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
+            switch (event.getEventTypes()){
+                case GENERATION_ACCOUNT_REFRESH_ADAPTER:
+                    try {
+                        int p = task.getPercent();    //任务进度百分比
+                        String speed = task.getConvertSpeed();    //转换单位后的下载速度,单位转换需要在配置文件中打开
+                        System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
+                        if (tvProgress == null) {
+                            return;
+                        }
+                        tvProgress.setText(String.format(Locale.CHINA, "%d%%",Math.abs(p)));
+
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                    break;
+                case DOWNLOAD_STOP:
+                    tvProgress.setText("继续下载");
+                    break;
+                case DOWNLOAD_COMPLETE:
+                    tvProgress.setText("安装游戏");
+                    break;
+                case DOWNLOAD_CANCEL:
+                    tvProgress.setText("下载取消");
+                    break;
+                case DOWNLOAD_FAIL:
+                    tvProgress.setText("下载失败");
+                    break;
+            }
+        }
+
+    }
 }

+ 3 - 11
app/src/main/java/com/sheep/gamegroup/util/DeviceIDUtil.java

@@ -417,18 +417,10 @@ public class DeviceIDUtil {
 
         StringBuffer stringBuffer = new StringBuffer();
         if(wanWei > 0){
-            stringBuffer.append(wanWei+"万");
+            stringBuffer.append(wanWei+"万+");
+        }else {
+            stringBuffer.append(number % 10000 +"");
         }
-        if(qianWei > 0){
-            stringBuffer.append(qianWei+"千");
-        }
-        if(baiWei > 0){
-            stringBuffer.append(baiWei+"百");
-        }
-        if(shiWei > 0){
-            stringBuffer.append(shiWei+"十");
-        }
-        stringBuffer.append(geWei);
 
         return stringBuffer.toString();
     }

+ 11 - 2
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -303,8 +303,13 @@ public class ViewUtil {
     public static AlertDialog showMsgDialog(final Context context, String msg, String title) {
         return showMsgDialog(context, new DialogConfig().setMsg(msg).setTitle(title).setBtnLeftText("知道了"));
     }
-    public static AlertDialog showMsgDialog(final Context context, String msg, String title, String leftBtn, String rightBtn, View.OnClickListener onClickListener, View.OnClickListener onRightClickListener) {
-        return showMsgDialog(context, new DialogConfig().setMsg(msg).setTitle(title).setBtnLeftText(leftBtn).setBtnRightText(rightBtn).setBtnLeftOnClickListener(onClickListener).setBtnRightOnClickListener(onRightClickListener));
+    public static AlertDialog showMsgDialog(final Context context, String msg, String title, String leftBtn, String rightBtn,
+                                            View.OnClickListener onClickListener, View.OnClickListener onRightClickListener, View.OnClickListener onCloseClickListener) {
+        return showMsgDialog(context, new DialogConfig().setMsg(msg).setTitle(title).setBtnLeftText(leftBtn)
+                .setBtnRightText(rightBtn)
+                .setBtnLeftOnClickListener(onClickListener)
+                .setBtnRightOnClickListener(onRightClickListener)
+                .setBtnCloseOnClickListener(onCloseClickListener));
     }
     public static AlertDialog showMsgDialog(final Context context, String msg, String title,boolean isFinish) {
         return showMsgDialog(context, new DialogConfig().setMsg(msg).setTitle(title).setFinish(isFinish).setBtnLeftText("知道了"));
@@ -320,6 +325,7 @@ public class ViewUtil {
         final View.OnClickListener btnLeftOnClickListener = dialogConfig.getBtnLeftOnClickListener();
         String btnRightText = dialogConfig.getBtnRightText();
         final View.OnClickListener btnRightOnClickListener = dialogConfig.getBtnRightOnClickListener();
+        final View.OnClickListener btnCloseOnClickListener = dialogConfig.getBtnCloseOnClickListener();
         View dialog_parent = View.inflate(mContext, R.layout.dialog_parent, null);
         final AlertDialog dialog = new AlertDialog.Builder(mContext, mContext instanceof Activity ? R.style.MyDialogActivityTheme : R.style.AppTheme_Dialog_Alert).setView(dialog_parent).create();
         TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
@@ -417,6 +423,9 @@ public class ViewUtil {
                 dialog_close.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
+                        if(btnCloseOnClickListener != null){
+                            btnCloseOnClickListener.onClick(v);
+                        }
                         dialog.dismiss();
                     }
                 });

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

@@ -201,7 +201,7 @@ public class ActFindGame extends BaseActivity {
 
     @Override
     public void initData() {
-        FindApp findApp = DataUtil.getInstance().getCacheResult(ApiKey.applications(id), FindApp.class);
+        FindApp findApp = null;
         if(findApp != null){
             loadApp(findApp);
         } else {
@@ -528,7 +528,7 @@ public class ActFindGame extends BaseActivity {
 
     //更新按钮状态与添加点击事件
     private void updateView(Activity activity, FindApp findApp, TextView textView) {
-        if(findApp.getReceive_account() == 0){//未领取账号
+        if(findApp.getAvailable_receive() == 0 && findApp.getReceive_account() == 0){//未领取账号
 
             CommonUtil.getInstance()
                     .xiaomiRevieceAcctoun(find_game_down_tv, findApp, activity);

+ 10 - 28
app/src/main/java/com/sheep/gamegroup/view/activity/ActSearchGame.java

@@ -149,6 +149,7 @@ public class ActSearchGame extends BaseActivity {
                 TextView find_information_game_yuan = (TextView) itemView.findViewById(R.id.find_information_game_yuan);
                 TextView find_information_game_task_bottom = (TextView) itemView.findViewById(R.id.find_information_game_task_bottom);
                 TextView find_information_game_task_top = (TextView) itemView.findViewById(R.id.find_information_game_task_top);
+                TextView find_information_game_task_center = (TextView) itemView.findViewById(R.id.find_information_game_task_center);
 
                 if(item instanceof TaskReleaseEty){
                     final TaskReleaseEty  items = (TaskReleaseEty) item;
@@ -177,14 +178,16 @@ public class ActSearchGame extends BaseActivity {
                     ViewUtil.setText(find_information_game_name, items.getName());
                     ViewUtil.setText(find_information_game_surplus);
                     ViewUtil.setText(find_information_game_time, "");
-                    find_information_game_yuan.setVisibility(View.INVISIBLE);//这里必须为INVISIBLE,因为要显示两个按钮,下面的按钮位置不动
-                    find_information_game_task_top.setVisibility(View.VISIBLE);
-                    if(items.getReceive_account() == 0){//未领取账号
+                    find_information_game_yuan.setVisibility(View.GONE);//这里必须为INVISIBLE,因为要显示两个按钮,下面的按钮位置不动
+                    find_information_game_task_top.setVisibility(View.GONE);
+                    find_information_game_task_bottom.setVisibility(View.GONE);
+                    find_information_game_task_center.setVisibility(View.VISIBLE);
+                    if(items.getAvailable_receive() == 0 && items.getReceive_account() == 0){//未领取账号
                         CommonUtil.getInstance()
-                                .xiaomiRevieceAcctoun(find_information_game_task_top, items, activity);
+                                .xiaomiRevieceAcctoun(find_information_game_task_center, items, activity);
                     }else {
-                        items.getDownloadHelper().updateDownloadTaskView((Activity) activity, items, find_information_game_task_top);
-                        find_information_game_task_top.setTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + items.getDownload_url());
+                        items.getDownloadHelper().updateDownloadTaskView((Activity) activity, items, find_information_game_task_center);
+                        find_information_game_task_center.setTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + items.getDownload_url());
                     }
                 }
 
@@ -396,28 +399,7 @@ public class ActSearchGame extends BaseActivity {
 
     @Subscribe
     public void onEventMainThread(BigEvent event){
-        switch (event.getEventTypes()){
-
-            case GENERATION_ACCOUNT_REFRESH_ADAPTER:
-                if(event.getData() instanceof DownloadTask){
-                    DownloadTask task = (DownloadTask) event.getData();
-                    try {
-                        int p = task.getPercent();    //任务进度百分比
-                        String speed = task.getConvertSpeed();    //转换单位后的下载速度,单位转换需要在配置文件中打开
-                        System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
-                        String url = task.getKey();
-                        TextView tvProgress = search_game_list.findViewWithTag(TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
-                        if (tvProgress == null) {
-                            return;
-                        }
-                        tvProgress.setText(String.format(Locale.CHINA, "%d%%",Math.abs(p)));
-
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-                break;
-        }
+        CommonUtil.getInstance().setEventResultViewStatus(event, search_game_list);
     }
 
     @Override

+ 4 - 20
app/src/main/java/com/sheep/gamegroup/view/activity/ActXiaomiGame.java

@@ -160,7 +160,7 @@ public class ActXiaomiGame extends BaseActivity {
                 detail_task_tv_center.setTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + item.getDownload_url());
                 detail_task_tv_center.setVisibility(View.VISIBLE);
 
-                if(item.getReceive_account() == 0){//未领取账号
+                if(item.getAvailable_receive() == 0 && item.getReceive_account() == 0){//未领取账号
 
                     CommonUtil.getInstance()
                             .xiaomiRevieceAcctoun(detail_task_tv_center, item, activity);
@@ -245,6 +245,7 @@ public class ActXiaomiGame extends BaseActivity {
                         try {
                             if(baseMessage == null){
 
+                                CommonUtil.getInstance().updateEmptyView(empty_view, true);
                                 G.showToast("暂无游戏");
                             }else {
                                 List<XiaomiGameEntity> newList = baseMessage.getDatas(XiaomiGameEntity.class);
@@ -255,6 +256,7 @@ public class ActXiaomiGame extends BaseActivity {
                                 view_list.getAdapter().notifyDataSetChanged();
                             }
                         } catch (Exception e) {
+                            CommonUtil.getInstance().updateEmptyView(empty_view, true);
                             e.printStackTrace();
                         }
                     }
@@ -269,26 +271,8 @@ public class ActXiaomiGame extends BaseActivity {
             case REFRESH_XIAOMI_GAME_LIST:
                 initData();
                 break;
-            case UPDATE_BTN_STATUS:
-                if(event.getData() instanceof DownloadTask){
-                    DownloadTask task = (DownloadTask) event.getData();
-                    try {
-                        int p = task.getPercent();    //任务进度百分比
-                        String speed = task.getConvertSpeed();    //转换单位后的下载速度,单位转换需要在配置文件中打开
-                        System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
-                        String url = task.getKey();
-                        TextView tvProgress = view_list.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
-                        if (tvProgress == null) {
-                            return;
-                        }
-                        tvProgress.setText(String.format(Locale.CHINA, "%d%%",Math.abs(p)));
-
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-                break;
         }
+        CommonUtil.getInstance().setEventResultViewStatus(event, view_list);
     }
 
     @Override

+ 14 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/XiaomiGameEntity.java

@@ -1,5 +1,7 @@
 package com.sheep.gamegroup.view.activity;
 
+import android.text.TextUtils;
+
 import com.sheep.gamegroup.heler.DownloadHelper;
 import com.sheep.gamegroup.model.api.IDownload;
 
@@ -63,6 +65,16 @@ public class XiaomiGameEntity implements Serializable,IDownload {
 
     private String type;//类型
 
+    private int available_receive;//0:可领取账号 1:不可领取账号
+
+    public int getAvailable_receive() {
+        return available_receive;
+    }
+
+    public void setAvailable_receive(int available_receive) {
+        this.available_receive = available_receive;
+    }
+
     public void setPackage_sizes(String package_sizes) {
         this.package_size = package_sizes;
     }
@@ -165,7 +177,7 @@ public class XiaomiGameEntity implements Serializable,IDownload {
 
     @Override
     public String getPackage_size() {
-        return package_size;
+        return TextUtils.isEmpty(package_size)?"0":package_size;
     }
 
     public void setIcon(String icon) {
@@ -306,7 +318,7 @@ public class XiaomiGameEntity implements Serializable,IDownload {
     }
 
     public String getVersions() {
-        return versions;
+        return TextUtils.isEmpty(versions)?"0":versions;
     }
 
     public void setVersions(String versions) {

+ 4 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/service/DownloadService.java

@@ -47,12 +47,12 @@ public class DownloadService extends Service{
         LogUtil.println("DownloadService", "running", task.getKey(), task.getTaskName(), task.getPercent());
         mDownloadTaskService.setDownloadTaskPercent(task.getPercent(), task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d,0,task.getKey());
         EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.GENERATION_ACCOUNT_REFRESH_ADAPTER).setData(task));
-        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.UPDATE_BTN_STATUS).setData(task));
     }
 
     @Download.onTaskStop void taskStop(DownloadTask task) {
         LogUtil.println("DownloadService", "taskStop", task.getKey(), task.getTaskName());
         mDownloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadTaskService.STATUS_PAUSE);
+        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_STOP).setData(task));
     }
 
     @Download.onNoSupportBreakPoint void onNoSupportBreakPoint(DownloadTask task) {
@@ -61,11 +61,13 @@ public class DownloadService extends Service{
     @Download.onTaskCancel void taskCancel(DownloadTask task) {
         LogUtil.println("DownloadService", "taskCancel", task.getKey(), task.getTaskName());
         mDownloadTaskService.deleteDownloadTaskByDownloadUrl(task.getKey());
+        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_CANCEL).setData(task));
     }
 
     @Download.onTaskFail void taskFail(DownloadTask task) {
         LogUtil.println("DownloadService", "taskFail", task.getKey(), task.getTaskName());
         mDownloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadTaskService.STATUS_FAIL);
+        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(task));
         //空间不足,弹框提示
         try{
             if (0 <= task.getFileSize() && task.getFileSize() > HelperUtils.getFreeSpaceB()) {
@@ -80,6 +82,7 @@ public class DownloadService extends Service{
         LogUtil.println("DownloadService", "taskComplete", task.getKey(), task.getTaskName());
         mDownloadTaskService.setDownloadTaskFinish(task.getKey(), task.getDownloadPath());
         ApkUtils.installApk(getApplicationContext(), task.getDownloadPath());
+        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_COMPLETE).setData(task));
     }
     @Nullable
     @Override