Skip to content

Commit

Permalink
migrate theme colors
Browse files Browse the repository at this point in the history
closes #849
  • Loading branch information
sk22 committed Oct 9, 2023
1 parent e9bd5a3 commit 0d5fb25
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import android.content.SharedPreferences;
import android.util.Log;

import androidx.annotation.StringRes;

import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;

Expand All @@ -25,8 +23,6 @@
import java.util.Map;
import java.util.Set;

import androidx.annotation.StringRes;

public class GlobalUserPreferences{
private static final String TAG="GlobalUserPreferences";

Expand Down Expand Up @@ -132,8 +128,13 @@ public static void load(){
.apply();
}

if(prefs.getInt("migrationLevel", 0) < 61) migrateToUpstreamVersion61();
if(prefs.getInt("migrationLevel", 0) < 101) migrateToVersion101();
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();
}

public static void save(){
Expand Down Expand Up @@ -177,13 +178,22 @@ public static void save(){
.apply();
}

private static void migrateToVersion101(){
Log.d(TAG, "Migrating preferences to version 101!! (copy current theme to local preferences)");
private static void migrateToVersion102(){
Log.d(TAG, "Migrating preferences to version 102!! (copy current theme to local preferences)");

AccountSessionManager asm=AccountSessionManager.getInstance();
for(AccountSession session : asm.getLoggedInAccounts()){
String accountID=session.getID();
AccountLocalPreferences localPrefs=session.getLocalPreferences();
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();
}
}

Expand Down Expand Up @@ -233,8 +243,6 @@ private static void migrateToUpstreamVersion61(){

localPrefs.save();
}

prefs.edit().putInt("migrationLevel", 61).apply();
}

public enum ThemePreference{
Expand Down

0 comments on commit 0d5fb25

Please sign in to comment.