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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package com.vauth.foxyvpn.ui.theme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.vauth.foxyvpn.data.SettingsStore
/**
* Reactive holder for every Interface/appearance setting. Each setter writes
* through to [SettingsStore] (the persistence source of truth) and updates
* Compose state so the whole UI recomposes instantly.
*/
class AppearanceController(private val settingsStore: SettingsStore) {
var themeMode: ThemeMode by mutableStateOf(settingsStore.themeMode)
private set
var dynamicColor: Boolean by mutableStateOf(settingsStore.dynamicColor)
private set
var colorStyle: ColorStyle by mutableStateOf(settingsStore.colorStyle)
private set
var accentColorIndex: Int by mutableIntStateOf(settingsStore.accentColorIndex)
private set
var colorContrast: ColorContrast by mutableStateOf(settingsStore.colorContrast)
private set
var reduceMotion: Boolean by mutableStateOf(settingsStore.reduceMotion)
private set
var uiFontScale: UiFontScale by mutableStateOf(settingsStore.uiFontScale)
private set
var appLanguage: AppLanguage by mutableStateOf(settingsStore.appLanguage)
private set
var screenTransition: ScreenTransition by mutableStateOf(settingsStore.screenTransition)
private set
var navBarStyle: NavBarStyle by mutableStateOf(settingsStore.navBarStyle)
private set
var connectButtonStyle: ConnectButtonStyle by mutableStateOf(settingsStore.connectButtonStyle)
private set
var cardCornerStyle: CardCornerStyle by mutableStateOf(settingsStore.cardCornerStyle)
private set
var listDensity: ListDensity by mutableStateOf(settingsStore.listDensity)
private set
var themeProfileId: String? by mutableStateOf(settingsStore.themeProfileId)
private set
var appDesign: SettingsStore.AppDesign by mutableStateOf(settingsStore.appDesign)
private set
var personalization: Personalization by mutableStateOf(settingsStore.toPersonalization())
private set
var showServerPing: Boolean by mutableStateOf(settingsStore.showServerPing)
private set
var showServerUsage: Boolean by mutableStateOf(settingsStore.showServerUsage)
private set
var monospaceAddress: Boolean by mutableStateOf(settingsStore.monospaceAddress)
private set
var confirmRemove: Boolean by mutableStateOf(settingsStore.confirmRemove)
private set
var homeAfterSelect: Boolean by mutableStateOf(settingsStore.homeAfterSelect)
private set
var doubleColumnDisplay: Boolean by mutableStateOf(settingsStore.doubleColumnDisplay)
private set
var hapticFeedback: Boolean by mutableStateOf(settingsStore.hapticFeedback)
private set
fun updateThemeMode(next: ThemeMode) {
settingsStore.themeMode = next
themeMode = next
}
/** AMOLED switch: maps onto ThemeMode.AMOLED like ZedSecure's amoledBlack. */
fun updateAmoled(on: Boolean) {
updateThemeMode(if (on) ThemeMode.AMOLED else ThemeMode.SYSTEM)
}
fun updateDynamicColor(on: Boolean) {
settingsStore.dynamicColor = on
dynamicColor = on
}
fun updateColorStyle(next: ColorStyle) {
settingsStore.colorStyle = next
colorStyle = next
clearProfileSelection()
}
fun updateAccentColorIndex(next: Int) {
settingsStore.accentColorIndex = next
accentColorIndex = next
clearProfileSelection()
}
fun updateColorContrast(next: ColorContrast) {
settingsStore.colorContrast = next
colorContrast = next
}
fun updateReduceMotion(on: Boolean) {
settingsStore.reduceMotion = on
reduceMotion = on
}
fun updateHapticFeedback(on: Boolean) {
settingsStore.hapticFeedback = on
hapticFeedback = on
}
fun updateUiFontScale(next: UiFontScale) {
settingsStore.uiFontScale = next
uiFontScale = next
}
fun updateAppLanguage(next: AppLanguage) {
settingsStore.appLanguage = next
appLanguage = next
}
fun updateScreenTransition(next: ScreenTransition) {
settingsStore.screenTransition = next
screenTransition = next
}
fun updateNavBarStyle(next: NavBarStyle) {
settingsStore.navBarStyle = next
navBarStyle = next
}
fun updateConnectButtonStyle(next: ConnectButtonStyle) {
settingsStore.connectButtonStyle = next
connectButtonStyle = next
}
fun updateCardCornerStyle(next: CardCornerStyle) {
settingsStore.cardCornerStyle = next
cardCornerStyle = next
refreshPersonalization()
}
fun updateListDensity(next: ListDensity) {
settingsStore.listDensity = next
listDensity = next
refreshPersonalization()
}
fun updateAppDesign(next: SettingsStore.AppDesign) {
settingsStore.appDesign = next
appDesign = next
}
fun updateCustomColor(which: PersonalizeSlot, argb: Long?) {
val value = argb ?: SettingsStore.UNSET_COLOR
when (which) {
PersonalizeSlot.Connect -> settingsStore.customConnectColor = value
PersonalizeSlot.Connected -> settingsStore.customConnectedColor = value
PersonalizeSlot.ServerCard -> settingsStore.customServerCardColor = value
PersonalizeSlot.ServerActive -> settingsStore.customServerActiveColor = value
PersonalizeSlot.ConfigCard -> settingsStore.customConfigCardColor = value
PersonalizeSlot.ConfigCardText -> settingsStore.customConfigCardTextColor = value
}
refreshPersonalization()
clearProfileSelection()
}
fun updateShowServerPing(on: Boolean) {
settingsStore.showServerPing = on
showServerPing = on
refreshPersonalization()
}
fun updateShowServerUsage(on: Boolean) {
settingsStore.showServerUsage = on
showServerUsage = on
refreshPersonalization()
}
fun updateMonospaceAddress(on: Boolean) {
settingsStore.monospaceAddress = on
monospaceAddress = on
refreshPersonalization()
}
fun updateConfirmRemove(on: Boolean) {
settingsStore.confirmRemove = on
confirmRemove = on
}
fun updateHomeAfterSelect(on: Boolean) {
settingsStore.homeAfterSelect = on
homeAfterSelect = on
}
fun updateDoubleColumnDisplay(on: Boolean) {
settingsStore.doubleColumnDisplay = on
doubleColumnDisplay = on
}
fun applyThemeProfile(profile: ThemeProfile?) {
if (profile == null) {
settingsStore.resetPersonalization()
} else {
settingsStore.applyThemeProfile(profile)
}
themeProfileId = settingsStore.themeProfileId
themeMode = settingsStore.themeMode
accentColorIndex = settingsStore.accentColorIndex
refreshPersonalization()
}
fun resetPersonalization() {
settingsStore.resetPersonalization()
themeProfileId = null
refreshPersonalization()
}
fun hasPersonalization(): Boolean = settingsStore.hasPersonalization()
private fun refreshPersonalization() {
personalization = settingsStore.toPersonalization()
}
private fun clearProfileSelection() {
if (themeProfileId != null) {
settingsStore.themeProfileId = null
themeProfileId = null
}
}
}
enum class PersonalizeSlot(val title: String) {
Connect("Connect button"),
Connected("Connected state"),
ServerCard("Location card"),
ServerActive("Active location card"),
ConfigCard("Config card"),
ConfigCardText("Config card text"),
}
@Composable
fun rememberAppearanceController(settingsStore: SettingsStore): AppearanceController =
remember(settingsStore) { AppearanceController(settingsStore) }