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 9c3c725da..ce8d439ce 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,6 +1,7 @@ package com.topjohnwu.magisk.model.events import android.app.Activity +import android.content.Intent import androidx.appcompat.app.AppCompatActivity import com.karumi.dexter.Dexter import com.karumi.dexter.MultiplePermissionsReport @@ -96,3 +97,20 @@ class RecreateEvent : ViewEvent(), ActivityExecutor { activity.recreate() } } + +class RequestFileEvent : ViewEvent(), ActivityExecutor { + override fun invoke(activity: AppCompatActivity) { + Intent(Intent.ACTION_GET_CONTENT) + .setType("*/*") + .addCategory(Intent.CATEGORY_OPENABLE) + .also { activity.startActivityForResult(it, REQUEST_CODE) } + } + + companion object { + private const val REQUEST_CODE = 10 + fun resolve(requestCode: Int, resultCode: Int, data: Intent?) = data + ?.takeIf { resultCode == Activity.RESULT_OK } + ?.takeIf { requestCode == REQUEST_CODE } + ?.data + } +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatActivity.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatActivity.kt index 8f79c78f7..f0cb17d5d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatActivity.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.redesign.compat +import android.content.Intent import android.os.Bundle import android.view.View import android.view.ViewGroup @@ -29,6 +30,11 @@ abstract class CompatActivity( source.baseFragments[index].java.newInstance() //endregion + fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + controller.currentFrag?.onActivityResult(requestCode, resultCode, data) + } fun onCreate(savedInstanceState: Bundle?) = controller.run { rootFragmentListener = this@CompatNavigationDelegate diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt index fb4cb11d1..8721cca2a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt @@ -6,8 +6,9 @@ import androidx.databinding.Observable import com.topjohnwu.magisk.base.viewmodel.BaseViewModel import com.topjohnwu.magisk.utils.KObservableField import io.reactivex.disposables.Disposable +import org.koin.core.KoinComponent -abstract class CompatViewModel : BaseViewModel() { +abstract class CompatViewModel : BaseViewModel(), KoinComponent { val insets = KObservableField(Insets.NONE) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt index 09efdae15..9690f3282 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt @@ -1,8 +1,10 @@ package com.topjohnwu.magisk.ui.install +import android.content.Intent import android.graphics.Insets import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.FragmentInstallMd2Binding +import com.topjohnwu.magisk.model.events.RequestFileEvent import com.topjohnwu.magisk.redesign.compat.CompatFragment import org.koin.androidx.viewmodel.ext.android.viewModel @@ -13,6 +15,11 @@ class InstallFragment : CompatFragment(null) + + init { + method.addOnPropertyChangedCallback { + if (method.value == R.id.method_patch) { + RequestFileEvent().publish() + } + } + } + fun step(nextStep: Int) { step.value = nextStep } + fun install() = DownloadService(get()) { + subject = DownloadSubject.Magisk(resolveConfiguration()) + } + + // --- + + private fun resolveConfiguration() = when (method.value) { + R.id.method_download -> Configuration.Download + R.id.method_patch -> Configuration.Patch(data.value!!) + R.id.method_direct -> Configuration.Flash.Primary + R.id.method_inactive_slot -> Configuration.Flash.Secondary + else -> throw IllegalArgumentException("Unknown value") + } + + private fun isABDevice() = ShellUtils + .fastCmd("grep_prop ro.build.ab_update") + .let { it.isNotEmpty() && it.toBoolean() } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_install_md2.xml b/app/src/main/res/layout/fragment_install_md2.xml index 9aadeedcf..0d279e7c4 100644 --- a/app/src/main/res/layout/fragment_install_md2.xml +++ b/app/src/main/res/layout/fragment_install_md2.xml @@ -143,7 +143,7 @@ android:id="@+id/install_step_method_button" style="?styleButtonText" gone="@{viewModel.step != 1}" - isEnabled="@{viewModel.method != -1}" + isEnabled="@{viewModel.method == @id/method_patch ? viewModel.data != null : viewModel.method != -1}" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="@{() -> viewModel.step(2)}" @@ -179,12 +179,14 @@ android:id="@+id/method_direct" style="?styleRadioNormal" android:layout_width="match_parent" + gone="@{!viewModel.rooted}" android:layout_height="wrap_content" android:text="@string/direct_install" /> @@ -199,6 +201,7 @@ style="?styleButtonText" gone="@{viewModel.step != 2}" android:layout_width="wrap_content" + android:onClick="@{() -> viewModel.install()}" android:layout_height="wrap_content" android:layout_gravity="end" android:layout_margin="@dimen/l1"