Refactoring of the Connectivity Settings

This commit is contained in:
Vitor Pamplona
2023-07-23 16:33:18 -04:00
parent b055e520c2
commit 786b8436f8
20 changed files with 121 additions and 115 deletions
@@ -7,11 +7,13 @@ import androidx.compose.runtime.Immutable
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.model.GLOBAL_FOLLOWS import com.vitorpamplona.amethyst.model.GLOBAL_FOLLOWS
import com.vitorpamplona.amethyst.model.KIND3_FOLLOWS import com.vitorpamplona.amethyst.model.KIND3_FOLLOWS
import com.vitorpamplona.amethyst.model.RelaySetupInfo import com.vitorpamplona.amethyst.model.RelaySetupInfo
import com.vitorpamplona.amethyst.model.Settings import com.vitorpamplona.amethyst.model.Settings
import com.vitorpamplona.amethyst.model.hexToByteArray import com.vitorpamplona.amethyst.model.hexToByteArray
import com.vitorpamplona.amethyst.model.parseConnectivityType
import com.vitorpamplona.amethyst.service.HttpClient import com.vitorpamplona.amethyst.service.HttpClient
import com.vitorpamplona.amethyst.service.model.ContactListEvent import com.vitorpamplona.amethyst.service.model.ContactListEvent
import com.vitorpamplona.amethyst.service.model.Event import com.vitorpamplona.amethyst.service.model.Event
@@ -245,21 +247,21 @@ object LocalPreferences {
val globalPrefs = encryptedPreferences() val globalPrefs = encryptedPreferences()
globalPrefs.edit().apply { globalPrefs.edit().apply {
if (account.settings.automaticallyShowImages == null) { if (account.settings.automaticallyShowImages.prefCode == null) {
remove(PrefKeys.AUTOMATICALLY_SHOW_IMAGES) remove(PrefKeys.AUTOMATICALLY_SHOW_IMAGES)
} else { } else {
putBoolean(PrefKeys.AUTOMATICALLY_SHOW_IMAGES, account.settings.automaticallyShowImages!!) putBoolean(PrefKeys.AUTOMATICALLY_SHOW_IMAGES, account.settings.automaticallyShowImages.prefCode!!)
} }
if (account.settings.automaticallyStartPlayback == null) { if (account.settings.automaticallyStartPlayback.prefCode == null) {
remove(PrefKeys.AUTOMATICALLY_START_PLAYBACK) remove(PrefKeys.AUTOMATICALLY_START_PLAYBACK)
} else { } else {
putBoolean(PrefKeys.AUTOMATICALLY_START_PLAYBACK, account.settings.automaticallyStartPlayback!!) putBoolean(PrefKeys.AUTOMATICALLY_START_PLAYBACK, account.settings.automaticallyStartPlayback.prefCode!!)
} }
if (account.settings.automaticallyShowUrlPreview == null) { if (account.settings.automaticallyShowUrlPreview.prefCode == null) {
remove(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW) remove(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW)
} else { } else {
putBoolean(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW, account.settings.automaticallyShowUrlPreview!!) putBoolean(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW, account.settings.automaticallyShowUrlPreview.prefCode!!)
} }
putString(PrefKeys.PREFERRED_LANGUAGE, account.settings.preferredLanguage ?: "") putString(PrefKeys.PREFERRED_LANGUAGE, account.settings.preferredLanguage ?: "")
}.apply() }.apply()
@@ -390,20 +392,20 @@ object LocalPreferences {
val settings = Settings() val settings = Settings()
encryptedPreferences().apply { encryptedPreferences().apply {
settings.automaticallyShowImages = if (contains(PrefKeys.AUTOMATICALLY_SHOW_IMAGES)) { settings.automaticallyShowImages = if (contains(PrefKeys.AUTOMATICALLY_SHOW_IMAGES)) {
getBoolean(PrefKeys.AUTOMATICALLY_SHOW_IMAGES, false) parseConnectivityType(getBoolean(PrefKeys.AUTOMATICALLY_SHOW_IMAGES, false))
} else { } else {
null ConnectivityType.ALWAYS
} }
settings.automaticallyStartPlayback = if (contains(PrefKeys.AUTOMATICALLY_START_PLAYBACK)) { settings.automaticallyStartPlayback = if (contains(PrefKeys.AUTOMATICALLY_START_PLAYBACK)) {
getBoolean(PrefKeys.AUTOMATICALLY_START_PLAYBACK, false) parseConnectivityType(getBoolean(PrefKeys.AUTOMATICALLY_START_PLAYBACK, false))
} else { } else {
null ConnectivityType.ALWAYS
} }
settings.automaticallyShowUrlPreview = if (contains(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW)) { settings.automaticallyShowUrlPreview = if (contains(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW)) {
getBoolean(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW, false) parseConnectivityType(getBoolean(PrefKeys.AUTOMATICALLY_LOAD_URL_PREVIEW, false))
} else { } else {
null ConnectivityType.ALWAYS
} }
settings.preferredLanguage = getString(PrefKeys.PREFERRED_LANGUAGE, "") settings.preferredLanguage = getString(PrefKeys.PREFERRED_LANGUAGE, "")
@@ -111,7 +111,7 @@ class Account(
var userProfileCache: User? = null var userProfileCache: User? = null
fun updateAutomaticallyStartPlayback( fun updateAutomaticallyStartPlayback(
automaticallyStartPlayback: Boolean? automaticallyStartPlayback: ConnectivityType
) { ) {
settings.automaticallyStartPlayback = automaticallyStartPlayback settings.automaticallyStartPlayback = automaticallyStartPlayback
live.invalidateData() live.invalidateData()
@@ -119,7 +119,7 @@ class Account(
} }
fun updateAutomaticallyShowUrlPreview( fun updateAutomaticallyShowUrlPreview(
automaticallyShowUrlPreview: Boolean? automaticallyShowUrlPreview: ConnectivityType
) { ) {
settings.automaticallyShowUrlPreview = automaticallyShowUrlPreview settings.automaticallyShowUrlPreview = automaticallyShowUrlPreview
live.invalidateData() live.invalidateData()
@@ -127,7 +127,7 @@ class Account(
} }
fun updateAutomaticallyShowImages( fun updateAutomaticallyShowImages(
automaticallyShowImages: Boolean? automaticallyShowImages: ConnectivityType
) { ) {
settings.automaticallyShowImages = automaticallyShowImages settings.automaticallyShowImages = automaticallyShowImages
live.invalidateData() live.invalidateData()
@@ -1,11 +1,40 @@
package com.vitorpamplona.amethyst.model package com.vitorpamplona.amethyst.model
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import com.vitorpamplona.amethyst.R
@Stable @Stable
class Settings( class Settings(
var automaticallyShowImages: Boolean? = null,
var automaticallyStartPlayback: Boolean? = null,
var preferredLanguage: String? = null, var preferredLanguage: String? = null,
var automaticallyShowUrlPreview: Boolean? = null var automaticallyShowImages: ConnectivityType = ConnectivityType.ALWAYS,
var automaticallyStartPlayback: ConnectivityType = ConnectivityType.ALWAYS,
var automaticallyShowUrlPreview: ConnectivityType = ConnectivityType.ALWAYS
) )
enum class ConnectivityType(val prefCode: Boolean?, val screenCode: Int, val reourceId: Int) {
ALWAYS(null, 0, R.string.connectivity_type_always),
WIFI_ONLY(true, 1, R.string.connectivity_type_wifi_only),
NEVER(false, 2, R.string.connectivity_type_never)
}
fun parseConnectivityType(code: Boolean?): ConnectivityType {
return when (code) {
ConnectivityType.ALWAYS.prefCode -> ConnectivityType.ALWAYS
ConnectivityType.WIFI_ONLY.prefCode -> ConnectivityType.WIFI_ONLY
ConnectivityType.NEVER.prefCode -> ConnectivityType.NEVER
else -> {
ConnectivityType.ALWAYS
}
}
}
fun parseConnectivityType(screenCode: Int): ConnectivityType {
return when (screenCode) {
ConnectivityType.ALWAYS.screenCode -> ConnectivityType.ALWAYS
ConnectivityType.WIFI_ONLY.screenCode -> ConnectivityType.WIFI_ONLY
ConnectivityType.NEVER.screenCode -> ConnectivityType.NEVER
else -> {
ConnectivityType.ALWAYS
}
}
}
@@ -7,16 +7,9 @@ object ConnectivityStatus {
private val onMobileData = mutableStateOf(false) private val onMobileData = mutableStateOf(false)
val isOnMobileData: MutableState<Boolean> = onMobileData val isOnMobileData: MutableState<Boolean> = onMobileData
private val onWifi = mutableStateOf(false)
val isOnWifi: MutableState<Boolean> = onWifi
fun updateConnectivityStatus(isOnMobileData: Boolean, isOnWifi: Boolean) { fun updateConnectivityStatus(isOnMobileData: Boolean, isOnWifi: Boolean) {
if (onMobileData.value != isOnMobileData) { if (onMobileData.value != isOnMobileData) {
onMobileData.value = isOnMobileData onMobileData.value = isOnMobileData
} }
if (onWifi.value != isOnWifi) {
onWifi.value = isOnWifi
}
} }
} }
@@ -208,14 +208,13 @@ class MainActivity : AppCompatActivity() {
super.onCapabilitiesChanged(network, networkCapabilities) super.onCapabilitiesChanged(network, networkCapabilities)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
val hasMobileData = val hasMobileData = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
val hasWifi = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) val hasWifi = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
Log.d("NETWORKCALLBACK", "onCapabilitiesChanged: hasMobileData $hasMobileData") Log.d("NETWORKCALLBACK", "onCapabilitiesChanged: hasMobileData $hasMobileData")
Log.d("NETWORKCALLBACK", "onCapabilitiesChanged: hasWifi $hasWifi") Log.d("NETWORKCALLBACK", "onCapabilitiesChanged: hasWifi $hasWifi")
ConnectivityStatus.updateConnectivityStatus( ConnectivityStatus.updateConnectivityStatus(
networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR), hasMobileData,
networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) hasWifi
) )
} }
} }
@@ -8,6 +8,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
@@ -16,13 +17,12 @@ import kotlinx.coroutines.launch
@Composable @Composable
fun UrlPreview(url: String, urlText: String, accountViewModel: AccountViewModel) { fun UrlPreview(url: String, urlText: String, accountViewModel: AccountViewModel) {
val settings = accountViewModel.account.settings val automaticallyShowUrlPreview = remember {
val isMobile = ConnectivityStatus.isOnMobileData.value when (accountViewModel.account.settings.automaticallyShowUrlPreview) {
ConnectivityType.WIFI_ONLY -> !ConnectivityStatus.isOnMobileData.value
val automaticallyShowUrlPreview = when (settings.automaticallyShowUrlPreview) { ConnectivityType.NEVER -> false
true -> !isMobile ConnectivityType.ALWAYS -> true
false -> false }
else -> true
} }
if (!automaticallyShowUrlPreview) { if (!automaticallyShowUrlPreview) {
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
@@ -17,6 +18,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.service.previews.UrlInfoItem import com.vitorpamplona.amethyst.service.previews.UrlInfoItem
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
@@ -28,13 +30,12 @@ fun UrlPreviewCard(
previewInfo: UrlInfoItem, previewInfo: UrlInfoItem,
accountViewModel: AccountViewModel accountViewModel: AccountViewModel
) { ) {
val settings = accountViewModel.account.settings val automaticallyShowUrlPreview = remember {
val isMobile = ConnectivityStatus.isOnMobileData.value when (accountViewModel.account.settings.automaticallyShowUrlPreview) {
ConnectivityType.WIFI_ONLY -> !ConnectivityStatus.isOnMobileData.value
val automaticallyShowUrlPreview = when (settings.automaticallyShowUrlPreview) { ConnectivityType.NEVER -> false
true -> !isMobile ConnectivityType.ALWAYS -> true
false -> false }
else -> true
} }
if (!automaticallyShowUrlPreview) { if (!automaticallyShowUrlPreview) {
@@ -55,6 +55,7 @@ import androidx.media3.ui.PlayerView
import coil.imageLoader import coil.imageLoader
import coil.request.ImageRequest import coil.request.ImageRequest
import com.vitorpamplona.amethyst.PlaybackClientController import com.vitorpamplona.amethyst.PlaybackClientController
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.ui.note.LyricsIcon import com.vitorpamplona.amethyst.ui.note.LyricsIcon
import com.vitorpamplona.amethyst.ui.note.LyricsOffIcon import com.vitorpamplona.amethyst.ui.note.LyricsOffIcon
@@ -173,16 +174,13 @@ fun VideoViewInner(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
onDialog: ((Boolean) -> Unit)? = null onDialog: ((Boolean) -> Unit)? = null
) { ) {
val settings = accountViewModel.account.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyStartPlayback = remember { val automaticallyStartPlayback = remember {
mutableStateOf( mutableStateOf(
if (alwaysShowVideo) { true } else { if (alwaysShowVideo) { true } else {
when (settings.automaticallyStartPlayback) { when (accountViewModel.account.settings.automaticallyStartPlayback) {
true -> !isMobile ConnectivityType.WIFI_ONLY -> !ConnectivityStatus.isOnMobileData.value
false -> false ConnectivityType.NEVER -> false
else -> true ConnectivityType.ALWAYS -> true
} }
} }
) )
@@ -66,6 +66,7 @@ import coil.compose.AsyncImage
import coil.compose.AsyncImagePainter import coil.compose.AsyncImagePainter
import coil.imageLoader import coil.imageLoader
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import com.vitorpamplona.amethyst.service.BlurHashRequester import com.vitorpamplona.amethyst.service.BlurHashRequester
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
@@ -248,15 +249,13 @@ private fun LocalImageView(
) { ) {
if (content.localFile != null && content.localFile.exists()) { if (content.localFile != null && content.localFile.exists()) {
BoxWithConstraints(contentAlignment = Alignment.Center) { BoxWithConstraints(contentAlignment = Alignment.Center) {
val settings = accountViewModel?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val showImage = remember { val showImage = remember {
mutableStateOf( mutableStateOf(
if (alwayShowImage) { true } else { if (alwayShowImage) { true } else {
when (settings?.automaticallyShowImages) { when (accountViewModel?.account?.settings?.automaticallyShowImages) {
true -> !isMobile ConnectivityType.WIFI_ONLY -> !ConnectivityStatus.isOnMobileData.value
false -> false ConnectivityType.NEVER -> false
ConnectivityType.ALWAYS -> true
else -> true else -> true
} }
} }
@@ -318,15 +317,13 @@ private fun UrlImageView(
alwayShowImage: Boolean = false alwayShowImage: Boolean = false
) { ) {
BoxWithConstraints(contentAlignment = Alignment.Center) { BoxWithConstraints(contentAlignment = Alignment.Center) {
val settings = accountViewModel?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val showImage = remember { val showImage = remember {
mutableStateOf( mutableStateOf(
if (alwayShowImage) { true } else { if (alwayShowImage) { true } else {
when (settings?.automaticallyShowImages) { when (accountViewModel?.account?.settings?.automaticallyShowImages) {
true -> !isMobile ConnectivityType.WIFI_ONLY -> !ConnectivityStatus.isOnMobileData.value
false -> false ConnectivityType.NEVER -> false
ConnectivityType.ALWAYS -> true
else -> true else -> true
} }
} }
@@ -0,0 +1 @@
package com.vitorpamplona.amethyst.ui.note
@@ -77,6 +77,7 @@ import coil.request.SuccessResult
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.AddressableNote import com.vitorpamplona.amethyst.model.AddressableNote
import com.vitorpamplona.amethyst.model.Channel import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
@@ -3484,14 +3485,14 @@ private fun LongFormHeader(noteEvent: LongTextNoteEvent, note: Note, accountView
) )
) { ) {
Column { Column {
val settings = accountViewModel.account.settings val automaticallyShowUrlPreview = remember {
val isMobile = ConnectivityStatus.isOnMobileData.value when (accountViewModel.account.settings.automaticallyShowUrlPreview) {
ConnectivityType.WIFI_ONLY -> !ConnectivityStatus.isOnMobileData.value
val automaticallyShowUrlPreview = when (settings.automaticallyShowUrlPreview) { ConnectivityType.NEVER -> false
true -> !isMobile ConnectivityType.ALWAYS -> true
false -> false }
else -> true
} }
if (automaticallyShowUrlPreview) { if (automaticallyShowUrlPreview) {
image?.let { image?.let {
AsyncImage( AsyncImage(
@@ -13,6 +13,7 @@ import androidx.lifecycle.viewModelScope
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.AccountState import com.vitorpamplona.amethyst.model.AccountState
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
@@ -41,19 +42,19 @@ class AccountViewModel(val account: Account) : ViewModel() {
val userRelays: LiveData<UserState> = account.userProfile().live().relays.map { it } val userRelays: LiveData<UserState> = account.userProfile().live().relays.map { it }
fun updateAutomaticallyStartPlayback( fun updateAutomaticallyStartPlayback(
automaticallyStartPlayback: Boolean? automaticallyStartPlayback: ConnectivityType
) { ) {
account.updateAutomaticallyStartPlayback(automaticallyStartPlayback) account.updateAutomaticallyStartPlayback(automaticallyStartPlayback)
} }
fun updateAutomaticallyShowUrlPreview( fun updateAutomaticallyShowUrlPreview(
automaticallyShowUrlPreview: Boolean? automaticallyShowUrlPreview: ConnectivityType
) { ) {
account.updateAutomaticallyShowUrlPreview(automaticallyShowUrlPreview) account.updateAutomaticallyShowUrlPreview(automaticallyShowUrlPreview)
} }
fun updateAutomaticallyShowImages( fun updateAutomaticallyShowImages(
automaticallyShowImages: Boolean? automaticallyShowImages: ConnectivityType
) { ) {
account.updateAutomaticallyShowImages(automaticallyShowImages) account.updateAutomaticallyShowImages(automaticallyShowImages)
} }
@@ -35,6 +35,8 @@ import androidx.compose.ui.unit.sp
import androidx.core.os.LocaleListCompat import androidx.core.os.LocaleListCompat
import com.vitorpamplona.amethyst.LocalPreferences import com.vitorpamplona.amethyst.LocalPreferences
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.ConnectivityType
import com.vitorpamplona.amethyst.model.parseConnectivityType
import com.vitorpamplona.amethyst.ui.screen.ThemeViewModel import com.vitorpamplona.amethyst.ui.screen.ThemeViewModel
import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
import com.vitorpamplona.amethyst.ui.theme.StdPadding import com.vitorpamplona.amethyst.ui.theme.StdPadding
@@ -102,22 +104,14 @@ fun SettingsScreen(
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val selectedItens = persistentListOf( val selectedItens = persistentListOf(
stringResource(R.string.always), stringResource(ConnectivityType.ALWAYS.reourceId),
stringResource(R.string.wifi_only), stringResource(ConnectivityType.WIFI_ONLY.reourceId),
stringResource(R.string.never).replaceFirstChar { stringResource(ConnectivityType.NEVER.reourceId)
it.uppercase()
}
) )
val settings = accountViewModel.account.settings val settings = accountViewModel.account.settings
val index = if (settings.automaticallyShowImages == null) { 0 } else { val index = settings.automaticallyShowImages.screenCode
if (settings.automaticallyShowImages == true) 1 else 2 val videoIndex = settings.automaticallyStartPlayback.screenCode
} val linkIndex = settings.automaticallyShowUrlPreview.screenCode
val videoIndex = if (settings.automaticallyStartPlayback == null) { 0 } else {
if (settings.automaticallyShowImages == true) 1 else 2
}
val linkIndex = if (settings.automaticallyShowUrlPreview == null) { 0 } else {
if (settings.automaticallyShowUrlPreview == true) 1 else 2
}
val themeItens = persistentListOf( val themeItens = persistentListOf(
stringResource(R.string.system), stringResource(R.string.system),
@@ -194,11 +188,7 @@ fun SettingsScreen(
placeholder = selectedItens[index], placeholder = selectedItens[index],
options = selectedItens, options = selectedItens,
onSelect = { onSelect = {
val automaticallyShowImages = when (it) { val automaticallyShowImages = parseConnectivityType(it)
1 -> true
2 -> false
else -> null
}
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
accountViewModel.updateAutomaticallyShowImages(automaticallyShowImages) accountViewModel.updateAutomaticallyShowImages(automaticallyShowImages)
@@ -220,11 +210,7 @@ fun SettingsScreen(
placeholder = selectedItens[videoIndex], placeholder = selectedItens[videoIndex],
options = selectedItens, options = selectedItens,
onSelect = { onSelect = {
val automaticallyStartPlayback = when (it) { val automaticallyStartPlayback = parseConnectivityType(it)
1 -> true
2 -> false
else -> null
}
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
accountViewModel.updateAutomaticallyStartPlayback(automaticallyStartPlayback) accountViewModel.updateAutomaticallyStartPlayback(automaticallyStartPlayback)
@@ -246,11 +232,7 @@ fun SettingsScreen(
placeholder = selectedItens[linkIndex], placeholder = selectedItens[linkIndex],
options = selectedItens, options = selectedItens,
onSelect = { onSelect = {
val automaticallyShowUrlPreview = when (it) { val automaticallyShowUrlPreview = parseConnectivityType(it)
1 -> true
2 -> false
else -> null
}
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
accountViewModel.updateAutomaticallyShowUrlPreview(automaticallyShowUrlPreview) accountViewModel.updateAutomaticallyShowUrlPreview(automaticallyShowUrlPreview)
+2 -2
View File
@@ -461,8 +461,8 @@
<string name="add_sensitive_content_label">Citlivý obsah</string> <string name="add_sensitive_content_label">Citlivý obsah</string>
<string name="add_sensitive_content_description">Před zobrazením tohoto obsahu přidá upozornění na citlivý obsah.</string> <string name="add_sensitive_content_description">Před zobrazením tohoto obsahu přidá upozornění na citlivý obsah.</string>
<string name="settings">Nastavení</string> <string name="settings">Nastavení</string>
<string name="always">Vždy</string> <string name="connectivity_type_always">Vždy</string>
<string name="wifi_only">Pouze Wi-Fi</string> <string name="connectivity_type_wifi_only">Pouze Wi-Fi</string>
<string name="system">Systém</string> <string name="system">Systém</string>
<string name="light">Světlý</string> <string name="light">Světlý</string>
<string name="dark">Tmavý</string> <string name="dark">Tmavý</string>
+2 -2
View File
@@ -470,8 +470,8 @@ anz der Bedingungen ist erforderlich</string>
<string name="add_sensitive_content_label">Sensibler Inhalt</string> <string name="add_sensitive_content_label">Sensibler Inhalt</string>
<string name="add_sensitive_content_description">Fügt eine Warnung für sensiblen Inhalt hinzu, bevor dieser Inhalt angezeigt wird.</string> <string name="add_sensitive_content_description">Fügt eine Warnung für sensiblen Inhalt hinzu, bevor dieser Inhalt angezeigt wird.</string>
<string name="settings">Einstellungen</string> <string name="settings">Einstellungen</string>
<string name="always">Immer</string> <string name="connectivity_type_always">Immer</string>
<string name="wifi_only">Nur WLAN</string> <string name="connectivity_type_wifi_only">Nur WLAN</string>
<string name="system">System</string> <string name="system">System</string>
<string name="light">Hell</string> <string name="light">Hell</string>
<string name="dark">Dunkel</string> <string name="dark">Dunkel</string>
+2 -2
View File
@@ -455,8 +455,8 @@
<string name="add_sensitive_content_label">Érzékeny tartalom</string> <string name="add_sensitive_content_label">Érzékeny tartalom</string>
<string name="add_sensitive_content_description">Megjelenítés előtt egy érzékeny tartalom figyelmeztetés jelenik meg.</string> <string name="add_sensitive_content_description">Megjelenítés előtt egy érzékeny tartalom figyelmeztetés jelenik meg.</string>
<string name="settings">Beállítások</string> <string name="settings">Beállítások</string>
<string name="always">Mindig</string> <string name="connectivity_type_always">Mindig</string>
<string name="wifi_only">Csak WIFI</string> <string name="connectivity_type_wifi_only">Csak WIFI</string>
<string name="system">Rendszer</string> <string name="system">Rendszer</string>
<string name="light">Világos</string> <string name="light">Világos</string>
<string name="dark">Sötét</string> <string name="dark">Sötét</string>
+2 -2
View File
@@ -460,8 +460,8 @@
<string name="add_sensitive_content_label">センシティブなコンテンツ</string> <string name="add_sensitive_content_label">センシティブなコンテンツ</string>
<string name="add_sensitive_content_description">コンテンツを表示する前に、センシティブなコンテンツであることを示す警告を表示します</string> <string name="add_sensitive_content_description">コンテンツを表示する前に、センシティブなコンテンツであることを示す警告を表示します</string>
<string name="settings">設定</string> <string name="settings">設定</string>
<string name="always">常に</string> <string name="connectivity_type_always">常に</string>
<string name="wifi_only">Wifiのみ</string> <string name="connectivity_type_wifi_only">Wifiのみ</string>
<string name="system">システム</string> <string name="system">システム</string>
<string name="light">ライト</string> <string name="light">ライト</string>
<string name="dark">ダーク</string> <string name="dark">ダーク</string>
+2 -2
View File
@@ -415,8 +415,8 @@
<string name="add_sensitive_content_label">Conteúdo sensível</string> <string name="add_sensitive_content_label">Conteúdo sensível</string>
<string name="add_sensitive_content_description">Adiciona aviso de conteúdo sensível antes de mostrar este conteúdo</string> <string name="add_sensitive_content_description">Adiciona aviso de conteúdo sensível antes de mostrar este conteúdo</string>
<string name="settings">Configurações</string> <string name="settings">Configurações</string>
<string name="always">Sempre</string> <string name="connectivity_type_always">Sempre</string>
<string name="wifi_only">Somente wifi</string> <string name="connectivity_type_wifi_only">Somente wifi</string>
<string name="system">Sistema</string> <string name="system">Sistema</string>
<string name="light">Claro</string> <string name="light">Claro</string>
<string name="dark">Escuro</string> <string name="dark">Escuro</string>
+2 -2
View File
@@ -458,8 +458,8 @@
<string name="add_sensitive_content_label">Känsligt innehåll</string> <string name="add_sensitive_content_label">Känsligt innehåll</string>
<string name="add_sensitive_content_description">Lägger till varning för känsligt innehåll innan detta innehåll visas.</string> <string name="add_sensitive_content_description">Lägger till varning för känsligt innehåll innan detta innehåll visas.</string>
<string name="settings">Inställningar</string> <string name="settings">Inställningar</string>
<string name="always">Alltid</string> <string name="connectivity_type_always">Alltid</string>
<string name="wifi_only">Endast Wi-Fi</string> <string name="connectivity_type_wifi_only">Endast Wi-Fi</string>
<string name="system">System</string> <string name="system">System</string>
<string name="light">Ljus</string> <string name="light">Ljus</string>
<string name="dark">Mörk</string> <string name="dark">Mörk</string>
+4 -2
View File
@@ -482,8 +482,10 @@
<string name="add_sensitive_content_label">Sensitive Content</string> <string name="add_sensitive_content_label">Sensitive Content</string>
<string name="add_sensitive_content_description">Adds sensitive content warning before showing this content</string> <string name="add_sensitive_content_description">Adds sensitive content warning before showing this content</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="always">Always</string> <string name="connectivity_type_always">Always</string>
<string name="wifi_only">Wifi-only</string> <string name="connectivity_type_wifi_only">Wifi-only</string>
<string name="connectivity_type_never">Never</string>
<string name="system">System</string> <string name="system">System</string>
<string name="light">Light</string> <string name="light">Light</string>
<string name="dark">Dark</string> <string name="dark">Dark</string>