mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 06:09:18 +01:00
Replace Wi-Fi connection check with WifiManager
Previous implementation couldn't detect Wi-Fi connection while using a VPN.
This commit is contained in:
parent
d25707554e
commit
3155829994
@ -21,6 +21,7 @@ import eu.kanade.tachiyomi.util.system.connectivityManager
|
|||||||
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
||||||
import eu.kanade.tachiyomi.util.system.notification
|
import eu.kanade.tachiyomi.util.system.notification
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
|
import eu.kanade.tachiyomi.util.system.wifiManager
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.schedulers.Schedulers
|
import rx.schedulers.Schedulers
|
||||||
import rx.subscriptions.CompositeSubscription
|
import rx.subscriptions.CompositeSubscription
|
||||||
@ -153,7 +154,7 @@ class DownloadService : Service() {
|
|||||||
return stopDownloads(R.string.download_notifier_no_network)
|
return stopDownloads(R.string.download_notifier_no_network)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferences.downloadOnlyOverWifi() && !networkCapabilities.connectedToWifi()) {
|
if (preferences.downloadOnlyOverWifi() && !wifiManager.isWifiEnabled) {
|
||||||
stopDownloads(R.string.download_notifier_text_only_wifi)
|
stopDownloads(R.string.download_notifier_text_only_wifi)
|
||||||
} else {
|
} else {
|
||||||
val started = downloadManager.startDownloads()
|
val started = downloadManager.startDownloads()
|
||||||
@ -170,10 +171,6 @@ class DownloadService : Service() {
|
|||||||
this.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
this.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun NetworkCapabilities.connectedToWifi(): Boolean {
|
|
||||||
return this.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens to downloader status. Enables or disables the wake lock depending on the status.
|
* Listens to downloader status. Enables or disables the wake lock depending on the status.
|
||||||
*/
|
*/
|
||||||
|
@ -16,6 +16,7 @@ import android.content.res.Resources
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
@ -190,6 +191,9 @@ val Context.notificationManager: NotificationManager
|
|||||||
val Context.connectivityManager: ConnectivityManager
|
val Context.connectivityManager: ConnectivityManager
|
||||||
get() = getSystemService()!!
|
get() = getSystemService()!!
|
||||||
|
|
||||||
|
val Context.wifiManager: WifiManager
|
||||||
|
get() = getSystemService()!!
|
||||||
|
|
||||||
val Context.powerManager: PowerManager
|
val Context.powerManager: PowerManager
|
||||||
get() = getSystemService()!!
|
get() = getSystemService()!!
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user