You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Merge Teanity into sources
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.topjohnwu.magisk.model.events
|
||||
|
||||
internal interface EventHandler {
|
||||
|
||||
/**
|
||||
* Called for all [ViewEvent]s published by associated viewModel.
|
||||
* For [SimpleViewEvent]s, both this and [onSimpleEventDispatched]
|
||||
* methods are called - you can choose the way how you handle them.
|
||||
*/
|
||||
fun onEventDispatched(event: ViewEvent) {}
|
||||
|
||||
/**
|
||||
* Called for all [SimpleViewEvent]s published by associated viewModel.
|
||||
* Both this and [onEventDispatched] methods are called - you can choose
|
||||
* the way how you handle them.
|
||||
*/
|
||||
fun onSimpleEventDispatched(event: Int) {}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.topjohnwu.magisk.model.events
|
||||
|
||||
import com.skoumal.teanity.rxbus.RxBus
|
||||
import com.topjohnwu.magisk.utils.RxBus
|
||||
import com.topjohnwu.magisk.model.entity.MagiskPolicy
|
||||
import com.topjohnwu.magisk.model.entity.recycler.HideProcessRvItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.ModuleRvItem
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.topjohnwu.magisk.model.events
|
||||
|
||||
import com.topjohnwu.magisk.model.events.ViewEvent
|
||||
|
||||
class SimpleViewEvent(
|
||||
val event: Int
|
||||
) : ViewEvent()
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.topjohnwu.magisk.model.events
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.StringRes
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.topjohnwu.magisk.model.events.ViewEvent
|
||||
|
||||
class SnackbarEvent private constructor(
|
||||
@StringRes private val messageRes: Int,
|
||||
private val messageString: String?,
|
||||
val length: Int,
|
||||
val f: Snackbar.() -> Unit
|
||||
) : ViewEvent() {
|
||||
|
||||
constructor(
|
||||
@StringRes messageRes: Int,
|
||||
length: Int = Snackbar.LENGTH_SHORT,
|
||||
f: Snackbar.() -> Unit = {}
|
||||
) : this(messageRes, null, length, f)
|
||||
|
||||
constructor(
|
||||
message: String,
|
||||
length: Int = Snackbar.LENGTH_SHORT,
|
||||
f: Snackbar.() -> Unit = {}
|
||||
) : this(-1, message, length, f)
|
||||
|
||||
fun message(context: Context): String = messageString ?: context.getString(messageRes)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.topjohnwu.magisk.model.events
|
||||
|
||||
import androidx.lifecycle.Observer
|
||||
|
||||
/**
|
||||
* Observer for [ViewEvent]s, which automatically checks if event was handled
|
||||
*/
|
||||
class ViewEventObserver(private val onEventUnhandled: (ViewEvent) -> Unit) : Observer<ViewEvent> {
|
||||
override fun onChanged(event: ViewEvent?) {
|
||||
event?.let {
|
||||
if (!it.handled) {
|
||||
it.handled = true
|
||||
onEventUnhandled(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
package com.topjohnwu.magisk.model.events
|
||||
|
||||
import android.app.Activity
|
||||
import com.skoumal.teanity.viewevents.ViewEvent
|
||||
import com.topjohnwu.magisk.model.entity.module.Repo
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
|
||||
/**
|
||||
* Class for passing events from ViewModels to Activities/Fragments
|
||||
* Variable [handled] used so each event is handled only once
|
||||
* (see https://medium.com/google-developers/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case-ac2622673150)
|
||||
* Use [ViewEventObserver] for observing these events
|
||||
*/
|
||||
abstract class ViewEvent {
|
||||
|
||||
var handled = false
|
||||
}
|
||||
|
||||
data class OpenLinkEvent(val url: String) : ViewEvent()
|
||||
|
||||
@@ -35,4 +44,4 @@ class PermissionEvent(
|
||||
|
||||
class BackPressEvent : ViewEvent()
|
||||
|
||||
class DieEvent : ViewEvent()
|
||||
class DieEvent : ViewEvent()
|
||||
|
||||
Reference in New Issue
Block a user