diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt
index 0f3acad8b..ccf2ad9c1 100755
--- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt
+++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt
@@ -684,7 +684,7 @@ class GalleryDetailScene : BaseScene() {
.fillMaxWidth()
.height(32.dp),
) {}
- Text(text = stringResource(id = R.string.newer_version_avaliable))
+ Text(text = stringResource(id = R.string.newer_version_available))
}
Spacer(modifier = Modifier.size(dimensionResource(id = R.dimen.keyline_margin)))
}
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/settings/AboutScreen.kt b/app/src/main/java/com/hippo/ehviewer/ui/settings/AboutScreen.kt
index 02ca53895..ba43a6b43 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/settings/AboutScreen.kt
+++ b/app/src/main/java/com/hippo/ehviewer/ui/settings/AboutScreen.kt
@@ -28,19 +28,21 @@ import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.execute
import com.hippo.ehviewer.ui.LICENSE_SCREEN
import com.hippo.ehviewer.ui.LocalNavController
+import com.hippo.ehviewer.ui.tools.rememberDialogState
import com.hippo.ehviewer.ui.tools.toAnnotatedString
import com.hippo.ehviewer.util.ExceptionUtils
import com.hippo.ehviewer.util.installPackage
import com.hippo.ehviewer.util.iter
-import com.hippo.ehviewer.yorozuya.FileUtils
import eu.kanade.tachiyomi.util.lang.withUIContext
+import eu.kanade.tachiyomi.util.system.logcat
import io.ktor.util.encodeBase64
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import moe.tarsin.coroutines.runSuspendCatching
import okhttp3.Request
-import org.json.JSONArray
+import okio.sink
import org.json.JSONObject
+import java.io.File
import java.util.zip.ZipInputStream
private const val REPO_URL = "https://github.com/Ehviewer-Overhauled/Ehviewer"
@@ -62,6 +64,8 @@ fun AboutScreen() {
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
val snackbarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope { Dispatchers.IO }
+ val dialogState = rememberDialogState()
+ dialogState.Handler()
fun launchSnackBar(content: String) = coroutineScope.launch { snackbarHostState.showSnackbar(content) }
Scaffold(
topBar = {
@@ -124,32 +128,60 @@ fun AboutScreen() {
}
}?.getString("archive_download_url")
if (archiveUrl != null) {
- val file = FileUtils.createTempFile(AppConfig.tempDir, "apk")!!
- ghRequest(archiveUrl).execute {
- ZipInputStream(body.byteStream()).use { zip ->
- zip.nextEntry
- file.outputStream().use {
- zip.copyTo(it)
+ val download = dialogState.show(
+ confirmText = R.string.download,
+ dismissText = android.R.string.cancel,
+ title = R.string.new_version_available,
+ ) {
+ // TODO: Show changelog
+ Text(text = "Latest CI build: $commitSha")
+ }
+ if (download) {
+ val file = File(AppConfig.tempDir, "tmp.apk").apply { delete() }
+ ghRequest(archiveUrl).execute {
+ ZipInputStream(body.byteStream()).use { zip ->
+ zip.nextEntry
+ file.outputStream().use {
+ zip.copyTo(it)
+ }
}
}
- }
- withUIContext { context.installPackage(file) }
+ withUIContext { context.installPackage(file) }
+ } else {}
} else {
- launchSnackBar("CI is still running, please wait")
+ launchSnackBar(context.getString(R.string.ci_is_running))
}
} else {
- launchSnackBar("Already latest CI build")
+ launchSnackBar(context.getString(R.string.already_latest_ci_build))
}
} else {
val curVersion = BuildConfig.VERSION_NAME
- val releaseUrl = "$API_URL/releases"
- val latestVersion = ghRequest(releaseUrl).execute {
- JSONArray(body.string())[0] as JSONObject
- }.getString("name")
+ val releaseUrl = "$API_URL/releases/latest"
+ val (latestVersion, downloadUrl) = ghRequest(releaseUrl).execute {
+ JSONObject(body.string())
+ }.run {
+ getString("name") to (getJSONArray("assets")[0] as JSONObject).getString("browser_download_url")
+ }
if (latestVersion != curVersion) {
- launchSnackBar(latestVersion)
+ val download = dialogState.show(
+ confirmText = R.string.download,
+ dismissText = android.R.string.cancel,
+ title = R.string.new_version_available,
+ ) {
+ // TODO: Show changelog
+ Text(text = "Latest version: $latestVersion")
+ }
+ if (download) {
+ val file = File(AppConfig.tempDir, "tmp.apk").apply { delete() }
+ ghRequest(downloadUrl).execute {
+ file.sink().use {
+ body.source().readAll(it)
+ }
+ }
+ withUIContext { context.installPackage(file) }
+ } else {}
} else {
- launchSnackBar("Already latest Release $latestVersion")
+ launchSnackBar(context.getString(R.string.already_latest_release, latestVersion))
}
}
}.onFailure {
@@ -161,6 +193,7 @@ fun AboutScreen() {
}
private inline fun ghRequest(url: String, builder: Request.Builder.() -> Unit = {}) = Request.Builder().url(url).apply {
+ logcat { url }
val token = "github_" + "pat_11AXZS" + "T4A0k3TArCGakP3t_7DzUE5S" + "mr1zw8rmmzVtCeRq62" + "A4qkuDMw6YQm5ZUtHSLZ2MLI3J4VSifLXZ"
val user = "nullArrayList"
val base64 = "$user:$token".encodeBase64()
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index f5cdb0f6b..64c4841f9 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -158,7 +158,7 @@
屏蔽上传者“%s”?
屏蔽标签“%s”?
已添加屏蔽项
- 此画廊有新版本可用。
+ 此画廊有新版本可用。
%1$s, 添加于 %2$s
根本把持不住
@@ -510,6 +510,10 @@
详情模式下缩略图大小
账户
激进地预载缩略图
+ 有新版本!
+ CI 正在运行,请稍候
+ 已是最新 CI 构建
+ 已是最新版本 %s
设置
重试
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 96dd67d77..a20113fdc 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -157,7 +157,7 @@
把上傳者“%s”加入過濾列表?
隱藏標籤“%s”?
已經新增篩選條件
- 此圖庫有新版本可以使用。
+ 此圖庫有新版本可以使用。
%1$s, 增加於 %2$s
太神啦!
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 64af2d263..d126c2b3b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -200,7 +200,7 @@
Block the uploader \"%s\"?
Block the tag \"%s\"?
Blocker added
- There are newer versions of this gallery available.
+ There are newer versions of this gallery available.
%1$s, added %2$s
MASTERPIECE
@@ -573,6 +573,10 @@
Thumb size in thumb mode
Account
Preload thumbs aggressively
+ New version available!
+ CI is still running, please wait
+ Already latest CI build
+ Already latest Release %s
Settings
Default rotation type