TileService reporting active/inactive from CameraUploadSettings; a tap arms or disarms the periodic MediaStore backup worker. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>pull/3589/head
parent
ae8d8566b9
commit
226a41bd61
@ -0,0 +1,56 @@
|
|||||||
|
package org.cloudreve.android.tile
|
||||||
|
|
||||||
|
import android.service.quicksettings.Tile
|
||||||
|
import android.service.quicksettings.TileService
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.cloudreve.android.CloudreveApp
|
||||||
|
import org.cloudreve.android.work.CameraUploadWorker
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick Settings tile: shows whether camera backup is armed and toggles
|
||||||
|
* it. Tap → backup on; tap again → off.
|
||||||
|
*/
|
||||||
|
class SyncTileService : TileService() {
|
||||||
|
|
||||||
|
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
|
|
||||||
|
override fun onStartListening() {
|
||||||
|
super.onStartListening()
|
||||||
|
scope.launch { refresh() }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick() {
|
||||||
|
super.onClick()
|
||||||
|
val app = applicationContext as CloudreveApp
|
||||||
|
scope.launch {
|
||||||
|
val cam = app.cameraUploadSettings.snapshotNow()
|
||||||
|
if (cam.enabled) {
|
||||||
|
app.cameraUploadSettings.setEnabled(false)
|
||||||
|
CameraUploadWorker.cancel(applicationContext)
|
||||||
|
} else {
|
||||||
|
app.cameraUploadSettings.setEnabled(true)
|
||||||
|
CameraUploadWorker.apply(applicationContext, cam.wifiOnly)
|
||||||
|
}
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun refresh() {
|
||||||
|
val app = applicationContext as CloudreveApp
|
||||||
|
val enabled = app.cameraUploadSettings.snapshotNow().enabled
|
||||||
|
qsTile?.apply {
|
||||||
|
state = if (enabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
|
||||||
|
subtitle = if (enabled) "Camera backup on" else "Camera backup off"
|
||||||
|
updateTile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
scope.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue