forked from starifly/NekoBoxForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheme.kt
More file actions
162 lines (145 loc) · 5.76 KB
/
Copy pathTheme.kt
File metadata and controls
162 lines (145 loc) · 5.76 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package io.nekohasekai.sagernet.utils
import android.content.Context
import android.content.res.Configuration
import androidx.appcompat.app.AppCompatDelegate
import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.database.DataStore
import io.nekohasekai.sagernet.ktx.app
object Theme {
const val RED = 1
const val PINK_SSR = 2
const val PINK = 3
const val PURPLE = 4
const val DEEP_PURPLE = 5
const val INDIGO = 6
const val BLUE = 7
const val LIGHT_BLUE = 8
const val CYAN = 9
const val TEAL = 10
const val GREEN = 11
const val LIGHT_GREEN = 12
const val LIME = 13
const val YELLOW = 14
const val AMBER = 15
const val ORANGE = 16
const val DEEP_ORANGE = 17
const val BROWN = 18
const val GREY = 19
const val BLUE_GREY = 20
const val BLACK = 21
const val VERDANT_MINT = 22
const val DRACULA = 23
const val DYNAMIC = 24
private fun defaultTheme() = PINK_SSR
/**
* Metadata for a theme shown in the modern named picker.
*
* @param id one of the Theme int constants above (persisted to appTheme)
* @param nameRes display name string resource
* @param previewColor color resource for the preview swatch shown next to the name
*/
data class ThemeInfo(val id: Int, val nameRes: Int, val previewColor: Int)
/**
* Modern, full-fledged M3 themes presented by name in the picker dialog.
* The legacy single-accent palettes stay behind the "Classic colors…" grid.
* Order here is the display order in the dialog.
*/
val MODERN_THEMES: List<ThemeInfo> = listOf(
ThemeInfo(DYNAMIC, R.string.theme_dynamic, R.color.color_dynamic_swatch),
)
fun apply(context: Context) {
context.setTheme(getTheme())
}
fun applyDialog(context: Context) {
context.setTheme(getDialogTheme())
}
fun getTheme(): Int {
return getTheme(DataStore.appTheme)
}
fun getDialogTheme(): Int {
return getDialogTheme(DataStore.appTheme)
}
fun getTheme(theme: Int): Int {
return when (theme) {
RED -> R.style.Theme_SagerNet_Red
PINK -> R.style.Theme_SagerNet
PINK_SSR -> R.style.Theme_SagerNet_Pink_SSR
PURPLE -> R.style.Theme_SagerNet_Purple
DEEP_PURPLE -> R.style.Theme_SagerNet_DeepPurple
INDIGO -> R.style.Theme_SagerNet_Indigo
BLUE -> R.style.Theme_SagerNet_Blue
LIGHT_BLUE -> R.style.Theme_SagerNet_LightBlue
CYAN -> R.style.Theme_SagerNet_Cyan
TEAL -> R.style.Theme_SagerNet_Teal
GREEN -> R.style.Theme_SagerNet_Green
LIGHT_GREEN -> R.style.Theme_SagerNet_LightGreen
LIME -> R.style.Theme_SagerNet_Lime
YELLOW -> R.style.Theme_SagerNet_Yellow
AMBER -> R.style.Theme_SagerNet_Amber
ORANGE -> R.style.Theme_SagerNet_Orange
DEEP_ORANGE -> R.style.Theme_SagerNet_DeepOrange
BROWN -> R.style.Theme_SagerNet_Brown
GREY -> R.style.Theme_SagerNet_Grey
BLUE_GREY -> R.style.Theme_SagerNet_BlueGrey
BLACK -> R.style.Theme_SagerNet_Black
VERDANT_MINT -> R.style.Theme_SagerNet_VerdantMint
DRACULA -> R.style.Theme_SagerNet_Dracula
DYNAMIC -> R.style.Theme_SagerNet
else -> getTheme(defaultTheme())
}
}
fun getDialogTheme(theme: Int): Int {
return when (theme) {
RED -> R.style.Theme_SagerNet_Dialog_Red
PINK -> R.style.Theme_SagerNet_Dialog
PINK_SSR -> R.style.Theme_SagerNet_Dialog_Pink_SSR
PURPLE -> R.style.Theme_SagerNet_Dialog_Purple
DEEP_PURPLE -> R.style.Theme_SagerNet_Dialog_DeepPurple
INDIGO -> R.style.Theme_SagerNet_Dialog_Indigo
BLUE -> R.style.Theme_SagerNet_Dialog_Blue
LIGHT_BLUE -> R.style.Theme_SagerNet_Dialog_LightBlue
CYAN -> R.style.Theme_SagerNet_Dialog_Cyan
TEAL -> R.style.Theme_SagerNet_Dialog_Teal
GREEN -> R.style.Theme_SagerNet_Dialog_Green
LIGHT_GREEN -> R.style.Theme_SagerNet_Dialog_LightGreen
LIME -> R.style.Theme_SagerNet_Dialog_Lime
YELLOW -> R.style.Theme_SagerNet_Dialog_Yellow
AMBER -> R.style.Theme_SagerNet_Dialog_Amber
ORANGE -> R.style.Theme_SagerNet_Dialog_Orange
DEEP_ORANGE -> R.style.Theme_SagerNet_Dialog_DeepOrange
BROWN -> R.style.Theme_SagerNet_Dialog_Brown
GREY -> R.style.Theme_SagerNet_Dialog_Grey
BLUE_GREY -> R.style.Theme_SagerNet_Dialog_BlueGrey
BLACK -> R.style.Theme_SagerNet_Dialog_Black
VERDANT_MINT -> R.style.Theme_SagerNet_Dialog_VerdantMint
DRACULA -> R.style.Theme_SagerNet_Dialog_Dracula
DYNAMIC -> R.style.Theme_SagerNet_Dialog
else -> getDialogTheme(defaultTheme())
}
}
var currentNightMode = -1
fun getNightMode(): Int {
if (currentNightMode == -1) {
currentNightMode = DataStore.nightTheme
}
return getNightMode(currentNightMode)
}
fun getNightMode(mode: Int): Int {
return when (mode) {
0 -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
1 -> AppCompatDelegate.MODE_NIGHT_YES
2 -> AppCompatDelegate.MODE_NIGHT_NO
else -> AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
}
}
fun usingNightMode(): Boolean {
return when (DataStore.nightTheme) {
1 -> true
2 -> false
else -> (app.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
}
}
fun applyNightTheme() {
AppCompatDelegate.setDefaultNightMode(getNightMode())
}
}