Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment details menu redesign #20944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
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;
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;
Expand Down Expand Up @@ -80,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;
Expand Down Expand Up @@ -115,7 +114,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;
Expand All @@ -138,13 +136,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<EnabledActions> mEnabledActions = EnumSet.allOf(EnabledActions.class);

@Nullable protected CommentDetailFragmentBinding mBinding = null;

private final OnActionClickListener mOnActionClickListener = new OnActionClickListener() {
Expand All @@ -154,10 +145,22 @@ 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);
}
}

@Override public void onChangeStatusClicked() {
showModerationBottomSheet();
}
};

abstract void showModerationBottomSheet();

abstract UserProfileUiState getUserProfileUiState();

@Override
Expand Down Expand Up @@ -725,15 +728,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) {
Expand Down Expand Up @@ -901,6 +895,11 @@ public void onDestroy() {
*/
public interface OnActionClickListener {
void onEditCommentClicked();

void onUserInfoClicked();

void onShareClicked();

void onChangeStatusClicked();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnabledActions>

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -155,7 +160,7 @@ abstract class SharedCommentDetailFragment : CommentDetailFragment() {
)
}

private fun showModerationBottomSheet() {
override fun showModerationBottomSheet() {
ModerationBottomSheetDialogFragment.newInstance(
ModerationBottomSheetDialogFragment.CommentState(
canModerate = enabledActions.canModerate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,15 +23,15 @@ object CommentActionPopupHandler {
popupWindow.dismiss()
}
textShare.setOnClickListener {
ToastUtils.showToast(it.context, "not yet implemented")
listener?.onShareClicked()
popupWindow.dismiss()
}
textEditComment.setOnClickListener {
listener?.onEditCommentClicked()
popupWindow.dismiss()
}
textChangeStatus.setOnClickListener {
ToastUtils.showToast(it.context, "not yet implemented")
listener?.onChangeStatusClicked()
popupWindow.dismiss()
}
}.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ class NotificationsDetailListFragment : ListFragment(), NotificationFragment {
this.footerView = footerView
}

private val mOnNoteBlockTextClickListener = NoteBlockTextClickListener(this, notification, onActionClickListener)
private val mOnNoteBlockTextClickListener by lazy {
Copy link
Contributor Author

@jarvislin jarvislin Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onActionClickListener is always null if we don't use by lazy because we create mOnNoteBlockTextClickListener when onActionClickListener has not been set value.

NoteBlockTextClickListener(this, notification, onActionClickListener)
}

private val mOnGravatarClickedListener = object : OnGravatarClickedListener {
override fun onGravatarClicked(siteId: Long, userId: Long, siteUrl: String?) {
Expand Down Expand Up @@ -531,7 +533,7 @@ class NotificationsDetailListFragment : ListFragment(), NotificationFragment {
}
}

fun setOnEditCommentListener(listener: CommentDetailFragment.OnActionClickListener){
fun setOnEditCommentListener(listener: CommentDetailFragment.OnActionClickListener) {
onActionClickListener = listener
}

Expand Down
Loading