From 5f9c0a51e6a7a4e0567d3918c1417278eb2e9c2d Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Thu, 6 Jun 2024 17:46:02 +0200 Subject: [PATCH 1/3] Handle the share action --- .../ui/comments/CommentDetailFragment.java | 29 +++++++------------ .../comments/SharedCommentDetailFragment.kt | 5 ++++ .../unified/CommentActionPopupHandler.kt | 2 +- .../NotificationsDetailListFragment.kt | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java index ed71c3b2620d..b8c8d3763eff 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java @@ -47,6 +47,7 @@ import org.wordpress.android.models.UserSuggestion; import org.wordpress.android.models.usecases.LocalCommentCacheUpdateHandler; import org.wordpress.android.ui.ActivityId; +import org.wordpress.android.ui.ActivityLauncher; import org.wordpress.android.ui.CollapseFullScreenDialogFragment; import org.wordpress.android.ui.ViewPagerFragment; import org.wordpress.android.ui.comments.CommentActions.OnCommentActionListener; @@ -115,7 +116,6 @@ public abstract class CommentDetailFragment extends ViewPagerFragment implements @Nullable protected Note mNote; @Nullable private SuggestionAdapter mSuggestionAdapter; @Nullable private SuggestionServiceConnectionManager mSuggestionServiceConnectionManager; - @Nullable private String mRestoredReplyText; protected boolean mIsUsersBlog = false; protected boolean mShouldFocusReplyField; @Nullable private String mPreviousStatus; @@ -138,13 +138,6 @@ public abstract class CommentDetailFragment extends ViewPagerFragment implements @Nullable private OnNoteCommentActionListener mOnNoteCommentActionListener; @NonNull protected CommentSource mCommentSource; // this will be non-null when onCreate() - /* - * these determine which actions (moderation, replying, marking as spam) to enable - * for this comment - all actions are enabled when opened from the comment list, only - * changed when opened from a notification - */ - @NonNull private EnumSet mEnabledActions = EnumSet.allOf(EnabledActions.class); - @Nullable protected CommentDetailFragmentBinding mBinding = null; private final OnActionClickListener mOnActionClickListener = new OnActionClickListener() { @@ -154,7 +147,13 @@ public abstract class CommentDetailFragment extends ViewPagerFragment implements @Override public void onUserInfoClicked() { UserProfileBottomSheetFragment.newInstance(getUserProfileUiState()) - .show(getChildFragmentManager(), UserProfileBottomSheetFragment.TAG); + .show(getChildFragmentManager(), UserProfileBottomSheetFragment.TAG); + } + + @Override public void onShareClicked() { + if (getContext() != null) { + ActivityLauncher.openShareIntent(getContext(), mComment.getUrl(), null); + } } }; @@ -725,15 +724,6 @@ private void showCommentAsNotification( binding.textContent.setVisibility(View.GONE); - /* - * determine which actions to enable for this comment - if the comment is from this user's - * blog then all actions will be enabled, but they won't be if it's a reply to a comment - * this user made on someone else's blog - */ - if (note != null) { - mEnabledActions = note.getEnabledCommentActions(); - } - if (comment != null) { setComment(site, comment); } else if (note != null) { @@ -901,6 +891,9 @@ public void onDestroy() { */ public interface OnActionClickListener { void onEditCommentClicked(); + void onUserInfoClicked(); + + void onShareClicked(); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt index 448136c009b6..781d5440de1c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt @@ -60,6 +60,11 @@ abstract class SharedCommentDetailFragment : CommentDetailFragment() { @Inject lateinit var meGravatarLoader: MeGravatarLoader + /* + * these determine which actions (moderation, replying, marking as spam) to enable + * for this comment - all actions are enabled when opened from the comment list, only + * changed when opened from a notification + */ abstract val enabledActions: EnumSet override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt index 984007e7d176..6d0a74483ffa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt @@ -24,7 +24,7 @@ object CommentActionPopupHandler { popupWindow.dismiss() } textShare.setOnClickListener { - ToastUtils.showToast(it.context, "not yet implemented") + listener?.onShareClicked() popupWindow.dismiss() } textEditComment.setOnClickListener { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt index c261b9bd9c7e..0231f497cf73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt @@ -195,7 +195,7 @@ class NotificationsDetailListFragment : ListFragment(), NotificationFragment { this.footerView = footerView } - private val mOnNoteBlockTextClickListener = NoteBlockTextClickListener(this, notification, onActionClickListener) + private val mOnNoteBlockTextClickListener by lazy { NoteBlockTextClickListener(this, notification, onActionClickListener) } private val mOnGravatarClickedListener = object : OnGravatarClickedListener { override fun onGravatarClicked(siteId: Long, userId: Long, siteUrl: String?) { From 9f6b69cbe259937f0466eda3281b6f8eaf1a35db Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Thu, 6 Jun 2024 17:54:41 +0200 Subject: [PATCH 2/3] Handle the click of changing status in the comment menu --- .../android/ui/comments/CommentDetailFragment.java | 8 ++++++++ .../android/ui/comments/SharedCommentDetailFragment.kt | 2 +- .../ui/comments/unified/CommentActionPopupHandler.kt | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java index b8c8d3763eff..564aa31b2075 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java @@ -155,8 +155,14 @@ public abstract class CommentDetailFragment extends ViewPagerFragment implements ActivityLauncher.openShareIntent(getContext(), mComment.getUrl(), null); } } + + @Override public void onChangeStatusClicked() { + showModerationBottomSheet(); + } }; + abstract void showModerationBottomSheet(); + abstract UserProfileUiState getUserProfileUiState(); @Override @@ -895,5 +901,7 @@ public interface OnActionClickListener { void onUserInfoClicked(); void onShareClicked(); + + void onChangeStatusClicked(); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt index 781d5440de1c..4e6e61b5c192 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/SharedCommentDetailFragment.kt @@ -160,7 +160,7 @@ abstract class SharedCommentDetailFragment : CommentDetailFragment() { ) } - private fun showModerationBottomSheet() { + override fun showModerationBottomSheet() { ModerationBottomSheetDialogFragment.newInstance( ModerationBottomSheetDialogFragment.CommentState( canModerate = enabledActions.canModerate(), diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt index 6d0a74483ffa..77df41a02e8a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt @@ -32,7 +32,7 @@ object CommentActionPopupHandler { popupWindow.dismiss() } textChangeStatus.setOnClickListener { - ToastUtils.showToast(it.context, "not yet implemented") + listener?.onChangeStatusClicked() popupWindow.dismiss() } }.root From 78a2b0966028747ee0a615cfe2fa8690c0c52a64 Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Thu, 6 Jun 2024 18:31:38 +0200 Subject: [PATCH 3/3] Fix lint issues --- .../android/ui/comments/CommentDetailFragment.java | 2 -- .../ui/comments/unified/CommentActionPopupHandler.kt | 1 - .../ui/notifications/NotificationsDetailListFragment.kt | 6 ++++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java index 564aa31b2075..7d9856428fcc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java @@ -43,7 +43,6 @@ import org.wordpress.android.fluxc.tools.FluxCImageLoader; import org.wordpress.android.fluxc.tools.FormattableContentMapper; import org.wordpress.android.models.Note; -import org.wordpress.android.models.Note.EnabledActions; import org.wordpress.android.models.UserSuggestion; import org.wordpress.android.models.usecases.LocalCommentCacheUpdateHandler; import org.wordpress.android.ui.ActivityId; @@ -81,7 +80,6 @@ import org.wordpress.android.util.image.ImageManager; import org.wordpress.android.util.image.ImageType; -import java.util.EnumSet; import java.util.List; import javax.inject.Inject; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt index 77df41a02e8a..8725bc84d8a5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentActionPopupHandler.kt @@ -8,7 +8,6 @@ import android.widget.PopupWindow import org.wordpress.android.R import org.wordpress.android.databinding.CommentActionsBinding import org.wordpress.android.ui.comments.CommentDetailFragment -import org.wordpress.android.util.ToastUtils object CommentActionPopupHandler { @JvmStatic diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt index 0231f497cf73..db32e4a6f641 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.kt @@ -195,7 +195,9 @@ class NotificationsDetailListFragment : ListFragment(), NotificationFragment { this.footerView = footerView } - private val mOnNoteBlockTextClickListener by lazy { NoteBlockTextClickListener(this, notification, onActionClickListener) } + private val mOnNoteBlockTextClickListener by lazy { + NoteBlockTextClickListener(this, notification, onActionClickListener) + } private val mOnGravatarClickedListener = object : OnGravatarClickedListener { override fun onGravatarClicked(siteId: Long, userId: Long, siteUrl: String?) { @@ -531,7 +533,7 @@ class NotificationsDetailListFragment : ListFragment(), NotificationFragment { } } - fun setOnEditCommentListener(listener: CommentDetailFragment.OnActionClickListener){ + fun setOnEditCommentListener(listener: CommentDetailFragment.OnActionClickListener) { onActionClickListener = listener }