better reflect progress refreshing

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/89/head
androidacy-user 2 years ago
parent c42c2a2d33
commit e5567c7cbb

@ -452,14 +452,14 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
if (hasWebView()) { if (hasWebView()) {
val updateListener: SyncManager.UpdateListener = val updateListener: SyncManager.UpdateListener =
object : SyncManager.UpdateListener { object : SyncManager.UpdateListener {
override fun update(value: Double) { override fun update(value: Int) {
runOnUiThread(if (max == 0) Runnable { runOnUiThread(if (max == 0) Runnable {
progressIndicator.setProgressCompat( progressIndicator.setProgressCompat(
(value * PRECISION).toInt(), true value, true
) )
} else Runnable { } else Runnable {
progressIndicator.setProgressCompat( progressIndicator.setProgressCompat(
(value * PRECISION * 0.75f).toInt(), true value, true
) )
}) })
} }
@ -508,7 +508,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
val currentTmp = current val currentTmp = current
runOnUiThread { runOnUiThread {
progressIndicator.setProgressCompat( progressIndicator.setProgressCompat(
(1f * currentTmp / max * PRECISION * 0.25f + PRECISION * 0.75f).toInt(), currentTmp / max,
true true
) )
} }
@ -673,10 +673,10 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
if (BuildConfig.DEBUG) Timber.i("Check Update") if (BuildConfig.DEBUG) Timber.i("Check Update")
val updateListener: SyncManager.UpdateListener = val updateListener: SyncManager.UpdateListener =
object : SyncManager.UpdateListener { object : SyncManager.UpdateListener {
override fun update(value: Double) { override fun update(value: Int) {
runOnUiThread { runOnUiThread {
progressIndicator!!.setProgressCompat( progressIndicator!!.setProgressCompat(
(value * PRECISION).toInt(), true value, true
) )
} }
} }
@ -717,14 +717,14 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
cleanDnsCache() // Allow DNS reload from network cleanDnsCache() // Allow DNS reload from network
val max = instance!!.getUpdatableModuleCount() val max = instance!!.getUpdatableModuleCount()
val updateListener: SyncManager.UpdateListener = object : SyncManager.UpdateListener { val updateListener: SyncManager.UpdateListener = object : SyncManager.UpdateListener {
override fun update(value: Double) { override fun update(value: Int) {
runOnUiThread(if (max == 0) Runnable { runOnUiThread(if (max == 0) Runnable {
progressIndicator!!.setProgressCompat( progressIndicator!!.setProgressCompat(
(value * PRECISION).toInt(), true value, true
) )
} else Runnable { } else Runnable {
progressIndicator!!.setProgressCompat( progressIndicator!!.setProgressCompat(
(value * PRECISION * 0.75f).toInt(), true value, true
) )
}) })
} }
@ -757,7 +757,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
val currentTmp = current val currentTmp = current
runOnUiThread { runOnUiThread {
progressIndicator!!.setProgressCompat( progressIndicator!!.setProgressCompat(
(1f * currentTmp / max * PRECISION * 0.25f + PRECISION * 0.75f).toInt(), currentTmp / max,
true true
) )
} }
@ -914,7 +914,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
return context as FoxActivity return context as FoxActivity
} }
private const val PRECISION = 10000 private const val PRECISION = 100
@JvmField @JvmField
var doSetupNowRunning = true var doSetupNowRunning = true

@ -141,7 +141,7 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
return return
} }
modules.clear() modules.clear()
updateListener.update(0.0) updateListener.update(0)
// Using LinkedHashSet to deduplicate Androidacy entry. // Using LinkedHashSet to deduplicate Androidacy entry.
val repoDatas = LinkedHashSet(repoData.values).toTypedArray() val repoDatas = LinkedHashSet(repoData.values).toTypedArray()
val repoUpdaters = arrayOfNulls<RepoUpdater>(repoDatas.size) val repoUpdaters = arrayOfNulls<RepoUpdater>(repoDatas.size)
@ -151,9 +151,11 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
return return
} }
for (i in repoDatas.indices) { for (i in repoDatas.indices) {
updateListener.update(STEP1 * (i / repoDatas.size))
if (BuildConfig.DEBUG) Timber.d("Preparing to fetch: %s", repoDatas[i].name) if (BuildConfig.DEBUG) Timber.d("Preparing to fetch: %s", repoDatas[i].name)
moduleToUpdate += RepoUpdater(repoDatas[i]).also { repoUpdaters[i] = it }.fetchIndex() 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") if (BuildConfig.DEBUG) Timber.d("Updating meta-data")
var updatedModules = 0 var updatedModules = 0
@ -207,9 +209,11 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
Timber.e(e) Timber.e(e)
} }
updatedModules++ 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( updateListener.update(
STEP1 + (STEP2 / (moduleToUpdate / updatedModules) / repoDatas.size) STEP1 + STEP2 * ((updatedModules / moduleToUpdate) * (i + 1) / repoDatas.size)
) )
} }
for (repoModule in repoUpdaters[i]!!.toApply()!!) { for (repoModule in repoUpdaters[i]!!.toApply()!!) {
@ -345,9 +349,9 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
private const val MAGISK_REPO_MANAGER = private const val MAGISK_REPO_MANAGER =
"https://magisk-modules-repo.github.io/submission/modules.json" "https://magisk-modules-repo.github.io/submission/modules.json"
private val lock = Any() private val lock = Any()
private const val STEP1 = 0.1 private const val STEP1 = 40
private const val STEP2 = 0.8 private const val STEP2 = 40
private const val STEP3 = 0.1 private const val STEP3 = 20
@Volatile @Volatile
private var INSTANCE: RepoManager? = null private var INSTANCE: RepoManager? = null

@ -66,12 +66,12 @@ abstract class SyncManager {
// This method can't be called twice at the same time. // This method can't be called twice at the same time.
protected abstract fun scanInternal(updateListener: UpdateListener) protected abstract fun scanInternal(updateListener: UpdateListener)
interface UpdateListener { interface UpdateListener {
fun update(value: Double) fun update(value: Int)
} }
companion object { companion object {
private val NO_OP: UpdateListener = object : UpdateListener { private val NO_OP: UpdateListener = object : UpdateListener {
override fun update(value: Double) { override fun update(value: Int) {
} }
} }

Loading…
Cancel
Save