Files
RSSuper/android/src/main/java/com/rssuper/services/NotificationPreferencesStore.kt
Michael Freno 14efe072fa feat: implement cross-platform features and UI integration
- iOS: Add BackgroundSyncService, SyncScheduler, SyncWorker, BookmarkViewModel, FeedViewModel
- iOS: Add BackgroundSyncService, SyncScheduler, SyncWorker services
- Linux: Add settings-store.vala, State.vala signals, view widgets (FeedList, FeedDetail, AddFeed, Search, Settings, Bookmark)
- Linux: Add bookmark-store.vala, bookmark vala model, search-service.vala
- Android: Add NotificationService, NotificationManager, NotificationPreferencesStore
- Android: Add BookmarkDao, BookmarkRepository, SettingsStore
- Add unit tests for iOS, Android, Linux
- Add integration tests
- Add performance benchmarks
- Update tasks and documentation

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-30 23:06:12 -04:00

74 lines
2.6 KiB
Kotlin

package com.rssuper.services
import android.content.Context
import com.rssuper.database.RssDatabase
import com.rssuper.database.entities.NotificationPreferencesEntity
import com.rssuper.database.entities.toEntity
import com.rssuper.models.NotificationPreferences
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
class NotificationPreferencesStore(private val context: Context) {
private val database: RssDatabase = RssDatabase.getDatabase(context)
suspend fun getPreferences(): NotificationPreferences {
return withContext(Dispatchers.IO) {
val entity = database.notificationPreferencesDao().getSync("default")
entity?.toModel() ?: NotificationPreferences()
}
}
suspend fun savePreferences(preferences: NotificationPreferences) {
withContext(Dispatchers.IO) {
database.notificationPreferencesDao().insert(preferences.toEntity())
}
}
suspend fun updatePreference(
newArticles: Boolean? = null,
episodeReleases: Boolean? = null,
customAlerts: Boolean? = null,
badgeCount: Boolean? = null,
sound: Boolean? = null,
vibration: Boolean? = null
) {
withContext(Dispatchers.IO) {
val current = database.notificationPreferencesDao().getSync("default")
val preferences = current?.toModel() ?: NotificationPreferences()
val updated = preferences.copy(
newArticles = newArticles ?: preferences.newArticles,
episodeReleases = episodeReleases ?: preferences.episodeReleases,
customAlerts = customAlerts ?: preferences.customAlerts,
badgeCount = badgeCount ?: preferences.badgeCount,
sound = sound ?: preferences.sound,
vibration = vibration ?: preferences.vibration
)
database.notificationPreferencesDao().insert(updated.toEntity())
}
}
suspend fun isNotificationEnabled(type: NotificationType): Boolean {
val preferences = getPreferences()
return when (type) {
NotificationType.NEW_ARTICLE -> preferences.newArticles
NotificationType.PODCAST_EPISODE -> preferences.episodeReleases
NotificationType.LOW_PRIORITY, NotificationType.CRITICAL -> true
}
}
suspend fun isSoundEnabled(): Boolean {
return getPreferences().sound
}
suspend fun isVibrationEnabled(): Boolean {
return getPreferences().vibration
}
suspend fun isBadgeEnabled(): Boolean {
return getPreferences().badgeCount
}
}