Skip to content

Commit 792ac62

Browse files
qol tweaks
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent af7f3e6 commit 792ac62

File tree

11 files changed

+133
-105
lines changed

11 files changed

+133
-105
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ class AppUpdateManager private constructor() {
125125
const val FLAG_COMPAT_FORCE_HIDE = 0x0080
126126
const val FLAG_COMPAT_MMT_REBORN = 0x0100
127127
const val FLAG_COMPAT_ZIP_WRAPPER = 0x0200
128-
const val RELEASES_API_URL =
129-
"https://api.github.com/repos/Androidacy/MagiskModuleManager/releases/latest"
130128
val appUpdateManager = AppUpdateManager()
131129
fun getFlagsForModule(moduleId: String): Int {
132130
return appUpdateManager.getCompatibilityFlags(moduleId)

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

+2-13
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
665665
bottomNavigationView.selectedItemId = R.id.installed_menu_item
666666
}
667667
}
668-
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
669668
if (MainApplication.forceDebugLogging) Timber.i("Scanning for modules!")
670669
if (MainApplication.forceDebugLogging) Timber.i("Initialize Update")
671670
val max = instance!!.getUpdatableModuleCount()
@@ -761,9 +760,9 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
761760
if (MainApplication.forceDebugLogging) Timber.i("Apply")
762761
RepoManager.getINSTANCE()
763762
?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() }
764-
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
765763
moduleViewListBuilder.applyTo(moduleListOnline, moduleViewAdapterOnline!!)
766764
moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline!!)
765+
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
767766
// if moduleViewListBuilderOnline has the upgradeable notification, show a badge on the online repo nav item
768767
if (MainApplication.INSTANCE!!.modulesHaveUpdates) {
769768
if (MainApplication.forceDebugLogging) Timber.i("Applying badge")
@@ -784,16 +783,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
784783
}
785784
}
786785
}, true)
787-
// if system lang is not in MainApplication.supportedLocales, show a snackbar to ask user to help translate
788-
if (!MainApplication.supportedLocales.contains(this.resources.configuration.locales[0].language)) {
789-
// call showWeblateSnackbar() with language code and language name
790-
runtimeUtils!!.showWeblateSnackbar(
791-
this,
792-
this,
793-
this.resources.configuration.locales[0].language,
794-
this.resources.configuration.locales[0].displayLanguage
795-
)
796-
}
797786
ExternalHelper.INSTANCE.refreshHelper(this)
798787
initMode = false
799788
if (MainApplication.shouldShowFeedback() && !doSetupNowRunning) {
@@ -955,6 +944,7 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
955944
RepoManager.getINSTANCE()
956945
?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() }
957946
moduleViewListBuilder.applyTo(moduleList!!, moduleViewAdapter!!)
947+
moduleViewListBuilder.applyTo(moduleListOnline!!, moduleViewAdapterOnline!!)
958948
moduleViewListBuilderOnline.applyTo(moduleListOnline!!, moduleViewAdapterOnline!!)
959949
runOnUiThread {
960950
progressIndicator!!.setProgress(PRECISION, true)
@@ -1050,7 +1040,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
10501040
var doSetupRestarting = false
10511041
var localModuleInfoList: List<LocalModuleInfo> = ArrayList()
10521042
var onlineModuleInfoList: List<RepoModule> = ArrayList()
1053-
var isShowingWeblateSb = false // race condition
10541043
var INSTANCE: MainActivity? = null
10551044
}
10561045
}

app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyActivity.kt

+17-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class AndroidacyActivity : AppCompatActivity() {
7575
override fun onCreate(savedInstanceState: Bundle?) {
7676
moduleFile = File(this.cacheDir, "module.zip")
7777
super.onCreate(savedInstanceState)
78-
78+
7979
val intent = this.intent
8080
var uri: Uri? = intent.data
8181
@Suppress("KotlinConstantConditions")
@@ -311,17 +311,26 @@ class AndroidacyActivity : AppCompatActivity() {
311311
override fun onProgressChanged(view: WebView, newProgress: Int) {
312312
if (downloadMode) return
313313
if (newProgress != 100 && prgInd.visibility != View.VISIBLE) {
314-
if (MainApplication.forceDebugLogging) Timber.i("Progress: %d, showing progress bar", newProgress)
314+
if (MainApplication.forceDebugLogging) Timber.i(
315+
"Progress: %d, showing progress bar",
316+
newProgress
317+
)
315318
prgInd.visibility = View.VISIBLE
316319
}
317320
// if progress is greater than one, set indeterminate to false
318321
if (newProgress > 1) {
319-
if (MainApplication.forceDebugLogging) Timber.i("Progress: %d, setting indeterminate to false", newProgress)
322+
if (MainApplication.forceDebugLogging) Timber.i(
323+
"Progress: %d, setting indeterminate to false",
324+
newProgress
325+
)
320326
prgInd.isIndeterminate = false
321327
}
322328
prgInd.setProgress(newProgress, true)
323329
if (newProgress == 100 && prgInd.visibility != View.GONE) {
324-
if (MainApplication.forceDebugLogging) Timber.i("Progress: %d, hiding progress bar", newProgress)
330+
if (MainApplication.forceDebugLogging) Timber.i(
331+
"Progress: %d, hiding progress bar",
332+
newProgress
333+
)
325334
prgInd.isIndeterminate = true
326335
prgInd.visibility = View.GONE
327336
}
@@ -356,7 +365,10 @@ class AndroidacyActivity : AppCompatActivity() {
356365
androidacyWebAPI.downloadMode = false
357366
}
358367
backOnResume = true
359-
if (MainApplication.forceDebugLogging) Timber.i("Exiting WebView %s", AndroidacyUtil.hideToken(downloadUrl))
368+
if (MainApplication.forceDebugLogging) Timber.i(
369+
"Exiting WebView %s",
370+
AndroidacyUtil.hideToken(downloadUrl)
371+
)
360372
for (prefix in arrayOf<String>(
361373
"https://production-api.androidacy.com/magisk/file//",
362374
"https://staging-api.androidacy.com/magisk/file/"

app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyRepoData.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
126126
getPreferences("androidacy")!!.getString(
127127
"pref_androidacy_api_token",
128128
null
129-
))
129+
)
130+
)
130131
}
131132
}
132133

@@ -298,7 +299,10 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
298299
if (!jsonArray.isNull(i)) {
299300
jsonObject = jsonArray.getJSONObject(i)
300301
} else {
301-
if (MainApplication.forceDebugLogging) Timber.d("Skipping null module at index %d", i)
302+
if (MainApplication.forceDebugLogging) Timber.d(
303+
"Skipping null module at index %d",
304+
i
305+
)
302306
continue
303307
}
304308
} catch (e: JSONException) {

app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyUtil.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ enum class AndroidacyUtil {
3434
if (url == null) return false
3535
val uri = Uri.parse(url)
3636
return if (BuildConfig.DEBUG) {
37-
uri.host?.endsWith("api.androidacy.com") ?: false && (uri.path?.startsWith("/downloads") ?: false || uri.path?.startsWith("/magisk/file") ?: false || uri.path?.startsWith("/magisk/ddl") ?: false)
37+
uri.host?.endsWith("api.androidacy.com") ?: false && (uri.path?.startsWith("/downloads") ?: false || uri.path?.startsWith(
38+
"/magisk/file"
39+
) ?: false || uri.path?.startsWith("/magisk/ddl") ?: false)
3840
} else {
39-
uri.host?.equals("production-api.androidacy.com") ?: false && (uri.path?.startsWith("/downloads") ?: false || uri.path?.startsWith("/magisk/file") ?: false || uri.path?.startsWith("/magisk/ddl") ?: false)
41+
uri.host?.equals("production-api.androidacy.com") ?: false && (uri.path?.startsWith(
42+
"/downloads"
43+
) ?: false || uri.path?.startsWith("/magisk/file") ?: false || uri.path?.startsWith(
44+
"/magisk/ddl"
45+
) ?: false)
4046
}
4147
}
4248

app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt

+26-21
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ class InstallerInitializer {
144144
// try su -V
145145
if (Shell.cmd("su -V").exec().isSuccess) {
146146
val suVer = Shell.cmd("su -V").exec().out
147-
Timber.i("SU version: %s", suVer[0])
148-
// use regex to get version code
149-
val matcher2 = Regex("(\\d+)").find(suVer[0])
150-
if (matcher2 != null) {
151-
mgskVerCode = matcher2.groupValues[1].toInt()
152-
if (mgskVerCode > verCode) {
153-
verCode = mgskVerCode
154-
Timber.i("SU version: %d", mgskVerCode)
155-
}
156-
} else {
157-
if (MainApplication.forceDebugLogging) {
158-
Timber.e("Failed to get su version: matcher2 is null")
159-
}
160-
verCode = 0
147+
Timber.i("SU version: %s", suVer[0])
148+
// use regex to get version code
149+
val matcher2 = Regex("(\\d+)").find(suVer[0])
150+
if (matcher2 != null) {
151+
mgskVerCode = matcher2.groupValues[1].toInt()
152+
if (mgskVerCode > verCode) {
153+
verCode = mgskVerCode
154+
Timber.i("SU version: %d", mgskVerCode)
161155
}
156+
} else {
157+
if (MainApplication.forceDebugLogging) {
158+
Timber.e("Failed to get su version: matcher2 is null")
159+
}
160+
verCode = 0
161+
}
162162
} else {
163163
if (MainApplication.forceDebugLogging) {
164164
Timber.e("Failed to get su version: su -V: unsuccessful")
@@ -172,23 +172,28 @@ class InstallerInitializer {
172172
}
173173
verCode = 0
174174
}
175-
mgskPth = "/data/adb" // hardcoded path. all modern versions of ksu and magisk use this path
175+
mgskPth =
176+
"/data/adb" // hardcoded path. all modern versions of ksu and magisk use this path
176177
if (MainApplication.forceDebugLogging) {
177178
Timber.i("Magisk path: %s", mgskPth)
178179
}
179180
Companion.mgskPth = mgskPth
180181
val suVer2 = Shell.cmd("su -v").exec().out
181182
// if output[0] contains kernelsu, then it's ksu. if it contains magisk, then it's magisk. otherwise, it's something we don't know and we return null
182-
if (suVer2[0].contains("kernelsu", true)) {
183-
isKsu = true
184-
if (MainApplication.forceDebugLogging) {
185-
Timber.i("SU version: ksu")
186-
}
187-
} else if (suVer2[0].contains("magisk", true)) {
183+
if (suVer2[0].contains("magisk", true)) {
188184
isKsu = false
189185
if (MainApplication.forceDebugLogging) {
190186
Timber.i("SU version: magisk")
191187
}
188+
} else if (suVer2[0].contains("kernelsu", true) || suVer2[0].contains(
189+
"ksu",
190+
true
191+
)
192+
) {
193+
isKsu = true
194+
if (MainApplication.forceDebugLogging) {
195+
Timber.i("SU version: ksu")
196+
}
192197
} else {
193198
if (MainApplication.forceDebugLogging) {
194199
Timber.e("Failed to get su version: unknown su")

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

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ enum class ActionButtonType {
162162
if (moduleHolder.repoModule != null && moduleHolder.repoModule!!.zipUrl != null) {
163163
updateZipUrl = moduleHolder.repoModule!!.zipUrl!!
164164
}
165+
// check if MainApplicaiton.repomodules contains the module
166+
if (updateZipUrl.isEmpty() && INSTANCE!!.repoModules.containsKey(moduleInfo.id)) {
167+
updateZipUrl = INSTANCE!!.repoModules[moduleInfo.id]?.zipUrl.toString()
168+
}
165169
// if repomodule is null, try localmoduleinfo
166170
if (updateZipUrl.isEmpty() && moduleHolder.moduleInfo != null && moduleHolder.moduleInfo!!.updateZipUrl != null) {
167171
updateZipUrl = moduleHolder.moduleInfo!!.updateZipUrl!!

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

+61-16
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ModuleHolder : Comparable<ModuleHolder?> {
116116
Type.NOTIFICATION
117117
} else if (moduleInfo == null && repoModule != null) {
118118
Type.INSTALLABLE
119-
} else if (moduleInfo!!.versionCode < moduleInfo!!.updateVersionCode || repoModule != null && moduleInfo!!.versionCode < repoModule!!.moduleInfo.versionCode) {
119+
} else if (moduleInfo !== null && moduleInfo!!.versionCode < moduleInfo!!.updateVersionCode || repoModule != null && moduleInfo!!.versionCode < repoModule!!.moduleInfo.versionCode) {
120120
if (MainApplication.forceDebugLogging) Timber.i("Module %s is updateable", moduleId)
121121
var ignoreUpdate = false
122122
try {
@@ -188,17 +188,21 @@ class ModuleHolder : Comparable<ModuleHolder?> {
188188
if (MainApplication.forceDebugLogging) Timber.d("Module %s has update, but is ignored", moduleId)
189189
Type.INSTALLABLE
190190
} else {
191-
INSTANCE!!.modulesHaveUpdates = true
192-
if (!INSTANCE!!.updateModules.contains(moduleId)) {
193-
INSTANCE!!.updateModules += moduleId
194-
INSTANCE!!.updateModuleCount++
191+
if (hasUpdate()) {
192+
INSTANCE!!.modulesHaveUpdates = true
193+
if (!INSTANCE!!.updateModules.contains(moduleId)) {
194+
INSTANCE!!.updateModules += moduleId
195+
INSTANCE!!.updateModuleCount++
196+
}
197+
if (MainApplication.forceDebugLogging) Timber.d(
198+
"modulesHaveUpdates = %s, updateModuleCount = %s",
199+
INSTANCE!!.modulesHaveUpdates,
200+
INSTANCE!!.updateModuleCount
201+
)
202+
Type.UPDATABLE
203+
} else {
204+
Type.INSTALLED
195205
}
196-
if (MainApplication.forceDebugLogging) Timber.d(
197-
"modulesHaveUpdates = %s, updateModuleCount = %s",
198-
INSTANCE!!.modulesHaveUpdates,
199-
INSTANCE!!.updateModuleCount
200-
)
201-
Type.UPDATABLE
202206
}
203207
} else {
204208
Type.INSTALLED
@@ -214,13 +218,40 @@ class ModuleHolder : Comparable<ModuleHolder?> {
214218
}
215219

216220
fun shouldRemove(): Boolean {
217-
if (repoModule != null && moduleInfo != null && !hasUpdate()) {
221+
// if type is not installable or updatable and we have repoModule, we should remove
222+
if (type !== Type.INSTALLABLE && type !== Type.UPDATABLE && repoModule != null) {
223+
Timber.d("Removing %s because type is %s and repoModule is not null", moduleId, type.name)
224+
return true
225+
}
226+
// if type is updatable but we don't have an update, remove
227+
if (type === Type.UPDATABLE && !hasUpdate()) {
228+
Timber.d("Removing %s because type is %s and has no update", moduleId, type.name)
229+
return true
230+
}
231+
// if type is installed we have an update, remove
232+
if (type === Type.INSTALLED && repoModule != null && hasUpdate()) {
233+
Timber.d("Removing %s because type is %s and has update and repoModule is not null", moduleId, type.name)
234+
return true
235+
}
236+
// if type is installed but repomodule is not null, we should remove
237+
if (type === Type.INSTALLED && repoModule != null) {
238+
Timber.d("Removing %s because type is %s and repoModule is not null", moduleId, type.name)
218239
return true
219240
}
241+
// if lowqualitymodulefilter is enabled and module is low quality, remove
242+
if (!isDisableLowQualityModuleFilter) {
243+
if (repoModule != null && isLowQualityModule(repoModule!!.moduleInfo)) {
244+
Timber.d("Removing %s because repoModule is not null and is low quality", moduleId)
245+
return true
246+
}
247+
if (moduleInfo != null && isLowQualityModule(moduleInfo!!)) {
248+
Timber.d("Removing %s because moduleInfo is not null and is low quality", moduleId)
249+
return true
250+
}
251+
}
252+
// if type is installed but
220253
return notificationType?.shouldRemove()
221-
?: (footerPx == -1 && moduleInfo == null && (repoModule == null || !repoModule!!.repoData.isEnabled || isLowQualityModule(
222-
repoModule!!.moduleInfo
223-
) && !isDisableLowQualityModuleFilter))
254+
?: (footerPx == -1 && moduleInfo == null && (repoModule == null || !repoModule!!.repoData.isEnabled))
224255
}
225256

226257
fun getButtons(
@@ -295,7 +326,21 @@ class ModuleHolder : Comparable<ModuleHolder?> {
295326
}
296327

297328
fun hasUpdate(): Boolean {
298-
return moduleInfo != null && repoModule != null && moduleInfo!!.versionCode < repoModule!!.moduleInfo.versionCode
329+
if (moduleInfo == null) {
330+
Timber.w("Module %s has no moduleInfo", moduleId)
331+
return false
332+
}
333+
if (repoModule == null && !INSTANCE!!.repoModules.containsKey(moduleId)) {
334+
if (moduleInfo!!.updateVersionCode > moduleInfo!!.versionCode) {
335+
Timber.d("Module %s has update from %s to %s", moduleId, moduleInfo!!.versionCode, moduleInfo!!.updateVersionCode)
336+
return true
337+
}
338+
} else if (repoModule != null && repoModule!!.moduleInfo.versionCode > moduleInfo!!.versionCode) {
339+
Timber.d("Module %s has update from repo from %s to %s", moduleId, moduleInfo!!.versionCode, repoModule!!.moduleInfo.versionCode)
340+
return true
341+
}
342+
Timber.d("Module %s has no update", moduleId)
343+
return false
299344
}
300345

301346
override operator fun compareTo(other: ModuleHolder?): Int {

app/src/main/kotlin/com/fox2code/mmm/settings/RepoFragment.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,14 @@ class RepoFragment : PreferenceFragmentCompat() {
213213
return@setOnPreferenceChangeListener false
214214
}
215215
// Make sure originalApiKeyRef is not null
216-
if (originalApiKeyRef[0] == newValue) return@setOnPreferenceChangeListener true
216+
if (originalApiKeyRef[0] == newValue) {
217+
Toast.makeText(
218+
requireContext(),
219+
R.string.api_key_unchanged,
220+
Toast.LENGTH_SHORT
221+
).show()
222+
return@setOnPreferenceChangeListener false
223+
}
217224
// get original api key
218225
val apiKey = newValue.toString()
219226
// Show snack bar with indeterminate progress

0 commit comments

Comments
 (0)