|
|
@@ -10,6 +10,7 @@ import android.net.Uri;
|
|
|
import android.os.IBinder;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
|
|
|
import com.arialyy.annotations.Download;
|
|
|
@@ -19,7 +20,10 @@ import com.kfzs.duanduan.utils.ApkUtils;
|
|
|
import com.kfzs.duanduan.view.DialogStorageLow;
|
|
|
import com.sheep.gamegroup.event.BigEvent;
|
|
|
import com.sheep.gamegroup.event.EventTypes;
|
|
|
+import com.sheep.gamegroup.greendao.download.DownLoadInfo;
|
|
|
import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
+import com.sheep.gamegroup.model.entity.FindApp;
|
|
|
+import com.sheep.gamegroup.model.entity.PlayGameEntity;
|
|
|
import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
import com.sheep.gamegroup.util.ActivityManager;
|
|
|
import com.sheep.gamegroup.util.DataUtil;
|
|
|
@@ -32,9 +36,7 @@ import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.Locale;
|
|
|
-import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import rx.Observable;
|
|
|
@@ -51,13 +53,13 @@ import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
|
|
|
|
|
|
public class DownloadService extends Service {
|
|
|
|
|
|
- private DownloadUtil mDownloadTaskService;
|
|
|
+ private DownloadUtil downloadUtil;
|
|
|
|
|
|
@Override
|
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
|
Aria.download(this).register();
|
|
|
- mDownloadTaskService = new DownloadUtil(this);
|
|
|
+ downloadUtil = new DownloadUtil(this);
|
|
|
}
|
|
|
public static final String ON_PRE = "onPre";
|
|
|
public static final String RUNNING = "running";
|
|
|
@@ -76,9 +78,11 @@ public class DownloadService extends Service {
|
|
|
String taskStatus = DataUtil.getAsString(String.format(Locale.CHINA, "hasShow[%s]", task.getKey()), ON_PRE);
|
|
|
switch (taskStatus) {
|
|
|
case ON_PRE:
|
|
|
+ DownLoadInfo downloadInfo = downloadUtil.getDownloadTaskByUrl(task.getKey());
|
|
|
+ String taskName = downloadInfo != null ? downloadInfo.getMGameName() : task.getTaskName();
|
|
|
DataUtil.putAsString(String.format(Locale.CHINA, "hasShow[%s]", task.getKey()), HAS_SHOW);
|
|
|
ViewUtil.showMsgDialog(ActivityManager.getInstance().currentActivity(), new DialogConfig().setTitle("提示")
|
|
|
- .setMsg("任务【"+task.getTaskName()+"】下载无响应,是否使用其它下载方式(在列表中长按任务也可选择其它下载方式)").setBtnLeftText("取消").setBtnRightText("确定")
|
|
|
+ .setMsg("任务【"+taskName+"】下载无响应,是否使用其它下载方式(在任务列表中长按也可选择其它下载方式)").setBtnLeftText("取消").setBtnRightText("确定")
|
|
|
.setBtnRightOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
@@ -106,14 +110,14 @@ public class DownloadService extends Service {
|
|
|
protected void running(DownloadTask task) {
|
|
|
LogUtil.println("DownloadService", "running", task.getKey(), task.getTaskName(), task.getPercent());
|
|
|
DataUtil.putAsString(String.format(Locale.CHINA, "hasShow[%s]", task.getKey()), RUNNING);
|
|
|
- mDownloadTaskService.setDownloadTaskPercent(task.getPercent(), task.getCurrentProgress() / 1024d / 1024d, task.getFileSize() / 1024d / 1024d, 0, task.getKey());
|
|
|
+ downloadUtil.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));
|
|
|
}
|
|
|
|
|
|
@Download.onTaskStop
|
|
|
void taskStop(DownloadTask task) {
|
|
|
LogUtil.println("DownloadService", "taskStop", task.getKey(), task.getTaskName());
|
|
|
- mDownloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadUtil.STATUS_PAUSE);
|
|
|
+ downloadUtil.setDownloadTaskStatus(task.getKey(), DownloadUtil.STATUS_PAUSE);
|
|
|
EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_STOP).setData(task));
|
|
|
}
|
|
|
|
|
|
@@ -124,14 +128,14 @@ public class DownloadService extends Service {
|
|
|
@Download.onTaskCancel
|
|
|
void taskCancel(DownloadTask task) {
|
|
|
LogUtil.println("DownloadService", "taskCancel", task.getKey(), task.getTaskName());
|
|
|
- mDownloadTaskService.deleteDownloadTaskByDownloadUrl(task.getKey());
|
|
|
+ downloadUtil.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(), DownloadUtil.STATUS_FAIL);
|
|
|
+ downloadUtil.setDownloadTaskStatus(task.getKey(), DownloadUtil.STATUS_FAIL);
|
|
|
EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(task));
|
|
|
//空间不足,弹框提示
|
|
|
try {
|
|
|
@@ -146,7 +150,7 @@ public class DownloadService extends Service {
|
|
|
@Download.onTaskComplete
|
|
|
void taskComplete(DownloadTask task) {
|
|
|
LogUtil.println("DownloadService", "taskComplete", task.getKey(), task.getTaskName());
|
|
|
- mDownloadTaskService.setDownloadTaskFinish(task.getKey(), task.getDownloadPath());
|
|
|
+ downloadUtil.setDownloadTaskFinish(task.getKey(), task.getDownloadPath());
|
|
|
ApkUtils.installApk(getApplicationContext(), task.getDownloadPath());
|
|
|
EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_COMPLETE).setData(task));
|
|
|
}
|
|
|
@@ -166,6 +170,14 @@ public class DownloadService extends Service {
|
|
|
if(task != null && task.needDownloadApp())
|
|
|
setDownLoadLongClick(view, task.getDownload_link(), task.getTask_name());
|
|
|
}
|
|
|
+ public static void setDownLoadLongClick(View view, final FindApp task) {
|
|
|
+ if(task != null && !TextUtils.isEmpty(task.getDownload_link()))
|
|
|
+ setDownLoadLongClick(view, task.getDownload_link(), task.getTask_name());
|
|
|
+ }
|
|
|
+ public static void setDownLoadLongClick(View view, final PlayGameEntity task) {
|
|
|
+ if(task != null && task.isCanDownload())
|
|
|
+ setDownLoadLongClick(view, task.getDownload_link(), task.getTask_name());
|
|
|
+ }
|
|
|
|
|
|
public static void setDownLoadLongClick(View view, final String link, final String taskName) {
|
|
|
view.setOnLongClickListener(new View.OnLongClickListener() {
|