mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
parent
71d855e836
commit
eb5ce5be1e
@ -17,21 +17,21 @@ import kotlin.reflect.KClass
|
||||
abstract class MagiskFragment<ViewModel : MagiskViewModel, Binding : ViewDataBinding> :
|
||||
TeanityFragment<ViewModel, Binding>(), 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<KClass<Fragment>> = 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<ViewModel : MagiskViewModel, Binding : ViewDataBin
|
||||
}
|
||||
|
||||
fun withPermissions(vararg permissions: String, builder: PermissionRequestBuilder.() -> 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
|
||||
|
||||
|
@ -21,7 +21,7 @@ class LogFragment : MagiskFragment<LogViewModel, FragmentLogBinding>() {
|
||||
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<LogViewModel, FragmentLogBinding>() {
|
||||
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<LogViewModel, FragmentLogBinding>() {
|
||||
|
||||
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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ class ModulesFragment : MagiskFragment<ModuleViewModel, FragmentModulesBinding>(
|
||||
}
|
||||
|
||||
private fun selectFile() {
|
||||
magiskActivity.withExternalRW {
|
||||
activity.withExternalRW {
|
||||
onSuccess {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.type = "application/zip"
|
||||
|
@ -94,7 +94,7 @@ class ReposFragment : MagiskFragment<ModuleViewModel, FragmentReposBinding>(),
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun installModule(item: Repo) {
|
||||
val context = magiskActivity
|
||||
val context = activity
|
||||
|
||||
fun download(install: Boolean) = context.withExternalRW {
|
||||
onSuccess {
|
||||
|
Loading…
x
Reference in New Issue
Block a user