Update favorite when reacting on Iceshrimp
This commit is contained in:
parent
684164903a
commit
2856e99569
|
@ -659,6 +659,14 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
|||
warning.getItem().status.filterRevealed = true;
|
||||
}
|
||||
|
||||
public void onFavoriteChanged(Status status, String itemID) {
|
||||
FooterStatusDisplayItem.Holder footer=findHolderOfType(itemID, FooterStatusDisplayItem.Holder.class);
|
||||
if(footer!=null){
|
||||
footer.getItem().status=status;
|
||||
footer.onFavoriteClick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccountID(){
|
||||
return accountID;
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.joinmastodon.android.api.requests.statuses.PleromaDeleteStatusReactio
|
|||
import org.joinmastodon.android.api.session.AccountSession;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.events.EmojiReactionsUpdatedEvent;
|
||||
import org.joinmastodon.android.events.StatusCountersUpdatedEvent;
|
||||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||
import org.joinmastodon.android.fragments.account_list.StatusEmojiReactionsListFragment;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
|
@ -46,6 +47,8 @@ import org.joinmastodon.android.ui.utils.TextDrawable;
|
|||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
import org.joinmastodon.android.ui.views.EmojiReactionButton;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import me.grishka.appkit.Nav;
|
||||
import me.grishka.appkit.api.Callback;
|
||||
import me.grishka.appkit.api.ErrorResponse;
|
||||
|
@ -103,7 +106,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
vh.btn.setAlpha(visible ? ALPHA_DISABLED : 1);
|
||||
}
|
||||
|
||||
private MastodonAPIRequest<?> createRequest(String name, int count, boolean delete, Holder.EmojiReactionViewHolder vh, Runnable cb, Runnable err){
|
||||
private MastodonAPIRequest<?> createRequest(String name, int count, boolean delete, Holder.EmojiReactionViewHolder vh, Consumer<Status> cb, Runnable err){
|
||||
setActionProgressVisible(vh, true);
|
||||
boolean ak=parentFragment.isInstanceAkkoma();
|
||||
boolean keepSpinning=delete && count == 1;
|
||||
|
@ -115,7 +118,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
@Override
|
||||
public void onSuccess(Object result){
|
||||
if(!keepSpinning) setActionProgressVisible(vh, false);
|
||||
cb.run();
|
||||
cb.accept(null);
|
||||
}
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
|
@ -132,7 +135,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
@Override
|
||||
public void onSuccess(Status result){
|
||||
if(!keepSpinning) setActionProgressVisible(vh, false);
|
||||
cb.run();
|
||||
cb.accept(result);
|
||||
}
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
|
@ -255,7 +258,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
}
|
||||
}
|
||||
EmojiReaction finalExisting=existing;
|
||||
item.createRequest(emoji, existing==null ? 1 : existing.count, false, null, ()->{
|
||||
item.createRequest(emoji, existing==null ? 1 : existing.count, false, null, (status)->{
|
||||
resetBtn.run();
|
||||
if(finalExisting==null){
|
||||
int pos=item.status.reactions.size();
|
||||
|
@ -269,6 +272,10 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
finalExisting.add(me);
|
||||
adapter.notifyItemChanged(item.status.reactions.indexOf(finalExisting));
|
||||
}
|
||||
if(instance.isIceshrimp() && status!=null){
|
||||
item.parentFragment.onFavoriteChanged(status, getItemID());
|
||||
E.post(new StatusCountersUpdatedEvent(status));
|
||||
}
|
||||
E.post(new EmojiReactionsUpdatedEvent(item.status.id, item.status.reactions, countBefore==0, adapter.parentHolder));
|
||||
}, resetBtn).exec(item.accountID);
|
||||
}
|
||||
|
@ -404,7 +411,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
}
|
||||
btn.setOnClickListener(e->{
|
||||
boolean deleting=reaction.me;
|
||||
parent.createRequest(reaction.name, reaction.count, deleting, this, ()->{
|
||||
parent.createRequest(reaction.name, reaction.count, deleting, this, (status)->{
|
||||
EmojiReactionsAdapter adapter = (EmojiReactionsAdapter) getBindingAdapter();
|
||||
for(int i=0; i<parent.status.reactions.size(); i++){
|
||||
EmojiReaction r=parent.status.reactions.get(i);
|
||||
|
@ -430,6 +437,10 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
if(instance.configuration!=null && instance.configuration.reactions!=null && instance.configuration.reactions.maxReactions!=0){
|
||||
adapter.parentHolder.updateAddButtonClickable(deleting);
|
||||
}
|
||||
if(instance.isIceshrimp() && status!=null){
|
||||
parent.parentFragment.onFavoriteChanged(status, adapter.parentHolder.getItemID());
|
||||
E.post(new StatusCountersUpdatedEvent(status));
|
||||
}
|
||||
E.post(new EmojiReactionsUpdatedEvent(parent.status.id, parent.status.reactions, parent.status.reactions.isEmpty(), adapter.parentHolder));
|
||||
adapter.parentHolder.imgLoader.updateImages();
|
||||
}, null).exec(parent.parentFragment.getAccountID());
|
||||
|
|
|
@ -303,6 +303,17 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
|||
return true;
|
||||
}
|
||||
|
||||
public void onFavoriteClick() {
|
||||
favorite.setSelected(item.status.favourited);
|
||||
favorite.animate().scaleX(0.95f).scaleY(0.95f).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(75).start();
|
||||
UiUtils.opacityOut(favorite);
|
||||
favorite.postDelayed(() -> {
|
||||
favorite.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
|
||||
UiUtils.opacityIn(favorite);
|
||||
}, 300);
|
||||
bindText(favorites, item.status.favouritesCount);
|
||||
}
|
||||
|
||||
private void onFavoriteClick(View v){
|
||||
if(item.status.preview) return;
|
||||
favorite.setSelected(!item.status.favourited);
|
||||
|
|
Loading…
Reference in New Issue