diff --git a/app/src/main/java/me/ash/reader/data/entity/Version.kt b/app/src/main/java/me/ash/reader/data/entity/Version.kt index f362526..1d8243f 100644 --- a/app/src/main/java/me/ash/reader/data/entity/Version.kt +++ b/app/src/main/java/me/ash/reader/data/entity/Version.kt @@ -28,3 +28,5 @@ class Version(identifiers: List) { override fun toString() = "$major.$minor.$point" } + +fun String?.toVersion(): Version = Version(this) diff --git a/app/src/main/java/me/ash/reader/data/repository/AppRepository.kt b/app/src/main/java/me/ash/reader/data/repository/AppRepository.kt index 4948c6e..0697c43 100644 --- a/app/src/main/java/me/ash/reader/data/repository/AppRepository.kt +++ b/app/src/main/java/me/ash/reader/data/repository/AppRepository.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext import me.ash.reader.R -import me.ash.reader.data.entity.Version +import me.ash.reader.data.entity.toVersion import me.ash.reader.data.module.ApplicationScope import me.ash.reader.data.module.DispatcherIO import me.ash.reader.data.source.AppNetworkDataSource @@ -24,12 +24,12 @@ class AppRepository @Inject constructor( private val dispatcherIO: CoroutineDispatcher, ) { suspend fun checkUpdate(): Boolean = withContext(dispatcherIO) { - return@withContext try { + try { val latest = appNetworkDataSource.getReleaseLatest(context.getString(R.string.update_link)) - val latestVersion = Version(latest.tag_name) -// val latestVersion = Version("0.7.3") - val skipVersion = Version(context.skipVersionNumber) + val latestVersion = latest.tag_name.toVersion() +// val latestVersion = "0.7.3".toVersion() + val skipVersion = context.skipVersionNumber.toVersion() val currentVersion = context.getCurrentVersion() val latestLog = latest.body ?: "" val latestPublishDate = latest.published_at ?: latest.created_at ?: "" diff --git a/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt b/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt index d2f6a43..c2a12aa 100644 --- a/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt +++ b/app/src/main/java/me/ash/reader/ui/ext/ContextExt.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Context import android.content.ContextWrapper import me.ash.reader.data.entity.Version +import me.ash.reader.data.entity.toVersion fun Context.findActivity(): Activity? = when (this) { is Activity -> this @@ -11,5 +12,7 @@ fun Context.findActivity(): Activity? = when (this) { else -> null } -fun Context.getCurrentVersion(): Version = - Version(packageManager.getPackageInfo(packageName, 0).versionName) \ No newline at end of file +fun Context.getCurrentVersion(): Version = packageManager + .getPackageInfo(packageName, 0) + .versionName + .toVersion() \ No newline at end of file diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt index f012f9b..74904d4 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt @@ -30,6 +30,7 @@ import androidx.work.WorkInfo import kotlinx.coroutines.flow.map import me.ash.reader.R import me.ash.reader.data.entity.Version +import me.ash.reader.data.entity.toVersion import me.ash.reader.data.repository.SyncWorker.Companion.getIsSyncing import me.ash.reader.ui.component.Banner import me.ash.reader.ui.component.DisplayText @@ -65,14 +66,14 @@ fun FeedsPage( val skipVersion = context.dataStore.data .map { it[DataStoreKeys.SkipVersionNumber.key] ?: "" } - .map { Version(it) } - .collectAsState(initial = Version()) + .collectAsState(initial = "") .value + .toVersion() val latestVersion = context.dataStore.data .map { it[DataStoreKeys.NewVersionNumber.key] ?: "" } - .map { Version(it) } - .collectAsState(initial = Version()) + .collectAsState(initial = "") .value + .toVersion() val currentVersion by remember { mutableStateOf(context.getCurrentVersion()) } val owner = LocalLifecycleOwner.current diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt b/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt index e7589fd..baa85a1 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt @@ -18,7 +18,7 @@ import androidx.compose.ui.zIndex import androidx.navigation.NavHostController import kotlinx.coroutines.flow.map import me.ash.reader.R -import me.ash.reader.data.entity.Version +import me.ash.reader.data.entity.toVersion import me.ash.reader.ui.component.Banner import me.ash.reader.ui.component.DisplayText import me.ash.reader.ui.component.FeedbackIconButton @@ -38,14 +38,14 @@ fun SettingsPage( var updateDialogVisible by remember { mutableStateOf(false) } val skipVersion = context.dataStore.data .map { it[DataStoreKeys.SkipVersionNumber.key] ?: "" } - .map { Version(it) } - .collectAsState(initial = Version()) + .collectAsState(initial = "") .value + .toVersion() val latestVersion = context.dataStore.data .map { it[DataStoreKeys.NewVersionNumber.key] ?: "" } - .map { Version(it) } - .collectAsState(initial = Version()) + .collectAsState(initial = "") .value + .toVersion() val currentVersion by remember { mutableStateOf(context.getCurrentVersion()) } Scaffold( diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt b/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt index bae04a1..c1d8f7d 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/TipsAndSupport.kt @@ -110,7 +110,6 @@ fun TipsAndSupport( }, onTap = { scope.launch { - context.dataStore.put(DataStoreKeys.SkipVersionNumber, "") updateViewModel.dispatch( UpdateViewAction.CheckUpdate( { @@ -120,11 +119,13 @@ fun TipsAndSupport( ) }, { - if (!it) Toast.makeText( - context, - isLatestVersion, - Toast.LENGTH_SHORT - ).show() + if (!it) { + Toast.makeText( + context, + isLatestVersion, + Toast.LENGTH_SHORT + ).show() + } } ) ) diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/UpdateViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/settings/UpdateViewModel.kt index fdf3570..3593603 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/UpdateViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/UpdateViewModel.kt @@ -36,7 +36,7 @@ class UpdateViewModel @Inject constructor( viewModelScope.launch { preProcessor() appRepository.checkUpdate().let { - if (it) changeUpdateDialogVisible(true) + changeUpdateDialogVisible(it) postProcessor(it) } }