From 3068aab681fb907248df300221abea1e1229d571 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 19 May 2024 20:25:59 +0800 Subject: [PATCH] Use CI update channel by default for snapshots (#1223) * Use CI update channel by default for snapshots And use build time as initial update time. * Fix build time --- app/build.gradle.kts | 11 ++--------- app/src/main/kotlin/com/hippo/ehviewer/Settings.kt | 4 ++-- .../com/hippo/ehviewer/ui/settings/AboutScreen.kt | 2 +- .../main/kotlin/com/hippo/ehviewer/util/AppConfig.kt | 3 +++ app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt | 2 +- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b0e68e689..30f68d3cf 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,8 +1,6 @@ import com.mikepenz.aboutlibraries.plugin.DuplicateMode.MERGE import com.mikepenz.aboutlibraries.plugin.DuplicateRule.GROUP import java.time.Instant -import java.time.ZoneOffset -import java.time.format.DateTimeFormatter val isRelease: Boolean get() = gradle.startParameter.taskNames.any { it.contains("Release") } @@ -50,11 +48,6 @@ android { commandLine = "git rev-parse --short=7 HEAD".split(' ') }.standardOutput.asText.get().trim() - val buildTime by lazy { - val formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm").withZone(ZoneOffset.UTC) - formatter.format(Instant.now()) - } - val repoName = providers.exec { commandLine = "git remote get-url origin".split(' ') }.standardOutput.asText.get().trim().removePrefix("https://github.com/").removePrefix("git@github.com:") @@ -164,11 +157,11 @@ android { isShrinkResources = true proguardFiles("proguard-rules.pro") signingConfig = signConfig - buildConfigField("String", "BUILD_TIME", "\"$buildTime\"") + buildConfigField("long", "BUILD_TIME", "${Instant.now().epochSecond}") } debug { applicationIdSuffix = ".debug" - buildConfigField("String", "BUILD_TIME", "\"\"") + buildConfigField("long", "BUILD_TIME", "0") lint { abortOnError = false } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt index 806efd50b..81c1e6b1b 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt @@ -146,7 +146,7 @@ object Settings : DataStorePreferences(null) { var appLinkVerifyTip by boolPref("app_link_verify_tip", false) var enabledSecurity by boolPref("enable_secure", false) var backupBeforeUpdate by boolPref("backup_before_update", true) - var useCIUpdateChannel by boolPref("ci_update_channel", false) + var useCIUpdateChannel by boolPref("ci_update_channel", "SNAPSHOT" in BuildConfig.VERSION_NAME) var mediaScan by boolPref("media_scan", false).observed { updateWhenKeepMediaStatusChanges() } var hasDefaultDownloadLabel by boolPref("has_default_download_label", false) var saveParseErrorBody by boolPref("save_parse_error_body", true) @@ -168,7 +168,7 @@ object Settings : DataStorePreferences(null) { var recentToplist by stringPref("recent_toplist", "11") var userAgent by stringPref("user_agent", CHROME_USER_AGENT) var defaultDownloadLabel by stringOrNullPref("default_download_label", null) - var lastUpdateTime by longPref("last_update_time", 0) + var lastUpdateTime by longPref("last_update_time", BuildConfig.BUILD_TIME) // Tachiyomi Reader var newReader by boolPref("new_compose_reader", false) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AboutScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AboutScreen.kt index cebe84dbd..281e9e79d 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AboutScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AboutScreen.kt @@ -59,7 +59,7 @@ private const val RELEASE_URL = "$REPO_URL/releases" @Composable @Stable -private fun versionCode() = "${BuildConfig.VERSION_NAME} (${BuildConfig.COMMIT_SHA})\n" + stringResource(R.string.settings_about_build_time, BuildConfig.BUILD_TIME) +private fun versionCode() = "${BuildConfig.VERSION_NAME} (${BuildConfig.COMMIT_SHA})\n" + stringResource(R.string.settings_about_build_time, AppConfig.buildTime) @Composable @Stable diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt index 2431930c1..318cb3db0 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/AppConfig.kt @@ -18,6 +18,7 @@ package com.hippo.ehviewer.util import android.os.Build import android.os.Environment import com.hippo.ehviewer.BuildConfig +import com.hippo.ehviewer.client.parser.ParserUtils import com.hippo.unifile.UniFile import com.hippo.unifile.asUniFile import java.io.File @@ -38,6 +39,8 @@ object AppConfig { fun matchVariant(name: String) = name.contains(BuildConfig.FLAVOR) && name.contains(abi) + val buildTime = ParserUtils.formatDate(BuildConfig.BUILD_TIME * 1000) + private val externalAppDir: File? get() { if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()) { diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt index 84076e13f..69494305b 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt @@ -26,7 +26,7 @@ object Crash { writer.write("VersionName=${BuildConfig.VERSION_NAME}\n") writer.write("VersionCode=${BuildConfig.VERSION_CODE}\n") writer.write("CommitSha=${BuildConfig.COMMIT_SHA}\n") - writer.write("BuildTime=${BuildConfig.BUILD_TIME}\n") + writer.write("BuildTime=${AppConfig.buildTime}\n") writer.write("\n") // Device info