This repository was archived by the owner on May 23, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 387
Expand file tree
/
Copy pathAccountPreferenceDataStore.kt
More file actions
50 lines (44 loc) · 2.17 KB
/
AccountPreferenceDataStore.kt
File metadata and controls
50 lines (44 loc) · 2.17 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
package com.keylesspalace.tusky.settings
import androidx.preference.PreferenceDataStore
import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent
import com.keylesspalace.tusky.db.AccountManager
import com.keylesspalace.tusky.db.entity.AccountEntity
import com.keylesspalace.tusky.di.ApplicationScope
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
class AccountPreferenceDataStore @Inject constructor(
private val accountManager: AccountManager,
private val eventHub: EventHub,
@ApplicationScope private val externalScope: CoroutineScope
) : PreferenceDataStore() {
private val account: AccountEntity = accountManager.activeAccount!!
override fun getBoolean(key: String, defValue: Boolean): Boolean {
return when (key) {
PrefKeys.ALWAYS_SHOW_SENSITIVE_MEDIA -> account.alwaysShowSensitiveMedia
PrefKeys.ALWAYS_OPEN_SPOILER -> account.alwaysOpenSpoiler
PrefKeys.MEDIA_PREVIEW_ENABLED -> account.mediaPreviewEnabled
PrefKeys.TAB_FILTER_HOME_BOOSTS -> account.isShowHomeBoosts
PrefKeys.TAB_FILTER_HOME_REPLIES -> account.isShowHomeReplies
PrefKeys.TAB_SHOW_HOME_SELF_BOOSTS -> account.isShowHomeSelfBoosts
PrefKeys.FILTER_BOTS -> account.filterBots
else -> defValue
}
}
override fun putBoolean(key: String, value: Boolean) {
when (key) {
PrefKeys.ALWAYS_SHOW_SENSITIVE_MEDIA -> account.alwaysShowSensitiveMedia = value
PrefKeys.ALWAYS_OPEN_SPOILER -> account.alwaysOpenSpoiler = value
PrefKeys.MEDIA_PREVIEW_ENABLED -> account.mediaPreviewEnabled = value
PrefKeys.TAB_FILTER_HOME_BOOSTS -> account.isShowHomeBoosts = value
PrefKeys.TAB_FILTER_HOME_REPLIES -> account.isShowHomeReplies = value
PrefKeys.TAB_SHOW_HOME_SELF_BOOSTS -> account.isShowHomeSelfBoosts = value
PrefKeys.FILTER_BOTS -> account.filterBots = value
}
accountManager.saveAccount(account)
externalScope.launch {
eventHub.dispatch(PreferenceChangedEvent(key))
}
}
}