Cleanup ActivityResult callbacks

This commit is contained in:
topjohnwu
2020-10-06 02:04:19 -07:00
parent 333fe6da0e
commit fc19b50290
11 changed files with 58 additions and 106 deletions
@@ -1,12 +1,10 @@
package com.topjohnwu.magisk.ui.install
import android.content.Intent
import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.BaseUIFragment
import com.topjohnwu.magisk.core.download.BaseDownloader
import com.topjohnwu.magisk.databinding.FragmentInstallMd2Binding
import com.topjohnwu.magisk.events.RequestFileEvent
import com.topjohnwu.magisk.ktx.coroutineScope
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -15,11 +13,6 @@ class InstallFragment : BaseUIFragment<InstallViewModel, FragmentInstallMd2Bindi
override val layoutRes = R.layout.fragment_install_md2
override val viewModel by viewModel<InstallViewModel>()
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
viewModel.data = RequestFileEvent.resolve(requestCode, resultCode, data)
}
override fun onStart() {
super.onStart()
requireActivity().setTitle(R.string.install)
@@ -1,5 +1,6 @@
package com.topjohnwu.magisk.ui.install
import android.app.Activity
import android.net.Uri
import androidx.databinding.Bindable
import androidx.lifecycle.viewModelScope
@@ -11,7 +12,7 @@ import com.topjohnwu.magisk.core.download.Action
import com.topjohnwu.magisk.core.download.DownloadService
import com.topjohnwu.magisk.core.download.Subject
import com.topjohnwu.magisk.data.repository.StringRepository
import com.topjohnwu.magisk.events.RequestFileEvent
import com.topjohnwu.magisk.events.MagiskInstallFileEvent
import com.topjohnwu.magisk.events.dialog.SecondSlotWarningDialog
import com.topjohnwu.magisk.utils.set
import com.topjohnwu.superuser.Shell
@@ -35,7 +36,10 @@ class InstallViewModel(
set(value) = set(value, field, { field = it }, BR.method) {
when (it) {
R.id.method_patch -> {
RequestFileEvent().publish()
MagiskInstallFileEvent { code, intent ->
if (code == Activity.RESULT_OK)
data = intent?.data
}.publish()
}
R.id.method_inactive_slot -> {
SecondSlotWarningDialog().publish()