|
|
@@ -1,407 +0,0 @@
|
|
|
-package com.sheep.gamegroup.view.adapter;
|
|
|
-
|
|
|
-import android.app.Activity;
|
|
|
-import android.app.DownloadManager;
|
|
|
-import android.content.ClipData;
|
|
|
-import android.content.ClipboardManager;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.DialogInterface;
|
|
|
-import android.content.Intent;
|
|
|
-import android.net.Uri;
|
|
|
-import android.support.v7.app.AlertDialog;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.view.LayoutInflater;
|
|
|
-import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
-import android.widget.BaseAdapter;
|
|
|
-import android.widget.ImageView;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.bumptech.glide.Glide;
|
|
|
-import com.bumptech.glide.request.RequestOptions;
|
|
|
-import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
|
|
|
-import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
-import com.sheep.gamegroup.model.entity.TaskReleaseEty;
|
|
|
-import com.sheep.gamegroup.presenter.TryMakeMoneyPresenter;
|
|
|
-import com.sheep.gamegroup.util.CommonUtil;
|
|
|
-import com.sheep.gamegroup.util.Jump2View;
|
|
|
-import com.sheep.gamegroup.util.SelfCountDownTimer;
|
|
|
-import com.sheep.gamegroup.util.TimeUtil;
|
|
|
-import com.sheep.gamegroup.util.UMConfigUtils;
|
|
|
-import com.sheep.jiuyan.samllsheep.R;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-import javax.inject.Inject;
|
|
|
-
|
|
|
-import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by ljy on 2018/4/27.
|
|
|
- */
|
|
|
-
|
|
|
-public class TryMakeMoneyAdb2 extends BaseAdapter {
|
|
|
- private HashMap<View, SelfCountDownTimer> timerHashMap= new HashMap<>();
|
|
|
- private ArrayList<Object> list;
|
|
|
- private Context context;
|
|
|
- @Inject
|
|
|
- TryMakeMoneyPresenter presenter;
|
|
|
- private int type = 0;//0:推荐 1:热门 2:预约
|
|
|
-
|
|
|
- public TryMakeMoneyAdb2(ArrayList<Object> list, Context context) {
|
|
|
- this.list = list;
|
|
|
- this.context = context;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 传入presenter
|
|
|
- */
|
|
|
- public void addPresenter(TryMakeMoneyPresenter presenter){
|
|
|
- this.presenter = presenter;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 传入type
|
|
|
- */
|
|
|
- public void addType(int type){
|
|
|
- this.type = type;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 传入正在运行的任务
|
|
|
- * @param taskAcceptedEty
|
|
|
- */
|
|
|
- public void setTaskAcceptedEty(TaskAcceptedEty taskAcceptedEty) {
|
|
|
- this.taskAcceptedEty = taskAcceptedEty;
|
|
|
- }
|
|
|
- private TaskAcceptedEty taskAcceptedEty;
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getCount() {
|
|
|
- return list.size();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object getItem(int position) {
|
|
|
- return list.get(position);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public long getItemId(int position) {
|
|
|
- return position;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
- ViewHolder holder = null;
|
|
|
- if(holder == null){
|
|
|
- holder = new ViewHolder();
|
|
|
- convertView = LayoutInflater.from(context).inflate(R.layout.try_makemoney_item_recommend, null);
|
|
|
- holder.item_title_tv = convertView.findViewById(R.id.item_title_tv);
|
|
|
- holder.item_money = convertView.findViewById(R.id.item_money);
|
|
|
- holder.item_anem_tv = convertView.findViewById(R.id.item_anem_tv);
|
|
|
- holder.item_num_tv = convertView.findViewById(R.id.item_num_tv);
|
|
|
- holder.item_date_tv = convertView.findViewById(R.id.item_date_tv);
|
|
|
- holder.detail_task_tv = convertView.findViewById(R.id.detail_task_tv);
|
|
|
- holder.countdown_tv = convertView.findViewById(R.id.countdown_tv);
|
|
|
- holder.item_num_tv = convertView.findViewById(R.id.item_num_tv);
|
|
|
- holder.item_title_iv = convertView.findViewById(R.id.item_title_iv);
|
|
|
- holder.item_icon_iv = convertView.findViewById(R.id.item_icon_iv);
|
|
|
- holder.line_tv = convertView.findViewById(R.id.line_tv);
|
|
|
- convertView.setTag(holder);
|
|
|
- }else {
|
|
|
- holder = (ViewHolder) convertView.getTag();
|
|
|
- }
|
|
|
-
|
|
|
- Object object = getItem(position);
|
|
|
- if(object == null){
|
|
|
- return convertView;
|
|
|
- }
|
|
|
- if(object instanceof TaskReleaseEty){
|
|
|
- otherTask(holder, convertView, (TaskReleaseEty) object,position);
|
|
|
- }else {//正在运行中
|
|
|
- runTask(holder, convertView, (TaskAcceptedEty) object);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return convertView;
|
|
|
- }
|
|
|
-
|
|
|
- class ViewHolder{
|
|
|
- TextView item_title_tv, item_money, item_anem_tv, item_num_tv,
|
|
|
- item_date_tv, detail_task_tv, countdown_tv, line_tv;
|
|
|
- ImageView item_title_iv, item_icon_iv;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 正在运行中的任务
|
|
|
- */
|
|
|
- private void runTask(ViewHolder viewHolder,View convertView, final TaskAcceptedEty taskAcceptedEty){
|
|
|
- viewHolder.line_tv.setVisibility(View.GONE);
|
|
|
- viewHolder.item_title_tv.setVisibility(View.VISIBLE);
|
|
|
- viewHolder.item_title_tv.setText("进行中");
|
|
|
-
|
|
|
-
|
|
|
- viewHolder.item_anem_tv.setText(taskAcceptedEty.getRelease_task().getName()+"");
|
|
|
- viewHolder.item_num_tv.setText("剩余"+ taskAcceptedEty.getRelease_task().getLast_num()+"份");
|
|
|
- viewHolder.item_money.setText("+"+ taskAcceptedEty.getRelease_task().getBonus() +"元");
|
|
|
- viewHolder.item_date_tv.setText(
|
|
|
- "截止时间:" + TimeUtil.getDate(TimeUtil.FORMAT, Long.valueOf(taskAcceptedEty.getRelease_task().getDeadline()+"")));
|
|
|
-
|
|
|
- viewHolder.detail_task_tv.setText("取消任务");
|
|
|
- viewHolder.detail_task_tv.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
-
|
|
|
- presenter.giveUpTask(taskAcceptedEty.getId());
|
|
|
- //暂停下载
|
|
|
- CommonUtil.getInstance().stopDownloadTask(context, taskAcceptedEty.getRelease_task().getTask().getDownload_link());
|
|
|
- }
|
|
|
- });
|
|
|
- Glide.with(context)
|
|
|
- .load(taskAcceptedEty.getRelease_task().getTask().getIcon()+"")
|
|
|
- .apply(new RequestOptions().placeholder(R.mipmap.x_ic_def_head))
|
|
|
- .into(viewHolder.item_icon_iv);
|
|
|
- convertView.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
-
|
|
|
- TaskEty taskEty = taskAcceptedEty.getRelease_task().getTask();
|
|
|
- taskEty.setRunTask(1);
|
|
|
- taskEty.setBonus(taskAcceptedEty.getRelease_task().getBonus());
|
|
|
- taskEty.setRelease_task_id(taskAcceptedEty.getRelease_task().getId());
|
|
|
- taskEty.setAcceptedTaskId(taskAcceptedEty.getId());
|
|
|
- taskEty.setName(taskAcceptedEty.getRelease_task().getName());
|
|
|
- Jump2View.getInstance().goTaskDetailView(context, taskEty, taskAcceptedEty);
|
|
|
- UMConfigUtils.onEvent(UMConfigUtils.Event.TASK_DETAIL);
|
|
|
- }
|
|
|
- });
|
|
|
- setDebugDownLoad(context, convertView, taskAcceptedEty.getRelease_task().getTask());
|
|
|
-
|
|
|
- /**
|
|
|
- * 倒计时
|
|
|
- */
|
|
|
- if(taskAcceptedEty.getRelease_task().getCancel_duration() > 0){
|
|
|
- final TextView countdown_tv = viewHolder.countdown_tv;
|
|
|
- SelfCountDownTimer scTimer = timerHashMap.get(countdown_tv);
|
|
|
- if(scTimer != null){
|
|
|
- scTimer.cancel();
|
|
|
- scTimer = null;
|
|
|
- }
|
|
|
-
|
|
|
- countdown_tv.setVisibility(View.VISIBLE);
|
|
|
- String sr = "若<font color='#ff2d4b'><small>" + "" + "</small></font>后任务未完成,该任务自动取消,您可以重新接受该任务";
|
|
|
- countdown_tv.setText(sr+"");
|
|
|
- SelfCountDownTimer selfCountDownTimer = new SelfCountDownTimer( taskAcceptedEty.getRelease_task().getCancel_duration() * 1000, 1000, taskAcceptedEty.getRelease_task().getCancel_duration()) {
|
|
|
- @Override
|
|
|
- public void onTimerRest() {
|
|
|
- countdown_tv.setText("");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onTimerTick(long millisUntilFinished, int counTime) {
|
|
|
- countdown_tv.setText(CommonUtil.getInstance().assemblyString(TimeUtil.getHours(millisUntilFinished))+"");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onTimerFinish() {
|
|
|
- countdown_tv.setVisibility(View.GONE);
|
|
|
- presenter.giveUpTask(taskAcceptedEty.getId());
|
|
|
- //暂停下载
|
|
|
- CommonUtil.getInstance().stopDownloadTask(context, taskAcceptedEty.getRelease_task().getTask().getDownload_link());
|
|
|
- }
|
|
|
- };
|
|
|
- selfCountDownTimer.reset(taskAcceptedEty.getRelease_task().getCancel_duration());
|
|
|
- selfCountDownTimer.start();
|
|
|
- timerHashMap.put(countdown_tv, selfCountDownTimer);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 其他任务
|
|
|
- */
|
|
|
- private void otherTask(ViewHolder viewHolder, View convertView, final TaskReleaseEty taskReleaseEty,int i){
|
|
|
- if(i == 0){
|
|
|
- viewHolder.item_title_tv.setVisibility(View.VISIBLE);
|
|
|
- viewHolder.item_title_iv.setVisibility(View.VISIBLE);
|
|
|
- String titleStr = "推荐";
|
|
|
- switch (type){
|
|
|
- case 0:
|
|
|
- titleStr = "推荐";
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- titleStr = "热门任务";
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- titleStr = "即将开始";
|
|
|
- break;
|
|
|
- default:
|
|
|
- titleStr = "推荐";
|
|
|
- break;
|
|
|
- }
|
|
|
- viewHolder.item_title_tv.setText(titleStr+"");
|
|
|
- Glide.with(context)
|
|
|
- .load(new RequestOptions().placeholder(R.mipmap.task_hot_icon))
|
|
|
- .into(viewHolder.item_title_iv);
|
|
|
-
|
|
|
- }else{
|
|
|
- viewHolder.item_title_tv.setVisibility(View.GONE);
|
|
|
- viewHolder.item_title_iv.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- if(i == getCount()-1){
|
|
|
- viewHolder.line_tv.setVisibility(View.GONE);
|
|
|
- }else {
|
|
|
- viewHolder.line_tv.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
- viewHolder.item_anem_tv.setText(taskReleaseEty.getName()+"");
|
|
|
- viewHolder.item_num_tv.setText("剩余"+ taskReleaseEty.getLast_num()+"份");
|
|
|
- viewHolder.item_money.setText("+"+ taskReleaseEty.getBonus() +"元");
|
|
|
- viewHolder.item_date_tv.setText(
|
|
|
- "截止时间:" + TimeUtil.getDate(TimeUtil.FORMAT, Long.valueOf(taskReleaseEty.getDeadline()+"")));
|
|
|
- viewHolder.detail_task_tv.setText("领取任务");
|
|
|
- viewHolder.detail_task_tv.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- TaskEty taskEty = taskReleaseEty.getTask();
|
|
|
- taskEty.setRunTask(0);
|
|
|
- taskEty.setRelease_task_id(taskReleaseEty.getId());
|
|
|
- taskEty.setName(taskReleaseEty.getName());
|
|
|
- Jump2View.getInstance().goDialogActivityView(context, taskEty, taskAcceptedEty);
|
|
|
- }
|
|
|
- });
|
|
|
- Glide.with(context)
|
|
|
- .load(taskReleaseEty.getTask().getIcon()+"")
|
|
|
- .apply(new RequestOptions().placeholder(R.mipmap.x_ic_def_head))
|
|
|
- .into( viewHolder.item_icon_iv);
|
|
|
- convertView.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
-
|
|
|
- TaskEty taskEty = taskReleaseEty.getTask();
|
|
|
- taskEty.setRunTask(0);
|
|
|
- taskEty.setBonus(taskReleaseEty.getBonus());
|
|
|
- taskEty.setRelease_task_id(taskReleaseEty.getId());
|
|
|
- taskEty.setName(taskReleaseEty.getName());
|
|
|
- Jump2View.getInstance().goTaskDetailView(context, taskEty, taskAcceptedEty);
|
|
|
- }
|
|
|
- });
|
|
|
- setDebugDownLoad(context, convertView, taskReleaseEty.getTask());
|
|
|
- }
|
|
|
-
|
|
|
- public static void setDebugDownLoad(final Context context, View view, final TaskEty taskEty) {
|
|
|
- view.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
- @Override
|
|
|
- public boolean onLongClick(View view) {
|
|
|
- final String[] items = {"复制", "系统下载", "浏览器下载"};
|
|
|
- AlertDialog dialog = new AlertDialog.Builder(context).setTitle("请选择操作")
|
|
|
- .setItems(items, new DialogInterface.OnClickListener() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- switch (items[which]){
|
|
|
- case "复制":
|
|
|
- debugCopy(context, taskEty);
|
|
|
- break;
|
|
|
- case "系统下载":
|
|
|
- debugSysDownload(context, taskEty);
|
|
|
- break;
|
|
|
- case "浏览器下载":
|
|
|
- debugWebDownload(context, taskEty);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }).create();
|
|
|
- dialog.show();
|
|
|
- return true;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private static void debugCopy(final Context context, final TaskEty taskEty) {
|
|
|
- ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
- if(clipboardManager != null && !TextUtils.isEmpty(taskEty.getDownload_link())) {
|
|
|
- //创建ClipData对象
|
|
|
- ClipData clipData = ClipData.newPlainText("sheep text copy", taskEty.getDownload_link());
|
|
|
- //添加ClipData对象到剪切板中
|
|
|
- clipboardManager.setPrimaryClip(clipData);
|
|
|
- G.showToast("已经复制游戏下载链接");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static void debugSysDownload(final Context context, final TaskEty taskEty) {
|
|
|
- // 创建下载请求
|
|
|
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(taskEty.getDownload_link()));
|
|
|
-
|
|
|
- /*
|
|
|
- * 设置在通知栏是否显示下载通知(下载进度), 有 3 个值可选:
|
|
|
- * VISIBILITY_VISIBLE: 下载过程中可见, 下载完后自动消失 (默认)
|
|
|
- * VISIBILITY_VISIBLE_NOTIFY_COMPLETED: 下载过程中和下载完成后均可见
|
|
|
- * VISIBILITY_HIDDEN: 始终不显示通知
|
|
|
- */
|
|
|
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
|
|
-
|
|
|
- // 设置通知的标题和描述
|
|
|
- request.setTitle(taskEty.getTask_name());
|
|
|
- request.setDescription("下载小绵羊任务中的apk:"+taskEty.getPackage_names());
|
|
|
-
|
|
|
- /*
|
|
|
- * 设置允许使用的网络类型, 可选值:
|
|
|
- * NETWORK_MOBILE: 移动网络
|
|
|
- * NETWORK_WIFI: WIFI网络
|
|
|
- * NETWORK_BLUETOOTH: 蓝牙网络
|
|
|
- * 默认为所有网络都允许
|
|
|
- */
|
|
|
-// request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
|
|
|
-
|
|
|
- // 添加请求头
|
|
|
- // request.addRequestHeader("User-Agent", "Chrome Mozilla/5.0");
|
|
|
-
|
|
|
- // 设置下载文件的保存位置
|
|
|
- File saveFile = new File(DIR, taskEty.getTask_name()+".apk");
|
|
|
- request.setDestinationUri(Uri.fromFile(saveFile));
|
|
|
-
|
|
|
- /*
|
|
|
- * 2. 获取下载管理器服务的实例, 添加下载任务
|
|
|
- */
|
|
|
- DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
- if(manager != null) {
|
|
|
- // 将下载请求加入下载队列, 返回一个下载ID
|
|
|
- long downloadId = manager.enqueue(request);
|
|
|
- G.showToast("系统开始下载apk");
|
|
|
- }
|
|
|
- }
|
|
|
- private static void debugWebDownload(final Context context, final TaskEty taskEty) {
|
|
|
- if(context instanceof Activity) {
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.setAction(Intent.ACTION_VIEW);
|
|
|
- intent.addCategory(Intent.CATEGORY_BROWSABLE);
|
|
|
- intent.setData(Uri.parse(taskEty.getDownload_link()));
|
|
|
- context.startActivity(intent);
|
|
|
- G.showToast("浏览器开始下载apk");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重置map参数
|
|
|
- */
|
|
|
- public void cancelAllTimers() {
|
|
|
- Set<Map.Entry<View, SelfCountDownTimer>> s = timerHashMap.entrySet();
|
|
|
- Iterator it = s.iterator();
|
|
|
- while (it.hasNext()) {
|
|
|
- try {
|
|
|
- Map.Entry pairs = (Map.Entry) it.next();
|
|
|
- SelfCountDownTimer cdt = (SelfCountDownTimer) pairs.getValue();
|
|
|
- cdt.cancel();
|
|
|
- cdt = null;
|
|
|
- } catch (Exception ignored) {
|
|
|
- }
|
|
|
- }
|
|
|
- it = null;
|
|
|
- s = null;
|
|
|
- timerHashMap.clear();
|
|
|
- }
|
|
|
-}
|