Remove dexter dependency

This commit is contained in:
topjohnwu 2020-01-03 02:06:53 +08:00
parent 40c64d50d5
commit 465aaeff82
9 changed files with 34 additions and 60 deletions

View File

@ -132,5 +132,4 @@ dependencies {
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.core:core-ktx:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha01' implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'com.karumi:dexter:6.0.0'
} }

View File

@ -1,8 +1,8 @@
package com.topjohnwu.magisk.model.events package com.topjohnwu.magisk.model.events
import android.content.Context import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.topjohnwu.magisk.base.BaseActivity
interface ContextExecutor { interface ContextExecutor {
@ -12,7 +12,7 @@ interface ContextExecutor {
interface ActivityExecutor { interface ActivityExecutor {
operator fun invoke(activity: AppCompatActivity) operator fun invoke(activity: BaseActivity<*, *>)
} }

View File

@ -3,7 +3,6 @@ package com.topjohnwu.magisk.model.events
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import com.topjohnwu.magisk.Const import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.base.BaseActivity import com.topjohnwu.magisk.base.BaseActivity
import com.topjohnwu.magisk.intent import com.topjohnwu.magisk.intent
@ -11,7 +10,7 @@ import com.topjohnwu.magisk.ui.flash.FlashActivity
class InstallExternalModuleEvent : ViewEvent(), ActivityExecutor { class InstallExternalModuleEvent : ViewEvent(), ActivityExecutor {
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
activity as BaseActivity<*, *> activity as BaseActivity<*, *>
activity.withExternalRW { activity.withExternalRW {
onSuccess { onSuccess {

View File

@ -2,7 +2,6 @@ package com.topjohnwu.magisk.model.events
import android.content.Context import android.content.Context
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.topjohnwu.magisk.base.BaseActivity import com.topjohnwu.magisk.base.BaseActivity
import com.topjohnwu.magisk.extensions.snackbar import com.topjohnwu.magisk.extensions.snackbar
@ -28,7 +27,7 @@ class SnackbarEvent private constructor(
fun message(context: Context): String = messageString ?: context.getString(messageRes) fun message(context: Context): String = messageString ?: context.getString(messageRes)
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
if (activity is BaseActivity<*, *>) { if (activity is BaseActivity<*, *>) {
activity.snackbar(activity.snackbarView, message(activity), length, f) activity.snackbar(activity.snackbarView, message(activity), length, f)
} }

View File

@ -3,12 +3,6 @@ package com.topjohnwu.magisk.model.events
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import com.karumi.dexter.Dexter
import com.karumi.dexter.MultiplePermissionsReport
import com.karumi.dexter.PermissionToken
import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.topjohnwu.magisk.Const import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.base.BaseActivity import com.topjohnwu.magisk.base.BaseActivity
@ -17,7 +11,6 @@ import com.topjohnwu.magisk.extensions.DynamicClassLoader
import com.topjohnwu.magisk.extensions.subscribeK import com.topjohnwu.magisk.extensions.subscribeK
import com.topjohnwu.magisk.extensions.writeTo import com.topjohnwu.magisk.extensions.writeTo
import com.topjohnwu.magisk.model.entity.module.Repo import com.topjohnwu.magisk.model.entity.module.Repo
import com.topjohnwu.magisk.model.permissions.PermissionRequestBuilder
import com.topjohnwu.magisk.utils.RxBus import com.topjohnwu.magisk.utils.RxBus
import com.topjohnwu.magisk.utils.SafetyNetHelper import com.topjohnwu.magisk.utils.SafetyNetHelper
import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MagiskDialog
@ -137,7 +130,7 @@ class UpdateSafetyNetEvent : ViewEvent(), ContextExecutor, KoinComponent, Safety
} }
class ViewActionEvent(val action: BaseActivity<*, *>.() -> Unit) : ViewEvent(), ActivityExecutor { class ViewActionEvent(val action: BaseActivity<*, *>.() -> Unit) : ViewEvent(), ActivityExecutor {
override fun invoke(activity: AppCompatActivity) = (activity as BaseActivity<*, *>).run(action) override fun invoke(activity: BaseActivity<*, *>) = (activity as BaseActivity<*, *>).run(action)
} }
class OpenFilePickerEvent : ViewEvent() class OpenFilePickerEvent : ViewEvent()
@ -157,7 +150,8 @@ class PermissionEvent(
val callback: PublishSubject<Boolean> val callback: PublishSubject<Boolean>
) : ViewEvent(), ActivityExecutor { ) : ViewEvent(), ActivityExecutor {
private val permissionRequest = PermissionRequestBuilder().apply { override fun invoke(activity: BaseActivity<*, *>) =
activity.withPermissions(*permissions.toTypedArray()) {
onSuccess { onSuccess {
callback.onNext(true) callback.onNext(true)
} }
@ -165,46 +159,29 @@ class PermissionEvent(
callback.onNext(false) callback.onNext(false)
callback.onError(SecurityException("User refused permissions")) callback.onError(SecurityException("User refused permissions"))
} }
}.build()
override fun invoke(activity: AppCompatActivity) = Dexter.withActivity(activity)
.withPermissions(permissions)
.withListener(object : MultiplePermissionsListener {
override fun onPermissionRationaleShouldBeShown(
permissions: MutableList<PermissionRequest>,
token: PermissionToken
) = token.continuePermissionRequest()
override fun onPermissionsChecked(
report: MultiplePermissionsReport
) = if (report.areAllPermissionsGranted()) {
permissionRequest.onSuccess()
} else {
permissionRequest.onFailure()
} }
}).check()
} }
class BackPressEvent : ViewEvent(), ActivityExecutor { class BackPressEvent : ViewEvent(), ActivityExecutor {
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
activity.onBackPressed() activity.onBackPressed()
} }
} }
class DieEvent : ViewEvent(), ActivityExecutor { class DieEvent : ViewEvent(), ActivityExecutor {
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
activity.finish() activity.finish()
} }
} }
class RecreateEvent : ViewEvent(), ActivityExecutor { class RecreateEvent : ViewEvent(), ActivityExecutor {
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
activity.recreate() activity.recreate()
} }
} }
class RequestFileEvent : ViewEvent(), ActivityExecutor { class RequestFileEvent : ViewEvent(), ActivityExecutor {
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
Intent(Intent.ACTION_GET_CONTENT) Intent(Intent.ACTION_GET_CONTENT)
.setType("*/*") .setType("*/*")
.addCategory(Intent.CATEGORY_OPENABLE) .addCategory(Intent.CATEGORY_OPENABLE)

View File

@ -1,6 +1,6 @@
package com.topjohnwu.magisk.model.events.dialog package com.topjohnwu.magisk.model.events.dialog
import androidx.appcompat.app.AppCompatActivity import com.topjohnwu.magisk.base.BaseActivity
import com.topjohnwu.magisk.model.events.ActivityExecutor import com.topjohnwu.magisk.model.events.ActivityExecutor
import com.topjohnwu.magisk.model.events.ViewEvent import com.topjohnwu.magisk.model.events.ViewEvent
import com.topjohnwu.magisk.utils.BiometricHelper import com.topjohnwu.magisk.utils.BiometricHelper
@ -16,7 +16,7 @@ class BiometricDialog(
builder(Builder()) builder(Builder())
} }
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
BiometricHelper.authenticate( BiometricHelper.authenticate(
activity, activity,
onError = listenerOnFailure, onError = listenerOnFailure,

View File

@ -1,10 +1,10 @@
package com.topjohnwu.magisk.model.events.dialog package com.topjohnwu.magisk.model.events.dialog
import android.app.Activity import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.base.BaseActivity
import com.topjohnwu.magisk.model.events.ActivityExecutor import com.topjohnwu.magisk.model.events.ActivityExecutor
import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MagiskDialog
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
@ -13,7 +13,7 @@ class DarkThemeDialog : DialogEvent(), ActivityExecutor {
private var activity: WeakReference<Activity>? = null private var activity: WeakReference<Activity>? = null
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
this.activity = WeakReference(activity) this.activity = WeakReference(activity)
} }

View File

@ -3,8 +3,8 @@ package com.topjohnwu.magisk.model.navigation
import android.os.Bundle import android.os.Bundle
import androidx.annotation.AnimRes import androidx.annotation.AnimRes
import androidx.annotation.AnimatorRes import androidx.annotation.AnimatorRes
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.topjohnwu.magisk.base.BaseActivity
import com.topjohnwu.magisk.model.events.ActivityExecutor import com.topjohnwu.magisk.model.events.ActivityExecutor
import com.topjohnwu.magisk.model.events.ViewEvent import com.topjohnwu.magisk.model.events.ViewEvent
import com.topjohnwu.magisk.redesign.compat.CompatActivity import com.topjohnwu.magisk.redesign.compat.CompatActivity
@ -23,7 +23,7 @@ class MagiskNavigationEvent(
operator fun invoke(builder: Builder.() -> Unit) = Builder().apply(builder).build() operator fun invoke(builder: Builder.() -> Unit) = Builder().apply(builder).build()
} }
override fun invoke(activity: AppCompatActivity) { override fun invoke(activity: BaseActivity<*, *>) {
if (activity !is CompatActivity<*, *>) return if (activity !is CompatActivity<*, *>) return
activity.navigation?.navigateTo(this) activity.navigation?.navigateTo(this)
} }

View File

@ -2,10 +2,10 @@ package com.topjohnwu.magisk.redesign.compat
import android.graphics.Insets import android.graphics.Insets
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.topjohnwu.magisk.base.BaseActivity
import com.topjohnwu.magisk.model.events.ActivityExecutor import com.topjohnwu.magisk.model.events.ActivityExecutor
import com.topjohnwu.magisk.model.events.ContextExecutor import com.topjohnwu.magisk.model.events.ContextExecutor
import com.topjohnwu.magisk.model.events.FragmentExecutor import com.topjohnwu.magisk.model.events.FragmentExecutor
@ -26,7 +26,7 @@ class CompatDelegate internal constructor(
view.viewModel.requestRefresh() view.viewModel.requestRefresh()
} }
fun onEventExecute(event: ViewEvent, activity: AppCompatActivity) { fun onEventExecute(event: ViewEvent, activity: BaseActivity<*, *>) {
(event as? ContextExecutor)?.invoke(activity) (event as? ContextExecutor)?.invoke(activity)
(event as? ActivityExecutor)?.invoke(activity) (event as? ActivityExecutor)?.invoke(activity)
(event as? FragmentExecutor)?.let { (event as? FragmentExecutor)?.let {
@ -37,7 +37,7 @@ class CompatDelegate internal constructor(
fun onEventExecute(event: ViewEvent, fragment: Fragment) { fun onEventExecute(event: ViewEvent, fragment: Fragment) {
(event as? ContextExecutor)?.invoke(fragment.requireContext()) (event as? ContextExecutor)?.invoke(fragment.requireContext())
(event as? FragmentExecutor)?.invoke(fragment) (event as? FragmentExecutor)?.invoke(fragment)
(event as? ActivityExecutor)?.invoke(fragment.requireActivity() as AppCompatActivity) (event as? ActivityExecutor)?.invoke(fragment.requireActivity() as BaseActivity<*, *>)
} }
private fun ensureInsets() { private fun ensureInsets() {