From d3f49334e299466b83643516f62920a8b05f64d5 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 28 Sep 2019 12:17:34 -0400 Subject: [PATCH] Move function as extension --- .../java/com/topjohnwu/magisk/base/BaseActivity.kt | 12 ++++-------- .../java/com/topjohnwu/magisk/extensions/XAndroid.kt | 6 +++++- .../com/topjohnwu/magisk/ui/home/HomeFragment.kt | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/base/BaseActivity.kt b/app/src/main/java/com/topjohnwu/magisk/base/BaseActivity.kt index e9c049ff2..04dad084f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/base/BaseActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/base/BaseActivity.kt @@ -11,7 +11,6 @@ import androidx.appcompat.app.AppCompatDelegate import androidx.collection.SparseArrayCompat import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat -import androidx.core.net.toUri import androidx.databinding.DataBindingUtil import androidx.databinding.ViewDataBinding import com.topjohnwu.magisk.BR @@ -21,7 +20,6 @@ import com.topjohnwu.magisk.extensions.set import com.topjohnwu.magisk.model.events.EventHandler import com.topjohnwu.magisk.model.permissions.PermissionRequestBuilder import com.topjohnwu.magisk.utils.LocaleManager -import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.currentLocale import kotlin.random.Random @@ -69,8 +67,6 @@ abstract class BaseActivity Unit) { val request = PermissionRequestBuilder().apply(builder).build() val ungranted = permissions.filter { @@ -91,6 +87,10 @@ abstract class BaseActivity Unit) { + withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, builder = builder) + } + override fun onRequestPermissionsResult( requestCode: Int, permissions: Array, grantResults: IntArray) { var success = true @@ -107,10 +107,6 @@ abstract class BaseActivity Unit) { - withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, builder = builder) - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) resultCallbacks[requestCode]?.apply { diff --git a/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt b/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt index 3c669600a..d8d5802f3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt +++ b/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt @@ -17,7 +17,9 @@ import android.view.View import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat +import androidx.core.net.toUri import com.topjohnwu.magisk.utils.FileProvider +import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.currentLocale import java.io.File import java.io.FileNotFoundException @@ -152,4 +154,6 @@ fun Context.startEndToLeftRight(start: Int, end: Int): Pair { return end to start } return start to end -} \ No newline at end of file +} + +fun Context.openUrl(url: String) = Utils.openLink(this, url.toUri()) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt index bc17b8368..a35207f61 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt @@ -10,6 +10,7 @@ import com.topjohnwu.magisk.base.BaseFragment import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.databinding.FragmentMagiskBinding import com.topjohnwu.magisk.extensions.inject +import com.topjohnwu.magisk.extensions.openUrl import com.topjohnwu.magisk.extensions.subscribeK import com.topjohnwu.magisk.extensions.writeTo import com.topjohnwu.magisk.model.events.*