Commit 4ef19d17 authored by Viktor De Pasquale's avatar Viktor De Pasquale Committed by John Wu

Added a flag for connection status

Reactively updated flag which only checks whether the "data" / "wifi" / "ethernet" is plugged in or enabled. If the user connects to the wifi but has no actual connection, the app will never know.
Please refrain from using other access methods (like pinging a host), it can get picked up by a VPN or other methods and possibly expose MM.
parent 223913c3
...@@ -62,6 +62,7 @@ dependencies { ...@@ -62,6 +62,7 @@ dependencies {
implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.github.skoumalcz:teanity:0.3.3' implementation 'com.github.skoumalcz:teanity:0.3.3'
implementation 'com.ncapdevi:frag-nav:3.2.0' implementation 'com.ncapdevi:frag-nav:3.2.0'
implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.3'
def vMarkwon = '3.1.0' def vMarkwon = '3.1.0'
implementation "ru.noties.markwon:core:${vMarkwon}" implementation "ru.noties.markwon:core:${vMarkwon}"
......
package com.topjohnwu.magisk.ui.base package com.topjohnwu.magisk.ui.base
import android.app.Activity import android.app.Activity
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
import com.skoumal.teanity.extensions.doOnSubscribeUi import com.skoumal.teanity.extensions.doOnSubscribeUi
import com.skoumal.teanity.extensions.subscribeK
import com.skoumal.teanity.util.KObservableField
import com.skoumal.teanity.viewmodel.LoadingViewModel import com.skoumal.teanity.viewmodel.LoadingViewModel
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
...@@ -12,6 +15,14 @@ import io.reactivex.subjects.PublishSubject ...@@ -12,6 +15,14 @@ import io.reactivex.subjects.PublishSubject
abstract class MagiskViewModel : LoadingViewModel() { abstract class MagiskViewModel : LoadingViewModel() {
val isConnected = KObservableField(true)
init {
ReactiveNetwork.observeInternetConnectivity()
.subscribeK { isConnected.value = it }
.add()
}
fun withView(action: Activity.() -> Unit) { fun withView(action: Activity.() -> Unit) {
ViewActionEvent(action).publish() ViewActionEvent(action).publish()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment