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 a05134d16..f089ddff7 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 @@ -17,21 +17,21 @@ import kotlin.reflect.KClass abstract class MagiskFragment : TeanityFragment(), Navigator { - protected val magiskActivity get() = activity as MagiskActivity<*, *> + protected val activity get() = requireActivity() as MagiskActivity<*, *> // We don't need nested fragments override val baseFragments: List> = listOf() - override fun navigateTo(event: MagiskNavigationEvent) = magiskActivity.navigateTo(event) + override fun navigateTo(event: MagiskNavigationEvent) = activity.navigateTo(event) @CallSuper override fun onEventDispatched(event: ViewEvent) { super.onEventDispatched(event) when (event) { - is BackPressEvent -> magiskActivity.onBackPressed() + is BackPressEvent -> activity.onBackPressed() is MagiskNavigationEvent -> navigateTo(event) is ViewActionEvent -> event.action(requireActivity()) - is PermissionEvent -> magiskActivity.withPermissions(*event.permissions.toTypedArray()) { + is PermissionEvent -> activity.withPermissions(*event.permissions.toTypedArray()) { onSuccess { event.callback.onNext(true) } onFailure { event.callback.onNext(false) @@ -42,10 +42,10 @@ abstract class MagiskFragment Unit) { - magiskActivity.withPermissions(*permissions, builder = builder) + activity.withPermissions(*permissions, builder = builder) } - fun openLink(url: String) = magiskActivity.openUrl(url) + fun openLink(url: String) = activity.openUrl(url) open fun onBackPressed(): Boolean = false diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt index 9db8f2a67..80c98c253 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt @@ -21,7 +21,7 @@ class LogFragment : MagiskFragment() { override fun onEventDispatched(event: ViewEvent) { super.onEventDispatched(event) when (event) { - is PageChangedEvent -> magiskActivity.invalidateOptionsMenu() + is PageChangedEvent -> activity.invalidateOptionsMenu() } } @@ -33,7 +33,7 @@ class LogFragment : MagiskFragment() { override fun onStart() { super.onStart() setHasOptionsMenu(true) - magiskActivity.setTitle(R.string.log) + activity.setTitle(R.string.log) } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { @@ -43,7 +43,11 @@ class LogFragment : MagiskFragment() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_save -> viewModel.saveLog() + R.id.menu_save -> activity.withExternalRW { + onSuccess { + viewModel.saveLog() + } + } R.id.menu_clear -> viewModel.clearLog() R.id.menu_refresh -> viewModel.refresh() } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt index 087bf4223..279ac5036 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt @@ -9,6 +9,7 @@ import com.skoumal.teanity.util.DiffObservableList import com.skoumal.teanity.util.KObservableField import com.skoumal.teanity.viewevents.SnackbarEvent import com.topjohnwu.magisk.BR +import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Const import com.topjohnwu.magisk.R import com.topjohnwu.magisk.data.repository.LogRepository @@ -22,8 +23,8 @@ import com.topjohnwu.magisk.ui.base.MagiskViewModel import com.topjohnwu.superuser.Shell import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter import me.tatarka.bindingcollectionadapter2.OnItemBind +import timber.log.Timber import java.io.File -import java.io.IOException import java.util.* class LogViewModel( @@ -78,10 +79,11 @@ class LogViewModel( now.get(Calendar.MINUTE), now.get(Calendar.SECOND) ) - val logFile = File(Const.EXTERNAL_PATH, filename) - try { + val logFile = File(Config.downloadDirectory, filename) + runCatching { logFile.createNewFile() - } catch (e: IOException) { + }.onFailure { + Timber.e(it) return } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt index 3f213d120..17a1e16fa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt @@ -88,7 +88,7 @@ class ModulesFragment : MagiskFragment( } private fun selectFile() { - magiskActivity.withExternalRW { + activity.withExternalRW { onSuccess { val intent = Intent(Intent.ACTION_GET_CONTENT) intent.type = "application/zip" diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt index d360805bb..6fa93d20a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt @@ -94,7 +94,7 @@ class ReposFragment : MagiskFragment(), @SuppressLint("MissingPermission") private fun installModule(item: Repo) { - val context = magiskActivity + val context = activity fun download(install: Boolean) = context.withExternalRW { onSuccess {