From 8dc128563af0826dd5518b9fbd64419803308453 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Wed, 30 Jun 2021 18:13:51 -0400 Subject: [PATCH] close #517 --- .../instagrabber/adapters/FeedAdapterV2.java | 2 +- .../adapters/FeedItemCallbackAdapter.java | 2 +- .../viewholder/feed/FeedItemViewHolder.java | 4 +- .../viewholder/feed/FeedSliderViewHolder.java | 8 +++- .../fragments/CollectionPostsFragment.java | 4 +- .../fragments/HashTagFragment.java | 4 +- .../fragments/LocationFragment.java | 4 +- .../fragments/PostViewV2Fragment.java | 12 ++--- .../fragments/SavedViewerFragment.java | 4 +- .../fragments/TopicPostsFragment.java | 4 +- .../fragments/main/FeedFragment.java | 4 +- .../fragments/main/ProfileFragment.kt | 4 +- .../awais/instagrabber/utils/DownloadUtils.kt | 44 ++++++++++--------- app/src/main/res/values/ids.xml | 2 + 14 files changed, 53 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/FeedAdapterV2.java b/app/src/main/java/awais/instagrabber/adapters/FeedAdapterV2.java index ac94b02c..102640a6 100644 --- a/app/src/main/java/awais/instagrabber/adapters/FeedAdapterV2.java +++ b/app/src/main/java/awais/instagrabber/adapters/FeedAdapterV2.java @@ -226,7 +226,7 @@ public final class FeedAdapterV2 extends ListAdapter feedItemCallback.onDownloadClick(media, -1)); + bottomBinding.btnDownload.setOnClickListener(v -> + feedItemCallback.onDownloadClick(media, -1, null) + ); } bindItem(media); } diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedSliderViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedSliderViewHolder.java index 6931c851..66902340 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedSliderViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedSliderViewHolder.java @@ -59,11 +59,15 @@ public class FeedSliderViewHolder extends FeedItemViewHolder { final String text = (position + 1) + "/" + sliderItemLen; binding.mediaCounter.setText(text); setDimensions(binding.mediaList, sliderItems.get(position)); - binding.itemFeedBottom.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(feedModel, position)); + binding.itemFeedBottom.btnDownload.setOnClickListener(v -> + feedItemCallback.onDownloadClick(feedModel, position, binding.itemFeedBottom.btnDownload) + ); } }); setDimensions(binding.mediaList, sliderItems.get(0)); - binding.itemFeedBottom.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(feedModel, 0)); + binding.itemFeedBottom.btnDownload.setOnClickListener(v -> + feedItemCallback.onDownloadClick(feedModel, 0, binding.itemFeedBottom.btnDownload) + ); adapter.submitList(sliderItems); } diff --git a/app/src/main/java/awais/instagrabber/fragments/CollectionPostsFragment.java b/app/src/main/java/awais/instagrabber/fragments/CollectionPostsFragment.java index 77e55bbe..f69ebcc9 100644 --- a/app/src/main/java/awais/instagrabber/fragments/CollectionPostsFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/CollectionPostsFragment.java @@ -126,10 +126,10 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay } @Override - public void onDownloadClick(final Media feedModel, final int childPosition) { + public void onDownloadClick(final Media feedModel, final int childPosition, final View popupLocation) { final Context context = getContext(); if (context == null) return; - DownloadUtils.showDownloadDialog(context, feedModel, childPosition); + DownloadUtils.showDownloadDialog(context, feedModel, childPosition, popupLocation); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java index d04c9389..189820f6 100644 --- a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java @@ -145,10 +145,10 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe } @Override - public void onDownloadClick(final Media feedModel, final int childPosition) { + public void onDownloadClick(final Media feedModel, final int childPosition, final View popupLocation) { final Context context = getContext(); if (context == null) return; - DownloadUtils.showDownloadDialog(context, feedModel, childPosition); + DownloadUtils.showDownloadDialog(context, feedModel, childPosition, popupLocation); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java index 6e18f5f0..17f1f1b9 100644 --- a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java @@ -139,10 +139,10 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR } @Override - public void onDownloadClick(final Media feedModel, final int childPosition) { + public void onDownloadClick(final Media feedModel, final int childPosition, final View popupLocation) { final Context context = getContext(); if (context == null) return; - DownloadUtils.showDownloadDialog(context, feedModel, childPosition); + DownloadUtils.showDownloadDialog(context, feedModel, childPosition, popupLocation); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index fd6d1ee5..9a987981 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -446,7 +446,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme private void setupDownload() { bottom.download.setOnClickListener(v -> { - DownloadUtils.showDownloadDialog(context, viewModel.getMedia(), sliderPosition); + DownloadUtils.showDownloadDialog(context, viewModel.getMedia(), sliderPosition, bottom.download); }); TooltipCompat.setTooltipText(bottom.download, getString(R.string.action_download)); } @@ -744,12 +744,6 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme final Media media = viewModel.getMedia(); final User profileModel = media.getUser(); if (profileModel == null) return; - final boolean isPrivate = profileModel.isPrivate(); - if (isPrivate) { - final Context context = getContext(); - if (context == null) return; -// Toast.makeText(context, R.string.share_private_post, Toast.LENGTH_LONG).show(); - } if (viewModel.isLoggedIn()) { final Context context = getContext(); if (context == null) return; @@ -776,7 +770,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme } return true; } else if (itemId == R.id.share) { - shareLink(media, isPrivate); + shareLink(media, profileModel.isPrivate()); return true; } return false; @@ -784,7 +778,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme popupMenu.show(); return; } - shareLink(media, isPrivate); + shareLink(media, false); }); } diff --git a/app/src/main/java/awais/instagrabber/fragments/SavedViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/SavedViewerFragment.java index 71d517b9..57c40b85 100644 --- a/app/src/main/java/awais/instagrabber/fragments/SavedViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/SavedViewerFragment.java @@ -109,10 +109,10 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL } @Override - public void onDownloadClick(final Media feedModel, final int childPosition) { + public void onDownloadClick(final Media feedModel, final int childPosition, final View popupLocation) { final Context context = getContext(); if (context == null) return; - DownloadUtils.showDownloadDialog(context, feedModel, childPosition); + DownloadUtils.showDownloadDialog(context, feedModel, childPosition, popupLocation); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/TopicPostsFragment.java b/app/src/main/java/awais/instagrabber/fragments/TopicPostsFragment.java index bba645a7..acbc2eef 100644 --- a/app/src/main/java/awais/instagrabber/fragments/TopicPostsFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/TopicPostsFragment.java @@ -120,10 +120,10 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O } @Override - public void onDownloadClick(final Media feedModel, final int childPosition) { + public void onDownloadClick(final Media feedModel, final int childPosition, final View popupLocation) { final Context context = getContext(); if (context == null) return; - DownloadUtils.showDownloadDialog(context, feedModel, childPosition); + DownloadUtils.showDownloadDialog(context, feedModel, childPosition, popupLocation); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java index ae4e9b6b..593ea96f 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java @@ -116,10 +116,10 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre } @Override - public void onDownloadClick(final Media feedModel, final int childPosition) { + public void onDownloadClick(final Media feedModel, final int childPosition, final View popupLocation) { final Context context = getContext(); if (context == null) return; - DownloadUtils.showDownloadDialog(context, feedModel, childPosition); + DownloadUtils.showDownloadDialog(context, feedModel, childPosition, popupLocation); } @Override diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt index 82d6a078..9c2ef9ae 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt @@ -127,8 +127,8 @@ class ProfileFragment : Fragment(), OnRefreshListener, ConfirmDialogFragmentCall NavHostFragment.findNavController(this@ProfileFragment).navigate(commentsAction) } - override fun onDownloadClick(media: Media?, childPosition: Int) { - DownloadUtils.showDownloadDialog(context ?: return, media ?: return, childPosition) + override fun onDownloadClick(media: Media?, childPosition: Int, popupLocation: View) { + DownloadUtils.showDownloadDialog(context ?: return, media ?: return, childPosition, popupLocation) } override fun onEmailClick(emailId: String?) { diff --git a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt index e2491caa..c330d3e4 100644 --- a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt +++ b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.kt @@ -6,8 +6,12 @@ import android.content.UriPermission import android.net.Uri import android.provider.DocumentsContract import android.util.Log +import android.view.MenuItem +import android.view.View import android.widget.Toast import androidx.appcompat.app.AlertDialog +import androidx.appcompat.view.ContextThemeWrapper +import androidx.appcompat.widget.PopupMenu import androidx.core.util.Pair import androidx.documentfile.provider.DocumentFile import androidx.work.* @@ -397,30 +401,28 @@ object DownloadUtils { fun showDownloadDialog( context: Context, feedModel: Media, - childPosition: Int + childPosition: Int, + popupLocation: View? ) { - if (childPosition >= 0) { - val clickListener = - DialogInterface.OnClickListener { dialog: DialogInterface, which: Int -> - when (which) { - 0 -> download(context, feedModel, childPosition) - 1 -> download(context, feedModel) - DialogInterface.BUTTON_NEGATIVE -> dialog.dismiss() - else -> dialog.dismiss() - } - } - val items = arrayOf( - context.getString(R.string.post_viewer_download_current), - context.getString(R.string.post_viewer_download_album) - ) - AlertDialog.Builder(context) - .setTitle(R.string.post_viewer_download_dialog_title) - .setItems(items, clickListener) - .setNegativeButton(R.string.cancel, null) - .show() + if (childPosition == -1 || popupLocation == null) { + download(context, feedModel) return } - download(context, feedModel) + val themeWrapper = ContextThemeWrapper(context, R.style.popupMenuStyle) + val popupMenu = PopupMenu(themeWrapper, popupLocation) + val menu = popupMenu.menu + menu.add(0, R.id.download_current, 0, R.string.post_viewer_download_current) + menu.add(0, R.id.download_all, 1, R.string.post_viewer_download_album) + popupMenu.setOnMenuItemClickListener { item: MenuItem -> + val itemId = item.itemId + if (itemId == R.id.download_current) { + download(context, feedModel, childPosition) + } else if (itemId == R.id.download_all) { + download(context, feedModel) + } + false + } + popupMenu.show() } @JvmStatic diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index d94430a5..29c6fecc 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -6,4 +6,6 @@ + + \ No newline at end of file