Skip to content

Commit

Permalink
fix(YouTube - Settings): Do not show a toast if migrating old unknown…
Browse files Browse the repository at this point in the history
… settings
  • Loading branch information
LisoUseInAIKyrios committed Apr 9, 2024
1 parent eba73c5 commit f2e15a2
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public static void migrateFromOldPreferences(@NonNull SharedPrefCategory oldPref
if (!oldPrefs.preferences.contains(settingKey)) {
return; // Nothing to do.
}

Object newValue = setting.get();
final Object migratedValue;
if (setting instanceof BooleanSetting) {
Expand All @@ -238,13 +239,17 @@ public static void migrateFromOldPreferences(@NonNull SharedPrefCategory oldPref
migratedValue = oldPrefs.getString(settingKey, (String) newValue);
} else {
Logger.printException(() -> "Unknown setting: " + setting);
// Remove otherwise it'll show a toast on every launch
oldPrefs.preferences.edit().remove(settingKey).apply();
return;
}

oldPrefs.preferences.edit().remove(settingKey).apply(); // Remove the old setting.
if (migratedValue.equals(newValue)) {
Logger.printDebug(() -> "Value does not need migrating: " + settingKey);
return; // Old value is already equal to the new setting value.
}

Logger.printDebug(() -> "Migrating old preference value into current preference: " + settingKey);
//noinspection unchecked
setting.save(migratedValue);
Expand Down

0 comments on commit f2e15a2

Please sign in to comment.