From ea93013ebc583ab701708a82844572f619d6ccc1 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Apr 2019 14:49:52 +0200 Subject: [PATCH 01/66] Added kotlin support --- app/build.gradle | 12 ++++++++++++ build.gradle | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 39c100149..d8833d332 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,16 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' + +kapt { + correctErrorTypes = true + useBuildCache = true + mapDiagnosticLocations = true + javacOptions { + option("-Xmaxerrs", 1000) + } +} android { defaultConfig { diff --git a/build.gradle b/build.gradle index 00ba953dc..471d50845 100644 --- a/build.gradle +++ b/build.gradle @@ -11,13 +11,12 @@ buildscript { repositories { google() jcenter() - maven { - url 'http://storage.googleapis.com/r8-releases/raw' - } + maven { url 'http://storage.googleapis.com/r8-releases/raw' } } dependencies { classpath 'com.android.tools:r8:1.4.79' - classpath 'com.android.tools.build:gradle:3.5.0-alpha10' + classpath 'com.android.tools.build:gradle:3.3.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21" // NOTE: Do not place your application dependencies here; they belong From f006a85fec920a93b1fe2f67e8cbd88075beb2bb Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Apr 2019 15:32:36 +0200 Subject: [PATCH 02/66] Fixed butter knife not building with kotlin --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index d8833d332..cfda68a6e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,5 +62,5 @@ dependencies { def butterKnifeVersion = '10.1.0' implementation "com.jakewharton:butterknife-runtime:${butterKnifeVersion}" - annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" + kapt "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" } From bea5308ab7bf42aca8ef9ed04a82f558804af079 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Apr 2019 18:03:22 +0200 Subject: [PATCH 03/66] Updated locations of nearly all files This has been done in preparations for rewrite to kotlin and upcoming design changes. Nothing should be broken but use caution. --- app/proguard-rules.pro | 7 ++- app/src/main/java/a/b.java | 2 +- app/src/main/java/a/c.java | 2 +- app/src/main/java/a/f.java | 2 +- app/src/main/java/a/g.java | 2 +- app/src/main/java/a/h.java | 2 +- app/src/main/java/a/j.java | 2 +- app/src/main/java/a/m.java | 2 +- app/src/main/java/a/w.java | 2 +- .../main/java/com/topjohnwu/magisk/App.java | 14 ++--- .../java/com/topjohnwu/magisk/ClassMap.java | 10 ++-- .../magisk/{ => data}/database/MagiskDB.java | 6 +-- .../database/RepoDatabaseHelper.java | 4 +- .../adapters/ApplicationAdapter.java | 17 +++--- .../{ => model}/adapters/ModulesAdapter.java | 11 ++-- .../{ => model}/adapters/PolicyAdapter.java | 25 +++++---- .../{ => model}/adapters/ReposAdapter.java | 19 ++++--- .../adapters/SectionedAdapter.java | 2 +- .../adapters/StringListAdapter.java | 6 +-- .../{ => model}/adapters/SuLogAdapter.java | 11 ++-- .../adapters/TabFragmentAdapter.java | 8 +-- .../download}/DownloadModuleService.java | 17 +++--- .../entity}/BaseModule.java | 6 +-- .../{container => model/entity}/Module.java | 4 +- .../{container => model/entity}/Policy.java | 6 +-- .../{container => model/entity}/Repo.java | 2 +- .../entity}/SuLogEntry.java | 2 +- .../receiver}/GeneralReceiver.java | 8 +-- .../update}/UpdateCheckService.java | 11 ++-- .../worker}/DelegateWorker.java | 14 ++--- .../topjohnwu/magisk/tasks/UpdateRepos.java | 2 +- .../magisk/{ => ui}/MainActivity.java | 33 ++++++------ .../magisk/{ => ui}/SplashActivity.java | 19 ++++--- .../{components => ui/base}/BaseActivity.java | 16 +++--- .../{components => ui/base}/BaseFragment.java | 5 +- .../base}/BasePreferenceFragment.java | 10 ++-- .../magisk/{ => ui/flash}/FlashActivity.java | 17 +++--- .../hide}/MagiskHideFragment.java | 15 +++--- .../home}/MagiskFragment.java | 53 +++++++++---------- .../{fragments => ui/log}/LogFragment.java | 11 ++-- .../log}/MagiskLogFragment.java | 15 +++--- .../{fragments => ui/log}/SuLogFragment.java | 11 ++-- .../module}/ModulesFragment.java | 19 ++++--- .../module}/ReposFragment.java | 17 +++--- .../settings}/SettingsFragment.java | 20 +++---- .../superuser}/SuperuserFragment.java | 13 +++-- .../{ => ui/surequest}/SuRequestActivity.java | 15 +++--- .../topjohnwu/magisk/utils/DownloadApp.java | 4 +- .../com/topjohnwu/magisk/utils/PatchAPK.java | 8 +-- .../com/topjohnwu/magisk/utils/SuLogger.java | 4 +- .../com/topjohnwu/magisk/utils/Utils.java | 17 +++--- .../{container => utils}/ValueSortedMap.java | 6 +-- .../ArrowExpandable.java | 2 +- .../{uicomponents => view}/Expandable.java | 2 +- .../ExpandableViewHolder.java | 2 +- .../MarkDownWindow.java | 5 +- .../{uicomponents => view}/Notifications.java | 14 ++--- .../ProgressNotification.java | 6 +-- .../{uicomponents => view}/SafetyNet.java | 9 ++-- .../{uicomponents => view}/Shortcuts.java | 8 +-- .../{uicomponents => view}/SnackbarMaker.java | 6 +-- .../UpdateCardHolder.java | 2 +- .../{ => view}/dialogs/CustomAlertDialog.java | 7 ++- .../{ => view}/dialogs/EnvFixDialog.java | 6 +-- .../dialogs/FingerprintAuthDialog.java | 8 +-- .../dialogs/InstallMethodDialog.java | 14 ++--- .../dialogs/MagiskInstallDialog.java | 6 +-- .../dialogs/ManagerInstallDialog.java | 8 +-- .../{ => view}/dialogs/UninstallDialog.java | 10 ++-- 69 files changed, 338 insertions(+), 333 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/{ => data}/database/MagiskDB.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{ => data}/database/RepoDatabaseHelper.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/ApplicationAdapter.java (99%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/ModulesAdapter.java (96%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/PolicyAdapter.java (93%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/ReposAdapter.java (95%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/SectionedAdapter.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/StringListAdapter.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/SuLogAdapter.java (96%) rename app/src/main/java/com/topjohnwu/magisk/{ => model}/adapters/TabFragmentAdapter.java (95%) rename app/src/main/java/com/topjohnwu/magisk/{components => model/download}/DownloadModuleService.java (94%) rename app/src/main/java/com/topjohnwu/magisk/{container => model/entity}/BaseModule.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{container => model/entity}/Module.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{container => model/entity}/Policy.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{container => model/entity}/Repo.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{container => model/entity}/SuLogEntry.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{components => model/receiver}/GeneralReceiver.java (94%) rename app/src/main/java/com/topjohnwu/magisk/{components => model/update}/UpdateCheckService.java (85%) rename app/src/main/java/com/topjohnwu/magisk/{components => model/worker}/DelegateWorker.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{ => ui}/MainActivity.java (91%) rename app/src/main/java/com/topjohnwu/magisk/{ => ui}/SplashActivity.java (87%) rename app/src/main/java/com/topjohnwu/magisk/{components => ui/base}/BaseActivity.java (99%) rename app/src/main/java/com/topjohnwu/magisk/{components => ui/base}/BaseFragment.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{components => ui/base}/BasePreferenceFragment.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{ => ui/flash}/FlashActivity.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/hide}/MagiskHideFragment.java (95%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/home}/MagiskFragment.java (93%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/log}/LogFragment.java (87%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/log}/MagiskLogFragment.java (95%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/log}/SuLogFragment.java (93%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/module}/ModulesFragment.java (94%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/module}/ReposFragment.java (95%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/settings}/SettingsFragment.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{fragments => ui/superuser}/SuperuserFragment.java (89%) rename app/src/main/java/com/topjohnwu/magisk/{ => ui/surequest}/SuRequestActivity.java (96%) rename app/src/main/java/com/topjohnwu/magisk/{container => utils}/ValueSortedMap.java (95%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/ArrowExpandable.java (96%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/Expandable.java (94%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/ExpandableViewHolder.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/MarkDownWindow.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/Notifications.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/ProgressNotification.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/SafetyNet.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/Shortcuts.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/SnackbarMaker.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{uicomponents => view}/UpdateCardHolder.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{ => view}/dialogs/CustomAlertDialog.java (99%) rename app/src/main/java/com/topjohnwu/magisk/{ => view}/dialogs/EnvFixDialog.java (97%) rename app/src/main/java/com/topjohnwu/magisk/{ => view}/dialogs/FingerprintAuthDialog.java (98%) rename app/src/main/java/com/topjohnwu/magisk/{ => view}/dialogs/InstallMethodDialog.java (93%) rename app/src/main/java/com/topjohnwu/magisk/{ => view}/dialogs/MagiskInstallDialog.java (92%) rename app/src/main/java/com/topjohnwu/magisk/{ => view}/dialogs/ManagerInstallDialog.java (91%) rename app/src/main/java/com/topjohnwu/magisk/{ => view}/dialogs/UninstallDialog.java (93%) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index d6b2bb835..00ff344e1 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -30,7 +30,7 @@ } # DelegateWorker --keep,allowobfuscation class * extends com.topjohnwu.magisk.components.DelegateWorker +-keep,allowobfuscation class * extends com.topjohnwu.magisk.model.worker.DelegateWorker # BootSigner -keepclassmembers class com.topjohnwu.signing.BootSigner { *; } @@ -49,3 +49,8 @@ # Excessive obfuscation -repackageclasses 'a' -allowaccessmodification + +# QOL +-dontnote ** +-dontwarn com.caverock.androidsvg.** +-dontwarn ru.noties.markwon.** diff --git a/app/src/main/java/a/b.java b/app/src/main/java/a/b.java index 0e0409f89..db9475e9c 100644 --- a/app/src/main/java/a/b.java +++ b/app/src/main/java/a/b.java @@ -1,6 +1,6 @@ package a; -import com.topjohnwu.magisk.MainActivity; +import com.topjohnwu.magisk.ui.MainActivity; public class b extends MainActivity { /* stub */ diff --git a/app/src/main/java/a/c.java b/app/src/main/java/a/c.java index 5e7bea238..73073ef6a 100644 --- a/app/src/main/java/a/c.java +++ b/app/src/main/java/a/c.java @@ -1,6 +1,6 @@ package a; -import com.topjohnwu.magisk.SplashActivity; +import com.topjohnwu.magisk.ui.SplashActivity; public class c extends SplashActivity { /* stub */ diff --git a/app/src/main/java/a/f.java b/app/src/main/java/a/f.java index a40a5c70f..08d136b28 100644 --- a/app/src/main/java/a/f.java +++ b/app/src/main/java/a/f.java @@ -1,6 +1,6 @@ package a; -import com.topjohnwu.magisk.FlashActivity; +import com.topjohnwu.magisk.ui.flash.FlashActivity; public class f extends FlashActivity { /* stub */ diff --git a/app/src/main/java/a/g.java b/app/src/main/java/a/g.java index 13771c547..ceaf4ff41 100644 --- a/app/src/main/java/a/g.java +++ b/app/src/main/java/a/g.java @@ -2,7 +2,7 @@ package a; import android.content.Context; -import com.topjohnwu.magisk.components.UpdateCheckService; +import com.topjohnwu.magisk.model.update.UpdateCheckService; import androidx.annotation.NonNull; import androidx.work.WorkerParameters; diff --git a/app/src/main/java/a/h.java b/app/src/main/java/a/h.java index 5b8709277..0be3819f7 100644 --- a/app/src/main/java/a/h.java +++ b/app/src/main/java/a/h.java @@ -1,6 +1,6 @@ package a; -import com.topjohnwu.magisk.components.GeneralReceiver; +import com.topjohnwu.magisk.model.receiver.GeneralReceiver; public class h extends GeneralReceiver { /* stub */ diff --git a/app/src/main/java/a/j.java b/app/src/main/java/a/j.java index bdf1407cb..937100012 100644 --- a/app/src/main/java/a/j.java +++ b/app/src/main/java/a/j.java @@ -1,6 +1,6 @@ package a; -import com.topjohnwu.magisk.components.DownloadModuleService; +import com.topjohnwu.magisk.model.download.DownloadModuleService; public class j extends DownloadModuleService { /* stub */ diff --git a/app/src/main/java/a/m.java b/app/src/main/java/a/m.java index d879fcd72..3d727085d 100644 --- a/app/src/main/java/a/m.java +++ b/app/src/main/java/a/m.java @@ -1,6 +1,6 @@ package a; -import com.topjohnwu.magisk.SuRequestActivity; +import com.topjohnwu.magisk.ui.surequest.SuRequestActivity; public class m extends SuRequestActivity { /* stub */ diff --git a/app/src/main/java/a/w.java b/app/src/main/java/a/w.java index 7be9efa37..e5a2fd89a 100644 --- a/app/src/main/java/a/w.java +++ b/app/src/main/java/a/w.java @@ -2,7 +2,7 @@ package a; import android.content.Context; -import com.topjohnwu.magisk.components.DelegateWorker; +import com.topjohnwu.magisk.model.worker.DelegateWorker; import java.lang.reflect.ParameterizedType; diff --git a/app/src/main/java/com/topjohnwu/magisk/App.java b/app/src/main/java/com/topjohnwu/magisk/App.java index 14284d949..179419249 100644 --- a/app/src/main/java/com/topjohnwu/magisk/App.java +++ b/app/src/main/java/com/topjohnwu/magisk/App.java @@ -10,13 +10,9 @@ import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatDelegate; - -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.database.MagiskDB; -import com.topjohnwu.magisk.database.RepoDatabaseHelper; +import com.topjohnwu.magisk.data.database.MagiskDB; +import com.topjohnwu.magisk.data.database.RepoDatabaseHelper; +import com.topjohnwu.magisk.ui.base.BaseActivity; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.net.Networking; @@ -24,6 +20,10 @@ import com.topjohnwu.superuser.Shell; import java.util.concurrent.ThreadPoolExecutor; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatDelegate; + public class App extends Application implements Application.ActivityLifecycleCallbacks { public static App self; diff --git a/app/src/main/java/com/topjohnwu/magisk/ClassMap.java b/app/src/main/java/com/topjohnwu/magisk/ClassMap.java index 5bd8ace31..4013d5918 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ClassMap.java +++ b/app/src/main/java/com/topjohnwu/magisk/ClassMap.java @@ -1,8 +1,12 @@ package com.topjohnwu.magisk; -import com.topjohnwu.magisk.components.DownloadModuleService; -import com.topjohnwu.magisk.components.GeneralReceiver; -import com.topjohnwu.magisk.components.UpdateCheckService; +import com.topjohnwu.magisk.model.download.DownloadModuleService; +import com.topjohnwu.magisk.model.receiver.GeneralReceiver; +import com.topjohnwu.magisk.model.update.UpdateCheckService; +import com.topjohnwu.magisk.ui.MainActivity; +import com.topjohnwu.magisk.ui.SplashActivity; +import com.topjohnwu.magisk.ui.flash.FlashActivity; +import com.topjohnwu.magisk.ui.surequest.SuRequestActivity; import java.util.HashMap; import java.util.Map; diff --git a/app/src/main/java/com/topjohnwu/magisk/database/MagiskDB.java b/app/src/main/java/com/topjohnwu/magisk/data/database/MagiskDB.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/database/MagiskDB.java rename to app/src/main/java/com/topjohnwu/magisk/data/database/MagiskDB.java index 69a3ee383..96b703cd1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/database/MagiskDB.java +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/MagiskDB.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.database; +package com.topjohnwu.magisk.data.database; import android.content.ContentValues; import android.content.Context; @@ -7,8 +7,8 @@ import android.text.TextUtils; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.container.Policy; -import com.topjohnwu.magisk.container.SuLogEntry; +import com.topjohnwu.magisk.model.entity.Policy; +import com.topjohnwu.magisk.model.entity.SuLogEntry; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; diff --git a/app/src/main/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java b/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDatabaseHelper.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java rename to app/src/main/java/com/topjohnwu/magisk/data/database/RepoDatabaseHelper.java index 852a2e887..8bb2bd369 100644 --- a/app/src/main/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDatabaseHelper.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.database; +package com.topjohnwu.magisk.data.database; import android.content.Context; import android.database.Cursor; @@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.container.Repo; +import com.topjohnwu.magisk.model.entity.Repo; import java.util.HashSet; import java.util.Set; diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/ApplicationAdapter.java similarity index 99% rename from app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/ApplicationAdapter.java index 8c6363e3f..6c7d86eeb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/ApplicationAdapter.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; import android.content.Context; import android.content.pm.ApplicationInfo; @@ -13,20 +13,14 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.WorkerThread; -import androidx.collection.ArraySet; -import androidx.recyclerview.widget.RecyclerView; - import com.buildware.widget.indeterm.IndeterminateCheckBox; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.uicomponents.ArrowExpandable; -import com.topjohnwu.magisk.uicomponents.Expandable; import com.topjohnwu.magisk.utils.Event; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.ArrowExpandable; +import com.topjohnwu.magisk.view.Expandable; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.internal.UiThreadHandler; @@ -35,6 +29,11 @@ import java.util.Comparator; import java.util.List; import java.util.Set; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; +import androidx.collection.ArraySet; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import java9.util.Comparators; import java9.util.Lists; diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/ModulesAdapter.java similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/ModulesAdapter.java index 604cba6f5..e82481ffa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/ModulesAdapter.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; import android.content.Context; import android.text.TextUtils; @@ -9,17 +9,16 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.container.Module; -import com.topjohnwu.magisk.uicomponents.SnackbarMaker; +import com.topjohnwu.magisk.model.entity.Module; +import com.topjohnwu.magisk.view.SnackbarMaker; import com.topjohnwu.superuser.Shell; import java.util.List; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; public class ModulesAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/PolicyAdapter.java similarity index 93% rename from app/src/main/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/PolicyAdapter.java index 72fdcba1a..6b285dcc7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/PolicyAdapter.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; import android.app.Activity; import android.content.DialogInterface; @@ -9,24 +9,23 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.appcompat.widget.SwitchCompat; -import androidx.recyclerview.widget.RecyclerView; - import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.container.Policy; -import com.topjohnwu.magisk.database.MagiskDB; -import com.topjohnwu.magisk.dialogs.CustomAlertDialog; -import com.topjohnwu.magisk.dialogs.FingerprintAuthDialog; -import com.topjohnwu.magisk.uicomponents.ArrowExpandable; -import com.topjohnwu.magisk.uicomponents.Expandable; -import com.topjohnwu.magisk.uicomponents.ExpandableViewHolder; -import com.topjohnwu.magisk.uicomponents.SnackbarMaker; +import com.topjohnwu.magisk.data.database.MagiskDB; +import com.topjohnwu.magisk.model.entity.Policy; import com.topjohnwu.magisk.utils.FingerprintHelper; +import com.topjohnwu.magisk.view.ArrowExpandable; +import com.topjohnwu.magisk.view.Expandable; +import com.topjohnwu.magisk.view.ExpandableViewHolder; +import com.topjohnwu.magisk.view.SnackbarMaker; +import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog; +import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog; import java.util.List; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; public class PolicyAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/ReposAdapter.java similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/ReposAdapter.java index 764fd3f63..162b809fb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/ReposAdapter.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; import android.content.Context; import android.content.Intent; @@ -13,25 +13,24 @@ import android.widget.ImageView; import android.widget.SearchView; import android.widget.TextView; -import androidx.recyclerview.widget.RecyclerView; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.components.DownloadModuleService; -import com.topjohnwu.magisk.container.Module; -import com.topjohnwu.magisk.container.Repo; -import com.topjohnwu.magisk.database.RepoDatabaseHelper; -import com.topjohnwu.magisk.dialogs.CustomAlertDialog; -import com.topjohnwu.magisk.uicomponents.MarkDownWindow; +import com.topjohnwu.magisk.data.database.RepoDatabaseHelper; +import com.topjohnwu.magisk.model.download.DownloadModuleService; +import com.topjohnwu.magisk.model.entity.Module; +import com.topjohnwu.magisk.model.entity.Repo; +import com.topjohnwu.magisk.ui.base.BaseActivity; import com.topjohnwu.magisk.utils.Event; +import com.topjohnwu.magisk.view.MarkDownWindow; +import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import java9.util.stream.StreamSupport; diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/SectionedAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/SectionedAdapter.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/adapters/SectionedAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/SectionedAdapter.java index de181cc19..e04ec20c7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/SectionedAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/SectionedAdapter.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; import android.view.ViewGroup; diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/StringListAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/StringListAdapter.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/adapters/StringListAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/StringListAdapter.java index fb13c87bd..b76064220 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/StringListAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/StringListAdapter.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; import android.app.Activity; import android.util.DisplayMetrics; @@ -7,13 +7,13 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import java.util.List; + import androidx.annotation.IdRes; import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -import java.util.List; - public abstract class StringListAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/SuLogAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/SuLogAdapter.java similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/adapters/SuLogAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/SuLogAdapter.java index 84c0a3449..b1afdd51d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/SuLogAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/SuLogAdapter.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; import android.content.Context; import android.view.LayoutInflater; @@ -9,18 +9,17 @@ import android.view.animation.RotateAnimation; import android.widget.ImageView; import android.widget.TextView; -import androidx.recyclerview.widget.RecyclerView; - import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.container.SuLogEntry; -import com.topjohnwu.magisk.database.MagiskDB; -import com.topjohnwu.magisk.uicomponents.ExpandableViewHolder; +import com.topjohnwu.magisk.data.database.MagiskDB; +import com.topjohnwu.magisk.model.entity.SuLogEntry; +import com.topjohnwu.magisk.view.ExpandableViewHolder; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; public class SuLogAdapter extends SectionedAdapter { diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/TabFragmentAdapter.java b/app/src/main/java/com/topjohnwu/magisk/model/adapters/TabFragmentAdapter.java similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/adapters/TabFragmentAdapter.java rename to app/src/main/java/com/topjohnwu/magisk/model/adapters/TabFragmentAdapter.java index d0eea2be7..eddb897fb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/TabFragmentAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/adapters/TabFragmentAdapter.java @@ -1,13 +1,13 @@ -package com.topjohnwu.magisk.adapters; +package com.topjohnwu.magisk.model.adapters; +import java.util.ArrayList; +import java.util.List; + import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; -import java.util.ArrayList; -import java.util.List; - public class TabFragmentAdapter extends FragmentPagerAdapter { private List fragmentList; diff --git a/app/src/main/java/com/topjohnwu/magisk/components/DownloadModuleService.java b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadModuleService.java similarity index 94% rename from app/src/main/java/com/topjohnwu/magisk/components/DownloadModuleService.java rename to app/src/main/java/com/topjohnwu/magisk/model/download/DownloadModuleService.java index a17333cb8..8b1ce786a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/DownloadModuleService.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadModuleService.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.components; +package com.topjohnwu.magisk.model.download; import android.app.PendingIntent; import android.app.Service; @@ -6,15 +6,13 @@ import android.content.Intent; import android.net.Uri; import android.os.IBinder; -import androidx.annotation.Nullable; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.FlashActivity; -import com.topjohnwu.magisk.container.Repo; -import com.topjohnwu.magisk.uicomponents.Notifications; -import com.topjohnwu.magisk.uicomponents.ProgressNotification; +import com.topjohnwu.magisk.model.entity.Repo; +import com.topjohnwu.magisk.ui.flash.FlashActivity; +import com.topjohnwu.magisk.view.Notifications; +import com.topjohnwu.magisk.view.ProgressNotification; import com.topjohnwu.net.Networking; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.ShellUtils; @@ -25,12 +23,15 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; +import androidx.annotation.Nullable; + public class DownloadModuleService extends Service { private List notifications; @@ -136,7 +137,7 @@ public class DownloadModuleService extends Service { ShellUtils.pump(update_bin, zout); } zout.putNextEntry(new ZipEntry("META-INF/com/google/android/updater-script")); - zout.write("#MAGISK\n".getBytes("UTF-8")); + zout.write("#MAGISK\n".getBytes(StandardCharsets.UTF_8)); } int off = -1; diff --git a/app/src/main/java/com/topjohnwu/magisk/container/BaseModule.java b/app/src/main/java/com/topjohnwu/magisk/model/entity/BaseModule.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/container/BaseModule.java rename to app/src/main/java/com/topjohnwu/magisk/model/entity/BaseModule.java index 259d1a985..20ccc4bec 100644 --- a/app/src/main/java/com/topjohnwu/magisk/container/BaseModule.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/BaseModule.java @@ -1,14 +1,14 @@ -package com.topjohnwu.magisk.container; +package com.topjohnwu.magisk.model.entity; import android.content.ContentValues; import android.database.Cursor; import android.os.Parcel; import android.os.Parcelable; -import androidx.annotation.NonNull; - import java.util.List; +import androidx.annotation.NonNull; + public abstract class BaseModule implements Comparable, Parcelable { private String mId, mName, mVersion, mAuthor, mDescription; diff --git a/app/src/main/java/com/topjohnwu/magisk/container/Module.java b/app/src/main/java/com/topjohnwu/magisk/model/entity/Module.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/container/Module.java rename to app/src/main/java/com/topjohnwu/magisk/model/entity/Module.java index 3c2cd032e..ed04b2830 100644 --- a/app/src/main/java/com/topjohnwu/magisk/container/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/Module.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.container; +package com.topjohnwu.magisk.model.entity; import android.os.Parcel; import android.os.Parcelable; @@ -76,4 +76,4 @@ public class Module extends BaseModule { return mUpdated; } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/topjohnwu/magisk/container/Policy.java b/app/src/main/java/com/topjohnwu/magisk/model/entity/Policy.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/container/Policy.java rename to app/src/main/java/com/topjohnwu/magisk/model/entity/Policy.java index 6ff51f25a..10cc6dac6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/container/Policy.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/Policy.java @@ -1,13 +1,13 @@ -package com.topjohnwu.magisk.container; +package com.topjohnwu.magisk.model.entity; import android.content.ContentValues; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import androidx.annotation.NonNull; - import com.topjohnwu.magisk.utils.Utils; +import androidx.annotation.NonNull; + public class Policy implements Comparable{ public static final int INTERACTIVE = 0; diff --git a/app/src/main/java/com/topjohnwu/magisk/container/Repo.java b/app/src/main/java/com/topjohnwu/magisk/model/entity/Repo.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/container/Repo.java rename to app/src/main/java/com/topjohnwu/magisk/model/entity/Repo.java index 63ffe197a..43f85f12e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/container/Repo.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/Repo.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.container; +package com.topjohnwu.magisk.model.entity; import android.content.ContentValues; import android.database.Cursor; diff --git a/app/src/main/java/com/topjohnwu/magisk/container/SuLogEntry.java b/app/src/main/java/com/topjohnwu/magisk/model/entity/SuLogEntry.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/container/SuLogEntry.java rename to app/src/main/java/com/topjohnwu/magisk/model/entity/SuLogEntry.java index 2638105f4..aa778d65e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/container/SuLogEntry.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/SuLogEntry.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.container; +package com.topjohnwu.magisk.model.entity; import android.content.ContentValues; diff --git a/app/src/main/java/com/topjohnwu/magisk/components/GeneralReceiver.java b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.java similarity index 94% rename from app/src/main/java/com/topjohnwu/magisk/components/GeneralReceiver.java rename to app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.java index 40c103f35..dd71c7f09 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/GeneralReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.components; +package com.topjohnwu.magisk.model.receiver; import android.content.BroadcastReceiver; import android.content.Context; @@ -8,11 +8,11 @@ import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.SuRequestActivity; -import com.topjohnwu.magisk.uicomponents.Notifications; -import com.topjohnwu.magisk.uicomponents.Shortcuts; +import com.topjohnwu.magisk.ui.surequest.SuRequestActivity; import com.topjohnwu.magisk.utils.DownloadApp; import com.topjohnwu.magisk.utils.SuLogger; +import com.topjohnwu.magisk.view.Notifications; +import com.topjohnwu.magisk.view.Shortcuts; import com.topjohnwu.superuser.Shell; public class GeneralReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java b/app/src/main/java/com/topjohnwu/magisk/model/update/UpdateCheckService.java similarity index 85% rename from app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java rename to app/src/main/java/com/topjohnwu/magisk/model/update/UpdateCheckService.java index 79d6241a4..87c6544ef 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/update/UpdateCheckService.java @@ -1,15 +1,16 @@ -package com.topjohnwu.magisk.components; - -import androidx.annotation.NonNull; -import androidx.work.ListenableWorker; +package com.topjohnwu.magisk.model.update; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.model.worker.DelegateWorker; import com.topjohnwu.magisk.tasks.CheckUpdates; -import com.topjohnwu.magisk.uicomponents.Notifications; +import com.topjohnwu.magisk.view.Notifications; import com.topjohnwu.superuser.Shell; +import androidx.annotation.NonNull; +import androidx.work.ListenableWorker; + public class UpdateCheckService extends DelegateWorker { @NonNull diff --git a/app/src/main/java/com/topjohnwu/magisk/components/DelegateWorker.java b/app/src/main/java/com/topjohnwu/magisk/model/worker/DelegateWorker.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/components/DelegateWorker.java rename to app/src/main/java/com/topjohnwu/magisk/model/worker/DelegateWorker.java index 609cbb114..670e88d1c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/DelegateWorker.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/worker/DelegateWorker.java @@ -1,9 +1,15 @@ -package com.topjohnwu.magisk.components; +package com.topjohnwu.magisk.model.worker; import android.content.Context; import android.net.Network; import android.net.Uri; +import com.google.common.util.concurrent.ListenableFuture; + +import java.util.List; +import java.util.Set; +import java.util.UUID; + import androidx.annotation.MainThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -11,12 +17,6 @@ import androidx.annotation.RequiresApi; import androidx.work.Data; import androidx.work.ListenableWorker; -import com.google.common.util.concurrent.ListenableFuture; - -import java.util.List; -import java.util.Set; -import java.util.UUID; - public abstract class DelegateWorker { private ListenableWorker worker; diff --git a/app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java b/app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java index d13dd6546..9d6e44571 100644 --- a/app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java +++ b/app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java @@ -6,7 +6,7 @@ import android.util.Pair; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.container.Repo; +import com.topjohnwu.magisk.model.entity.Repo; import com.topjohnwu.magisk.utils.Event; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Utils; diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java similarity index 91% rename from app/src/main/java/com/topjohnwu/magisk/MainActivity.java rename to app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java index f98f1977f..3da71cf37 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk; +package com.topjohnwu.magisk.ui; import android.content.Intent; import android.os.Build; @@ -8,26 +8,29 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; +import com.google.android.material.navigation.NavigationView; +import com.topjohnwu.magisk.ClassMap; +import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.ui.base.BaseActivity; +import com.topjohnwu.magisk.ui.hide.MagiskHideFragment; +import com.topjohnwu.magisk.ui.home.MagiskFragment; +import com.topjohnwu.magisk.ui.log.LogFragment; +import com.topjohnwu.magisk.ui.module.ModulesFragment; +import com.topjohnwu.magisk.ui.module.ReposFragment; +import com.topjohnwu.magisk.ui.settings.SettingsFragment; +import com.topjohnwu.magisk.ui.superuser.SuperuserFragment; +import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.net.Networking; +import com.topjohnwu.superuser.Shell; + import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.widget.Toolbar; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; - -import com.google.android.material.navigation.NavigationView; -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.fragments.LogFragment; -import com.topjohnwu.magisk.fragments.MagiskFragment; -import com.topjohnwu.magisk.fragments.MagiskHideFragment; -import com.topjohnwu.magisk.fragments.ModulesFragment; -import com.topjohnwu.magisk.fragments.ReposFragment; -import com.topjohnwu.magisk.fragments.SettingsFragment; -import com.topjohnwu.magisk.fragments.SuperuserFragment; -import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.net.Networking; -import com.topjohnwu.superuser.Shell; - import butterknife.BindView; public class MainActivity extends BaseActivity diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.java similarity index 87% rename from app/src/main/java/com/topjohnwu/magisk/SplashActivity.java rename to app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.java index 91c3722af..ee0d8014d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.java @@ -1,23 +1,28 @@ -package com.topjohnwu.magisk; +package com.topjohnwu.magisk.ui; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; import android.text.TextUtils; -import androidx.appcompat.app.AlertDialog; - -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.database.RepoDatabaseHelper; +import com.topjohnwu.magisk.BuildConfig; +import com.topjohnwu.magisk.ClassMap; +import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.data.database.RepoDatabaseHelper; import com.topjohnwu.magisk.tasks.CheckUpdates; import com.topjohnwu.magisk.tasks.UpdateRepos; -import com.topjohnwu.magisk.uicomponents.Notifications; -import com.topjohnwu.magisk.uicomponents.Shortcuts; +import com.topjohnwu.magisk.ui.base.BaseActivity; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.Notifications; +import com.topjohnwu.magisk.view.Shortcuts; import com.topjohnwu.net.Networking; import com.topjohnwu.superuser.Shell; +import androidx.appcompat.app.AlertDialog; + public class SplashActivity extends BaseActivity { public static boolean DONE = false; diff --git a/app/src/main/java/com/topjohnwu/magisk/components/BaseActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseActivity.java similarity index 99% rename from app/src/main/java/com/topjohnwu/magisk/components/BaseActivity.java rename to app/src/main/java/com/topjohnwu/magisk/ui/base/BaseActivity.java index 9db327987..ed42d5b10 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/BaseActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseActivity.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.components; +package com.topjohnwu.magisk.ui.base; import android.Manifest; import android.content.Context; @@ -11,6 +11,13 @@ import android.os.Bundle; import android.text.TextUtils; import android.view.WindowManager; +import com.topjohnwu.magisk.App; +import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.utils.Event; +import com.topjohnwu.magisk.utils.LocaleManager; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StyleRes; @@ -19,13 +26,6 @@ import androidx.collection.SparseArrayCompat; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; -import com.topjohnwu.magisk.App; -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.utils.Event; -import com.topjohnwu.magisk.utils.LocaleManager; - public abstract class BaseActivity extends AppCompatActivity implements Event.AutoListener { static int[] EMPTY_INT_ARRAY = new int[0]; diff --git a/app/src/main/java/com/topjohnwu/magisk/components/BaseFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseFragment.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/components/BaseFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/base/BaseFragment.java index fbaa8f71a..3594a4c19 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/BaseFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseFragment.java @@ -1,12 +1,11 @@ -package com.topjohnwu.magisk.components; +package com.topjohnwu.magisk.ui.base; import android.content.Intent; -import androidx.fragment.app.Fragment; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.utils.Event; +import androidx.fragment.app.Fragment; import butterknife.Unbinder; public abstract class BaseFragment extends Fragment implements Event.AutoListener { diff --git a/app/src/main/java/com/topjohnwu/magisk/components/BasePreferenceFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/components/BasePreferenceFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.java index f6512518f..02e04ac3e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/BasePreferenceFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.components; +package com.topjohnwu.magisk.ui.base; import android.annotation.SuppressLint; import android.content.SharedPreferences; @@ -8,6 +8,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.topjohnwu.magisk.App; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.utils.Event; + import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragmentCompat; @@ -16,10 +20,6 @@ import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceViewHolder; import androidx.recyclerview.widget.RecyclerView; -import com.topjohnwu.magisk.App; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.utils.Event; - public abstract class BasePreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, Event.AutoListener { diff --git a/app/src/main/java/com/topjohnwu/magisk/FlashActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashActivity.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/FlashActivity.java rename to app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashActivity.java index 974f2dfb4..741050e77 100644 --- a/app/src/main/java/com/topjohnwu/magisk/FlashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashActivity.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk; +package com.topjohnwu.magisk.ui.flash; import android.content.Intent; import android.net.Uri; @@ -8,15 +8,12 @@ import android.widget.Button; import android.widget.LinearLayout; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import androidx.recyclerview.widget.RecyclerView; - -import com.topjohnwu.magisk.adapters.StringListAdapter; -import com.topjohnwu.magisk.components.BaseActivity; +import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.model.adapters.StringListAdapter; import com.topjohnwu.magisk.tasks.FlashZip; import com.topjohnwu.magisk.tasks.MagiskInstaller; +import com.topjohnwu.magisk.ui.base.BaseActivity; import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.CallbackList; @@ -32,6 +29,10 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import androidx.annotation.NonNull; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindColor; import butterknife.BindView; import butterknife.OnClick; diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/hide/MagiskHideFragment.java similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/hide/MagiskHideFragment.java index 1f31e27d2..c7f4c3356 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/hide/MagiskHideFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.hide; import android.os.Bundle; import android.view.LayoutInflater; @@ -9,17 +9,16 @@ import android.view.View; import android.view.ViewGroup; import android.widget.SearchView; +import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.model.adapters.ApplicationAdapter; +import com.topjohnwu.magisk.ui.base.BaseFragment; +import com.topjohnwu.magisk.utils.Event; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.adapters.ApplicationAdapter; -import com.topjohnwu.magisk.components.BaseFragment; -import com.topjohnwu.magisk.utils.Event; - import butterknife.BindView; public class MagiskHideFragment extends BaseFragment { diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.java similarity index 93% rename from app/src/main/java/com/topjohnwu/magisk/fragments/MagiskFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.java index 455307d46..4a1864214 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/MagiskFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.home; import android.net.Uri; import android.os.Bundle; @@ -9,6 +9,31 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; +import com.topjohnwu.magisk.BuildConfig; +import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.tasks.CheckUpdates; +import com.topjohnwu.magisk.ui.MainActivity; +import com.topjohnwu.magisk.ui.base.BaseActivity; +import com.topjohnwu.magisk.ui.base.BaseFragment; +import com.topjohnwu.magisk.utils.Event; +import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.ArrowExpandable; +import com.topjohnwu.magisk.view.Expandable; +import com.topjohnwu.magisk.view.ExpandableViewHolder; +import com.topjohnwu.magisk.view.MarkDownWindow; +import com.topjohnwu.magisk.view.SafetyNet; +import com.topjohnwu.magisk.view.UpdateCardHolder; +import com.topjohnwu.magisk.view.dialogs.EnvFixDialog; +import com.topjohnwu.magisk.view.dialogs.MagiskInstallDialog; +import com.topjohnwu.magisk.view.dialogs.ManagerInstallDialog; +import com.topjohnwu.magisk.view.dialogs.UninstallDialog; +import com.topjohnwu.net.Networking; +import com.topjohnwu.superuser.Shell; + +import java.util.Locale; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.cardview.widget.CardView; @@ -18,32 +43,6 @@ import androidx.transition.Fade; import androidx.transition.Transition; import androidx.transition.TransitionManager; import androidx.transition.TransitionSet; - -import com.topjohnwu.magisk.BuildConfig; -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.MainActivity; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.components.BaseFragment; -import com.topjohnwu.magisk.dialogs.EnvFixDialog; -import com.topjohnwu.magisk.dialogs.MagiskInstallDialog; -import com.topjohnwu.magisk.dialogs.ManagerInstallDialog; -import com.topjohnwu.magisk.dialogs.UninstallDialog; -import com.topjohnwu.magisk.tasks.CheckUpdates; -import com.topjohnwu.magisk.uicomponents.ArrowExpandable; -import com.topjohnwu.magisk.uicomponents.Expandable; -import com.topjohnwu.magisk.uicomponents.ExpandableViewHolder; -import com.topjohnwu.magisk.uicomponents.MarkDownWindow; -import com.topjohnwu.magisk.uicomponents.SafetyNet; -import com.topjohnwu.magisk.uicomponents.UpdateCardHolder; -import com.topjohnwu.magisk.utils.Event; -import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.net.Networking; -import com.topjohnwu.superuser.Shell; - -import java.util.Locale; - import butterknife.BindColor; import butterknife.BindView; import butterknife.OnClick; diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/LogFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.java similarity index 87% rename from app/src/main/java/com/topjohnwu/magisk/fragments/LogFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.java index d068b3bb1..d684e1d6f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/LogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.log; import android.os.Build; @@ -7,14 +7,13 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import androidx.viewpager.widget.ViewPager; - import com.google.android.material.tabs.TabLayout; -import com.topjohnwu.magisk.MainActivity; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.adapters.TabFragmentAdapter; -import com.topjohnwu.magisk.components.BaseFragment; +import com.topjohnwu.magisk.model.adapters.TabFragmentAdapter; +import com.topjohnwu.magisk.ui.MainActivity; +import com.topjohnwu.magisk.ui.base.BaseFragment; +import androidx.viewpager.widget.ViewPager; import butterknife.BindView; public class LogFragment extends BaseFragment { diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/log/MagiskLogFragment.java similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/log/MagiskLogFragment.java index dee954f78..0e44c25e9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/MagiskLogFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.log; import android.os.Bundle; import android.view.LayoutInflater; @@ -8,17 +8,13 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.adapters.StringListAdapter; -import com.topjohnwu.magisk.components.BaseFragment; -import com.topjohnwu.magisk.uicomponents.SnackbarMaker; +import com.topjohnwu.magisk.model.adapters.StringListAdapter; +import com.topjohnwu.magisk.ui.base.BaseFragment; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.SnackbarMaker; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.internal.NOPList; @@ -27,6 +23,9 @@ import java.io.IOException; import java.util.Calendar; import java.util.List; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; public class MagiskLogFragment extends BaseFragment { diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/SuLogFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/log/SuLogFragment.java similarity index 93% rename from app/src/main/java/com/topjohnwu/magisk/fragments/SuLogFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/log/SuLogFragment.java index e22b415e6..9f6595d00 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/SuLogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/SuLogFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.log; import android.os.Bundle; import android.view.LayoutInflater; @@ -9,13 +9,12 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.model.adapters.SuLogAdapter; +import com.topjohnwu.magisk.ui.base.BaseFragment; + import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; - -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.adapters.SuLogAdapter; -import com.topjohnwu.magisk.components.BaseFragment; - import butterknife.BindView; public class SuLogFragment extends BaseFragment { diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/ModulesFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.java similarity index 94% rename from app/src/main/java/com/topjohnwu/magisk/fragments/ModulesFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.java index 06affa253..78d5989a7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/ModulesFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.module; import android.app.Activity; import android.content.Intent; @@ -11,18 +11,13 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.adapters.ModulesAdapter; -import com.topjohnwu.magisk.components.BaseFragment; -import com.topjohnwu.magisk.container.Module; +import com.topjohnwu.magisk.model.adapters.ModulesAdapter; +import com.topjohnwu.magisk.model.entity.Module; +import com.topjohnwu.magisk.ui.base.BaseFragment; +import com.topjohnwu.magisk.ui.flash.FlashActivity; import com.topjohnwu.magisk.utils.Event; import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.Utils; @@ -32,6 +27,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import butterknife.BindView; import butterknife.OnClick; diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/ReposFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.java similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/fragments/ReposFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.java index b45e2acf0..4c12fee70 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/ReposFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.module; import android.app.AlertDialog; import android.os.Bundle; @@ -11,18 +11,17 @@ import android.view.ViewGroup; import android.widget.SearchView; import android.widget.TextView; +import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.model.adapters.ReposAdapter; +import com.topjohnwu.magisk.tasks.UpdateRepos; +import com.topjohnwu.magisk.ui.base.BaseFragment; +import com.topjohnwu.magisk.utils.Event; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.adapters.ReposAdapter; -import com.topjohnwu.magisk.components.BaseFragment; -import com.topjohnwu.magisk.tasks.UpdateRepos; -import com.topjohnwu.magisk.utils.Event; - import butterknife.BindView; public class ReposFragment extends BaseFragment { diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/SettingsFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/fragments/SettingsFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java index 4902aa392..7938275b8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/SettingsFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.settings; import android.content.SharedPreferences; import android.os.Build; @@ -8,26 +8,19 @@ import android.view.View; import android.widget.EditText; import android.widget.Toast; -import androidx.appcompat.app.AlertDialog; -import androidx.preference.ListPreference; -import androidx.preference.Preference; -import androidx.preference.PreferenceCategory; -import androidx.preference.PreferenceScreen; -import androidx.preference.SwitchPreferenceCompat; - import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.components.BasePreferenceFragment; -import com.topjohnwu.magisk.dialogs.FingerprintAuthDialog; import com.topjohnwu.magisk.tasks.CheckUpdates; +import com.topjohnwu.magisk.ui.base.BasePreferenceFragment; import com.topjohnwu.magisk.utils.DownloadApp; import com.topjohnwu.magisk.utils.Event; import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.PatchAPK; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog; import com.topjohnwu.net.Networking; import com.topjohnwu.superuser.Shell; @@ -35,6 +28,13 @@ import java.io.IOException; import java.util.Arrays; import java.util.Locale; +import androidx.appcompat.app.AlertDialog; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreferenceCompat; + public class SettingsFragment extends BasePreferenceFragment { private ListPreference updateChannel, autoRes, suNotification, diff --git a/app/src/main/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java similarity index 89% rename from app/src/main/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java rename to app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java index 26132abb7..2f5beaf7b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.fragments; +package com.topjohnwu.magisk.ui.superuser; import android.content.pm.PackageManager; import android.os.Bundle; @@ -7,16 +7,15 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.adapters.PolicyAdapter; -import com.topjohnwu.magisk.components.BaseFragment; -import com.topjohnwu.magisk.container.Policy; +import com.topjohnwu.magisk.model.adapters.PolicyAdapter; +import com.topjohnwu.magisk.model.entity.Policy; +import com.topjohnwu.magisk.ui.base.BaseFragment; import java.util.List; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; public class SuperuserFragment extends BaseFragment { diff --git a/app/src/main/java/com/topjohnwu/magisk/SuRequestActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.java similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/SuRequestActivity.java rename to app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.java index e5b482e47..481956be5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SuRequestActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk; +package com.topjohnwu.magisk.ui.surequest; import android.annotation.SuppressLint; import android.content.Intent; @@ -17,11 +17,12 @@ import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; -import androidx.annotation.Nullable; -import androidx.appcompat.content.res.AppCompatResources; - -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.container.Policy; +import com.topjohnwu.magisk.App; +import com.topjohnwu.magisk.BuildConfig; +import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.model.entity.Policy; +import com.topjohnwu.magisk.ui.base.BaseActivity; import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.SuConnector; import com.topjohnwu.magisk.utils.SuLogger; @@ -30,6 +31,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import androidx.annotation.Nullable; +import androidx.appcompat.content.res.AppCompatResources; import butterknife.BindView; import java9.lang.Iterables; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java b/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java index 14f9329e4..39727e52d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DownloadApp.java @@ -7,8 +7,8 @@ import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.SplashActivity; -import com.topjohnwu.magisk.uicomponents.ProgressNotification; +import com.topjohnwu.magisk.ui.SplashActivity; +import com.topjohnwu.magisk.view.ProgressNotification; import com.topjohnwu.net.Networking; import com.topjohnwu.net.ResponseListener; import com.topjohnwu.superuser.Shell; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/PatchAPK.java b/app/src/main/java/com/topjohnwu/magisk/utils/PatchAPK.java index d7f8eddf2..0d77c058a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/PatchAPK.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/PatchAPK.java @@ -3,16 +3,14 @@ package com.topjohnwu.magisk.utils; import android.content.ComponentName; import android.widget.Toast; -import androidx.core.app.NotificationCompat; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.SplashActivity; -import com.topjohnwu.magisk.uicomponents.Notifications; +import com.topjohnwu.magisk.ui.SplashActivity; +import com.topjohnwu.magisk.view.Notifications; import com.topjohnwu.signing.JarMap; import com.topjohnwu.signing.SignAPK; import com.topjohnwu.superuser.Shell; @@ -29,6 +27,8 @@ import java.util.ArrayList; import java.util.List; import java.util.jar.JarEntry; +import androidx.core.app.NotificationCompat; + public class PatchAPK { public static final String LOWERALPHA = "abcdefghijklmnopqrstuvwxyz"; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java index 0a41cedfe..888a65262 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java @@ -9,8 +9,8 @@ import android.widget.Toast; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.container.Policy; -import com.topjohnwu.magisk.container.SuLogEntry; +import com.topjohnwu.magisk.model.entity.Policy; +import com.topjohnwu.magisk.model.entity.SuLogEntry; import java.util.Date; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 9cb213c7a..1cbcb06d5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -12,21 +12,14 @@ import android.net.Uri; import android.provider.OpenableColumns; import android.widget.Toast; -import androidx.work.Constraints; -import androidx.work.ExistingPeriodicWorkPolicy; -import androidx.work.NetworkType; -import androidx.work.PeriodicWorkRequest; -import androidx.work.WorkManager; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.components.UpdateCheckService; -import com.topjohnwu.magisk.container.Module; -import com.topjohnwu.magisk.container.ValueSortedMap; +import com.topjohnwu.magisk.model.entity.Module; +import com.topjohnwu.magisk.model.update.UpdateCheckService; import com.topjohnwu.net.Networking; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.internal.UiThreadHandler; @@ -37,6 +30,12 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.TimeUnit; +import androidx.work.Constraints; +import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.NetworkType; +import androidx.work.PeriodicWorkRequest; +import androidx.work.WorkManager; + public class Utils { public static void toast(CharSequence msg, int duration) { diff --git a/app/src/main/java/com/topjohnwu/magisk/container/ValueSortedMap.java b/app/src/main/java/com/topjohnwu/magisk/utils/ValueSortedMap.java similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/container/ValueSortedMap.java rename to app/src/main/java/com/topjohnwu/magisk/utils/ValueSortedMap.java index 9f5047d75..babd8ba79 100644 --- a/app/src/main/java/com/topjohnwu/magisk/container/ValueSortedMap.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ValueSortedMap.java @@ -1,6 +1,4 @@ -package com.topjohnwu.magisk.container; - -import androidx.annotation.NonNull; +package com.topjohnwu.magisk.utils; import java.util.ArrayList; import java.util.Collection; @@ -9,6 +7,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import androidx.annotation.NonNull; + public class ValueSortedMap> extends HashMap { private List sorted = new ArrayList<>(); diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/ArrowExpandable.java b/app/src/main/java/com/topjohnwu/magisk/view/ArrowExpandable.java similarity index 96% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/ArrowExpandable.java rename to app/src/main/java/com/topjohnwu/magisk/view/ArrowExpandable.java index c49d402cd..81478cddd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/ArrowExpandable.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/ArrowExpandable.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.view.View; import android.view.animation.Animation; diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/Expandable.java b/app/src/main/java/com/topjohnwu/magisk/view/Expandable.java similarity index 94% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/Expandable.java rename to app/src/main/java/com/topjohnwu/magisk/view/Expandable.java index e854d929b..82471b66d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/Expandable.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/Expandable.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; public abstract class Expandable { diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/ExpandableViewHolder.java b/app/src/main/java/com/topjohnwu/magisk/view/ExpandableViewHolder.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/ExpandableViewHolder.java rename to app/src/main/java/com/topjohnwu/magisk/view/ExpandableViewHolder.java index 015ce3fdb..f27b96b31 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/ExpandableViewHolder.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/ExpandableViewHolder.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.animation.ValueAnimator; import android.view.View; diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java b/app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java rename to app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.java index a161d916a..f7e3b3dae 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.java @@ -1,11 +1,9 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; -import androidx.appcompat.app.AlertDialog; - import com.topjohnwu.magisk.R; import com.topjohnwu.net.Networking; import com.topjohnwu.net.ResponseListener; @@ -13,6 +11,7 @@ import com.topjohnwu.net.ResponseListener; import java.io.InputStream; import java.util.Scanner; +import androidx.appcompat.app.AlertDialog; import ru.noties.markwon.Markwon; import ru.noties.markwon.html.HtmlPlugin; import ru.noties.markwon.image.ImagesPlugin; diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/Notifications.java b/app/src/main/java/com/topjohnwu/magisk/view/Notifications.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/Notifications.java rename to app/src/main/java/com/topjohnwu/magisk/view/Notifications.java index e90956f35..244c51b25 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/Notifications.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/Notifications.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -7,19 +7,19 @@ import android.content.Context; import android.content.Intent; import android.os.Build; -import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; -import androidx.core.app.TaskStackBuilder; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.SplashActivity; -import com.topjohnwu.magisk.components.GeneralReceiver; +import com.topjohnwu.magisk.model.receiver.GeneralReceiver; +import com.topjohnwu.magisk.ui.SplashActivity; import com.topjohnwu.magisk.utils.Utils; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; +import androidx.core.app.TaskStackBuilder; + public class Notifications { public static NotificationManagerCompat mgr = NotificationManagerCompat.from(App.self); diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/ProgressNotification.java b/app/src/main/java/com/topjohnwu/magisk/view/ProgressNotification.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/ProgressNotification.java rename to app/src/main/java/com/topjohnwu/magisk/view/ProgressNotification.java index 19b1ddcd7..a7ff7721d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/ProgressNotification.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/ProgressNotification.java @@ -1,17 +1,17 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.app.Notification; import android.app.PendingIntent; import android.content.Intent; import android.widget.Toast; -import androidx.core.app.NotificationCompat; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.net.DownloadProgressListener; +import androidx.core.app.NotificationCompat; + public class ProgressNotification implements DownloadProgressListener { private NotificationCompat.Builder builder; diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/SafetyNet.java b/app/src/main/java/com/topjohnwu/magisk/view/SafetyNet.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/SafetyNet.java rename to app/src/main/java/com/topjohnwu/magisk/view/SafetyNet.java index 8b08d9674..8796bac8d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/SafetyNet.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/SafetyNet.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.app.Activity; import android.content.Context; @@ -10,19 +10,18 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; -import androidx.annotation.StringRes; -import androidx.cardview.widget.CardView; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.dialogs.CustomAlertDialog; import com.topjohnwu.magisk.utils.ISafetyNetHelper; +import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog; import com.topjohnwu.net.Networking; import com.topjohnwu.superuser.Shell; import java.io.File; +import androidx.annotation.StringRes; +import androidx.cardview.widget.CardView; import butterknife.BindColor; import butterknife.BindView; import butterknife.OnClick; diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/Shortcuts.java b/app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/Shortcuts.java rename to app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.java index a0c313556..ba841564c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/Shortcuts.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.content.Context; import android.content.Intent; @@ -7,18 +7,18 @@ import android.content.pm.ShortcutManager; import android.graphics.drawable.Icon; import android.os.Build; -import androidx.annotation.RequiresApi; - import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.SplashActivity; +import com.topjohnwu.magisk.ui.SplashActivity; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import java.util.ArrayList; +import androidx.annotation.RequiresApi; + public class Shortcuts { public static void setup(Context context) { diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/SnackbarMaker.java b/app/src/main/java/com/topjohnwu/magisk/view/SnackbarMaker.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/SnackbarMaker.java rename to app/src/main/java/com/topjohnwu/magisk/view/SnackbarMaker.java index 431eb2221..dc0f1ca61 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/SnackbarMaker.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/SnackbarMaker.java @@ -1,16 +1,16 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.app.Activity; import android.net.Uri; import android.view.View; import android.widget.TextView; -import androidx.annotation.StringRes; - import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Utils; +import androidx.annotation.StringRes; + public class SnackbarMaker { public static Snackbar make(Activity activity, CharSequence text, int duration) { diff --git a/app/src/main/java/com/topjohnwu/magisk/uicomponents/UpdateCardHolder.java b/app/src/main/java/com/topjohnwu/magisk/view/UpdateCardHolder.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/uicomponents/UpdateCardHolder.java rename to app/src/main/java/com/topjohnwu/magisk/view/UpdateCardHolder.java index 03486deee..3e657e458 100644 --- a/app/src/main/java/com/topjohnwu/magisk/uicomponents/UpdateCardHolder.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/UpdateCardHolder.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.uicomponents; +package com.topjohnwu.magisk.view; import android.view.LayoutInflater; import android.view.View; diff --git a/app/src/main/java/com/topjohnwu/magisk/dialogs/CustomAlertDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/CustomAlertDialog.java similarity index 99% rename from app/src/main/java/com/topjohnwu/magisk/dialogs/CustomAlertDialog.java rename to app/src/main/java/com/topjohnwu/magisk/view/dialogs/CustomAlertDialog.java index e45ea5cdd..4c6919a33 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialogs/CustomAlertDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/CustomAlertDialog.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.dialogs; +package com.topjohnwu.magisk.view.dialogs; import android.app.Activity; import android.content.DialogInterface; @@ -8,14 +8,13 @@ import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; +import com.topjohnwu.magisk.R; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.annotation.StyleRes; import androidx.appcompat.app.AlertDialog; - -import com.topjohnwu.magisk.R; - import butterknife.BindView; public class CustomAlertDialog extends AlertDialog.Builder { diff --git a/app/src/main/java/com/topjohnwu/magisk/dialogs/EnvFixDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.java similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/dialogs/EnvFixDialog.java rename to app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.java index 9c7328bba..95e1364b6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialogs/EnvFixDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.java @@ -1,11 +1,9 @@ -package com.topjohnwu.magisk.dialogs; +package com.topjohnwu.magisk.view.dialogs; import android.app.Activity; import android.app.ProgressDialog; import android.widget.Toast; -import androidx.annotation.NonNull; - import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.tasks.MagiskInstaller; import com.topjohnwu.magisk.utils.RootUtils; @@ -14,6 +12,8 @@ import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.internal.UiThreadHandler; import com.topjohnwu.superuser.io.SuFile; +import androidx.annotation.NonNull; + public class EnvFixDialog extends CustomAlertDialog { public EnvFixDialog(@NonNull Activity activity) { diff --git a/app/src/main/java/com/topjohnwu/magisk/dialogs/FingerprintAuthDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java similarity index 98% rename from app/src/main/java/com/topjohnwu/magisk/dialogs/FingerprintAuthDialog.java rename to app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java index 725e1f54d..d9f7642e2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialogs/FingerprintAuthDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.dialogs; +package com.topjohnwu.magisk.view.dialogs; import android.annotation.TargetApi; import android.app.Activity; @@ -11,13 +11,13 @@ import android.os.Build; import android.view.Gravity; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; - import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.Utils; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; + @TargetApi(Build.VERSION_CODES.M) public class FingerprintAuthDialog extends CustomAlertDialog { diff --git a/app/src/main/java/com/topjohnwu/magisk/dialogs/InstallMethodDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/InstallMethodDialog.java similarity index 93% rename from app/src/main/java/com/topjohnwu/magisk/dialogs/InstallMethodDialog.java rename to app/src/main/java/com/topjohnwu/magisk/view/dialogs/InstallMethodDialog.java index 83c3acf7b..6b2970c1f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialogs/InstallMethodDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/InstallMethodDialog.java @@ -1,26 +1,26 @@ -package com.topjohnwu.magisk.dialogs; +package com.topjohnwu.magisk.view.dialogs; import android.app.Activity; import android.content.Intent; import android.widget.Toast; -import androidx.appcompat.app.AlertDialog; - import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.uicomponents.ProgressNotification; -import com.topjohnwu.magisk.uicomponents.SnackbarMaker; +import com.topjohnwu.magisk.ui.base.BaseActivity; +import com.topjohnwu.magisk.ui.flash.FlashActivity; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.ProgressNotification; +import com.topjohnwu.magisk.view.SnackbarMaker; import com.topjohnwu.net.Networking; import java.io.File; import java.util.List; +import androidx.appcompat.app.AlertDialog; + class InstallMethodDialog extends AlertDialog.Builder { InstallMethodDialog(BaseActivity activity, List options) { diff --git a/app/src/main/java/com/topjohnwu/magisk/dialogs/MagiskInstallDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/MagiskInstallDialog.java similarity index 92% rename from app/src/main/java/com/topjohnwu/magisk/dialogs/MagiskInstallDialog.java rename to app/src/main/java/com/topjohnwu/magisk/view/dialogs/MagiskInstallDialog.java index 681aab0d3..64426c656 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialogs/MagiskInstallDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/MagiskInstallDialog.java @@ -1,13 +1,13 @@ -package com.topjohnwu.magisk.dialogs; +package com.topjohnwu.magisk.view.dialogs; import android.net.Uri; import android.text.TextUtils; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.uicomponents.MarkDownWindow; +import com.topjohnwu.magisk.ui.base.BaseActivity; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.MarkDownWindow; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.ShellUtils; diff --git a/app/src/main/java/com/topjohnwu/magisk/dialogs/ManagerInstallDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/ManagerInstallDialog.java similarity index 91% rename from app/src/main/java/com/topjohnwu/magisk/dialogs/ManagerInstallDialog.java rename to app/src/main/java/com/topjohnwu/magisk/view/dialogs/ManagerInstallDialog.java index d13d5372f..debb76719 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialogs/ManagerInstallDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/ManagerInstallDialog.java @@ -1,15 +1,15 @@ -package com.topjohnwu.magisk.dialogs; +package com.topjohnwu.magisk.view.dialogs; import android.app.Activity; import android.text.TextUtils; -import androidx.annotation.NonNull; - import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.uicomponents.MarkDownWindow; import com.topjohnwu.magisk.utils.DownloadApp; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.MarkDownWindow; + +import androidx.annotation.NonNull; public class ManagerInstallDialog extends CustomAlertDialog { diff --git a/app/src/main/java/com/topjohnwu/magisk/dialogs/UninstallDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/UninstallDialog.java similarity index 93% rename from app/src/main/java/com/topjohnwu/magisk/dialogs/UninstallDialog.java rename to app/src/main/java/com/topjohnwu/magisk/view/dialogs/UninstallDialog.java index 8460e314f..4fae38407 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialogs/UninstallDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/UninstallDialog.java @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.dialogs; +package com.topjohnwu.magisk.view.dialogs; import android.app.Activity; import android.app.ProgressDialog; @@ -7,20 +7,20 @@ import android.net.Uri; import android.text.TextUtils; import android.widget.Toast; -import androidx.annotation.NonNull; - import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.uicomponents.ProgressNotification; +import com.topjohnwu.magisk.ui.flash.FlashActivity; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.view.ProgressNotification; import com.topjohnwu.net.Networking; import com.topjohnwu.superuser.Shell; import java.io.File; +import androidx.annotation.NonNull; + public class UninstallDialog extends CustomAlertDialog { public UninstallDialog(@NonNull Activity activity) { From e035523eb8e30d2af53b1c7b47e6fddcbd863f0b Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Apr 2019 18:52:30 +0200 Subject: [PATCH 04/66] Added base framework --- app/build.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index cfda68a6e..e4e77b7a3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,4 +63,13 @@ dependencies { def butterKnifeVersion = '10.1.0' implementation "com.jakewharton:butterknife-runtime:${butterKnifeVersion}" kapt "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" + + implementation ("com.github.skoumalcz:teanity:0.3.3") { + exclude group: 'com.karumi', module: 'dexter' + exclude group: 'com.evernote', module: 'android-state' + exclude group: 'androidx.work', module: 'work-runtime-ktx' + exclude group: 'androidx.room', module: 'room-runtime' + exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin' //hopefully not forever + exclude group: 'io.reactivex.rxjava2', module: 'rxandroid' //hopefully not forever + } } From 2d58c725e085eeb31914562ff36c31fa252274b2 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Apr 2019 20:01:49 +0200 Subject: [PATCH 05/66] Added koin, databinding and navigation components Converted App class and Main activity to Kotlin. With that refactored fields within App class to allow lazy initialization BEWARE: at this point the navigation is very much broken, won't let you anywhere beyond home screen --- app/build.gradle | 15 +- .../main/java/com/topjohnwu/magisk/App.java | 101 --------- app/src/main/java/com/topjohnwu/magisk/App.kt | 120 +++++++++++ .../java/com/topjohnwu/magisk/Config.java | 48 ++--- .../topjohnwu/magisk/di/ApplicationModule.kt | 11 + .../com/topjohnwu/magisk/di/DatabaseModule.kt | 6 + .../com/topjohnwu/magisk/di/MiscModule.kt | 10 + .../java/com/topjohnwu/magisk/di/Modules.kt | 10 + .../topjohnwu/magisk/di/NetworkingModule.kt | 6 + .../topjohnwu/magisk/di/RepositoryModule.kt | 6 + .../topjohnwu/magisk/di/ViewModelsModule.kt | 10 + .../magisk/model/navigation/Navigation.kt | 4 + .../model/receiver/GeneralReceiver.java | 4 +- .../com/topjohnwu/magisk/ui/MainActivity.java | 193 ------------------ .../com/topjohnwu/magisk/ui/MainActivity.kt | 166 +++++++++++++++ .../com/topjohnwu/magisk/ui/MainViewModel.kt | 6 + .../magisk/ui/base/BaseActivity.java | 2 +- .../ui/base/BasePreferenceFragment.java | 4 +- .../magisk/ui/base/MagiskActivity.kt | 8 + .../magisk/ui/base/MagiskFragment.kt | 8 + .../magisk/ui/base/MagiskViewModel.kt | 6 + .../topjohnwu/magisk/ui/log/LogFragment.java | 6 +- .../magisk/ui/log/SuLogFragment.java | 4 +- .../magisk/ui/settings/SettingsFragment.java | 8 +- .../ui/superuser/SuperuserFragment.java | 4 +- .../ui/surequest/SuRequestActivity.java | 6 +- .../com/topjohnwu/magisk/utils/SuLogger.java | 4 +- app/src/main/res/layout/activity_main.xml | 57 +++--- .../main/res/layout/activity_main_content.xml | 40 ++++ app/src/main/res/layout/toolbar.xml | 7 +- .../main/res/navigation/navigation_main.xml | 14 ++ build.gradle | 10 +- 32 files changed, 524 insertions(+), 380 deletions(-) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/App.java create mode 100644 app/src/main/java/com/topjohnwu/magisk/App.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/di/Modules.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt create mode 100644 app/src/main/res/layout/activity_main_content.xml create mode 100644 app/src/main/res/navigation/navigation_main.xml diff --git a/app/build.gradle b/app/build.gradle index e4e77b7a3..84ac3affd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,6 +30,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + + dataBinding { + enabled = true + } } dependencies { @@ -64,12 +68,13 @@ dependencies { implementation "com.jakewharton:butterknife-runtime:${butterKnifeVersion}" kapt "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" - implementation ("com.github.skoumalcz:teanity:0.3.3") { - exclude group: 'com.karumi', module: 'dexter' - exclude group: 'com.evernote', module: 'android-state' + def koin = "2.0.0-rc-2" + implementation("org.koin:koin-core:${koin}") + implementation("org.koin:koin-android:${koin}") + implementation("org.koin:koin-androidx-viewmodel:${koin}") + + implementation("com.github.skoumalcz:teanity:0.3.3") { exclude group: 'androidx.work', module: 'work-runtime-ktx' exclude group: 'androidx.room', module: 'room-runtime' - exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin' //hopefully not forever - exclude group: 'io.reactivex.rxjava2', module: 'rxandroid' //hopefully not forever } } diff --git a/app/src/main/java/com/topjohnwu/magisk/App.java b/app/src/main/java/com/topjohnwu/magisk/App.java deleted file mode 100644 index 179419249..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/App.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.topjohnwu.magisk; - -import android.app.Activity; -import android.app.Application; -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.preference.PreferenceManager; - -import com.topjohnwu.magisk.data.database.MagiskDB; -import com.topjohnwu.magisk.data.database.RepoDatabaseHelper; -import com.topjohnwu.magisk.ui.base.BaseActivity; -import com.topjohnwu.magisk.utils.LocaleManager; -import com.topjohnwu.magisk.utils.RootUtils; -import com.topjohnwu.net.Networking; -import com.topjohnwu.superuser.Shell; - -import java.util.concurrent.ThreadPoolExecutor; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatDelegate; - -public class App extends Application implements Application.ActivityLifecycleCallbacks { - - public static App self; - public static Context deContext; - public static ThreadPoolExecutor THREAD_POOL; - - // Global resources - public SharedPreferences prefs; - public MagiskDB mDB; - public RepoDatabaseHelper repoDB; - private volatile BaseActivity foreground; - - static { - AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); - Shell.Config.setFlags(Shell.FLAG_MOUNT_MASTER | Shell.FLAG_USE_MAGISK_BUSYBOX); - Shell.Config.verboseLogging(BuildConfig.DEBUG); - Shell.Config.addInitializers(RootUtils.class); - Shell.Config.setTimeout(2); - THREAD_POOL = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR; - } - - @Override - protected void attachBaseContext(Context base) { - super.attachBaseContext(base); - self = this; - deContext = base; - registerActivityLifecycleCallbacks(this); - - if (Build.VERSION.SDK_INT >= 24) { - deContext = base.createDeviceProtectedStorageContext(); - deContext.moveSharedPreferencesFrom(base, - PreferenceManager.getDefaultSharedPreferencesName(base)); - } - prefs = PreferenceManager.getDefaultSharedPreferences(deContext); - mDB = new MagiskDB(base); - - Networking.init(base); - LocaleManager.setLocale(this); - } - - @Override - public void onConfigurationChanged(@NonNull Configuration newConfig) { - super.onConfigurationChanged(newConfig); - LocaleManager.setLocale(this); - } - - public static BaseActivity foreground() { - return self.foreground; - } - - @Override - public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {} - - @Override - public void onActivityStarted(@NonNull Activity activity) {} - - @Override - public synchronized void onActivityResumed(@NonNull Activity activity) { - foreground = (BaseActivity) activity; - } - - @Override - public synchronized void onActivityPaused(@NonNull Activity activity) { - foreground = null; - } - - @Override - public void onActivityStopped(@NonNull Activity activity) {} - - @Override - public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {} - - @Override - public void onActivityDestroyed(@NonNull Activity activity) {} -} diff --git a/app/src/main/java/com/topjohnwu/magisk/App.kt b/app/src/main/java/com/topjohnwu/magisk/App.kt new file mode 100644 index 000000000..2d9b5d679 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/App.kt @@ -0,0 +1,120 @@ +package com.topjohnwu.magisk + +import android.annotation.SuppressLint +import android.app.Activity +import android.app.Application +import android.content.Context +import android.content.SharedPreferences +import android.content.res.Configuration +import android.os.AsyncTask +import android.os.Build +import android.os.Bundle +import android.preference.PreferenceManager +import androidx.appcompat.app.AppCompatDelegate +import com.topjohnwu.magisk.data.database.MagiskDB +import com.topjohnwu.magisk.data.database.RepoDatabaseHelper +import com.topjohnwu.magisk.di.koinModules +import com.topjohnwu.magisk.utils.LocaleManager +import com.topjohnwu.magisk.utils.RootUtils +import com.topjohnwu.net.Networking +import com.topjohnwu.superuser.Shell +import org.koin.android.ext.koin.androidContext +import org.koin.core.context.startKoin +import java.util.concurrent.ThreadPoolExecutor + +open class App : Application(), Application.ActivityLifecycleCallbacks { + + // Global resources + val prefs: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deContext) } + val DB: MagiskDB by lazy { MagiskDB(deContext) } + @JvmField + var repoDB: RepoDatabaseHelper? = null + @Volatile + private var foreground: Activity? = null + + override fun onCreate() { + super.onCreate() + + startKoin { + androidContext(this@App) + modules(koinModules) + } + } + + override fun attachBaseContext(base: Context) { + super.attachBaseContext(base) + self = this + deContext = base + registerActivityLifecycleCallbacks(this) + + if (Build.VERSION.SDK_INT >= 24) { + deContext = base.createDeviceProtectedStorageContext() + deContext.moveSharedPreferencesFrom( + base, + PreferenceManager.getDefaultSharedPreferencesName(base) + ) + } + + Networking.init(base) + LocaleManager.setLocale(this) + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + LocaleManager.setLocale(this) + } + + //region ActivityLifecycleCallbacks + override fun onActivityCreated(activity: Activity, bundle: Bundle?) {} + + override fun onActivityStarted(activity: Activity) {} + + @Synchronized + override fun onActivityResumed(activity: Activity) { + foreground = activity + } + + @Synchronized + override fun onActivityPaused(activity: Activity) { + foreground = null + } + + override fun onActivityStopped(activity: Activity) {} + + override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {} + + override fun onActivityDestroyed(activity: Activity) {} + //endregion + + companion object { + + //fixme this should be at least weak reference, me no likey + @SuppressLint("StaticFieldLeak") + @JvmStatic + lateinit var self: App + + //fixme this should be at least weak reference, me no likey + @SuppressLint("StaticFieldLeak") + @JvmStatic + lateinit var deContext: Context + + //fixme me no likey + @JvmField + var THREAD_POOL: ThreadPoolExecutor + + init { + AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) + Shell.Config.setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_USE_MAGISK_BUSYBOX) + Shell.Config.verboseLogging(BuildConfig.DEBUG) + Shell.Config.addInitializers(RootUtils::class.java) + Shell.Config.setTimeout(2) + THREAD_POOL = AsyncTask.THREAD_POOL_EXECUTOR as ThreadPoolExecutor + } + + //fixme me no likey + @JvmStatic + fun foreground(): Activity? { + return self.foreground + } + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/Config.java b/app/src/main/java/com/topjohnwu/magisk/Config.java index 10f4119ea..76f4580ba 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Config.java +++ b/app/src/main/java/com/topjohnwu/magisk/Config.java @@ -3,8 +3,6 @@ package com.topjohnwu.magisk; import android.content.SharedPreferences; import android.util.Xml; -import androidx.collection.ArrayMap; - import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.ShellUtils; @@ -17,6 +15,8 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.File; import java.io.IOException; +import androidx.collection.ArrayMap; + public class Config { // Current status @@ -109,14 +109,14 @@ public class Config { public static void export() { // Flush prefs to disk App app = App.self; - app.prefs.edit().commit(); + app.getPrefs().edit().commit(); File xml = new File(App.deContext.getFilesDir().getParent() + "/shared_prefs", app.getPackageName() + "_preferences.xml"); Shell.su(Utils.fmt("cat %s > /data/adb/%s", xml, Const.MANAGER_CONFIGS)).exec(); } public static void initialize() { - SharedPreferences pref = App.self.prefs; + SharedPreferences pref = App.self.getPrefs(); SharedPreferences.Editor editor = pref.edit(); File config = SuFile.open("/data/adb", Const.MANAGER_CONFIGS); if (config.exists()) { @@ -238,19 +238,19 @@ public class Config { App app = App.self; switch (getConfigType(key)) { case PREF_INT: - return (T) (Integer) app.prefs.getInt(key, getDef(key)); + return (T) (Integer) app.getPrefs().getInt(key, getDef(key)); case PREF_STR_INT: - return (T) (Integer) Utils.getPrefsInt(app.prefs, key, getDef(key)); + return (T) (Integer) Utils.getPrefsInt(app.getPrefs(), key, getDef(key)); case PREF_BOOL: - return (T) (Boolean) app.prefs.getBoolean(key, getDef(key)); + return (T) (Boolean) app.getPrefs().getBoolean(key, getDef(key)); case PREF_STR: - return (T) app.prefs.getString(key, getDef(key)); + return (T) app.getPrefs().getString(key, getDef(key)); case DB_INT: - return (T) (Integer) app.mDB.getSettings(key, getDef(key)); + return (T) (Integer) app.getDB().getSettings(key, getDef(key)); case DB_BOOL: - return (T) (Boolean) (app.mDB.getSettings(key, getDef(key) ? 1 : 0) != 0); + return (T) (Boolean) (app.getDB().getSettings(key, getDef(key) ? 1 : 0) != 0); case DB_STR: - return (T) app.mDB.getStrings(key, getDef(key)); + return (T) app.getDB().getStrings(key, getDef(key)); } /* Will never get here (IllegalArgumentException in getConfigType) */ return null; @@ -260,25 +260,25 @@ public class Config { App app = App.self; switch (getConfigType(key)) { case PREF_INT: - app.prefs.edit().putInt(key, (int) val).apply(); + app.getPrefs().edit().putInt(key, (int) val).apply(); break; case PREF_STR_INT: - app.prefs.edit().putString(key, String.valueOf(val)).apply(); + app.getPrefs().edit().putString(key, String.valueOf(val)).apply(); break; case PREF_BOOL: - app.prefs.edit().putBoolean(key, (boolean) val).apply(); + app.getPrefs().edit().putBoolean(key, (boolean) val).apply(); break; case PREF_STR: - app.prefs.edit().putString(key, (String) val).apply(); + app.getPrefs().edit().putString(key, (String) val).apply(); break; case DB_INT: - app.mDB.setSettings(key, (int) val); + app.getDB().setSettings(key, (int) val); break; case DB_BOOL: - app.mDB.setSettings(key, (boolean) val ? 1 : 0); + app.getDB().setSettings(key, (boolean) val ? 1 : 0); break; case DB_STR: - app.mDB.setStrings(key, (String) val); + app.getDB().setStrings(key, (String) val); break; } } @@ -290,14 +290,14 @@ public class Config { case PREF_STR_INT: case PREF_BOOL: case PREF_STR: - app.prefs.edit().remove(key).apply(); + app.getPrefs().edit().remove(key).apply(); break; case DB_BOOL: case DB_INT: - app.mDB.rmSettings(key); + app.getDB().rmSettings(key); break; case DB_STR: - app.mDB.setStrings(key, null); + app.getDB().setStrings(key, null); break; } } @@ -365,13 +365,13 @@ public class Config { switch (type) { case DB_INT: editor.putString(key, String.valueOf( - app.mDB.getSettings(key, (Integer) defs.get(key)))); + app.getDB().getSettings(key, (Integer) defs.get(key)))); continue; case DB_STR: - editor.putString(key, app.mDB.getStrings(key, (String) defs.get(key))); + editor.putString(key, app.getDB().getStrings(key, (String) defs.get(key))); continue; case DB_BOOL: - int bs = app.mDB.getSettings(key, -1); + int bs = app.getDB().getSettings(key, -1); editor.putBoolean(key, bs < 0 ? (Boolean) defs.get(key) : bs != 0); continue; } diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt new file mode 100644 index 000000000..09fd26d68 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt @@ -0,0 +1,11 @@ +package com.topjohnwu.magisk.di + +import android.content.Context +import com.skoumal.teanity.rxbus.RxBus +import org.koin.dsl.module + + +val applicationModule = module { + single { RxBus() } + single { get().resources } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt new file mode 100644 index 000000000..b3c44dc0d --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt @@ -0,0 +1,6 @@ +package com.topjohnwu.magisk.di + +import org.koin.dsl.module + + +val databaseModule = module {} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt new file mode 100644 index 000000000..037a9edd6 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt @@ -0,0 +1,10 @@ +package com.topjohnwu.magisk.di + +import org.koin.dsl.module + + +val miscModule = module { + + // define miscs here + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/Modules.kt b/app/src/main/java/com/topjohnwu/magisk/di/Modules.kt new file mode 100644 index 000000000..850e09c88 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/di/Modules.kt @@ -0,0 +1,10 @@ +package com.topjohnwu.magisk.di + +val koinModules = listOf( + applicationModule, + networkingModule, + databaseModule, + repositoryModule, + viewModelModules, + miscModule +) diff --git a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt new file mode 100644 index 000000000..e3cd89d17 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt @@ -0,0 +1,6 @@ +package com.topjohnwu.magisk.di + +import org.koin.dsl.module + + +val networkingModule = module {} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt new file mode 100644 index 000000000..0d55b410c --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt @@ -0,0 +1,6 @@ +package com.topjohnwu.magisk.di + +import org.koin.dsl.module + + +val repositoryModule = module {} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt new file mode 100644 index 000000000..523a7bdfc --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt @@ -0,0 +1,10 @@ +package com.topjohnwu.magisk.di + +import com.topjohnwu.magisk.ui.MainViewModel +import org.koin.androidx.viewmodel.dsl.viewModel +import org.koin.dsl.module + + +val viewModelModules = module { + viewModel { MainViewModel() } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt new file mode 100644 index 000000000..133bb88fe --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt @@ -0,0 +1,4 @@ +package com.topjohnwu.magisk.model.navigation + + +object Navigation diff --git a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.java b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.java index dd71c7f09..0a7432c4d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.java @@ -61,12 +61,12 @@ public class GeneralReceiver extends BroadcastReceiver { case Intent.ACTION_PACKAGE_REPLACED: // This will only work pre-O if (Config.get(Config.Key.SU_REAUTH)) { - app.mDB.deletePolicy(getPkg(intent)); + app.getDB().deletePolicy(getPkg(intent)); } break; case Intent.ACTION_PACKAGE_FULLY_REMOVED: String pkg = getPkg(intent); - app.mDB.deletePolicy(pkg); + app.getDB().deletePolicy(pkg); Shell.su("magiskhide --rm " + pkg).submit(); break; case Intent.ACTION_LOCALE_CHANGED: diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java deleted file mode 100644 index 3da71cf37..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.topjohnwu.magisk.ui; - -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import com.google.android.material.navigation.NavigationView; -import com.topjohnwu.magisk.ClassMap; -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ui.base.BaseActivity; -import com.topjohnwu.magisk.ui.hide.MagiskHideFragment; -import com.topjohnwu.magisk.ui.home.MagiskFragment; -import com.topjohnwu.magisk.ui.log.LogFragment; -import com.topjohnwu.magisk.ui.module.ModulesFragment; -import com.topjohnwu.magisk.ui.module.ReposFragment; -import com.topjohnwu.magisk.ui.settings.SettingsFragment; -import com.topjohnwu.magisk.ui.superuser.SuperuserFragment; -import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.net.Networking; -import com.topjohnwu.superuser.Shell; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.ActionBarDrawerToggle; -import androidx.appcompat.widget.Toolbar; -import androidx.drawerlayout.widget.DrawerLayout; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentTransaction; -import butterknife.BindView; - -public class MainActivity extends BaseActivity - implements NavigationView.OnNavigationItemSelectedListener { - - private final Handler mDrawerHandler = new Handler(); - private int mDrawerItem; - private static boolean fromShortcut = false; - - @BindView(R.id.toolbar) public Toolbar toolbar; - @BindView(R.id.drawer_layout) DrawerLayout drawer; - @BindView(R.id.nav_view) NavigationView navigationView; - - private float toolbarElevation; - - @Override - public int getDarkTheme() { - return R.style.AppTheme_Dark; - } - - @Override - protected void onCreate(final Bundle savedInstanceState) { - if (!SplashActivity.DONE) { - startActivity(new Intent(this, ClassMap.get(SplashActivity.class))); - finish(); - } - - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - new MainActivity_ViewBinding(this); - checkHideSection(); - setSupportActionBar(toolbar); - - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.magisk, R.string.magisk) { - @Override - public void onDrawerOpened(View drawerView) { - super.onDrawerOpened(drawerView); - super.onDrawerSlide(drawerView, 0); // this disables the arrow @ completed tate - } - - @Override - public void onDrawerSlide(View drawerView, float slideOffset) { - super.onDrawerSlide(drawerView, 0); // this disables the animation - } - }; - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - toolbarElevation = toolbar.getElevation(); - } - - drawer.addDrawerListener(toggle); - toggle.syncState(); - - if (savedInstanceState == null) { - String section = getIntent().getStringExtra(Const.Key.OPEN_SECTION); - fromShortcut = section != null; - navigate(section); - } - - navigationView.setNavigationItemSelectedListener(this); - } - - @Override - public void onBackPressed() { - if (drawer.isDrawerOpen(navigationView)) { - drawer.closeDrawer(navigationView); - } else if (mDrawerItem != R.id.magisk && !fromShortcut) { - navigate(R.id.magisk); - } else { - finish(); - } - } - - @Override - public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) { - mDrawerHandler.removeCallbacksAndMessages(null); - mDrawerHandler.postDelayed(() -> navigate(menuItem.getItemId()), 250); - drawer.closeDrawer(navigationView); - return true; - } - - public void checkHideSection() { - Menu menu = navigationView.getMenu(); - menu.findItem(R.id.magiskhide).setVisible(Shell.rootAccess() && - (boolean) Config.get(Config.Key.MAGISKHIDE)); - menu.findItem(R.id.modules).setVisible(Shell.rootAccess() && Config.magiskVersionCode >= 0); - menu.findItem(R.id.downloads).setVisible(Networking.checkNetworkStatus(this) - && Shell.rootAccess() && Config.magiskVersionCode >= 0); - menu.findItem(R.id.log).setVisible(Shell.rootAccess()); - menu.findItem(R.id.superuser).setVisible(Utils.showSuperUser()); - } - - public void navigate(String item) { - int itemId = R.id.magisk; - if (item != null) { - switch (item) { - case "superuser": - itemId = R.id.superuser; - break; - case "modules": - itemId = R.id.modules; - break; - case "downloads": - itemId = R.id.downloads; - break; - case "magiskhide": - itemId = R.id.magiskhide; - break; - case "log": - itemId = R.id.log; - break; - case "settings": - itemId = R.id.settings; - break; - } - } - navigate(itemId); - } - - public void navigate(int itemId) { - mDrawerItem = itemId; - navigationView.setCheckedItem(itemId); - switch (itemId) { - case R.id.magisk: - fromShortcut = false; - displayFragment(new MagiskFragment(), true); - break; - case R.id.superuser: - displayFragment(new SuperuserFragment(), true); - break; - case R.id.modules: - displayFragment(new ModulesFragment(), true); - break; - case R.id.downloads: - displayFragment(new ReposFragment(), true); - break; - case R.id.magiskhide: - displayFragment(new MagiskHideFragment(), true); - break; - case R.id.log: - displayFragment(new LogFragment(), false); - break; - case R.id.settings: - displayFragment(new SettingsFragment(), true); - break; - } - } - - private void displayFragment(@NonNull Fragment navFragment, boolean setElevation) { - supportInvalidateOptionsMenu(); - getSupportFragmentManager() - .beginTransaction() - .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) - .replace(R.id.content_frame, navFragment) - .commitNow(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - toolbar.setElevation(setElevation ? toolbarElevation : 0); - } - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt new file mode 100644 index 000000000..33040ba88 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -0,0 +1,166 @@ +package com.topjohnwu.magisk.ui + +import android.content.Intent +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.view.MenuItem +import android.view.View +import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.fragment.app.Fragment +import com.google.android.material.navigation.NavigationView +import com.topjohnwu.magisk.ClassMap +import com.topjohnwu.magisk.Config +import com.topjohnwu.magisk.Const +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.databinding.ActivityMainBinding +import com.topjohnwu.magisk.ui.base.MagiskActivity +import com.topjohnwu.magisk.ui.hide.MagiskHideFragment +import com.topjohnwu.magisk.ui.home.MagiskFragment +import com.topjohnwu.magisk.ui.log.LogFragment +import com.topjohnwu.magisk.ui.module.ModulesFragment +import com.topjohnwu.magisk.ui.module.ReposFragment +import com.topjohnwu.magisk.ui.settings.SettingsFragment +import com.topjohnwu.magisk.ui.superuser.SuperuserFragment +import com.topjohnwu.magisk.utils.Utils +import com.topjohnwu.net.Networking +import com.topjohnwu.superuser.Shell +import kotlinx.android.synthetic.main.toolbar.* +import org.koin.androidx.viewmodel.ext.android.viewModel + +open class MainActivity : MagiskActivity(), + NavigationView.OnNavigationItemSelectedListener { + + override val layoutRes: Int = R.layout.activity_main + override val viewModel: MainViewModel by viewModel() + override val navHostId: Int = R.id.main_nav_host + + private val mDrawerHandler = Handler() + private var mDrawerItem: Int = 0 + private var toolbarElevation: Float = 0.toFloat() + + /*override fun getDarkTheme(): Int { + return R.style.AppTheme_Dark + }*/ + + override fun onCreate(savedInstanceState: Bundle?) { + if (!SplashActivity.DONE) { + startActivity(Intent(this, ClassMap.get(SplashActivity::class.java))) + finish() + } + + super.onCreate(savedInstanceState) + checkHideSection() + setSupportActionBar(toolbar) + + val toggle = object : + ActionBarDrawerToggle( + this, + binding.drawerLayout, + toolbar, + R.string.magisk, + R.string.magisk + ) { + override fun onDrawerOpened(drawerView: View) { + super.onDrawerOpened(drawerView) + super.onDrawerSlide(drawerView, 0f) // this disables the arrow @ completed tate + } + + override fun onDrawerSlide(drawerView: View, slideOffset: Float) { + super.onDrawerSlide(drawerView, 0f) // this disables the animation + } + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + toolbarElevation = toolbar!!.elevation + } + + binding.drawerLayout.addDrawerListener(toggle) + toggle.syncState() + + if (savedInstanceState == null) { + val section = intent.getStringExtra(Const.Key.OPEN_SECTION) + fromShortcut = section != null + navigate(section) + } + + binding.navView.setNavigationItemSelectedListener(this) + } + + override fun onBackPressed() { + if (binding.drawerLayout.isDrawerOpen(binding.navView)) { + binding.drawerLayout.closeDrawer(binding.navView) + } else if (mDrawerItem != R.id.magisk && !fromShortcut) { + navigate(R.id.magisk) + } else { + finish() + } + } + + override fun onNavigationItemSelected(menuItem: MenuItem): Boolean { + mDrawerHandler.removeCallbacksAndMessages(null) + mDrawerHandler.postDelayed({ navigate(menuItem.itemId) }, 250) + binding.drawerLayout.closeDrawer(binding.navView) + return true + } + + fun checkHideSection() { + val menu = binding.navView.menu + menu.findItem(R.id.magiskhide).isVisible = + Shell.rootAccess() && Config.get(Config.Key.MAGISKHIDE) as Boolean + menu.findItem(R.id.modules).isVisible = Shell.rootAccess() && Config.magiskVersionCode >= 0 + menu.findItem(R.id.downloads).isVisible = (Networking.checkNetworkStatus(this) + && Shell.rootAccess() && Config.magiskVersionCode >= 0) + menu.findItem(R.id.log).isVisible = Shell.rootAccess() + menu.findItem(R.id.superuser).isVisible = Utils.showSuperUser() + } + + fun navigate(item: String?) { + var itemId = R.id.magisk + if (item != null) { + when (item) { + "superuser" -> itemId = R.id.superuser + "modules" -> itemId = R.id.modules + "downloads" -> itemId = R.id.downloads + "magiskhide" -> itemId = R.id.magiskhide + "log" -> itemId = R.id.log + "settings" -> itemId = R.id.settings + } + } + navigate(itemId) + } + + fun navigate(itemId: Int) { + mDrawerItem = itemId + binding.navView.setCheckedItem(itemId) + when (itemId) { + R.id.magisk -> { + fromShortcut = false + displayFragment(MagiskFragment(), true) + } + R.id.superuser -> displayFragment(SuperuserFragment(), true) + R.id.modules -> displayFragment(ModulesFragment(), true) + R.id.downloads -> displayFragment(ReposFragment(), true) + R.id.magiskhide -> displayFragment(MagiskHideFragment(), true) + R.id.log -> displayFragment(LogFragment(), false) + R.id.settings -> displayFragment(SettingsFragment(), true) + } + } + + @Deprecated("") + private fun displayFragment(navFragment: Fragment, setElevation: Boolean) { + /*supportInvalidateOptionsMenu(); + getSupportFragmentManager() + .beginTransaction() + .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) + .replace(R.id.content_frame, navFragment) + .commitNow(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + toolbar.setElevation(setElevation ? toolbarElevation : 0); + }*/ + } + + companion object { + private var fromShortcut = false + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt new file mode 100644 index 000000000..c77002d3e --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt @@ -0,0 +1,6 @@ +package com.topjohnwu.magisk.ui + +import com.topjohnwu.magisk.ui.base.MagiskViewModel + + +class MainViewModel : MagiskViewModel() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseActivity.java index ed42d5b10..8abb0602b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseActivity.java @@ -153,7 +153,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Event.Au @Override public SharedPreferences getSharedPreferences(String name, int mode) { if (TextUtils.equals(name, getPackageName() + "_preferences")) - return app.prefs; + return app.getPrefs(); return super.getSharedPreferences(name, mode); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.java index 02e04ac3e..89e072b26 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.java @@ -28,14 +28,14 @@ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); - app.prefs.registerOnSharedPreferenceChangeListener(this); + app.getPrefs().registerOnSharedPreferenceChangeListener(this); Event.register(this); return v; } @Override public void onDestroyView() { - app.prefs.unregisterOnSharedPreferenceChangeListener(this); + app.getPrefs().unregisterOnSharedPreferenceChangeListener(this); Event.unregister(this); super.onDestroyView(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt new file mode 100644 index 000000000..f93e766e0 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt @@ -0,0 +1,8 @@ +package com.topjohnwu.magisk.ui.base + +import androidx.databinding.ViewDataBinding +import com.skoumal.teanity.view.TeanityActivity + + +abstract class MagiskActivity : + TeanityActivity() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt new file mode 100644 index 000000000..024b00492 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt @@ -0,0 +1,8 @@ +package com.topjohnwu.magisk.ui.base + +import androidx.databinding.ViewDataBinding +import com.skoumal.teanity.view.TeanityFragment + + +abstract class MagiskFragment : + TeanityFragment() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt new file mode 100644 index 000000000..ca82d4039 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt @@ -0,0 +1,6 @@ +package com.topjohnwu.magisk.ui.base + +import com.skoumal.teanity.viewmodel.TeanityViewModel + + +abstract class MagiskViewModel : TeanityViewModel() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.java index d684e1d6f..871563a0b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.java @@ -1,7 +1,6 @@ package com.topjohnwu.magisk.ui.log; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -10,7 +9,6 @@ import android.view.ViewGroup; import com.google.android.material.tabs.TabLayout; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.model.adapters.TabFragmentAdapter; -import com.topjohnwu.magisk.ui.MainActivity; import com.topjohnwu.magisk.ui.base.BaseFragment; import androidx.viewpager.widget.ViewPager; @@ -28,9 +26,9 @@ public class LogFragment extends BaseFragment { View v = inflater.inflate(R.layout.fragment_log, container, false); unbinder = new LogFragment_ViewBinding(this, v); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ((MainActivity) requireActivity()).toolbar.setElevation(0); - } + }*/ TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager()); diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/log/SuLogFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/log/SuLogFragment.java index 9f6595d00..07e42adaf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/log/SuLogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/SuLogFragment.java @@ -42,7 +42,7 @@ public class SuLogFragment extends BaseFragment { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_su_log, container, false); unbinder = new SuLogFragment_ViewBinding(this, v); - adapter = new SuLogAdapter(app.mDB); + adapter = new SuLogAdapter(app.getDB()); recyclerView.setAdapter(adapter); updateList(); @@ -69,7 +69,7 @@ public class SuLogFragment extends BaseFragment { updateList(); return true; case R.id.menu_clear: - app.mDB.clearLogs(); + app.getDB().clearLogs(); updateList(); return true; default: diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java index 7938275b8..f5ec2f56d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java @@ -46,7 +46,7 @@ public class SettingsFragment extends BasePreferenceFragment { requireActivity().setTitle(R.string.settings); boolean showSuperuser = Utils.showSuperUser(); - app.prefs.edit() + app.getPrefs().edit() .putBoolean(Config.Key.SU_FINGERPRINT, FingerprintHelper.useFingerprint()) .apply(); @@ -66,7 +66,7 @@ public class SettingsFragment extends BasePreferenceFragment { return true; }); findPreference("clear").setOnPreferenceClickListener(pref -> { - app.prefs.edit().remove(Config.Key.ETAG_KEY).apply(); + app.getPrefs().edit().remove(Config.Key.ETAG_KEY).apply(); app.repoDB.clearRepo(); Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT); return true; @@ -94,7 +94,7 @@ public class SettingsFragment extends BasePreferenceFragment { if (channel == Config.Value.CUSTOM_CHANNEL) { View v = LayoutInflater.from(requireActivity()).inflate(R.layout.custom_channel_dialog, null); EditText url = v.findViewById(R.id.custom_url); - url.setText(app.prefs.getString(Config.Key.CUSTOM_CHANNEL, "")); + url.setText(app.getPrefs().getString(Config.Key.CUSTOM_CHANNEL, "")); new AlertDialog.Builder(requireActivity()) .setTitle(R.string.settings_update_custom) .setView(v) @@ -183,7 +183,7 @@ public class SettingsFragment extends BasePreferenceFragment { case Config.Key.ROOT_ACCESS: case Config.Key.SU_MULTIUSER_MODE: case Config.Key.SU_MNT_NS: - app.mDB.setSettings(key, Utils.getPrefsInt(prefs, key)); + app.getDB().setSettings(key, Utils.getPrefsInt(prefs, key)); break; case Config.Key.DARK_THEME: requireActivity().recreate(); diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java index 2f5beaf7b..a78ca91ed 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java @@ -48,13 +48,13 @@ public class SuperuserFragment extends BaseFragment { } private void displayPolicyList() { - List policyList = app.mDB.getPolicyList(); + List policyList = app.getDB().getPolicyList(); if (policyList.size() == 0) { emptyRv.setVisibility(View.VISIBLE); recyclerView.setVisibility(View.GONE); } else { - recyclerView.setAdapter(new PolicyAdapter(policyList, app.mDB, pm)); + recyclerView.setAdapter(new PolicyAdapter(policyList, app.getDB(), pm)); emptyRv.setVisibility(View.GONE); recyclerView.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.java b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.java index 481956be5..674f62c44 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.java @@ -107,8 +107,8 @@ public class SuRequestActivity extends BaseActivity { }; Bundle bundle = connector.readSocketInput(); int uid = Integer.parseInt(bundle.getString("uid")); - app.mDB.clearOutdated(); - policy = app.mDB.getPolicy(uid); + app.getDB().clearOutdated(); + policy = app.getDB().getPolicy(uid); if (policy == null) { policy = new Policy(uid, getPackageManager()); } @@ -136,7 +136,7 @@ public class SuRequestActivity extends BaseActivity { if (time >= 0) { policy.until = (time == 0) ? 0 : (System.currentTimeMillis() / 1000 + time * 60); - app.mDB.updatePolicy(policy); + app.getDB().updatePolicy(policy); } handleAction(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java index 888a65262..17d7c9286 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java @@ -37,7 +37,7 @@ public class SuLogger { } } else { // Doesn't report whether notify or not, check database ourselves - policy = app.mDB.getPolicy(fromUid); + policy = app.getDB().getPolicy(fromUid); if (policy == null) return; notify = policy.notification; @@ -62,7 +62,7 @@ public class SuLogger { log.fromPid = pid; log.command = command; log.date = new Date(); - app.mDB.addLog(log); + app.getDB().addLog(log); } private static void handleNotify(Policy policy) { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3489c737c..702fc71b1 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,35 +1,36 @@ - + xmlns:tools="http://schemas.android.com/tools"> - + + + + + + - - - - - - - - + tools:openDrawer="start"> - + + + + + + + + diff --git a/app/src/main/res/layout/activity_main_content.xml b/app/src/main/res/layout/activity_main_content.xml new file mode 100644 index 000000000..b86eafce2 --- /dev/null +++ b/app/src/main/res/layout/activity_main_content.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/toolbar.xml b/app/src/main/res/layout/toolbar.xml index f96cb2eb8..a02d7099c 100644 --- a/app/src/main/res/layout/toolbar.xml +++ b/app/src/main/res/layout/toolbar.xml @@ -1,7 +1,8 @@ - + app:elevation="4dp" /> diff --git a/app/src/main/res/navigation/navigation_main.xml b/app/src/main/res/navigation/navigation_main.xml new file mode 100644 index 000000000..ee4201d1b --- /dev/null +++ b/app/src/main/res/navigation/navigation_main.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/build.gradle b/build.gradle index 471d50845..7f770a079 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ if (configPath.exists()) configPath.withInputStream { is -> props.load(is) } buildscript { - + repositories { google() jcenter() @@ -16,8 +16,8 @@ buildscript { dependencies { classpath 'com.android.tools:r8:1.4.79' classpath 'com.android.tools.build:gradle:3.3.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21" - + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21' + classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -36,11 +36,13 @@ subprojects { repositories { google() jcenter() + maven { url "https://maven.fabric.io/public" } maven { url "https://jitpack.io" } + maven { url "http://oss.sonatype.org/content/repositories/snapshots" } } afterEvaluate { if (getPlugins().hasPlugin('com.android.library') || - getPlugins().hasPlugin('com.android.application')) { + getPlugins().hasPlugin('com.android.application')) { android { compileSdkVersion 'android-Q' buildToolsVersion '29.0.0-rc2' From 94ba7cb0c56963a33ef275a6e5b59ddddec3d60b Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Apr 2019 20:09:37 +0200 Subject: [PATCH 06/66] Added navigation endpoints --- .../magisk/model/navigation/Navigation.kt | 32 ++++++++++++++++++- .../com/topjohnwu/magisk/ui/MainActivity.kt | 2 ++ .../main/res/navigation/navigation_main.xml | 25 +++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt index 133bb88fe..a1893db53 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt @@ -1,4 +1,34 @@ package com.topjohnwu.magisk.model.navigation +import com.skoumal.teanity.viewevents.NavigationEvent +import com.topjohnwu.magisk.R -object Navigation + +object Navigation { + + fun home() = NavigationEvent { + navDirections { destination = R.id.magiskFragment } + navOptions { popUpTo = R.id.magiskFragment } + } + + fun superuser() = NavigationEvent { + navDirections { destination = R.id.superuserFragment } + } + + fun modules() = NavigationEvent { + navDirections { destination = R.id.modulesFragment } + } + + fun repos() = NavigationEvent { + navDirections { destination = R.id.reposFragment } + } + + fun hide() = NavigationEvent { + navDirections { destination = R.id.magiskHideFragment } + } + + fun log() = NavigationEvent { + navDirections { destination = R.id.logFragment } + } + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index 33040ba88..3dd4d1b08 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -115,6 +115,7 @@ open class MainActivity : MagiskActivity(), menu.findItem(R.id.superuser).isVisible = Utils.showSuperUser() } + @Deprecated("Will be replaced by navigation components") fun navigate(item: String?) { var itemId = R.id.magisk if (item != null) { @@ -130,6 +131,7 @@ open class MainActivity : MagiskActivity(), navigate(itemId) } + @Deprecated("Will be replaced by navigation components") fun navigate(itemId: Int) { mDrawerItem = itemId binding.navView.setCheckedItem(itemId) diff --git a/app/src/main/res/navigation/navigation_main.xml b/app/src/main/res/navigation/navigation_main.xml index ee4201d1b..83313cb43 100644 --- a/app/src/main/res/navigation/navigation_main.xml +++ b/app/src/main/res/navigation/navigation_main.xml @@ -10,5 +10,30 @@ android:name="com.topjohnwu.magisk.ui.home.MagiskFragment" android:label="fragment_magisk" tools:layout="@layout/fragment_magisk" /> + + + + + From 0efaddff23a1fe890b4b602c2d64a6dbffe4bbf4 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Apr 2019 21:17:54 +0200 Subject: [PATCH 07/66] Added binding between navigation view and navigation components Removed bunch of code focusing on the hamburger not being stationary --- .../magisk/model/navigation/Navigation.kt | 4 + .../com/topjohnwu/magisk/ui/MainActivity.kt | 143 +++--------------- .../com/topjohnwu/magisk/ui/MainViewModel.kt | 7 +- .../magisk/utils/DataBindingAdapters.kt | 11 ++ app/src/main/res/drawable/ic_menu.xml | 10 ++ app/src/main/res/layout/activity_main.xml | 1 + .../main/res/layout/activity_main_content.xml | 10 +- app/src/main/res/menu/drawer.xml | 12 +- 8 files changed, 70 insertions(+), 128 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt create mode 100644 app/src/main/res/drawable/ic_menu.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt index a1893db53..7a971e5f5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt @@ -31,4 +31,8 @@ object Navigation { navDirections { destination = R.id.logFragment } } + + object Main { + const val OPEN_NAV = 1 + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index 3dd4d1b08..de80683ad 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -1,44 +1,26 @@ package com.topjohnwu.magisk.ui import android.content.Intent -import android.os.Build import android.os.Bundle -import android.os.Handler -import android.view.MenuItem -import android.view.View -import androidx.appcompat.app.ActionBarDrawerToggle -import androidx.fragment.app.Fragment -import com.google.android.material.navigation.NavigationView +import androidx.core.view.GravityCompat +import androidx.navigation.ui.setupWithNavController import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.Config -import com.topjohnwu.magisk.Const import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ActivityMainBinding +import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.ui.base.MagiskActivity -import com.topjohnwu.magisk.ui.hide.MagiskHideFragment -import com.topjohnwu.magisk.ui.home.MagiskFragment -import com.topjohnwu.magisk.ui.log.LogFragment -import com.topjohnwu.magisk.ui.module.ModulesFragment -import com.topjohnwu.magisk.ui.module.ReposFragment -import com.topjohnwu.magisk.ui.settings.SettingsFragment -import com.topjohnwu.magisk.ui.superuser.SuperuserFragment import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.net.Networking import com.topjohnwu.superuser.Shell -import kotlinx.android.synthetic.main.toolbar.* import org.koin.androidx.viewmodel.ext.android.viewModel -open class MainActivity : MagiskActivity(), - NavigationView.OnNavigationItemSelectedListener { +open class MainActivity : MagiskActivity() { override val layoutRes: Int = R.layout.activity_main override val viewModel: MainViewModel by viewModel() override val navHostId: Int = R.id.main_nav_host - private val mDrawerHandler = Handler() - private var mDrawerItem: Int = 0 - private var toolbarElevation: Float = 0.toFloat() - /*override fun getDarkTheme(): Int { return R.style.AppTheme_Dark }*/ @@ -51,118 +33,39 @@ open class MainActivity : MagiskActivity(), super.onCreate(savedInstanceState) checkHideSection() - setSupportActionBar(toolbar) + setSupportActionBar(binding.mainInclude.mainToolbar) - val toggle = object : - ActionBarDrawerToggle( - this, - binding.drawerLayout, - toolbar, - R.string.magisk, - R.string.magisk - ) { - override fun onDrawerOpened(drawerView: View) { - super.onDrawerOpened(drawerView) - super.onDrawerSlide(drawerView, 0f) // this disables the arrow @ completed tate - } - - override fun onDrawerSlide(drawerView: View, slideOffset: Float) { - super.onDrawerSlide(drawerView, 0f) // this disables the animation - } - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - toolbarElevation = toolbar!!.elevation - } - - binding.drawerLayout.addDrawerListener(toggle) - toggle.syncState() - - if (savedInstanceState == null) { - val section = intent.getStringExtra(Const.Key.OPEN_SECTION) - fromShortcut = section != null - navigate(section) - } - - binding.navView.setNavigationItemSelectedListener(this) + binding.navView.setupWithNavController(navController) } override fun onBackPressed() { if (binding.drawerLayout.isDrawerOpen(binding.navView)) { binding.drawerLayout.closeDrawer(binding.navView) - } else if (mDrawerItem != R.id.magisk && !fromShortcut) { - navigate(R.id.magisk) } else { - finish() + super.onBackPressed() } } - override fun onNavigationItemSelected(menuItem: MenuItem): Boolean { - mDrawerHandler.removeCallbacksAndMessages(null) - mDrawerHandler.postDelayed({ navigate(menuItem.itemId) }, 250) - binding.drawerLayout.closeDrawer(binding.navView) - return true + override fun onSimpleEventDispatched(event: Int) { + super.onSimpleEventDispatched(event) + when (event) { + Navigation.Main.OPEN_NAV -> openNav() + } } + private fun openNav() = binding.drawerLayout.openDrawer(GravityCompat.START) + fun checkHideSection() { val menu = binding.navView.menu - menu.findItem(R.id.magiskhide).isVisible = + menu.findItem(R.id.magiskHideFragment).isVisible = Shell.rootAccess() && Config.get(Config.Key.MAGISKHIDE) as Boolean - menu.findItem(R.id.modules).isVisible = Shell.rootAccess() && Config.magiskVersionCode >= 0 - menu.findItem(R.id.downloads).isVisible = (Networking.checkNetworkStatus(this) - && Shell.rootAccess() && Config.magiskVersionCode >= 0) - menu.findItem(R.id.log).isVisible = Shell.rootAccess() - menu.findItem(R.id.superuser).isVisible = Utils.showSuperUser() - } - - @Deprecated("Will be replaced by navigation components") - fun navigate(item: String?) { - var itemId = R.id.magisk - if (item != null) { - when (item) { - "superuser" -> itemId = R.id.superuser - "modules" -> itemId = R.id.modules - "downloads" -> itemId = R.id.downloads - "magiskhide" -> itemId = R.id.magiskhide - "log" -> itemId = R.id.log - "settings" -> itemId = R.id.settings - } - } - navigate(itemId) - } - - @Deprecated("Will be replaced by navigation components") - fun navigate(itemId: Int) { - mDrawerItem = itemId - binding.navView.setCheckedItem(itemId) - when (itemId) { - R.id.magisk -> { - fromShortcut = false - displayFragment(MagiskFragment(), true) - } - R.id.superuser -> displayFragment(SuperuserFragment(), true) - R.id.modules -> displayFragment(ModulesFragment(), true) - R.id.downloads -> displayFragment(ReposFragment(), true) - R.id.magiskhide -> displayFragment(MagiskHideFragment(), true) - R.id.log -> displayFragment(LogFragment(), false) - R.id.settings -> displayFragment(SettingsFragment(), true) - } - } - - @Deprecated("") - private fun displayFragment(navFragment: Fragment, setElevation: Boolean) { - /*supportInvalidateOptionsMenu(); - getSupportFragmentManager() - .beginTransaction() - .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) - .replace(R.id.content_frame, navFragment) - .commitNow(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - toolbar.setElevation(setElevation ? toolbarElevation : 0); - }*/ - } - - companion object { - private var fromShortcut = false + menu.findItem(R.id.modulesFragment).isVisible = + Shell.rootAccess() && Config.magiskVersionCode >= 0 + menu.findItem(R.id.reposFragment).isVisible = + (Networking.checkNetworkStatus(this) && Shell.rootAccess() && Config.magiskVersionCode >= 0) + menu.findItem(R.id.logFragment).isVisible = + Shell.rootAccess() + menu.findItem(R.id.superuserFragment).isVisible = + Utils.showSuperUser() } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt index c77002d3e..883adca5f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainViewModel.kt @@ -1,6 +1,11 @@ package com.topjohnwu.magisk.ui +import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.ui.base.MagiskViewModel -class MainViewModel : MagiskViewModel() +class MainViewModel : MagiskViewModel() { + + fun navPressed() = Navigation.Main.OPEN_NAV.publish() + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt new file mode 100644 index 000000000..f160e46ba --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -0,0 +1,11 @@ +package com.topjohnwu.magisk.utils + +import android.view.View +import androidx.appcompat.widget.Toolbar +import androidx.databinding.BindingAdapter + + +@BindingAdapter("onNavigationClick") +fun setOnNavigationClickedListener(view: Toolbar, listener: View.OnClickListener) { + view.setNavigationOnClickListener(listener) +} diff --git a/app/src/main/res/drawable/ic_menu.xml b/app/src/main/res/drawable/ic_menu.xml new file mode 100644 index 000000000..d1bac8735 --- /dev/null +++ b/app/src/main/res/drawable/ic_menu.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 702fc71b1..d21d436b5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -19,6 +19,7 @@ tools:openDrawer="start"> diff --git a/app/src/main/res/layout/activity_main_content.xml b/app/src/main/res/layout/activity_main_content.xml index b86eafce2..da5318b8e 100644 --- a/app/src/main/res/layout/activity_main_content.xml +++ b/app/src/main/res/layout/activity_main_content.xml @@ -19,7 +19,15 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + diff --git a/app/src/main/res/menu/drawer.xml b/app/src/main/res/menu/drawer.xml index 40a26c32b..6710d2ddc 100644 --- a/app/src/main/res/menu/drawer.xml +++ b/app/src/main/res/menu/drawer.xml @@ -6,17 +6,17 @@ android:id="@+id/main_group"> @@ -28,13 +28,13 @@ android:id="@+id/second_group"> @@ -45,7 +45,7 @@ android:id="@+id/third_group"> From f3095222682cb911c4cb057aa0ef929088090f9a Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Fri, 12 Apr 2019 22:06:57 +0200 Subject: [PATCH 08/66] Added (backported) values and styles for views --- app/src/main/res/values/colors.xml | 24 +++++++ app/src/main/res/values/dimens.xml | 17 +++++ app/src/main/res/values/view_appearances.xml | 45 ++++++++++++ .../main/res/values/view_button_styles.xml | 60 ++++++++++++++++ app/src/main/res/values/view_card_styles.xml | 20 ++++++ .../main/res/values/view_dialog_styles.xml | 11 +++ .../main/res/values/view_divider_styles.xml | 18 +++++ app/src/main/res/values/view_image_styles.xml | 27 ++++++++ app/src/main/res/values/view_input_styles.xml | 15 ++++ .../main/res/values/view_progress_styles.xml | 10 +++ app/src/main/res/values/view_styles.xml | 6 ++ app/src/main/res/values/view_text_styles.xml | 68 +++++++++++++++++++ 12 files changed, 321 insertions(+) create mode 100644 app/src/main/res/values/view_appearances.xml create mode 100644 app/src/main/res/values/view_button_styles.xml create mode 100644 app/src/main/res/values/view_card_styles.xml create mode 100644 app/src/main/res/values/view_dialog_styles.xml create mode 100644 app/src/main/res/values/view_divider_styles.xml create mode 100644 app/src/main/res/values/view_image_styles.xml create mode 100644 app/src/main/res/values/view_input_styles.xml create mode 100644 app/src/main/res/values/view_progress_styles.xml create mode 100644 app/src/main/res/values/view_styles.xml create mode 100644 app/src/main/res/values/view_text_styles.xml diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6af55b822..4071fa8ec 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,6 +1,30 @@ + + + #009688 + #00796B + #D50000 + #6D1111 + + #888888 + + #1D1D1D + #6a6868 + #fff + + #FFFFFF + #2AFFFFFF + #2A000000 + + #fff + @color/colorPrimary + + #66000000 + + + #009688 #00796B #FFC107 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 6235002dd..74b6a01fe 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -8,4 +8,21 @@ 2dp 2dp 16dp + + + + 64dp + 48dp + 32dp + 16dp + 8dp + 4dp + 2dp + + 8dp + 20dp + + 1dp + + \ No newline at end of file diff --git a/app/src/main/res/values/view_appearances.xml b/app/src/main/res/values/view_appearances.xml new file mode 100644 index 000000000..1a1d5121f --- /dev/null +++ b/app/src/main/res/values/view_appearances.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_button_styles.xml b/app/src/main/res/values/view_button_styles.xml new file mode 100644 index 000000000..30ec17475 --- /dev/null +++ b/app/src/main/res/values/view_button_styles.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_card_styles.xml b/app/src/main/res/values/view_card_styles.xml new file mode 100644 index 000000000..af1aed063 --- /dev/null +++ b/app/src/main/res/values/view_card_styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_dialog_styles.xml b/app/src/main/res/values/view_dialog_styles.xml new file mode 100644 index 000000000..7a1cc28e2 --- /dev/null +++ b/app/src/main/res/values/view_dialog_styles.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_divider_styles.xml b/app/src/main/res/values/view_divider_styles.xml new file mode 100644 index 000000000..d77d43b1e --- /dev/null +++ b/app/src/main/res/values/view_divider_styles.xml @@ -0,0 +1,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_image_styles.xml b/app/src/main/res/values/view_image_styles.xml new file mode 100644 index 000000000..83651a21c --- /dev/null +++ b/app/src/main/res/values/view_image_styles.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_input_styles.xml b/app/src/main/res/values/view_input_styles.xml new file mode 100644 index 000000000..2dfdf4371 --- /dev/null +++ b/app/src/main/res/values/view_input_styles.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_progress_styles.xml b/app/src/main/res/values/view_progress_styles.xml new file mode 100644 index 000000000..5d26132be --- /dev/null +++ b/app/src/main/res/values/view_progress_styles.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/view_styles.xml b/app/src/main/res/values/view_styles.xml new file mode 100644 index 000000000..7cbd5ce8a --- /dev/null +++ b/app/src/main/res/values/view_styles.xml @@ -0,0 +1,6 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From bd00ae8eded4804713e73212784ddf71c2985b68 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 13 Apr 2019 00:14:37 +0200 Subject: [PATCH 09/66] Updated Magisk fragment to Kotlin Exported old update card to special xml include where binding takes care of everything that had to be done in code beforehand. Added several easing functions and enums. Backported some classes and functions from the old fork Expect major breakage. Literally nothing works as the functionality needs to be implemented --- .../topjohnwu/magisk/di/ApplicationModule.kt | 2 + .../topjohnwu/magisk/di/ViewModelsModule.kt | 2 + .../magisk/model/events/ViewEvents.kt | 14 + .../magisk/model/observer/Observer.kt | 31 + .../magisk/ui/base/MagiskActivity.kt | 8 +- .../magisk/ui/base/MagiskFragment.kt | 10 +- .../magisk/ui/base/MagiskViewModel.kt | 4 +- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 91 ++ .../magisk/ui/home/MagiskFragment.java | 332 ------- .../magisk/ui/home/MagiskFragment.kt | 279 ++++++ .../topjohnwu/magisk/ui/home/MagiskItem.kt | 6 + .../topjohnwu/magisk/ui/home/MagiskState.kt | 6 + .../magisk/utils/DataBindingAdapters.kt | 7 + .../com/topjohnwu/magisk/utils/XBinding.kt | 8 + app/src/main/res/layout/fragment_magisk.xml | 870 +++++++++--------- .../main/res/layout/include_update_card.xml | 160 ++++ app/src/main/res/layout/update_card.xml | 3 - 17 files changed, 1083 insertions(+), 750 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/model/observer/Observer.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.java create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/utils/XBinding.kt create mode 100644 app/src/main/res/layout/include_update_card.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt index 09fd26d68..dd5e7bebc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt @@ -2,10 +2,12 @@ package com.topjohnwu.magisk.di import android.content.Context import com.skoumal.teanity.rxbus.RxBus +import com.topjohnwu.magisk.App import org.koin.dsl.module val applicationModule = module { single { RxBus() } single { get().resources } + single { get() as App } } diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt index 523a7bdfc..e4df34487 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt @@ -1,10 +1,12 @@ package com.topjohnwu.magisk.di import com.topjohnwu.magisk.ui.MainViewModel +import com.topjohnwu.magisk.ui.home.HomeViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.dsl.module val viewModelModules = module { viewModel { MainViewModel() } + viewModel { HomeViewModel(get(), get()) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt new file mode 100644 index 000000000..bf405b0b3 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt @@ -0,0 +1,14 @@ +package com.topjohnwu.magisk.model.events + +import com.skoumal.teanity.viewevents.ViewEvent + + +data class OpenLinkEvent(val url: String) : ViewEvent() + +object ManagerInstallEvent : ViewEvent() +object MagiskInstallEvent : ViewEvent() + +object ManagerChangelogEvent : ViewEvent() +object MagiskChangelogEvent : ViewEvent() + +object UninstallEvent : ViewEvent() diff --git a/app/src/main/java/com/topjohnwu/magisk/model/observer/Observer.kt b/app/src/main/java/com/topjohnwu/magisk/model/observer/Observer.kt new file mode 100644 index 000000000..3f675dded --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/observer/Observer.kt @@ -0,0 +1,31 @@ +package com.topjohnwu.magisk.model.observer + +import androidx.databinding.Observable +import androidx.databinding.ObservableField +import java.io.Serializable + + +class Observer(vararg dependencies: Observable, private val observer: () -> T) : + ObservableField(*dependencies), Serializable { + + val value: T get() = observer() + + @Deprecated( + message = "Use KObservableField.value syntax from code", + replaceWith = ReplaceWith("value") + ) + override fun get(): T { + return value + } + + @Deprecated( + message = "Observer cannot be set", + level = DeprecationLevel.HIDDEN + ) + override fun set(newValue: T) { + } + + override fun toString(): String { + return "Observer(value=$value)" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt index f93e766e0..d9b0a8c16 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt @@ -1,8 +1,14 @@ package com.topjohnwu.magisk.ui.base +import androidx.core.net.toUri import androidx.databinding.ViewDataBinding import com.skoumal.teanity.view.TeanityActivity +import com.topjohnwu.magisk.utils.Utils abstract class MagiskActivity : - TeanityActivity() + TeanityActivity() { + + fun openUrl(url: String) = Utils.openLink(this, url.toUri()) + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt index 024b00492..8d186a228 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt @@ -5,4 +5,12 @@ import com.skoumal.teanity.view.TeanityFragment abstract class MagiskFragment : - TeanityFragment() + TeanityFragment() { + + protected val magiskActivity get() = activity as MagiskActivity<*, *> + + fun openLink(url: String) { + magiskActivity.openUrl(url) + } + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt index ca82d4039..c6f6ad86e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt @@ -1,6 +1,6 @@ package com.topjohnwu.magisk.ui.base -import com.skoumal.teanity.viewmodel.TeanityViewModel +import com.skoumal.teanity.viewmodel.LoadingViewModel -abstract class MagiskViewModel : TeanityViewModel() +abstract class MagiskViewModel : LoadingViewModel() 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 new file mode 100644 index 000000000..f223c1087 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -0,0 +1,91 @@ +package com.topjohnwu.magisk.ui.home + +import android.content.res.Resources +import com.skoumal.teanity.util.KObservableField +import com.topjohnwu.magisk.App +import com.topjohnwu.magisk.Config +import com.topjohnwu.magisk.Const +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.model.events.* +import com.topjohnwu.magisk.model.observer.Observer +import com.topjohnwu.magisk.ui.base.MagiskViewModel +import com.topjohnwu.magisk.utils.toggle + + +class HomeViewModel( + private val resources: Resources, + private val app: App +) : MagiskViewModel() { + + val isAdvancedExpanded = KObservableField(false) + + val isForceEncryption = KObservableField(false /*todo*/) + val isKeepVerity = KObservableField(false /*todo*/) + + private val prefsObserver = Observer(isForceEncryption, isKeepVerity) { + Config.keepEnc = isForceEncryption.value + Config.keepVerity = isKeepVerity.value + } + + val magiskState = KObservableField(MagiskState.LOADING) + val magiskStateText = Observer(magiskState) { + @Suppress("WhenWithOnlyElse") + when (magiskState.value) { + MagiskState.NO_ROOT -> TODO() + MagiskState.NOT_INSTALLED -> TODO() + MagiskState.UP_TO_DATE -> TODO() + MagiskState.LOADING -> TODO() + MagiskState.OBSOLETE -> TODO() + } + } + val magiskCurrentVersion = KObservableField("") + val magiskLatestVersion = KObservableField("") + val magiskAdditionalInfo = Observer(magiskState) { + if (Config.get(Config.Key.COREONLY)) + resources.getString(R.string.core_only_enabled) + else + "" + } + + val managerState = KObservableField(MagiskState.LOADING) + val managerStateText = Observer(managerState) { + @Suppress("WhenWithOnlyElse") + when (managerState.value) { + MagiskState.NO_ROOT -> TODO() + MagiskState.NOT_INSTALLED -> TODO() + MagiskState.UP_TO_DATE -> TODO() + MagiskState.LOADING -> TODO() + MagiskState.OBSOLETE -> TODO() + } + } + val managerCurrentVersion = KObservableField("") + val managerLatestVersion = KObservableField("") + val managerAdditionalInfo = Observer(managerState) { + if (app.packageName != BuildConfig.APPLICATION_ID) + "(${app.packageName})" + else + "" + } + + fun paypalPressed() = OpenLinkEvent(Const.Url.PAYPAL_URL).publish() + fun patreonPressed() = OpenLinkEvent(Const.Url.PATREON_URL).publish() + fun twitterPressed() = OpenLinkEvent(Const.Url.TWITTER_URL).publish() + fun githubPressed() = OpenLinkEvent(Const.Url.REPO_URL).publish() + fun xdaPressed() = OpenLinkEvent(Const.Url.XDA_THREAD).publish() + fun uninstallPressed() = UninstallEvent.publish() + + fun refresh() {} + + fun advancedPressed() = isAdvancedExpanded.toggle() + + fun installPressed(item: MagiskItem) = when (item) { + MagiskItem.MANAGER -> ManagerInstallEvent.publish() + MagiskItem.MAGISK -> MagiskInstallEvent.publish() + } + + fun cardPressed(item: MagiskItem) = when (item) { + MagiskItem.MANAGER -> ManagerChangelogEvent.publish() + MagiskItem.MAGISK -> MagiskChangelogEvent.publish() + } + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.java deleted file mode 100644 index 4a1864214..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.java +++ /dev/null @@ -1,332 +0,0 @@ -package com.topjohnwu.magisk.ui.home; - -import android.net.Uri; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.ImageView; -import android.widget.LinearLayout; - -import com.topjohnwu.magisk.BuildConfig; -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.tasks.CheckUpdates; -import com.topjohnwu.magisk.ui.MainActivity; -import com.topjohnwu.magisk.ui.base.BaseActivity; -import com.topjohnwu.magisk.ui.base.BaseFragment; -import com.topjohnwu.magisk.utils.Event; -import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.magisk.view.ArrowExpandable; -import com.topjohnwu.magisk.view.Expandable; -import com.topjohnwu.magisk.view.ExpandableViewHolder; -import com.topjohnwu.magisk.view.MarkDownWindow; -import com.topjohnwu.magisk.view.SafetyNet; -import com.topjohnwu.magisk.view.UpdateCardHolder; -import com.topjohnwu.magisk.view.dialogs.EnvFixDialog; -import com.topjohnwu.magisk.view.dialogs.MagiskInstallDialog; -import com.topjohnwu.magisk.view.dialogs.ManagerInstallDialog; -import com.topjohnwu.magisk.view.dialogs.UninstallDialog; -import com.topjohnwu.net.Networking; -import com.topjohnwu.superuser.Shell; - -import java.util.Locale; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.cardview.widget.CardView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import androidx.transition.ChangeBounds; -import androidx.transition.Fade; -import androidx.transition.Transition; -import androidx.transition.TransitionManager; -import androidx.transition.TransitionSet; -import butterknife.BindColor; -import butterknife.BindView; -import butterknife.OnClick; - -public class MagiskFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener { - - private static boolean shownDialog = false; - - @BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.linearLayout) LinearLayout root; - - @BindView(R.id.install_option_card) CardView installOptionCard; - @BindView(R.id.keep_force_enc) CheckBox keepEncChkbox; - @BindView(R.id.keep_verity) CheckBox keepVerityChkbox; - @BindView(R.id.install_option_expand) ViewGroup optionExpandLayout; - @BindView(R.id.arrow) ImageView arrow; - - @BindView(R.id.uninstall_button) CardView uninstallButton; - - @BindColor(R.color.red500) int colorBad; - @BindColor(R.color.green500) int colorOK; - @BindColor(R.color.yellow500) int colorWarn; - @BindColor(R.color.green500) int colorNeutral; - @BindColor(R.color.blue500) int colorInfo; - - private UpdateCardHolder magisk; - private UpdateCardHolder manager; - private SafetyNet safetyNet; - private Transition transition; - private Expandable optionExpand; - - private void magiskInstall(View v) { - // Show Manager update first - if (Config.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { - new ManagerInstallDialog(requireActivity()).show(); - return; - } - new MagiskInstallDialog((BaseActivity) requireActivity()).show(); - } - - private void managerInstall(View v) { - new ManagerInstallDialog(requireActivity()).show(); - } - - private void openLink(String url) { - Utils.openLink(requireActivity(), Uri.parse(url)); - } - - @OnClick(R.id.paypal) - void paypal() { - openLink(Const.Url.PAYPAL_URL); - } - - @OnClick(R.id.patreon) - void patreon() { - openLink(Const.Url.PATREON_URL); - } - - @OnClick(R.id.twitter) - void twitter() { - openLink(Const.Url.TWITTER_URL); - } - - @OnClick(R.id.github) - void github() { - openLink(Const.Url.SOURCE_CODE_URL); - } - - @OnClick(R.id.xda) - void xda() { - openLink(Const.Url.XDA_THREAD); - } - - @OnClick(R.id.uninstall_button) - void uninstall() { - new UninstallDialog(requireActivity()).show(); - } - - @OnClick(R.id.arrow) - void expandOptions() { - if (optionExpand.isExpanded()) - optionExpand.collapse(); - else optionExpand.expand(); - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_magisk, container, false); - unbinder = new MagiskFragment_ViewBinding(this, v); - requireActivity().setTitle(R.string.magisk); - - optionExpand = new ArrowExpandable(new ExpandableViewHolder(optionExpandLayout), arrow); - safetyNet = new SafetyNet(v); - magisk = new UpdateCardHolder(inflater, root); - manager = new UpdateCardHolder(inflater, root); - manager.setClickable(vv -> - MarkDownWindow.show(requireActivity(), null, - getResources().openRawResource(R.raw.changelog))); - root.addView(magisk.itemView, 1); - root.addView(manager.itemView, 2); - - keepVerityChkbox.setChecked(Config.keepVerity); - keepVerityChkbox.setOnCheckedChangeListener((view, checked) -> Config.keepVerity = checked); - keepEncChkbox.setChecked(Config.keepEnc); - keepEncChkbox.setOnCheckedChangeListener((view, checked) -> Config.keepEnc = checked); - - mSwipeRefreshLayout.setOnRefreshListener(this); - - magisk.install.setOnClickListener(this::magiskInstall); - manager.install.setOnClickListener(this::managerInstall); - if (Config.get(Config.Key.COREONLY)) { - magisk.additional.setText(R.string.core_only_enabled); - magisk.additional.setVisibility(View.VISIBLE); - } - if (!app.getPackageName().equals(BuildConfig.APPLICATION_ID)) { - manager.additional.setText("(" + app.getPackageName() + ")"); - manager.additional.setVisibility(View.VISIBLE); - } - - transition = new TransitionSet() - .setOrdering(TransitionSet.ORDERING_TOGETHER) - .addTransition(new Fade(Fade.OUT)) - .addTransition(new ChangeBounds()) - .addTransition(new Fade(Fade.IN)); - - updateUI(); - return v; - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - safetyNet.unbinder.unbind(); - magisk.unbinder.unbind(); - manager.unbinder.unbind(); - } - - @Override - public void onRefresh() { - mSwipeRefreshLayout.setRefreshing(false); - TransitionManager.beginDelayedTransition(root, transition); - safetyNet.reset(); - magisk.reset(); - manager.reset(); - - Config.loadMagiskInfo(); - updateUI(); - - Event.reset(this); - Config.remoteMagiskVersionString = null; - Config.remoteMagiskVersionCode = -1; - - shownDialog = false; - - // Trigger state check - if (Networking.checkNetworkStatus(app)) { - CheckUpdates.check(); - } - } - - @Override - public int[] getListeningEvents() { - return new int[] {Event.UPDATE_CHECK_DONE}; - } - - @Override - public void onEvent(int event) { - updateCheckUI(); - } - - private void updateUI() { - ((MainActivity) requireActivity()).checkHideSection(); - int image, color; - String status; - if (Config.magiskVersionCode < 0) { - color = colorBad; - image = R.drawable.ic_cancel; - status = getString(R.string.magisk_version_error); - magisk.status.setText(status); - magisk.currentVersion.setVisibility(View.GONE); - } else { - color = colorOK; - image = R.drawable.ic_check_circle; - status = getString(R.string.magisk); - magisk.currentVersion.setText(getString(R.string.current_installed, - String.format(Locale.US, "v%s (%d)", - Config.magiskVersionString, Config.magiskVersionCode))); - } - magisk.statusIcon.setColorFilter(color); - magisk.statusIcon.setImageResource(image); - - manager.statusIcon.setColorFilter(colorOK); - manager.statusIcon.setImageResource(R.drawable.ic_check_circle); - manager.currentVersion.setText(getString(R.string.current_installed, - String.format(Locale.US, "v%s (%d)", - BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE))); - - if (!Networking.checkNetworkStatus(app)) { - // No network, updateCheckUI will not be triggered - magisk.status.setText(status); - manager.status.setText(R.string.app_name); - magisk.setValid(false); - manager.setValid(false); - } - } - - private void updateCheckUI() { - int image, color; - String status, button = ""; - - TransitionManager.beginDelayedTransition(root, transition); - - if (Config.remoteMagiskVersionCode < 0) { - color = colorNeutral; - image = R.drawable.ic_help; - status = getString(R.string.invalid_update_channel); - } else { - magisk.latestVersion.setText(getString(R.string.latest_version, - String.format(Locale.US, "v%s (%d)", - Config.remoteMagiskVersionString, Config.remoteMagiskVersionCode))); - if (Config.remoteMagiskVersionCode > Config.magiskVersionCode) { - color = colorInfo; - image = R.drawable.ic_update; - status = getString(R.string.magisk_update_title); - button = getString(R.string.update); - } else { - color = colorOK; - image = R.drawable.ic_check_circle; - status = getString(R.string.magisk_up_to_date); - button = getString(R.string.install); - } - } - if (Config.magiskVersionCode > 0) { - // Only override status if Magisk is installed - magisk.statusIcon.setImageResource(image); - magisk.statusIcon.setColorFilter(color); - magisk.status.setText(status); - magisk.install.setText(button); - } - - if (Config.remoteManagerVersionCode < 0) { - color = colorNeutral; - image = R.drawable.ic_help; - status = getString(R.string.invalid_update_channel); - } else { - manager.latestVersion.setText(getString(R.string.latest_version, - String.format(Locale.US, "v%s (%d)", - Config.remoteManagerVersionString, Config.remoteManagerVersionCode))); - if (Config.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { - color = colorInfo; - image = R.drawable.ic_update; - status = getString(R.string.manager_update_title); - manager.install.setText(R.string.update); - } else { - color = colorOK; - image = R.drawable.ic_check_circle; - status = getString(R.string.manager_up_to_date); - manager.install.setText(R.string.install); - } - } - manager.statusIcon.setImageResource(image); - manager.statusIcon.setColorFilter(color); - manager.status.setText(status); - - magisk.setValid(Config.remoteMagiskVersionCode > 0); - manager.setValid(Config.remoteManagerVersionCode > 0); - - if (Config.remoteMagiskVersionCode < 0) { - // Hide install related components - installOptionCard.setVisibility(View.GONE); - uninstallButton.setVisibility(View.GONE); - } else { - // Show install related components - installOptionCard.setVisibility(View.VISIBLE); - uninstallButton.setVisibility(Shell.rootAccess() ? View.VISIBLE : View.GONE); - } - - if (!shownDialog && Config.magiskVersionCode > 0 && - !Shell.su("env_check").exec().isSuccess()) { - shownDialog = true; - new EnvFixDialog(requireActivity()).show(); - } - } -} - diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt new file mode 100644 index 000000000..77f435eea --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt @@ -0,0 +1,279 @@ +package com.topjohnwu.magisk.ui.home + +import com.skoumal.teanity.viewevents.ViewEvent +import com.topjohnwu.magisk.Config +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.model.events.MagiskInstallEvent +import com.topjohnwu.magisk.model.events.ManagerInstallEvent +import com.topjohnwu.magisk.model.events.OpenLinkEvent +import com.topjohnwu.magisk.model.events.UninstallEvent +import com.topjohnwu.magisk.utils.Event +import com.topjohnwu.magisk.view.MarkDownWindow +import com.topjohnwu.magisk.view.dialogs.ManagerInstallDialog +import com.topjohnwu.magisk.view.dialogs.UninstallDialog +import org.koin.androidx.viewmodel.ext.android.viewModel +import com.topjohnwu.magisk.ui.base.MagiskFragment as NewMagiskFragment + +class MagiskFragment : NewMagiskFragment() { + + /*@BindView(R.id.swipeRefreshLayout) + internal var mSwipeRefreshLayout: SwipeRefreshLayout? = null + @BindView(R.id.linearLayout) + internal var root: LinearLayout? = null + + @BindView(R.id.install_option_card) + internal var installOptionCard: CardView? = null + @BindView(R.id.keep_force_enc) + internal var keepEncChkbox: CheckBox? = null + @BindView(R.id.keep_verity) + internal var keepVerityChkbox: CheckBox? = null + @BindView(R.id.install_option_expand) + internal var optionExpandLayout: ViewGroup? = null + @BindView(R.id.arrow) + internal var arrow: ImageView? = null + + @BindView(R.id.uninstall_button) + internal var uninstallButton: CardView? = null + + @BindColor(R.color.red500) + internal var colorBad: Int = 0 + @BindColor(R.color.green500) + internal var colorOK: Int = 0 + @BindColor(R.color.yellow500) + internal var colorWarn: Int = 0 + @BindColor(R.color.green500) + internal var colorNeutral: Int = 0 + @BindColor(R.color.blue500) + internal var colorInfo: Int = 0*/ + + /*private var magisk: UpdateCardHolder? = null + private var manager: UpdateCardHolder? = null + private var safetyNet: SafetyNet? = null + private var transition: Transition? = null + private var optionExpand: Expandable? = null*/ + + override val layoutRes: Int = R.layout.fragment_magisk + override val viewModel: HomeViewModel by viewModel() + + override fun onEventDispatched(event: ViewEvent) { + super.onEventDispatched(event) + when (event) { + is OpenLinkEvent -> openLink(event.url) + is ManagerInstallEvent -> installManager() + is MagiskInstallEvent -> installMagisk() + is UninstallEvent -> uninstall() + } + } + + private fun installMagisk() { + // Show Manager update first + if (Config.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { + ManagerInstallDialog(requireActivity()).show() + return + } + //FIXME dialog requires old base + //MagiskInstallDialog(requireActivity()).show() + } + + private fun installManager() = ManagerInstallDialog(requireActivity()).show() + + private fun uninstall() { + UninstallDialog(requireActivity()).show() + } + + private fun changelogManager() { + MarkDownWindow.show( + requireActivity(), null, + resources.openRawResource(R.raw.changelog) + ) + } + + /*override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val v = inflater.inflate(R.layout.fragment_magisk, container, false) + requireActivity().setTitle(R.string.magisk) + + //safetyNet = SafetyNet(v) + + *//*transition = TransitionSet() + .setOrdering(TransitionSet.ORDERING_TOGETHER) + .addTransition(Fade(Fade.OUT)) + .addTransition(ChangeBounds()) + .addTransition(Fade(Fade.IN))*//* + + updateUI() + return v + }*/ + + private fun onRefresh() { + /*mSwipeRefreshLayout!!.isRefreshing = false + TransitionManager.beginDelayedTransition(root!!, transition) + safetyNet!!.reset() + magisk!!.reset() + manager!!.reset()*/ + + Config.loadMagiskInfo() + updateUI() + + //FIXME requires old base + /*Event.reset(this) + Config.remoteMagiskVersionString = null + Config.remoteMagiskVersionCode = -1*/ + + shownDialog = false + + // Trigger state check + /*if (Networking.checkNetworkStatus(app)) { + CheckUpdates.check() + }*/ + } + + private fun getListeningEvents(): IntArray { + return intArrayOf(Event.UPDATE_CHECK_DONE) + } + + private fun onEvent(event: Int) { + updateCheckUI() + } + + private fun updateUI() { + /*(requireActivity() as MainActivity).checkHideSection() + val image: Int + val color: Int + val status: String + if (Config.magiskVersionCode < 0) { + color = colorBad + image = R.drawable.ic_cancel + status = getString(R.string.magisk_version_error) + magisk!!.status.text = status + magisk!!.currentVersion.visibility = View.GONE + } else { + color = colorOK + image = R.drawable.ic_check_circle + status = getString(R.string.magisk) + magisk!!.currentVersion.text = getString( + R.string.current_installed, + String.format( + Locale.US, "v%s (%d)", + Config.magiskVersionString, Config.magiskVersionCode + ) + ) + } + magisk!!.statusIcon.setColorFilter(color) + magisk!!.statusIcon.setImageResource(image) + + manager!!.statusIcon.setColorFilter(colorOK) + manager!!.statusIcon.setImageResource(R.drawable.ic_check_circle) + manager!!.currentVersion.text = getString( + R.string.current_installed, + String.format( + Locale.US, "v%s (%d)", + BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE + ) + ) + + if (!Networking.checkNetworkStatus(app)) { + // No network, updateCheckUI will not be triggered + magisk!!.status.text = status + manager!!.status.setText(R.string.app_name) + magisk!!.setValid(false) + manager!!.setValid(false) + }*/ + } + + private fun updateCheckUI() { + /*var image: Int + var color: Int + var status: String + var button = "" + + + if (Config.remoteMagiskVersionCode < 0) { + color = colorNeutral + image = R.drawable.ic_help + status = getString(R.string.invalid_update_channel) + } else { + magisk!!.latestVersion.text = getString( + R.string.latest_version, + String.format( + Locale.US, "v%s (%d)", + Config.remoteMagiskVersionString, Config.remoteMagiskVersionCode + ) + ) + if (Config.remoteMagiskVersionCode > Config.magiskVersionCode) { + color = colorInfo + image = R.drawable.ic_update + status = getString(R.string.magisk_update_title) + button = getString(R.string.update) + } else { + color = colorOK + image = R.drawable.ic_check_circle + status = getString(R.string.magisk_up_to_date) + button = getString(R.string.install) + } + } + if (Config.magiskVersionCode > 0) { + // Only override status if Magisk is installed + magisk!!.statusIcon.setImageResource(image) + magisk!!.statusIcon.setColorFilter(color) + magisk!!.status.text = status + magisk!!.install.text = button + } + + if (Config.remoteManagerVersionCode < 0) { + color = colorNeutral + image = R.drawable.ic_help + status = getString(R.string.invalid_update_channel) + } else { + manager!!.latestVersion.text = getString( + R.string.latest_version, + String.format( + Locale.US, "v%s (%d)", + Config.remoteManagerVersionString, Config.remoteManagerVersionCode + ) + ) + if (Config.remoteManagerVersionCode > BuildConfig.VERSION_CODE) { + color = colorInfo + image = R.drawable.ic_update + status = getString(R.string.manager_update_title) + manager!!.install.setText(R.string.update) + } else { + color = colorOK + image = R.drawable.ic_check_circle + status = getString(R.string.manager_up_to_date) + manager!!.install.setText(R.string.install) + } + } + manager!!.statusIcon.setImageResource(image) + manager!!.statusIcon.setColorFilter(color) + manager!!.status.text = status + + magisk!!.setValid(Config.remoteMagiskVersionCode > 0) + manager!!.setValid(Config.remoteManagerVersionCode > 0) + + if (Config.remoteMagiskVersionCode < 0) { + // Hide install related components + installOptionCard!!.visibility = View.GONE + uninstallButton!!.visibility = View.GONE + } else { + // Show install related components + installOptionCard!!.visibility = View.VISIBLE + uninstallButton!!.visibility = if (Shell.rootAccess()) View.VISIBLE else View.GONE + } + + if (!shownDialog && Config.magiskVersionCode > 0 && + !Shell.su("env_check").exec().isSuccess + ) { + shownDialog = true + EnvFixDialog(requireActivity()).show() + }*/ + } + + companion object { + + private var shownDialog = false + } +} + diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt new file mode 100644 index 000000000..8f26b0c1d --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt @@ -0,0 +1,6 @@ +package com.topjohnwu.magisk.ui.home + + +enum class MagiskItem { + MANAGER, MAGISK +} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt new file mode 100644 index 000000000..8d880001d --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt @@ -0,0 +1,6 @@ +package com.topjohnwu.magisk.ui.home + + +enum class MagiskState { + NO_ROOT, NOT_INSTALLED, UP_TO_DATE, OBSOLETE, LOADING +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt index f160e46ba..61d27118b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -1,6 +1,8 @@ package com.topjohnwu.magisk.utils import android.view.View +import androidx.annotation.DrawableRes +import androidx.appcompat.widget.AppCompatImageView import androidx.appcompat.widget.Toolbar import androidx.databinding.BindingAdapter @@ -9,3 +11,8 @@ import androidx.databinding.BindingAdapter fun setOnNavigationClickedListener(view: Toolbar, listener: View.OnClickListener) { view.setNavigationOnClickListener(listener) } + +@BindingAdapter("srcCompat") +fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) { + view.setImageResource(resId) +} diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/XBinding.kt b/app/src/main/java/com/topjohnwu/magisk/utils/XBinding.kt new file mode 100644 index 000000000..ff9307a9e --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/utils/XBinding.kt @@ -0,0 +1,8 @@ +package com.topjohnwu.magisk.utils + +import com.skoumal.teanity.util.KObservableField + + +fun KObservableField.toggle() { + value = !value +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_magisk.xml b/app/src/main/res/layout/fragment_magisk.xml index a83e96333..10c6dd845 100644 --- a/app/src/main/res/layout/fragment_magisk.xml +++ b/app/src/main/res/layout/fragment_magisk.xml @@ -1,472 +1,520 @@ - + - + + + + + + + + + + + android:layout_height="fill_parent" + android:orientation="vertical" + app:onRefreshListener="@{() -> viewModel.refresh()}" + app:refreshing="@{viewModel.loading}"> - - - - - - - - - - - - - - + android:orientation="vertical"> - + - - + android:layout_height="wrap_content" + android:layout_marginTop="5dp" + android:layout_marginBottom="5dp"> + + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.5" + app:layout_constraintStart_toEndOf="@+id/icon" + app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + android:layout_height="wrap_content"> - + + + + + + + + + + + + + + + android:paddingBottom="10dp"> + + + + + + + + + + + - - + - - - + android:layout_height="match_parent" + android:layout_marginStart="5dp" + android:layout_marginTop="4dp" + android:layout_marginEnd="5dp" + android:layout_marginBottom="4dp" + app:cardCornerRadius="@dimen/card_corner_radius" + app:cardElevation="@dimen/card_elevation"> - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@+id/paypal"> - + + + + + + + + + + + app:layout_constraintStart_toEndOf="@id/github"> + + + + + + + + + + + + + + + + + - + - - - - - + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_marginStart="5dp" + android:layout_marginTop="4dp" + android:layout_marginEnd="5dp" + android:layout_marginBottom="4dp" + android:clickable="true" + android:focusable="true" + android:foreground="?android:attr/selectableItemBackground" + android:onClick="@{() -> viewModel.uninstallPressed()}" + app:cardCornerRadius="@dimen/card_corner_radius" + app:cardElevation="@dimen/card_elevation"> - + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp" + android:ems="10" + android:fontFamily="sans-serif" + android:gravity="center" + android:text="@string/uninstall" + android:textAllCaps="false" + android:textSize="20sp" + android:textStyle="bold" /> - + - - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/app/src/main/res/layout/include_update_card.xml b/app/src/main/res/layout/include_update_card.xml new file mode 100644 index 000000000..03a6d003f --- /dev/null +++ b/app/src/main/res/layout/include_update_card.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/update_card.xml b/app/src/main/res/layout/update_card.xml index 103f62725..2fd143493 100644 --- a/app/src/main/res/layout/update_card.xml +++ b/app/src/main/res/layout/update_card.xml @@ -75,7 +75,6 @@ android:layout_height="wrap_content" android:maxLines="1" android:text="@string/checking_for_updates" - android:visibility="gone" app:autoSizeMinTextSize="1sp" app:autoSizeTextType="uniform" app:layout_constraintEnd_toEndOf="@+id/status" @@ -87,7 +86,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:maxLines="1" - android:visibility="gone" app:autoSizeMinTextSize="1sp" app:autoSizeTextType="uniform" app:layout_constraintEnd_toEndOf="@+id/status" @@ -101,7 +99,6 @@ android:layout_marginEnd="8dp" android:maxLines="1" android:text="@string/install" - android:visibility="gone" app:autoSizeMaxTextSize="14sp" app:autoSizeTextType="uniform" app:layout_constraintBottom_toBottomOf="parent" From 9bb4dfad1313b97c5539cfec16faedf63861c97e Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 14 Apr 2019 11:00:16 +0200 Subject: [PATCH 10/66] Added back version checking (and version boxes) after transitioning homepage to MVVM Fixed several errors caused along the way --- app/build.gradle | 3 + app/src/main/java/com/topjohnwu/magisk/App.kt | 3 + .../magisk/ui/base/MagiskViewModel.kt | 13 ++- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 92 +++++++++++++++---- .../magisk/ui/home/MagiskFragment.kt | 7 +- .../magisk/utils/DataBindingAdapters.kt | 6 ++ .../main/res/layout/include_update_card.xml | 3 +- app/src/main/res/values/colors.xml | 3 + 8 files changed, 105 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 84ac3affd..fc25ba0cb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -73,6 +73,9 @@ dependencies { implementation("org.koin:koin-android:${koin}") implementation("org.koin:koin-androidx-viewmodel:${koin}") + def timber = "4.7.1" + implementation "com.jakewharton.timber:timber:${timber}" + implementation("com.github.skoumalcz:teanity:0.3.3") { exclude group: 'androidx.work', module: 'work-runtime-ktx' exclude group: 'androidx.room', module: 'room-runtime' diff --git a/app/src/main/java/com/topjohnwu/magisk/App.kt b/app/src/main/java/com/topjohnwu/magisk/App.kt index 2d9b5d679..bbe501fb9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/App.kt +++ b/app/src/main/java/com/topjohnwu/magisk/App.kt @@ -20,6 +20,7 @@ import com.topjohnwu.net.Networking import com.topjohnwu.superuser.Shell import org.koin.android.ext.koin.androidContext import org.koin.core.context.startKoin +import timber.log.Timber import java.util.concurrent.ThreadPoolExecutor open class App : Application(), Application.ActivityLifecycleCallbacks { @@ -39,6 +40,8 @@ open class App : Application(), Application.ActivityLifecycleCallbacks { androidContext(this@App) modules(koinModules) } + + Timber.plant(Timber.DebugTree()) } override fun attachBaseContext(base: Context) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt index c6f6ad86e..8c1349c68 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt @@ -1,6 +1,17 @@ package com.topjohnwu.magisk.ui.base import com.skoumal.teanity.viewmodel.LoadingViewModel +import com.topjohnwu.magisk.utils.Event +import timber.log.Timber -abstract class MagiskViewModel : LoadingViewModel() +abstract class MagiskViewModel : LoadingViewModel(), Event.AutoListener { + + init { + Event.register(this) + } + + override fun onEvent(event: Int) = Timber.i("Event of $event was not handled") + override fun getListeningEvents(): IntArray = intArrayOf() + +} 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 f223c1087..76fafc1d0 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 @@ -2,14 +2,14 @@ package com.topjohnwu.magisk.ui.home import android.content.res.Resources import com.skoumal.teanity.util.KObservableField -import com.topjohnwu.magisk.App -import com.topjohnwu.magisk.Config -import com.topjohnwu.magisk.Const -import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.* import com.topjohnwu.magisk.model.events.* import com.topjohnwu.magisk.model.observer.Observer +import com.topjohnwu.magisk.tasks.CheckUpdates import com.topjohnwu.magisk.ui.base.MagiskViewModel +import com.topjohnwu.magisk.utils.Event import com.topjohnwu.magisk.utils.toggle +import com.topjohnwu.net.Networking class HomeViewModel( @@ -19,8 +19,8 @@ class HomeViewModel( val isAdvancedExpanded = KObservableField(false) - val isForceEncryption = KObservableField(false /*todo*/) - val isKeepVerity = KObservableField(false /*todo*/) + val isForceEncryption = KObservableField(Config.keepEnc) + val isKeepVerity = KObservableField(Config.keepVerity) private val prefsObserver = Observer(isForceEncryption, isKeepVerity) { Config.keepEnc = isForceEncryption.value @@ -29,13 +29,12 @@ class HomeViewModel( val magiskState = KObservableField(MagiskState.LOADING) val magiskStateText = Observer(magiskState) { - @Suppress("WhenWithOnlyElse") when (magiskState.value) { MagiskState.NO_ROOT -> TODO() - MagiskState.NOT_INSTALLED -> TODO() - MagiskState.UP_TO_DATE -> TODO() - MagiskState.LOADING -> TODO() - MagiskState.OBSOLETE -> TODO() + MagiskState.NOT_INSTALLED -> resources.getString(R.string.magisk_version_error) + MagiskState.UP_TO_DATE -> resources.getString(R.string.magisk_up_to_date) + MagiskState.LOADING -> resources.getString(R.string.checking_for_updates) + MagiskState.OBSOLETE -> resources.getString(R.string.magisk_update_title) } } val magiskCurrentVersion = KObservableField("") @@ -49,13 +48,12 @@ class HomeViewModel( val managerState = KObservableField(MagiskState.LOADING) val managerStateText = Observer(managerState) { - @Suppress("WhenWithOnlyElse") when (managerState.value) { - MagiskState.NO_ROOT -> TODO() - MagiskState.NOT_INSTALLED -> TODO() - MagiskState.UP_TO_DATE -> TODO() - MagiskState.LOADING -> TODO() - MagiskState.OBSOLETE -> TODO() + MagiskState.NO_ROOT -> "wtf" + MagiskState.NOT_INSTALLED -> resources.getString(R.string.invalid_update_channel) + MagiskState.UP_TO_DATE -> resources.getString(R.string.manager_up_to_date) + MagiskState.LOADING -> resources.getString(R.string.checking_for_updates) + MagiskState.OBSOLETE -> resources.getString(R.string.manager_update_title) } } val managerCurrentVersion = KObservableField("") @@ -67,6 +65,16 @@ class HomeViewModel( "" } + private val current = resources.getString(R.string.current_installed) + private val latest = resources.getString(R.string.latest_version) + + init { + refresh() + } + + override fun onEvent(event: Int) = updateSelf() + override fun getListeningEvents(): IntArray = intArrayOf(Event.UPDATE_CHECK_DONE) + fun paypalPressed() = OpenLinkEvent(Const.Url.PAYPAL_URL).publish() fun patreonPressed() = OpenLinkEvent(Const.Url.PATREON_URL).publish() fun twitterPressed() = OpenLinkEvent(Const.Url.TWITTER_URL).publish() @@ -74,8 +82,6 @@ class HomeViewModel( fun xdaPressed() = OpenLinkEvent(Const.Url.XDA_THREAD).publish() fun uninstallPressed() = UninstallEvent.publish() - fun refresh() {} - fun advancedPressed() = isAdvancedExpanded.toggle() fun installPressed(item: MagiskItem) = when (item) { @@ -88,4 +94,52 @@ class HomeViewModel( MagiskItem.MAGISK -> MagiskChangelogEvent.publish() } + fun refresh() { + state = State.LOADING + magiskState.value = MagiskState.LOADING + managerState.value = MagiskState.LOADING + Event.reset(this) + Config.remoteMagiskVersionString = null + Config.remoteMagiskVersionCode = -1 + + if (Networking.checkNetworkStatus(app)) { + CheckUpdates.check() + } else { + state = State.LOADING_FAILED + } + } + + private fun updateSelf() { + state = State.LOADED + magiskState.value = when (Config.magiskVersionCode) { + in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED + !in Config.remoteMagiskVersionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE + else -> MagiskState.UP_TO_DATE + } + + magiskCurrentVersion.value = version + .format(Config.magiskVersionString, Config.magiskVersionCode) + .let { current.format(it) } + magiskLatestVersion.value = version + .format(Config.remoteMagiskVersionString, Config.remoteMagiskVersionCode) + .let { latest.format(it) } + + managerState.value = when (Config.remoteManagerVersionCode) { + in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED //wrong update channel + in (BuildConfig.VERSION_CODE + 1)..Int.MAX_VALUE -> MagiskState.OBSOLETE + else -> MagiskState.UP_TO_DATE + } + + managerCurrentVersion.value = version + .format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) + .let { current.format(it) } + managerLatestVersion.value = version + .format(Config.remoteManagerVersionString, Config.remoteManagerVersionCode) + .let { latest.format(it) } + } + + companion object { + private const val version = "%s (%d)" + } + } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt index 77f435eea..5f602cc1f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskFragment.kt @@ -1,12 +1,10 @@ package com.topjohnwu.magisk.ui.home import com.skoumal.teanity.viewevents.ViewEvent +import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.model.events.MagiskInstallEvent -import com.topjohnwu.magisk.model.events.ManagerInstallEvent -import com.topjohnwu.magisk.model.events.OpenLinkEvent -import com.topjohnwu.magisk.model.events.UninstallEvent +import com.topjohnwu.magisk.model.events.* import com.topjohnwu.magisk.utils.Event import com.topjohnwu.magisk.view.MarkDownWindow import com.topjohnwu.magisk.view.dialogs.ManagerInstallDialog @@ -62,6 +60,7 @@ class MagiskFragment : NewMagiskFragment installManager() is MagiskInstallEvent -> installMagisk() is UninstallEvent -> uninstall() + is ManagerChangelogEvent -> changelogManager() } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt index 61d27118b..4f1e27800 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -1,6 +1,7 @@ package com.topjohnwu.magisk.utils import android.view.View +import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.appcompat.widget.AppCompatImageView import androidx.appcompat.widget.Toolbar @@ -16,3 +17,8 @@ fun setOnNavigationClickedListener(view: Toolbar, listener: View.OnClickListener fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) { view.setImageResource(resId) } + +@BindingAdapter("app:tint") +fun setTint(view: AppCompatImageView, @ColorInt tint: Int) { + view.setColorFilter(tint) +} diff --git a/app/src/main/res/layout/include_update_card.xml b/app/src/main/res/layout/include_update_card.xml index 03a6d003f..a772a4811 100644 --- a/app/src/main/res/layout/include_update_card.xml +++ b/app/src/main/res/layout/include_update_card.xml @@ -79,6 +79,7 @@ android:layout_height="25dp" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" + app:tint="@{state == MagiskState.UP_TO_DATE ? @color/colorCorrect : (state == MagiskState.OBSOLETE ? @color/colorUpdate : @color/colorError)}" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/status" app:layout_constraintStart_toStartOf="parent" @@ -86,7 +87,7 @@ #66000000 + @color/green500 + @color/red500 + @color/blue500 #009688 From 42adc7382f84570b74d5145a3885e16522f1a0a6 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 14 Apr 2019 11:07:13 +0200 Subject: [PATCH 11/66] Updated kotlin --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7f770a079..246eb4fb9 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { dependencies { classpath 'com.android.tools:r8:1.4.79' classpath 'com.android.tools.build:gradle:3.3.2' - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.30' classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0' // NOTE: Do not place your application dependencies here; they belong From 3101c538e9eaf3bbd6a0d2e657f4ca089dc6cb76 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 14 Apr 2019 11:27:23 +0200 Subject: [PATCH 12/66] Added (backported) styles from design concept --- app/src/main/res/values/styles_new.xml | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/src/main/res/values/styles_new.xml diff --git a/app/src/main/res/values/styles_new.xml b/app/src/main/res/values/styles_new.xml new file mode 100644 index 000000000..66e4f51ea --- /dev/null +++ b/app/src/main/res/values/styles_new.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + \ No newline at end of file From 8a8441c875441b4e635cf2d5200369871035f9ac Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Wed, 17 Apr 2019 18:20:53 +0200 Subject: [PATCH 29/66] Added failure callback to fingerprint dialog --- .../view/dialogs/FingerprintAuthDialog.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java index d9f7642e2..eaf71b846 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java @@ -16,15 +16,18 @@ import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.Utils; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @TargetApi(Build.VERSION_CODES.M) public class FingerprintAuthDialog extends CustomAlertDialog { - private Runnable callback; + private final Runnable callback; + @Nullable + private Runnable failureCallback; private DialogFingerprintHelper helper; - public FingerprintAuthDialog(@NonNull Activity activity, Runnable onSuccess) { + public FingerprintAuthDialog(@NonNull Activity activity, @NonNull Runnable onSuccess) { super(activity); callback = onSuccess; Drawable fingerprint = activity.getResources().getDrawable(R.drawable.ic_fingerprint); @@ -37,13 +40,28 @@ public class FingerprintAuthDialog extends CustomAlertDialog { vh.messageView.setCompoundDrawablePadding(Utils.dpInPx(20)); vh.messageView.setGravity(Gravity.CENTER); setMessage(R.string.auth_fingerprint); - setNegativeButton(R.string.close, (d, w) -> helper.cancel()); - setOnCancelListener(d -> helper.cancel()); + setNegativeButton(R.string.close, (d, w) -> { + helper.cancel(); + if (failureCallback != null) { + failureCallback.run(); + } + }); + setOnCancelListener(d -> { + helper.cancel(); + if (failureCallback != null) { + failureCallback.run(); + } + }); try { helper = new DialogFingerprintHelper(); } catch (Exception ignored) {} } + public FingerprintAuthDialog(@NonNull Activity activity, @NonNull Runnable onSuccess, @NonNull Runnable onFailure) { + this(activity, onSuccess); + failureCallback = onFailure; + } + @Override public AlertDialog show() { create(); From bcd1064e948808266c1a119b299dcdc1c2e38beb Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Wed, 17 Apr 2019 18:27:03 +0200 Subject: [PATCH 30/66] Updated superuser fragment to new arch Fixed theme issues along the way --- .../topjohnwu/magisk/di/ApplicationModule.kt | 1 + .../com/topjohnwu/magisk/di/DatabaseModule.kt | 5 +- .../topjohnwu/magisk/di/ViewModelsModule.kt | 2 + .../model/entity/recycler/PolicyRvItem.kt | 23 ++ .../magisk/model/events/ViewEvents.kt | 3 + .../magisk/ui/base/MagiskActivity.kt | 2 + .../magisk/ui/base/MagiskFragment.kt | 2 + .../magisk/ui/base/MagiskViewModel.kt | 6 + .../ui/superuser/SuperuserFragment.java | 63 ------ .../magisk/ui/superuser/SuperuserFragment.kt | 24 ++ .../magisk/ui/superuser/SuperuserViewModel.kt | 146 ++++++++++++ .../main/res/layout/fragment_superuser.xml | 69 ++++-- app/src/main/res/layout/item_policy.xml | 213 ++++++++++++++++++ app/src/main/res/values-night/styles_new.xml | 1 + app/src/main/res/values/styles_new.xml | 1 + 15 files changed, 476 insertions(+), 85 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt create mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt create mode 100644 app/src/main/res/layout/item_policy.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt index dd5e7bebc..f0545b75e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt @@ -10,4 +10,5 @@ val applicationModule = module { single { RxBus() } single { get().resources } single { get() as App } + single { get().packageManager } } diff --git a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt index b3c44dc0d..483f9e3ef 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt @@ -1,6 +1,9 @@ package com.topjohnwu.magisk.di +import com.topjohnwu.magisk.App import org.koin.dsl.module -val databaseModule = module {} +val databaseModule = module { + single { get().DB } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt index e4df34487..c4538d0f6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.di import com.topjohnwu.magisk.ui.MainViewModel import com.topjohnwu.magisk.ui.home.HomeViewModel +import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.dsl.module @@ -9,4 +10,5 @@ import org.koin.dsl.module val viewModelModules = module { viewModel { MainViewModel() } viewModel { HomeViewModel(get(), get()) } + viewModel { SuperuserViewModel(get(), get(), get()) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt new file mode 100644 index 000000000..e7093af63 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt @@ -0,0 +1,23 @@ +package com.topjohnwu.magisk.model.entity.recycler + +import android.graphics.drawable.Drawable +import com.skoumal.teanity.databinding.ComparableRvItem +import com.skoumal.teanity.util.KObservableField +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.model.entity.Policy +import com.topjohnwu.magisk.utils.toggle + +class PolicyRvItem(val item: Policy, val icon: Drawable) : ComparableRvItem() { + + override val layoutRes: Int = R.layout.item_policy + + val isExpanded = KObservableField(false) + val isEnabled = KObservableField(item.policy == Policy.ALLOW) + val shouldNotify = KObservableField(item.notification) + val shouldLog = KObservableField(item.logging) + + fun toggle() = isExpanded.toggle() + + override fun contentSameAs(other: PolicyRvItem): Boolean = itemSameAs(other) + override fun itemSameAs(other: PolicyRvItem): Boolean = item.uid == other.item.uid +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt index bc92e7479..f4b5fbf5b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.model.events +import android.app.Activity import com.skoumal.teanity.viewevents.ViewEvent @@ -15,3 +16,5 @@ class UninstallEvent : ViewEvent() class EnvFixEvent : ViewEvent() class UpdateSafetyNetEvent : ViewEvent() + +class ViewActionEvent(val action: Activity.() -> Unit) : ViewEvent() \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt index f145bde2a..b47364d17 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt @@ -11,6 +11,7 @@ import com.ncapdevi.fragnav.FragNavController import com.ncapdevi.fragnav.FragNavTransactionOptions import com.skoumal.teanity.viewevents.ViewEvent import com.topjohnwu.magisk.Config +import com.topjohnwu.magisk.model.events.ViewActionEvent import com.topjohnwu.magisk.model.navigation.MagiskAnimBuilder import com.topjohnwu.magisk.model.navigation.MagiskNavigationEvent import com.topjohnwu.magisk.model.navigation.Navigator @@ -62,6 +63,7 @@ abstract class MagiskActivity navigateTo(event) + is ViewActionEvent -> event.action(this) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt index fe7f97922..da231691f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskFragment.kt @@ -5,6 +5,7 @@ import androidx.databinding.ViewDataBinding import androidx.fragment.app.Fragment import com.skoumal.teanity.view.TeanityFragment import com.skoumal.teanity.viewevents.ViewEvent +import com.topjohnwu.magisk.model.events.ViewActionEvent import com.topjohnwu.magisk.model.navigation.MagiskNavigationEvent import com.topjohnwu.magisk.model.navigation.Navigator import kotlin.reflect.KClass @@ -25,6 +26,7 @@ abstract class MagiskFragment navigateTo(event) + is ViewActionEvent -> event.action(requireActivity()) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt index 2f7d29fcd..2df9d2c3d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt @@ -1,6 +1,8 @@ package com.topjohnwu.magisk.ui.base +import android.app.Activity import com.skoumal.teanity.viewmodel.LoadingViewModel +import com.topjohnwu.magisk.model.events.ViewActionEvent import com.topjohnwu.magisk.utils.Event import timber.log.Timber @@ -10,4 +12,8 @@ abstract class MagiskViewModel : LoadingViewModel(), Event.AutoListener { override fun onEvent(event: Int) = Timber.i("Event of $event was not handled") override fun getListeningEvents(): IntArray = intArrayOf() + fun withView(action: Activity.() -> Unit) { + ViewActionEvent(action).publish() + } + } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java deleted file mode 100644 index a78ca91ed..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.topjohnwu.magisk.ui.superuser; - -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.model.adapters.PolicyAdapter; -import com.topjohnwu.magisk.model.entity.Policy; -import com.topjohnwu.magisk.ui.base.BaseFragment; - -import java.util.List; - -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; - -public class SuperuserFragment extends BaseFragment { - - @BindView(R.id.recyclerView) RecyclerView recyclerView; - @BindView(R.id.empty_rv) TextView emptyRv; - - private PackageManager pm; - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_superuser, container, false); - unbinder = new SuperuserFragment_ViewBinding(this, view); - - pm = requireActivity().getPackageManager(); - return view; - } - - @Override - public void onStart() { - super.onStart(); - requireActivity().setTitle(getString(R.string.superuser)); - } - - @Override - public void onResume() { - super.onResume(); - displayPolicyList(); - } - - private void displayPolicyList() { - List policyList = app.getDB().getPolicyList(); - - if (policyList.size() == 0) { - emptyRv.setVisibility(View.VISIBLE); - recyclerView.setVisibility(View.GONE); - } else { - recyclerView.setAdapter(new PolicyAdapter(policyList, app.getDB(), pm)); - emptyRv.setVisibility(View.GONE); - recyclerView.setVisibility(View.VISIBLE); - } - } - -} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt new file mode 100644 index 000000000..db545db56 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt @@ -0,0 +1,24 @@ +package com.topjohnwu.magisk.ui.superuser + +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.databinding.FragmentSuperuserBinding +import com.topjohnwu.magisk.ui.base.MagiskFragment +import org.koin.androidx.viewmodel.ext.android.viewModel + +class SuperuserFragment : + MagiskFragment() { + + override val layoutRes: Int = R.layout.fragment_superuser + override val viewModel: SuperuserViewModel by viewModel() + + override fun onStart() { + super.onStart() + magiskActivity.supportActionBar?.title = getString(R.string.superuser) + } + + override fun onResume() { + super.onResume() + viewModel.updatePolicies() + } + +} 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 new file mode 100644 index 000000000..bf5e0935c --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -0,0 +1,146 @@ +package com.topjohnwu.magisk.ui.superuser + +import android.content.pm.PackageManager +import android.content.res.Resources +import com.skoumal.teanity.databinding.ComparableRvItem +import com.skoumal.teanity.extensions.addOnPropertyChangedCallback +import com.skoumal.teanity.extensions.applySchedulers +import com.skoumal.teanity.util.DiffObservableList +import com.skoumal.teanity.viewevents.SnackbarEvent +import com.topjohnwu.magisk.BR +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.data.database.MagiskDB +import com.topjohnwu.magisk.model.entity.Policy +import com.topjohnwu.magisk.model.entity.recycler.PolicyRvItem +import com.topjohnwu.magisk.ui.base.MagiskViewModel +import com.topjohnwu.magisk.utils.FingerprintHelper +import com.topjohnwu.magisk.utils.toggle +import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog +import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog +import io.reactivex.Single +import me.tatarka.bindingcollectionadapter2.ItemBinding +import timber.log.Timber + +class SuperuserViewModel( + private val database: MagiskDB, + private val packageManager: PackageManager, + private val resources: Resources +) : MagiskViewModel() { + + val items = DiffObservableList(ComparableRvItem.callback) + val itemBinding = ItemBinding.of> { itemBinding, _, item -> + item.bind(itemBinding) + itemBinding.bindExtra(BR.viewModel, this@SuperuserViewModel) + } + + private var ignoreNext: PolicyRvItem? = null + + init { + updatePolicies() + } + + fun updatePolicies() { + Single.fromCallable { database.policyList } + .flattenAsFlowable { it } + .map { PolicyRvItem(it, it.info.loadIcon(packageManager)).setListeners() } + .toList() + .applySchedulers() + .applyViewModel(this) + .subscribe({ + items.update(it) + }, Timber::e) + .add() + } + + fun deletePressed(item: PolicyRvItem) { + fun updateState() = deletePolicy(item.item) + .subscribe({ + items.remove(item) + }, Timber::e) + .add() + + withView { + if (FingerprintHelper.useFingerprint()) { + FingerprintAuthDialog(this) { updateState() }.show() + } else { + CustomAlertDialog(this) + .setTitle(R.string.su_revoke_title) + .setMessage(getString(R.string.su_revoke_msg, item.item.appName)) + .setPositiveButton(R.string.yes) { _, _ -> updateState() } + .setNegativeButton(R.string.no_thanks, null) + .setCancelable(true) + .show() + } + } + } + + private fun PolicyRvItem.setListeners() = apply { + isEnabled.addOnPropertyChangedCallback { + it ?: return@addOnPropertyChangedCallback + + if (ignoreNext == this) { + ignoreNext = null + return@addOnPropertyChangedCallback + } + + fun updateState() { + item.policy = if (it) Policy.ALLOW else Policy.DENY + + updatePolicy(item) + .map { it.policy == Policy.ALLOW } + .subscribe({ + val textId = if (it) R.string.su_snack_grant else R.string.su_snack_deny + val text = resources.getString(textId).format(item.appName) + SnackbarEvent(text).publish() + }, Timber::e) + .add() + } + + if (FingerprintHelper.useFingerprint()) { + withView { + FingerprintAuthDialog(this, { updateState() }, { + ignoreNext = this@setListeners + isEnabled.toggle() + }).show() + } + } else { + updateState() + } + } + shouldNotify.addOnPropertyChangedCallback { + it ?: return@addOnPropertyChangedCallback + item.notification = it + + updatePolicy(item) + .map { it.notification } + .subscribe({ + val textId = if (it) R.string.su_snack_notif_on else R.string.su_snack_notif_off + val text = resources.getString(textId).format(item.appName) + SnackbarEvent(text).publish() + }, Timber::e) + .add() + } + shouldLog.addOnPropertyChangedCallback { + it ?: return@addOnPropertyChangedCallback + item.logging = it + + updatePolicy(item) + .map { it.logging } + .subscribe({ + val textId = if (it) R.string.su_snack_log_on else R.string.su_snack_log_off + val text = resources.getString(textId).format(item.appName) + SnackbarEvent(text).publish() + }, Timber::e) + .add() + } + } + + private fun updatePolicy(policy: Policy) = + Single.fromCallable { database.updatePolicy(policy); policy } + .applySchedulers() + + private fun deletePolicy(policy: Policy) = + Single.fromCallable { database.deletePolicy(policy); policy } + .applySchedulers() + +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_superuser.xml b/app/src/main/res/layout/fragment_superuser.xml index a09b31fdd..c67588746 100644 --- a/app/src/main/res/layout/fragment_superuser.xml +++ b/app/src/main/res/layout/fragment_superuser.xml @@ -1,26 +1,53 @@ - + xmlns:tools="http://schemas.android.com/tools"> - + + + + + + + android:layout_height="match_parent"> - + + + + + + + + + + - diff --git a/app/src/main/res/layout/item_policy.xml b/app/src/main/res/layout/item_policy.xml new file mode 100644 index 000000000..d5ebbed9d --- /dev/null +++ b/app/src/main/res/layout/item_policy.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/styles_new.xml b/app/src/main/res/values-night/styles_new.xml index 5b0ea2a22..350f77b95 100644 --- a/app/src/main/res/values-night/styles_new.xml +++ b/app/src/main/res/values-night/styles_new.xml @@ -9,6 +9,7 @@ @color/dark_secondary_text ?android:attr/textColorSecondary @color/accentFallback + @android:color/black \ No newline at end of file diff --git a/app/src/main/res/values/styles_new.xml b/app/src/main/res/values/styles_new.xml index cc4fa1c1e..03793ea6d 100644 --- a/app/src/main/res/values/styles_new.xml +++ b/app/src/main/res/values/styles_new.xml @@ -10,6 +10,7 @@ @color/colorSecondary @color/colorSecondary @color/colorSecondaryDark + @android:color/white -