From 04ae2c1b4bde19398bb74d591f7b0b2d1ccdfcbf Mon Sep 17 00:00:00 2001 From: seven332 Date: Tue, 15 Mar 2016 01:24:25 +0800 Subject: [PATCH] Long click download button to download with default label --- .../hippo/ehviewer/ui/CommonOperations.java | 4 +-- .../ehviewer/ui/scene/GalleryDetailScene.java | 26 ++++++++++++------- .../ehviewer/ui/scene/GalleryListScene.java | 2 +- .../hippo/ehviewer/ui/scene/HistoryScene.java | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java index 6ebdec42e..bf4d7a385 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java @@ -216,10 +216,10 @@ public final class CommonOperations { client.execute(request); } - public static void startDownload(final Activity activity, final GalleryInfo galleryInfo) { + public static void startDownload(final Activity activity, final GalleryInfo galleryInfo, boolean forceDefault) { final DownloadManager dm = EhApplication.getDownloadManager(activity); - boolean justStart = dm.containDownloadInfo(galleryInfo.gid); + boolean justStart = forceDefault || dm.containDownloadInfo(galleryInfo.gid); String label = null; // Get default download label if (!justStart && Settings.getHasDefaultDownloadLabel()) { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java index 3c87823cf..c96c9cdf3 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java @@ -104,7 +104,8 @@ import java.util.List; import java.util.Locale; public class GalleryDetailScene extends BaseScene implements View.OnClickListener, - com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener { + com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener, + View.OnLongClickListener{ @IntDef({STATE_INIT, STATE_NORMAL, STATE_REFRESH, STATE_REFRESH_HEADER, STATE_FAILED}) @Retention(RetentionPolicy.SOURCE) @@ -421,6 +422,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene mCategory.setOnClickListener(this); mOtherActions.setOnClickListener(this); mDownload.setOnClickListener(this); + mDownload.setOnLongClickListener(this); mRead.setOnClickListener(this); mBelowHeader = mainView.findViewById(R.id.below_header); @@ -987,15 +989,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene lub.setCategory(category); GalleryListScene.startScene(this, lub); } else if (mDownload == v) { - // Add download - GalleryInfo galleryInfo = null; - if (mGalleryInfo != null) { - galleryInfo = mGalleryInfo; - } else if (mGalleryDetail != null) { - galleryInfo = mGalleryDetail; - } + GalleryInfo galleryInfo = getGalleryInfo(); if (galleryInfo != null) { - CommonOperations.startDownload(getActivity(), galleryInfo); + CommonOperations.startDownload(getActivity(), galleryInfo, false); } } else if (mRead == v) { GalleryInfo galleryInfo = null; @@ -1106,6 +1102,18 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene } } + @Override + public boolean onLongClick(View v) { + if (mDownload == v) { + GalleryInfo galleryInfo = getGalleryInfo(); + if (galleryInfo != null) { + CommonOperations.startDownload(getActivity(), galleryInfo, true); + } + return true; + } + return false; + } + @Override public void onBackPressed() { if (ApiHelper.SUPPORT_TRANSITION && mViewTransition != null && mThumb != null && diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java index 4aaf5e869..500c64585 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java @@ -588,7 +588,7 @@ public final class GalleryListScene extends BaseScene public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: // Download - CommonOperations.startDownload(getActivity(), gi); + CommonOperations.startDownload(getActivity(), gi, false); break; case 1: // Favorites CommonOperations.addToFavorites(getActivity(), gi, diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java index 54b5ae2d3..1d1453733 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.java @@ -174,7 +174,7 @@ public class HistoryScene extends ToolbarScene public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: // Download - CommonOperations.startDownload(getActivity(), gi); + CommonOperations.startDownload(getActivity(), gi, false); break; case 1: // Favorites CommonOperations.addToFavorites(getActivity(), gi,