From e5567c7cbbc627c2d52e2db111c49e7b898e510c Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Mon, 3 Jul 2023 21:53:42 -0400 Subject: [PATCH] better reflect progress refreshing Signed-off-by: androidacy-user --- .../kotlin/com/fox2code/mmm/MainActivity.kt | 22 +++++++++---------- .../com/fox2code/mmm/repo/RepoManager.kt | 18 +++++++++------ .../com/fox2code/mmm/utils/SyncManager.kt | 4 ++-- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt b/app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt index 6a14c73..52501cc 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt @@ -452,14 +452,14 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis if (hasWebView()) { val updateListener: SyncManager.UpdateListener = object : SyncManager.UpdateListener { - override fun update(value: Double) { + override fun update(value: Int) { runOnUiThread(if (max == 0) Runnable { progressIndicator.setProgressCompat( - (value * PRECISION).toInt(), true + value, true ) } else Runnable { progressIndicator.setProgressCompat( - (value * PRECISION * 0.75f).toInt(), true + value, true ) }) } @@ -508,7 +508,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis val currentTmp = current runOnUiThread { progressIndicator.setProgressCompat( - (1f * currentTmp / max * PRECISION * 0.25f + PRECISION * 0.75f).toInt(), + currentTmp / max, true ) } @@ -673,10 +673,10 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis if (BuildConfig.DEBUG) Timber.i("Check Update") val updateListener: SyncManager.UpdateListener = object : SyncManager.UpdateListener { - override fun update(value: Double) { + override fun update(value: Int) { runOnUiThread { progressIndicator!!.setProgressCompat( - (value * PRECISION).toInt(), true + value, true ) } } @@ -717,14 +717,14 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis cleanDnsCache() // Allow DNS reload from network val max = instance!!.getUpdatableModuleCount() val updateListener: SyncManager.UpdateListener = object : SyncManager.UpdateListener { - override fun update(value: Double) { + override fun update(value: Int) { runOnUiThread(if (max == 0) Runnable { progressIndicator!!.setProgressCompat( - (value * PRECISION).toInt(), true + value, true ) } else Runnable { progressIndicator!!.setProgressCompat( - (value * PRECISION * 0.75f).toInt(), true + value, true ) }) } @@ -757,7 +757,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis val currentTmp = current runOnUiThread { progressIndicator!!.setProgressCompat( - (1f * currentTmp / max * PRECISION * 0.25f + PRECISION * 0.75f).toInt(), + currentTmp / max, true ) } @@ -914,7 +914,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis return context as FoxActivity } - private const val PRECISION = 10000 + private const val PRECISION = 100 @JvmField var doSetupNowRunning = true diff --git a/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt b/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt index ffd3089..4f2163d 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt @@ -141,7 +141,7 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa return } modules.clear() - updateListener.update(0.0) + updateListener.update(0) // Using LinkedHashSet to deduplicate Androidacy entry. val repoDatas = LinkedHashSet(repoData.values).toTypedArray() val repoUpdaters = arrayOfNulls(repoDatas.size) @@ -151,9 +151,11 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa return } for (i in repoDatas.indices) { + updateListener.update(STEP1 * (i / repoDatas.size)) if (BuildConfig.DEBUG) Timber.d("Preparing to fetch: %s", repoDatas[i].name) moduleToUpdate += RepoUpdater(repoDatas[i]).also { repoUpdaters[i] = it }.fetchIndex() - updateListener.update(STEP1 / repoDatas.size * (i + 1)) + // divvy the 40 of step1 to each repo + updateListener.update(STEP1 * ((i + 1) / repoDatas.size)) } if (BuildConfig.DEBUG) Timber.d("Updating meta-data") var updatedModules = 0 @@ -207,9 +209,11 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa Timber.e(e) } updatedModules++ - // update the update listener with step1 + computed step 2 (which is updated modules / total modules / total repos) + // update the update listener + // STEP1 is done so always add it + // step2 percentage is calculated by the number of modules updated out of total, then multiplied by the percentage of repos done updateListener.update( - STEP1 + (STEP2 / (moduleToUpdate / updatedModules) / repoDatas.size) + STEP1 + STEP2 * ((updatedModules / moduleToUpdate) * (i + 1) / repoDatas.size) ) } for (repoModule in repoUpdaters[i]!!.toApply()!!) { @@ -345,9 +349,9 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa private const val MAGISK_REPO_MANAGER = "https://magisk-modules-repo.github.io/submission/modules.json" private val lock = Any() - private const val STEP1 = 0.1 - private const val STEP2 = 0.8 - private const val STEP3 = 0.1 + private const val STEP1 = 40 + private const val STEP2 = 40 + private const val STEP3 = 20 @Volatile private var INSTANCE: RepoManager? = null diff --git a/app/src/main/kotlin/com/fox2code/mmm/utils/SyncManager.kt b/app/src/main/kotlin/com/fox2code/mmm/utils/SyncManager.kt index 372ba80..9d2df44 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/utils/SyncManager.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/utils/SyncManager.kt @@ -66,12 +66,12 @@ abstract class SyncManager { // This method can't be called twice at the same time. protected abstract fun scanInternal(updateListener: UpdateListener) interface UpdateListener { - fun update(value: Double) + fun update(value: Int) } companion object { private val NO_OP: UpdateListener = object : UpdateListener { - override fun update(value: Double) { + override fun update(value: Int) { } }