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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
package it.niedermann.nextcloud.deck;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import com.jakewharton.threetenabp.AndroidThreeTen;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode;
import static androidx.multidex.MultiDex.install;
public class DeckApplication extends Application {
public static final long NO_ACCOUNT_ID = -1L;
public static final long NO_BOARD_ID = -1L;
public static final long NO_STACK_ID = -1L;
@Override
public void onCreate() {
setAppTheme(isDarkTheme(getApplicationContext()));
super.onCreate();
AndroidThreeTen.init(this);
}
// --------
// Multidex
// --------
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
install(this);
}
// -----------------
// Day / Night theme
// -----------------
public static void setAppTheme(boolean darkTheme) {
setDefaultNightMode(darkTheme ? MODE_NIGHT_YES : MODE_NIGHT_NO);
}
public static boolean isDarkTheme(@NonNull Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.pref_key_dark_theme), false);
}
// --------------------------------------
// Current account / board / stack states
// --------------------------------------
public static void saveCurrentAccountId(@NonNull Context context, long accountId) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_last_account" + " | " + accountId);
editor.putLong(context.getString(R.string.shared_preference_last_account), accountId);
editor.apply();
}
public static long readCurrentAccountId(@NonNull Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
long accountId = sharedPreferences.getLong(context.getString(R.string.shared_preference_last_account), NO_ACCOUNT_ID);
DeckLog.log("--- Read: shared_preference_last_account" + " | " + accountId);
return accountId;
}
public static void saveCurrentBoardId(@NonNull Context context, long accountId, long boardId) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_last_board_for_account_" + accountId + " | " + boardId);
editor.putLong(context.getString(R.string.shared_preference_last_board_for_account_) + accountId, boardId);
editor.apply();
}
public static long readCurrentBoardId(@NonNull Context context, long accountId) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
long boardId = sharedPreferences.getLong(context.getString(R.string.shared_preference_last_board_for_account_) + accountId, NO_BOARD_ID);
DeckLog.log("--- Read: shared_preference_last_board_for_account_" + accountId + " | " + boardId);
return boardId;
}
public static void saveCurrentStackId(@NonNull Context context, long accountId, long boardId, long stackId) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
DeckLog.log("--- Write: shared_preference_last_stack_for_account_and_board_" + accountId + "_" + boardId + " | " + stackId);
editor.putLong(context.getString(R.string.shared_preference_last_stack_for_account_and_board_) + accountId + "_" + boardId, stackId);
editor.apply();
}
public static long readCurrentStackId(@NonNull Context context, long accountId, long boardId) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
long savedStackId = sharedPreferences.getLong(context.getString(R.string.shared_preference_last_stack_for_account_and_board_) + accountId + "_" + boardId, NO_STACK_ID);
DeckLog.log("--- Read: shared_preference_last_stack_for_account_and_board" + accountId + "_" + boardId + " | " + savedStackId);
return savedStackId;
}
}
|