Move cache pruning to a WorkManager worker (#3649)

- Extend what was `NotificationWorkerFactory` to `WorkerFactory`. This
  can construct arbitrary Workers as long as they provide their own
  Factory for construction.

  The per-Worker factory contains any injected components just for that
  worker type, keeping `WorkerFactory` clean.

- Move `NotificationWorkerFactory` to the new model.

- Implement `PruneCacheWorker`, and remove the code from
 `CachedTimelineViewModel`.

- Create the periodic worker in `TuskyApplication`, ensuring that the
  database is only pruned when the device is idle.
This commit is contained in:
Nik Clayton 2023-06-11 13:17:30 +02:00 committed by GitHub
commit 4025ab35ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 227 additions and 71 deletions

View file

@ -20,11 +20,11 @@ import android.content.Intent
import android.util.Log
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import com.keylesspalace.tusky.components.notifications.NotificationWorker
import com.keylesspalace.tusky.components.notifications.registerUnifiedPushEndpoint
import com.keylesspalace.tusky.components.notifications.unregisterUnifiedPushEndpoint
import com.keylesspalace.tusky.db.AccountManager
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.worker.NotificationWorker
import dagger.android.AndroidInjection
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope