diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/StatusInteractionController.java b/mastodon/src/main/java/org/joinmastodon/android/api/StatusInteractionController.java index a2a72e902..08a5dbd66 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/StatusInteractionController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/StatusInteractionController.java @@ -4,6 +4,7 @@ import android.os.Looper; import org.joinmastodon.android.E; import org.joinmastodon.android.MastodonApp; +import org.joinmastodon.android.api.requests.statuses.SetStatusBookmarked; import org.joinmastodon.android.api.requests.statuses.SetStatusFavorited; import org.joinmastodon.android.api.requests.statuses.SetStatusReblogged; import org.joinmastodon.android.events.StatusCountersUpdatedEvent; @@ -18,6 +19,7 @@ public class StatusInteractionController{ private final String accountID; private final HashMap runningFavoriteRequests=new HashMap<>(); private final HashMap runningReblogRequests=new HashMap<>(); + private final HashMap runningBookmarkRequests=new HashMap<>(); public StatusInteractionController(String accountID){ this.accountID=accountID; @@ -61,6 +63,36 @@ public class StatusInteractionController{ E.post(new StatusCountersUpdatedEvent(status)); } + public void setBookmarked(Status status, boolean bookmarked){ + if(!Looper.getMainLooper().isCurrentThread()) + throw new IllegalStateException("Can only be called from main thread"); + + SetStatusBookmarked current=runningBookmarkRequests.remove(status.id); + if(current!=null){ + current.cancel(); + } + SetStatusBookmarked req=(SetStatusBookmarked) new SetStatusBookmarked(status.id, bookmarked) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(Status result){ + runningBookmarkRequests.remove(status.id); + E.post(new StatusCountersUpdatedEvent(result)); + } + + @Override + public void onError(ErrorResponse error){ + runningBookmarkRequests.remove(status.id); + error.showToast(MastodonApp.context); + status.bookmarked=!bookmarked; + E.post(new StatusCountersUpdatedEvent(status)); + } + }) + .exec(accountID); + runningBookmarkRequests.put(status.id, req); + status.bookmarked=bookmarked; + E.post(new StatusCountersUpdatedEvent(status)); + } + public void setReblogged(Status status, boolean reblogged){ if(!Looper.getMainLooper().isCurrentThread()) throw new IllegalStateException("Can only be called from main thread"); 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 776585cd7..145726021 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 @@ -43,7 +43,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{ } public static class Holder extends StatusDisplayItem.Holder{ - private final TextView reply, boost, favorite; + private final TextView reply, boost, favorite, bookmark; private final ImageView share; private final View.AccessibilityDelegate buttonAccessibilityDelegate=new View.AccessibilityDelegate(){ @@ -60,22 +60,27 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{ reply=findViewById(R.id.reply); boost=findViewById(R.id.boost); favorite=findViewById(R.id.favorite); + bookmark=findViewById(R.id.bookmark); share=findViewById(R.id.share); if(Build.VERSION.SDK_INT + + + + + + #18000000 @color/warning_500 + @color/success_500 @color/primary_500 @color/gray_100 diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index 813814edf..9f172dec6 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -278,6 +278,7 @@ Reblog Favorite Share + Bookmark Media without description Add media Add a poll