implement bookmark button
This commit is contained in:
parent
080a320e12
commit
9c89abf1c4
|
@ -4,6 +4,7 @@ import android.os.Looper;
|
||||||
|
|
||||||
import org.joinmastodon.android.E;
|
import org.joinmastodon.android.E;
|
||||||
import org.joinmastodon.android.MastodonApp;
|
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.SetStatusFavorited;
|
||||||
import org.joinmastodon.android.api.requests.statuses.SetStatusReblogged;
|
import org.joinmastodon.android.api.requests.statuses.SetStatusReblogged;
|
||||||
import org.joinmastodon.android.events.StatusCountersUpdatedEvent;
|
import org.joinmastodon.android.events.StatusCountersUpdatedEvent;
|
||||||
|
@ -18,6 +19,7 @@ public class StatusInteractionController{
|
||||||
private final String accountID;
|
private final String accountID;
|
||||||
private final HashMap<String, SetStatusFavorited> runningFavoriteRequests=new HashMap<>();
|
private final HashMap<String, SetStatusFavorited> runningFavoriteRequests=new HashMap<>();
|
||||||
private final HashMap<String, SetStatusReblogged> runningReblogRequests=new HashMap<>();
|
private final HashMap<String, SetStatusReblogged> runningReblogRequests=new HashMap<>();
|
||||||
|
private final HashMap<String, SetStatusBookmarked> runningBookmarkRequests=new HashMap<>();
|
||||||
|
|
||||||
public StatusInteractionController(String accountID){
|
public StatusInteractionController(String accountID){
|
||||||
this.accountID=accountID;
|
this.accountID=accountID;
|
||||||
|
@ -61,6 +63,36 @@ public class StatusInteractionController{
|
||||||
E.post(new StatusCountersUpdatedEvent(status));
|
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){
|
public void setReblogged(Status status, boolean reblogged){
|
||||||
if(!Looper.getMainLooper().isCurrentThread())
|
if(!Looper.getMainLooper().isCurrentThread())
|
||||||
throw new IllegalStateException("Can only be called from main thread");
|
throw new IllegalStateException("Can only be called from main thread");
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Holder extends StatusDisplayItem.Holder<FooterStatusDisplayItem>{
|
public static class Holder extends StatusDisplayItem.Holder<FooterStatusDisplayItem>{
|
||||||
private final TextView reply, boost, favorite;
|
private final TextView reply, boost, favorite, bookmark;
|
||||||
private final ImageView share;
|
private final ImageView share;
|
||||||
|
|
||||||
private final View.AccessibilityDelegate buttonAccessibilityDelegate=new View.AccessibilityDelegate(){
|
private final View.AccessibilityDelegate buttonAccessibilityDelegate=new View.AccessibilityDelegate(){
|
||||||
|
@ -60,22 +60,27 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
reply=findViewById(R.id.reply);
|
reply=findViewById(R.id.reply);
|
||||||
boost=findViewById(R.id.boost);
|
boost=findViewById(R.id.boost);
|
||||||
favorite=findViewById(R.id.favorite);
|
favorite=findViewById(R.id.favorite);
|
||||||
|
bookmark=findViewById(R.id.bookmark);
|
||||||
share=findViewById(R.id.share);
|
share=findViewById(R.id.share);
|
||||||
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.N){
|
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.N){
|
||||||
UiUtils.fixCompoundDrawableTintOnAndroid6(reply);
|
UiUtils.fixCompoundDrawableTintOnAndroid6(reply);
|
||||||
UiUtils.fixCompoundDrawableTintOnAndroid6(boost);
|
UiUtils.fixCompoundDrawableTintOnAndroid6(boost);
|
||||||
UiUtils.fixCompoundDrawableTintOnAndroid6(favorite);
|
UiUtils.fixCompoundDrawableTintOnAndroid6(favorite);
|
||||||
|
UiUtils.fixCompoundDrawableTintOnAndroid6(bookmark);
|
||||||
}
|
}
|
||||||
View reply=findViewById(R.id.reply_btn);
|
View reply=findViewById(R.id.reply_btn);
|
||||||
View boost=findViewById(R.id.boost_btn);
|
View boost=findViewById(R.id.boost_btn);
|
||||||
View favorite=findViewById(R.id.favorite_btn);
|
View favorite=findViewById(R.id.favorite_btn);
|
||||||
View share=findViewById(R.id.share_btn);
|
View share=findViewById(R.id.share_btn);
|
||||||
|
View bookmark=findViewById(R.id.bookmark_btn);
|
||||||
reply.setOnClickListener(this::onReplyClick);
|
reply.setOnClickListener(this::onReplyClick);
|
||||||
reply.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
reply.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
||||||
boost.setOnClickListener(this::onBoostClick);
|
boost.setOnClickListener(this::onBoostClick);
|
||||||
boost.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
boost.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
||||||
favorite.setOnClickListener(this::onFavoriteClick);
|
favorite.setOnClickListener(this::onFavoriteClick);
|
||||||
favorite.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
favorite.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
||||||
|
bookmark.setOnClickListener(this::onBookmarkClick);
|
||||||
|
bookmark.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
||||||
share.setOnClickListener(this::onShareClick);
|
share.setOnClickListener(this::onShareClick);
|
||||||
share.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
share.setAccessibilityDelegate(buttonAccessibilityDelegate);
|
||||||
}
|
}
|
||||||
|
@ -87,6 +92,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
bindButton(favorite, item.status.favouritesCount);
|
bindButton(favorite, item.status.favouritesCount);
|
||||||
boost.setSelected(item.status.reblogged);
|
boost.setSelected(item.status.reblogged);
|
||||||
favorite.setSelected(item.status.favourited);
|
favorite.setSelected(item.status.favourited);
|
||||||
|
bookmark.setSelected(item.status.bookmarked);
|
||||||
boost.setEnabled(item.status.visibility==StatusPrivacy.PUBLIC || item.status.visibility==StatusPrivacy.UNLISTED
|
boost.setEnabled(item.status.visibility==StatusPrivacy.PUBLIC || item.status.visibility==StatusPrivacy.UNLISTED
|
||||||
|| (item.status.visibility==StatusPrivacy.PRIVATE && item.status.account.id.equals(AccountSessionManager.getInstance().getAccount(item.accountID).self.id)));
|
|| (item.status.visibility==StatusPrivacy.PRIVATE && item.status.account.id.equals(AccountSessionManager.getInstance().getAccount(item.accountID).self.id)));
|
||||||
}
|
}
|
||||||
|
@ -120,6 +126,11 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
bindButton(favorite, item.status.favouritesCount);
|
bindButton(favorite, item.status.favouritesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onBookmarkClick(View v){
|
||||||
|
AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setBookmarked(item.status, !item.status.bookmarked);
|
||||||
|
bookmark.setSelected(item.status.bookmarked);
|
||||||
|
}
|
||||||
|
|
||||||
private void onShareClick(View v){
|
private void onShareClick(View v){
|
||||||
Intent intent=new Intent(Intent.ACTION_SEND);
|
Intent intent=new Intent(Intent.ACTION_SEND);
|
||||||
intent.setType("text/plain");
|
intent.setType("text/plain");
|
||||||
|
@ -134,6 +145,8 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
return R.string.button_reblog;
|
return R.string.button_reblog;
|
||||||
if(id==R.id.favorite_btn)
|
if(id==R.id.favorite_btn)
|
||||||
return R.string.button_favorite;
|
return R.string.button_favorite;
|
||||||
|
if(id==R.id.bookmark_btn)
|
||||||
|
return R.string.button_bookmark;
|
||||||
if(id==R.id.share_btn)
|
if(id==R.id.share_btn)
|
||||||
return R.string.button_share;
|
return R.string.button_share;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -73,6 +73,28 @@
|
||||||
tools:text="123"/>
|
tools:text="123"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="0px"
|
||||||
|
android:layout_height="1px"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/bookmark_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:minWidth="56dp">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/bookmark"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:drawableStart="@drawable/ic_fluent_bookmark_24_selector"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:drawableTint="@color/bookmark_icon"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textAppearance="@style/m3_label_large" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<Space
|
<Space
|
||||||
android:layout_width="0px"
|
android:layout_width="0px"
|
||||||
android:layout_height="1px"
|
android:layout_height="1px"
|
||||||
|
|
|
@ -92,6 +92,7 @@
|
||||||
<color name="highlight_over_light">#18000000</color>
|
<color name="highlight_over_light">#18000000</color>
|
||||||
|
|
||||||
<color name="favorite_selected">@color/warning_500</color>
|
<color name="favorite_selected">@color/warning_500</color>
|
||||||
|
<color name="bookmark_selected">@color/success_500</color>
|
||||||
<color name="boost_selected">@color/primary_500</color>
|
<color name="boost_selected">@color/primary_500</color>
|
||||||
|
|
||||||
<color name="shortcut_icon_background">@color/gray_100</color>
|
<color name="shortcut_icon_background">@color/gray_100</color>
|
||||||
|
|
|
@ -278,6 +278,7 @@
|
||||||
<string name="button_reblog">Reblog</string>
|
<string name="button_reblog">Reblog</string>
|
||||||
<string name="button_favorite">Favorite</string>
|
<string name="button_favorite">Favorite</string>
|
||||||
<string name="button_share">Share</string>
|
<string name="button_share">Share</string>
|
||||||
|
<string name="button_bookmark">Bookmark</string>
|
||||||
<string name="media_no_description">Media without description</string>
|
<string name="media_no_description">Media without description</string>
|
||||||
<string name="add_media">Add media</string>
|
<string name="add_media">Add media</string>
|
||||||
<string name="add_poll">Add a poll</string>
|
<string name="add_poll">Add a poll</string>
|
||||||
|
|
Loading…
Reference in New Issue