Handle clicks on posts

This commit is contained in:
Grishka 2022-02-08 19:49:45 +03:00
parent d9cd15eb2d
commit 990f364bf9
8 changed files with 58 additions and 6 deletions

View File

@ -230,6 +230,29 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> 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<list.getChildCount();i++){
View child=list.getChildAt(i);
holder=list.getChildViewHolder(child);
if(holder instanceof StatusDisplayItem.Holder){
String otherID=((StatusDisplayItem.Holder<?>) 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<T extends DisplayItemsParent> exten
return 0;
}
public void onItemClick(String id){
}
protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter<BindableViewHolder<StatusDisplayItem>> implements ImageLoaderRecyclerAdapter{
public DisplayItemsAdapter(){

View File

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

View File

@ -39,7 +39,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
return Type.FOOTER;
}
public static class Holder extends BindableViewHolder<FooterStatusDisplayItem>{
public static class Holder extends StatusDisplayItem.Holder<FooterStatusDisplayItem>{
private final TextView reply, boost, favorite;
private final ImageView share;

View File

@ -59,7 +59,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
return avaRequest;
}
public static class Holder extends BindableViewHolder<HeaderStatusDisplayItem> implements ImageLoaderViewHolder{
public static class Holder extends StatusDisplayItem.Holder<HeaderStatusDisplayItem> implements ImageLoaderViewHolder{
private final TextView name, username, timestamp;
private final ImageView avatar, more;

View File

@ -49,7 +49,7 @@ public class PhotoStatusDisplayItem extends StatusDisplayItem{
return request;
}
public static class Holder extends BindableViewHolder<PhotoStatusDisplayItem> implements ImageLoaderViewHolder{
public static class Holder extends StatusDisplayItem.Holder<PhotoStatusDisplayItem> implements ImageLoaderViewHolder{
public final ImageView photo;
public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_photo, parent);

View File

@ -24,7 +24,7 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{
return Type.REBLOG_OR_REPLY_LINE;
}
public static class Holder extends BindableViewHolder<ReblogOrReplyLineStatusDisplayItem>{
public static class Holder extends StatusDisplayItem.Holder<ReblogOrReplyLineStatusDisplayItem>{
private final TextView text;
public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_reblog_or_reply_line, parent);

View File

@ -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<T extends StatusDisplayItem> extends BindableViewHolder<T> 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);
}
}
}

View File

@ -69,7 +69,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem implements LinkSpan
}
}
public static class Holder extends BindableViewHolder<TextStatusDisplayItem> implements ImageLoaderViewHolder{
public static class Holder extends StatusDisplayItem.Holder<TextStatusDisplayItem> implements ImageLoaderViewHolder{
private final LinkedTextView text;
private CustomEmojiSpan[] emojiSpans;