From 859a4acfa5730e9adfa846b1b9f38a86fc98135e Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Fri, 2 Oct 2020 23:00:15 +0200 Subject: [PATCH] Implement clicking on 'Reply to' text ... and remove the Reply to button from the menu. --- .../tusky/adapter/StatusBaseViewHolder.java | 7 +++++-- .../conversation/ConversationsFragment.kt | 4 ++++ .../fragments/SearchStatusesFragment.kt | 19 +++++++------------ .../tusky/fragment/NotificationsFragment.java | 7 +++++++ .../tusky/fragment/SFragment.java | 10 ---------- .../tusky/fragment/TimelineFragment.java | 10 ++++++++++ .../tusky/fragment/ViewThreadFragment.java | 7 +++++++ .../interfaces/StatusActionListener.java | 1 + .../keylesspalace/tusky/view/StatusView.kt | 1 + app/src/main/res/menu/status_more.xml | 3 --- .../main/res/menu/status_more_for_user.xml | 3 --- 11 files changed, 42 insertions(+), 30 deletions(-) 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 6d956860..c23265a3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -382,7 +382,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } - protected void setReplyInfo(StatusViewData.Concrete status) { + protected void setReplyInfo(StatusViewData.Concrete status, StatusActionListener listener) { if (status.getInReplyToId() != null) { Context context = replyInfo.getContext(); String replyToAccount = status.getInReplyToAccountAcct(); @@ -391,6 +391,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { replyInfo.setPaintFlags(replyInfo.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); else replyInfo.setPaintFlags(replyInfo.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG)); + + replyInfo.setOnClickListener(v -> listener.onViewReplyTo(getAdapterPosition())); + replyInfo.setVisibility(View.VISIBLE); } else { replyInfo.setVisibility(View.GONE); @@ -775,7 +778,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { setUsername(status.getNickname()); setCreatedAt(status.getCreatedAt(), statusDisplayOptions); setIsReply(status.getInReplyToId() != null); - setReplyInfo(status); + setReplyInfo(status, listener); setAvatar(status.getAvatar(), status.getRebloggedAvatar(), status.isBot(), statusDisplayOptions); setReblogged(status.isReblogged()); setFavourited(status.isFavourited()); diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt index dc2d60c8..c75e5829 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsFragment.kt @@ -138,6 +138,10 @@ class ConversationsFragment : SFragment(), StatusActionListener, Injectable, Res } } + override fun onViewReplyTo(position: Int) { + // there are no Reply to labels in conversations + } + override fun onOpenReblog(position: Int) { // there are no reblogs in search results } diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt index f8c8ea63..3ff348b1 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt @@ -155,6 +155,13 @@ class SearchStatusesFragment : SearchFragment + val actionableStatus = status.actionableStatus + bottomSheetActivity?.viewThread(actionableStatus.inReplyToId!!, null) + } + } + override fun onOpenReblog(position: Int) { searchAdapter.getItem(position)?.first?.let { status -> bottomSheetActivity?.viewAccount(status.account.id) @@ -195,10 +202,6 @@ class SearchStatusesFragment : SearchFragment when (item.itemId) { R.id.status_share_content -> { @@ -309,10 +308,6 @@ class SearchStatusesFragment : SearchFragment { - onShowReplyTo(status.inReplyToId!!) - return@setOnMenuItemClickListener true - } R.id.status_open_as -> { showOpenAsDialog(statusUrl!!, item.title) return@setOnMenuItemClickListener true diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index 62ad90c1..feabe041 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -591,6 +591,13 @@ public class NotificationsFragment extends SFragment implements super.viewThread(notification.getStatus()); } + @Override + public void onViewReplyTo(int position) { + Notification notification = notifications.get(position).asRightOrNull(); + if (notification == null) return; + super.onShowReplyTo(notification.getStatus().getInReplyToId()); + } + @Override public void onOpenReblog(int position) { Notification notification = notifications.get(position).asRight(); diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java index 8fd5607f..bc7dba69 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java @@ -267,12 +267,6 @@ public abstract class SFragment extends BaseFragment implements Injectable { } openAsItem.setTitle(openAsTitle); - if(status.getInReplyToId() == null) { - MenuItem replyToItem = menu.findItem(R.id.status_reply_to); - - replyToItem.setVisible(false); - } - // maybe not a best check if(status.getPleroma() != null) { boolean showMute = true; // predict state @@ -325,10 +319,6 @@ public abstract class SFragment extends BaseFragment implements Injectable { LinkHelper.openLinkInBrowser(Uri.parse(statusUrl), getContext()); return true; } - case R.id.status_reply_to: { - onShowReplyTo(status.getInReplyToId()); - return true; - } case R.id.status_open_as: { showOpenAsDialog(statusUrl, item.getTitle()); return true; diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java index e29a46f0..aa73858f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java @@ -848,6 +848,16 @@ public class TimelineFragment extends SFragment implements super.viewThread(statuses.get(position).asRight()); } + @Override + public void onViewReplyTo(int position) { + Status status = statuses.get(position).asRightOrNull(); + if (status == null) return; + + String replyToId = status.getReblog() == null ? status.getInReplyToId() : status.getReblog().getInReplyToId(); + if (replyToId == null) return; + super.onShowReplyTo(replyToId); + } + @Override public void onViewTag(String tag) { if (kind == Kind.TAG && tags.size() == 1 && tags.contains(tag)) { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java index a6ff4a50..e7288c91 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java @@ -315,6 +315,13 @@ public final class ViewThreadFragment extends SFragment implements super.viewThread(status); } + @Override + public void onViewReplyTo(int position) { + Status status = statuses.get(position); + if (thisThreadsStatusId.equals(status.getInReplyToId())) return; + super.onShowReplyTo(status.getInReplyToId()); + } + @Override public void onOpenReblog(int position) { // there should be no reblogs in the thread but let's implement it to be sure diff --git a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java b/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java index 16d28eac..d956cec2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java +++ b/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java @@ -31,6 +31,7 @@ public interface StatusActionListener extends LinkListener { void onMore(@NonNull View view, final int position); void onViewMedia(int position, int attachmentIndex, @Nullable View view); void onViewThread(int position); + void onViewReplyTo(int position); /** * Open reblog author for the status. diff --git a/app/src/main/java/com/keylesspalace/tusky/view/StatusView.kt b/app/src/main/java/com/keylesspalace/tusky/view/StatusView.kt index 1fc4a2e7..72793b15 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/StatusView.kt +++ b/app/src/main/java/com/keylesspalace/tusky/view/StatusView.kt @@ -58,6 +58,7 @@ class StatusView @JvmOverloads constructor( override fun onMore(view: View, position: Int) { } override fun onViewMedia(position: Int, attachmentIndex: Int, view: View?) { } override fun onViewThread(position: Int) { } + override fun onViewReplyTo(position: Int) { } override fun onOpenReblog(position: Int) { } override fun onExpandedChange(expanded: Boolean, position: Int) { } override fun onContentHiddenChange(isShowing: Boolean, position: Int) { } diff --git a/app/src/main/res/menu/status_more.xml b/app/src/main/res/menu/status_more.xml index e2419d23..32eb95aa 100644 --- a/app/src/main/res/menu/status_more.xml +++ b/app/src/main/res/menu/status_more.xml @@ -12,9 +12,6 @@ android:title="@string/status_share_content" /> - diff --git a/app/src/main/res/menu/status_more_for_user.xml b/app/src/main/res/menu/status_more_for_user.xml index 13248290..fdc546fb 100644 --- a/app/src/main/res/menu/status_more_for_user.xml +++ b/app/src/main/res/menu/status_more_for_user.xml @@ -12,9 +12,6 @@ android:title="@string/status_share_content" /> -