refactor: put all Moshidon local and global settings into place
This commit is contained in:
parent
23eb36a45d
commit
cb368ad17c
2 changed files with 200 additions and 0 deletions
|
@ -1,12 +1,19 @@
|
|||
package org.joinmastodon.android;
|
||||
|
||||
import static org.joinmastodon.android.api.MastodonAPIController.gson;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import org.joinmastodon.android.api.session.AccountLocalPreferences;
|
||||
import org.joinmastodon.android.api.session.AccountSession;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class GlobalUserPreferences{
|
||||
public static boolean playGifs;
|
||||
public static boolean useCustomTabs;
|
||||
|
@ -18,6 +25,47 @@ public class GlobalUserPreferences{
|
|||
public static boolean showCWs;
|
||||
public static boolean hideSensitiveMedia;
|
||||
|
||||
// MOSHIDON:
|
||||
public static boolean trueBlackTheme;
|
||||
public static boolean loadNewPosts;
|
||||
public static boolean showNewPostsButton;
|
||||
public static boolean toolbarMarquee;
|
||||
public static boolean disableSwipe;
|
||||
public static boolean enableDeleteNotifications;
|
||||
public static boolean translateButtonOpenedOnly;
|
||||
public static boolean uniformNotificationIcon;
|
||||
public static boolean reduceMotion;
|
||||
public static boolean showAltIndicator;
|
||||
public static boolean showNoAltIndicator;
|
||||
public static boolean enablePreReleases;
|
||||
public static PrefixRepliesMode prefixReplies;
|
||||
public static boolean collapseLongPosts;
|
||||
public static boolean spectatorMode;
|
||||
public static boolean autoHideFab;
|
||||
public static boolean allowRemoteLoading;
|
||||
public static AutoRevealMode autoRevealEqualSpoilers;
|
||||
public static boolean disableM3PillActiveIndicator;
|
||||
public static boolean showNavigationLabels;
|
||||
public static boolean displayPronounsInTimelines, displayPronounsInThreads, displayPronounsInUserListings;
|
||||
public static boolean overlayMedia;
|
||||
public static boolean showSuicideHelp;
|
||||
public static boolean underlinedLinks;
|
||||
public static AccountLocalPreferences.ColorPreference color;
|
||||
public static boolean likeIcon;
|
||||
public static boolean showDividers;
|
||||
public static boolean relocatePublishButton;
|
||||
public static boolean defaultToUnlistedReplies;
|
||||
public static boolean doubleTapToSearch;
|
||||
public static boolean doubleTapToSwipe;
|
||||
public static boolean confirmBeforeReblog;
|
||||
public static boolean hapticFeedback;
|
||||
public static boolean replyLineAboveHeader;
|
||||
public static boolean swapBookmarkWithBoostAction;
|
||||
public static boolean mentionRebloggerAutomatically;
|
||||
public static boolean showPostsWithoutAlt;
|
||||
public static boolean showMediaPreview;
|
||||
public static boolean removeTrackingParams;
|
||||
|
||||
private static SharedPreferences getPrefs(){
|
||||
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
@ -110,4 +158,35 @@ public class GlobalUserPreferences{
|
|||
OLD_POST,
|
||||
NON_MUTUAL
|
||||
}
|
||||
|
||||
// MOSHIDON:
|
||||
public enum AutoRevealMode {
|
||||
NEVER,
|
||||
THREADS,
|
||||
DISCUSSIONS
|
||||
}
|
||||
|
||||
// MOSHIDON:
|
||||
public enum PrefixRepliesMode {
|
||||
NEVER,
|
||||
ALWAYS,
|
||||
TO_OTHERS
|
||||
}
|
||||
|
||||
// MOSHIDON: we have jason
|
||||
public static <T> T fromJson(String json, Type type, T orElse){
|
||||
if(json==null) return orElse;
|
||||
try{
|
||||
T value=gson.fromJson(json, type);
|
||||
return value==null ? orElse : value;
|
||||
}catch(JsonSyntaxException ignored){
|
||||
return orElse;
|
||||
}
|
||||
}
|
||||
|
||||
// MOSHIDON: enums too!
|
||||
public static <T extends Enum<T>> T enumValue(Class<T> enumType, String name) {
|
||||
try { return Enum.valueOf(enumType, name); }
|
||||
catch (NullPointerException npe) { return null; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,80 @@
|
|||
package org.joinmastodon.android.api.session;
|
||||
|
||||
import static org.joinmastodon.android.GlobalUserPreferences.enumValue;
|
||||
import static org.joinmastodon.android.GlobalUserPreferences.fromJson;
|
||||
import static org.joinmastodon.android.api.MastodonAPIController.gson;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.model.ContentType;
|
||||
import org.joinmastodon.android.model.Emoji;
|
||||
import org.joinmastodon.android.model.PushSubscription;
|
||||
import org.joinmastodon.android.model.TimelineDefinition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AccountLocalPreferences{
|
||||
private final SharedPreferences prefs;
|
||||
|
||||
public boolean serverSideFiltersSupported;
|
||||
|
||||
|
||||
// MOSHIDON:
|
||||
public boolean showReplies;
|
||||
public boolean showBoosts;
|
||||
public ArrayList<String> recentLanguages;
|
||||
public boolean bottomEncoding;
|
||||
public ContentType defaultContentType;
|
||||
public boolean contentTypesEnabled;
|
||||
public ArrayList<TimelineDefinition> timelines;
|
||||
public boolean localOnlySupported;
|
||||
public boolean glitchInstance;
|
||||
public String publishButtonText;
|
||||
public String timelineReplyVisibility; // akkoma-only
|
||||
public boolean keepOnlyLatestNotification;
|
||||
public boolean emojiReactionsEnabled;
|
||||
public ShowEmojiReactions showEmojiReactions;
|
||||
public ColorPreference color;
|
||||
public ArrayList<Emoji> recentCustomEmoji;
|
||||
public boolean preReplySheet;
|
||||
|
||||
// MOSHIDON: this is also ours
|
||||
private final static Type recentLanguagesType=new TypeToken<ArrayList<String>>() {}.getType();
|
||||
private final static Type timelinesType=new TypeToken<ArrayList<TimelineDefinition>>() {}.getType();
|
||||
private final static Type recentCustomEmojiType=new TypeToken<ArrayList<Emoji>>() {}.getType();
|
||||
private final static Type notificationFiltersType = new TypeToken<PushSubscription.Alerts>() {}.getType();
|
||||
public PushSubscription.Alerts notificationFilters;
|
||||
|
||||
|
||||
public AccountLocalPreferences(SharedPreferences prefs){
|
||||
this.prefs=prefs;
|
||||
serverSideFiltersSupported=prefs.getBoolean("serverSideFilters", false);
|
||||
|
||||
// MOSHIDON:
|
||||
showReplies=prefs.getBoolean("showReplies", true);
|
||||
showBoosts=prefs.getBoolean("showBoosts", true);
|
||||
recentLanguages=fromJson(prefs.getString("recentLanguages", null), recentLanguagesType, new ArrayList<>());
|
||||
bottomEncoding=prefs.getBoolean("bottomEncoding", false);
|
||||
defaultContentType=enumValue(ContentType .class, prefs.getString("defaultContentType", ContentType.PLAIN.name()));
|
||||
contentTypesEnabled=prefs.getBoolean("contentTypesEnabled", true);
|
||||
timelines=fromJson(prefs.getString("timelines", null), timelinesType, TimelineDefinition.getDefaultTimelines(session.getID()));
|
||||
localOnlySupported=prefs.getBoolean("localOnlySupported", false);
|
||||
glitchInstance=prefs.getBoolean("glitchInstance", false);
|
||||
publishButtonText=prefs.getString("publishButtonText", null);
|
||||
timelineReplyVisibility=prefs.getString("timelineReplyVisibility", null);
|
||||
keepOnlyLatestNotification=prefs.getBoolean("keepOnlyLatestNotification", false);
|
||||
emojiReactionsEnabled=prefs.getBoolean("emojiReactionsEnabled", session.getInstance().isPresent() && session.getInstance().get().isAkkoma());
|
||||
showEmojiReactions=ShowEmojiReactions.valueOf(prefs.getString("showEmojiReactions", ShowEmojiReactions.HIDE_EMPTY.name()));
|
||||
color=prefs.contains("color") ? ColorPreference.valueOf(prefs.getString("color", null)) : null;
|
||||
recentCustomEmoji=fromJson(prefs.getString("recentCustomEmoji", null), recentCustomEmojiType, new ArrayList<>());
|
||||
notificationFilters=fromJson(prefs.getString("notificationFilters", gson.toJson(PushSubscription.Alerts.ofAll())), notificationFiltersType, PushSubscription.Alerts.ofAll());
|
||||
|
||||
}
|
||||
|
||||
public long getNotificationsPauseEndTime(){
|
||||
|
@ -23,6 +88,62 @@ public class AccountLocalPreferences{
|
|||
public void save(){
|
||||
prefs.edit()
|
||||
.putBoolean("serverSideFilters", serverSideFiltersSupported)
|
||||
|
||||
// MOSHIDON:
|
||||
.putBoolean("showReplies", showReplies)
|
||||
.putBoolean("showBoosts", showBoosts)
|
||||
.putString("recentLanguages", gson.toJson(recentLanguages))
|
||||
.putBoolean("bottomEncoding", bottomEncoding)
|
||||
.putString("defaultContentType", defaultContentType==null ? null : defaultContentType.name())
|
||||
.putBoolean("contentTypesEnabled", contentTypesEnabled)
|
||||
.putString("timelines", gson.toJson(timelines))
|
||||
.putBoolean("localOnlySupported", localOnlySupported)
|
||||
.putBoolean("glitchInstance", glitchInstance)
|
||||
.putString("publishButtonText", publishButtonText)
|
||||
.putString("timelineReplyVisibility", timelineReplyVisibility)
|
||||
.putBoolean("keepOnlyLatestNotification", keepOnlyLatestNotification)
|
||||
.putBoolean("emojiReactionsEnabled", emojiReactionsEnabled)
|
||||
.putString("showEmojiReactions", showEmojiReactions.name())
|
||||
.putString("color", color!=null ? color.name() : null)
|
||||
.putString("recentCustomEmoji", gson.toJson(recentCustomEmoji))
|
||||
.putString("notificationFilters", gson.toJson(notificationFilters))
|
||||
|
||||
.apply();
|
||||
}
|
||||
|
||||
// MOSHIDON:
|
||||
public enum ColorPreference{
|
||||
MATERIAL3,
|
||||
PURPLE,
|
||||
PINK,
|
||||
GREEN,
|
||||
BLUE,
|
||||
BROWN,
|
||||
RED,
|
||||
YELLOW,
|
||||
NORD,
|
||||
WHITE;
|
||||
|
||||
public @StringRes int getName() {
|
||||
return switch(this){
|
||||
case MATERIAL3 -> R.string.sk_color_palette_material3;
|
||||
case PINK -> R.string.sk_color_palette_pink;
|
||||
case PURPLE -> R.string.sk_color_palette_purple;
|
||||
case GREEN -> R.string.sk_color_palette_green;
|
||||
case BLUE -> R.string.sk_color_palette_blue;
|
||||
case BROWN -> R.string.sk_color_palette_brown;
|
||||
case RED -> R.string.sk_color_palette_red;
|
||||
case YELLOW -> R.string.sk_color_palette_yellow;
|
||||
case NORD -> R.string.mo_color_palette_nord;
|
||||
case WHITE -> R.string.mo_color_palette_black_and_white;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// MOSHIDON:
|
||||
public enum ShowEmojiReactions{
|
||||
HIDE_EMPTY,
|
||||
ONLY_OPENED,
|
||||
ALWAYS
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue