Implement clicking on 'Reply to' text

... and remove the Reply to button from the menu.
This commit is contained in:
Karol Kosek 2020-10-02 23:00:15 +02:00
parent 40db8951f9
commit 859a4acfa5
11 changed files with 42 additions and 30 deletions

View File

@ -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());

View File

@ -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
}

View File

@ -155,6 +155,13 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
}
}
override fun onViewReplyTo(position: Int) {
searchAdapter.getItem(position)?.first?.let { status ->
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<Pair<Status, StatusViewData.Concre
}
}
private fun onShowReplyTo(replyToId: String) {
bottomSheetActivity?.viewThread(replyToId, null)
}
companion object {
fun newInstance() = SearchStatusesFragment()
}
@ -272,10 +275,6 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
}
openAsItem.title = openAsTitle
if(status.inReplyToId == null) {
popup.menu.findItem(R.id.status_reply_to)?.isVisible = false
}
popup.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.status_share_content -> {
@ -309,10 +308,6 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
LinkHelper.openLinkInBrowser(Uri.parse(statusUrl), context);
return@setOnMenuItemClickListener true
}
R.id.status_reply_to -> {
onShowReplyTo(status.inReplyToId!!)
return@setOnMenuItemClickListener true
}
R.id.status_open_as -> {
showOpenAsDialog(statusUrl!!, item.title)
return@setOnMenuItemClickListener true

View File

@ -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();

View File

@ -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;

View File

@ -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)) {

View File

@ -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

View File

@ -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.

View File

@ -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) { }

View File

@ -12,9 +12,6 @@
android:title="@string/status_share_content" />
</menu>
</item>
<item
android:id="@+id/status_reply_to"
android:title="@string/action_reply_to" />
<item
android:id="@+id/status_copy_link"
android:title="@string/action_copy_link" />

View File

@ -12,9 +12,6 @@
android:title="@string/status_share_content" />
</menu>
</item>
<item
android:id="@+id/status_reply_to"
android:title="@string/action_reply_to" />
<item
android:id="@+id/status_copy_link"
android:title="@string/action_copy_link" />