Skip to content

Commit e5567c7

Browse files
better reflect progress refreshing
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent c42c2a2 commit e5567c7

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
452452
if (hasWebView()) {
453453
val updateListener: SyncManager.UpdateListener =
454454
object : SyncManager.UpdateListener {
455-
override fun update(value: Double) {
455+
override fun update(value: Int) {
456456
runOnUiThread(if (max == 0) Runnable {
457457
progressIndicator.setProgressCompat(
458-
(value * PRECISION).toInt(), true
458+
value, true
459459
)
460460
} else Runnable {
461461
progressIndicator.setProgressCompat(
462-
(value * PRECISION * 0.75f).toInt(), true
462+
value, true
463463
)
464464
})
465465
}
@@ -508,7 +508,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
508508
val currentTmp = current
509509
runOnUiThread {
510510
progressIndicator.setProgressCompat(
511-
(1f * currentTmp / max * PRECISION * 0.25f + PRECISION * 0.75f).toInt(),
511+
currentTmp / max,
512512
true
513513
)
514514
}
@@ -673,10 +673,10 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
673673
if (BuildConfig.DEBUG) Timber.i("Check Update")
674674
val updateListener: SyncManager.UpdateListener =
675675
object : SyncManager.UpdateListener {
676-
override fun update(value: Double) {
676+
override fun update(value: Int) {
677677
runOnUiThread {
678678
progressIndicator!!.setProgressCompat(
679-
(value * PRECISION).toInt(), true
679+
value, true
680680
)
681681
}
682682
}
@@ -717,14 +717,14 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
717717
cleanDnsCache() // Allow DNS reload from network
718718
val max = instance!!.getUpdatableModuleCount()
719719
val updateListener: SyncManager.UpdateListener = object : SyncManager.UpdateListener {
720-
override fun update(value: Double) {
720+
override fun update(value: Int) {
721721
runOnUiThread(if (max == 0) Runnable {
722722
progressIndicator!!.setProgressCompat(
723-
(value * PRECISION).toInt(), true
723+
value, true
724724
)
725725
} else Runnable {
726726
progressIndicator!!.setProgressCompat(
727-
(value * PRECISION * 0.75f).toInt(), true
727+
value, true
728728
)
729729
})
730730
}
@@ -757,7 +757,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
757757
val currentTmp = current
758758
runOnUiThread {
759759
progressIndicator!!.setProgressCompat(
760-
(1f * currentTmp / max * PRECISION * 0.25f + PRECISION * 0.75f).toInt(),
760+
currentTmp / max,
761761
true
762762
)
763763
}
@@ -914,7 +914,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
914914
return context as FoxActivity
915915
}
916916

917-
private const val PRECISION = 10000
917+
private const val PRECISION = 100
918918

919919
@JvmField
920920
var doSetupNowRunning = true

app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
141141
return
142142
}
143143
modules.clear()
144-
updateListener.update(0.0)
144+
updateListener.update(0)
145145
// Using LinkedHashSet to deduplicate Androidacy entry.
146146
val repoDatas = LinkedHashSet(repoData.values).toTypedArray()
147147
val repoUpdaters = arrayOfNulls<RepoUpdater>(repoDatas.size)
@@ -151,9 +151,11 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
151151
return
152152
}
153153
for (i in repoDatas.indices) {
154+
updateListener.update(STEP1 * (i / repoDatas.size))
154155
if (BuildConfig.DEBUG) Timber.d("Preparing to fetch: %s", repoDatas[i].name)
155156
moduleToUpdate += RepoUpdater(repoDatas[i]).also { repoUpdaters[i] = it }.fetchIndex()
156-
updateListener.update(STEP1 / repoDatas.size * (i + 1))
157+
// divvy the 40 of step1 to each repo
158+
updateListener.update(STEP1 * ((i + 1) / repoDatas.size))
157159
}
158160
if (BuildConfig.DEBUG) Timber.d("Updating meta-data")
159161
var updatedModules = 0
@@ -207,9 +209,11 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
207209
Timber.e(e)
208210
}
209211
updatedModules++
210-
// update the update listener with step1 + computed step 2 (which is updated modules / total modules / total repos)
212+
// update the update listener
213+
// STEP1 is done so always add it
214+
// step2 percentage is calculated by the number of modules updated out of total, then multiplied by the percentage of repos done
211215
updateListener.update(
212-
STEP1 + (STEP2 / (moduleToUpdate / updatedModules) / repoDatas.size)
216+
STEP1 + STEP2 * ((updatedModules / moduleToUpdate) * (i + 1) / repoDatas.size)
213217
)
214218
}
215219
for (repoModule in repoUpdaters[i]!!.toApply()!!) {
@@ -345,9 +349,9 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
345349
private const val MAGISK_REPO_MANAGER =
346350
"https://magisk-modules-repo.github.io/submission/modules.json"
347351
private val lock = Any()
348-
private const val STEP1 = 0.1
349-
private const val STEP2 = 0.8
350-
private const val STEP3 = 0.1
352+
private const val STEP1 = 40
353+
private const val STEP2 = 40
354+
private const val STEP3 = 20
351355

352356
@Volatile
353357
private var INSTANCE: RepoManager? = null

app/src/main/kotlin/com/fox2code/mmm/utils/SyncManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ abstract class SyncManager {
6666
// This method can't be called twice at the same time.
6767
protected abstract fun scanInternal(updateListener: UpdateListener)
6868
interface UpdateListener {
69-
fun update(value: Double)
69+
fun update(value: Int)
7070
}
7171

7272
companion object {
7373
private val NO_OP: UpdateListener = object : UpdateListener {
74-
override fun update(value: Double) {
74+
override fun update(value: Int) {
7575

7676
}
7777
}

0 commit comments

Comments
 (0)