|
|
@@ -5,10 +5,12 @@ 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.os.Environment;
|
|
|
import android.support.design.widget.AppBarLayout;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.support.v7.widget.StaggeredGridLayoutManager;
|
|
|
@@ -187,7 +189,7 @@ public class TryMakeMoneyAdp extends AdpCommonRecy<RecyleObj> {
|
|
|
Jump2View.getInstance().goDialogActivityView(context, taskEty);
|
|
|
}
|
|
|
});
|
|
|
- test(viewHolder, etyList.get(i).getTask());
|
|
|
+ setDebugDownLoad(context, viewHolder.itemView, etyList.get(i).getTask());
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -253,89 +255,103 @@ public class TryMakeMoneyAdp extends AdpCommonRecy<RecyleObj> {
|
|
|
Jump2View.getInstance().goDialogActivityView(context, taskEty);
|
|
|
}
|
|
|
});
|
|
|
+ setDebugDownLoad(context, holder.itemView, acceptedEty.getRelease_task().getTask());
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void test(RecyclerView.ViewHolder viewHolder, final TaskEty taskEty) {
|
|
|
-
|
|
|
+ public static void setDebugDownLoad(final Context context, View view, final TaskEty taskEty) {
|
|
|
if(BuildConfig.DEBUG){
|
|
|
- viewHolder.itemView.findViewById(R.id.item_icon_iv).setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
+ view.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
@Override
|
|
|
public boolean onLongClick(View view) {
|
|
|
- // 创建下载请求
|
|
|
- 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);
|
|
|
- return downloadId !=0;
|
|
|
- }
|
|
|
+ final String[] items = {"复制", "系统下载", "浏览器下载"};
|
|
|
+ AlertDialog dialog = new AlertDialog.Builder(context).setTitle("请选择操作")
|
|
|
+ .setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
- viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
- @Override
|
|
|
- public boolean onLongClick(View view) {
|
|
|
- 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");
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
- (viewHolder.itemView.findViewById(R.id.detail_task_tv)).setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
- @Override
|
|
|
- public boolean onLongClick(View view) {
|
|
|
- ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
- if(clipboardManager != null) {
|
|
|
- //创建ClipData对象
|
|
|
- ClipData clipData = ClipData.newPlainText("sheep text copy", taskEty.getDownload_link());
|
|
|
- //添加ClipData对象到剪切板中
|
|
|
- clipboardManager.setPrimaryClip(clipData);
|
|
|
- G.showToast("已经复制下载链接");
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
+ @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) {
|
|
|
+ //创建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");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|