|
|
@@ -1,5 +1,6 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
@@ -14,15 +15,19 @@ import android.widget.LinearLayout;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.arialyy.aria.core.download.DownloadTask;
|
|
|
import com.kfzs.duanduan.utils.StatusBarUtils;
|
|
|
import com.kfzs.duanduan.view.DialogStorageLow;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
import com.sheep.gamegroup.event.BigEvent;
|
|
|
+import com.sheep.gamegroup.helper.DownloadHelper;
|
|
|
import com.sheep.gamegroup.model.entity.Container;
|
|
|
+import com.sheep.gamegroup.model.entity.FindApp;
|
|
|
import com.sheep.gamegroup.util.ActionUtil;
|
|
|
import com.sheep.gamegroup.util.ChannelContent;
|
|
|
import com.sheep.gamegroup.util.CommonUtil;
|
|
|
import com.sheep.gamegroup.util.DataUtil;
|
|
|
+import com.sheep.gamegroup.util.DownloadUtil;
|
|
|
import com.sheep.gamegroup.util.DrawablesHelper;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
@@ -37,13 +42,17 @@ import com.sheep.gamegroup.view.fragment.FgtSmallSheep;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
@@ -52,6 +61,10 @@ import rx.android.schedulers.AndroidSchedulers;
|
|
|
import rx.functions.Action1;
|
|
|
import rx.schedulers.Schedulers;
|
|
|
|
|
|
+import static android.content.Intent.ACTION_PACKAGE_ADDED;
|
|
|
+import static android.content.Intent.ACTION_PACKAGE_REMOVED;
|
|
|
+import static com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Created by realicing on 2018/9/6.
|
|
|
@@ -357,11 +370,26 @@ public class ActMain extends BaseActivity {
|
|
|
|
|
|
//包含更新进度的view的view(会长推广弹出框中有下载进度用到)
|
|
|
private View progressView;
|
|
|
+ private DownloadHelper downloadHelper;
|
|
|
+ private String packageName;
|
|
|
+ private String url;
|
|
|
+
|
|
|
+ public void setPackageName(String packageName) {
|
|
|
+ this.packageName = packageName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setUrl(String url) {
|
|
|
+ this.url = url;
|
|
|
+ }
|
|
|
|
|
|
public void setProgressView(View progressView) {
|
|
|
this.progressView = progressView;
|
|
|
}
|
|
|
|
|
|
+ public void setDownloadHelper(DownloadHelper downloadHelper) {
|
|
|
+ this.downloadHelper = downloadHelper;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 主要的事件广播接收更新处理
|
|
|
*
|
|
|
@@ -374,12 +402,71 @@ public class ActMain extends BaseActivity {
|
|
|
DialogStorageLow.showDialog(this);
|
|
|
break;
|
|
|
default:
|
|
|
- if(progressView != null)
|
|
|
- CommonUtil.getInstance().setEventResultViewStatus(event, progressView, false);
|
|
|
+ if(progressView != null) {
|
|
|
+ if (event.getData() instanceof DownloadTask) {
|
|
|
+ DownloadTask task = (DownloadTask) event.getData();
|
|
|
+ String url = task.getKey();
|
|
|
+ TextView tvProgress = progressView.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
|
|
|
+ if(tvProgress != null) {
|
|
|
+ switch (event.getEventTypes()) {
|
|
|
+ case GENERATION_ACCOUNT_REFRESH_ADAPTER:
|
|
|
+ try {
|
|
|
+ int p = task.getPercent(); //任务进度百分比
|
|
|
+ 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("安装游戏");
|
|
|
+ if(downloadHelper != null)
|
|
|
+ downloadHelper.updateState(DownloadUtil.STATUS_FINISH);
|
|
|
+ break;
|
|
|
+ case DOWNLOAD_CANCEL:
|
|
|
+ tvProgress.setText("下载取消");
|
|
|
+ break;
|
|
|
+ case DOWNLOAD_FAIL:
|
|
|
+ tvProgress.setText("下载失败");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Subscribe
|
|
|
+ public void onEventMainThread(Intent intent) {
|
|
|
+ if(intent != null && intent.getAction() != null && intent.getDataString() != null && intent.getDataString().contains("package:")){
|
|
|
+ String packageName = intent.getDataString().replace("package:","");
|
|
|
+
|
|
|
+ TextView tvProgress = progressView.findViewWithTag(PUBLIC_TAG_PREFIX_TEXTVIEW_LIST + url);
|
|
|
+ if(tvProgress != null && downloadHelper != null && TextUtils.equals(packageName, this.packageName)) {
|
|
|
+ switch (intent.getAction()){
|
|
|
+ case ACTION_PACKAGE_ADDED:
|
|
|
+ tvProgress.setText(CommonUtil.GAME_OPEN);
|
|
|
+ downloadHelper.updateState(DownloadUtil.STATUS_INSTALLED);
|
|
|
+ break;
|
|
|
+ case ACTION_PACKAGE_REMOVED:
|
|
|
+ String path = PackageUtil.isExistsFile(packageName, url);
|
|
|
+ if(TextUtils.isEmpty(path)) {
|
|
|
+ downloadHelper.updateState(DownloadUtil.STATUS_INIT);
|
|
|
+ tvProgress.setText(CommonUtil.START_DOWNLOAD);
|
|
|
+ } else {
|
|
|
+ downloadHelper.updateState(DownloadUtil.STATUS_FINISH);
|
|
|
+ tvProgress.setText(CommonUtil.START_INSTALL);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|