Fix linting error

This commit is contained in:
arkon 2022-10-09 10:54:54 -04:00
parent 0d9c1e6e9c
commit b95a30e424

View file

@ -98,7 +98,7 @@ class DownloadService : Service() {
ioScope?.cancel() ioScope?.cancel()
_isRunning.value = false _isRunning.value = false
downloadManager.stopDownloads() downloadManager.stopDownloads()
wakeLock.releaseIfNeeded() wakeLock.releaseIfHeld()
super.onDestroy() super.onDestroy()
} }
@ -116,9 +116,6 @@ class DownloadService : Service() {
downloadManager.stopDownloads(getString(string)) downloadManager.stopDownloads(getString(string))
} }
/**
* Listens to network changes.
*/
private fun listenNetworkChanges() { private fun listenNetworkChanges() {
ReactiveNetwork() ReactiveNetwork()
.observeNetworkConnectivity(applicationContext) .observeNetworkConnectivity(applicationContext)
@ -153,26 +150,22 @@ class DownloadService : Service() {
_isRunning _isRunning
.onEach { isRunning -> .onEach { isRunning ->
if (isRunning) { if (isRunning) {
wakeLock.acquireIfNeeded() wakeLock.acquireIfNotHeld()
} else { } else {
wakeLock.releaseIfNeeded() wakeLock.releaseIfHeld()
} }
} }
.catch { /* Ignore errors */ } .catch {
// Ignore errors
}
.launchIn(ioScope) .launchIn(ioScope)
} }
/** private fun PowerManager.WakeLock.releaseIfHeld() {
* Releases the wake lock if it's held.
*/
private fun PowerManager.WakeLock.releaseIfNeeded() {
if (isHeld) release() if (isHeld) release()
} }
/** private fun PowerManager.WakeLock.acquireIfNotHeld() {
* Acquires the wake lock if it's not held.
*/
private fun PowerManager.WakeLock.acquireIfNeeded() {
if (!isHeld) acquire() if (!isHeld) acquire()
} }