Update Preferences
This commit is contained in:
parent
140cb3ed0a
commit
27e8780d82
|
@ -0,0 +1,23 @@
|
||||||
|
package me.ash.reader.data.preference
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import me.ash.reader.ui.ext.DataStoreKeys
|
||||||
|
import me.ash.reader.ui.ext.dataStore
|
||||||
|
import me.ash.reader.ui.ext.put
|
||||||
|
|
||||||
|
object NewVersionDownloadUrlPreference {
|
||||||
|
const val default = ""
|
||||||
|
|
||||||
|
fun put(context: Context, scope: CoroutineScope, value: String) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
context.dataStore.put(DataStoreKeys.NewVersionDownloadUrl, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromPreferences(preferences: Preferences) =
|
||||||
|
preferences[DataStoreKeys.NewVersionDownloadUrl.key] ?: default
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package me.ash.reader.data.preference
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import me.ash.reader.ui.ext.DataStoreKeys
|
||||||
|
import me.ash.reader.ui.ext.dataStore
|
||||||
|
import me.ash.reader.ui.ext.put
|
||||||
|
|
||||||
|
object NewVersionLogPreference {
|
||||||
|
const val default = ""
|
||||||
|
|
||||||
|
fun put(context: Context, scope: CoroutineScope, value: String) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
context.dataStore.put(DataStoreKeys.NewVersionLog, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromPreferences(preferences: Preferences) =
|
||||||
|
preferences[DataStoreKeys.NewVersionLog.key] ?: default
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package me.ash.reader.data.preference
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import me.ash.reader.data.model.Version
|
||||||
|
import me.ash.reader.data.model.toVersion
|
||||||
|
import me.ash.reader.ui.ext.DataStoreKeys
|
||||||
|
import me.ash.reader.ui.ext.dataStore
|
||||||
|
import me.ash.reader.ui.ext.put
|
||||||
|
|
||||||
|
object NewVersionNumberPreference {
|
||||||
|
val default = Version()
|
||||||
|
|
||||||
|
fun put(context: Context, scope: CoroutineScope, value: String) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
context.dataStore.put(DataStoreKeys.NewVersionNumber, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromPreferences(preferences: Preferences) =
|
||||||
|
preferences[DataStoreKeys.NewVersionNumber.key].toVersion()
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package me.ash.reader.data.preference
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import me.ash.reader.ui.ext.DataStoreKeys
|
||||||
|
import me.ash.reader.ui.ext.dataStore
|
||||||
|
import me.ash.reader.ui.ext.put
|
||||||
|
|
||||||
|
object NewVersionPublishDatePreference {
|
||||||
|
const val default = ""
|
||||||
|
|
||||||
|
fun put(context: Context, scope: CoroutineScope, value: String) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
context.dataStore.put(DataStoreKeys.NewVersionPublishDate, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromPreferences(preferences: Preferences) =
|
||||||
|
preferences[DataStoreKeys.NewVersionPublishDate.key] ?: default
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package me.ash.reader.data.preference
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import me.ash.reader.ui.ext.DataStoreKeys
|
||||||
|
import me.ash.reader.ui.ext.dataStore
|
||||||
|
import me.ash.reader.ui.ext.put
|
||||||
|
|
||||||
|
object NewVersionSizePreference {
|
||||||
|
const val default = ""
|
||||||
|
|
||||||
|
fun Int.formatSize(): String =
|
||||||
|
(this / 1024f / 1024f)
|
||||||
|
.takeIf { it > 0f }
|
||||||
|
?.run { " ${String.format("%.2f", this)} MB" } ?: ""
|
||||||
|
|
||||||
|
fun put(context: Context, scope: CoroutineScope, value: String) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
context.dataStore.put(DataStoreKeys.NewVersionSize, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromPreferences(preferences: Preferences) =
|
||||||
|
preferences[DataStoreKeys.NewVersionSize.key] ?: default
|
||||||
|
}
|
|
@ -10,6 +10,13 @@ sealed class Preference {
|
||||||
|
|
||||||
fun Preferences.toSettings(): Settings {
|
fun Preferences.toSettings(): Settings {
|
||||||
return Settings(
|
return Settings(
|
||||||
|
newVersionNumber = NewVersionNumberPreference.fromPreferences(this),
|
||||||
|
skipVersionNumber = SkipVersionNumberPreference.fromPreferences(this),
|
||||||
|
newVersionPublishDate = NewVersionPublishDatePreference.fromPreferences(this),
|
||||||
|
newVersionLog = NewVersionLogPreference.fromPreferences(this),
|
||||||
|
newVersionSize = NewVersionSizePreference.fromPreferences(this),
|
||||||
|
newVersionDownloadUrl = NewVersionDownloadUrlPreference.fromPreferences(this),
|
||||||
|
|
||||||
themeIndex = ThemeIndexPreference.fromPreferences(this),
|
themeIndex = ThemeIndexPreference.fromPreferences(this),
|
||||||
customPrimaryColor = CustomPrimaryColorPreference.fromPreferences(this),
|
customPrimaryColor = CustomPrimaryColorPreference.fromPreferences(this),
|
||||||
darkTheme = DarkThemePreference.fromPreferences(this),
|
darkTheme = DarkThemePreference.fromPreferences(this),
|
||||||
|
|
|
@ -7,10 +7,18 @@ import androidx.compose.runtime.compositionLocalOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import me.ash.reader.data.model.Version
|
||||||
import me.ash.reader.ui.ext.collectAsStateValue
|
import me.ash.reader.ui.ext.collectAsStateValue
|
||||||
import me.ash.reader.ui.ext.dataStore
|
import me.ash.reader.ui.ext.dataStore
|
||||||
|
|
||||||
data class Settings(
|
data class Settings(
|
||||||
|
val newVersionNumber: Version = NewVersionNumberPreference.default,
|
||||||
|
val skipVersionNumber: Version = SkipVersionNumberPreference.default,
|
||||||
|
val newVersionPublishDate: String = NewVersionPublishDatePreference.default,
|
||||||
|
val newVersionLog: String = NewVersionLogPreference.default,
|
||||||
|
val newVersionSize: String = NewVersionSizePreference.default,
|
||||||
|
val newVersionDownloadUrl: String = NewVersionDownloadUrlPreference.default,
|
||||||
|
|
||||||
val themeIndex: Int = ThemeIndexPreference.default,
|
val themeIndex: Int = ThemeIndexPreference.default,
|
||||||
val customPrimaryColor: String = CustomPrimaryColorPreference.default,
|
val customPrimaryColor: String = CustomPrimaryColorPreference.default,
|
||||||
val darkTheme: DarkThemePreference = DarkThemePreference.default,
|
val darkTheme: DarkThemePreference = DarkThemePreference.default,
|
||||||
|
@ -53,6 +61,13 @@ fun SettingsProvider(
|
||||||
}.collectAsStateValue(initial = Settings())
|
}.collectAsStateValue(initial = Settings())
|
||||||
|
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
|
LocalNewVersionNumber provides settings.newVersionNumber,
|
||||||
|
LocalSkipVersionNumber provides settings.skipVersionNumber,
|
||||||
|
LocalNewVersionPublishDate provides settings.newVersionPublishDate,
|
||||||
|
LocalNewVersionLog provides settings.newVersionLog,
|
||||||
|
LocalNewVersionSize provides settings.newVersionSize,
|
||||||
|
LocalNewVersionDownloadUrl provides settings.newVersionDownloadUrl,
|
||||||
|
|
||||||
LocalThemeIndex provides settings.themeIndex,
|
LocalThemeIndex provides settings.themeIndex,
|
||||||
LocalCustomPrimaryColor provides settings.customPrimaryColor,
|
LocalCustomPrimaryColor provides settings.customPrimaryColor,
|
||||||
LocalDarkTheme provides settings.darkTheme,
|
LocalDarkTheme provides settings.darkTheme,
|
||||||
|
@ -85,6 +100,13 @@ fun SettingsProvider(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val LocalNewVersionNumber = compositionLocalOf { NewVersionNumberPreference.default }
|
||||||
|
val LocalSkipVersionNumber = compositionLocalOf { SkipVersionNumberPreference.default }
|
||||||
|
val LocalNewVersionPublishDate = compositionLocalOf { NewVersionPublishDatePreference.default }
|
||||||
|
val LocalNewVersionLog = compositionLocalOf { NewVersionLogPreference.default }
|
||||||
|
val LocalNewVersionSize = compositionLocalOf { NewVersionSizePreference.default }
|
||||||
|
val LocalNewVersionDownloadUrl = compositionLocalOf { NewVersionDownloadUrlPreference.default }
|
||||||
|
|
||||||
val LocalThemeIndex =
|
val LocalThemeIndex =
|
||||||
compositionLocalOf { ThemeIndexPreference.default }
|
compositionLocalOf { ThemeIndexPreference.default }
|
||||||
val LocalCustomPrimaryColor =
|
val LocalCustomPrimaryColor =
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package me.ash.reader.data.preference
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import me.ash.reader.data.model.Version
|
||||||
|
import me.ash.reader.data.model.toVersion
|
||||||
|
import me.ash.reader.ui.ext.DataStoreKeys
|
||||||
|
import me.ash.reader.ui.ext.dataStore
|
||||||
|
import me.ash.reader.ui.ext.put
|
||||||
|
|
||||||
|
object SkipVersionNumberPreference {
|
||||||
|
val default = Version()
|
||||||
|
|
||||||
|
fun put(context: Context, scope: CoroutineScope, value: String) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
context.dataStore.put(DataStoreKeys.SkipVersionNumber, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromPreferences(preferences: Preferences) =
|
||||||
|
preferences[DataStoreKeys.SkipVersionNumber.key].toVersion()
|
||||||
|
}
|
|
@ -11,10 +11,15 @@ import me.ash.reader.R
|
||||||
import me.ash.reader.data.model.toVersion
|
import me.ash.reader.data.model.toVersion
|
||||||
import me.ash.reader.data.module.DispatcherIO
|
import me.ash.reader.data.module.DispatcherIO
|
||||||
import me.ash.reader.data.module.DispatcherMain
|
import me.ash.reader.data.module.DispatcherMain
|
||||||
|
import me.ash.reader.data.preference.*
|
||||||
|
import me.ash.reader.data.preference.NewVersionSizePreference.formatSize
|
||||||
import me.ash.reader.data.source.AppNetworkDataSource
|
import me.ash.reader.data.source.AppNetworkDataSource
|
||||||
import me.ash.reader.data.source.Download
|
import me.ash.reader.data.source.Download
|
||||||
import me.ash.reader.data.source.downloadToFileWithProgress
|
import me.ash.reader.data.source.downloadToFileWithProgress
|
||||||
import me.ash.reader.ui.ext.*
|
import me.ash.reader.ui.ext.getCurrentVersion
|
||||||
|
import me.ash.reader.ui.ext.getLatestApk
|
||||||
|
import me.ash.reader.ui.ext.showToast
|
||||||
|
import me.ash.reader.ui.ext.skipVersionNumber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AppRepository @Inject constructor(
|
class AppRepository @Inject constructor(
|
||||||
|
@ -46,7 +51,7 @@ class AppRepository @Inject constructor(
|
||||||
}
|
}
|
||||||
val latest = response.body()!!
|
val latest = response.body()!!
|
||||||
val latestVersion = latest.tag_name.toVersion()
|
val latestVersion = latest.tag_name.toVersion()
|
||||||
// val latestVersion = "0.7.3".toVersion()
|
// val latestVersion = "1.0.0".toVersion()
|
||||||
val skipVersion = context.skipVersionNumber.toVersion()
|
val skipVersion = context.skipVersionNumber.toVersion()
|
||||||
val currentVersion = context.getCurrentVersion()
|
val currentVersion = context.getCurrentVersion()
|
||||||
val latestLog = latest.body ?: ""
|
val latestLog = latest.body ?: ""
|
||||||
|
@ -57,14 +62,11 @@ class AppRepository @Inject constructor(
|
||||||
Log.i("RLog", "current version $currentVersion")
|
Log.i("RLog", "current version $currentVersion")
|
||||||
if (latestVersion.whetherNeedUpdate(currentVersion, skipVersion)) {
|
if (latestVersion.whetherNeedUpdate(currentVersion, skipVersion)) {
|
||||||
Log.i("RLog", "new version $latestVersion")
|
Log.i("RLog", "new version $latestVersion")
|
||||||
context.dataStore.put(
|
NewVersionNumberPreference.put(context, this, latestVersion.toString())
|
||||||
DataStoreKeys.NewVersionNumber,
|
NewVersionLogPreference.put(context, this, latestLog)
|
||||||
latestVersion.toString()
|
NewVersionPublishDatePreference.put(context, this, latestPublishDate)
|
||||||
)
|
NewVersionSizePreference.put(context, this, latestSize.formatSize())
|
||||||
context.dataStore.put(DataStoreKeys.NewVersionLog, latestLog)
|
NewVersionDownloadUrlPreference.put(context, this, latestDownloadUrl)
|
||||||
context.dataStore.put(DataStoreKeys.NewVersionPublishDate, latestPublishDate)
|
|
||||||
context.dataStore.put(DataStoreKeys.NewVersionSize, latestSize)
|
|
||||||
context.dataStore.put(DataStoreKeys.NewVersionDownloadUrl, latestDownloadUrl)
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
@ -15,16 +15,6 @@ import java.io.IOException
|
||||||
|
|
||||||
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
|
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
|
||||||
|
|
||||||
val Context.newVersionPublishDate: String
|
|
||||||
get() = this.dataStore.get(DataStoreKeys.NewVersionPublishDate) ?: ""
|
|
||||||
val Context.newVersionLog: String
|
|
||||||
get() = this.dataStore.get(DataStoreKeys.NewVersionLog) ?: ""
|
|
||||||
val Context.newVersionSize: Int
|
|
||||||
get() = this.dataStore.get(DataStoreKeys.NewVersionSize) ?: 0
|
|
||||||
val Context.newVersionDownloadUrl: String
|
|
||||||
get() = this.dataStore.get(DataStoreKeys.NewVersionDownloadUrl) ?: ""
|
|
||||||
val Context.newVersionNumber: String
|
|
||||||
get() = this.dataStore.get(DataStoreKeys.NewVersionNumber) ?: ""
|
|
||||||
val Context.skipVersionNumber: String
|
val Context.skipVersionNumber: String
|
||||||
get() = this.dataStore.get(DataStoreKeys.SkipVersionNumber) ?: ""
|
get() = this.dataStore.get(DataStoreKeys.SkipVersionNumber) ?: ""
|
||||||
val Context.isFirstLaunch: Boolean
|
val Context.isFirstLaunch: Boolean
|
||||||
|
@ -93,9 +83,9 @@ sealed class DataStoreKeys<T> {
|
||||||
get() = stringPreferencesKey("newVersionLog")
|
get() = stringPreferencesKey("newVersionLog")
|
||||||
}
|
}
|
||||||
|
|
||||||
object NewVersionSize : DataStoreKeys<Int>() {
|
object NewVersionSize : DataStoreKeys<String>() {
|
||||||
override val key: Preferences.Key<Int>
|
override val key: Preferences.Key<String>
|
||||||
get() = intPreferencesKey("newVersionSize")
|
get() = stringPreferencesKey("newVersionSize")
|
||||||
}
|
}
|
||||||
|
|
||||||
object NewVersionDownloadUrl : DataStoreKeys<String>() {
|
object NewVersionDownloadUrl : DataStoreKeys<String>() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package me.ash.reader.ui.page.home.feeds
|
package me.ash.reader.ui.page.home.feeds
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
@ -25,19 +26,20 @@ import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import me.ash.reader.R
|
import me.ash.reader.R
|
||||||
import me.ash.reader.data.model.getName
|
import me.ash.reader.data.model.getName
|
||||||
import me.ash.reader.data.model.toVersion
|
|
||||||
import me.ash.reader.data.preference.*
|
import me.ash.reader.data.preference.*
|
||||||
import me.ash.reader.data.repository.SyncWorker.Companion.getIsSyncing
|
import me.ash.reader.data.repository.SyncWorker.Companion.getIsSyncing
|
||||||
|
import me.ash.reader.ui.component.FilterBar
|
||||||
import me.ash.reader.ui.component.base.Banner
|
import me.ash.reader.ui.component.base.Banner
|
||||||
import me.ash.reader.ui.component.base.DisplayText
|
import me.ash.reader.ui.component.base.DisplayText
|
||||||
import me.ash.reader.ui.component.base.FeedbackIconButton
|
import me.ash.reader.ui.component.base.FeedbackIconButton
|
||||||
import me.ash.reader.ui.component.base.Subtitle
|
import me.ash.reader.ui.component.base.Subtitle
|
||||||
import me.ash.reader.ui.ext.*
|
import me.ash.reader.ui.ext.collectAsStateValue
|
||||||
|
import me.ash.reader.ui.ext.findActivity
|
||||||
|
import me.ash.reader.ui.ext.getCurrentVersion
|
||||||
|
import me.ash.reader.ui.ext.surfaceColorAtElevation
|
||||||
import me.ash.reader.ui.page.common.RouteName
|
import me.ash.reader.ui.page.common.RouteName
|
||||||
import me.ash.reader.ui.component.FilterBar
|
|
||||||
import me.ash.reader.ui.page.home.FilterState
|
import me.ash.reader.ui.page.home.FilterState
|
||||||
import me.ash.reader.ui.page.home.HomeViewAction
|
import me.ash.reader.ui.page.home.HomeViewAction
|
||||||
import me.ash.reader.ui.page.home.HomeViewModel
|
import me.ash.reader.ui.page.home.HomeViewModel
|
||||||
|
@ -48,6 +50,7 @@ import me.ash.reader.ui.page.home.feeds.subscribe.SubscribeViewAction
|
||||||
import me.ash.reader.ui.page.home.feeds.subscribe.SubscribeViewModel
|
import me.ash.reader.ui.page.home.feeds.subscribe.SubscribeViewModel
|
||||||
import me.ash.reader.ui.theme.palette.onDark
|
import me.ash.reader.ui.theme.palette.onDark
|
||||||
|
|
||||||
|
@SuppressLint("FlowOperatorInvokedInComposition")
|
||||||
@OptIn(
|
@OptIn(
|
||||||
ExperimentalMaterial3Api::class, com.google.accompanist.pager.ExperimentalPagerApi::class,
|
ExperimentalMaterial3Api::class, com.google.accompanist.pager.ExperimentalPagerApi::class,
|
||||||
androidx.compose.foundation.ExperimentalFoundationApi::class
|
androidx.compose.foundation.ExperimentalFoundationApi::class
|
||||||
|
@ -71,16 +74,8 @@ fun FeedsPage(
|
||||||
val feedsViewState = feedsViewModel.viewState.collectAsStateValue()
|
val feedsViewState = feedsViewModel.viewState.collectAsStateValue()
|
||||||
val filterState = homeViewModel.filterState.collectAsStateValue()
|
val filterState = homeViewModel.filterState.collectAsStateValue()
|
||||||
|
|
||||||
val skipVersion = context.dataStore.data
|
val newVersion = LocalNewVersionNumber.current
|
||||||
.map { it[DataStoreKeys.SkipVersionNumber.key] ?: "" }
|
val skipVersion = LocalSkipVersionNumber.current
|
||||||
.collectAsState(initial = "")
|
|
||||||
.value
|
|
||||||
.toVersion()
|
|
||||||
val latestVersion = context.dataStore.data
|
|
||||||
.map { it[DataStoreKeys.NewVersionNumber.key] ?: "" }
|
|
||||||
.collectAsState(initial = "")
|
|
||||||
.value
|
|
||||||
.toVersion()
|
|
||||||
val currentVersion by remember { mutableStateOf(context.getCurrentVersion()) }
|
val currentVersion by remember { mutableStateOf(context.getCurrentVersion()) }
|
||||||
|
|
||||||
val owner = LocalLifecycleOwner.current
|
val owner = LocalLifecycleOwner.current
|
||||||
|
@ -145,7 +140,7 @@ fun FeedsPage(
|
||||||
imageVector = Icons.Outlined.Settings,
|
imageVector = Icons.Outlined.Settings,
|
||||||
contentDescription = stringResource(R.string.settings),
|
contentDescription = stringResource(R.string.settings),
|
||||||
tint = MaterialTheme.colorScheme.onSurface,
|
tint = MaterialTheme.colorScheme.onSurface,
|
||||||
showBadge = latestVersion.whetherNeedUpdate(currentVersion, skipVersion),
|
showBadge = newVersion.whetherNeedUpdate(currentVersion, skipVersion),
|
||||||
) {
|
) {
|
||||||
navController.navigate(RouteName.SETTINGS) {
|
navController.navigate(RouteName.SETTINGS) {
|
||||||
launchSingleTop = true
|
launchSingleTop = true
|
||||||
|
|
|
@ -9,7 +9,10 @@ import androidx.compose.material.icons.outlined.*
|
||||||
import androidx.compose.material.icons.rounded.ArrowBack
|
import androidx.compose.material.icons.rounded.ArrowBack
|
||||||
import androidx.compose.material.icons.rounded.Close
|
import androidx.compose.material.icons.rounded.Close
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
@ -17,14 +20,12 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import me.ash.reader.R
|
import me.ash.reader.R
|
||||||
import me.ash.reader.data.model.toVersion
|
import me.ash.reader.data.preference.LocalNewVersionNumber
|
||||||
|
import me.ash.reader.data.preference.LocalSkipVersionNumber
|
||||||
import me.ash.reader.ui.component.base.Banner
|
import me.ash.reader.ui.component.base.Banner
|
||||||
import me.ash.reader.ui.component.base.DisplayText
|
import me.ash.reader.ui.component.base.DisplayText
|
||||||
import me.ash.reader.ui.component.base.FeedbackIconButton
|
import me.ash.reader.ui.component.base.FeedbackIconButton
|
||||||
import me.ash.reader.ui.ext.DataStoreKeys
|
|
||||||
import me.ash.reader.ui.ext.dataStore
|
|
||||||
import me.ash.reader.ui.ext.getCurrentVersion
|
import me.ash.reader.ui.ext.getCurrentVersion
|
||||||
import me.ash.reader.ui.page.common.RouteName
|
import me.ash.reader.ui.page.common.RouteName
|
||||||
import me.ash.reader.ui.page.settings.tips.UpdateDialog
|
import me.ash.reader.ui.page.settings.tips.UpdateDialog
|
||||||
|
@ -40,16 +41,8 @@ fun SettingsPage(
|
||||||
updateViewModel: UpdateViewModel = hiltViewModel(),
|
updateViewModel: UpdateViewModel = hiltViewModel(),
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val skipVersion = context.dataStore.data
|
val newVersion = LocalNewVersionNumber.current
|
||||||
.map { it[DataStoreKeys.SkipVersionNumber.key] ?: "" }
|
val skipVersion = LocalSkipVersionNumber.current
|
||||||
.collectAsState(initial = "")
|
|
||||||
.value
|
|
||||||
.toVersion()
|
|
||||||
val latestVersion = context.dataStore.data
|
|
||||||
.map { it[DataStoreKeys.NewVersionNumber.key] ?: "" }
|
|
||||||
.collectAsState(initial = "")
|
|
||||||
.value
|
|
||||||
.toVersion()
|
|
||||||
val currentVersion by remember { mutableStateOf(context.getCurrentVersion()) }
|
val currentVersion by remember { mutableStateOf(context.getCurrentVersion()) }
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
@ -81,13 +74,13 @@ fun SettingsPage(
|
||||||
}
|
}
|
||||||
item {
|
item {
|
||||||
Box {
|
Box {
|
||||||
if (latestVersion.whetherNeedUpdate(currentVersion, skipVersion)) {
|
if (newVersion.whetherNeedUpdate(currentVersion, skipVersion)) {
|
||||||
Banner(
|
Banner(
|
||||||
modifier = Modifier.zIndex(1f),
|
modifier = Modifier.zIndex(1f),
|
||||||
title = stringResource(R.string.get_new_updates),
|
title = stringResource(R.string.get_new_updates),
|
||||||
desc = stringResource(
|
desc = stringResource(
|
||||||
R.string.get_new_updates_desc,
|
R.string.get_new_updates_desc,
|
||||||
latestVersion.toString(),
|
newVersion.toString(),
|
||||||
),
|
),
|
||||||
icon = Icons.Outlined.Lightbulb,
|
icon = Icons.Outlined.Lightbulb,
|
||||||
action = {
|
action = {
|
||||||
|
|
|
@ -31,12 +31,12 @@ import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import me.ash.reader.R
|
import me.ash.reader.R
|
||||||
|
import me.ash.reader.data.preference.*
|
||||||
import me.ash.reader.data.source.Download
|
import me.ash.reader.data.source.Download
|
||||||
import me.ash.reader.ui.component.base.Dialog
|
import me.ash.reader.ui.component.base.Dialog
|
||||||
import me.ash.reader.ui.ext.*
|
import me.ash.reader.ui.ext.collectAsStateValue
|
||||||
|
import me.ash.reader.ui.ext.installLatestApk
|
||||||
|
|
||||||
@SuppressLint("FlowOperatorInvokedInComposition")
|
@SuppressLint("FlowOperatorInvokedInComposition")
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -47,24 +47,10 @@ fun UpdateDialog(
|
||||||
val viewState = updateViewModel.viewState.collectAsStateValue()
|
val viewState = updateViewModel.viewState.collectAsStateValue()
|
||||||
val downloadState = viewState.downloadFlow.collectAsState(initial = Download.NotYet).value
|
val downloadState = viewState.downloadFlow.collectAsState(initial = Download.NotYet).value
|
||||||
val scope = rememberCoroutineScope { Dispatchers.IO }
|
val scope = rememberCoroutineScope { Dispatchers.IO }
|
||||||
val newVersionNumber = context.dataStore.data
|
val newVersionNumber = LocalNewVersionNumber.current
|
||||||
.map { it[DataStoreKeys.NewVersionNumber.key] ?: "" }
|
val newVersionPublishDate = LocalNewVersionPublishDate.current
|
||||||
.collectAsState(initial = "")
|
val newVersionLog = LocalNewVersionLog.current
|
||||||
.value
|
val newVersionSize = LocalNewVersionSize.current
|
||||||
val newVersionPublishDate = context.dataStore.data
|
|
||||||
.map { it[DataStoreKeys.NewVersionPublishDate.key] ?: "" }
|
|
||||||
.collectAsState(initial = "")
|
|
||||||
.value
|
|
||||||
val newVersionLog = context.dataStore.data
|
|
||||||
.map { it[DataStoreKeys.NewVersionLog.key] ?: "" }
|
|
||||||
.collectAsState(initial = "")
|
|
||||||
.value
|
|
||||||
val newVersionSize = " " + context.dataStore.data
|
|
||||||
.map { it[DataStoreKeys.NewVersionSize.key] ?: 0 }
|
|
||||||
.map { it / 1024f / 1024f }
|
|
||||||
.map { if (it > 0f) " ${String.format("%.2f", it)} MB" else "" }
|
|
||||||
.collectAsState(initial = 0)
|
|
||||||
.value
|
|
||||||
|
|
||||||
val settings = rememberLauncherForActivityResult(
|
val settings = rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
|
@ -104,7 +90,7 @@ fun UpdateDialog(
|
||||||
Text(text = stringResource(R.string.change_log))
|
Text(text = stringResource(R.string.change_log))
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "$newVersionPublishDate$newVersionSize",
|
text = "$newVersionPublishDate $newVersionSize",
|
||||||
color = MaterialTheme.colorScheme.outline.copy(alpha = 0.7f),
|
color = MaterialTheme.colorScheme.outline.copy(alpha = 0.7f),
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
|
@ -125,7 +111,7 @@ fun UpdateDialog(
|
||||||
context.startActivity(
|
context.startActivity(
|
||||||
Intent(
|
Intent(
|
||||||
Intent.ACTION_VIEW,
|
Intent.ACTION_VIEW,
|
||||||
Uri.parse(context.getString(R.string.github_link)),
|
Uri.parse("${context.getString(R.string.github_link)}/releases/latest"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
// Disable automatic updates in F-Droid
|
// Disable automatic updates in F-Droid
|
||||||
|
@ -162,10 +148,8 @@ fun UpdateDialog(
|
||||||
if (downloadState !is Download.Progress) {
|
if (downloadState !is Download.Progress) {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch {
|
SkipVersionNumberPreference.put(context, scope, newVersionNumber.toString())
|
||||||
context.dataStore.put(DataStoreKeys.SkipVersionNumber, newVersionNumber)
|
updateViewModel.dispatch(UpdateViewAction.Hide)
|
||||||
updateViewModel.dispatch(UpdateViewAction.Hide)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(R.string.skip_this_version))
|
Text(text = stringResource(R.string.skip_this_version))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user