Skip to content

Commit

Permalink
qol tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: androidacy-user <opensource@androidacy.com>
  • Loading branch information
androidacy-user committed Dec 11, 2023
1 parent af7f3e6 commit 792ac62
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 105 deletions.
2 changes: 0 additions & 2 deletions app/src/main/kotlin/com/fox2code/mmm/AppUpdateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ class AppUpdateManager private constructor() {
const val FLAG_COMPAT_FORCE_HIDE = 0x0080
const val FLAG_COMPAT_MMT_REBORN = 0x0100
const val FLAG_COMPAT_ZIP_WRAPPER = 0x0200
const val RELEASES_API_URL =
"https://api.github.com/repos/Androidacy/MagiskModuleManager/releases/latest"
val appUpdateManager = AppUpdateManager()
fun getFlagsForModule(moduleId: String): Int {
return appUpdateManager.getCompatibilityFlags(moduleId)
Expand Down
15 changes: 2 additions & 13 deletions app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
bottomNavigationView.selectedItemId = R.id.installed_menu_item
}
}
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
if (MainApplication.forceDebugLogging) Timber.i("Scanning for modules!")
if (MainApplication.forceDebugLogging) Timber.i("Initialize Update")
val max = instance!!.getUpdatableModuleCount()
Expand Down Expand Up @@ -761,9 +760,9 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
if (MainApplication.forceDebugLogging) Timber.i("Apply")
RepoManager.getINSTANCE()
?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() }
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
moduleViewListBuilder.applyTo(moduleListOnline, moduleViewAdapterOnline!!)
moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline!!)
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
// if moduleViewListBuilderOnline has the upgradeable notification, show a badge on the online repo nav item
if (MainApplication.INSTANCE!!.modulesHaveUpdates) {
if (MainApplication.forceDebugLogging) Timber.i("Applying badge")
Expand All @@ -784,16 +783,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
}
}
}, true)
// if system lang is not in MainApplication.supportedLocales, show a snackbar to ask user to help translate
if (!MainApplication.supportedLocales.contains(this.resources.configuration.locales[0].language)) {
// call showWeblateSnackbar() with language code and language name
runtimeUtils!!.showWeblateSnackbar(
this,
this,
this.resources.configuration.locales[0].language,
this.resources.configuration.locales[0].displayLanguage
)
}
ExternalHelper.INSTANCE.refreshHelper(this)
initMode = false
if (MainApplication.shouldShowFeedback() && !doSetupNowRunning) {
Expand Down Expand Up @@ -955,6 +944,7 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
RepoManager.getINSTANCE()
?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() }
moduleViewListBuilder.applyTo(moduleList!!, moduleViewAdapter!!)
moduleViewListBuilder.applyTo(moduleListOnline!!, moduleViewAdapterOnline!!)
moduleViewListBuilderOnline.applyTo(moduleListOnline!!, moduleViewAdapterOnline!!)
runOnUiThread {
progressIndicator!!.setProgress(PRECISION, true)
Expand Down Expand Up @@ -1050,7 +1040,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
var doSetupRestarting = false
var localModuleInfoList: List<LocalModuleInfo> = ArrayList()
var onlineModuleInfoList: List<RepoModule> = ArrayList()
var isShowingWeblateSb = false // race condition
var INSTANCE: MainActivity? = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AndroidacyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
moduleFile = File(this.cacheDir, "module.zip")
super.onCreate(savedInstanceState)

val intent = this.intent
var uri: Uri? = intent.data
@Suppress("KotlinConstantConditions")
Expand Down Expand Up @@ -311,17 +311,26 @@ class AndroidacyActivity : AppCompatActivity() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
if (downloadMode) return
if (newProgress != 100 && prgInd.visibility != View.VISIBLE) {
if (MainApplication.forceDebugLogging) Timber.i("Progress: %d, showing progress bar", newProgress)
if (MainApplication.forceDebugLogging) Timber.i(
"Progress: %d, showing progress bar",
newProgress
)
prgInd.visibility = View.VISIBLE
}
// if progress is greater than one, set indeterminate to false
if (newProgress > 1) {
if (MainApplication.forceDebugLogging) Timber.i("Progress: %d, setting indeterminate to false", newProgress)
if (MainApplication.forceDebugLogging) Timber.i(
"Progress: %d, setting indeterminate to false",
newProgress
)
prgInd.isIndeterminate = false
}
prgInd.setProgress(newProgress, true)
if (newProgress == 100 && prgInd.visibility != View.GONE) {
if (MainApplication.forceDebugLogging) Timber.i("Progress: %d, hiding progress bar", newProgress)
if (MainApplication.forceDebugLogging) Timber.i(
"Progress: %d, hiding progress bar",
newProgress
)
prgInd.isIndeterminate = true
prgInd.visibility = View.GONE
}
Expand Down Expand Up @@ -356,7 +365,10 @@ class AndroidacyActivity : AppCompatActivity() {
androidacyWebAPI.downloadMode = false
}
backOnResume = true
if (MainApplication.forceDebugLogging) Timber.i("Exiting WebView %s", AndroidacyUtil.hideToken(downloadUrl))
if (MainApplication.forceDebugLogging) Timber.i(
"Exiting WebView %s",
AndroidacyUtil.hideToken(downloadUrl)
)
for (prefix in arrayOf<String>(
"https://production-api.androidacy.com/magisk/file//",
"https://staging-api.androidacy.com/magisk/file/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
getPreferences("androidacy")!!.getString(
"pref_androidacy_api_token",
null
))
)
)
}
}

Expand Down Expand Up @@ -298,7 +299,10 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
if (!jsonArray.isNull(i)) {
jsonObject = jsonArray.getJSONObject(i)
} else {
if (MainApplication.forceDebugLogging) Timber.d("Skipping null module at index %d", i)
if (MainApplication.forceDebugLogging) Timber.d(
"Skipping null module at index %d",
i
)
continue
}
} catch (e: JSONException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ enum class AndroidacyUtil {
if (url == null) return false
val uri = Uri.parse(url)
return if (BuildConfig.DEBUG) {
uri.host?.endsWith("api.androidacy.com") ?: false && (uri.path?.startsWith("/downloads") ?: false || uri.path?.startsWith("/magisk/file") ?: false || uri.path?.startsWith("/magisk/ddl") ?: false)
uri.host?.endsWith("api.androidacy.com") ?: false && (uri.path?.startsWith("/downloads") ?: false || uri.path?.startsWith(
"/magisk/file"
) ?: false || uri.path?.startsWith("/magisk/ddl") ?: false)
} else {
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)
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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ class InstallerInitializer {
// try su -V
if (Shell.cmd("su -V").exec().isSuccess) {
val suVer = Shell.cmd("su -V").exec().out
Timber.i("SU version: %s", suVer[0])
// use regex to get version code
val matcher2 = Regex("(\\d+)").find(suVer[0])
if (matcher2 != null) {
mgskVerCode = matcher2.groupValues[1].toInt()
if (mgskVerCode > verCode) {
verCode = mgskVerCode
Timber.i("SU version: %d", mgskVerCode)
}
} else {
if (MainApplication.forceDebugLogging) {
Timber.e("Failed to get su version: matcher2 is null")
}
verCode = 0
Timber.i("SU version: %s", suVer[0])
// use regex to get version code
val matcher2 = Regex("(\\d+)").find(suVer[0])
if (matcher2 != null) {
mgskVerCode = matcher2.groupValues[1].toInt()
if (mgskVerCode > verCode) {
verCode = mgskVerCode
Timber.i("SU version: %d", mgskVerCode)
}
} else {
if (MainApplication.forceDebugLogging) {
Timber.e("Failed to get su version: matcher2 is null")
}
verCode = 0
}
} else {
if (MainApplication.forceDebugLogging) {
Timber.e("Failed to get su version: su -V: unsuccessful")
Expand All @@ -172,23 +172,28 @@ class InstallerInitializer {
}
verCode = 0
}
mgskPth = "/data/adb" // hardcoded path. all modern versions of ksu and magisk use this path
mgskPth =
"/data/adb" // hardcoded path. all modern versions of ksu and magisk use this path
if (MainApplication.forceDebugLogging) {
Timber.i("Magisk path: %s", mgskPth)
}
Companion.mgskPth = mgskPth
val suVer2 = Shell.cmd("su -v").exec().out
// 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
if (suVer2[0].contains("kernelsu", true)) {
isKsu = true
if (MainApplication.forceDebugLogging) {
Timber.i("SU version: ksu")
}
} else if (suVer2[0].contains("magisk", true)) {
if (suVer2[0].contains("magisk", true)) {
isKsu = false
if (MainApplication.forceDebugLogging) {
Timber.i("SU version: magisk")
}
} else if (suVer2[0].contains("kernelsu", true) || suVer2[0].contains(
"ksu",
true
)
) {
isKsu = true
if (MainApplication.forceDebugLogging) {
Timber.i("SU version: ksu")
}
} else {
if (MainApplication.forceDebugLogging) {
Timber.e("Failed to get su version: unknown su")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ enum class ActionButtonType {
if (moduleHolder.repoModule != null && moduleHolder.repoModule!!.zipUrl != null) {
updateZipUrl = moduleHolder.repoModule!!.zipUrl!!
}
// check if MainApplicaiton.repomodules contains the module
if (updateZipUrl.isEmpty() && INSTANCE!!.repoModules.containsKey(moduleInfo.id)) {
updateZipUrl = INSTANCE!!.repoModules[moduleInfo.id]?.zipUrl.toString()
}
// if repomodule is null, try localmoduleinfo
if (updateZipUrl.isEmpty() && moduleHolder.moduleInfo != null && moduleHolder.moduleInfo!!.updateZipUrl != null) {
updateZipUrl = moduleHolder.moduleInfo!!.updateZipUrl!!
Expand Down
77 changes: 61 additions & 16 deletions app/src/main/kotlin/com/fox2code/mmm/module/ModuleHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ModuleHolder : Comparable<ModuleHolder?> {
Type.NOTIFICATION
} else if (moduleInfo == null && repoModule != null) {
Type.INSTALLABLE
} else if (moduleInfo!!.versionCode < moduleInfo!!.updateVersionCode || repoModule != null && moduleInfo!!.versionCode < repoModule!!.moduleInfo.versionCode) {
} else if (moduleInfo !== null && moduleInfo!!.versionCode < moduleInfo!!.updateVersionCode || repoModule != null && moduleInfo!!.versionCode < repoModule!!.moduleInfo.versionCode) {
if (MainApplication.forceDebugLogging) Timber.i("Module %s is updateable", moduleId)
var ignoreUpdate = false
try {
Expand Down Expand Up @@ -188,17 +188,21 @@ class ModuleHolder : Comparable<ModuleHolder?> {
if (MainApplication.forceDebugLogging) Timber.d("Module %s has update, but is ignored", moduleId)
Type.INSTALLABLE
} else {
INSTANCE!!.modulesHaveUpdates = true
if (!INSTANCE!!.updateModules.contains(moduleId)) {
INSTANCE!!.updateModules += moduleId
INSTANCE!!.updateModuleCount++
if (hasUpdate()) {
INSTANCE!!.modulesHaveUpdates = true
if (!INSTANCE!!.updateModules.contains(moduleId)) {
INSTANCE!!.updateModules += moduleId
INSTANCE!!.updateModuleCount++
}
if (MainApplication.forceDebugLogging) Timber.d(
"modulesHaveUpdates = %s, updateModuleCount = %s",
INSTANCE!!.modulesHaveUpdates,
INSTANCE!!.updateModuleCount
)
Type.UPDATABLE
} else {
Type.INSTALLED
}
if (MainApplication.forceDebugLogging) Timber.d(
"modulesHaveUpdates = %s, updateModuleCount = %s",
INSTANCE!!.modulesHaveUpdates,
INSTANCE!!.updateModuleCount
)
Type.UPDATABLE
}
} else {
Type.INSTALLED
Expand All @@ -214,13 +218,40 @@ class ModuleHolder : Comparable<ModuleHolder?> {
}

fun shouldRemove(): Boolean {
if (repoModule != null && moduleInfo != null && !hasUpdate()) {
// if type is not installable or updatable and we have repoModule, we should remove
if (type !== Type.INSTALLABLE && type !== Type.UPDATABLE && repoModule != null) {
Timber.d("Removing %s because type is %s and repoModule is not null", moduleId, type.name)
return true
}
// if type is updatable but we don't have an update, remove
if (type === Type.UPDATABLE && !hasUpdate()) {
Timber.d("Removing %s because type is %s and has no update", moduleId, type.name)
return true
}
// if type is installed we have an update, remove
if (type === Type.INSTALLED && repoModule != null && hasUpdate()) {
Timber.d("Removing %s because type is %s and has update and repoModule is not null", moduleId, type.name)
return true
}
// if type is installed but repomodule is not null, we should remove
if (type === Type.INSTALLED && repoModule != null) {
Timber.d("Removing %s because type is %s and repoModule is not null", moduleId, type.name)
return true
}
// if lowqualitymodulefilter is enabled and module is low quality, remove
if (!isDisableLowQualityModuleFilter) {
if (repoModule != null && isLowQualityModule(repoModule!!.moduleInfo)) {
Timber.d("Removing %s because repoModule is not null and is low quality", moduleId)
return true
}
if (moduleInfo != null && isLowQualityModule(moduleInfo!!)) {
Timber.d("Removing %s because moduleInfo is not null and is low quality", moduleId)
return true
}
}
// if type is installed but
return notificationType?.shouldRemove()
?: (footerPx == -1 && moduleInfo == null && (repoModule == null || !repoModule!!.repoData.isEnabled || isLowQualityModule(
repoModule!!.moduleInfo
) && !isDisableLowQualityModuleFilter))
?: (footerPx == -1 && moduleInfo == null && (repoModule == null || !repoModule!!.repoData.isEnabled))
}

fun getButtons(
Expand Down Expand Up @@ -295,7 +326,21 @@ class ModuleHolder : Comparable<ModuleHolder?> {
}

fun hasUpdate(): Boolean {
return moduleInfo != null && repoModule != null && moduleInfo!!.versionCode < repoModule!!.moduleInfo.versionCode
if (moduleInfo == null) {
Timber.w("Module %s has no moduleInfo", moduleId)
return false
}
if (repoModule == null && !INSTANCE!!.repoModules.containsKey(moduleId)) {
if (moduleInfo!!.updateVersionCode > moduleInfo!!.versionCode) {
Timber.d("Module %s has update from %s to %s", moduleId, moduleInfo!!.versionCode, moduleInfo!!.updateVersionCode)
return true
}
} else if (repoModule != null && repoModule!!.moduleInfo.versionCode > moduleInfo!!.versionCode) {
Timber.d("Module %s has update from repo from %s to %s", moduleId, moduleInfo!!.versionCode, repoModule!!.moduleInfo.versionCode)
return true
}
Timber.d("Module %s has no update", moduleId)
return false
}

override operator fun compareTo(other: ModuleHolder?): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,14 @@ class RepoFragment : PreferenceFragmentCompat() {
return@setOnPreferenceChangeListener false
}
// Make sure originalApiKeyRef is not null
if (originalApiKeyRef[0] == newValue) return@setOnPreferenceChangeListener true
if (originalApiKeyRef[0] == newValue) {
Toast.makeText(
requireContext(),
R.string.api_key_unchanged,
Toast.LENGTH_SHORT
).show()
return@setOnPreferenceChangeListener false
}
// get original api key
val apiKey = newValue.toString()
// Show snack bar with indeterminate progress
Expand Down
Loading

0 comments on commit 792ac62

Please sign in to comment.