mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-21 10:57:42 +00:00
Fixed unreasonable change resulting in major breakage all around the app
This commit is contained in:
@@ -5,7 +5,7 @@ import com.topjohnwu.magisk.extensions.doOnSubscribeUi
|
|||||||
import com.topjohnwu.magisk.model.events.BackPressEvent
|
import com.topjohnwu.magisk.model.events.BackPressEvent
|
||||||
import com.topjohnwu.magisk.model.events.PermissionEvent
|
import com.topjohnwu.magisk.model.events.PermissionEvent
|
||||||
import com.topjohnwu.magisk.model.events.ViewActionEvent
|
import com.topjohnwu.magisk.model.events.ViewActionEvent
|
||||||
import com.topjohnwu.magisk.utils.KObservableField
|
import com.topjohnwu.magisk.model.observer.Observer
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import com.topjohnwu.magisk.Info.isConnected as gIsConnected
|
import com.topjohnwu.magisk.Info.isConnected as gIsConnected
|
||||||
@@ -15,11 +15,7 @@ abstract class BaseViewModel(
|
|||||||
initialState: State = State.LOADING
|
initialState: State = State.LOADING
|
||||||
) : LoadingViewModel(initialState) {
|
) : LoadingViewModel(initialState) {
|
||||||
|
|
||||||
val isConnected = object : KObservableField<Boolean>(gIsConnected.value, gIsConnected) {
|
val isConnected = Observer(gIsConnected) { gIsConnected.value }
|
||||||
override fun get(): Boolean {
|
|
||||||
return gIsConnected.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun withView(action: Activity.() -> Unit) {
|
fun withView(action: Activity.() -> Unit) {
|
||||||
ViewActionEvent(action).publish()
|
ViewActionEvent(action).publish()
|
||||||
|
@@ -2,18 +2,30 @@ package com.topjohnwu.magisk.utils
|
|||||||
|
|
||||||
import androidx.databinding.Observable
|
import androidx.databinding.Observable
|
||||||
import androidx.databinding.ObservableField
|
import androidx.databinding.ObservableField
|
||||||
|
import com.topjohnwu.magisk.model.observer.Observer
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kotlin version of [ObservableField].
|
* Kotlin version of [ObservableField].
|
||||||
* You can define if wrapped type is Nullable or not.
|
* You can define if wrapped type is Nullable or not.
|
||||||
* You can use kotlin get/set syntax for value
|
* You can use kotlin get/set syntax for value
|
||||||
|
*
|
||||||
|
* ## Notes
|
||||||
|
* This stays final for fuck's sake. Too many things depend on it, so you just cannot go around and
|
||||||
|
* change it randomly. Even though you think you're improving the design, you might be fucking this
|
||||||
|
* up in unimaginable ways. So DON'T TOUCH THIS.
|
||||||
|
*
|
||||||
|
* In order to have value-less observer you need - you guessed it - **a fucking [Observer]**!
|
||||||
*/
|
*/
|
||||||
open class KObservableField<T> : ObservableField<T>, Serializable {
|
class KObservableField<T> : ObservableField<T>, Serializable {
|
||||||
|
|
||||||
var value: T
|
var value: T
|
||||||
get() = get()
|
set(value) {
|
||||||
set(value) { set(value) }
|
if (field != value) {
|
||||||
|
field = value
|
||||||
|
notifyChange()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constructor(init: T) {
|
constructor(init: T) {
|
||||||
value = init
|
value = init
|
||||||
@@ -23,8 +35,23 @@ open class KObservableField<T> : ObservableField<T>, Serializable {
|
|||||||
value = init
|
value = init
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Deprecated(
|
||||||
|
message = "Needed for data binding, use KObservableField.value syntax from code",
|
||||||
|
replaceWith = ReplaceWith("value")
|
||||||
|
)
|
||||||
override fun get(): T {
|
override fun get(): T {
|
||||||
return super.get() as T
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Needed for data binding, use KObservableField.value = ... syntax from code",
|
||||||
|
replaceWith = ReplaceWith("value = newValue")
|
||||||
|
)
|
||||||
|
override fun set(newValue: T) {
|
||||||
|
value = newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "KObservableField(value=$value)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user