Просмотр исходного кода

Merge remote-tracking branch 'origin/sheep2.0' into sheep2.0

xiongxiaohe лет назад: 8
Родитель
Сommit
9ac14abaf3
22 измененных файлов с 183 добавлено и 187 удалено
  1. 3 2
      app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java
  2. 2 0
      app/src/main/java/com/sheep/gamegroup/presenter/AccountAndSecuritPresenter.java
  3. 2 0
      app/src/main/java/com/sheep/gamegroup/presenter/AskGetMoneyPresenter.java
  4. 6 2
      app/src/main/java/com/sheep/gamegroup/presenter/BindDataPresenter.java
  5. 2 0
      app/src/main/java/com/sheep/gamegroup/presenter/BindOrChangeWeixinPresenter.java
  6. 3 0
      app/src/main/java/com/sheep/gamegroup/presenter/LoginPresenter.java
  7. 1 1
      app/src/main/java/com/sheep/gamegroup/presenter/PhonePresenter.java
  8. 2 0
      app/src/main/java/com/sheep/gamegroup/presenter/ReNamePresenter.java
  9. 2 0
      app/src/main/java/com/sheep/gamegroup/presenter/TaskListPresenter.java
  10. 2 0
      app/src/main/java/com/sheep/gamegroup/presenter/WithdrawalListPresenter.java
  11. 2 0
      app/src/main/java/com/sheep/gamegroup/presenter/WithdrawalPresenter.java
  12. 2 2
      app/src/main/java/com/sheep/gamegroup/util/ConnectAddress.java
  13. 13 0
      app/src/main/java/com/sheep/gamegroup/util/MyDbManager.java
  14. 7 8
      app/src/main/java/com/sheep/gamegroup/view/activity/BindDataAct.java
  15. 18 86
      app/src/main/java/com/sheep/gamegroup/view/activity/DialogActivity.java
  16. 1 1
      app/src/main/java/com/sheep/gamegroup/view/activity/TryMakeMoneyact.java
  17. 69 67
      app/src/main/java/com/sheep/gamegroup/view/adapter/DownLoadTvAdp.java
  18. 9 5
      app/src/main/java/com/sheep/gamegroup/view/adapter/TaskStateAdapter.java
  19. 24 0
      app/src/main/res/layout/dowanload_tv_item.xml
  20. 9 11
      app/src/main/res/layout/download_item_dialog.xml
  21. 3 2
      app/src/main/res/layout/task_state_item.xml
  22. 1 0
      app/src/main/res/values/common.xml

+ 3 - 2
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -86,12 +86,13 @@ public interface ApiService {
      * 绑定身份证号
      */
     @PUT(V1+"app/user/bind_id_number/")
-    Observable<BaseMessage> bindIdNumber(@Query("id_number") String id_number);
+//    Observable<BaseMessage> bindIdNumber(@Query("id_number") String id_number);
+    Observable<BaseMessage> bindIdNumber(@Body JSONObject objec);
     /**
      * 绑定银行卡
      */
     @PUT(V1+"app/user/bind_bank_card/")
-    Observable<BaseMessage> bindBankCard(@Query("bank_card") String bank_card);
+    Observable<BaseMessage> bindBankCard(@Body JSONObject objec);
 
     /**
      * 用户提现

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/presenter/AccountAndSecuritPresenter.java

@@ -11,6 +11,7 @@ import java.util.HashMap;
 import javax.inject.Inject;
 
 import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -34,6 +35,7 @@ public class AccountAndSecuritPresenter implements  AccountAndSecuritContract.Pr
 
 
         apiService.getInfo().subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new Observer<BaseMessage>() {
                     @Override
                     public void onCompleted() {

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/presenter/AskGetMoneyPresenter.java

@@ -18,6 +18,7 @@ import java.util.HashMap;
 import javax.inject.Inject;
 
 import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -40,6 +41,7 @@ public class AskGetMoneyPresenter implements AskGetMoneyContract.Presenter {
 
         apiService.FriendCountAndAward()
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new Observer<BaseMessage>() {
                     @Override
                     public void onCompleted() {

+ 6 - 2
app/src/main/java/com/sheep/gamegroup/presenter/BindDataPresenter.java

@@ -9,6 +9,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 
 import javax.inject.Inject;
 
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -35,6 +36,7 @@ public class BindDataPresenter implements BindDataContract.Presenter {
 
         apiService.bindRealname((JSONObject) o)
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                     @Override
                     public void onError(BaseMessage baseMessage) {
@@ -52,8 +54,9 @@ public class BindDataPresenter implements BindDataContract.Presenter {
     @Override
     public void submitDataBankcard(Object o) {
 
-        apiService.bindBankCard(o.toString())
+        apiService.bindBankCard((JSONObject) o)
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                     @Override
                     public void onError(BaseMessage baseMessage) {
@@ -71,8 +74,9 @@ public class BindDataPresenter implements BindDataContract.Presenter {
     @Override
     public void submitDataIdnumber(Object o) {
 
-        apiService.bindIdNumber(o.toString())
+        apiService.bindIdNumber((JSONObject) o)
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                     @Override
                     public void onError(BaseMessage baseMessage) {

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/presenter/BindOrChangeWeixinPresenter.java

@@ -11,6 +11,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import javax.inject.Inject;
 
 import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -32,6 +33,7 @@ public class BindOrChangeWeixinPresenter implements BindOrChangeWeixinContract.P
     public void bindWeixin(Object o) {
         apiService.bindWeixin(((JSONObject) o).getString("code"))
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.context){
 
                     @Override

+ 3 - 0
app/src/main/java/com/sheep/gamegroup/presenter/LoginPresenter.java

@@ -27,6 +27,7 @@ import java.util.Map;
 import javax.inject.Inject;
 
 import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -52,6 +53,7 @@ public class LoginPresenter implements LoginContract.Presenter {
         j.put("scope",ChannelContent.getInstance().getChannel_name() );
         if(type==1){
             apiService.LoginByWX(j).subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
                     .subscribe(new Observer<BaseMessage>() {
                         @Override
                         public void onCompleted() {
@@ -86,6 +88,7 @@ public class LoginPresenter implements LoginContract.Presenter {
 
         }else{
             apiService.LoginByQQ(j).subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
                     .subscribe(new Observer<BaseMessage>() {
                         @Override
                         public void onCompleted() {

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/presenter/PhonePresenter.java

@@ -50,7 +50,7 @@ public class PhonePresenter implements PhoneContract.Presenter {
 
             apiService.getCaptcha(j)
                     .subscribeOn(Schedulers.io())
-                    .observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
+                    .observeOn(AndroidSchedulers.mainThread())
                     .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                         @Override
                         public void onError(BaseMessage baseMessage) {

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/presenter/ReNamePresenter.java

@@ -12,6 +12,7 @@ import java.util.HashMap;
 import javax.inject.Inject;
 
 import rx.Observer;
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -38,6 +39,7 @@ public class ReNamePresenter implements  ReNameContract.Presenter  {
 
         apiService.changeBaseInfo(j)
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new Observer<BaseMessage>() {
                     @Override
                     public void onCompleted() {

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/presenter/TaskListPresenter.java

@@ -9,6 +9,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 
 import javax.inject.Inject;
 
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -29,6 +30,7 @@ public class TaskListPresenter implements TaskListContract.Presenter {
     public void acceptedTask(int page, int pre_page) {
         apiService.acceptedTask(page, pre_page)
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                     @Override
                     public void onError(BaseMessage baseMessage) {

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/presenter/WithdrawalListPresenter.java

@@ -9,6 +9,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 
 import javax.inject.Inject;
 
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -31,6 +32,7 @@ public class WithdrawalListPresenter implements WithdrawalListContract.Presenter
 
         apiService.goWithdrawal(page, per_page, start_time, end_time)
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                     @Override
                     public void onError(BaseMessage baseMessage) {

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/presenter/WithdrawalPresenter.java

@@ -9,6 +9,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 
 import javax.inject.Inject;
 
+import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
 
 /**
@@ -30,6 +31,7 @@ public class WithdrawalPresenter implements WithdrawalContract.Presenter {
     public void goWithdrawal(JSONObject jsonObject) {
         apiService.goWithdrawal(jsonObject)
                 .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                     @Override
                     public void onError(BaseMessage baseMessage) {

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

@@ -6,8 +6,8 @@ package com.sheep.gamegroup.util;
 
 public class ConnectAddress {
 
-  public static final String BASE_HTTP = "http://10.8.220.6:8080/";//何威
-//     public static final String BASE_HTTP = "http://10.8.220.5:8080/";//张伟
+//  public static final String BASE_HTTP = "http://10.8.220.6:8080/";//何威
+     public static final String BASE_HTTP = "http://10.8.220.5:8080/";//张伟
 //   public static final String BASE_HTTP = "http://test.sheep.kfzs.com/";//测试服地址
 
     public static final String V1 = "/v1/";

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

@@ -40,6 +40,7 @@ public class MyDbManager {
      *保存或更新表表
      */
     public void saveOrUpdateUser(UserEntity user) throws DbException {
+        deleteTable(UserEntity.class);//先清空表
         db.saveOrUpdate(user);
     }
 
@@ -93,4 +94,16 @@ public class MyDbManager {
         }
 
     }
+
+    /**
+     *删除表
+     * @param o
+     */
+    private void deleteTable(Class<?> o){
+        try {
+            db.dropTable(o);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
 }

+ 7 - 8
app/src/main/java/com/sheep/gamegroup/view/activity/BindDataAct.java

@@ -63,8 +63,7 @@ public class BindDataAct extends BaseActivity implements BindDataContract.View {
     @Override
     public void upView(Object o) {
         hideProgress();
-        G.showToast("ok");
-        Toast.makeText(activity, "绑定成功",Toast.LENGTH_SHORT);
+        G.showToast("绑定成功");
         finish();
 
     }
@@ -147,16 +146,16 @@ public class BindDataAct extends BaseActivity implements BindDataContract.View {
                 value = textEt.getText().toString();
                 break;
             case 40002:
-                key = "bank_card";
+                key = "id_number";
                 title = "绑定身份证";
-                textLayout.setVisibility(View.GONE);
-                numberNoticeTv.setVisibility(View.GONE);
-                value = numberEt.getText().toString();
+                numberLayout.setVisibility(View.GONE);
+                textNoticeTv.setVisibility(View.GONE);
+                value = textEt.getText().toString();
                 break;
             case 40003:
-                key = "id_number";
+                key = "bank_card";
                 title = "绑定银行卡";
-                textNoticeTv.setText("真实姓名");
+                textLayout.setVisibility(View.GONE);
                 numberNoticeTv.setText("卡号");
                 value = numberEt.getText().toString();
                 break;

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

@@ -9,18 +9,12 @@ import android.preference.DialogPreference;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.RequiresApi;
-import android.util.Log;
-import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewGroup;
 import android.webkit.WebChromeClient;
 import android.webkit.WebResourceRequest;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
-import android.widget.ArrayAdapter;
-import android.widget.BaseAdapter;
 import android.widget.ImageView;
-import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -46,24 +40,16 @@ import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
 import com.sheep.gamegroup.view.customview.SProgress;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
-import com.sheep.jiuyan.samllsheep.adapter.DownListAdapter;
-import com.sheep.jiuyan.samllsheep.base.BaseActivity;
 import com.sheep.jiuyan.samllsheep.download.DownloadInfo;
 import com.sheep.jiuyan.samllsheep.download.DownloadManager;
 import com.sheep.jiuyan.samllsheep.download.DownloadState;
-import com.sheep.jiuyan.samllsheep.download.DownloadViewHolder;
 import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 
 
 import org.greenrobot.eventbus.EventBus;
-import org.xutils.HttpManager;
-import org.xutils.common.Callback;
-import org.xutils.common.task.PriorityExecutor;
 import org.xutils.ex.DbException;
-import org.xutils.http.HttpMethod;
-import org.xutils.http.RequestParams;
 import org.xutils.x;
 
 import java.io.File;
@@ -115,7 +101,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
      * 下载
      */
     private DownLoadTvAdp loadTvAdp;
-    private Callback.Cancelable cancelable;
+    private List<DownloadInfo> infoList = new ArrayList<>();
 
     @Inject
     TaskDialogPresenter preference;
@@ -147,7 +133,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
         setContentView(R.layout.download_item_dialog);
         ButterKnife.bind(this);
         activity = this;
-        x.view().inject(this);
         initViews();
         initDatas();
     }
@@ -164,13 +149,18 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
         dialogItemSizeTv.setText( task_entity.getPackage_size() + "M");
         isDownLoad = PackageUtil.isAppInstalled(SheepApp.mContext, task_entity.getPackage_names());
 
-        downLoadApk();
+        isHaveLoad();
+//        downLoadApk();
         /**
          * 下载
          */
-        loadTvAdp = new DownLoadTvAdp(activity);
+        loadTvAdp = new DownLoadTvAdp(activity, infoList);
         listview_down.setAdapter(loadTvAdp);
 
+        loadTvAdp.setTaskState(type);
+        loadTvAdp.addTaskPreference(preference);
+        loadTvAdp.addTaskEty(task_entity);
+
         //Todo ok
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("id",task_entity.getRelease_task_id());
@@ -178,7 +168,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
 
     }
 
-        private void initViews() {
+    private void initViews() {
 
 //        startStaskSprogress.setVisibility(View.GONE);
         task_entity = (TaskEty) getIntent().getSerializableExtra("task_entity");
@@ -277,7 +267,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
         startStaskSprogress.setVisibility(View.VISIBLE);
         if (task_entity != null) {
             ClassFileHelper.getInstance().createSDDirection();
-            final File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
+            File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
             if (!mApkPath.exists()) {
 //                new File(mApkPath.getAbsolutePath());
                 try{
@@ -302,65 +292,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
                     downloadInfo.setPkgName(task_entity.getPackage_names());
                     MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
                 }
-
-
-                //设置请求参数
-                RequestParams params = new RequestParams(task_entity.getDownload_link());
-                params.setAutoResume(true);//设置是否在下载是自动断点续传
-                params.setAutoRename(false);//设置是否根据头信息自动命名文件
-                params.setSaveFilePath(mApkPath.getAbsolutePath());
-                params.setExecutor(new PriorityExecutor(2, true));//自定义线程池,有效的值范围[1, 3], 设置为3时, 可能阻塞图片加载.
-                params.setCancelFast(true);//是否可以被立即停止.
-                cancelable = x.http().get(params, new Callback.ProgressCallback<File>(){
-
-                    @Override
-                    public void onSuccess(File file) {
-                        Log.e("-----下载","onSuccess");
-                        PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
-                    }
-
-                    @Override
-                    public void onError(Throwable throwable, boolean b) {
-                        Log.e("-----下载","onError--"+"throwable:"+throwable.getMessage()+",b:"+b);
-
-                    }
-
-                    @Override
-                    public void onCancelled(CancelledException e) {
-                        Log.e("-----下载","onCancelled");
-
-                    }
-
-                    @Override
-                    public void onFinished() {
-                        Log.e("-----下载","onFinished");
-
-                    }
-
-                    @Override
-                    public void onWaiting() {
-                        Log.e("-----下载","onWaiting");
-
-                    }
-
-                    @Override
-                    public void onStarted() {
-                        Log.e("-----下载","onStarted");
-
-                    }
-
-                    @Override
-                    public void onLoading(long total, long current, boolean b) {
-                        Log.e("-----下载","onLoading--total:"+total+",current:"+current+",b:"+b);
-                        Message message = new Message();
-                        message.what = 1;
-                        Bundle bundle = new Bundle();
-                        bundle.putLong("total", total);
-                        bundle.putLong("current", current);
-                        message.setData(bundle);
-                        handler.sendMessage(message);
-                    }
-                });
             } else {
                 PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
             }
@@ -375,12 +306,13 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
     /**
      * 判断apk是否下载过
      */
-    private void isHave(){
+    private DownloadInfo isHaveLoad(){
+        DownloadInfo downloadInfo = null;
         if (task_entity != null) {
             ClassFileHelper.getInstance().createSDDirection();
             File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
             if (!mApkPath.exists()) {
-                DownloadInfo downloadInfo = MyDbManager.getInstance().dbFindDownLoad(task_entity.getTask_name(), mApkPath.getAbsolutePath());
+                downloadInfo = MyDbManager.getInstance().dbFindDownLoad(task_entity.getTask_name(), mApkPath.getAbsolutePath());
                 if (downloadInfo == null) {
                     downloadInfo = new DownloadInfo();
                     downloadInfo.setUrl(task_entity.getDownload_link());
@@ -393,10 +325,13 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
                     downloadInfo.setPkgName(task_entity.getPackage_names());
                     MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
                 }else{
-                    start_task_tv.setText("继续下载");
+//                    start_task_tv.setText("继续下载");
                 }
+                infoList.clear();
+                infoList.add(downloadInfo);
             }
         }
+        return downloadInfo;
     }
     /**
      * 去试玩
@@ -448,7 +383,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
     @Override
     public void startTaskFailView(Object o) {
 
-        G.showToast("开启任务失败");
+        G.showToast(((BaseMessage)o).getMsg()+ "");
 
     }
 
@@ -481,9 +416,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        if(cancelable != null){
-            cancelable.cancel();
-        }
     }
 
 }

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

@@ -100,7 +100,7 @@ public class TryMakeMoneyact extends BaseActivity implements TryMakeMoneyContrac
                 refresh.setRefreshing(false);
             }
         });
-        recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
+        recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
             @Override
             public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                 super.onScrollStateChanged(recyclerView, newState);

+ 69 - 67
app/src/main/java/com/sheep/gamegroup/view/adapter/DownLoadTvAdp.java

@@ -9,7 +9,11 @@ import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
 
+import com.alibaba.fastjson.JSONObject;
 import com.bumptech.glide.Glide;
+import com.kfzs.duanduan.utils.dlg.DeviceUtils;
+import com.sheep.gamegroup.model.entity.TaskEty;
+import com.sheep.gamegroup.presenter.TaskDialogPresenter;
 import com.sheep.gamegroup.view.customview.SProgress;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -24,6 +28,7 @@ import org.xutils.ex.DbException;
 import org.xutils.x;
 
 import java.io.File;
+import java.util.List;
 
 
 /**
@@ -34,24 +39,41 @@ public class DownLoadTvAdp extends BaseAdapter {
     private Context mContext;
     private final LayoutInflater mInflater;
     private DownloadManager downloadManager;
+    private List<DownloadInfo> infoList;
+    private int taskType;
+    TaskDialogPresenter preference;
+    private TaskEty task_entity;
 
-    public DownLoadTvAdp(Context mContext) {
+    public DownLoadTvAdp(Context mContext,List<DownloadInfo> infoList) {
+        this.infoList = infoList;
         this.mContext = mContext;
         this.mInflater = LayoutInflater.from(mContext);
         downloadManager = DownloadManager.getInstance();
     }
 
+    /**
+     *
+     * @param taskType
+     */
+    public void setTaskState(int taskType){
+        this.taskType = taskType;
+    }
+    public void addTaskPreference(TaskDialogPresenter preference){
+        this.preference = preference;
+    }
+    public void addTaskEty(TaskEty task_entity){
+        this.task_entity = task_entity;
+    }
+
 
     @Override
     public int getCount() {
-        if (downloadManager == null)
-            return 0;
-        return downloadManager.getDownloadListCount();
+        return infoList.size();
     }
 
     @Override
     public Object getItem(int i) {
-        return downloadManager.getDownloadInfo(i);
+        return infoList.get(i);
     }
 
     @Override
@@ -63,71 +85,51 @@ public class DownLoadTvAdp extends BaseAdapter {
     @Override
     public View getView(int i, View view, ViewGroup viewGroup) {
         DownloadItemViewHolder holder = null;
-        DownloadInfo downloadInfo = downloadManager.getDownloadInfo(i);
+        DownloadInfo downloadInfo = (DownloadInfo) getItem(i);
         if (view == null) {
-            view = mInflater.inflate(R.layout.down_item, null);
+            view = mInflater.inflate(R.layout.dowanload_tv_item, null);
             holder = new DownloadItemViewHolder(view, downloadInfo);
             view.setTag(holder);
         } else {
             holder = (DownloadItemViewHolder) view.getTag();
             holder.update(downloadInfo);
         }
-        holder.refreshkem();
-        if (downloadInfo.getState().value() < DownloadState.FINISHED.value()) {
-            try {
-                downloadManager.startDownload(
-                        downloadInfo.getPkgName(),
-                        downloadInfo.getUrl(),
-                        downloadInfo.getLabel(),
-                        downloadInfo.getFileSavePath(), "",
-                        downloadInfo.isAutoResume(),
-                        downloadInfo.isAutoRename(),
-                        holder);
-            } catch (DbException ex) {
-                Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
+        if(taskType == 0){//开始任务
+            holder.start_task_tv.setText("开始任务");
+        }else {
+            holder.refreshkem();
+            if (downloadInfo.getState().value() < DownloadState.FINISHED.value()) {
+                try {
+                    downloadManager.startDownload(
+                            downloadInfo.getPkgName(),
+                            downloadInfo.getUrl(),
+                            downloadInfo.getLabel(),
+                            downloadInfo.getFileSavePath(), "",
+                            downloadInfo.isAutoResume(),
+                            downloadInfo.isAutoRename(),
+                            holder);
+                } catch (DbException ex) {
+                    Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
+                }
             }
         }
+
         return view;
     }
 
     class DownloadItemViewHolder extends DownloadViewHolder implements View.OnClickListener {
 
-        private android.widget.ImageView ImageView;
-        private TextView tv_game_name;
-        private ImageView iv_state;
-        private ImageView iv_remove;
-        private SProgress pb_download;
-        private TextView tv_prorgess;
-        private View ll_install;
+        private TextView start_task_tv;
 
         public DownloadItemViewHolder(View view, DownloadInfo downloadInfo) {
             super(view, downloadInfo);
-            ImageView = (ImageView) view.findViewById(R.id.img_icon);
-            tv_game_name = (TextView) view.findViewById(R.id.tv_game_name);
-            iv_state = (ImageView) view.findViewById(R.id.iv_state);
-            pb_download = (SProgress) view.findViewById(R.id.pb_download);
-            iv_remove = (ImageView) view.findViewById(R.id.iv_remove);
-            tv_prorgess = (TextView) view.findViewById(R.id.tv_prorgess);
-            ll_install = view.findViewById(R.id.ll_install);
-            Glide.with(mContext)
-                    .load(downloadInfo.getIcon())
-                    .placeholder(R.drawable.icon)
-                    .dontAnimate()
-                    .into(ImageView);
-            iv_state.setOnClickListener(this);
-            iv_remove.setOnClickListener(this);
-            tv_prorgess.setOnClickListener(this);
-            ll_install.setOnClickListener(this);
+            start_task_tv = (TextView) view.findViewById(R.id.start_task_tv);
+            start_task_tv.setOnClickListener(this);
         }
 
         @Override
         public void update(DownloadInfo downloadInfo) {
             super.update(downloadInfo);
-            Glide.with(mContext)
-                    .load(downloadInfo.getIcon())
-                    .placeholder(R.drawable.icon)
-                    .dontAnimate()
-                    .into(ImageView);
         }
 
         @Override
@@ -161,58 +163,48 @@ public class DownLoadTvAdp extends BaseAdapter {
         }
 
         public void refresh() {
-            tv_game_name.setText(downloadInfo.getLabel());
-            pb_download.setProgress(downloadInfo.getProgress());
-            tv_prorgess.setText(downloadInfo.getProgress() + "%");
+            start_task_tv.setText(downloadInfo.getProgress() + "%");
             DownloadState state = downloadInfo.getState();
             switch (state) {
                 case WAITING:
                 case STARTED:
-                    iv_state.setImageResource(R.drawable.icon_stop);
+                    start_task_tv.setText("继续");
                     break;
                 case ERROR:
                 case STOPPED:
-                    iv_state.setImageResource(R.drawable.icon_begin);
                     break;
                 case FINISHED:
-                    iv_state.setVisibility(View.GONE);
                     if (PackageUtil.isAppInstalled(mContext, getDownloadInfo().getPkgName())) {
-                        tv_prorgess.setText("已安装");
+                        start_task_tv.setText("已安装");
                     } else {
-                        tv_prorgess.setText("安 装");
+                        start_task_tv.setText("安 装");
                         PackageUtil.installApk(mContext, getDownloadInfo().getFileSavePath());
                     }
                     break;
                 default:
-                    iv_state.setImageResource(R.drawable.icon_begin);
                     break;
             }
         }
 
         public void refreshkem() {
-            tv_game_name.setText(downloadInfo.getLabel());
-            pb_download.setProgress(downloadInfo.getProgress());
-            tv_prorgess.setText(downloadInfo.getProgress() + "%");
+            start_task_tv.setText(downloadInfo.getProgress() + "%");
             DownloadState state = downloadInfo.getState();
             switch (state) {
                 case WAITING:
                 case STARTED:
-                    iv_state.setImageResource(R.drawable.icon_stop);
+                    start_task_tv.setText("继续");
                     break;
                 case ERROR:
                 case STOPPED:
-                    iv_state.setImageResource(R.drawable.icon_begin);
                     break;
                 case FINISHED:
-                    iv_state.setVisibility(View.GONE);
                     if (PackageUtil.isAppInstalled(mContext, getDownloadInfo().getPkgName())) {
-                        tv_prorgess.setText("已安装");
+                        start_task_tv.setText("已安装");
                     } else {
-                        tv_prorgess.setText("安 装");
+                        start_task_tv.setText("安 装");
                     }
                     break;
                 default:
-                    iv_state.setImageResource(R.drawable.icon_begin);
                     break;
             }
         }
@@ -220,7 +212,11 @@ public class DownLoadTvAdp extends BaseAdapter {
         @Override
         public void onClick(View view) {
             switch (view.getId()) {
-                case R.id.iv_state:
+                case R.id.start_task_tv:
+                    if(taskType == 0){
+                        startTask();
+                        return;
+                    }
                     DownloadState state = downloadInfo.getState();
                     switch (state) {
                         case WAITING:
@@ -286,4 +282,10 @@ public class DownLoadTvAdp extends BaseAdapter {
             }
         }
     }
+    private void startTask(){
+        JSONObject object = new JSONObject();
+        object.put("device_id", new DeviceUtils(mContext).getIMEI()+"");
+        object.put("release_task_id", Integer.valueOf(task_entity.getRelease_task_id()+""));
+        preference.acceptedTask(object);
+    }
 }

+ 9 - 5
app/src/main/java/com/sheep/gamegroup/view/adapter/TaskStateAdapter.java

@@ -10,7 +10,10 @@ import android.widget.BaseAdapter;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.alibaba.fastjson.JSONObject;
+import com.kfzs.duanduan.utils.dlg.DeviceUtils;
 import com.sheep.gamegroup.model.entity.TaskState;
+import com.sheep.gamegroup.presenter.TaskDialogPresenter;
 import com.sheep.jiuyan.samllsheep.R;
 
 import java.util.List;
@@ -40,7 +43,7 @@ public class TaskStateAdapter extends BaseAdapter {
 
     @Override
     public long getItemId(int position) {
-        return 0;
+        return position;
     }
 
     @SuppressLint("ResourceAsColor")
@@ -61,13 +64,13 @@ public class TaskStateAdapter extends BaseAdapter {
         if(getItem(position).getStatus() == 2){
 
             holder.point_iv.setImageResource(R.mipmap.tast_state_piont_ok_img);
-            holder.line_view.setBackgroundColor(R.color.yellow2_end);
-            holder.name_tv.setTextColor(R.color.yellow2_end);
+            holder.line_view.setBackgroundColor(context.getResources().getColor(R.color.yellow2_end));
+            holder.name_tv.setTextColor(context.getResources().getColor(R.color.yellow2_end));
         }else {
 
             holder.point_iv.setImageResource(R.mipmap.tast_state_piont_no_img);
-            holder.line_view.setBackgroundColor(R.color.txt_black_9e9c9c);
-            holder.name_tv.setTextColor(R.color.black);
+            holder.line_view.setBackgroundColor(context.getResources().getColor(R.color.txt_black_9e9c9c));
+            holder.name_tv.setTextColor(context.getResources().getColor(R.color.black));
         }
         if(position == getCount()-1){
             holder.line_view.setVisibility(View.GONE);
@@ -83,4 +86,5 @@ public class TaskStateAdapter extends BaseAdapter {
         View line_view;
         TextView name_tv;
     }
+
 }

+ 24 - 0
app/src/main/res/layout/dowanload_tv_item.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+
+    <TextView
+        android:id="@+id/start_task_tv"
+        android:layout_width="151dp"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_marginLeft="@dimen/content_padding_40"
+        android:layout_marginRight="@dimen/content_padding_40"
+        android:layout_marginTop="@dimen/content_padding_small"
+        android:background="@drawable/sp_bg_gradient_rectangle_yellow"
+        android:gravity="center"
+        android:minHeight="36dp"
+        android:minWidth="151dp"
+        android:text="开始任务"
+        android:textSize="18sp"
+        android:textColor="@color/txt_black"
+        android:visibility="visible"/>
+
+</RelativeLayout>

+ 9 - 11
app/src/main/res/layout/download_item_dialog.xml

@@ -18,15 +18,14 @@
             android:layout_height="wrap_content"
             android:minWidth="300dp"
             android:minHeight="196dp"
-            android:orientation="horizontal"
-            android:background="@drawable/x_shap_shadow_bg_rectgangle_white">
+            android:orientation="horizontal">
 
             <RelativeLayout
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:layout_alignParentRight="@dimen/view_size_60"
-                android:layout_marginTop="@dimen/content_padding"
-                android:padding="@dimen/content_padding">
+                android:layout_margin="@dimen/content_padding_10"
+                android:padding="@dimen/content_padding_20"
+                android:background="@drawable/x_shap_shadow_bg_rectgangle_white">
 
                 <ImageView
                     android:id="@+id/dialog_item_icon_iv"
@@ -161,13 +160,12 @@
 
             <ImageView
                 android:id="@+id/dialog_item_x"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:minHeight="@dimen/view_size_20"
-                android:minWidth="@dimen/view_size_20"
-                android:layout_alignParentRight="true"
+                android:layout_width="22dp"
+                android:layout_height="22dp"
+                android:padding="2dp"
+                android:layout_alignParentEnd="true"
                 android:src="@mipmap/try_dialog_x"
-                android:layout_margin="@dimen/content_padding"/>
+                android:background="@drawable/shape_black_ring"/>
         </RelativeLayout>
     </ScrollView>
 </RelativeLayout>

+ 3 - 2
app/src/main/res/layout/task_state_item.xml

@@ -6,13 +6,14 @@
 
     <RelativeLayout
         android:layout_width="wrap_content"
-        android:layout_height="wrap_content">
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/content_padding_2">
 
         <ImageView
             android:id="@+id/point_iv"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:src="@mipmap/tast_state_piont_ok_img"/>
+            android:src="@mipmap/tast_state_piont_no_img"/>
         <View
             android:id="@+id/line_view"
             android:layout_width="1dp"

+ 1 - 0
app/src/main/res/values/common.xml

@@ -68,6 +68,7 @@
 
     <!--APP中的主要内容的各种间距值pading默认值和较大值-->
     <dimen name="content_padding_3">3dp</dimen>
+    <dimen name="content_padding_2">2dp</dimen>
     <dimen name="content_padding_small">6dp</dimen>
     <dimen name="content_padding_8">8dp</dimen>
     <dimen name="content_padding_big">18dp</dimen>