qol tweaks

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/102/head v2.3.6
androidacy-user 2 years ago
parent af7f3e6a8a
commit 792ac62878

@ -125,8 +125,6 @@ class AppUpdateManager private constructor() {
const val FLAG_COMPAT_FORCE_HIDE = 0x0080 const val FLAG_COMPAT_FORCE_HIDE = 0x0080
const val FLAG_COMPAT_MMT_REBORN = 0x0100 const val FLAG_COMPAT_MMT_REBORN = 0x0100
const val FLAG_COMPAT_ZIP_WRAPPER = 0x0200 const val FLAG_COMPAT_ZIP_WRAPPER = 0x0200
const val RELEASES_API_URL =
"https://api.github.com/repos/Androidacy/MagiskModuleManager/releases/latest"
val appUpdateManager = AppUpdateManager() val appUpdateManager = AppUpdateManager()
fun getFlagsForModule(moduleId: String): Int { fun getFlagsForModule(moduleId: String): Int {
return appUpdateManager.getCompatibilityFlags(moduleId) return appUpdateManager.getCompatibilityFlags(moduleId)

@ -665,7 +665,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
bottomNavigationView.selectedItemId = R.id.installed_menu_item bottomNavigationView.selectedItemId = R.id.installed_menu_item
} }
} }
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
if (MainApplication.forceDebugLogging) Timber.i("Scanning for modules!") if (MainApplication.forceDebugLogging) Timber.i("Scanning for modules!")
if (MainApplication.forceDebugLogging) Timber.i("Initialize Update") if (MainApplication.forceDebugLogging) Timber.i("Initialize Update")
val max = instance!!.getUpdatableModuleCount() val max = instance!!.getUpdatableModuleCount()
@ -761,9 +760,9 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
if (MainApplication.forceDebugLogging) Timber.i("Apply") if (MainApplication.forceDebugLogging) Timber.i("Apply")
RepoManager.getINSTANCE() RepoManager.getINSTANCE()
?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() } ?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() }
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter!!)
moduleViewListBuilder.applyTo(moduleListOnline, moduleViewAdapterOnline!!) moduleViewListBuilder.applyTo(moduleListOnline, moduleViewAdapterOnline!!)
moduleViewListBuilderOnline.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 moduleViewListBuilderOnline has the upgradeable notification, show a badge on the online repo nav item
if (MainApplication.INSTANCE!!.modulesHaveUpdates) { if (MainApplication.INSTANCE!!.modulesHaveUpdates) {
if (MainApplication.forceDebugLogging) Timber.i("Applying badge") if (MainApplication.forceDebugLogging) Timber.i("Applying badge")
@ -784,16 +783,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
} }
} }
}, true) }, 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) ExternalHelper.INSTANCE.refreshHelper(this)
initMode = false initMode = false
if (MainApplication.shouldShowFeedback() && !doSetupNowRunning) { if (MainApplication.shouldShowFeedback() && !doSetupNowRunning) {
@ -955,6 +944,7 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
RepoManager.getINSTANCE() RepoManager.getINSTANCE()
?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() } ?.runAfterUpdate { moduleViewListBuilderOnline.appendRemoteModules() }
moduleViewListBuilder.applyTo(moduleList!!, moduleViewAdapter!!) moduleViewListBuilder.applyTo(moduleList!!, moduleViewAdapter!!)
moduleViewListBuilder.applyTo(moduleListOnline!!, moduleViewAdapterOnline!!)
moduleViewListBuilderOnline.applyTo(moduleListOnline!!, moduleViewAdapterOnline!!) moduleViewListBuilderOnline.applyTo(moduleListOnline!!, moduleViewAdapterOnline!!)
runOnUiThread { runOnUiThread {
progressIndicator!!.setProgress(PRECISION, true) progressIndicator!!.setProgress(PRECISION, true)
@ -1050,7 +1040,6 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
var doSetupRestarting = false var doSetupRestarting = false
var localModuleInfoList: List<LocalModuleInfo> = ArrayList() var localModuleInfoList: List<LocalModuleInfo> = ArrayList()
var onlineModuleInfoList: List<RepoModule> = ArrayList() var onlineModuleInfoList: List<RepoModule> = ArrayList()
var isShowingWeblateSb = false // race condition
var INSTANCE: MainActivity? = null var INSTANCE: MainActivity? = null
} }
} }

@ -311,17 +311,26 @@ class AndroidacyActivity : AppCompatActivity() {
override fun onProgressChanged(view: WebView, newProgress: Int) { override fun onProgressChanged(view: WebView, newProgress: Int) {
if (downloadMode) return if (downloadMode) return
if (newProgress != 100 && prgInd.visibility != View.VISIBLE) { 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 prgInd.visibility = View.VISIBLE
} }
// if progress is greater than one, set indeterminate to false // if progress is greater than one, set indeterminate to false
if (newProgress > 1) { 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.isIndeterminate = false
} }
prgInd.setProgress(newProgress, true) prgInd.setProgress(newProgress, true)
if (newProgress == 100 && prgInd.visibility != View.GONE) { 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.isIndeterminate = true
prgInd.visibility = View.GONE prgInd.visibility = View.GONE
} }
@ -356,7 +365,10 @@ class AndroidacyActivity : AppCompatActivity() {
androidacyWebAPI.downloadMode = false androidacyWebAPI.downloadMode = false
} }
backOnResume = true 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>( for (prefix in arrayOf<String>(
"https://production-api.androidacy.com/magisk/file//", "https://production-api.androidacy.com/magisk/file//",
"https://staging-api.androidacy.com/magisk/file/" "https://staging-api.androidacy.com/magisk/file/"

@ -126,7 +126,8 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
getPreferences("androidacy")!!.getString( getPreferences("androidacy")!!.getString(
"pref_androidacy_api_token", "pref_androidacy_api_token",
null null
)) )
)
} }
} }
@ -298,7 +299,10 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
if (!jsonArray.isNull(i)) { if (!jsonArray.isNull(i)) {
jsonObject = jsonArray.getJSONObject(i) jsonObject = jsonArray.getJSONObject(i)
} else { } 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 continue
} }
} catch (e: JSONException) { } catch (e: JSONException) {

@ -34,9 +34,15 @@ enum class AndroidacyUtil {
if (url == null) return false if (url == null) return false
val uri = Uri.parse(url) val uri = Uri.parse(url)
return if (BuildConfig.DEBUG) { 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 { } 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)
} }
} }

@ -172,23 +172,28 @@ class InstallerInitializer {
} }
verCode = 0 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) { if (MainApplication.forceDebugLogging) {
Timber.i("Magisk path: %s", mgskPth) Timber.i("Magisk path: %s", mgskPth)
} }
Companion.mgskPth = mgskPth Companion.mgskPth = mgskPth
val suVer2 = Shell.cmd("su -v").exec().out 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 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)) { if (suVer2[0].contains("magisk", true)) {
isKsu = true
if (MainApplication.forceDebugLogging) {
Timber.i("SU version: ksu")
}
} else if (suVer2[0].contains("magisk", true)) {
isKsu = false isKsu = false
if (MainApplication.forceDebugLogging) { if (MainApplication.forceDebugLogging) {
Timber.i("SU version: magisk") 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 { } else {
if (MainApplication.forceDebugLogging) { if (MainApplication.forceDebugLogging) {
Timber.e("Failed to get su version: unknown su") Timber.e("Failed to get su version: unknown su")

@ -162,6 +162,10 @@ enum class ActionButtonType {
if (moduleHolder.repoModule != null && moduleHolder.repoModule!!.zipUrl != null) { if (moduleHolder.repoModule != null && moduleHolder.repoModule!!.zipUrl != null) {
updateZipUrl = moduleHolder.repoModule!!.zipUrl!! 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 repomodule is null, try localmoduleinfo
if (updateZipUrl.isEmpty() && moduleHolder.moduleInfo != null && moduleHolder.moduleInfo!!.updateZipUrl != null) { if (updateZipUrl.isEmpty() && moduleHolder.moduleInfo != null && moduleHolder.moduleInfo!!.updateZipUrl != null) {
updateZipUrl = moduleHolder.moduleInfo!!.updateZipUrl!! updateZipUrl = moduleHolder.moduleInfo!!.updateZipUrl!!

@ -116,7 +116,7 @@ class ModuleHolder : Comparable<ModuleHolder?> {
Type.NOTIFICATION Type.NOTIFICATION
} else if (moduleInfo == null && repoModule != null) { } else if (moduleInfo == null && repoModule != null) {
Type.INSTALLABLE 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) if (MainApplication.forceDebugLogging) Timber.i("Module %s is updateable", moduleId)
var ignoreUpdate = false var ignoreUpdate = false
try { try {
@ -188,6 +188,7 @@ class ModuleHolder : Comparable<ModuleHolder?> {
if (MainApplication.forceDebugLogging) Timber.d("Module %s has update, but is ignored", moduleId) if (MainApplication.forceDebugLogging) Timber.d("Module %s has update, but is ignored", moduleId)
Type.INSTALLABLE Type.INSTALLABLE
} else { } else {
if (hasUpdate()) {
INSTANCE!!.modulesHaveUpdates = true INSTANCE!!.modulesHaveUpdates = true
if (!INSTANCE!!.updateModules.contains(moduleId)) { if (!INSTANCE!!.updateModules.contains(moduleId)) {
INSTANCE!!.updateModules += moduleId INSTANCE!!.updateModules += moduleId
@ -199,6 +200,9 @@ class ModuleHolder : Comparable<ModuleHolder?> {
INSTANCE!!.updateModuleCount INSTANCE!!.updateModuleCount
) )
Type.UPDATABLE Type.UPDATABLE
} else {
Type.INSTALLED
}
} }
} else { } else {
Type.INSTALLED Type.INSTALLED
@ -214,13 +218,40 @@ class ModuleHolder : Comparable<ModuleHolder?> {
} }
fun shouldRemove(): Boolean { 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 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() return notificationType?.shouldRemove()
?: (footerPx == -1 && moduleInfo == null && (repoModule == null || !repoModule!!.repoData.isEnabled || isLowQualityModule( ?: (footerPx == -1 && moduleInfo == null && (repoModule == null || !repoModule!!.repoData.isEnabled))
repoModule!!.moduleInfo
) && !isDisableLowQualityModuleFilter))
} }
fun getButtons( fun getButtons(
@ -295,7 +326,21 @@ class ModuleHolder : Comparable<ModuleHolder?> {
} }
fun hasUpdate(): Boolean { 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 { override operator fun compareTo(other: ModuleHolder?): Int {

@ -213,7 +213,14 @@ class RepoFragment : PreferenceFragmentCompat() {
return@setOnPreferenceChangeListener false return@setOnPreferenceChangeListener false
} }
// Make sure originalApiKeyRef is not null // 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 // get original api key
val apiKey = newValue.toString() val apiKey = newValue.toString()
// Show snack bar with indeterminate progress // Show snack bar with indeterminate progress

@ -11,8 +11,6 @@ import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Handler
import android.os.Looper
import android.provider.Settings import android.provider.Settings
import android.view.View import android.view.View
import android.widget.CheckBox import android.widget.CheckBox
@ -27,7 +25,6 @@ import com.fox2code.mmm.MainApplication
import com.fox2code.mmm.R import com.fox2code.mmm.R
import com.fox2code.mmm.SetupActivity import com.fox2code.mmm.SetupActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import timber.log.Timber import timber.log.Timber
@ -206,38 +203,6 @@ class RuntimeUtils {
return MainActivity.doSetupRestarting return MainActivity.doSetupRestarting
} }
/**
* Shows a snackbar offering to take users to Weblate if their language is not available.
*
* @param language The language code.
* @param languageName The language name.
*/
@SuppressLint("RestrictedApi")
fun showWeblateSnackbar(
context: Context, activity: MainActivity, language: String, languageName: String
) {
MainActivity.isShowingWeblateSb = true
// if we haven't shown context snackbar for context version yet
val prefs = MainApplication.getPreferences("mmm")!!
if (prefs.getInt("weblate_snackbar_shown", 0) == BuildConfig.VERSION_CODE) return
val snackbar: Snackbar = Snackbar.make(
activity.findViewById(R.id.root_container),
activity.getString(R.string.language_not_available, languageName),
4000
)
snackbar.setAction(R.string.ok) {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://translate.nift4.org/engage/foxmmm/?language=$language")
activity.startActivity(intent)
}
snackbar.show()
// after four seconds, set isShowingWeblateSb to false
Handler(Looper.getMainLooper()).postDelayed({
MainActivity.isShowingWeblateSb = false
}, 4000)
prefs.edit().putInt("weblate_snackbar_shown", BuildConfig.VERSION_CODE).apply()
}
/** /**
* Shows a snackbar to upgrade androidacy membership. * Shows a snackbar to upgrade androidacy membership.
* Sure it'll be wildly popular but it's only shown for 7 seconds every 7 days. * Sure it'll be wildly popular but it's only shown for 7 seconds every 7 days.
@ -248,13 +213,6 @@ class RuntimeUtils {
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
fun showUpgradeSnackbar(context: Context, activity: MainActivity) { fun showUpgradeSnackbar(context: Context, activity: MainActivity) {
if (MainApplication.forceDebugLogging) Timber.i("showUpgradeSnackbar start") if (MainApplication.forceDebugLogging) Timber.i("showUpgradeSnackbar start")
// if sb is already showing, wait 4 seconds and try again
if (MainActivity.isShowingWeblateSb) {
Handler(Looper.getMainLooper()).postDelayed({
showUpgradeSnackbar(context, activity)
}, 4500)
return
}
val prefs = MainApplication.getPreferences("mmm")!! val prefs = MainApplication.getPreferences("mmm")!!
// if last shown < 7 days ago // if last shown < 7 days ago
if (prefs.getLong("ugsns4", 0) > System.currentTimeMillis() - 604800000) return if (prefs.getLong("ugsns4", 0) > System.currentTimeMillis() - 604800000) return

@ -149,7 +149,7 @@
</style> </style>
<style name="Theme.MagiskModuleManager.AlertDialog" parent="MaterialAlertDialog.Material3"> <style name="Theme.MagiskModuleManager.AlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog.Centered">
<item name="dialogCornerRadius">28dp</item> <item name="dialogCornerRadius">28dp</item>
<item name="cornerFamily">rounded</item> <item name="cornerFamily">rounded</item>
<item name="android:colorBackground">?attr/colorSurface</item> <item name="android:colorBackground">?attr/colorSurface</item>

Loading…
Cancel
Save