implement global default color

closes sk22#853
This commit is contained in:
sk
2023-10-13 01:28:59 +02:00
parent c9eac34ae6
commit f84a923102
6 changed files with 60 additions and 57 deletions

View File

@@ -1,6 +1,7 @@
package org.joinmastodon.android;
import static org.joinmastodon.android.api.MastodonAPIController.gson;
import static org.joinmastodon.android.api.session.AccountLocalPreferences.ColorPreference.MATERIAL3;
import android.content.Context;
import android.content.SharedPreferences;
@@ -10,6 +11,7 @@ import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import org.joinmastodon.android.api.session.AccountLocalPreferences;
import org.joinmastodon.android.api.session.AccountLocalPreferences.ColorPreference;
import org.joinmastodon.android.api.session.AccountSession;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.ContentType;
@@ -59,6 +61,7 @@ public class GlobalUserPreferences{
public static boolean overlayMedia;
public static boolean showSuicideHelp;
public static boolean underlinedLinks;
public static ColorPreference color;
private static SharedPreferences getPrefs(){
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
@@ -120,6 +123,7 @@ public class GlobalUserPreferences{
overlayMedia=prefs.getBoolean("overlayMedia", false);
showSuicideHelp=prefs.getBoolean("showSuicideHelp", true);
underlinedLinks=prefs.getBoolean("underlinedLinks", true);
color=ColorPreference.valueOf(prefs.getString("color", MATERIAL3.name()));
if (prefs.contains("prefixRepliesWithRe")) {
prefixReplies = prefs.getBoolean("prefixRepliesWithRe", false)
@@ -133,8 +137,6 @@ public class GlobalUserPreferences{
int migrationLevel=prefs.getInt("migrationLevel", BuildConfig.VERSION_CODE);
if(migrationLevel < 61)
migrateToUpstreamVersion61();
if(migrationLevel < 102)
migrateToVersion102();
if(migrationLevel < BuildConfig.VERSION_CODE)
prefs.edit().putInt("migrationLevel", BuildConfig.VERSION_CODE).apply();
}
@@ -178,6 +180,7 @@ public class GlobalUserPreferences{
.putBoolean("overlayMedia", overlayMedia)
.putBoolean("showSuicideHelp", showSuicideHelp)
.putBoolean("underlinedLinks", underlinedLinks)
.putString("color", color.name())
.apply();
}
@@ -202,25 +205,6 @@ public class GlobalUserPreferences{
//region preferences migrations
private static void migrateToVersion102(){
Log.d(TAG, "Migrating preferences to version 102!! (copy current theme to local preferences)");
SharedPreferences prefs=getPrefs();
// only migrate if global prefs even contains a color (but like.. it should)
if(prefs.contains("color")){
AccountSessionManager asm=AccountSessionManager.getInstance();
for(AccountSession session : asm.getLoggedInAccounts()){
if(session.getRawLocalPreferences().contains("color")) continue;
AccountLocalPreferences localPrefs=session.getLocalPreferences();
localPrefs.color=AccountLocalPreferences.ColorPreference.valueOf(prefs.getString(
"color", AccountLocalPreferences.ColorPreference.MATERIAL3.name()
));
localPrefs.save();
}
prefs.edit().remove("color").apply();
}
}
private static void migrateToUpstreamVersion61(){
Log.d(TAG, "Migrating preferences to upstream version 61!!");