parent
71d855e836
commit
eb5ce5be1e
@ -17,21 +17,21 @@ import kotlin.reflect.KClass
|
|||||||
abstract class MagiskFragment<ViewModel : MagiskViewModel, Binding : ViewDataBinding> :
|
abstract class MagiskFragment<ViewModel : MagiskViewModel, Binding : ViewDataBinding> :
|
||||||
TeanityFragment<ViewModel, Binding>(), Navigator {
|
TeanityFragment<ViewModel, Binding>(), Navigator {
|
||||||
|
|
||||||
protected val magiskActivity get() = activity as MagiskActivity<*, *>
|
protected val activity get() = requireActivity() as MagiskActivity<*, *>
|
||||||
|
|
||||||
// We don't need nested fragments
|
// We don't need nested fragments
|
||||||
override val baseFragments: List<KClass<Fragment>> = listOf()
|
override val baseFragments: List<KClass<Fragment>> = listOf()
|
||||||
|
|
||||||
override fun navigateTo(event: MagiskNavigationEvent) = magiskActivity.navigateTo(event)
|
override fun navigateTo(event: MagiskNavigationEvent) = activity.navigateTo(event)
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onEventDispatched(event: ViewEvent) {
|
override fun onEventDispatched(event: ViewEvent) {
|
||||||
super.onEventDispatched(event)
|
super.onEventDispatched(event)
|
||||||
when (event) {
|
when (event) {
|
||||||
is BackPressEvent -> magiskActivity.onBackPressed()
|
is BackPressEvent -> activity.onBackPressed()
|
||||||
is MagiskNavigationEvent -> navigateTo(event)
|
is MagiskNavigationEvent -> navigateTo(event)
|
||||||
is ViewActionEvent -> event.action(requireActivity())
|
is ViewActionEvent -> event.action(requireActivity())
|
||||||
is PermissionEvent -> magiskActivity.withPermissions(*event.permissions.toTypedArray()) {
|
is PermissionEvent -> activity.withPermissions(*event.permissions.toTypedArray()) {
|
||||||
onSuccess { event.callback.onNext(true) }
|
onSuccess { event.callback.onNext(true) }
|
||||||
onFailure {
|
onFailure {
|
||||||
event.callback.onNext(false)
|
event.callback.onNext(false)
|
||||||
@ -42,10 +42,10 @@ abstract class MagiskFragment<ViewModel : MagiskViewModel, Binding : ViewDataBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun withPermissions(vararg permissions: String, builder: PermissionRequestBuilder.() -> Unit) {
|
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
|
open fun onBackPressed(): Boolean = false
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class LogFragment : MagiskFragment<LogViewModel, FragmentLogBinding>() {
|
|||||||
override fun onEventDispatched(event: ViewEvent) {
|
override fun onEventDispatched(event: ViewEvent) {
|
||||||
super.onEventDispatched(event)
|
super.onEventDispatched(event)
|
||||||
when (event) {
|
when (event) {
|
||||||
is PageChangedEvent -> magiskActivity.invalidateOptionsMenu()
|
is PageChangedEvent -> activity.invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class LogFragment : MagiskFragment<LogViewModel, FragmentLogBinding>() {
|
|||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
magiskActivity.setTitle(R.string.log)
|
activity.setTitle(R.string.log)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
@ -43,7 +43,11 @@ class LogFragment : MagiskFragment<LogViewModel, FragmentLogBinding>() {
|
|||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
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_clear -> viewModel.clearLog()
|
||||||
R.id.menu_refresh -> viewModel.refresh()
|
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.util.KObservableField
|
||||||
import com.skoumal.teanity.viewevents.SnackbarEvent
|
import com.skoumal.teanity.viewevents.SnackbarEvent
|
||||||
import com.topjohnwu.magisk.BR
|
import com.topjohnwu.magisk.BR
|
||||||
|
import com.topjohnwu.magisk.Config
|
||||||
import com.topjohnwu.magisk.Const
|
import com.topjohnwu.magisk.Const
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.data.repository.LogRepository
|
import com.topjohnwu.magisk.data.repository.LogRepository
|
||||||
@ -22,8 +23,8 @@ import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
|||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter
|
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter
|
||||||
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
||||||
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LogViewModel(
|
class LogViewModel(
|
||||||
@ -78,10 +79,11 @@ class LogViewModel(
|
|||||||
now.get(Calendar.MINUTE), now.get(Calendar.SECOND)
|
now.get(Calendar.MINUTE), now.get(Calendar.SECOND)
|
||||||
)
|
)
|
||||||
|
|
||||||
val logFile = File(Const.EXTERNAL_PATH, filename)
|
val logFile = File(Config.downloadDirectory, filename)
|
||||||
try {
|
runCatching {
|
||||||
logFile.createNewFile()
|
logFile.createNewFile()
|
||||||
} catch (e: IOException) {
|
}.onFailure {
|
||||||
|
Timber.e(it)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ class ModulesFragment : MagiskFragment<ModuleViewModel, FragmentModulesBinding>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun selectFile() {
|
private fun selectFile() {
|
||||||
magiskActivity.withExternalRW {
|
activity.withExternalRW {
|
||||||
onSuccess {
|
onSuccess {
|
||||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||||
intent.type = "application/zip"
|
intent.type = "application/zip"
|
||||||
|
@ -94,7 +94,7 @@ class ReposFragment : MagiskFragment<ModuleViewModel, FragmentReposBinding>(),
|
|||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun installModule(item: Repo) {
|
private fun installModule(item: Repo) {
|
||||||
val context = magiskActivity
|
val context = activity
|
||||||
|
|
||||||
fun download(install: Boolean) = context.withExternalRW {
|
fun download(install: Boolean) = context.withExternalRW {
|
||||||
onSuccess {
|
onSuccess {
|
||||||
|
Loading…
Reference in New Issue
Block a user