From 34450cdddd69c586d61197dcea1ef1c69e65e026 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 19 Aug 2020 02:05:23 -0700 Subject: [PATCH] More refactoring Cleanups, move classes to sane locations, etc. --- app/proguard-rules.pro | 6 +- .../topjohnwu/magisk/arch/BaseViewModel.kt | 8 +- .../topjohnwu/magisk/core/GeneralReceiver.kt | 4 +- .../magisk/core/download/DownloadService.kt | 8 +- .../magisk/core/download/ManagerUpgrade.kt | 6 +- .../magisk/core/download/RemoteFileService.kt | 6 +- .../magisk/core/magiskdb/PolicyDao.kt | 12 +- .../magisk/core/model/module/Repo.kt | 2 +- .../MagiskLog.kt => core/model/su/SuLog.kt} | 11 +- .../model/{MagiskPolicy.kt => su/SuPolicy.kt} | 16 +-- .../magisk/core/su/SuCallbackHandler.kt | 10 +- .../magisk/core/su/SuRequestHandler.kt | 10 +- .../magisk/core/tasks/MagiskInstaller.kt | 19 +-- .../magisk/data/database/SuLogDao.kt | 10 +- .../magisk/data/repository/LogRepository.kt | 4 +- .../data/repository/MagiskRepository.kt | 4 +- .../magisk/databinding/RecyclerViewItems.kt | 11 ++ .../magisk/databinding/RvBindingAdapter.kt | 3 +- .../events/InstallExternalModuleEvent.kt | 2 +- .../{model => }/events/OpenInappLinkEvent.kt | 2 +- .../magisk/{model => }/events/RebootEvent.kt | 2 +- .../topjohnwu/magisk/events/SnackbarEvent.kt | 46 +++++++ .../com/topjohnwu/magisk/events/ViewEvents.kt | 76 +++++++++++ .../events/dialog/BiometricDialog.kt | 2 +- .../events/dialog/DarkThemeDialog.kt | 2 +- .../{model => }/events/dialog/DialogEvent.kt | 2 +- .../{model => }/events/dialog/EnvFixDialog.kt | 6 +- .../events/dialog/ManagerInstallDialog.kt | 6 +- .../events/dialog/ModuleInstallDialog.kt | 6 +- .../events/dialog/SecondSlotWarningDialog.kt | 2 +- .../events/dialog/SuperuserRevokeDialog.kt | 4 +- .../events/dialog/UninstallDialog.kt | 6 +- .../java/com/topjohnwu/magisk/ktx/Snackbar.kt | 126 ------------------ .../model/entity/recycler/LenientRvItem.kt | 16 --- .../magisk/model/entity/recycler/ThemeItem.kt | 14 -- .../model/entity/state/IndeterminateState.kt | 5 - .../magisk/model/events/SnackbarEvent.kt | 39 ------ .../{entity => }/internal/Configuration.kt | 2 +- .../{entity => }/internal/DownloadSubject.kt | 2 +- .../recycler => ui/flash}/ConsoleItem.kt | 6 +- .../magisk/ui/flash/FlashViewModel.kt | 3 +- .../{model/entity => ui/hide}/HideAppInfo.kt | 2 +- .../entity/recycler => ui/hide}/HideRvItem.kt | 5 +- .../{model/entity => ui/hide}/HideTarget.kt | 2 +- .../topjohnwu/magisk/ui/hide/HideViewModel.kt | 6 - .../entity => ui/home}/DeveloperItem.kt | 2 +- .../topjohnwu/magisk/ui/home/HomeFragment.kt | 2 +- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 11 +- .../magisk/ui/install/InstallFragment.kt | 2 +- .../magisk/ui/install/InstallViewModel.kt | 8 +- .../entity/recycler => ui/log}/LogRvItem.kt | 10 +- .../topjohnwu/magisk/ui/log/LogViewModel.kt | 11 +- .../magisk/ui/module/ModuleFragment.kt | 2 +- .../recycler => ui/module}/ModuleRvItem.kt | 3 +- .../magisk/ui/module/ModuleViewModel.kt | 12 +- .../safetynet/CheckSafetyNetEvent.kt} | 81 +---------- .../utils => ui/safetynet}/SafetyNetHelper.kt | 2 +- .../magisk/ui/safetynet/SafetynetViewModel.kt | 3 +- .../settings/BaseSettingsItem.kt} | 18 +-- .../magisk/ui/settings/SettingsItems.kt | 47 ++++--- .../magisk/ui/settings/SettingsViewModel.kt | 21 ++- .../recycler => ui/superuser}/PolicyRvItem.kt | 19 ++- .../superuser}/SpinnerRvItem.kt | 4 +- .../magisk/ui/superuser/SuperuserViewModel.kt | 27 ++-- .../magisk/ui/surequest/SuRequestViewModel.kt | 8 +- .../magisk/ui/theme/ThemeViewModel.kt | 6 +- .../recycler => view}/TappableHeadlineItem.kt | 2 +- .../entity/recycler => view}/TextItem.kt | 2 +- app/src/main/res/layout/fragment_home_md2.xml | 2 +- app/src/main/res/layout/item_console_md2.xml | 2 +- app/src/main/res/layout/item_developer.xml | 2 +- app/src/main/res/layout/item_hide_md2.xml | 2 +- .../main/res/layout/item_hide_process_md2.xml | 2 +- app/src/main/res/layout/item_icon_link.xml | 2 +- .../main/res/layout/item_log_access_md2.xml | 2 +- .../main/res/layout/item_module_download.xml | 2 +- app/src/main/res/layout/item_module_md2.xml | 2 +- app/src/main/res/layout/item_policy_md2.xml | 2 +- app/src/main/res/layout/item_repo_md2.xml | 2 +- app/src/main/res/layout/item_section_md2.xml | 2 +- app/src/main/res/layout/item_settings.xml | 4 +- .../main/res/layout/item_settings_section.xml | 2 +- app/src/main/res/layout/item_spinner.xml | 4 +- .../res/layout/item_tappable_headline.xml | 4 +- app/src/main/res/layout/item_text.xml | 4 +- 85 files changed, 365 insertions(+), 522 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/MagiskLog.kt => core/model/su/SuLog.kt} (67%) rename app/src/main/java/com/topjohnwu/magisk/core/model/{MagiskPolicy.kt => su/SuPolicy.kt} (85%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/InstallExternalModuleEvent.kt (96%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/OpenInappLinkEvent.kt (96%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/RebootEvent.kt (96%) create mode 100644 app/src/main/java/com/topjohnwu/magisk/events/SnackbarEvent.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/BiometricDialog.kt (95%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/DarkThemeDialog.kt (97%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/DialogEvent.kt (90%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/EnvFixDialog.kt (89%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/ManagerInstallDialog.kt (88%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/ModuleInstallDialog.kt (87%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/SecondSlotWarningDialog.kt (90%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/SuperuserRevokeDialog.kt (94%) rename app/src/main/java/com/topjohnwu/magisk/{model => }/events/dialog/UninstallDialog.kt (90%) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/ktx/Snackbar.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LenientRvItem.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ThemeItem.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/model/entity/state/IndeterminateState.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/model/events/SnackbarEvent.kt rename app/src/main/java/com/topjohnwu/magisk/model/{entity => }/internal/Configuration.kt (93%) rename app/src/main/java/com/topjohnwu/magisk/model/{entity => }/internal/DownloadSubject.kt (98%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => ui/flash}/ConsoleItem.kt (81%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity => ui/hide}/HideAppInfo.kt (93%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => ui/hide}/HideRvItem.kt (92%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity => ui/hide}/HideTarget.kt (85%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity => ui/home}/DeveloperItem.kt (98%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => ui/log}/LogRvItem.kt (74%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => ui/module}/ModuleRvItem.kt (96%) rename app/src/main/java/com/topjohnwu/magisk/{model/events/ViewEvents.kt => ui/safetynet/CheckSafetyNetEvent.kt} (63%) rename app/src/main/java/com/topjohnwu/magisk/{core/utils => ui/safetynet}/SafetyNetHelper.kt (80%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler/SettingsItem.kt => ui/settings/BaseSettingsItem.kt} (90%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => ui/superuser}/PolicyRvItem.kt (75%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => ui/superuser}/SpinnerRvItem.kt (87%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => view}/TappableHeadlineItem.kt (94%) rename app/src/main/java/com/topjohnwu/magisk/{model/entity/recycler => view}/TextItem.kt (86%) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 4786c3aa4..dfa293cf4 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -29,9 +29,9 @@ -keep class a.* { *; } # Snet --keepclassmembers class com.topjohnwu.magisk.core.utils.SafetyNetHelper { *; } --keep,allowobfuscation interface com.topjohnwu.magisk.core.utils.SafetyNetHelper$Callback --keepclassmembers class * implements com.topjohnwu.magisk.core.utils.SafetyNetHelper$Callback { +-keepclassmembers class com.topjohnwu.magisk.ui.safetynet.SafetyNetHelper { *; } +-keep,allowobfuscation interface com.topjohnwu.magisk.ui.safetynet.SafetyNetHelper$Callback +-keepclassmembers class * implements com.topjohnwu.magisk.ui.safetynet.SafetyNetHelper$Callback { void onResponse(int); } diff --git a/app/src/main/java/com/topjohnwu/magisk/arch/BaseViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/arch/BaseViewModel.kt index 4e3a7eea3..903cb3d28 100644 --- a/app/src/main/java/com/topjohnwu/magisk/arch/BaseViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/arch/BaseViewModel.kt @@ -15,10 +15,10 @@ import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.base.BaseActivity -import com.topjohnwu.magisk.model.events.BackPressEvent -import com.topjohnwu.magisk.model.events.PermissionEvent -import com.topjohnwu.magisk.model.events.SnackbarEvent -import com.topjohnwu.magisk.model.events.ViewActionEvent +import com.topjohnwu.magisk.events.BackPressEvent +import com.topjohnwu.magisk.events.PermissionEvent +import com.topjohnwu.magisk.events.SnackbarEvent +import com.topjohnwu.magisk.events.ViewActionEvent import com.topjohnwu.magisk.model.navigation.NavigationWrapper import com.topjohnwu.magisk.utils.ObservableHost import com.topjohnwu.magisk.utils.set diff --git a/app/src/main/java/com/topjohnwu/magisk/core/GeneralReceiver.kt b/app/src/main/java/com/topjohnwu/magisk/core/GeneralReceiver.kt index 11d14f98f..0470fe8ef 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/GeneralReceiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/GeneralReceiver.kt @@ -8,8 +8,8 @@ import com.topjohnwu.magisk.core.magiskdb.PolicyDao import com.topjohnwu.magisk.core.model.ManagerJson import com.topjohnwu.magisk.core.su.SuCallbackHandler import com.topjohnwu.magisk.ktx.reboot -import com.topjohnwu.magisk.model.entity.internal.Configuration -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject +import com.topjohnwu.magisk.model.internal.Configuration +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.magisk.view.Shortcuts import com.topjohnwu.superuser.Shell import kotlinx.coroutines.GlobalScope diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt index 0103290a7..4f18b0f36 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt @@ -13,10 +13,10 @@ import com.topjohnwu.magisk.core.tasks.EnvFixTask import com.topjohnwu.magisk.ktx.chooser import com.topjohnwu.magisk.ktx.exists import com.topjohnwu.magisk.ktx.provide -import com.topjohnwu.magisk.model.entity.internal.Configuration.* -import com.topjohnwu.magisk.model.entity.internal.Configuration.Flash.Secondary -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.* +import com.topjohnwu.magisk.model.internal.Configuration.* +import com.topjohnwu.magisk.model.internal.Configuration.Flash.Secondary +import com.topjohnwu.magisk.model.internal.DownloadSubject +import com.topjohnwu.magisk.model.internal.DownloadSubject.* import com.topjohnwu.magisk.ui.flash.FlashFragment import com.topjohnwu.magisk.utils.APKInstall import org.koin.core.get diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt index bd0753a7a..5373e5a79 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt @@ -10,9 +10,9 @@ import com.topjohnwu.magisk.core.intent import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.utils.PatchAPK import com.topjohnwu.magisk.ktx.writeTo -import com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Restore -import com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Upgrade -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject +import com.topjohnwu.magisk.model.internal.Configuration.APK.Restore +import com.topjohnwu.magisk.model.internal.Configuration.APK.Upgrade +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.superuser.Shell import java.io.File diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/RemoteFileService.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/RemoteFileService.kt index c57145edf..5b6e408fa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/RemoteFileService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/RemoteFileService.kt @@ -10,9 +10,9 @@ import com.topjohnwu.magisk.core.utils.ProgressInputStream import com.topjohnwu.magisk.data.network.GithubRawServices import com.topjohnwu.magisk.ktx.checkSum import com.topjohnwu.magisk.ktx.writeTo -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Module +import com.topjohnwu.magisk.model.internal.DownloadSubject +import com.topjohnwu.magisk.model.internal.DownloadSubject.Magisk +import com.topjohnwu.magisk.model.internal.DownloadSubject.Module import com.topjohnwu.magisk.view.Notifications import kotlinx.coroutines.launch import okhttp3.ResponseBody diff --git a/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt b/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt index 9b0342cd4..fef1cc403 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/magiskdb/PolicyDao.kt @@ -3,9 +3,9 @@ package com.topjohnwu.magisk.core.magiskdb import android.content.Context import android.content.pm.PackageManager import com.topjohnwu.magisk.core.Const -import com.topjohnwu.magisk.core.model.MagiskPolicy -import com.topjohnwu.magisk.core.model.toMap -import com.topjohnwu.magisk.core.model.toPolicy +import com.topjohnwu.magisk.core.model.su.SuPolicy +import com.topjohnwu.magisk.core.model.su.toMap +import com.topjohnwu.magisk.core.model.su.toPolicy import com.topjohnwu.magisk.ktx.now import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -49,11 +49,11 @@ class PolicyDao( } }.query().first().toPolicyOrNull() - suspend fun update(policy: MagiskPolicy) = buildQuery { + suspend fun update(policy: SuPolicy) = buildQuery { values(policy.toMap()) }.commit() - suspend fun fetchAll(mapper: (MagiskPolicy) -> R) = buildQuery { condition { equals("uid/100000", Const.USER_ID) } @@ -61,7 +61,7 @@ class PolicyDao( it.toPolicyOrNull()?.let(mapper) } - private fun Map.toPolicyOrNull(): MagiskPolicy? { + private fun Map.toPolicyOrNull(): SuPolicy? { return runCatching { toPolicy(context.packageManager) }.getOrElse { Timber.e(it) if (it is PackageManager.NameNotFoundException) { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt index 291c839aa..5f6ca98de 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/module/Repo.kt @@ -59,6 +59,6 @@ data class Repo( class IllegalRepoException(message: String) : Exception(message) companion object { - val dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM)!! + val dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLog.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuLog.kt similarity index 67% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLog.kt rename to app/src/main/java/com/topjohnwu/magisk/core/model/su/SuLog.kt index a9a47ed68..63792fe14 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuLog.kt @@ -1,16 +1,15 @@ -package com.topjohnwu.magisk.model.entity +package com.topjohnwu.magisk.core.model.su import androidx.room.Entity import androidx.room.Ignore import androidx.room.PrimaryKey -import com.topjohnwu.magisk.core.model.MagiskPolicy -import com.topjohnwu.magisk.core.model.MagiskPolicy.Companion.ALLOW +import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.ALLOW import com.topjohnwu.magisk.ktx.now import com.topjohnwu.magisk.ktx.timeFormatTime import com.topjohnwu.magisk.ktx.toTime @Entity(tableName = "logs") -data class MagiskLog( +data class SuLog( val fromUid: Int, val toUid: Int, val fromPid: Int, @@ -24,8 +23,8 @@ data class MagiskLog( @Ignore val timeString = time.toTime(timeFormatTime) } -fun MagiskPolicy.toLog( +fun SuPolicy.toLog( toUid: Int, fromPid: Int, command: String -) = MagiskLog(uid, toUid, fromPid, packageName, appName, command, policy == ALLOW, now) +) = SuLog(uid, toUid, fromPid, packageName, appName, command, policy == ALLOW, now) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/MagiskPolicy.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt similarity index 85% rename from app/src/main/java/com/topjohnwu/magisk/core/model/MagiskPolicy.kt rename to app/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt index 881965482..e2727263f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/MagiskPolicy.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt @@ -1,12 +1,12 @@ -package com.topjohnwu.magisk.core.model +package com.topjohnwu.magisk.core.model.su import android.content.pm.ApplicationInfo import android.content.pm.PackageManager -import com.topjohnwu.magisk.core.model.MagiskPolicy.Companion.INTERACTIVE +import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.INTERACTIVE import com.topjohnwu.magisk.ktx.getLabel -data class MagiskPolicy( +data class SuPolicy( var uid: Int, val packageName: String, val appName: String, @@ -25,7 +25,7 @@ data class MagiskPolicy( } -fun MagiskPolicy.toMap() = mapOf( +fun SuPolicy.toMap() = mapOf( "uid" to uid, "package_name" to packageName, "policy" to policy, @@ -35,7 +35,7 @@ fun MagiskPolicy.toMap() = mapOf( ) @Throws(PackageManager.NameNotFoundException::class) -fun Map.toPolicy(pm: PackageManager): MagiskPolicy { +fun Map.toPolicy(pm: PackageManager): SuPolicy { val uid = get("uid")?.toIntOrNull() ?: -1 val packageName = get("package_name").orEmpty() val info = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES) @@ -43,7 +43,7 @@ fun Map.toPolicy(pm: PackageManager): MagiskPolicy { if (info.uid != uid) throw PackageManager.NameNotFoundException() - return MagiskPolicy( + return SuPolicy( uid = uid, packageName = packageName, policy = get("policy")?.toIntOrNull() ?: INTERACTIVE, @@ -56,11 +56,11 @@ fun Map.toPolicy(pm: PackageManager): MagiskPolicy { } @Throws(PackageManager.NameNotFoundException::class) -fun Int.toPolicy(pm: PackageManager, policy: Int = INTERACTIVE): MagiskPolicy { +fun Int.toPolicy(pm: PackageManager, policy: Int = INTERACTIVE): SuPolicy { val pkg = pm.getPackagesForUid(this)?.firstOrNull() ?: throw PackageManager.NameNotFoundException() val info = pm.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES) - return MagiskPolicy( + return SuPolicy( uid = info.uid, packageName = pkg, policy = policy, diff --git a/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt b/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt index 3f948261a..0198e0cef 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt @@ -11,14 +11,14 @@ import com.topjohnwu.magisk.ProviderCallHandler import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.intent -import com.topjohnwu.magisk.core.model.MagiskPolicy -import com.topjohnwu.magisk.core.model.toPolicy +import com.topjohnwu.magisk.core.model.su.SuPolicy +import com.topjohnwu.magisk.core.model.su.toLog +import com.topjohnwu.magisk.core.model.su.toPolicy import com.topjohnwu.magisk.core.wrap import com.topjohnwu.magisk.data.repository.LogRepository import com.topjohnwu.magisk.ktx.get import com.topjohnwu.magisk.ktx.startActivity import com.topjohnwu.magisk.ktx.startActivityWithRoot -import com.topjohnwu.magisk.model.entity.toLog import com.topjohnwu.magisk.ui.surequest.SuRequestActivity import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.superuser.Shell @@ -132,9 +132,9 @@ object SuCallbackHandler : ProviderCallHandler { } } - private fun notify(context: Context, policy: MagiskPolicy) { + private fun notify(context: Context, policy: SuPolicy) { if (policy.notification && Config.suNotification == Config.Value.NOTIFICATION_TOAST) { - val resId = if (policy.policy == MagiskPolicy.ALLOW) + val resId = if (policy.policy == SuPolicy.ALLOW) R.string.su_allow_toast else R.string.su_deny_toast diff --git a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt index 3de65f036..49193efda 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt @@ -10,8 +10,8 @@ import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.magiskdb.PolicyDao -import com.topjohnwu.magisk.core.model.MagiskPolicy -import com.topjohnwu.magisk.core.model.toPolicy +import com.topjohnwu.magisk.core.model.su.SuPolicy +import com.topjohnwu.magisk.core.model.su.toPolicy import com.topjohnwu.magisk.ktx.now import kotlinx.coroutines.* import timber.log.Timber @@ -27,7 +27,7 @@ abstract class SuRequestHandler( private lateinit var output: DataOutputStream private lateinit var input: DataInputStream - protected lateinit var policy: MagiskPolicy + protected lateinit var policy: SuPolicy private set abstract fun onStart() @@ -44,11 +44,11 @@ abstract class SuRequestHandler( when (Config.suAutoReponse) { Config.Value.SU_AUTO_DENY -> { - respond(MagiskPolicy.DENY, 0) + respond(SuPolicy.DENY, 0) return true } Config.Value.SU_AUTO_ALLOW -> { - respond(MagiskPolicy.ALLOW, 0) + respond(SuPolicy.ALLOW, 0) return true } } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index 2fb182d0a..7eafb474d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -14,10 +14,10 @@ import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.data.network.GithubRawServices import com.topjohnwu.magisk.di.Protected +import com.topjohnwu.magisk.events.dialog.EnvFixDialog import com.topjohnwu.magisk.ktx.readUri import com.topjohnwu.magisk.ktx.reboot import com.topjohnwu.magisk.ktx.withStreams -import com.topjohnwu.magisk.model.events.dialog.EnvFixDialog import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.signing.SignBoot import com.topjohnwu.superuser.Shell @@ -100,6 +100,7 @@ abstract class MagiskInstallImpl : KoinComponent { return true } + @Suppress("DEPRECATION") private fun extractZip(): Boolean { val arch: String arch = if (Build.VERSION.SDK_INT >= 21) { @@ -130,14 +131,14 @@ abstract class MagiskInstallImpl : KoinComponent { } if (name == null && ze.name.startsWith("chromeos/")) name = ze.name - if (name == null) - continue - val dest = if (installDir is SuFile) - SuFile(installDir, name) - else - File(installDir, name) - dest.parentFile!!.mkdirs() - SuFileOutputStream(dest).use { zi.copyTo(it) } + name?.also { + val dest = if (installDir is SuFile) + SuFile(installDir, it) + else + File(installDir, it) + dest.parentFile!!.mkdirs() + SuFileOutputStream(dest).use { s -> zi.copyTo(s) } + } ?: continue } } } catch (e: IOException) { diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/SuLogDao.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/SuLogDao.kt index b35ce4951..e86b48c87 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/SuLogDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/SuLogDao.kt @@ -1,12 +1,12 @@ package com.topjohnwu.magisk.data.database import androidx.room.* -import com.topjohnwu.magisk.model.entity.MagiskLog +import com.topjohnwu.magisk.core.model.su.SuLog import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.util.* -@Database(version = 1, entities = [MagiskLog::class], exportSchema = false) +@Database(version = 1, entities = [SuLog::class], exportSchema = false) abstract class SuLogDatabase : RoomDatabase() { abstract fun suLogDao(): SuLogDao @@ -20,18 +20,18 @@ abstract class SuLogDao(private val db: SuLogDatabase) { suspend fun deleteAll() = withContext(Dispatchers.IO) { db.clearAllTables() } - suspend fun fetchAll(): MutableList { + suspend fun fetchAll(): MutableList { deleteOutdated() return fetch() } @Query("SELECT * FROM logs ORDER BY time DESC") - protected abstract suspend fun fetch(): MutableList + protected abstract suspend fun fetch(): MutableList @Query("DELETE FROM logs WHERE time < :timeout") protected abstract suspend fun deleteOutdated(timeout: Long = twoWeeksAgo) @Insert - abstract suspend fun insert(log: MagiskLog) + abstract suspend fun insert(log: SuLog) } diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt index 58604dcb2..765e625cd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt @@ -1,9 +1,9 @@ package com.topjohnwu.magisk.data.repository import com.topjohnwu.magisk.core.Const +import com.topjohnwu.magisk.core.model.su.SuLog import com.topjohnwu.magisk.data.database.SuLogDao import com.topjohnwu.magisk.ktx.await -import com.topjohnwu.magisk.model.entity.MagiskLog import com.topjohnwu.superuser.Shell @@ -36,6 +36,6 @@ class LogRepository( fun clearMagiskLogs(cb: (Shell.Result) -> Unit) = Shell.su("echo -n > ${Const.MAGISK_LOG}").submit(cb) - suspend fun insert(log: MagiskLog) = logDao.insert(log) + suspend fun insert(log: SuLog) = logDao.insert(log) } diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt index ff43c09a9..7812a753c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt @@ -7,8 +7,8 @@ import com.topjohnwu.magisk.data.network.GithubRawServices import com.topjohnwu.magisk.ktx.await import com.topjohnwu.magisk.ktx.getLabel import com.topjohnwu.magisk.ktx.packageName -import com.topjohnwu.magisk.model.entity.HideAppInfo -import com.topjohnwu.magisk.model.entity.HideTarget +import com.topjohnwu.magisk.ui.hide.HideAppInfo +import com.topjohnwu.magisk.ui.hide.HideTarget import com.topjohnwu.superuser.Shell import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext diff --git a/app/src/main/java/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt b/app/src/main/java/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt index 3afc8af42..4ae6d3c61 100644 --- a/app/src/main/java/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt +++ b/app/src/main/java/com/topjohnwu/magisk/databinding/RecyclerViewItems.kt @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.databinding import androidx.annotation.CallSuper import androidx.databinding.PropertyChangeRegistry import androidx.databinding.ViewDataBinding +import androidx.recyclerview.widget.RecyclerView import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.utils.DiffObservableList import com.topjohnwu.magisk.utils.ObservableHost @@ -52,3 +53,13 @@ abstract class ComparableRvItem : RvItem() { abstract class ObservableItem : ComparableRvItem(), ObservableHost { override var callbacks: PropertyChangeRegistry? = null } + +/** + * This item addresses issues where enclosing recycler has to be invalidated or generally + * manipulated with. This shouldn't be however necessary for 99.9% of use-cases. Refrain from using + * this item as it provides virtually no additional functionality. Stick with ComparableRvItem. + * */ + +interface LenientRvItem { + fun onBindingBound(binding: ViewDataBinding, recyclerView: RecyclerView) +} diff --git a/app/src/main/java/com/topjohnwu/magisk/databinding/RvBindingAdapter.kt b/app/src/main/java/com/topjohnwu/magisk/databinding/RvBindingAdapter.kt index b482273e4..8b3975721 100644 --- a/app/src/main/java/com/topjohnwu/magisk/databinding/RvBindingAdapter.kt +++ b/app/src/main/java/com/topjohnwu/magisk/databinding/RvBindingAdapter.kt @@ -2,7 +2,6 @@ package com.topjohnwu.magisk.databinding import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.RecyclerView -import com.topjohnwu.magisk.model.entity.recycler.LenientRvItem import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter class RvBindingAdapter : BindingRecyclerViewAdapter() { @@ -19,7 +18,7 @@ class RvBindingAdapter : BindingRecyclerViewAdapter() { super.onBindBinding(binding, variableId, layoutRes, position, item) when (item) { - is LenientRvItem<*> -> { + is LenientRvItem -> { val recycler = recyclerView ?: return item.onBindingBound(binding) item.onBindingBound(binding, recycler) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/InstallExternalModuleEvent.kt b/app/src/main/java/com/topjohnwu/magisk/events/InstallExternalModuleEvent.kt similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/model/events/InstallExternalModuleEvent.kt rename to app/src/main/java/com/topjohnwu/magisk/events/InstallExternalModuleEvent.kt index a5fb5d58d..b23c44305 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/InstallExternalModuleEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/InstallExternalModuleEvent.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events +package com.topjohnwu.magisk.events import android.Manifest import android.app.Activity diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/OpenInappLinkEvent.kt b/app/src/main/java/com/topjohnwu/magisk/events/OpenInappLinkEvent.kt similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/model/events/OpenInappLinkEvent.kt rename to app/src/main/java/com/topjohnwu/magisk/events/OpenInappLinkEvent.kt index dcf8c3c32..ae9be3669 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/OpenInappLinkEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/OpenInappLinkEvent.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events +package com.topjohnwu.magisk.events import android.content.Context import android.content.res.Resources diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/RebootEvent.kt b/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/model/events/RebootEvent.kt rename to app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt index b64dfa23f..5f64e9015 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/RebootEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events +package com.topjohnwu.magisk.events import android.view.ContextThemeWrapper import android.view.MenuItem diff --git a/app/src/main/java/com/topjohnwu/magisk/events/SnackbarEvent.kt b/app/src/main/java/com/topjohnwu/magisk/events/SnackbarEvent.kt new file mode 100644 index 000000000..56e50550c --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/events/SnackbarEvent.kt @@ -0,0 +1,46 @@ +package com.topjohnwu.magisk.events + +import android.view.View +import androidx.annotation.StringRes +import com.google.android.material.snackbar.Snackbar +import com.topjohnwu.magisk.arch.ActivityExecutor +import com.topjohnwu.magisk.arch.BaseUIActivity +import com.topjohnwu.magisk.arch.ViewEvent +import com.topjohnwu.magisk.core.base.BaseActivity +import com.topjohnwu.magisk.utils.TransitiveText + +class SnackbarEvent private constructor( + private val msg: TransitiveText, + private val length: Int, + private val builder: Snackbar.() -> Unit +) : ViewEvent(), ActivityExecutor { + + constructor( + @StringRes res: Int, + length: Int = Snackbar.LENGTH_SHORT, + builder: Snackbar.() -> Unit = {} + ) : this(TransitiveText.Res(res), length, builder) + + constructor( + message: String, + length: Int = Snackbar.LENGTH_SHORT, + builder: Snackbar.() -> Unit = {} + ) : this(TransitiveText.String(message), length, builder) + + + private fun snackbar( + view: View, + message: String, + length: Int = Snackbar.LENGTH_SHORT, + builder: Snackbar.() -> Unit = {} + ) = Snackbar.make(view, message, length).apply(builder).show() + + override fun invoke(activity: BaseActivity) { + if (activity is BaseUIActivity<*, *>) { + snackbar(activity.snackbarView, + msg.getText(activity.resources).toString(), + length, builder) + } + } + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt b/app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt new file mode 100644 index 000000000..d0f0bc20e --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt @@ -0,0 +1,76 @@ +package com.topjohnwu.magisk.events + +import android.app.Activity +import android.content.Context +import android.content.Intent +import com.topjohnwu.magisk.arch.ActivityExecutor +import com.topjohnwu.magisk.arch.ContextExecutor +import com.topjohnwu.magisk.arch.ViewEvent +import com.topjohnwu.magisk.arch.ViewEventWithScope +import com.topjohnwu.magisk.core.base.BaseActivity +import com.topjohnwu.magisk.core.model.module.Repo +import com.topjohnwu.magisk.view.MarkDownWindow +import kotlinx.coroutines.launch + +class ViewActionEvent(val action: BaseActivity.() -> Unit) : ViewEvent(), ActivityExecutor { + override fun invoke(activity: BaseActivity) = action(activity) +} + +class OpenChangelogEvent(val item: Repo) : ViewEventWithScope(), ContextExecutor { + override fun invoke(context: Context) { + scope.launch { + MarkDownWindow.show(context, null, item::readme) + } + } +} + +class PermissionEvent( + private val permissions: List, + private val callback: (Boolean) -> Unit +) : ViewEvent(), ActivityExecutor { + + override fun invoke(activity: BaseActivity) = + activity.withPermissions(*permissions.toTypedArray()) { + onSuccess { + callback(true) + } + onFailure { + callback(false) + } + } +} + +class BackPressEvent : ViewEvent(), ActivityExecutor { + override fun invoke(activity: BaseActivity) { + activity.onBackPressed() + } +} + +class DieEvent : ViewEvent(), ActivityExecutor { + override fun invoke(activity: BaseActivity) { + activity.finish() + } +} + +class RecreateEvent : ViewEvent(), ActivityExecutor { + override fun invoke(activity: BaseActivity) { + activity.recreate() + } +} + +class RequestFileEvent : ViewEvent(), ActivityExecutor { + override fun invoke(activity: BaseActivity) { + Intent(Intent.ACTION_GET_CONTENT) + .setType("*/*") + .addCategory(Intent.CATEGORY_OPENABLE) + .also { activity.startActivityForResult(it, REQUEST_CODE) } + } + + companion object { + private const val REQUEST_CODE = 10 + fun resolve(requestCode: Int, resultCode: Int, data: Intent?) = data + ?.takeIf { resultCode == Activity.RESULT_OK } + ?.takeIf { requestCode == REQUEST_CODE } + ?.data + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/BiometricDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricDialog.kt similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/BiometricDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricDialog.kt index 82b69df69..31345f64d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/BiometricDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricDialog.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import com.topjohnwu.magisk.arch.ActivityExecutor import com.topjohnwu.magisk.arch.ViewEvent diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DarkThemeDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/DarkThemeDialog.kt similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DarkThemeDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/DarkThemeDialog.kt index 0698d34c9..c9ac4e650 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DarkThemeDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/DarkThemeDialog.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import android.app.Activity import androidx.appcompat.app.AppCompatDelegate diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DialogEvent.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/DialogEvent.kt similarity index 90% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DialogEvent.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/DialogEvent.kt index 995e30c82..104830708 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/DialogEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/DialogEvent.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import android.content.Context import com.topjohnwu.magisk.arch.ContextExecutor diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/EnvFixDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/EnvFixDialog.kt similarity index 89% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/EnvFixDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/EnvFixDialog.kt index b9a134d33..eb94999b7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/EnvFixDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/EnvFixDialog.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import android.content.BroadcastReceiver import android.content.Context @@ -7,8 +7,8 @@ import android.content.IntentFilter import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.download.DownloadService -import com.topjohnwu.magisk.model.entity.internal.Configuration.EnvFix -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk +import com.topjohnwu.magisk.model.internal.Configuration.EnvFix +import com.topjohnwu.magisk.model.internal.DownloadSubject.Magisk import com.topjohnwu.magisk.view.MagiskDialog class EnvFixDialog : DialogEvent() { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ManagerInstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/ManagerInstallDialog.kt similarity index 88% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ManagerInstallDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/ManagerInstallDialog.kt index 9c8e62660..70b0f4837 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ManagerInstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/ManagerInstallDialog.kt @@ -1,11 +1,11 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.ktx.res -import com.topjohnwu.magisk.model.entity.internal.Configuration -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject +import com.topjohnwu.magisk.model.internal.Configuration +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MarkDownWindow import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ModuleInstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/ModuleInstallDialog.kt similarity index 87% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ModuleInstallDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/ModuleInstallDialog.kt index f27499251..f1a768b2e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ModuleInstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/ModuleInstallDialog.kt @@ -1,10 +1,10 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.model.module.Repo -import com.topjohnwu.magisk.model.entity.internal.Configuration -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject +import com.topjohnwu.magisk.model.internal.Configuration +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.magisk.view.MagiskDialog class ModuleInstallDialog(private val item: Repo) : DialogEvent() { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/SecondSlotWarningDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/SecondSlotWarningDialog.kt similarity index 90% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/SecondSlotWarningDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/SecondSlotWarningDialog.kt index 150afa28a..86874b3d3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/SecondSlotWarningDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/SecondSlotWarningDialog.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import com.topjohnwu.magisk.R import com.topjohnwu.magisk.view.MagiskDialog diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/SuperuserRevokeDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/SuperuserRevokeDialog.kt similarity index 94% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/SuperuserRevokeDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/SuperuserRevokeDialog.kt index 39e24d36a..d697aa627 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/SuperuserRevokeDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/SuperuserRevokeDialog.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import com.topjohnwu.magisk.R import com.topjohnwu.magisk.view.MagiskDialog @@ -30,4 +30,4 @@ class SuperuserRevokeDialog( listenerOnSuccess = listener } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/UninstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt similarity index 90% rename from app/src/main/java/com/topjohnwu/magisk/model/events/dialog/UninstallDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt index f1400cda4..4a2522086 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/UninstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt @@ -1,11 +1,11 @@ -package com.topjohnwu.magisk.model.events.dialog +package com.topjohnwu.magisk.events.dialog import android.widget.Toast import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.DownloadService -import com.topjohnwu.magisk.model.entity.internal.Configuration -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject +import com.topjohnwu.magisk.model.internal.Configuration +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.superuser.Shell diff --git a/app/src/main/java/com/topjohnwu/magisk/ktx/Snackbar.kt b/app/src/main/java/com/topjohnwu/magisk/ktx/Snackbar.kt deleted file mode 100644 index 150c537c4..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ktx/Snackbar.kt +++ /dev/null @@ -1,126 +0,0 @@ -package com.topjohnwu.magisk.ktx - -import android.content.Context -import android.content.res.ColorStateList -import android.view.View -import android.widget.TextView -import androidx.annotation.ColorInt -import androidx.annotation.ColorRes -import androidx.annotation.StringRes -import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.ContextCompat -import androidx.core.view.ViewCompat -import androidx.fragment.app.Fragment -import com.google.android.material.snackbar.Snackbar - -fun AppCompatActivity.snackbar( - view: View, - @StringRes messageRes: Int, - length: Int = Snackbar.LENGTH_SHORT, - f: Snackbar.() -> Unit = {} -) { - snackbar(view, getString(messageRes), length, f) -} - -fun AppCompatActivity.snackbar( - view: View, - message: String, - length: Int = Snackbar.LENGTH_SHORT, - f: Snackbar.() -> Unit = {} -) = Snackbar.make(view, message, length) - .apply(f) - .show() - -fun Fragment.snackbar( - view: View, - @StringRes messageRes: Int, - length: Int = Snackbar.LENGTH_SHORT, - f: Snackbar.() -> Unit = {} -) { - snackbar(view, getString(messageRes), length, f) -} - -fun Fragment.snackbar( - view: View, - message: String, - length: Int = Snackbar.LENGTH_SHORT, - f: Snackbar.() -> Unit = {} -) = Snackbar.make(view, message, length) - .apply(f) - .show() - -fun Snackbar.action(init: KSnackbar.() -> Unit) = apply { - val config = KSnackbar().apply(init) - - setAction(config.title(context), config.onClickListener) - - when { - config.hasValidColor -> setActionTextColor(config.color(context) ?: return@apply) - config.hasValidColorStateList -> setActionTextColor(config.colorStateList(context) ?: return@apply) - } -} - -class KSnackbar { - var colorRes: Int = -1 - var colorStateListRes: Int = -1 - - var title: CharSequence = "" - var titleRes: Int = -1 - - internal var onClickListener: (View) -> Unit = {} - internal val hasValidColor get() = colorRes != -1 - internal val hasValidColorStateList get() = colorStateListRes != -1 - - fun onClicked(listener: (View) -> Unit) { - onClickListener = listener - } - - internal fun title(context: Context) = if (title.isBlank()) context.getString(titleRes) else title - internal fun colorStateList(context: Context) = context.colorStateListCompat(colorStateListRes) - internal fun color(context: Context) = context.colorCompat(colorRes) -} - -@Deprecated("Kotlin DSL version is preferred", ReplaceWith("action {}")) -fun Snackbar.action( - @StringRes actionRes: Int, - @ColorRes colorRes: Int? = null, - listener: (View) -> Unit -) { - view.resources.getString(actionRes) - colorRes?.let { ContextCompat.getColor(view.context, colorRes) } - action {} -} - -@Deprecated("Kotlin DSL version is preferred", ReplaceWith("action {}")) -fun Snackbar.action(action: String, @ColorInt color: Int? = null, listener: (View) -> Unit) { - setAction(action, listener) - color?.let { setActionTextColor(color) } -} - -fun Snackbar.textColorRes(@ColorRes colorRes: Int) { - textColor(context.colorCompat(colorRes) ?: return) -} - -fun Snackbar.textColor(@ColorInt color: Int) { - val tv = view.findViewById(com.google.android.material.R.id.snackbar_text) - tv.setTextColor(color) -} - -fun Snackbar.backgroundColorRes(@ColorRes colorRes: Int) { - backgroundColor(context.colorCompat(colorRes) ?: return) -} - -fun Snackbar.backgroundColor(@ColorInt color: Int) { - ViewCompat.setBackgroundTintList( - view, - ColorStateList.valueOf(color) - ) -} - -fun Snackbar.alert() { - textColor(0xF44336) -} - -fun Snackbar.success() { - textColor(0x4CAF50) -} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LenientRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LenientRvItem.kt deleted file mode 100644 index f21df6b91..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LenientRvItem.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.topjohnwu.magisk.model.entity.recycler - -import androidx.databinding.ViewDataBinding -import androidx.recyclerview.widget.RecyclerView -import com.topjohnwu.magisk.databinding.ComparableRvItem - -/** - * This item addresses issues where enclosing recycler has to be invalidated or generally - * manipulated with. This shouldn't be however necessary for 99.9% of use-cases. Refrain from using - * this item as it provides virtually no additional functionality. Stick with ComparableRvItem. - * */ -abstract class LenientRvItem : ComparableRvItem() { - - open fun onBindingBound(binding: ViewDataBinding, recyclerView: RecyclerView) {} - -} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ThemeItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ThemeItem.kt deleted file mode 100644 index 4997269e7..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ThemeItem.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.topjohnwu.magisk.model.entity.recycler - -import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.databinding.ComparableRvItem -import com.topjohnwu.magisk.ui.theme.Theme - -class ThemeItem(val theme: Theme) : ComparableRvItem() { - - override val layoutRes = R.layout.item_theme - - override fun contentSameAs(other: ThemeItem) = itemSameAs(other) - override fun itemSameAs(other: ThemeItem) = theme == other.theme - -} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/state/IndeterminateState.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/state/IndeterminateState.kt deleted file mode 100644 index 43b97f12d..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/state/IndeterminateState.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.topjohnwu.magisk.model.entity.state - -enum class IndeterminateState { - CHECKED, INDETERMINATE, UNCHECKED -} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/SnackbarEvent.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/SnackbarEvent.kt deleted file mode 100644 index ad5678299..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/SnackbarEvent.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.topjohnwu.magisk.model.events - -import android.content.Context -import androidx.annotation.StringRes -import com.google.android.material.snackbar.Snackbar -import com.topjohnwu.magisk.arch.ActivityExecutor -import com.topjohnwu.magisk.arch.BaseUIActivity -import com.topjohnwu.magisk.arch.ViewEvent -import com.topjohnwu.magisk.core.base.BaseActivity -import com.topjohnwu.magisk.ktx.snackbar - -class SnackbarEvent private constructor( - @StringRes private val messageRes: Int, - private val messageString: String?, - val length: Int, - val f: Snackbar.() -> Unit -) : ViewEvent(), ActivityExecutor { - - constructor( - @StringRes messageRes: Int, - length: Int = Snackbar.LENGTH_SHORT, - f: Snackbar.() -> Unit = {} - ) : this(messageRes, null, length, f) - - constructor( - message: String, - length: Int = Snackbar.LENGTH_SHORT, - f: Snackbar.() -> Unit = {} - ) : this(-1, message, length, f) - - fun message(context: Context): String = messageString ?: context.getString(messageRes) - - override fun invoke(activity: BaseActivity) { - if (activity is BaseUIActivity<*, *>) { - activity.snackbar(activity.snackbarView, message(activity), length, f) - } - } - -} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/Configuration.kt b/app/src/main/java/com/topjohnwu/magisk/model/internal/Configuration.kt similarity index 93% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/internal/Configuration.kt rename to app/src/main/java/com/topjohnwu/magisk/model/internal/Configuration.kt index 1ea2c0df6..f3bf49eed 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/Configuration.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/internal/Configuration.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.internal +package com.topjohnwu.magisk.model.internal import android.net.Uri import android.os.Parcelable diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt b/app/src/main/java/com/topjohnwu/magisk/model/internal/DownloadSubject.kt similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt rename to app/src/main/java/com/topjohnwu/magisk/model/internal/DownloadSubject.kt index df7091923..07f088cef 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/internal/DownloadSubject.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.internal +package com.topjohnwu.magisk.model.internal import android.content.Context import android.os.Parcelable diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ConsoleItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/ConsoleItem.kt similarity index 81% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ConsoleItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/flash/ConsoleItem.kt index 3430dab43..a0a9cffcb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ConsoleItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/ConsoleItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.ui.flash import android.view.View import android.widget.TextView @@ -6,9 +6,11 @@ import androidx.core.view.updateLayoutParams import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.RecyclerView import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.databinding.ComparableRvItem +import com.topjohnwu.magisk.databinding.LenientRvItem import kotlin.math.max -class ConsoleItem(val item: String) : LenientRvItem() { +class ConsoleItem(val item: String) : ComparableRvItem(), LenientRvItem { override val layoutRes = R.layout.item_console_md2 private var parentWidth = -1 diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt index 29989f7c5..1f64e6f9b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt @@ -15,9 +15,8 @@ import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.tasks.FlashZip import com.topjohnwu.magisk.core.tasks.MagiskInstaller import com.topjohnwu.magisk.databinding.RvBindingAdapter +import com.topjohnwu.magisk.events.SnackbarEvent import com.topjohnwu.magisk.ktx.* -import com.topjohnwu.magisk.model.entity.recycler.ConsoleItem -import com.topjohnwu.magisk.model.events.SnackbarEvent import com.topjohnwu.magisk.utils.set import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.superuser.CallbackList diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/HideAppInfo.kt b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideAppInfo.kt similarity index 93% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/HideAppInfo.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/hide/HideAppInfo.kt index 6ecbb70f3..425f62900 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/HideAppInfo.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideAppInfo.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity +package com.topjohnwu.magisk.ui.hide import android.content.pm.ApplicationInfo import android.graphics.drawable.Drawable diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideRvItem.kt similarity index 92% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/hide/HideRvItem.kt index a1402405f..3b99406b7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideRvItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.ui.hide import android.view.View import android.view.ViewGroup @@ -7,9 +7,6 @@ import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ObservableItem import com.topjohnwu.magisk.ktx.startAnimations -import com.topjohnwu.magisk.model.entity.HideAppTarget -import com.topjohnwu.magisk.model.entity.StatefulProcess -import com.topjohnwu.magisk.ui.hide.HideViewModel import com.topjohnwu.magisk.utils.addOnPropertyChangedCallback import com.topjohnwu.magisk.utils.set import kotlin.math.roundToInt diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/HideTarget.kt b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideTarget.kt similarity index 85% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/HideTarget.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/hide/HideTarget.kt index bd8f1425f..12309b9f0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/HideTarget.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideTarget.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity +package com.topjohnwu.magisk.ui.hide class HideTarget(line: String) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt index 7f106c4d8..e0d78337b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt @@ -11,12 +11,6 @@ import com.topjohnwu.magisk.arch.itemBindingOf import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.utils.currentLocale import com.topjohnwu.magisk.data.repository.MagiskRepository -import com.topjohnwu.magisk.model.entity.HideAppInfo -import com.topjohnwu.magisk.model.entity.HideAppTarget -import com.topjohnwu.magisk.model.entity.HideTarget -import com.topjohnwu.magisk.model.entity.StatefulProcess -import com.topjohnwu.magisk.model.entity.recycler.HideItem -import com.topjohnwu.magisk.model.entity.recycler.HideProcessItem import com.topjohnwu.magisk.utils.set import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/DeveloperItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/DeveloperItem.kt similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/DeveloperItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/home/DeveloperItem.kt index 3046fd7b4..de64542e6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/DeveloperItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/DeveloperItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity +package com.topjohnwu.magisk.ui.home import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Const diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt index acd648492..4cf6c3177 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt @@ -5,7 +5,7 @@ import android.view.* import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.BaseUIFragment import com.topjohnwu.magisk.databinding.FragmentHomeMd2Binding -import com.topjohnwu.magisk.model.events.RebootEvent +import com.topjohnwu.magisk.events.RebootEvent import com.topjohnwu.superuser.Shell import org.koin.androidx.viewmodel.ext.android.viewModel diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index f7d75ecb4..8a384be90 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -16,15 +16,14 @@ import com.topjohnwu.magisk.core.download.RemoteFileService import com.topjohnwu.magisk.core.model.MagiskJson import com.topjohnwu.magisk.core.model.ManagerJson import com.topjohnwu.magisk.data.repository.MagiskRepository +import com.topjohnwu.magisk.events.OpenInappLinkEvent +import com.topjohnwu.magisk.events.dialog.EnvFixDialog +import com.topjohnwu.magisk.events.dialog.ManagerInstallDialog +import com.topjohnwu.magisk.events.dialog.UninstallDialog import com.topjohnwu.magisk.ktx.await import com.topjohnwu.magisk.ktx.packageName import com.topjohnwu.magisk.ktx.res -import com.topjohnwu.magisk.model.entity.IconLink -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Manager -import com.topjohnwu.magisk.model.events.OpenInappLinkEvent -import com.topjohnwu.magisk.model.events.dialog.EnvFixDialog -import com.topjohnwu.magisk.model.events.dialog.ManagerInstallDialog -import com.topjohnwu.magisk.model.events.dialog.UninstallDialog +import com.topjohnwu.magisk.model.internal.DownloadSubject.Manager import com.topjohnwu.magisk.utils.set import com.topjohnwu.superuser.Shell import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt index f2f9af9a1..6ecf97ca7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.viewModelScope import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.BaseUIFragment import com.topjohnwu.magisk.databinding.FragmentInstallMd2Binding -import com.topjohnwu.magisk.model.events.RequestFileEvent +import com.topjohnwu.magisk.events.RequestFileEvent import org.koin.androidx.viewmodel.ext.android.viewModel class InstallFragment : BaseUIFragment() { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt index c3b5a51d4..5f0d77ac4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt @@ -11,10 +11,10 @@ import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.download.RemoteFileService import com.topjohnwu.magisk.data.repository.StringRepository -import com.topjohnwu.magisk.model.entity.internal.Configuration -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject -import com.topjohnwu.magisk.model.events.RequestFileEvent -import com.topjohnwu.magisk.model.events.dialog.SecondSlotWarningDialog +import com.topjohnwu.magisk.events.RequestFileEvent +import com.topjohnwu.magisk.events.dialog.SecondSlotWarningDialog +import com.topjohnwu.magisk.model.internal.Configuration +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.set import com.topjohnwu.superuser.Shell diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LogRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogRvItem.kt similarity index 74% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LogRvItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/log/LogRvItem.kt index 270072aa6..30d356174 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LogRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogRvItem.kt @@ -1,15 +1,15 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.ui.log import androidx.databinding.Bindable import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.core.model.su.SuLog import com.topjohnwu.magisk.databinding.ObservableItem import com.topjohnwu.magisk.ktx.timeDateFormat import com.topjohnwu.magisk.ktx.toTime -import com.topjohnwu.magisk.model.entity.MagiskLog import com.topjohnwu.magisk.utils.set -class LogItem(val item: MagiskLog) : ObservableItem() { +class LogRvItem(val item: SuLog) : ObservableItem() { override val layoutRes = R.layout.item_log_access_md2 @@ -23,9 +23,9 @@ class LogItem(val item: MagiskLog) : ObservableItem() { var isBottom = false set(value) = set(value, field, { field = it }, BR.bottom) - override fun itemSameAs(other: LogItem) = item.appName == other.item.appName + override fun itemSameAs(other: LogRvItem) = item.appName == other.item.appName - override fun contentSameAs(other: LogItem) = item.fromUid == other.item.fromUid && + override fun contentSameAs(other: LogRvItem) = item.fromUid == other.item.fromUid && item.toUid == other.item.toUid && item.fromPid == other.item.fromPid && item.packageName == other.item.packageName && diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt index fae9cf8c2..ed8b89f6b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt @@ -10,10 +10,9 @@ import com.topjohnwu.magisk.arch.itemBindingOf import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.data.repository.LogRepository -import com.topjohnwu.magisk.model.entity.recycler.LogItem -import com.topjohnwu.magisk.model.entity.recycler.TextItem -import com.topjohnwu.magisk.model.events.SnackbarEvent +import com.topjohnwu.magisk.events.SnackbarEvent import com.topjohnwu.magisk.utils.set +import com.topjohnwu.magisk.view.TextItem import com.topjohnwu.superuser.Shell import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -34,8 +33,8 @@ class LogViewModel( // --- su log - val items = diffListOf() - val itemBinding = itemBindingOf { + val items = diffListOf() + val itemBinding = itemBindingOf { it.bindExtra(BR.viewModel, this) } @@ -47,7 +46,7 @@ class LogViewModel( override fun refresh() = viewModelScope.launch { consoleText = repo.fetchMagiskLogs() val (suLogs, diff) = withContext(Dispatchers.Default) { - val suLogs = repo.fetchSuLogs().map { LogItem(it) } + val suLogs = repo.fetchSuLogs().map { LogRvItem(it) } suLogs to items.calculateDiff(suLogs) } items.firstOrNull()?.isTop = false diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt index 6bb5488d3..0bbae71bf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt @@ -13,8 +13,8 @@ import com.topjohnwu.magisk.arch.BaseUIFragment import com.topjohnwu.magisk.arch.ReselectionTarget import com.topjohnwu.magisk.arch.ViewEvent import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding +import com.topjohnwu.magisk.events.InstallExternalModuleEvent import com.topjohnwu.magisk.ktx.hideKeyboard -import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent import com.topjohnwu.magisk.ui.MainActivity import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener import com.topjohnwu.magisk.utils.MotionRevealHelper diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt index c1c3460fc..abe56c415 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.ui.module import androidx.databinding.Bindable import com.topjohnwu.magisk.BR @@ -7,7 +7,6 @@ import com.topjohnwu.magisk.core.model.module.Module import com.topjohnwu.magisk.core.model.module.Repo import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.databinding.ObservableItem -import com.topjohnwu.magisk.ui.module.ModuleViewModel import com.topjohnwu.magisk.utils.set object InstallModule : ComparableRvItem() { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index c95812290..adbbd8572 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -14,16 +14,12 @@ import com.topjohnwu.magisk.core.tasks.RepoUpdater import com.topjohnwu.magisk.data.database.RepoByNameDao import com.topjohnwu.magisk.data.database.RepoByUpdatedDao import com.topjohnwu.magisk.databinding.RvItem +import com.topjohnwu.magisk.events.InstallExternalModuleEvent +import com.topjohnwu.magisk.events.OpenChangelogEvent +import com.topjohnwu.magisk.events.dialog.ModuleInstallDialog import com.topjohnwu.magisk.ktx.addOnListChangedCallback import com.topjohnwu.magisk.ktx.reboot -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject -import com.topjohnwu.magisk.model.entity.recycler.InstallModule -import com.topjohnwu.magisk.model.entity.recycler.ModuleItem -import com.topjohnwu.magisk.model.entity.recycler.RepoItem -import com.topjohnwu.magisk.model.entity.recycler.SectionTitle -import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent -import com.topjohnwu.magisk.model.events.OpenChangelogEvent -import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener import com.topjohnwu.magisk.utils.set import kotlinx.coroutines.Dispatchers diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt similarity index 63% rename from app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt index 82cc44054..a283b62ad 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/CheckSafetyNetEvent.kt @@ -1,23 +1,14 @@ -package com.topjohnwu.magisk.model.events +package com.topjohnwu.magisk.ui.safetynet -import android.app.Activity import android.content.Context -import android.content.Intent import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.arch.ActivityExecutor import com.topjohnwu.magisk.arch.ContextExecutor -import com.topjohnwu.magisk.arch.ViewEvent import com.topjohnwu.magisk.arch.ViewEventWithScope import com.topjohnwu.magisk.core.Const -import com.topjohnwu.magisk.core.base.BaseActivity -import com.topjohnwu.magisk.core.model.module.Repo -import com.topjohnwu.magisk.core.utils.SafetyNetHelper import com.topjohnwu.magisk.data.network.GithubRawServices import com.topjohnwu.magisk.ktx.DynamicClassLoader import com.topjohnwu.magisk.ktx.writeTo -import com.topjohnwu.magisk.ui.safetynet.SafetyNetResult import com.topjohnwu.magisk.view.MagiskDialog -import com.topjohnwu.magisk.view.MarkDownWindow import com.topjohnwu.superuser.Shell import dalvik.system.DexFile import kotlinx.coroutines.CancellationException @@ -32,6 +23,7 @@ import java.io.File import java.io.IOException import java.lang.reflect.InvocationHandler +@Suppress("DEPRECATION") class CheckSafetyNetEvent( private val callback: (SafetyNetResult) -> Unit = {} ) : ViewEventWithScope(), ContextExecutor, KoinComponent, SafetyNetHelper.Callback { @@ -78,8 +70,10 @@ class CheckSafetyNetEvent( val helper = helperClass .getMethod("get", Class::class.java, Context::class.java, Any::class.java) - .invoke(null, SafetyNetHelper::class.java, - context, this@CheckSafetyNetEvent) as SafetyNetHelper + .invoke( + null, SafetyNetHelper::class.java, + context, this@CheckSafetyNetEvent + ) as SafetyNetHelper if (helper.version < Const.SNET_EXT_VER) throw Exception() @@ -136,66 +130,3 @@ class CheckSafetyNetEvent( callback(SafetyNetResult(response)) } } - -class ViewActionEvent(val action: BaseActivity.() -> Unit) : ViewEvent(), ActivityExecutor { - override fun invoke(activity: BaseActivity) = action(activity) -} - -class OpenChangelogEvent(val item: Repo) : ViewEventWithScope(), ContextExecutor { - override fun invoke(context: Context) { - scope.launch { - MarkDownWindow.show(context, null, item::readme) - } - } -} - -class PermissionEvent( - private val permissions: List, - private val callback: (Boolean) -> Unit -) : ViewEvent(), ActivityExecutor { - - override fun invoke(activity: BaseActivity) = - activity.withPermissions(*permissions.toTypedArray()) { - onSuccess { - callback(true) - } - onFailure { - callback(false) - } - } -} - -class BackPressEvent : ViewEvent(), ActivityExecutor { - override fun invoke(activity: BaseActivity) { - activity.onBackPressed() - } -} - -class DieEvent : ViewEvent(), ActivityExecutor { - override fun invoke(activity: BaseActivity) { - activity.finish() - } -} - -class RecreateEvent : ViewEvent(), ActivityExecutor { - override fun invoke(activity: BaseActivity) { - activity.recreate() - } -} - -class RequestFileEvent : ViewEvent(), ActivityExecutor { - override fun invoke(activity: BaseActivity) { - Intent(Intent.ACTION_GET_CONTENT) - .setType("*/*") - .addCategory(Intent.CATEGORY_OPENABLE) - .also { activity.startActivityForResult(it, REQUEST_CODE) } - } - - companion object { - private const val REQUEST_CODE = 10 - fun resolve(requestCode: Int, resultCode: Int, data: Intent?) = data - ?.takeIf { resultCode == Activity.RESULT_OK } - ?.takeIf { requestCode == REQUEST_CODE } - ?.data - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/SafetyNetHelper.kt b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetyNetHelper.kt similarity index 80% rename from app/src/main/java/com/topjohnwu/magisk/core/utils/SafetyNetHelper.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetyNetHelper.kt index 59e2a014d..50bed6032 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/SafetyNetHelper.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetyNetHelper.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.core.utils +package com.topjohnwu.magisk.ui.safetynet import org.json.JSONObject diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt index 795b33368..c40fbab90 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt @@ -4,7 +4,6 @@ import androidx.databinding.Bindable import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.BaseViewModel -import com.topjohnwu.magisk.model.events.CheckSafetyNetEvent import com.topjohnwu.magisk.ui.safetynet.SafetyNetState.* import com.topjohnwu.magisk.utils.set import org.json.JSONObject @@ -54,7 +53,7 @@ class SafetynetViewModel : BaseViewModel() { private fun attest() { currentState = LOADING - CheckSafetyNetEvent() { + CheckSafetyNetEvent { resolveResponse(it) }.publish() } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/SettingsItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/BaseSettingsItem.kt similarity index 90% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/SettingsItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/settings/BaseSettingsItem.kt index 1ed2d4269..1f4907e71 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/SettingsItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/BaseSettingsItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.ui.settings import android.content.Context import android.content.res.Resources @@ -16,7 +16,7 @@ import com.topjohnwu.magisk.view.MagiskDialog import org.koin.core.KoinComponent import org.koin.core.get -sealed class SettingsItem : ObservableItem() { +sealed class BaseSettingsItem : ObservableItem() { override val layoutRes get() = R.layout.item_settings @@ -46,19 +46,19 @@ sealed class SettingsItem : ObservableItem() { open fun refresh() {} - override fun itemSameAs(other: SettingsItem) = this === other - override fun contentSameAs(other: SettingsItem) = itemSameAs(other) + override fun itemSameAs(other: BaseSettingsItem) = this === other + override fun contentSameAs(other: BaseSettingsItem) = itemSameAs(other) // --- interface Callback { - fun onItemPressed(view: View, item: SettingsItem, callback: () -> Unit = {}) - fun onItemChanged(view: View, item: SettingsItem) + fun onItemPressed(view: View, item: BaseSettingsItem, callback: () -> Unit = {}) + fun onItemChanged(view: View, item: BaseSettingsItem) } // --- - abstract class Value : SettingsItem() { + abstract class Value : BaseSettingsItem() { /** * Represents last agreed-upon value by the validation process and the user for current @@ -176,9 +176,9 @@ sealed class SettingsItem : ObservableItem() { } - abstract class Blank : SettingsItem() + abstract class Blank : BaseSettingsItem() - abstract class Section : SettingsItem() { + abstract class Section : BaseSettingsItem() { override val layoutRes = R.layout.item_settings_section } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt index 485e7ef1e..f90be7083 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt @@ -19,7 +19,6 @@ import com.topjohnwu.magisk.databinding.DialogSettingsAppNameBinding import com.topjohnwu.magisk.databinding.DialogSettingsDownloadPathBinding import com.topjohnwu.magisk.databinding.DialogSettingsUpdateChannelBinding import com.topjohnwu.magisk.ktx.get -import com.topjohnwu.magisk.model.entity.recycler.SettingsItem import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.asTransitive import com.topjohnwu.magisk.utils.set @@ -30,11 +29,11 @@ import java.io.File // --- Customization -object Customization : SettingsItem.Section() { +object Customization : BaseSettingsItem.Section() { override val title = R.string.settings_customization.asTransitive() } -object Language : SettingsItem.Selector() { +object Language : BaseSettingsItem.Selector() { override var value = -1 set(value) = setV(value, field, { field = it }) { Config.locale = entryValues[it] @@ -56,18 +55,18 @@ object Language : SettingsItem.Selector() { } } -object Theme : SettingsItem.Blank() { +object Theme : BaseSettingsItem.Blank() { override val icon = R.drawable.ic_paint override val title = R.string.section_theme.asTransitive() } // --- Manager -object Manager : SettingsItem.Section() { +object Manager : BaseSettingsItem.Section() { override val title = R.string.manager.asTransitive() } -object ClearRepoCache : SettingsItem.Blank() { +object ClearRepoCache : BaseSettingsItem.Blank() { override val title = R.string.settings_clear_cache_title.asTransitive() override val description = R.string.settings_clear_cache_summary.asTransitive() @@ -76,7 +75,7 @@ object ClearRepoCache : SettingsItem.Blank() { } } -object Hide : SettingsItem.Input() { +object Hide : BaseSettingsItem.Input() { override val title = R.string.settings_hide_manager_title.asTransitive() override val description = R.string.settings_hide_manager_summary.asTransitive() @@ -99,7 +98,7 @@ object Hide : SettingsItem.Input() { } -object Restore : SettingsItem.Blank() { +object Restore : BaseSettingsItem.Blank() { override val title = R.string.settings_restore_manager_title.asTransitive() override val description = R.string.settings_restore_manager_summary.asTransitive() } @@ -108,7 +107,7 @@ object Restore : SettingsItem.Blank() { fun HideOrRestore() = if (get().packageName == BuildConfig.APPLICATION_ID) Hide else Restore -object DownloadPath : SettingsItem.Input() { +object DownloadPath : BaseSettingsItem.Input() { override var value = Config.downloadPath set(value) = setV(value, field, { field = it }) { Config.downloadPath = it } @@ -130,7 +129,7 @@ object DownloadPath : SettingsItem.Input() { .inflate(LayoutInflater.from(context)).also { it.data = this }.root } -object UpdateChannel : SettingsItem.Selector() { +object UpdateChannel : BaseSettingsItem.Selector() { override var value = Config.updateChannel set(value) = setV(value, field, { field = it }) { Config.updateChannel = it } @@ -142,7 +141,7 @@ object UpdateChannel : SettingsItem.Selector() { override val entryValRes = R.array.value_array } -object UpdateChannelUrl : SettingsItem.Input() { +object UpdateChannelUrl : BaseSettingsItem.Input() { override val title = R.string.settings_update_custom.asTransitive() override var value = Config.customChannelUrl set(value) = setV(value, field, { field = it }) { Config.customChannelUrl = it } @@ -162,7 +161,7 @@ object UpdateChannelUrl : SettingsItem.Input() { .inflate(LayoutInflater.from(context)).also { it.data = this }.root } -object UpdateChecker : SettingsItem.Toggle() { +object UpdateChecker : BaseSettingsItem.Toggle() { override val title = R.string.settings_check_update_title.asTransitive() override val description = R.string.settings_check_update_summary.asTransitive() override var value = Config.checkUpdate @@ -173,12 +172,12 @@ object UpdateChecker : SettingsItem.Toggle() { } // check whether is module already installed beforehand? -object SystemlessHosts : SettingsItem.Blank() { +object SystemlessHosts : BaseSettingsItem.Blank() { override val title = R.string.settings_hosts_title.asTransitive() override val description = R.string.settings_hosts_summary.asTransitive() } -object Biometrics : SettingsItem.Toggle() { +object Biometrics : BaseSettingsItem.Toggle() { override val title = R.string.settings_su_biometric_title.asTransitive() override var value = Config.suBiometric set(value) = setV(value, field, { field = it }) { Config.suBiometric = it } @@ -193,7 +192,7 @@ object Biometrics : SettingsItem.Toggle() { } } -object Reauthenticate : SettingsItem.Toggle() { +object Reauthenticate : BaseSettingsItem.Toggle() { override val title = R.string.settings_su_reauth_title.asTransitive() override val description = R.string.settings_su_reauth_summary.asTransitive() override var value = Config.suReAuth @@ -206,11 +205,11 @@ object Reauthenticate : SettingsItem.Toggle() { // --- Magisk -object Magisk : SettingsItem.Section() { +object Magisk : BaseSettingsItem.Section() { override val title = R.string.magisk.asTransitive() } -object MagiskHide : SettingsItem.Toggle() { +object MagiskHide : BaseSettingsItem.Toggle() { override val title = R.string.magiskhide.asTransitive() override val description = R.string.settings_magiskhide_summary.asTransitive() override var value = Config.magiskHide @@ -225,11 +224,11 @@ object MagiskHide : SettingsItem.Toggle() { // --- Superuser -object Superuser : SettingsItem.Section() { +object Superuser : BaseSettingsItem.Section() { override val title = R.string.superuser.asTransitive() } -object AccessMode : SettingsItem.Selector() { +object AccessMode : BaseSettingsItem.Selector() { override val title = R.string.superuser_access.asTransitive() override val entryRes = R.array.su_access override val entryValRes = R.array.value_array @@ -240,7 +239,7 @@ object AccessMode : SettingsItem.Selector() { } } -object MultiuserMode : SettingsItem.Selector() { +object MultiuserMode : BaseSettingsItem.Selector() { override val title = R.string.multiuser_mode.asTransitive() override val entryRes = R.array.multiuser_mode override val entryValRes = R.array.value_array @@ -258,7 +257,7 @@ object MultiuserMode : SettingsItem.Selector() { } } -object MountNamespaceMode : SettingsItem.Selector() { +object MountNamespaceMode : BaseSettingsItem.Selector() { override val title = R.string.mount_namespace_mode.asTransitive() override val entryRes = R.array.namespace override val entryValRes = R.array.value_array @@ -272,7 +271,7 @@ object MountNamespaceMode : SettingsItem.Selector() { get() = resources.getStringArray(R.array.namespace_summary)[value].asTransitive() } -object AutomaticResponse : SettingsItem.Selector() { +object AutomaticResponse : BaseSettingsItem.Selector() { override val title = R.string.auto_response.asTransitive() override val entryRes = R.array.auto_response override val entryValRes = R.array.value_array @@ -283,7 +282,7 @@ object AutomaticResponse : SettingsItem.Selector() { } } -object RequestTimeout : SettingsItem.Selector() { +object RequestTimeout : BaseSettingsItem.Selector() { override val title = R.string.request_timeout.asTransitive() override val entryRes = R.array.request_timeout override val entryValRes = R.array.request_timeout_value @@ -297,7 +296,7 @@ object RequestTimeout : SettingsItem.Selector() { get() = entryValues.indexOfFirst { it.toInt() == Config.suDefaultTimeout } } -object SUNotification : SettingsItem.Selector() { +object SUNotification : BaseSettingsItem.Selector() { override val title = R.string.superuser_notification.asTransitive() override val entryRes = R.array.su_notification override val entryValRes = R.array.value_array diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt index 8a623a4dc..26529ed4b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt @@ -15,11 +15,10 @@ import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.utils.PatchAPK import com.topjohnwu.magisk.data.database.RepoDao -import com.topjohnwu.magisk.model.entity.internal.Configuration -import com.topjohnwu.magisk.model.entity.internal.DownloadSubject -import com.topjohnwu.magisk.model.entity.recycler.SettingsItem -import com.topjohnwu.magisk.model.events.RecreateEvent -import com.topjohnwu.magisk.model.events.dialog.BiometricDialog +import com.topjohnwu.magisk.events.RecreateEvent +import com.topjohnwu.magisk.events.dialog.BiometricDialog +import com.topjohnwu.magisk.model.internal.Configuration +import com.topjohnwu.magisk.model.internal.DownloadSubject import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.superuser.Shell import kotlinx.coroutines.launch @@ -27,10 +26,10 @@ import org.koin.core.get class SettingsViewModel( private val repositoryDao: RepoDao -) : BaseViewModel(), SettingsItem.Callback { +) : BaseViewModel(), BaseSettingsItem.Callback { - val adapter = adapterOf() - val itemBinding = itemBindingOf { it.bindExtra(BR.callback, this) } + val adapter = adapterOf() + val itemBinding = itemBindingOf { it.bindExtra(BR.callback, this) } val items = diffListOf(createItems()) init { @@ -39,7 +38,7 @@ class SettingsViewModel( } } - private fun createItems(): List { + private fun createItems(): List { // Customization val list = mutableListOf( Customization, @@ -90,7 +89,7 @@ class SettingsViewModel( return list } - override fun onItemPressed(view: View, item: SettingsItem, callback: () -> Unit) = when (item) { + override fun onItemPressed(view: View, item: BaseSettingsItem, callback: () -> Unit) = when (item) { is DownloadPath -> withExternalRW(callback) is Biometrics -> authenticate(callback) is Theme -> SettingsFragmentDirections.actionSettingsFragmentToThemeFragment().publish() @@ -100,7 +99,7 @@ class SettingsViewModel( else -> callback() } - override fun onItemChanged(view: View, item: SettingsItem) = when (item) { + override fun onItemChanged(view: View, item: BaseSettingsItem) = when (item) { is Language -> RecreateEvent().publish() is UpdateChannel -> openUrlIfNecessary(view) is Hide -> PatchAPK.hideManager(view.context, item.value) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/PolicyRvItem.kt similarity index 75% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/superuser/PolicyRvItem.kt index 5f748f400..d3afb4490 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/PolicyRvItem.kt @@ -1,19 +1,18 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.ui.superuser import android.graphics.drawable.Drawable import androidx.databinding.Bindable import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.core.model.MagiskPolicy +import com.topjohnwu.magisk.core.model.su.SuPolicy import com.topjohnwu.magisk.databinding.ObservableItem -import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel import com.topjohnwu.magisk.utils.set -class PolicyItem( - val item: MagiskPolicy, +class PolicyRvItem( + val item: SuPolicy, val icon: Drawable, val viewModel: SuperuserViewModel -) : ObservableItem() { +) : ObservableItem() { override val layoutRes = R.layout.item_policy_md2 @get:Bindable @@ -21,7 +20,7 @@ class PolicyItem( set(value) = set(value, field, { field = it }, BR.expanded) // This property hosts the policy state - var policyState = item.policy == MagiskPolicy.ALLOW + var policyState = item.policy == SuPolicy.ALLOW set(value) = set(value, field, { field = it }, BR.enabled) // This property binds with the UI state @@ -44,7 +43,7 @@ class PolicyItem( private val updatedPolicy get() = item.copy( - policy = if (policyState) MagiskPolicy.ALLOW else MagiskPolicy.DENY, + policy = if (policyState) SuPolicy.ALLOW else SuPolicy.DENY, notification = shouldNotify, logging = shouldLog ) @@ -65,7 +64,7 @@ class PolicyItem( viewModel.deletePressed(this) } - override fun contentSameAs(other: PolicyItem) = itemSameAs(other) - override fun itemSameAs(other: PolicyItem) = item.uid == other.item.uid + override fun contentSameAs(other: PolicyRvItem) = itemSameAs(other) + override fun itemSameAs(other: PolicyRvItem) = item.uid == other.item.uid } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/SpinnerRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SpinnerRvItem.kt similarity index 87% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/SpinnerRvItem.kt rename to app/src/main/java/com/topjohnwu/magisk/ui/superuser/SpinnerRvItem.kt index 7a69f924e..0b078905d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/SpinnerRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SpinnerRvItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.ui.superuser import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ComparableRvItem @@ -10,4 +10,4 @@ class SpinnerRvItem(val item: String) : ComparableRvItem() { override fun contentSameAs(other: SpinnerRvItem) = itemSameAs(other) override fun itemSameAs(other: SpinnerRvItem) = item == other.item -} \ No newline at end of file +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index 49fb5bc82..7d55de1d3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -11,16 +11,15 @@ import com.topjohnwu.magisk.arch.adapterOf import com.topjohnwu.magisk.arch.diffListOf import com.topjohnwu.magisk.arch.itemBindingOf import com.topjohnwu.magisk.core.magiskdb.PolicyDao -import com.topjohnwu.magisk.core.model.MagiskPolicy +import com.topjohnwu.magisk.core.model.su.SuPolicy import com.topjohnwu.magisk.core.utils.BiometricHelper import com.topjohnwu.magisk.core.utils.currentLocale import com.topjohnwu.magisk.databinding.ComparableRvItem -import com.topjohnwu.magisk.model.entity.recycler.PolicyItem -import com.topjohnwu.magisk.model.entity.recycler.TappableHeadlineItem -import com.topjohnwu.magisk.model.entity.recycler.TextItem -import com.topjohnwu.magisk.model.events.SnackbarEvent -import com.topjohnwu.magisk.model.events.dialog.BiometricDialog -import com.topjohnwu.magisk.model.events.dialog.SuperuserRevokeDialog +import com.topjohnwu.magisk.events.SnackbarEvent +import com.topjohnwu.magisk.events.dialog.BiometricDialog +import com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog +import com.topjohnwu.magisk.view.TappableHeadlineItem +import com.topjohnwu.magisk.view.TextItem import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -34,7 +33,7 @@ class SuperuserViewModel( private val itemNoData = TextItem(R.string.superuser_policy_none) - private val itemsPolicies = diffListOf() + private val itemsPolicies = diffListOf() private val itemsHelpers = ObservableArrayList() val adapter = adapterOf>() @@ -52,7 +51,7 @@ class SuperuserViewModel( state = State.LOADING val (policies, diff) = withContext(Dispatchers.Default) { val policies = db.fetchAll { - PolicyItem(it, it.applicationInfo.loadIcon(packageManager), this@SuperuserViewModel) + PolicyRvItem(it, it.applicationInfo.loadIcon(packageManager), this@SuperuserViewModel) }.sortedWith(compareBy( { it.item.appName.toLowerCase(currentLocale) }, { it.item.packageName } @@ -77,7 +76,7 @@ class SuperuserViewModel( private fun hidePressed() = SuperuserFragmentDirections.actionSuperuserFragmentToHideFragment().publish() - fun deletePressed(item: PolicyItem) { + fun deletePressed(item: PolicyRvItem) { fun updateState() = viewModelScope.launch { db.delete(item.item.uid) itemsPolicies.removeAll { it.genericItemSameAs(item) } @@ -100,7 +99,7 @@ class SuperuserViewModel( //--- - fun updatePolicy(policy: MagiskPolicy, isLogging: Boolean) = viewModelScope.launch { + fun updatePolicy(policy: SuPolicy, isLogging: Boolean) = viewModelScope.launch { db.update(policy) val str = when { isLogging -> when { @@ -115,16 +114,16 @@ class SuperuserViewModel( SnackbarEvent(resources.getString(str, policy.appName)).publish() } - fun togglePolicy(item: PolicyItem, enable: Boolean) { + fun togglePolicy(item: PolicyRvItem, enable: Boolean) { fun updateState() { item.policyState = enable - val policy = if (enable) MagiskPolicy.ALLOW else MagiskPolicy.DENY + val policy = if (enable) SuPolicy.ALLOW else SuPolicy.DENY val app = item.item.copy(policy = policy) viewModelScope.launch { db.update(app) - val res = if (app.policy == MagiskPolicy.ALLOW) R.string.su_snack_grant + val res = if (app.policy == SuPolicy.ALLOW) R.string.su_snack_grant else R.string.su_snack_deny SnackbarEvent(resources.getString(res).format(item.item.appName)).publish() } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt index 78b9f0092..dfa2aad62 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt @@ -13,12 +13,12 @@ import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.BaseViewModel import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.magiskdb.PolicyDao -import com.topjohnwu.magisk.core.model.MagiskPolicy.Companion.ALLOW -import com.topjohnwu.magisk.core.model.MagiskPolicy.Companion.DENY +import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.ALLOW +import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.DENY import com.topjohnwu.magisk.core.su.SuRequestHandler import com.topjohnwu.magisk.core.utils.BiometricHelper -import com.topjohnwu.magisk.model.entity.recycler.SpinnerRvItem -import com.topjohnwu.magisk.model.events.DieEvent +import com.topjohnwu.magisk.events.DieEvent +import com.topjohnwu.magisk.ui.superuser.SpinnerRvItem import com.topjohnwu.magisk.utils.set import com.topjohnwu.superuser.internal.UiThreadHandler import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeViewModel.kt index 664fd1575..1075dd9fb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeViewModel.kt @@ -1,9 +1,9 @@ package com.topjohnwu.magisk.ui.theme import com.topjohnwu.magisk.arch.BaseViewModel -import com.topjohnwu.magisk.model.entity.recycler.TappableHeadlineItem -import com.topjohnwu.magisk.model.events.RecreateEvent -import com.topjohnwu.magisk.model.events.dialog.DarkThemeDialog +import com.topjohnwu.magisk.events.RecreateEvent +import com.topjohnwu.magisk.events.dialog.DarkThemeDialog +import com.topjohnwu.magisk.view.TappableHeadlineItem class ThemeViewModel : BaseViewModel(), TappableHeadlineItem.Listener { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/TappableHeadlineItem.kt b/app/src/main/java/com/topjohnwu/magisk/view/TappableHeadlineItem.kt similarity index 94% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/TappableHeadlineItem.kt rename to app/src/main/java/com/topjohnwu/magisk/view/TappableHeadlineItem.kt index 48c394ae0..c24e5afcc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/TappableHeadlineItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/TappableHeadlineItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.view import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ComparableRvItem diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/TextItem.kt b/app/src/main/java/com/topjohnwu/magisk/view/TextItem.kt similarity index 86% rename from app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/TextItem.kt rename to app/src/main/java/com/topjohnwu/magisk/view/TextItem.kt index 56cd07b52..5e6526b15 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/TextItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/TextItem.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.model.entity.recycler +package com.topjohnwu.magisk.view import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ComparableRvItem diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml index af380335a..0c7ebe860 100644 --- a/app/src/main/res/layout/fragment_home_md2.xml +++ b/app/src/main/res/layout/fragment_home_md2.xml @@ -9,7 +9,7 @@ - + + type="com.topjohnwu.magisk.ui.flash.ConsoleItem" /> diff --git a/app/src/main/res/layout/item_developer.xml b/app/src/main/res/layout/item_developer.xml index 5d3fe9842..b035af453 100644 --- a/app/src/main/res/layout/item_developer.xml +++ b/app/src/main/res/layout/item_developer.xml @@ -7,7 +7,7 @@ + type="com.topjohnwu.magisk.ui.home.DeveloperItem" /> + type="com.topjohnwu.magisk.ui.hide.HideItem" /> + type="com.topjohnwu.magisk.ui.hide.HideProcessItem" /> + type="com.topjohnwu.magisk.ui.home.IconLink" /> + type="com.topjohnwu.magisk.ui.log.LogRvItem" /> + type="com.topjohnwu.magisk.ui.module.InstallModule" /> + type="com.topjohnwu.magisk.ui.module.ModuleItem" /> + type="com.topjohnwu.magisk.ui.superuser.PolicyRvItem" /> diff --git a/app/src/main/res/layout/item_repo_md2.xml b/app/src/main/res/layout/item_repo_md2.xml index 937faed51..670ae42b1 100644 --- a/app/src/main/res/layout/item_repo_md2.xml +++ b/app/src/main/res/layout/item_repo_md2.xml @@ -9,7 +9,7 @@ + type="com.topjohnwu.magisk.ui.module.RepoItem" /> + type="com.topjohnwu.magisk.ui.module.SectionTitle" /> + type="com.topjohnwu.magisk.ui.settings.BaseSettingsItem" /> + type="com.topjohnwu.magisk.ui.settings.BaseSettingsItem.Callback" /> diff --git a/app/src/main/res/layout/item_settings_section.xml b/app/src/main/res/layout/item_settings_section.xml index e083c9cf7..3dfe4791f 100644 --- a/app/src/main/res/layout/item_settings_section.xml +++ b/app/src/main/res/layout/item_settings_section.xml @@ -6,7 +6,7 @@ + type="com.topjohnwu.magisk.ui.settings.BaseSettingsItem" /> diff --git a/app/src/main/res/layout/item_spinner.xml b/app/src/main/res/layout/item_spinner.xml index df9caea56..16e2d6c75 100644 --- a/app/src/main/res/layout/item_spinner.xml +++ b/app/src/main/res/layout/item_spinner.xml @@ -6,7 +6,7 @@ + type="com.topjohnwu.magisk.ui.superuser.SpinnerRvItem" /> @@ -25,4 +25,4 @@ android:textAlignment="inherit" tools:text="Forever" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/item_tappable_headline.xml b/app/src/main/res/layout/item_tappable_headline.xml index c6c777451..a06c7a408 100644 --- a/app/src/main/res/layout/item_tappable_headline.xml +++ b/app/src/main/res/layout/item_tappable_headline.xml @@ -7,11 +7,11 @@ + type="com.topjohnwu.magisk.view.TappableHeadlineItem" /> + type="com.topjohnwu.magisk.view.TappableHeadlineItem.Listener" /> diff --git a/app/src/main/res/layout/item_text.xml b/app/src/main/res/layout/item_text.xml index 7bf74922f..cf3964c1a 100644 --- a/app/src/main/res/layout/item_text.xml +++ b/app/src/main/res/layout/item_text.xml @@ -6,7 +6,7 @@ + type="com.topjohnwu.magisk.view.TextItem" /> @@ -19,4 +19,4 @@ android:textAppearance="@style/AppearanceFoundation.Tiny.Variant" tools:text="@tools:sample/lorem/random" /> - \ No newline at end of file +