Skip to content

Commit a914ab8

Browse files
fixes for repo loading
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 508a1a9 commit a914ab8

4 files changed

Lines changed: 80 additions & 94 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import android.view.MenuItem
2121
import android.view.View
2222
import android.view.ViewGroup.MarginLayoutParams
2323
import android.view.WindowManager
24-
import android.view.animation.AccelerateInterpolator
2524
import android.view.animation.DecelerateInterpolator
2625
import android.view.inputmethod.EditorInfo
2726
import android.widget.Toast

app/src/main/kotlin/com/fox2code/mmm/module/ModuleViewListBuilder.kt

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package com.fox2code.mmm.module
66

77
import android.app.Activity
88
import android.os.Build
9+
import android.os.Handler
10+
import android.os.Looper
911
import android.view.View
1012
import androidx.recyclerview.widget.RecyclerView
1113
import com.fox2code.mmm.AppUpdateManager
@@ -32,6 +34,7 @@ class ModuleViewListBuilder(private val activity: Activity) {
3234
private var updating = false
3335
private var headerPx = 0
3436
private var footerPx = 0
37+
private var tries = 0
3538
private var moduleSorter: ModuleSorter = ModuleSorter.UPDATE
3639
private var updateInsets = RUNNABLE
3740
fun addNotification(notificationType: NotificationType?) {
@@ -85,55 +88,70 @@ class ModuleViewListBuilder(private val activity: Activity) {
8588
repoManager?.runAfterUpdate {
8689
Timber.i("A2: %s", repoManager.modules.size)
8790
val no32bitSupport = Build.SUPPORTED_32_BIT_ABIS.isEmpty()
88-
for (repoModule in repoManager.modules.values) {
89-
// add the remote module to the list in MainActivity
90-
MainActivity.onlineModuleInfoList += repoModule
91-
// if repoData is null, something is wrong
92-
@Suppress("SENSELESS_COMPARISON")
93-
if (repoModule.repoData == null) {
94-
Timber.w("RepoData is null for module %s", repoModule.id)
95-
continue
96-
}
97-
if (!repoModule.repoData.isEnabled) {
98-
Timber.i(
99-
"Repo %s is disabled, skipping module %s",
100-
repoModule.repoData.preferenceId,
101-
repoModule.id
102-
)
103-
continue
104-
}
105-
val moduleInfo = repoModule.moduleInfo
106-
if (!showIncompatible && (moduleInfo.minApi > Build.VERSION.SDK_INT || moduleInfo.maxApi != 0 && moduleInfo.maxApi < Build.VERSION.SDK_INT || peekMagiskPath() != null) && repoModule.moduleInfo.minMagisk > peekMagiskVersion() || no32bitSupport && (AppUpdateManager.getFlagsForModule(
107-
repoModule.id
108-
)
109-
and AppUpdateManager.FLAG_COMPAT_NEED_32BIT) != 0 || repoModule.moduleInfo.needRamdisk && !peekHasRamdisk()
110-
) continue // Skip adding incompatible modules
111-
var moduleHolder = mappedModuleHolders[repoModule.id]
112-
if (moduleHolder == null) {
113-
mappedModuleHolders[repoModule.id] = ModuleHolder(repoModule.id).also {
114-
moduleHolder = it
91+
try {
92+
for (repoModule in repoManager.modules.values) {
93+
// add the remote module to the list in MainActivity
94+
MainActivity.onlineModuleInfoList += repoModule
95+
// if repoData is null, something is wrong
96+
@Suppress("SENSELESS_COMPARISON") if (repoModule.repoData == null) {
97+
Timber.w("RepoData is null for module %s", repoModule.id)
98+
continue
11599
}
116-
}
117-
moduleHolder!!.repoModule = repoModule
118-
// check if local module is installed
119-
// iterate over MainActivity.localModuleInfoList until we hit the module with the same id
120-
for (localModuleInfo in MainActivity.localModuleInfoList) {
121-
if (localModuleInfo.id == repoModule.id) {
122-
moduleHolder!!.moduleInfo = localModuleInfo
123-
break
100+
if (!repoModule.repoData.isEnabled) {
101+
Timber.i(
102+
"Repo %s is disabled, skipping module %s",
103+
repoModule.repoData.preferenceId,
104+
repoModule.id
105+
)
106+
continue
107+
}
108+
val moduleInfo = repoModule.moduleInfo
109+
if (!showIncompatible && (moduleInfo.minApi > Build.VERSION.SDK_INT || moduleInfo.maxApi != 0 && moduleInfo.maxApi < Build.VERSION.SDK_INT || peekMagiskPath() != null) && repoModule.moduleInfo.minMagisk > peekMagiskVersion() || no32bitSupport && (AppUpdateManager.getFlagsForModule(
110+
repoModule.id
111+
) and AppUpdateManager.FLAG_COMPAT_NEED_32BIT) != 0 || repoModule.moduleInfo.needRamdisk && !peekHasRamdisk()
112+
) continue // Skip adding incompatible modules
113+
var moduleHolder = mappedModuleHolders[repoModule.id]
114+
if (moduleHolder == null) {
115+
mappedModuleHolders[repoModule.id] = ModuleHolder(repoModule.id).also {
116+
moduleHolder = it
117+
}
124118
}
119+
moduleHolder!!.repoModule = repoModule
120+
// check if local module is installed
121+
// iterate over MainActivity.localModuleInfoList until we hit the module with the same id
122+
for (localModuleInfo in MainActivity.localModuleInfoList) {
123+
if (localModuleInfo.id == repoModule.id) {
124+
moduleHolder!!.moduleInfo = localModuleInfo
125+
break
126+
}
127+
}
128+
}
129+
} catch (e: Exception) {
130+
Timber.e(e, "appendRemoteModules() failed")
131+
// retry up to five times, waiting i * 100ms between each try
132+
if (tries < 5) {
133+
tries++
134+
Timber.i("appendRemoteModules() retrying in %dms", tries * 100)
135+
Handler(Looper.getMainLooper()).postDelayed({
136+
appendRemoteModules()
137+
}, tries * 100.toLong())
138+
} else {
139+
Timber.e(e, "appendRemoteModules() failed after %d tries", tries)
140+
tries = 0
125141
}
126142
}
127-
Timber.i("appendRemoteModules() finished in %dms", System.currentTimeMillis() - startTime)
143+
Timber.i(
144+
"appendRemoteModules() finished in %dms",
145+
System.currentTimeMillis() - startTime
146+
)
128147
}
129148
}
130149
}
131150

132151
fun refreshNotificationsUI(moduleViewAdapter: ModuleViewAdapter) {
133152
val notificationCount = notifications.size
134153
notifySizeChanged(
135-
moduleViewAdapter, 0,
136-
notificationCount, notificationCount
154+
moduleViewAdapter, 0, notificationCount, notificationCount
137155
)
138156
}
139157

@@ -195,7 +213,8 @@ class ModuleViewListBuilder(private val activity: Activity) {
195213
newNotificationsLen = notifications.size + 1 - special
196214
val headerTypes = EnumSet.of(
197215
ModuleHolder.Type.SEPARATOR,
198-
ModuleHolder.Type.NOTIFICATION, ModuleHolder.Type.FOOTER
216+
ModuleHolder.Type.NOTIFICATION,
217+
ModuleHolder.Type.FOOTER
199218
)
200219
val moduleHolderIterator = mappedModuleHolders.values.iterator()
201220
synchronized(queryLock) {
@@ -218,8 +237,7 @@ class ModuleViewListBuilder(private val activity: Activity) {
218237
Thread(
219238
{ // Apply async
220239
applyTo(moduleList, moduleViewAdapter)
221-
},
222-
"Sorter apply Thread"
240+
}, "Sorter apply Thread"
223241
).start()
224242
}
225243
}
@@ -256,9 +274,7 @@ class ModuleViewListBuilder(private val activity: Activity) {
256274
if (notificationType != null) {
257275
oldNotifications.add(notificationType)
258276
if (!notificationType.special) oldNotificationsLen++
259-
} else if (moduleHolder.footerPx != -1 &&
260-
moduleHolder.filterLevel == 1
261-
) oldNotificationsLen++ // Fix header
277+
} else if (moduleHolder.footerPx != -1 && moduleHolder.filterLevel == 1) oldNotificationsLen++ // Fix header
262278
if (moduleHolder.separator === ModuleHolder.Type.INSTALLABLE) break
263279
oldOfflineModulesLen++
264280
}
@@ -274,25 +290,23 @@ class ModuleViewListBuilder(private val activity: Activity) {
274290
val oldLen = moduleViewAdapter.moduleHolders.size
275291
moduleViewAdapter.moduleHolders.clear()
276292
moduleViewAdapter.moduleHolders.addAll(moduleHolders)
277-
if (oldNotificationsLen != newNotificationsLen ||
278-
oldNotifications != notifications
279-
) {
293+
if (oldNotificationsLen != newNotificationsLen || oldNotifications != notifications) {
280294
notifySizeChanged(
281-
moduleViewAdapter, 0,
282-
oldNotificationsLen, newNotificationsLen
295+
moduleViewAdapter, 0, oldNotificationsLen, newNotificationsLen
283296
)
284297
} else {
285298
notifySizeChanged(moduleViewAdapter, 0, 1, 1)
286299
}
287300
if (newLen - newNotificationsLen == 0) {
288301
notifySizeChanged(
289-
moduleViewAdapter, newNotificationsLen,
290-
oldLen - oldNotificationsLen, 0
302+
moduleViewAdapter, newNotificationsLen, oldLen - oldNotificationsLen, 0
291303
)
292304
} else {
293305
notifySizeChanged(
294-
moduleViewAdapter, newNotificationsLen,
295-
oldOfflineModulesLen, newOfflineModulesLen
306+
moduleViewAdapter,
307+
newNotificationsLen,
308+
oldOfflineModulesLen,
309+
newOfflineModulesLen
296310
)
297311
notifySizeChanged(
298312
moduleViewAdapter,
@@ -306,8 +320,7 @@ class ModuleViewListBuilder(private val activity: Activity) {
306320
updateInsets = Runnable {
307321
notifySizeChanged(moduleViewAdapter, 0, 1, 1)
308322
notifySizeChanged(
309-
moduleViewAdapter,
310-
moduleHolders.size, 1, 1
323+
moduleViewAdapter, moduleHolders.size, 1, 1
311324
)
312325
}
313326
}
@@ -350,8 +363,7 @@ class ModuleViewListBuilder(private val activity: Activity) {
350363
companion object {
351364
private val RUNNABLE = Runnable {}
352365
private fun notifySizeChanged(
353-
moduleViewAdapter: ModuleViewAdapter,
354-
index: Int, oldLen: Int, newLen: Int
366+
moduleViewAdapter: ModuleViewAdapter, index: Int, oldLen: Int, newLen: Int
355367
) {
356368
// Timber.i("A: " + index + " " + oldLen + " " + newLen);
357369
if (oldLen == newLen) {

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

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
3232
import timber.log.Timber
3333
import java.io.File
3434
import java.nio.charset.StandardCharsets
35-
import java.util.concurrent.Executors
3635

3736
@Suppress("NAME_SHADOWING", "unused")
3837
class RepoManager private constructor(mainApplication: MainApplication) : SyncManager() {
@@ -173,44 +172,19 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
173172
val repoModules = repoUpdaters[i]!!.toUpdate()
174173
val repoData = repoDatas[i]
175174
if (BuildConfig.DEBUG) Timber.d("Registering %s", repoData.name)
176-
// max threads is equal to the number of cores
177-
val executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
178175
for (repoModule in repoModules!!) {
179176
try {
180177
if (repoModule.propUrl != null && repoModule.propUrl!!.isNotEmpty()) {
181-
executor.execute {
182-
repoData.storeMetadata(
183-
repoModule, doHttpGet(
184-
repoModule.propUrl!!, false
185-
)
178+
repoData.storeMetadata(
179+
repoModule, doHttpGet(
180+
repoModule.propUrl!!, false
186181
)
187-
write(
188-
File(repoData.cacheRoot, repoModule.id + ".prop"), doHttpGet(
189-
repoModule.propUrl!!, false
190-
)
182+
)
183+
write(
184+
File(repoData.cacheRoot, repoModule.id + ".prop"), doHttpGet(
185+
repoModule.propUrl!!, false
191186
)
192-
193-
if (repoData.tryLoadMetadata(repoModule) && (allowLowQualityModules || !isLowQualityModule(
194-
repoModule.moduleInfo
195-
))
196-
) {
197-
// Note: registeredRepoModule may not be null if registered by multiple repos
198-
val registeredRepoModule = modules[repoModule.id]
199-
if (registeredRepoModule == null) {
200-
modules[repoModule.id] = repoModule
201-
} else if (instance.isEnabled && registeredRepoModule.repoData === androidacyRepoData) {
202-
// empty
203-
} else if (instance.isEnabled && repoModule.repoData === androidacyRepoData) {
204-
modules[repoModule.id] = repoModule
205-
} else if (repoModule.moduleInfo.versionCode > registeredRepoModule.moduleInfo.versionCode) {
206-
modules[repoModule.id] = repoModule
207-
}
208-
} else {
209-
repoModule.moduleInfo.flags =
210-
repoModule.moduleInfo.flags or ModuleInfo.FLAG_METADATA_INVALID
211-
}
212-
return@execute
213-
}
187+
)
214188
}
215189
if (repoData.tryLoadMetadata(repoModule) && (allowLowQualityModules || !isLowQualityModule(
216190
repoModule.moduleInfo
@@ -253,6 +227,7 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
253227
}
254228
}
255229
}
230+
MainApplication.INSTANCE!!.repoModules.putAll(modules)
256231
}
257232
if (BuildConfig.DEBUG) Timber.d("Finishing update")
258233
if (hasConnectivity()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RepoUpdater(repoData2: RepoData) {
3737
return 0
3838
}
3939
// if MainApplication.repoModules is not empty, return it
40-
if (MainApplication.INSTANCE!!.repoModules.isNotEmpty()) {
40+
/*if (MainApplication.INSTANCE!!.repoModules.isNotEmpty()) {
4141
Timber.d("Returning MainApplication.repoModules for %s", repoData.preferenceId)
4242
// convert to list for toUpdate
4343
val toUpdateList = ArrayList<RepoModule>()
@@ -48,7 +48,7 @@ class RepoUpdater(repoData2: RepoData) {
4848
// toapply is a collection of RepoModule, so we need to convert the list to a set
4949
toApply = HashSet(MainApplication.INSTANCE!!.repoModules.values)
5050
return toUpdate!!.size
51-
}
51+
}*/
5252
// if we shouldn't update, get the values from the ModuleListCache realm
5353
if (!repoData.shouldUpdate() && repoData.preferenceId == "androidacy_repo") { // for now, only enable cache reading for androidacy repo, until we handle storing module prop file values in cache
5454
Timber.d("Fetching index from cache for %s", repoData.preferenceId)

0 commit comments

Comments
 (0)