Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Migration_10_11.java « migration « persistence « notes « owncloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 84ef21056f6b8d6ed3f4446920eee9abd111ac97 (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
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 java.util.Map;

import it.niedermann.owncloud.notes.preferences.DarkModeSetting;

public class Migration_10_11 extends Migration {
    @NonNull
    private final Context context;

    public Migration_10_11(@NonNull Context context) {
        super(10, 11);
        this.context = context;
    }

    /**
     * Changes the boolean for light / dark mode to {@link DarkModeSetting} to also be able to represent system default value
     */
    @Override
    public void migrate(@NonNull SupportSQLiteDatabase database) {
        final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        final var editor = sharedPreferences.edit();
        final var prefs = sharedPreferences.getAll();
        for (final var pref : prefs.entrySet()) {
            final String key = pref.getKey();
            final String DARK_THEME_KEY = "NLW_darkTheme";
            if ("darkTheme".equals(key) || key.startsWith(DARK_THEME_KEY) || key.startsWith("SNW_darkTheme")) {
                final Boolean darkTheme = (Boolean) pref.getValue();
                editor.putString(pref.getKey(), darkTheme ? DarkModeSetting.DARK.name() : DarkModeSetting.LIGHT.name());
            }
        }
        editor.apply();
    }
}