liujiangyao 8 роки тому
батько
коміт
6b77fa65eb

+ 4 - 2
app/build.gradle

@@ -130,7 +130,7 @@ dependencies {
     compile 'com.squareup.okhttp3:okhttp:3.10.0'
     compile 'org.greenrobot:eventbus:3.1.1'
     compile 'com.zhy:base-adapter:3.0.3'
-    compile 'com.liulishuo.filedownloader:library:1.6.9'
+//    compile 'com.liulishuo.filedownloader:library:1.6.9'
     compile 'com.tencent.bugly:crashreport_upgrade:1.3.4'
 
     //其中latest.release指代最新版本号,也可以指定明确的版本号,例如1.2.0
@@ -203,7 +203,7 @@ dependencies {
     compile 'com.flipboard:bottomsheet-commons:1.5.3'
     compile 'com.google.protobuf:protobuf-java:3.2.0'
     compile 'com.umeng.analytics:analytics:6.0.9'
-    compile(name: 'FileDownloader-1.0.0', ext: 'aar')
+//    compile(name: 'FileDownloader-1.0.0', ext: 'aar')
 
     //    compile files('libs/SocialSDK_QQ_Simplify.jar')
 
@@ -252,6 +252,8 @@ dependencies {
 //    compile 'com.google.zxing:core:3.3.0'
     compile project(':ucrop')
     compile project(':kfzslibrary')
+
+    compile 'com.mindorks.android:prdownloader:0.2.0'
 }
 def releaseTime() {
     return new Date().format("MMddHHmm", TimeZone.getTimeZone("UTC"))

+ 0 - 4
app/src/main/AndroidManifest.xml

@@ -310,10 +310,6 @@
             android:hardwareAccelerated="false"
             android:screenOrientation="portrait" />
 
-        <service
-            android:name="com.kfzs.duanduan.services.KFDownloadServices"
-            android:exported="false" />
-
         <provider
             android:name="com.kfzs.duanduan.data.graph.provider.KFZSProvider"
             android:authorities="com.kfzs.duanduan.data.graph.provider.${DUANDUAN_GRAPH}"

+ 22 - 57
app/src/main/java/com/kfzs/duanduan/ActDownloadMgr.java

@@ -5,6 +5,7 @@ import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ListView;
@@ -31,10 +32,6 @@ import com.sheep.jiuyan.samllsheep.R;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
-import org.wlf.filedownloader.DownloadFileInfo;
-import org.wlf.filedownloader.FileDownloader;
-import org.wlf.filedownloader.base.Log;
-import org.wlf.filedownloader.listener.OnDeleteDownloadFileListener;
 
 import java.io.File;
 import java.text.DecimalFormat;
@@ -209,7 +206,18 @@ public class ActDownloadMgr extends BaseCompatActivity {
 
             @Override
             public void downloadDelete(String downloadUrl) {
-
+                int iTempPosition = -1;
+                for (int position = 0; position < downloadTasks.size(); position++) {
+                    DownLoadInfo task = downloadTasks.get(position);
+                    if (downloadUrl.equals(task.getMDownloadUrl())) {
+                        iTempPosition = position;
+                        break;
+                    }
+                }
+                if (iTempPosition < 0) {
+                    return;
+                }
+                removeTask(iTempPosition);
             }
         }).setmTag(TAG).handlDownloadResult(info);
 
@@ -224,8 +232,8 @@ public class ActDownloadMgr extends BaseCompatActivity {
 
     //删除任务;
     private void downloadTaskItemEventDelete(DownLoadInfo downloadTask, int position) {
-        if (FileDownloader.getDownloadFile(downloadTask.getMDownloadUrl()) != null) {
-            FileDownloader.delete(downloadTask.getMDownloadUrl(), true, new DownloadTaskDeleteListener(position));
+        if (downloadTask.getMDownloadTaskId() != null) {
+            downloadTaskService.cancel(downloadTask);
         } else {
             if (!TextUtils.isEmpty(downloadTask.getMApkPath())) {
                 new File(downloadTask.getMApkPath()).delete();
@@ -284,65 +292,22 @@ public class ActDownloadMgr extends BaseCompatActivity {
         }
     }
 
-    private class DownloadTaskDeleteListener implements OnDeleteDownloadFileListener {
-
-        private int position;
-
-        public DownloadTaskDeleteListener(int itemPosition) {
-            this.position = itemPosition;
-        }
-
-        @Override
-        public void onDeleteDownloadFilePrepared(DownloadFileInfo downloadFileInfo) {
-        }
-
-        @Override
-        public void onDeleteDownloadFileSuccess(DownloadFileInfo downloadFileInfo) {
-            removeTask(position);
-        }
-
-        @Override
-        public void onDeleteDownloadFileFailed(DownloadFileInfo downloadFileInfo, DeleteDownloadFileFailReason deleteDownloadFileFailReason) {
-
-        }
-    }
-
-
     private void restartTaskByDownloadUrl(final DownLoadInfo task) {
-        FileDownloader.delete(task.getMDownloadUrl(), true, new OnDeleteDownloadFileListener() {
-
-            @Override
-            public void onDeleteDownloadFilePrepared(DownloadFileInfo downloadFileInfo) {
-            }
-
-            @Override
-            public void onDeleteDownloadFileSuccess(DownloadFileInfo downloadFileInfo) {
-                Log.d(TAG, "restartTaskByDownloadUrl#onDeleteDownloadFileSuccess");
-                // Clear old data
-                downloadTaskService.deleteDownloadTaskByDownloadUrl(task.getMDownloadUrl());
-                downloadTaskService.addDownloadTask(task);
-
-                setDownloadTaskData();
-                FileDownloader.start(task.getMDownloadUrl());
-            }
-
-            @Override
-            public void onDeleteDownloadFileFailed(DownloadFileInfo downloadFileInfo, DeleteDownloadFileFailReason deleteDownloadFileFailReason) {
-
-                Log.d(TAG, "restartTaskByDownloadUrl#onDeleteDownloadFileFailed");
-            }
-        });
-
+        downloadTaskService.cancel(task);
+        downloadTaskService.deleteDownloadTaskByDownloadUrl(task.getMDownloadUrl());
+        downloadTaskService.start(task);//重新下载
+        setDownloadTaskData();
     }
 
     private void changeTaskPersistenceStatus(String downloadUrl, int status, int percent, boolean bPauseTask) {
         boolean isUpdate = downloadTaskService.setDownloadTaskStatus(downloadUrl, status);
+        DownLoadInfo downLoadInfo = downloadTaskService.getDownloadTaskByUrl(downloadUrl);
         if (isUpdate) {
             setDownloadTaskData();
             if (bPauseTask) {
-                FileDownloader.pause(downloadUrl);
+                downloadTaskService.pause(downLoadInfo);
             } else {
-                FileDownloader.start(downloadUrl);
+                downloadTaskService.start(downLoadInfo);
 
             }
             postDownloadTaskEvents(downloadUrl, status, percent);

+ 6 - 36
app/src/main/java/com/kfzs/duanduan/ActMain.java

@@ -1,50 +1,30 @@
 package com.kfzs.duanduan;
 
 import android.Manifest;
-import android.app.Activity;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.graphics.BitmapFactory;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
 import android.support.v4.app.ActivityCompat;
 import android.support.v4.content.ContextCompat;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
-import android.view.animation.Animation;
-import android.view.animation.TranslateAnimation;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
 import android.widget.Toast;
 
-import com.android.volleyplus.Response;
-import com.google.gson.Gson;
-import com.kf.utils.ToastBuilder;
 import com.kfzs.appstore.utils.restful.KFZSNetwork;
-import com.kfzs.duanduan.bean.GiftItem;
 import com.kfzs.duanduan.bean.KFIntentKeys;
 import com.kfzs.duanduan.bll.UrlBll;
-import com.kfzs.duanduan.data.graph.KFZSUserHelper;
-import com.kfzs.duanduan.data.graph.provider.user.UserBean;
-import com.kfzs.duanduan.datashare.DDProviderHelper;
-import com.kfzs.duanduan.datashare.KFZSDDContentSession;
 import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
-import com.kfzs.duanduan.datashare.provider.session.SessionBean;
 import com.kfzs.duanduan.db.DataSave;
-import com.kfzs.duanduan.db.UserGraphUtils;
 import com.kfzs.duanduan.event.BigEvent;
 import com.kfzs.duanduan.event.EventTypes;
 import com.kfzs.duanduan.proto.ApiResponseOuterClass;
 import com.kfzs.duanduan.proto.GameOuterClass;
 import com.kfzs.duanduan.proto.RecommendedGameOuterClass;
-import com.kfzs.duanduan.proto.ShelvesGiftOuterClass;
-import com.kfzs.duanduan.proto.UserOuterClass;
-import com.kfzs.duanduan.react.MainTab;
 import com.kfzs.duanduan.react.TabsHelper;
 import com.kfzs.duanduan.services.DownloadTaskService;
 import com.kfzs.duanduan.utils.dlg.HelperUtils;
@@ -54,26 +34,15 @@ import com.kfzs.duanduan.utils.net.APIRequestInstance;
 import com.kfzs.duanduan.utils.net.ResponseNetworkTask;
 import com.kfzs.duanduan.view.AppHomepageAdvertisementDialog;
 import com.kfzs.duanduan.view.DialogStorageLow;
-import com.sheep.gamegroup.event.MoneyChange;
-import com.sheep.gamegroup.event.UserNameChange;
-import com.sheep.gamegroup.model.entity.UserInfoEntity;
 import com.sheep.gamegroup.util.UMConfigUtils;
-import com.sheep.gamegroup.view.dialog.DialogAccountAbnormal;
-import com.sheep.jiuyan.samllsheep.BuildConfig;
 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.SpUtils;
-import com.umeng.analytics.MobclickAgent;
 import com.zhy.http.okhttp.OkHttpUtils;
 import com.zhy.http.okhttp.callback.StringCallback;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
-import org.greenrobot.eventbus.ThreadMode;
 import org.json.JSONException;
 import org.json.JSONObject;
-import org.wlf.filedownloader.FileDownloader;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -330,9 +299,9 @@ public class ActMain extends BaseCompatActivity{
                                                         Toast.makeText(ActMain.this, "获取" + DataSave.getInstance().getChannelName() + "渠道下载地址失败", Toast.LENGTH_SHORT).show();
                                                     else {
                                                         KFZSApp.getInstance().mRealDownloadUrl.put(realUrl, downloadUrl);
-                                                        FileDownloader.start(realUrl);
-                                                        addNewDownloadTask(game.getGameName(), realUrl, game.getPackageName(),
+                                                        DownLoadInfo downloadInfo = addNewDownloadTask(game.getGameName(), realUrl, game.getPackageName(),
                                                                 Integer.parseInt(game.getVersionCode()), game.getIconImage(), game.getSize(), game.getId());
+                                                        mDownloadTaskService.start(downloadInfo);
                                                         EventBus.getDefault().post(BigEvent.get()
                                                                 .setEventTypes(EventTypes.TIPS_DOWN_ICON));
                                                     }
@@ -350,8 +319,7 @@ public class ActMain extends BaseCompatActivity{
 //                                        DialogAccountAbnormal.showDialog((Activity) ActMain.this,null, "当前网络处于非WIFI状态,确定下载吗?", "取消", "确定" );
 //                                        return;
 //                                    }
-                                    FileDownloader.start(downloadUrl);
-                                    addNewDownloadTask(game.getGameName(),
+                                    DownLoadInfo downloadInfo = addNewDownloadTask(game.getGameName(),
                                             downloadUrl,
                                             game.getPackageName(),
                                             Integer.parseInt(game.getVersionCode()),
@@ -359,6 +327,7 @@ public class ActMain extends BaseCompatActivity{
                                             game.getSize(),
                                             game.getId());
 
+                                    mDownloadTaskService.start(downloadInfo);
                                     EventBus.getDefault().post(BigEvent.get()
                                             .setEventTypes(EventTypes.TIPS_DOWN_ICON));
                                 }
@@ -382,7 +351,7 @@ public class ActMain extends BaseCompatActivity{
         }
     }
 
-    private void addNewDownloadTask(String gameName, String downloadUrl, String packageName,
+    private DownLoadInfo addNewDownloadTask(String gameName, String downloadUrl, String packageName,
                                     int versionCode, String iconUrl, String size, Integer gameId) {
 
         DownLoadInfo task = new DownLoadInfo();
@@ -394,6 +363,7 @@ public class ActMain extends BaseCompatActivity{
         task.setMTotalSize(Double.valueOf(size));
         task.setMGameID(gameId);
         mDownloadTaskService.addDownloadTask(task);
+        return task;
     }
 
 

+ 6 - 49
app/src/main/java/com/kfzs/duanduan/KFZSApp.java

@@ -5,22 +5,18 @@ import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.os.Build;
 import android.os.Environment;
-import android.support.multidex.MultiDex;
 import android.support.multidex.MultiDexApplication;
 import android.util.DisplayMetrics;
 import android.util.Log;
 
+import com.downloader.PRDownloader;
 import com.kfzs.appstore.utils.restful.KFZSNetwork;
 import com.kfzs.duanduan.db.DataSave;
-import com.kfzs.duanduan.services.KFDownloadServices;
 import com.kfzs.duanduan.utils.ApkUtils;
 import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 import com.sheep.jiuyan.samllsheep.utils.G;
-import com.umeng.analytics.MobclickAgent;
 
-import org.wlf.filedownloader.FileDownloadConfiguration;
-import org.wlf.filedownloader.FileDownloader;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -28,8 +24,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
-
 
 /**
  * <pre>
@@ -48,7 +42,7 @@ import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
  * </pre>
  * Created by sinlov on 17/2/10.
  */
-public class KFZSApp extends MultiDexApplication{
+public class KFZSApp extends MultiDexApplication {
 
     public static final boolean DEBUG = BuildConfig.KF_DEBUG;
 
@@ -71,6 +65,7 @@ public class KFZSApp extends MultiDexApplication{
     private Map<String, PackageInfo> installedApkContainer;
     public static final int MAX_DOWNLOAD_TASK_SIZE = 5;
     public HashMap<String, String> mRealDownloadUrl;
+
     @Override
     public void onCreate() {
         super.onCreate();
@@ -86,8 +81,8 @@ public class KFZSApp extends MultiDexApplication{
         KFZSNetwork.init(application);
         DisplayMetrics metric = getResources().getDisplayMetrics();
         G.DENSITY = metric.density;
-        G.HEIGHT=metric.heightPixels;
-        G.WIDTH=metric.widthPixels;
+        G.HEIGHT = metric.heightPixels;
+        G.WIDTH = metric.widthPixels;
 
         DataSave dataSave = DataSave.getInstance();
         String umengKey = dataSave.getUmengKey();
@@ -150,7 +145,6 @@ public class KFZSApp extends MultiDexApplication{
                 appCompatActivity.finish();
             }
 
-            stopDownloadService();
             killAppProcess();
         } catch (Exception e) {
             Log.e(TAG, "quit error" + e.getMessage() + "\n" + e.getCause());
@@ -222,31 +216,9 @@ public class KFZSApp extends MultiDexApplication{
     // init FileDownloader
     private void initFileDownloader() {
         ClassFileHelper.getInstance().createSDDirection();
-        String path_download = ClassFileHelper.DIR;
-        // 1.create FileDownloadConfiguration.Builder
-        FileDownloadConfiguration.Builder builder = new FileDownloadConfiguration.Builder(this);
-
-        // 2.config FileDownloadConfiguration.Builder
-        builder.configFileDownloadDir(path_download);
-
-        // allow 3 download tasks at the same time
-        builder.configDownloadTaskSize(MAX_DOWNLOAD_TASK_SIZE);
-
-
-        // config retry download times when failed
-        builder.configRetryDownloadTimes(5);
-
-        // enable debug mode
-        //builder.configDebugMode(true);
 
-        // config connect timeout
-        builder.configConnectTimeout(25000); // 25s
+        PRDownloader.initialize(getApplicationContext());
 
-        // 3.init FileDownloader with the configuration
-        FileDownloadConfiguration configuration = builder.build(); // build FileDownloadConfiguration with the builder
-        FileDownloader.init(configuration);
-
-        startDownloadService();
     }
 
 
@@ -265,25 +237,10 @@ public class KFZSApp extends MultiDexApplication{
     }
 
 
-    private void startDownloadService() {
-        Intent downloadService = new Intent(this, KFDownloadServices.class);
-        startService(downloadService);
-    }
-
-    private void stopDownloadService() {
-
-        Log.d(TAG, "stopDownloadService");
-        Intent downloadService = new Intent(this, KFDownloadServices.class);
-        stopService(downloadService);
-    }
-
-
     @Override
     public void onTerminate() {
         super.onTerminate();
         Log.d(TAG, "onTerminate");
-        FileDownloader.release();
-        stopDownloadService();
     }
 
 }

+ 3 - 24
app/src/main/java/com/kfzs/duanduan/oem/AppAddOrdelReceiver.java

@@ -6,15 +6,16 @@ import android.content.Intent;
 import android.os.Handler;
 import android.os.Looper;
 
+import com.alibaba.fastjson.JSONObject;
 import com.kfzs.duanduan.datashare.DDProviderHelper;
 import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
 import com.sheep.gamegroup.model.api.BaseMessageConverter;
 import com.sheep.gamegroup.util.ConnectAddress;
 import com.sheep.gamegroup.util.DeviceUtil;
+import com.sheep.gamegroup.util.NetUtil;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 
-import org.json.JSONObject;
 
 import java.io.IOException;
 
@@ -42,7 +43,6 @@ public class AppAddOrdelReceiver extends BroadcastReceiver {
                     @Override
                     public void run() {
                         String packages = intent.getDataString().replace("package:","");
-
                         String packageName = intent.getPackage();
                         final DownLoadInfo downLoadInfo = DDProviderHelper.getInstance()
                                 .getDownloadTaskToPackname(context, packages);
@@ -54,32 +54,11 @@ public class AppAddOrdelReceiver extends BroadcastReceiver {
                             public void run() {
                                 super.run();
                                 try {
-                                    OkHttpClient client = new OkHttpClient();
                                     JSONObject jsonObject = new JSONObject();
                                     jsonObject.put("device_id",DeviceUtil.getDeviceId(SheepApp.mContext)+"");
                                     jsonObject.put("id",downLoadInfo.getMGameID());
-                                    //加密--RequestBody.create(MediaType.parse("org/json; charset=utf-8"), jsonObject.toString())
-                                    String newJsonParams = BaseMessageConverter.encrypt(jsonObject.toString());
-
-
-                                    Request request = new Request.Builder()
-                                            .url(ConnectAddress.APP_URL+"/v1/app/accepted_task/download_task_notify/")
-                                            .addHeader("Authorization", SpUtils.getOpenId(SheepApp.mContext)+"")
-                                            .addHeader("X-Device-Id", DeviceUtil.getDeviceId(SheepApp.mContext)+"")
-                                            .put(RequestBody.create(MediaType.parse("org/json; charset=utf-8"), newJsonParams))
-                                            .build();
-                                    client.newCall(request)
-                                            .enqueue(new Callback() {
-                                                @Override
-                                                public void onFailure(Call call, IOException e) {
-
-                                                }
-
-                                                @Override
-                                                public void onResponse(Call call, Response response) throws IOException {
+                                    NetUtil.getNetUtil().sendAppDownload(context, jsonObject);
 
-                                                }
-                                            });
                                 } catch (Exception e) {
                                     e.printStackTrace();
                                 }

+ 104 - 0
app/src/main/java/com/kfzs/duanduan/services/DownloadTaskService.java

@@ -2,10 +2,25 @@ package com.kfzs.duanduan.services;
 
 import android.content.Context;
 
+import com.downloader.Error;
+import com.downloader.OnCancelListener;
+import com.downloader.OnDownloadListener;
+import com.downloader.OnPauseListener;
+import com.downloader.OnProgressListener;
+import com.downloader.OnStartOrResumeListener;
+import com.downloader.PRDownloader;
+import com.downloader.Progress;
+import com.downloader.Status;
+import com.downloader.request.DownloadRequest;
+import com.kfzs.duanduan.bean.DownloadStatus;
 import com.kfzs.duanduan.datashare.DDProviderHelper;
 import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
+import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 
 
+import org.greenrobot.eventbus.EventBus;
+
+import java.text.DecimalFormat;
 import java.util.List;
 
 /**
@@ -310,4 +325,93 @@ public class DownloadTaskService {
     }
 
 
+    private double getRandomFakeDownloadSize() {
+        DecimalFormat df = new DecimalFormat("######0.0");
+        double a = (Math.random() * 1);
+        return Double.valueOf(df.format(a));
+    }
+
+    public void start(DownLoadInfo downLoadInfo) {
+        if(downLoadInfo.getMDownloadTaskId() != null){
+            PRDownloader.resume(downLoadInfo.getMDownloadTaskId());
+            return;
+        }
+        final DownloadStatus statusInfo = new DownloadStatus();
+        statusInfo.setFileDownloadedSize( downLoadInfo.getMDownloadedSize() == null ? getRandomFakeDownloadSize() : downLoadInfo.getMDownloadedSize());
+        statusInfo.setFileTotalSize( downLoadInfo.getMTotalSize() == null ? 0 : downLoadInfo.getMTotalSize() / 1024f / 1024);
+        statusInfo.setDownloadUrl(downLoadInfo.getMDownloadUrl());
+        statusInfo.setDownloadPgrs(downLoadInfo.getMPercent() == null ? 0 : downLoadInfo.getMPercent());
+        statusInfo.setApkPath(downLoadInfo.getMApkPath());
+        statusInfo.setGameId(downLoadInfo.getMGameID());
+        DownloadRequest downloadRequest = PRDownloader.download(downLoadInfo.getMDownloadUrl(), ClassFileHelper.DIR, downLoadInfo.getMGameName() + ClassFileHelper.FILE_SUFFIX)
+                .build()
+                .setOnStartOrResumeListener(new OnStartOrResumeListener() {
+                    @Override
+                    public void onStartOrResume() {
+                        statusInfo.setStatus(DownloadTaskService.STATUS_INIT);
+                        EventBus.getDefault().post(statusInfo);
+                    }
+                })
+                .setOnPauseListener(new OnPauseListener() {
+                    @Override
+                    public void onPause() {
+                        statusInfo.setStatus(DownloadTaskService.STATUS_PAUSE);
+                        EventBus.getDefault().post(statusInfo);
+                    }
+                })
+                .setOnCancelListener(new OnCancelListener() {
+                    @Override
+                    public void onCancel() {
+                        statusInfo.setStatus(DownloadTaskService.STATUS_DELETE);
+                        EventBus.getDefault().post(statusInfo);
+                    }
+                })
+                .setOnProgressListener(new OnProgressListener() {
+                    private long time = System.currentTimeMillis();
+                    private long ftime = time;
+
+                    @Override
+                    public void onProgress(Progress progress) {
+                        long currentTimeMillis = System.currentTimeMillis();
+
+                        statusInfo.setStatus(DownloadTaskService.STATUS_ING);
+                        statusInfo.setFileDownloadedSize( progress.currentBytes / 1024f / 1024);
+                        statusInfo.setFileTotalSize( progress.totalBytes / 1024f / 1024);
+                        statusInfo.setDownloadPgrs((int) (progress.currentBytes * 100f / progress.totalBytes));
+                        statusInfo.setDownloadSpeed(progress.currentBytes * 1000f / 1024 / 1024 / (currentTimeMillis - ftime));
+
+                        if (currentTimeMillis - time > 1000 || progress.currentBytes == progress.totalBytes) {
+                            float totalTime = (currentTimeMillis - ftime) / 1000.0f;
+                            System.out.println((progress.currentBytes / 1024 / 1024 / totalTime) + " progress = " + progress.currentBytes + ",total = " + progress.totalBytes);
+                            time = currentTimeMillis;
+                            EventBus.getDefault().post(statusInfo);
+                        }
+                    }
+                });
+        downloadRequest.setTag(downLoadInfo.getMDownloadUrl());
+        statusInfo.setDownloadId(downloadRequest.start(new OnDownloadListener() {
+                    @Override
+                    public void onDownloadComplete() {
+                        statusInfo.setStatus(DownloadTaskService.STATUS_FINISH);
+                        EventBus.getDefault().post(statusInfo);
+                    }
+
+                    @Override
+                    public void onError(Error error) {
+                        statusInfo.setStatus(DownloadTaskService.STATUS_FAIL);
+                        statusInfo.setMessage(error.toString());
+                        EventBus.getDefault().post(statusInfo);
+                    }
+                }));
+    }
+
+    public void pause(DownLoadInfo downLoadInfo) {
+        if(downLoadInfo.getMDownloadTaskId() != null)
+            PRDownloader.pause(downLoadInfo.getMDownloadTaskId());
+    }
+    public void cancel(DownLoadInfo downLoadInfo) {
+        if(downLoadInfo.getMDownloadTaskId() != null)
+            PRDownloader.cancel((int)downLoadInfo.getMDownloadTaskId());
+    }
+
 }

+ 203 - 209
app/src/main/java/com/kfzs/duanduan/services/KFDownloadServices.java

@@ -1,209 +1,203 @@
-package com.kfzs.duanduan.services;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-import android.support.annotation.Nullable;
-import android.util.Log;
-
-import com.kfzs.duanduan.KFZSApp;
-import com.kfzs.duanduan.bean.DownloadStatus;
-import com.kfzs.duanduan.datashare.DDProviderHelper;
-import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
-
-import org.greenrobot.eventbus.EventBus;
-import org.wlf.filedownloader.DownloadFileInfo;
-import org.wlf.filedownloader.FileDownloader;
-import org.wlf.filedownloader.listener.OnRetryableFileDownloadStatusListener;
-
-import java.text.DecimalFormat;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * The appstore download service
- * Created by HooRang on 2017/2/20.
- */
-public class KFDownloadServices extends Service implements OnRetryableFileDownloadStatusListener {
-
-    private static final String TAG = KFDownloadServices.class.getSimpleName();
-
-    private static double FAKE_DOWNLOADED_SIZE = 0.5;
-
-
-    DownloadTaskService downloadTaskService;
-    private DownloadStatus statusInfo;
-    private Map<String, String> urlAndPackageNameMap = new HashMap<>();
-
-    @Override
-    public void onCreate() {
-        super.onCreate();
-
-        FileDownloader.registerDownloadStatusListener(this);
-        downloadTaskService = new DownloadTaskService(this);
-        //        FileDownloader.continueAll(true);
-    }
-
-    @Nullable
-    @Override
-    public IBinder onBind(Intent intent) {
-        Log.i(TAG, "onBind");
-        return null;
-
-
-    }
-
-
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-
-        Log.i(TAG, "onDestroy");
-        FileDownloader.pauseAll();
-        FileDownloader.unregisterDownloadStatusListener(this);
-
-    }
-
-
-    // 正在重试下载(如果你配置了重试次数,当一旦下载失败时会尝试重试下载),retryTimes是当前第几次重试
-    @Override
-    public void onFileDownloadStatusRetrying(DownloadFileInfo downloadFileInfo, int retryTimes) {
-        Log.i(TAG, "onFileDownloadStatusRetrying");
-    }
-
-
-    // 等待下载(等待其它任务执行完成,或者FileDownloader在忙别的操作)
-    @Override
-    public void onFileDownloadStatusWaiting(DownloadFileInfo downloadFileInfo) {
-        Log.i(TAG, "onFileDownloadStatusWaiting");
-    }
-
-
-    // 准备中(即,正在连接资源)
-    @Override
-    public void onFileDownloadStatusPreparing(DownloadFileInfo downloadFileInfo) {
-        Log.i(TAG, "onFileDownloadStatusPreparing");
-        statusInfo = new DownloadStatus();
-
-        // Send a fucking fake download event to update user interface
-        FAKE_DOWNLOADED_SIZE = getRandomFakeDownloadSize();
-        DownLoadInfo task = downloadTaskService.getDownloadTaskByUrl(downloadFileInfo.getUrl());
-        if (task != null) {
-            FAKE_DOWNLOADED_SIZE = task.getMDownloadedSize() == null ? FAKE_DOWNLOADED_SIZE : task.getMDownloadedSize();
-            statusInfo.setDownloadPgrs(task.getMPercent() == null ? 1 : task.getMPercent());
-        } else {
-            statusInfo.setDownloadPgrs(1);
-        }
-
-        double fileSize = downloadFileInfo.getFileSizeLong() / 1024f / 1024;
-        statusInfo.setStatus(DownloadTaskService.STATUS_ING);
-        statusInfo.setFileTotalSize(fileSize);
-        statusInfo.setFileDownloadedSize(FAKE_DOWNLOADED_SIZE);
-        statusInfo.setDownloadId(downloadFileInfo.getId());
-        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
-        EventBus.getDefault().post(statusInfo);
-    }
-
-    private String getPackageNameFromMapOrDb(String url) {
-        String packageName;
-        if (urlAndPackageNameMap.containsKey(url))
-            packageName = urlAndPackageNameMap.get(url);
-        else {
-            packageName = DDProviderHelper.getInstance().getDownloadTask(KFZSApp.getInstance(), url).getMPackageName();
-            urlAndPackageNameMap.put(url,packageName);
-        }
-        return packageName;
-    }
-
-    // 已准备好(即,已经连接到了资源)
-    @Override
-    public void onFileDownloadStatusPrepared(DownloadFileInfo downloadFileInfo) {
-        Log.i(TAG, "onFileDownloadStatusPrepared");
-    }
-
-    //正在下载,downloadSpeed为当前下载速度,单位KB/s,remainingTime为预估的剩余时间,单位秒
-    @Override
-    public void onFileDownloadStatusDownloading(DownloadFileInfo downloadFileInfo,
-                                                float downloadSpeed, long remainingTime) {
-        Log.i(TAG, "onFileDownloadStatusDownloading");
-        double downloadSize = downloadFileInfo.getDownloadedSizeLong() / 1024f / 1024;
-        if (downloadSize < FAKE_DOWNLOADED_SIZE) {
-            return;
-        }
-        double fileSize = downloadFileInfo.getFileSizeLong() / 1024f / 1024;
-        Double percent = downloadSize / fileSize * 100;
-        if(statusInfo == null){
-            return;
-        }
-        statusInfo.setStatus(DownloadTaskService.STATUS_ING);
-        statusInfo.setDownloadPgrs(percent.intValue());
-        statusInfo.setFileTotalSize(fileSize);
-        statusInfo.setFileDownloadedSize(downloadSize);
-        statusInfo.setDownloadId(downloadFileInfo.getId());
-        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
-        statusInfo.setDownloadSpeed(downloadSpeed);
-        EventBus.getDefault().post(statusInfo);
-    }
-
-    // 下载已被暂停
-    @Override
-    public void onFileDownloadStatusPaused(DownloadFileInfo downloadFileInfo) {
-        Log.i(TAG, "onFileDownloadStatusPaused");
-        if (null == statusInfo) {
-            statusInfo = new DownloadStatus();
-        }
-        double downloadSize = downloadFileInfo.getDownloadedSizeLong() / 1024f / 1024;
-        if (downloadSize < FAKE_DOWNLOADED_SIZE) {
-            return;
-        }
-        double fileSize = downloadFileInfo.getFileSizeLong() / 1024f / 1024;
-        Double percent = downloadSize / fileSize * 100;
-
-        if(statusInfo == null){
-            return;
-        }
-        statusInfo.setStatus(DownloadTaskService.STATUS_PAUSE);
-        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
-        statusInfo.setDownloadPgrs(percent.intValue());
-        statusInfo.setFileTotalSize(fileSize);
-        statusInfo.setFileDownloadedSize(downloadSize);
-        statusInfo.setDownloadId(downloadFileInfo.getId());
-        EventBus.getDefault().post(statusInfo);
-    }
-
-    // 下载完成(整个文件已经全部下载完成)
-    @Override
-    public void onFileDownloadStatusCompleted(DownloadFileInfo downloadFileInfo) {
-        Log.i(TAG, "onFileDownloadStatusCompleted");
-        if (null == statusInfo) {
-            statusInfo = new DownloadStatus();
-        }
-        statusInfo.setStatus(DownloadTaskService.STATUS_FINISH);
-        statusInfo.setApkPath(downloadFileInfo.getFilePath());
-        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
-        EventBus.getDefault().post(statusInfo);
-    }
-
-
-    // 下载失败了,详细查看失败原因failReason
-    @Override
-    public void onFileDownloadStatusFailed(String url, DownloadFileInfo downloadFileInfo, FileDownloadStatusFailReason failReason) {
-        Log.i(TAG, "onFileDownloadStatusFailed");
-        if (null == statusInfo) {
-            statusInfo = new DownloadStatus();
-        }
-        statusInfo.setStatus(DownloadTaskService.STATUS_FAIL);
-        statusInfo.setDownloadUrl(url);
-        statusInfo.setMessage(failReason.getMessage());
-        EventBus.getDefault().post(statusInfo);
-    }
-
-
-    private double getRandomFakeDownloadSize() {
-        DecimalFormat df = new DecimalFormat("######0.0");
-        double a = (Math.random() * 1);
-        return Double.valueOf(df.format(a));
-    }
-
-
-}
+//package com.kfzs.duanduan.services;
+//
+//import android.app.Service;
+//import android.content.Intent;
+//import android.os.IBinder;
+//import android.support.annotation.Nullable;
+//import android.util.Log;
+//
+//import com.kfzs.duanduan.KFZSApp;
+//import com.kfzs.duanduan.bean.DownloadStatus;
+//import com.kfzs.duanduan.datashare.DDProviderHelper;
+//import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
+//
+//import org.greenrobot.eventbus.EventBus;
+//
+//import java.text.DecimalFormat;
+//import java.util.HashMap;
+//import java.util.Map;
+//
+///**
+// * The appstore download service
+// * Created by HooRang on 2017/2/20.
+// */
+//public class KFDownloadServices extends Service {
+//
+//    private static final String TAG = KFDownloadServices.class.getSimpleName();
+//
+//    private static double FAKE_DOWNLOADED_SIZE = 0.5;
+//
+//
+//    DownloadTaskService downloadTaskService;
+//    private DownloadStatus statusInfo;
+//    private Map<String, String> urlAndPackageNameMap = new HashMap<>();
+//
+//    @Override
+//    public void onCreate() {
+//        super.onCreate();
+//
+//        downloadTaskService = new DownloadTaskService(this);
+//        //        FileDownloader.continueAll(true);
+//    }
+//
+//    @Nullable
+//    @Override
+//    public IBinder onBind(Intent intent) {
+//        Log.i(TAG, "onBind");
+//        return null;
+//
+//
+//    }
+//
+//
+//    @Override
+//    public void onDestroy() {
+//        super.onDestroy();
+//
+//        Log.i(TAG, "onDestroy");
+//
+//    }
+//
+//
+//    // 正在重试下载(如果你配置了重试次数,当一旦下载失败时会尝试重试下载),retryTimes是当前第几次重试
+//    @Override
+//    public void onFileDownloadStatusRetrying(DownloadFileInfo downloadFileInfo, int retryTimes) {
+//        Log.i(TAG, "onFileDownloadStatusRetrying");
+//    }
+//
+//
+//    // 等待下载(等待其它任务执行完成,或者FileDownloader在忙别的操作)
+//    @Override
+//    public void onFileDownloadStatusWaiting(DownloadFileInfo downloadFileInfo) {
+//        Log.i(TAG, "onFileDownloadStatusWaiting");
+//    }
+//
+//
+//    // 准备中(即,正在连接资源)
+//    @Override
+//    public void onFileDownloadStatusPreparing(DownloadFileInfo downloadFileInfo) {
+//        Log.i(TAG, "onFileDownloadStatusPreparing");
+//        statusInfo = new DownloadStatus();
+//
+//        // Send a fucking fake download event to update user interface
+//        FAKE_DOWNLOADED_SIZE = getRandomFakeDownloadSize();
+//        DownLoadInfo task = downloadTaskService.getDownloadTaskByUrl(downloadFileInfo.getUrl());
+//        if (task != null) {
+//            FAKE_DOWNLOADED_SIZE = task.getMDownloadedSize() == null ? FAKE_DOWNLOADED_SIZE : task.getMDownloadedSize();
+//            statusInfo.setDownloadPgrs(task.getMPercent() == null ? 1 : task.getMPercent());
+//        } else {
+//            statusInfo.setDownloadPgrs(1);
+//        }
+//
+//        double fileSize = downloadFileInfo.getFileSizeLong() / 1024f / 1024;
+//        statusInfo.setStatus(DownloadTaskService.STATUS_ING);
+//        statusInfo.setFileTotalSize(fileSize);
+//        statusInfo.setFileDownloadedSize(FAKE_DOWNLOADED_SIZE);
+//        statusInfo.setDownloadId(downloadFileInfo.getId());
+//        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
+//        EventBus.getDefault().post(statusInfo);
+//    }
+//
+//    private String getPackageNameFromMapOrDb(String url) {
+//        String packageName;
+//        if (urlAndPackageNameMap.containsKey(url))
+//            packageName = urlAndPackageNameMap.get(url);
+//        else {
+//            packageName = DDProviderHelper.getInstance().getDownloadTask(KFZSApp.getInstance(), url).getMPackageName();
+//            urlAndPackageNameMap.put(url,packageName);
+//        }
+//        return packageName;
+//    }
+//
+//    // 已准备好(即,已经连接到了资源)
+//    @Override
+//    public void onFileDownloadStatusPrepared(DownloadFileInfo downloadFileInfo) {
+//        Log.i(TAG, "onFileDownloadStatusPrepared");
+//    }
+//
+//    //正在下载,downloadSpeed为当前下载速度,单位KB/s,remainingTime为预估的剩余时间,单位秒
+//    @Override
+//    public void onFileDownloadStatusDownloading(DownloadFileInfo downloadFileInfo,
+//                                                float downloadSpeed, long remainingTime) {
+//        Log.i(TAG, "onFileDownloadStatusDownloading");
+//        double downloadSize = downloadFileInfo.getDownloadedSizeLong() / 1024f / 1024;
+//        if (downloadSize < FAKE_DOWNLOADED_SIZE) {
+//            return;
+//        }
+//        double fileSize = downloadFileInfo.getFileSizeLong() / 1024f / 1024;
+//        Double percent = downloadSize / fileSize * 100;
+//        if(statusInfo == null){
+//            return;
+//        }
+//        statusInfo.setStatus(DownloadTaskService.STATUS_ING);
+//        statusInfo.setDownloadPgrs(percent.intValue());
+//        statusInfo.setFileTotalSize(fileSize);
+//        statusInfo.setFileDownloadedSize(downloadSize);
+//        statusInfo.setDownloadId(downloadFileInfo.getId());
+//        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
+//        statusInfo.setDownloadSpeed(downloadSpeed);
+//        EventBus.getDefault().post(statusInfo);
+//    }
+//
+//    // 下载已被暂停
+//    @Override
+//    public void onFileDownloadStatusPaused(DownloadFileInfo downloadFileInfo) {
+//        Log.i(TAG, "onFileDownloadStatusPaused");
+//        if (null == statusInfo) {
+//            statusInfo = new DownloadStatus();
+//        }
+//        double downloadSize = downloadFileInfo.getDownloadedSizeLong() / 1024f / 1024;
+//        if (downloadSize < FAKE_DOWNLOADED_SIZE) {
+//            return;
+//        }
+//        double fileSize = downloadFileInfo.getFileSizeLong() / 1024f / 1024;
+//        Double percent = downloadSize / fileSize * 100;
+//
+//        if(statusInfo == null){
+//            return;
+//        }
+//        statusInfo.setStatus(DownloadTaskService.STATUS_PAUSE);
+//        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
+//        statusInfo.setDownloadPgrs(percent.intValue());
+//        statusInfo.setFileTotalSize(fileSize);
+//        statusInfo.setFileDownloadedSize(downloadSize);
+//        statusInfo.setDownloadId(downloadFileInfo.getId());
+//        EventBus.getDefault().post(statusInfo);
+//    }
+//
+//    // 下载完成(整个文件已经全部下载完成)
+//    @Override
+//    public void onFileDownloadStatusCompleted(DownloadFileInfo downloadFileInfo) {
+//        Log.i(TAG, "onFileDownloadStatusCompleted");
+//        if (null == statusInfo) {
+//            statusInfo = new DownloadStatus();
+//        }
+//        statusInfo.setStatus(DownloadTaskService.STATUS_FINISH);
+//        statusInfo.setApkPath(downloadFileInfo.getFilePath());
+//        statusInfo.setDownloadUrl(downloadFileInfo.getUrl());
+//        EventBus.getDefault().post(statusInfo);
+//    }
+//
+//
+//    // 下载失败了,详细查看失败原因failReason
+//    @Override
+//    public void onFileDownloadStatusFailed(String url, DownloadFileInfo downloadFileInfo, FileDownloadStatusFailReason failReason) {
+//        Log.i(TAG, "onFileDownloadStatusFailed");
+//        if (null == statusInfo) {
+//            statusInfo = new DownloadStatus();
+//        }
+//        statusInfo.setStatus(DownloadTaskService.STATUS_FAIL);
+//        statusInfo.setDownloadUrl(url);
+//        statusInfo.setMessage(failReason.getMessage());
+//        EventBus.getDefault().post(statusInfo);
+//    }
+//
+//
+//    private double getRandomFakeDownloadSize() {
+//        DecimalFormat df = new DecimalFormat("######0.0");
+//        double a = (Math.random() * 1);
+//        return Double.valueOf(df.format(a));
+//    }
+//
+//
+//}

+ 11 - 30
app/src/main/java/com/kfzs/duanduan/utils/GameStatusScanner.java

@@ -2,6 +2,7 @@ package com.kfzs.duanduan.utils;
 
 import android.content.Context;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.View;
 import android.widget.Toast;
 
@@ -32,10 +33,6 @@ import com.zhy.http.okhttp.callback.StringCallback;
 import org.greenrobot.eventbus.EventBus;
 import org.json.JSONException;
 import org.json.JSONObject;
-import org.wlf.filedownloader.DownloadFileInfo;
-import org.wlf.filedownloader.FileDownloader;
-import org.wlf.filedownloader.base.Log;
-import org.wlf.filedownloader.listener.OnDeleteDownloadFileListener;
 
 import java.io.File;
 import java.util.HashMap;
@@ -244,8 +241,8 @@ public abstract class GameStatusScanner {
 
     public static void startDownload(Context context,GameStatusScanner scanner, DownloadTaskService downloadTaskService, String gameId, int versionCode, String downloadUrl, String packageName, String gameName, String iconUrl) {
         setUmengOnEvent(context,gameName);
-        FileDownloader.start(downloadUrl);
-        addNewDownloadTask(downloadTaskService,gameName, downloadUrl, packageName, versionCode, iconUrl, Integer.parseInt(gameId));
+        DownLoadInfo downloadInfo = addNewDownloadTask(downloadTaskService, gameName, downloadUrl, packageName, versionCode, iconUrl, Integer.parseInt(gameId));
+        downloadTaskService.start(downloadInfo);
         if(scanner != null)
             scanner.onButtonClickReturnListener(downloadUrl, false, 0);
         //开始任务的时候,再发请求,不判断是否为首次添加等情况
@@ -331,27 +328,9 @@ public abstract class GameStatusScanner {
                     ApkUtils.installApk(mContext, downloadTask.getMApkPath());
                     onButtonClickReturnListener(downloadUrl, bPaused, percent);
                 } else {
-                    final DownLoadInfo finalDownloadTask = downloadTask;
-                    FileDownloader.delete(downloadUrl, true, new OnDeleteDownloadFileListener() {
-                        @Override
-                        public void onDeleteDownloadFilePrepared(DownloadFileInfo downloadFileInfo) {
-
-                        }
-
-                        @Override
-                        public void onDeleteDownloadFileSuccess(DownloadFileInfo downloadFileInfo) {
-                            downloadTaskService.deleteDownloadTaskByDownloadUrl(downloadUrl);
-                            FileDownloader.start(downloadUrl);
-                            addNewDownloadTask(downloadTaskService, finalDownloadTask.getMGameName(), downloadUrl, finalDownloadTask.getMPackageName(), finalDownloadTask.getMVersionCode(), finalDownloadTask.getMIconUrl(), finalDownloadTask.getMGameID());
-                            onButtonClickReturnListener(downloadUrl, false, 0);
-                        }
-
-                        @Override
-                        public void onDeleteDownloadFileFailed(DownloadFileInfo downloadFileInfo, DeleteDownloadFileFailReason deleteDownloadFileFailReason) {
-
-                        }
-                    });
-
+                    downloadTaskService.cancel(downloadTask);
+                    downloadTaskService.deleteDownloadTaskByDownloadUrl(downloadUrl);
+                    downloadTaskService.start(downloadTask);//重新下载
                 }
 
                 break;
@@ -377,6 +356,7 @@ public abstract class GameStatusScanner {
      */
     private void changeTaskPersistenceStatus(String downloadUrl, int status, int percent, boolean bPauseTask) {
         boolean success = downloadTaskService.setDownloadTaskStatus(downloadUrl, status);
+        DownLoadInfo downLoadInfo = downloadTaskService.getDownloadTaskByUrl(downloadUrl);
         if (success) {
             if (bPauseTask) {
                 mTarget.setText(R.string.pausing);
@@ -386,11 +366,11 @@ public abstract class GameStatusScanner {
                 event.setStatus(DownloadTaskService.STATUS_PAUSE);
                 EventBus.getDefault().post(event);
                 /*********************************/
-                FileDownloader.pause(downloadUrl);
+                downloadTaskService.pause(downLoadInfo);
             } else {
                 //这里应该改为安装中,而不是安装
                 mTarget.setText(R.string.installing);
-                FileDownloader.start(downloadUrl);
+                downloadTaskService.start(downLoadInfo);
             }
         }
     }
@@ -402,7 +382,7 @@ public abstract class GameStatusScanner {
         MobclickAgent.onEvent(mContext, UMConfigUtils.Event.GAME_DOWNLOAD, map);
     }
 
-    public static void addNewDownloadTask(DownloadTaskService downloadTaskService,String gameName, String downloadUrl, String packageName, int versionCode, String iconUrl, int gameId) {
+    public static DownLoadInfo addNewDownloadTask(DownloadTaskService downloadTaskService,String gameName, String downloadUrl, String packageName, int versionCode, String iconUrl, int gameId) {
         DownLoadInfo task = new DownLoadInfo();
         task.setMIconUrl(iconUrl);
         task.setMGameName(gameName);
@@ -411,6 +391,7 @@ public abstract class GameStatusScanner {
         task.setMVersionCode(versionCode);
         task.setMGameID(gameId);
         downloadTaskService.addDownloadTask(task);
+        return task;
     }
 
     public abstract void onButtonClickReturnListener(String downloadUrl, boolean drawBtnUI, int percent);

+ 8 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -220,6 +220,14 @@ public interface ApiService {
 //    Observable<BaseMessage> taskStatus(@Body JSONObject jsonObject);
 
     /**
+     *下载任务回调
+     * @param jsonObject
+     * @return
+     */
+    @PUT(V1 + "/app/accepted_task/download_task_notify/")
+    Observable<BaseMessage> taskDownloadNotify(@Body JSONObject jsonObject);
+
+    /**
      * 获取可用余额
      * @return
      */

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

@@ -3,7 +3,6 @@ package com.sheep.gamegroup.util;
 import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.jiuyan.samllsheep.download.DownloadInfo;
 
-import org.wlf.filedownloader.file_download.http_downloader.Download;
 import org.xutils.DbManager;
 import org.xutils.ex.DbException;
 import org.xutils.x;

+ 41 - 0
app/src/main/java/com/sheep/gamegroup/util/NetUtil.java

@@ -7,10 +7,28 @@ import android.content.Intent;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 
+import com.alibaba.fastjson.JSONObject;
+import com.sheep.gamegroup.model.api.ApiService;
+import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+import rx.Scheduler;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+
 /**
  * Created by ljy on 2018/3/8.
  */
 public class NetUtil {
+    private static NetUtil netUtil;
+
+    public static NetUtil getNetUtil(){
+        if (netUtil == null){
+            netUtil = new NetUtil();
+        }
+        return netUtil;
+    }
     /**
      * 判断网络是否连接
      *
@@ -78,4 +96,27 @@ public class NetUtil {
         intent.setAction("android.intent.action.VIEW");
         activity.startActivityForResult(intent, 0);
     }
+
+    /**
+     * 应用下载,接口请求
+     */
+    public void sendAppDownload(Context context, JSONObject o){
+        ApiService apiService = SheepApp.getInstance().getNetComponent().getApiService();
+
+        apiService.taskDownloadNotify((JSONObject) o)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+
+                    }
+
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+
+                    }
+                });
+
+    }
 }

+ 6 - 6
app/src/main/java/com/sheep/gamegroup/view/activity/DialogActivity.java

@@ -37,7 +37,7 @@ import com.sheep.gamegroup.presenter.TaskDialogPresenter;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DeviceUtil;
 import com.sheep.gamegroup.util.Jump2View;
-import com.sheep.gamegroup.util.MyListview;;
+import com.sheep.gamegroup.util.MyListview;
 import com.sheep.gamegroup.util.NetUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
@@ -46,10 +46,8 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 
-
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
-import org.wlf.filedownloader.FileDownloader;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -60,6 +58,8 @@ import butterknife.BindView;
 import butterknife.ButterKnife;
 import butterknife.OnClick;
 
+;
+
 /**
  * 弹框activity
  * Created by ljy on 2018/3/20.
@@ -270,9 +270,9 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
                         }
                         //Todo 合并下载模块t
 //                        startFiler();
-                        FileDownloader.start(task_entity.getDownload_link()+"");
+                        mDownloadTaskService.start(downLoadInfo);
                     }else {
-                        FileDownloader.pause(task_entity.getDownload_link());
+                        mDownloadTaskService.pause(downLoadInfo);
                     }
 
                     break;
@@ -434,7 +434,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
             case DIALOG_ACTIVITY_DOWNLOAD_FILE:
                 if(task_entity != null){
                     downLoadInfo = mDownloadTaskService.getDownloadTaskByUrl(task_entity.getDownload_link());
-                    FileDownloader.start(task_entity.getDownload_link()+"");
+                    mDownloadTaskService.start(downLoadInfo);
 
                 }
                 break;

+ 0 - 8
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -9,20 +9,13 @@ import android.util.DisplayMetrics;
 import com.kfzs.libs.di.http.DaggerHttpComponent;
 import com.kfzs.libs.di.http.HttpComponent;
 import com.kfzs.libs.di.http.HttpModule;
-import com.liulishuo.filedownloader.FileDownloader;
 import com.sheep.gamegroup.di.components.DaggerNetComponent;
 import com.sheep.gamegroup.di.components.NetComponent;
 import com.sheep.gamegroup.di.modules.NetModule;
-import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.UMConfigUtils;
-import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.tencent.bugly.Bugly;
-import com.tencent.bugly.beta.Beta;
 import com.tencent.mm.opensdk.openapi.IWXAPI;
-import com.umeng.analytics.MobclickAgent;
-
-import org.wlf.filedownloader.FileDownloadConfiguration;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -54,7 +47,6 @@ public class SheepApp extends BaseApplication {
     public void onCreate() {
         super.onCreate();
         mContext = getApplicationContext();
-        FileDownloader.setup(this);
         mSheepApp = this;
         regWx();
         registerActivityLifecycleCallbacks(activityLifecycleCallbacks);

+ 1 - 1
app/src/main/res/layout/ftg_credit_card.xml

@@ -9,7 +9,7 @@
         android:id="@+id/navigationbar"
         android:layout_width="match_parent"
         android:layout_height="@dimen/layout_heigh_default"
-        android:background="#ffffff" />
+        android:background="@color/white_F9F9F9" />
     <include layout="@layout/title_bottom_line"/>
 
     <ScrollView

+ 1 - 2
app/src/main/res/layout/mainbar.xml

@@ -3,7 +3,7 @@
     android:id="@+id/layout_navigationBar"
     android:layout_width="match_parent"
     android:layout_height="@dimen/layout_heigh_default"
-    android:background="@color/white">
+    android:background="@color/white_F9F9F9">
 
 
     <ImageView
@@ -36,7 +36,6 @@
         android:layout_alignParentRight="true"
         android:layout_centerVertical="true"
         android:layout_marginRight="5dp"
-        android:background="@color/white"
         android:gravity="center"
         android:minWidth="@dimen/layout_heigh_default"
         android:textColor="@color/B"

+ 4 - 1
app/src/main/res/layout/title.xml

@@ -89,5 +89,8 @@
             android:layout_height="12dp"
             android:src="@mipmap/triangle_popup_nomal"/>
     </LinearLayout>
-    <include layout="@layout/title_bottom_line"/>
+    <include layout="@layout/title_bottom_line"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"/>
 </RelativeLayout>

+ 1 - 1
app/src/main/res/values/colors.xml

@@ -24,7 +24,7 @@
 
     <color name="bbb">#f7dc0f</color>
 
-    <color name="bg_class_grey">#f5f5f5</color>
+    <color name="bg_class_grey">#f9f9f9</color>
 
     <drawable name="transparent">#ffffffff</drawable>
 </resources>