android: Better shared preference handling (#1471)

* android: Better shared preference handling

* To make sure we return real value, not untransformed one

* Revert "To make sure we return real value, not untransformed one"

This reverts commit 5a268e2cf4.
This commit is contained in:
Stanislav Dmitrenko
2022-12-01 01:20:08 +03:00
committed by GitHub
parent 9ad29aa17e
commit a4dd520248
2 changed files with 14 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.outlined.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
@@ -1480,7 +1481,18 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
}
}
class SharedPreference<T>(val get: () -> T, val set: (T) -> Unit)
class SharedPreference<T>(val get: () -> T, set: (T) -> Unit) {
val set: (T) -> Unit
private val _state: MutableState<T> by lazy { mutableStateOf(get()) }
val state: State<T> by lazy { _state }
init {
this.set = { value ->
set(value)
_state.value = value
}
}
}
// ChatCommand
sealed class CC {

View File

@@ -33,7 +33,7 @@ fun ChatListNavLinkView(chat: Chat, chatModel: ChatModel) {
chat.chatStats.unreadCount > 0 || chat.chatStats.unreadChat
}
val stopped = chatModel.chatRunning.value == false
val linkMode = chatModel.controller.appPrefs.simplexLinkMode.get()
val linkMode by remember { chatModel.controller.appPrefs.simplexLinkMode.state }
LaunchedEffect(chat.id) {
showMenu.value = false
delay(500L)