1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-21 22:27:29 +00:00
This commit is contained in:
Austin Huang 2021-06-30 18:13:51 -04:00
parent a6b2031950
commit 8dc128563a
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
14 changed files with 53 additions and 49 deletions

View File

@ -226,7 +226,7 @@ public final class FeedAdapterV2 extends ListAdapter<Media, RecyclerView.ViewHol
void onCommentsClick(final Media feedModel);
void onDownloadClick(final Media feedModel, final int childPosition);
void onDownloadClick(final Media feedModel, final int childPosition, final View popupLocation);
void onEmailClick(final String emailId);

View File

@ -28,7 +28,7 @@ public class FeedItemCallbackAdapter implements FeedAdapterV2.FeedItemCallback {
public void onCommentsClick(final Media media) {}
@Override
public void onDownloadClick(final Media media, final int childPosition) {}
public void onDownloadClick(final Media media, final int childPosition, final View popupLocation) {}
@Override
public void onEmailClick(final String emailId) {}

View File

@ -47,7 +47,9 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
setupComments(media);
setupCaption(media);
if (media.getType() != MediaItemType.MEDIA_TYPE_SLIDER) {
bottomBinding.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(media, -1));
bottomBinding.btnDownload.setOnClickListener(v ->
feedItemCallback.onDownloadClick(media, -1, null)
);
}
bindItem(media);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
});
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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?) {

View File

@ -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

View File

@ -6,4 +6,6 @@
<item name="detail" type="id" />
<item name="copy" type="id" />
<item name="share_dm" type="id" />
<item name="download_current" type="id" />
<item name="download_all" type="id" />
</resources>