diff --git a/app/src/main/java/io/nekohasekai/sagernet/ui/AssetsActivity.kt b/app/src/main/java/io/nekohasekai/sagernet/ui/AssetsActivity.kt index 2d88b3b3..be57d342 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/ui/AssetsActivity.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/ui/AssetsActivity.kt @@ -159,6 +159,7 @@ class AssetsActivity : ThemedActivity() { init { reloadAssets() + updating.visibility = View.GONE } fun reloadAssets() { @@ -174,11 +175,11 @@ class AssetsActivity : ThemedActivity() { assets.add(File(filesDir, "geosite.version.txt")) // if (files != null) assets.addAll(files) - updating.visibility = View.GONE - layout.refreshLayout.post { notifyDataSetChanged() } + + updating.setProgressCompat(0, true) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AssetHolder { @@ -239,7 +240,10 @@ class AssetsActivity : ThemedActivity() { private suspend fun updateAsset() { val filesDir = getExternalFilesDir(null) ?: filesDir - + var progress = 0 + fun setProgress() { + updating.setProgressCompat(progress, true) + } val repos: List = when (DataStore.rulesProvider) { 0 -> listOf("SagerNet/sing-geoip", "SagerNet/sing-geosite") @@ -247,15 +251,16 @@ class AssetsActivity : ThemedActivity() { 2 -> listOf("Chocolate4U/Iran-sing-box-rules") else -> listOf("SagerNet/sing-geoip", "SagerNet/sing-geosite") } - + progress = 15 onMainDispatcher { + setProgress() updating.visibility = View.VISIBLE } val geoDir = File(filesDir, "geo") var cacheFiles: Array = arrayOf() - for ((list, repo) in repos.withIndex()) { + for ((i, repo) in repos.withIndex()) { val client = Libcore.newHttpClient().apply { modernTLS() @@ -270,13 +275,11 @@ class AssetsActivity : ThemedActivity() { setURL("https://codeload.github.com/$repo/zip/refs/heads/rule-set") }.execute() - val cacheFile = File(filesDir.parentFile, filesDir.name + list + ".tmp") + val cacheFile = File(filesDir.parentFile, filesDir.name + i + ".tmp") cacheFile.parentFile?.mkdirs() response.writeTo(cacheFile.canonicalPath) cacheFiles += cacheFile - adapter.reloadAssets() - } catch (e: Exception) { onMainDispatcher { e.message?.let { snackbar(it).show() } @@ -284,23 +287,32 @@ class AssetsActivity : ThemedActivity() { } finally { client.close() } + + progress += 20 + onMainDispatcher { + setProgress() + } + } for (cacheFile in cacheFiles) { + progress += 15 + onMainDispatcher { + setProgress() + } Libcore.unzipWithoutDir(cacheFile.absolutePath, geoDir.absolutePath) cacheFile.delete() } - onMainDispatcher { - snackbar(R.string.route_asset_updated).show() - updating.visibility = View.GONE - } - val versionFileList: List = listOf( File(filesDir, "geoip.version.txt"), File(filesDir, "geosite.version.txt") ) for (versionFile in versionFileList) { + progress += 5 + onMainDispatcher { + setProgress() + } versionFile.writeText( LocalDate.now() .format( @@ -309,7 +321,14 @@ class AssetsActivity : ThemedActivity() { ) ) } - adapter.reloadAssets() + + progress = 100 + onMainDispatcher { + setProgress() + updating.visibility = View.GONE + adapter.reloadAssets() + snackbar(R.string.route_asset_updated).show() + } } override fun onSupportNavigateUp(): Boolean { diff --git a/husi.properties b/husi.properties index 50b6821c..703f2c78 100644 --- a/husi.properties +++ b/husi.properties @@ -1,3 +1,3 @@ PACKAGE_NAME=fr.husi VERSION_NAME=0.1.1 -VERSION_CODE=6 +VERSION_CODE=7