Add post pinning

closes #346
This commit is contained in:
Grishka 2024-02-29 00:57:47 +03:00
parent 58259d9fb0
commit b4904024c6
6 changed files with 44 additions and 2 deletions

View File

@ -9,7 +9,7 @@ android {
applicationId "org.joinmastodon.android"
minSdk 23
targetSdk 33
versionCode 86
versionCode 87
versionName "2.4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs "ar-rSA", "be-rBY", "bn-rBD", "bs-rBA", "ca-rES", "cs-rCZ", "da-rDK", "de-rDE", "el-rGR", "es-rES", "eu-rES", "fa-rIR", "fi-rFI", "fil-rPH", "fr-rFR", "ga-rIE", "gd-rGB", "gl-rES", "hi-rIN", "hr-rHR", "hu-rHU", "hy-rAM", "ig-rNG", "in-rID", "is-rIS", "it-rIT", "iw-rIL", "ja-rJP", "ka-rGE", "kab", "ko-rKR", "lt-rLT", "my-rMM", "nl-rNL", "no-rNO", "oc-rFR", "pl-rPL", "pt-rBR", "pt-rPT", "ro-rRO", "ru-rRU", "si-rLK", "sl-rSI", "sv-rSE", "th-rTH", "tr-rTR", "uk-rUA", "ur-rIN", "vi-rVN", "zh-rCN", "zh-rTW"

View File

@ -0,0 +1,11 @@
package org.joinmastodon.android.api.requests.statuses;
import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.Status;
public class SetStatusPinned extends MastodonAPIRequest<Status>{
public SetStatusPinned(String id, boolean pinned){
super(HttpMethod.POST, "/statuses/"+id+"/"+(pinned ? "pin" : "unpin"), Status.class);
setRequestBody(new Object());
}
}

View File

@ -60,7 +60,7 @@ public class Status extends BaseModel implements DisplayItemsParent{
public boolean reblogged;
public boolean muted;
public boolean bookmarked;
public boolean pinned;
public Boolean pinned;
public transient boolean spoilerRevealed;
public transient boolean hasGapAfter;

View File

@ -25,6 +25,7 @@ import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships;
import org.joinmastodon.android.api.requests.statuses.GetStatusSourceText;
import org.joinmastodon.android.api.requests.statuses.SetStatusPinned;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.AddAccountToListsFragment;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
@ -36,6 +37,7 @@ import org.joinmastodon.android.model.Attachment;
import org.joinmastodon.android.model.Relationship;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.OutlineProviders;
import org.joinmastodon.android.ui.Snackbar;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
import org.joinmastodon.android.ui.utils.UiUtils;
@ -208,6 +210,24 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
}else if(id==R.id.copy_link){
activity.getSystemService(ClipboardManager.class).setPrimaryClip(ClipData.newPlainText(null, item.status.url));
UiUtils.maybeShowTextCopiedToast(activity);
}else if(id==R.id.pin){
new SetStatusPinned(item.status.id, !item.status.pinned)
.setCallback(new Callback<>(){
@Override
public void onSuccess(Status result){
item.status.pinned=!item.status.pinned;
new Snackbar.Builder(activity)
.setText(item.status.pinned ? R.string.post_pinned : R.string.post_unpinned)
.show();
}
@Override
public void onError(ErrorResponse error){
error.showToast(activity);
}
})
.wrapProgress(activity, R.string.loading, true)
.exec(item.accountID);
}
return true;
});
@ -293,11 +313,17 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
MenuItem report=menu.findItem(R.id.report);
MenuItem follow=menu.findItem(R.id.follow);
MenuItem bookmark=menu.findItem(R.id.bookmark);
MenuItem pin=menu.findItem(R.id.pin);
if(item.status!=null){
bookmark.setVisible(true);
bookmark.setTitle(item.status.bookmarked ? R.string.remove_bookmark : R.string.add_bookmark);
pin.setVisible(item.status.pinned!=null);
if(item.status.pinned!=null){
pin.setTitle(item.status.pinned ? R.string.unpin_post : R.string.pin_post);
}
}else{
bookmark.setVisible(false);
pin.setVisible(false);
}
if(isOwnPost){
mute.setVisible(false);

View File

@ -2,6 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/menu_group1">
<item android:id="@+id/translate" android:title="@string/translate_post"/>
<item android:id="@+id/pin" android:title="@string/pin_post"/>
<item android:id="@+id/bookmark" android:title="@string/add_bookmark"/>
<item android:id="@+id/share" android:title="@string/button_share"/>
<item android:id="@+id/open_in_browser" android:title="@string/open_in_browser"/>

View File

@ -716,4 +716,8 @@
<string name="tab_home">Home</string>
<string name="tab_search">Explore</string>
<string name="tab_profile">Profile</string>
<string name="pin_post">Pin on profile</string>
<string name="unpin_post">Unpin from profile</string>
<string name="post_pinned">Post has been pinned</string>
<string name="post_unpinned">Post has been unpinned</string>
</resources>