From 990f364bf9e20fbe8827d001f6f13cd35ba2f2c8 Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 8 Feb 2022 19:49:45 +0300 Subject: [PATCH] Handle clicks on posts --- .../fragments/BaseStatusListFragment.java | 27 +++++++++++++++++++ .../android/fragments/ComposeFragment.java | 5 +++- .../displayitems/FooterStatusDisplayItem.java | 2 +- .../displayitems/HeaderStatusDisplayItem.java | 2 +- .../displayitems/PhotoStatusDisplayItem.java | 2 +- .../ReblogOrReplyLineStatusDisplayItem.java | 2 +- .../ui/displayitems/StatusDisplayItem.java | 22 +++++++++++++++ .../displayitems/TextStatusDisplayItem.java | 2 +- 8 files changed, 58 insertions(+), 6 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 574d7c94..df59a405 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -230,6 +230,29 @@ public abstract class BaseStatusListFragment exten } } }); + ((UsableRecyclerView)list).setSelectorBoundsProvider(new UsableRecyclerView.SelectorBoundsProvider(){ + @Override + public void getSelectorBounds(View view, Rect outRect){ + outRect.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); + RecyclerView.ViewHolder holder=list.getChildViewHolder(view); + if(holder instanceof StatusDisplayItem.Holder){ + String id=((StatusDisplayItem.Holder) holder).getItemID(); + for(int i=0;i) holder).getItemID(); + if(otherID.equals(id)){ + outRect.left=Math.min(outRect.left, child.getLeft()); + outRect.top=Math.min(outRect.top, child.getTop()); + outRect.right=Math.max(outRect.right, child.getRight()); + outRect.bottom=Math.max(outRect.bottom, child.getBottom()); + } + } + } + } + } + }); } @Override @@ -259,6 +282,10 @@ public abstract class BaseStatusListFragment exten return 0; } + public void onItemClick(String id){ + + } + protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter> implements ImageLoaderRecyclerAdapter{ public DisplayItemsAdapter(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index d70be7bb..d8b06b6e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -119,6 +119,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis private CustomEmojiPopupKeyboard emojiKeyboard; private Status replyTo; private String initialReplyMentions; + private String uuid; @Override public void onAttach(Activity activity){ @@ -283,6 +284,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis } private void updatePublishButtonState(){ + uuid=null; publishButton.setEnabled((trimmedCharCount>0 || !attachments.isEmpty()) && charCount<=charLimit && uploadingAttachment==null && failedAttachments.isEmpty() && queuedAttachments.isEmpty()); } @@ -308,7 +310,8 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis if(replyTo!=null){ req.inReplyToId=replyTo.id; } - String uuid=UUID.randomUUID().toString(); + if(uuid==null) + uuid=UUID.randomUUID().toString(); ProgressDialog progress=new ProgressDialog(getActivity()); progress.setMessage(getString(R.string.publishing)); progress.setCancelable(false); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java index c9fa1465..fd33810e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java @@ -39,7 +39,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{ return Type.FOOTER; } - public static class Holder extends BindableViewHolder{ + public static class Holder extends StatusDisplayItem.Holder{ private final TextView reply, boost, favorite; private final ImageView share; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index e6e51dca..741fdb36 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -59,7 +59,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ return avaRequest; } - public static class Holder extends BindableViewHolder implements ImageLoaderViewHolder{ + public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ private final TextView name, username, timestamp; private final ImageView avatar, more; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PhotoStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PhotoStatusDisplayItem.java index d4c986ef..84914b6c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PhotoStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PhotoStatusDisplayItem.java @@ -49,7 +49,7 @@ public class PhotoStatusDisplayItem extends StatusDisplayItem{ return request; } - public static class Holder extends BindableViewHolder implements ImageLoaderViewHolder{ + public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ public final ImageView photo; public Holder(Activity activity, ViewGroup parent){ super(activity, R.layout.display_item_photo, parent); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java index 582bcf3f..34346fd1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ReblogOrReplyLineStatusDisplayItem.java @@ -24,7 +24,7 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{ return Type.REBLOG_OR_REPLY_LINE; } - public static class Holder extends BindableViewHolder{ + public static class Holder extends StatusDisplayItem.Holder{ private final TextView text; public Holder(Activity activity, ViewGroup parent){ super(activity, R.layout.display_item_reblog_or_reply_line, parent); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 0b9dfa76..bc296d1b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -2,7 +2,9 @@ package org.joinmastodon.android.ui.displayitems; import android.app.Activity; import android.app.Fragment; +import android.content.Context; import android.text.TextUtils; +import android.view.View; import android.view.ViewGroup; import org.joinmastodon.android.R; @@ -16,6 +18,7 @@ import java.util.ArrayList; import me.grishka.appkit.imageloader.requests.ImageLoaderRequest; import me.grishka.appkit.utils.BindableViewHolder; +import me.grishka.appkit.views.UsableRecyclerView; public abstract class StatusDisplayItem{ public final String parentID; @@ -88,4 +91,23 @@ public abstract class StatusDisplayItem{ CARD, FOOTER, } + + public static abstract class Holder extends BindableViewHolder implements UsableRecyclerView.Clickable{ + public Holder(View itemView){ + super(itemView); + } + + public Holder(Context context, int layout, ViewGroup parent){ + super(context, layout, parent); + } + + public String getItemID(){ + return item.parentID; + } + + @Override + public void onClick(){ + item.parentFragment.onItemClick(item.parentID); + } + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java index 7606a1f0..73e85ef8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java @@ -69,7 +69,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem implements LinkSpan } } - public static class Holder extends BindableViewHolder implements ImageLoaderViewHolder{ + public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ private final LinkedTextView text; private CustomEmojiSpan[] emojiSpans;