summaryrefslogtreecommitdiff
path: root/app/src/main/java/org/terst/feedreader/data/Settings.kt
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-07-22 08:08:58 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-07-22 08:08:58 +0000
commitd8ce4b3c0f383e844b125d2d3abd618715bb3c89 (patch)
treeb586ff9b42392f2c44645773c2a2f2aadb9db406 /app/src/main/java/org/terst/feedreader/data/Settings.kt
Initial commit: Feeds, an Android RSS reader
Feed subscriptions (RSS 2.0 + Atom, hand-rolled parser), OPML import/export, WorkManager periodic fetch with conditional GET, Room-backed local storage (feeds/articles/filter rules), keyword mute/highlight filtering. Reader mode: on-device extraction via Mozilla's Readability.js (vendored from github.com/mozilla/readability, pinned to release 0.6.0) run in a hidden WebView, for feed articles whose provided content is too thin to be the real article body. Save: explicit action (from a feed article, or the Android share-sheet target for any URL) archives to Stash via POST /artifacts?sync=true, while a local on-device copy (Readability-extracted) is always kept so saved articles read offline regardless of Stash's reachability. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZ7ikw2ukGJFTHE3bJS7zL
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/data/Settings.kt')
-rw-r--r--app/src/main/java/org/terst/feedreader/data/Settings.kt34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/src/main/java/org/terst/feedreader/data/Settings.kt b/app/src/main/java/org/terst/feedreader/data/Settings.kt
new file mode 100644
index 0000000..b4af70e
--- /dev/null
+++ b/app/src/main/java/org/terst/feedreader/data/Settings.kt
@@ -0,0 +1,34 @@
+package org.terst.feedreader.data
+
+import android.content.Context
+import androidx.datastore.preferences.core.edit
+import androidx.datastore.preferences.core.stringPreferencesKey
+import androidx.datastore.preferences.preferencesDataStore
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.flow.map
+
+val Context.settingsDataStore by preferencesDataStore(name = "settings")
+
+private object SettingsKeys {
+ val STASH_BASE_URL = stringPreferencesKey("stash_base_url")
+ val STASH_API_KEY = stringPreferencesKey("stash_api_key")
+}
+
+/** Stash connection settings, configured on the Settings screen. Both blank until set. */
+class Settings(private val context: Context) {
+ val stashBaseUrl: Flow<String> =
+ context.settingsDataStore.data.map { it[SettingsKeys.STASH_BASE_URL] ?: "" }
+ val stashApiKey: Flow<String> =
+ context.settingsDataStore.data.map { it[SettingsKeys.STASH_API_KEY] ?: "" }
+
+ suspend fun stashBaseUrlNow(): String = stashBaseUrl.first()
+ suspend fun stashApiKeyNow(): String = stashApiKey.first()
+
+ suspend fun setStash(baseUrl: String, apiKey: String) {
+ context.settingsDataStore.edit { prefs ->
+ prefs[SettingsKeys.STASH_BASE_URL] = baseUrl.trim().trimEnd('/')
+ prefs[SettingsKeys.STASH_API_KEY] = apiKey.trim()
+ }
+ }
+}