forked from nextcloud/notes-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotesApplication.java
More file actions
124 lines (102 loc) · 4.48 KB
/
NotesApplication.java
File metadata and controls
124 lines (102 loc) · 4.48 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Nextcloud Notes - Android Client
*
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Álvaro Brey <alvaro@alvarobrey.com>
* SPDX-FileCopyrightText: 2016-2021 Stefan Niedermann <info@niedermann.it>
* SPDX-FileCopyrightText: 2021 Konrad Pozniak <k.pozniak@gmx.at>
* SPDX-FileCopyrightText: 2020 Christoph Loy <loy.christoph@gmail.com>
* SPDX-FileCopyrightText: 2017 Daniel Bailey <dan0xii@users.noreply.github.com>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package it.niedermann.owncloud.notes;
import static androidx.preference.PreferenceManager.getDefaultSharedPreferences;
import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebView;
import androidx.appcompat.app.AppCompatDelegate;
import com.nextcloud.android.sso.FilesAppTypeRegistry;
import com.nextcloud.android.sso.model.FilesAppType;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.preferences.DarkModeSetting;
public class NotesApplication extends Application {
private static final String TAG = NotesApplication.class.getSimpleName();
private static final long LOCK_TIME = 30_000;
private static boolean lockedPreference = false;
private static boolean isLocked = true;
private static long lastInteraction = 0;
private static String PREF_KEY_THEME;
private static boolean isGridViewEnabled = false;
private static boolean isSwipeEnabled = true;
private static BrandingUtil brandingUtil;
@Override
public void onCreate() {
PREF_KEY_THEME = getString(R.string.pref_key_theme);
setAppTheme(getAppTheme(getApplicationContext()));
final var prefs = getDefaultSharedPreferences(getApplicationContext());
lockedPreference = prefs.getBoolean(getString(R.string.pref_key_lock), false);
isGridViewEnabled = getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_gridview), false);
isSwipeEnabled = getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_swipe_actions), true);
super.onCreate();
brandingUtil = BrandingUtil.getInstance(this);
if (BuildConfig.DEBUG) {
WebView.setWebContentsDebuggingEnabled(true);
}
registerFilesAppType();
}
private void registerFilesAppType() {
String packageId = getResources().getString(R.string.package_id);
String accountType = getResources().getString(R.string.account_type);
if (TextUtils.isEmpty(packageId) || TextUtils.isEmpty(accountType)) {
return;
}
FilesAppTypeRegistry.getInstance().init(new FilesAppType(packageId, accountType, FilesAppType.Stage.PROD));
}
public static BrandingUtil brandingUtil() {
return brandingUtil;
}
public static void setAppTheme(DarkModeSetting setting) {
AppCompatDelegate.setDefaultNightMode(setting.getModeId());
}
public static boolean isGridViewEnabled() {
return isGridViewEnabled;
}
public static void updateGridViewEnabled(boolean gridView) {
isGridViewEnabled = gridView;
}
public static boolean isSwipeEnabled() {
return isSwipeEnabled;
}
public static void updateSwipeEnabled(boolean swipeEnabled) {
isSwipeEnabled = swipeEnabled;
}
public static DarkModeSetting getAppTheme(Context context) {
final var prefs = getDefaultSharedPreferences(context);
String mode;
try {
mode = prefs.getString(PREF_KEY_THEME, DarkModeSetting.SYSTEM_DEFAULT.name());
} catch (ClassCastException e) {
final boolean darkModeEnabled = prefs.getBoolean(PREF_KEY_THEME, false);
mode = darkModeEnabled ? DarkModeSetting.DARK.name() : DarkModeSetting.LIGHT.name();
}
return DarkModeSetting.valueOf(mode);
}
public static void setLockedPreference(boolean lockedPreference) {
Log.i(TAG, "New locked preference: " + lockedPreference);
NotesApplication.lockedPreference = lockedPreference;
}
public static boolean isLocked() {
if (!isLocked && System.currentTimeMillis() > (LOCK_TIME + lastInteraction)) {
isLocked = true;
}
return lockedPreference && isLocked;
}
public static void unlock() {
isLocked = false;
}
public static void updateLastInteraction() {
lastInteraction = System.currentTimeMillis();
}
}