blob: 18e9eba00547702a4ff63be6a7399965bf515df5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package it.niedermann.owncloud.notes.persistence.migration;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
import it.niedermann.owncloud.notes.persistence.SyncWorker;
/**
* Enabling backgroundSync, set from {@link String} values to {@link Boolean} values
* https://github.com/stefan-niedermann/nextcloud-notes/issues/1168
*/
public class Migration_21_22 extends Migration {
@NonNull
private final Context context;
public Migration_21_22(@NonNull Context context) {
super(21, 22);
this.context = context;
}
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
if (sharedPreferences.contains("backgroundSync")) {
if (sharedPreferences.getString("backgroundSync", "on").equals("off")) {
editor.remove("backgroundSync");
editor.putBoolean("backgroundSync", false);
SyncWorker.update(context, false);
} else {
editor.remove("backgroundSync");
editor.putBoolean("backgroundSync", true);
SyncWorker.update(context, true);
}
} else {
SyncWorker.update(context, true);
}
editor.apply();
}
}
|