-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathAppearanceSettings.kt
More file actions
76 lines (66 loc) · 2.21 KB
/
AppearanceSettings.kt
File metadata and controls
76 lines (66 loc) · 2.21 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
package dev.dimension.flare.data.model
import android.content.Context
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.datastore.core.DataStore
import androidx.datastore.core.Serializer
import androidx.datastore.dataStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromByteArray
import kotlinx.serialization.encodeToByteArray
import kotlinx.serialization.protobuf.ProtoBuf
import java.io.InputStream
import java.io.OutputStream
val LocalAppearanceSettings = staticCompositionLocalOf { AppearanceSettings() }
@Serializable
data class AppearanceSettings(
val theme: Theme = Theme.SYSTEM,
val dynamicTheme: Boolean = true,
val colorSeed: ULong = Color.Blue.value,
val avatarShape: AvatarShape = AvatarShape.CIRCLE,
val showActions: Boolean = true,
val pureColorMode: Boolean = true,
val showNumbers: Boolean = true,
val showLinkPreview: Boolean = true,
val showMedia: Boolean = true,
val showSensitiveContent: Boolean = false,
val videoAutoplay: VideoAutoplay = VideoAutoplay.WIFI,
val expandMediaSize: Boolean = false,
val compatLinkPreview: Boolean = false,
)
@Serializable
enum class Theme {
LIGHT,
DARK,
SYSTEM,
}
@Serializable
enum class AvatarShape {
CIRCLE,
SQUARE,
}
@Serializable
enum class VideoAutoplay {
ALWAYS,
WIFI,
NEVER,
}
@OptIn(ExperimentalSerializationApi::class)
private object AccountPreferencesSerializer : Serializer<AppearanceSettings> {
override suspend fun readFrom(input: InputStream): AppearanceSettings = ProtoBuf.decodeFromByteArray(input.readBytes())
override suspend fun writeTo(
t: AppearanceSettings,
output: OutputStream,
) = withContext(Dispatchers.IO) {
output.write(ProtoBuf.encodeToByteArray(t))
}
override val defaultValue: AppearanceSettings
get() = AppearanceSettings()
}
internal val Context.appearanceSettings: DataStore<AppearanceSettings> by dataStore(
fileName = "appearance_settings.pb",
serializer = AccountPreferencesSerializer,
)