From a705512dc5122fbda0c389b007600c1305f4eb68 Mon Sep 17 00:00:00 2001 From: Grishka Date: Mon, 5 Jun 2023 04:25:11 +0300 Subject: [PATCH] Update post options menu (AND-33) --- .../displayitems/FooterStatusDisplayItem.java | 5 +--- .../displayitems/HeaderStatusDisplayItem.java | 23 +++++++----------- .../android/ui/utils/UiUtils.java | 7 ++++++ mastodon/src/main/res/menu/post.xml | 24 ++++++++++++------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java index bffd9f51..e35f3413 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java @@ -162,10 +162,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{ } private void onShareClick(View v){ - Intent intent=new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, item.status.url); - v.getContext().startActivity(Intent.createChooser(intent, v.getContext().getString(R.string.share_toot_title))); + UiUtils.openSystemShareSheet(v.getContext(), item.status.url); } private int descriptionForId(int id){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index 0565bec3..27006c8d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -5,6 +5,7 @@ import android.app.Activity; import android.app.ProgressDialog; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Bundle; import android.os.Parcel; import android.text.SpannableStringBuilder; @@ -131,6 +132,8 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ optionsMenu=new PopupMenu(activity, more); optionsMenu.inflate(R.menu.post); + if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.P) + optionsMenu.getMenu().setGroupDividerEnabled(true); optionsMenu.setOnMenuItemClickListener(menuItem->{ Account account=item.user; int id=menuItem.getItemId(); @@ -188,10 +191,10 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ relationship=rel; Toast.makeText(activity, activity.getString(rel.following ? R.string.followed_user : rel.requested ? R.string.following_user_requested : R.string.unfollowed_user, account.getDisplayUsername()), Toast.LENGTH_SHORT).show(); }); - }else if(id==R.id.block_domain){ - UiUtils.confirmToggleBlockDomain(activity, item.parentFragment.getAccountID(), account.getDomain(), relationship!=null && relationship.domainBlocking, ()->{}); }else if(id==R.id.bookmark){ AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setBookmarked(item.status, !item.status.bookmarked); + }else if(id==R.id.share){ + UiUtils.openSystemShareSheet(activity, item.status.url); } return true; }); @@ -279,7 +282,6 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ menu.findItem(R.id.edit).setVisible(item.status!=null && isOwnPost); menu.findItem(R.id.delete).setVisible(item.status!=null && isOwnPost); menu.findItem(R.id.open_in_browser).setVisible(item.status!=null); - MenuItem blockDomain=menu.findItem(R.id.block_domain); MenuItem mute=menu.findItem(R.id.mute); MenuItem block=menu.findItem(R.id.block); MenuItem report=menu.findItem(R.id.report); @@ -296,22 +298,15 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ block.setVisible(false); report.setVisible(false); follow.setVisible(false); - blockDomain.setVisible(false); }else{ mute.setVisible(true); block.setVisible(true); report.setVisible(true); follow.setVisible(relationship==null || relationship.following || (!relationship.blocking && !relationship.blockedBy && !relationship.domainBlocking && !relationship.muting)); - mute.setTitle(item.parentFragment.getString(relationship!=null && relationship.muting ? R.string.unmute_user : R.string.mute_user, account.getDisplayUsername())); - block.setTitle(item.parentFragment.getString(relationship!=null && relationship.blocking ? R.string.unblock_user : R.string.block_user, account.getDisplayUsername())); - report.setTitle(item.parentFragment.getString(R.string.report_user, account.getDisplayUsername())); - if(!account.isLocal()){ - blockDomain.setVisible(true); - blockDomain.setTitle(item.parentFragment.getString(relationship!=null && relationship.domainBlocking ? R.string.unblock_domain : R.string.block_domain, account.getDomain())); - }else{ - blockDomain.setVisible(false); - } - follow.setTitle(item.parentFragment.getString(relationship!=null && relationship.following ? R.string.unfollow_user : R.string.follow_user, account.getDisplayUsername())); + mute.setTitle(item.parentFragment.getString(relationship!=null && relationship.muting ? R.string.unmute_user : R.string.mute_user, account.displayName)); + block.setTitle(item.parentFragment.getString(relationship!=null && relationship.blocking ? R.string.unblock_user : R.string.block_user, account.displayName)); + report.setTitle(item.parentFragment.getString(R.string.report_user, account.displayName)); + follow.setTitle(item.parentFragment.getString(relationship!=null && relationship.following ? R.string.unfollow_user : R.string.follow_user, account.displayName)); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index 3a9577fd..4b44d37d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -808,4 +808,11 @@ public class UiUtils{ return context.getResources().getQuantityString(R.plurals.x_days, days, days); } } + + public static void openSystemShareSheet(Context context, String url){ + Intent intent=new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, url); + context.startActivity(Intent.createChooser(intent, context.getString(R.string.share_toot_title))); + } } diff --git a/mastodon/src/main/res/menu/post.xml b/mastodon/src/main/res/menu/post.xml index 30a412ac..7e663bac 100644 --- a/mastodon/src/main/res/menu/post.xml +++ b/mastodon/src/main/res/menu/post.xml @@ -1,12 +1,18 @@ - - - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file