Skip to content

Commit

Permalink
Added the migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ge78fug committed Mar 1, 2023
1 parent 3a5f49d commit e438a18
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,39 @@ protected void migrate(final Context context) {
}
};

public static final Migration MIGRATION_4_5 = new Migration(4, 5) {
@Override
protected void migrate(final Context context) {
boolean brightnessGestureSwitch = sp.getBoolean(
context.getString(R.string.left_gesture_control_key), false);
boolean volumeGestureSwitch = sp.getBoolean(
context.getString(R.string.right_gesture_control_key), false);

SharedPreferences.Editor editor = sp.edit();

if (volumeGestureSwitch) {
if (!brightnessGestureSwitch) {
editor.putString(context.getString(R.string.left_gesture_control_key),
context.getString(R.string.brightness));
}
editor.putString(context.getString(R.string.right_gesture_control_key),
context.getString(R.string.volume));
} else if (brightnessGestureSwitch) {
editor.putString(context.getString(R.string.right_gesture_control_key),
context.getString(R.string.brightness));
editor.putString(context.getString(R.string.left_gesture_control_key),
context.getString(R.string.volume));
} else {
editor.putString(context.getString(R.string.left_gesture_control_key),
context.getString(R.string.none));
editor.putString(context.getString(R.string.right_gesture_control_key),
context.getString(R.string.none));
}

editor.apply();
}
};

/**
* List of all implemented migrations.
* <p>
Expand All @@ -119,12 +152,13 @@ protected void migrate(final Context context) {
MIGRATION_1_2,
MIGRATION_2_3,
MIGRATION_3_4,
MIGRATION_4_5,
};

/**
* Version number for preferences. Must be incremented every time a migration is necessary.
*/
public static final int VERSION = 4;
public static final int VERSION = 5;


public static void initMigrations(final Context context, final boolean isFirstRun) {
Expand Down

0 comments on commit e438a18

Please # to comment.