change behavior when adding reactions

closes sk22#769
This commit is contained in:
sk 2023-08-24 13:00:16 +02:00
parent 47fde1e08b
commit d44df2c23c
3 changed files with 51 additions and 21 deletions

View File

@ -106,7 +106,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
vh.btn.setClickable(!visible);
}
private MastodonAPIRequest<?> createRequest(String name, int count, boolean delete, Holder.EmojiReactionViewHolder vh, Runnable cb){
private MastodonAPIRequest<?> createRequest(String name, int count, boolean delete, Holder.EmojiReactionViewHolder vh, Runnable cb, Runnable err){
setActionProgressVisible(vh, true);
boolean ak=parentFragment.isInstanceAkkoma();
boolean keepSpinning=delete && count == 1;
@ -124,6 +124,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
public void onError(ErrorResponse error){
setActionProgressVisible(vh, false);
error.showToast(parentFragment.getContext());
if(err!=null) err.run();
}
});
}else{
@ -140,6 +141,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
public void onError(ErrorResponse error){
setActionProgressVisible(vh, false);
error.showToast(parentFragment.getContext());
if(err!=null) err.run();
}
});
}
@ -151,6 +153,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
private CustomEmojiPopupKeyboard emojiKeyboard;
private final View space;
private final ImageButton addButton;
private final ProgressBar progress;
private final EmojiReactionsAdapter adapter;
private final ListImageLoaderWrapper imgLoader;
@ -162,6 +165,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
imgLoader=new ListImageLoaderWrapper(activity, list, new RecyclerViewDelegate(list), null);
list.setAdapter(adapter=new EmojiReactionsAdapter(this, imgLoader));
addButton=findViewById(R.id.add_btn);
progress=findViewById(R.id.progress);
addButton.setOnClickListener(this::onReactClick);
space=findViewById(R.id.space);
list.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false));
@ -213,24 +217,36 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
private void addEmojiReaction(String emoji, Emoji info) {
if(item.status.reactions.stream().filter(r->r.name.equals(emoji) && r.me).findAny().isPresent()) return;
progress.setVisibility(View.VISIBLE);
addButton.setClickable(false);
addButton.setAlpha(0.55f);
Runnable resetBtn=()->{
progress.setVisibility(View.GONE);
addButton.setClickable(true);
addButton.setAlpha(1f);
};
Account me=AccountSessionManager.get(item.accountID).self;
EmojiReaction existing=null;
for(int i=0; i<item.status.reactions.size(); i++){
EmojiReaction r=item.status.reactions.get(i);
if(r.name.equals(emoji)){
existing=r;
r.add(me);
adapter.notifyItemChanged(i);
break;
}
}
if(existing==null){
EmojiReaction finalExisting=existing;
item.createRequest(emoji, existing==null ? 1 : existing.count, false, null, ()->{
resetBtn.run();
if(finalExisting==null){
item.status.reactions.add(0, info!=null ? EmojiReaction.of(info, me) : EmojiReaction.of(emoji, me));
adapter.notifyItemRangeInserted(0, 1);
}else{
finalExisting.add(me);
adapter.notifyItemChanged(item.status.reactions.indexOf(finalExisting));
}
E.post(new StatusCountersUpdatedEvent(item.status, adapter.parentHolder));
item.createRequest(emoji, existing==null ? 1 : existing.count, false, null, ()->{}).exec(item.accountID);
}, resetBtn).exec(item.accountID);
}
@Override
@ -362,7 +378,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
E.post(new StatusCountersUpdatedEvent(parent.status, adapter.parentHolder));
adapter.parentHolder.imgLoader.updateImages();
}).exec(parent.parentFragment.getAccountID());
}, null).exec(parent.parentFragment.getAccountID());
});
if (parent.parentFragment.isInstanceAkkoma()) {

View File

@ -9,17 +9,32 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/add_btn_wrap"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginStart="2dp">
<ProgressBar
android:id="@+id/progress"
style="?android:progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="10dp"
android:indeterminate="true"
android:outlineProvider="none"
android:visibility="gone"/>
<ImageButton
android:id="@+id/add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:minHeight="48dp"
android:minWidth="48dp"
android:background="@drawable/bg_button_m3_tonal_circle"
android:tooltipText="@string/sk_button_react"
android:contentDescription="@string/sk_button_react"
android:src="@drawable/ic_fluent_add_24_filled" />
</FrameLayout>
<org.joinmastodon.android.ui.views.EmojiReactionsRecyclerView
android:id="@+id/list"

View File

@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
tools:ignore="RtlSymmetry">
<ProgressBar
android:id="@+id/progress"