diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 676cdf0dc..dfceb3093 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable; import android.text.Spanned; import android.text.TextUtils; import android.text.format.DateUtils; +import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -21,7 +22,7 @@ import android.widget.Toast; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.PopupMenu; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; import androidx.core.text.HtmlCompat; @@ -78,6 +79,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { public static final String KEY_CREATED = "created"; } + private final String TAG = "StatusBaseViewHolder"; + private final TextView displayName; private final TextView username; private final ImageButton replyButton; @@ -645,7 +648,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { int position = getBindingAdapterPosition(); if (position != RecyclerView.NO_POSITION) { if (statusDisplayOptions.confirmReblogs()) { - showConfirmReblogDialog(listener, statusContent, buttonState, position); + showConfirmReblog(listener, buttonState, position); return false; } else { listener.onReblog(!buttonState, position); @@ -663,7 +666,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { int position = getBindingAdapterPosition(); if (position != RecyclerView.NO_POSITION) { if (statusDisplayOptions.confirmFavourites()) { - showConfirmFavouriteDialog(listener, statusContent, buttonState, position); + showConfirmFavourite(listener, buttonState, position); return false; } else { listener.onFavourite(!buttonState, position); @@ -702,38 +705,46 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { itemView.setOnClickListener(viewThreadListener); } - private void showConfirmReblogDialog(StatusActionListener listener, - String statusContent, - boolean buttonState, - int position) { - int okButtonTextId = buttonState ? R.string.action_unreblog : R.string.action_reblog; - new AlertDialog.Builder(reblogButton.getContext()) - .setMessage(statusContent) - .setPositiveButton(okButtonTextId, (__, ___) -> { - listener.onReblog(!buttonState, position); - if (!buttonState) { - // Play animation only when it's reblog, not unreblog - reblogButton.playAnimation(); - } - }) - .show(); + private void showConfirmReblog(StatusActionListener listener, + boolean buttonState, + int position) { + PopupMenu popup = new PopupMenu(itemView.getContext(), reblogButton); + popup.inflate(R.menu.status_reblog); + Menu menu = popup.getMenu(); + if (buttonState) { + menu.findItem(R.id.menu_action_reblog).setVisible(false); + } else { + menu.findItem(R.id.menu_action_unreblog).setVisible(false); + } + popup.setOnMenuItemClickListener(item -> { + listener.onReblog(!buttonState, position); + if(!buttonState) { + reblogButton.playAnimation(); + } + return true; + }); + popup.show(); } - private void showConfirmFavouriteDialog(StatusActionListener listener, - String statusContent, - boolean buttonState, - int position) { - int okButtonTextId = buttonState ? R.string.action_unfavourite : R.string.action_favourite; - new AlertDialog.Builder(favouriteButton.getContext()) - .setMessage(statusContent) - .setPositiveButton(okButtonTextId, (__, ___) -> { - listener.onFavourite(!buttonState, position); - if (!buttonState) { - // Play animation only when it's favourite, not unfavourite - favouriteButton.playAnimation(); - } - }) - .show(); + private void showConfirmFavourite(StatusActionListener listener, + boolean buttonState, + int position) { + PopupMenu popup = new PopupMenu(itemView.getContext(), favouriteButton); + popup.inflate(R.menu.status_favourite); + Menu menu = popup.getMenu(); + if (buttonState) { + menu.findItem(R.id.menu_action_favourite).setVisible(false); + } else { + menu.findItem(R.id.menu_action_unfavourite).setVisible(false); + } + popup.setOnMenuItemClickListener(item -> { + listener.onFavourite(!buttonState, position); + if(!buttonState) { + favouriteButton.playAnimation(); + } + return true; + }); + popup.show(); } public void setupWithStatus(StatusViewData.Concrete status, final StatusActionListener listener, diff --git a/app/src/main/res/menu/status_favourite.xml b/app/src/main/res/menu/status_favourite.xml new file mode 100644 index 000000000..66188c270 --- /dev/null +++ b/app/src/main/res/menu/status_favourite.xml @@ -0,0 +1,11 @@ + +
diff --git a/app/src/main/res/menu/status_reblog.xml b/app/src/main/res/menu/status_reblog.xml new file mode 100644 index 000000000..4d79e6b30 --- /dev/null +++ b/app/src/main/res/menu/status_reblog.xml @@ -0,0 +1,11 @@ + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8cea1a643..91ea0e9d7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -697,8 +697,8 @@