1
mirror of https://github.com/topjohnwu/Magisk synced 2024-11-05 04:51:15 +01:00

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.
This commit is contained in:
Viktor De Pasquale 2019-08-06 15:04:55 +02:00 committed by John Wu
parent 223913c30a
commit 4ef19d17da
2 changed files with 12 additions and 0 deletions

View File

@ -62,6 +62,7 @@ dependencies {
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.github.skoumalcz:teanity:0.3.3'
implementation 'com.ncapdevi:frag-nav:3.2.0'
implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.3'
def vMarkwon = '3.1.0'
implementation "ru.noties.markwon:core:${vMarkwon}"

View File

@ -1,7 +1,10 @@
package com.topjohnwu.magisk.ui.base
import android.app.Activity
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
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.topjohnwu.magisk.model.events.BackPressEvent
import com.topjohnwu.magisk.model.events.PermissionEvent
@ -12,6 +15,14 @@ import io.reactivex.subjects.PublishSubject
abstract class MagiskViewModel : LoadingViewModel() {
val isConnected = KObservableField(true)
init {
ReactiveNetwork.observeInternetConnectivity()
.subscribeK { isConnected.value = it }
.add()
}
fun withView(action: Activity.() -> Unit) {
ViewActionEvent(action).publish()
}