generated from JetBrains/compose-multiplatform-template
-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for deleting read posts after a certain period (#173)
* Add query to delete read posts that are before a certain period * Add KotlinX datetime dependency to android app module * Move `FeedsRefreshWorker` to background package * Add data store preference for saving posts deletion period * Add extension to calculate instant before a given period * Add background worker on Android for posts clean up * Add `postsDeletionPeriodImmediate` to settings repository * Add background processing task on iOS for posts clean up * Rename `RssRepository#deletePosts` to `deleteReadPosts` * Add setting to configure read posts deletion period * Rename `Period.YEAR` to `Period.ONE_YEAR`
- Loading branch information
1 parent
cb698ac
commit 4699066
Showing
19 changed files
with
383 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
androidApp/src/androidMain/kotlin/dev/sasikanth/rss/reader/background/PostsCleanUpWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2023 Sasikanth Miriyampalli | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.sasikanth.rss.reader.background | ||
|
||
import android.content.Context | ||
import androidx.work.Constraints | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.NetworkType | ||
import androidx.work.PeriodicWorkRequest | ||
import androidx.work.PeriodicWorkRequestBuilder | ||
import androidx.work.WorkerParameters | ||
import dev.sasikanth.rss.reader.repository.RssRepository | ||
import dev.sasikanth.rss.reader.repository.SettingsRepository | ||
import dev.sasikanth.rss.reader.utils.calculateInstantBeforePeriod | ||
import io.sentry.Sentry | ||
import java.time.Duration | ||
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
class PostsCleanUpWorker( | ||
context: Context, | ||
workerParameters: WorkerParameters, | ||
private val rssRepository: RssRepository, | ||
private val settingsRepository: SettingsRepository | ||
) : CoroutineWorker(context, workerParameters) { | ||
|
||
companion object { | ||
|
||
const val TAG = "POSTS_CLEAN_UP" | ||
|
||
fun periodicRequest(): PeriodicWorkRequest { | ||
val constraints = | ||
Constraints.Builder() | ||
.setRequiredNetworkType(NetworkType.CONNECTED) | ||
.setRequiresBatteryNotLow(true) | ||
.build() | ||
|
||
return PeriodicWorkRequestBuilder<PostsCleanUpWorker>(repeatInterval = Duration.ofDays(1)) | ||
.setConstraints(constraints) | ||
.build() | ||
} | ||
} | ||
|
||
override suspend fun doWork(): Result { | ||
try { | ||
val postsDeletionPeriod = settingsRepository.postsDeletionPeriodImmediate() | ||
rssRepository.deleteReadPosts(before = postsDeletionPeriod.calculateInstantBeforePeriod()) | ||
return Result.success() | ||
} catch (e: CancellationException) { | ||
// no-op | ||
} catch (e: Exception) { | ||
Sentry.captureException(e) | ||
} | ||
|
||
return Result.failure() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.