Add migration for current user settings
This commit is contained in:
parent
25446491ac
commit
68553f6e1d
|
@ -40,6 +40,11 @@ public class MainApplication extends Application {
|
|||
|
||||
AppDatabaseSettings.initDefaultSettings(getApplicationContext());
|
||||
|
||||
if (Boolean.parseBoolean(
|
||||
AppDatabaseSettings.getSettingsValue(getApplicationContext(), "prefsMigration"))) {
|
||||
AppDatabaseSettings.prefsMigration(getApplicationContext());
|
||||
}
|
||||
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
getApplicationContext(), "false", AppDatabaseSettings.APP_BIOMETRIC_LIFE_CYCLE_KEY);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import org.mian.gitnex.database.api.AppSettingsApi;
|
||||
import org.mian.gitnex.database.api.BaseApi;
|
||||
import org.mian.gitnex.database.models.AppSettings;
|
||||
|
@ -190,6 +191,10 @@ public class AppDatabaseSettings {
|
|||
APP_IMAGES_CACHE_SIZE_DEFAULT,
|
||||
APP_IMAGES_CACHE_SIZE_DEFAULT);
|
||||
}
|
||||
|
||||
if (appSettingsApi.fetchSettingCountByKey("prefsMigration") == 0) {
|
||||
appSettingsApi.insertNewSetting("prefsMigration", "true", "true");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSettingsValue(Context ctx, String key) {
|
||||
|
@ -207,9 +212,184 @@ public class AppDatabaseSettings {
|
|||
appSettingsApi.updateSettingValueByKey(val, key);
|
||||
}
|
||||
|
||||
// remove in next release
|
||||
// remove this in the upcoming releases (5.5 or up)
|
||||
public static void prefsMigration(Context ctx) {
|
||||
|
||||
TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
Log.e("TestVal", "prefsMigration-ran");
|
||||
|
||||
if (tinyDB.checkForExistingPref("themeId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("themeId")),
|
||||
AppDatabaseSettings.APP_THEME_KEY);
|
||||
tinyDB.remove("themeId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("lightThemeTimeHour")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("lightThemeTimeHour")),
|
||||
AppDatabaseSettings.APP_THEME_AUTO_LIGHT_HOUR_KEY);
|
||||
tinyDB.remove("lightThemeTimeHour");
|
||||
}
|
||||
if (tinyDB.checkForExistingPref("lightThemeTimeMinute")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("lightThemeTimeMinute")),
|
||||
AppDatabaseSettings.APP_THEME_AUTO_LIGHT_MIN_KEY);
|
||||
tinyDB.remove("lightThemeTimeMinute");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("darkThemeTimeHour")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("darkThemeTimeHour")),
|
||||
AppDatabaseSettings.APP_THEME_AUTO_DARK_HOUR_KEY);
|
||||
tinyDB.remove("darkThemeTimeHour");
|
||||
}
|
||||
if (tinyDB.checkForExistingPref("darkThemeTimeMinute")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("darkThemeTimeMinute")),
|
||||
AppDatabaseSettings.APP_THEME_AUTO_DARK_MIN_KEY);
|
||||
tinyDB.remove("darkThemeTimeMinute");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("customFontId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("customFontId")),
|
||||
AppDatabaseSettings.APP_FONT_KEY);
|
||||
tinyDB.remove("customFontId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("fragmentTabsAnimationId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("fragmentTabsAnimationId")),
|
||||
AppDatabaseSettings.APP_TABS_ANIMATION_KEY);
|
||||
tinyDB.remove("fragmentTabsAnimationId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("locale")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
tinyDB.getInt("langId") + "|" + tinyDB.getString("locale"),
|
||||
AppDatabaseSettings.APP_LOCALE_KEY);
|
||||
tinyDB.remove("locale");
|
||||
tinyDB.remove("langId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("ceColorId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("ceColorId")),
|
||||
AppDatabaseSettings.APP_CE_SYNTAX_HIGHLIGHT_KEY);
|
||||
tinyDB.remove("ceColorId");
|
||||
}
|
||||
if (tinyDB.checkForExistingPref("ceIndentationId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("ceIndentationId")),
|
||||
AppDatabaseSettings.APP_CE_INDENTATION_KEY);
|
||||
tinyDB.remove("ceIndentationId");
|
||||
}
|
||||
if (tinyDB.checkForExistingPref("ceIndentationTabsId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("ceIndentationTabsId")),
|
||||
AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY);
|
||||
tinyDB.remove("ceIndentationTabsId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("homeScreenId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("homeScreenId")),
|
||||
AppDatabaseSettings.APP_HOME_SCREEN_KEY);
|
||||
tinyDB.remove("homeScreenId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("defaultScreenId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("defaultScreenId")),
|
||||
AppDatabaseSettings.APP_LINK_HANDLER_KEY);
|
||||
tinyDB.remove("defaultScreenId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("enableCounterBadges")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("enableCounterBadges")),
|
||||
AppDatabaseSettings.APP_COUNTER_KEY);
|
||||
tinyDB.remove("enableCounterBadges");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("showLabelsInList")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("showLabelsInList")),
|
||||
AppDatabaseSettings.APP_LABELS_IN_LIST_KEY);
|
||||
tinyDB.remove("showLabelsInList");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("notificationsEnabled")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("notificationsEnabled")),
|
||||
AppDatabaseSettings.APP_NOTIFICATIONS_KEY);
|
||||
tinyDB.remove("notificationsEnabled");
|
||||
}
|
||||
if (tinyDB.checkForExistingPref("notificationsPollingDelayId")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getInt("notificationsPollingDelayId")),
|
||||
AppDatabaseSettings.APP_NOTIFICATIONS_DELAY_KEY);
|
||||
tinyDB.remove("notificationsPollingDelayId");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("biometricStatus")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("biometricStatus")),
|
||||
AppDatabaseSettings.APP_BIOMETRIC_KEY);
|
||||
tinyDB.remove("biometricStatus");
|
||||
}
|
||||
if (tinyDB.checkForExistingPref("biometricLifeCycle")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("biometricLifeCycle")),
|
||||
AppDatabaseSettings.APP_BIOMETRIC_LIFE_CYCLE_KEY);
|
||||
tinyDB.remove("biometricLifeCycle");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("useCustomTabs")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("useCustomTabs")),
|
||||
AppDatabaseSettings.APP_CUSTOM_BROWSER_KEY);
|
||||
tinyDB.remove("useCustomTabs");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("crashReportingEnabled")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("crashReportingEnabled")),
|
||||
AppDatabaseSettings.APP_CRASH_REPORTS_KEY);
|
||||
tinyDB.remove("crashReportingEnabled");
|
||||
}
|
||||
|
||||
if (tinyDB.checkForExistingPref("draftsCommentsDeletionEnabled")) {
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(tinyDB.getBoolean("draftsCommentsDeletionEnabled")),
|
||||
AppDatabaseSettings.APP_DRAFTS_DELETION_KEY);
|
||||
tinyDB.remove("draftsCommentsDeletionEnabled");
|
||||
}
|
||||
|
||||
AppDatabaseSettings.updateSettingsValue(ctx, "false", "prefsMigration");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -327,4 +327,8 @@ public class TinyDB {
|
|||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkForExistingPref(String key) {
|
||||
return preferences.contains(key);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue