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;
|
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
|
@Override
|
||||||
public String getAccountID(){
|
public String getAccountID(){
|
||||||
return accountID;
|
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.AccountSession;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
import org.joinmastodon.android.events.EmojiReactionsUpdatedEvent;
|
import org.joinmastodon.android.events.EmojiReactionsUpdatedEvent;
|
||||||
|
import org.joinmastodon.android.events.StatusCountersUpdatedEvent;
|
||||||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||||
import org.joinmastodon.android.fragments.account_list.StatusEmojiReactionsListFragment;
|
import org.joinmastodon.android.fragments.account_list.StatusEmojiReactionsListFragment;
|
||||||
import org.joinmastodon.android.model.Account;
|
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.utils.UiUtils;
|
||||||
import org.joinmastodon.android.ui.views.EmojiReactionButton;
|
import org.joinmastodon.android.ui.views.EmojiReactionButton;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import me.grishka.appkit.Nav;
|
import me.grishka.appkit.Nav;
|
||||||
import me.grishka.appkit.api.Callback;
|
import me.grishka.appkit.api.Callback;
|
||||||
import me.grishka.appkit.api.ErrorResponse;
|
import me.grishka.appkit.api.ErrorResponse;
|
||||||
|
@ -103,7 +106,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||||
vh.btn.setAlpha(visible ? ALPHA_DISABLED : 1);
|
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);
|
setActionProgressVisible(vh, true);
|
||||||
boolean ak=parentFragment.isInstanceAkkoma();
|
boolean ak=parentFragment.isInstanceAkkoma();
|
||||||
boolean keepSpinning=delete && count == 1;
|
boolean keepSpinning=delete && count == 1;
|
||||||
|
@ -115,7 +118,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Object result){
|
public void onSuccess(Object result){
|
||||||
if(!keepSpinning) setActionProgressVisible(vh, false);
|
if(!keepSpinning) setActionProgressVisible(vh, false);
|
||||||
cb.run();
|
cb.accept(null);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onError(ErrorResponse error){
|
public void onError(ErrorResponse error){
|
||||||
|
@ -132,7 +135,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Status result){
|
public void onSuccess(Status result){
|
||||||
if(!keepSpinning) setActionProgressVisible(vh, false);
|
if(!keepSpinning) setActionProgressVisible(vh, false);
|
||||||
cb.run();
|
cb.accept(result);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onError(ErrorResponse error){
|
public void onError(ErrorResponse error){
|
||||||
|
@ -255,7 +258,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EmojiReaction finalExisting=existing;
|
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();
|
resetBtn.run();
|
||||||
if(finalExisting==null){
|
if(finalExisting==null){
|
||||||
int pos=item.status.reactions.size();
|
int pos=item.status.reactions.size();
|
||||||
|
@ -269,6 +272,10 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||||
finalExisting.add(me);
|
finalExisting.add(me);
|
||||||
adapter.notifyItemChanged(item.status.reactions.indexOf(finalExisting));
|
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));
|
E.post(new EmojiReactionsUpdatedEvent(item.status.id, item.status.reactions, countBefore==0, adapter.parentHolder));
|
||||||
}, resetBtn).exec(item.accountID);
|
}, resetBtn).exec(item.accountID);
|
||||||
}
|
}
|
||||||
|
@ -404,7 +411,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||||
}
|
}
|
||||||
btn.setOnClickListener(e->{
|
btn.setOnClickListener(e->{
|
||||||
boolean deleting=reaction.me;
|
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();
|
EmojiReactionsAdapter adapter = (EmojiReactionsAdapter) getBindingAdapter();
|
||||||
for(int i=0; i<parent.status.reactions.size(); i++){
|
for(int i=0; i<parent.status.reactions.size(); i++){
|
||||||
EmojiReaction r=parent.status.reactions.get(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){
|
if(instance.configuration!=null && instance.configuration.reactions!=null && instance.configuration.reactions.maxReactions!=0){
|
||||||
adapter.parentHolder.updateAddButtonClickable(deleting);
|
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));
|
E.post(new EmojiReactionsUpdatedEvent(parent.status.id, parent.status.reactions, parent.status.reactions.isEmpty(), adapter.parentHolder));
|
||||||
adapter.parentHolder.imgLoader.updateImages();
|
adapter.parentHolder.imgLoader.updateImages();
|
||||||
}, null).exec(parent.parentFragment.getAccountID());
|
}, null).exec(parent.parentFragment.getAccountID());
|
||||||
|
|
|
@ -303,6 +303,17 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
return true;
|
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){
|
private void onFavoriteClick(View v){
|
||||||
if(item.status.preview) return;
|
if(item.status.preview) return;
|
||||||
favorite.setSelected(!item.status.favourited);
|
favorite.setSelected(!item.status.favourited);
|
||||||
|
|
Loading…
Reference in New Issue