app/src/main/kotlin/space/subread/dictionary/Store.kt (1908 bytes)
1 package space.subread.dictionary 2 3 import android.content.Context 4 import androidx.core.content.edit 5 import java.io.File 6 7 /** What the user chose. It stays when the app stops. */ 8 class Store(private val context: Context) { 9 10 private val prefs = context.getSharedPreferences("dictionary", Context.MODE_PRIVATE) 11 12 /** The sources of the local audio, in the order to try them. The names are the folder names of the Local Audio Server. */ 13 var localSources: String 14 get() = prefs.getString("local_sources", DEFAULT_LOCAL_SOURCES) ?: DEFAULT_LOCAL_SOURCES 15 set(value) = prefs.edit { putString("local_sources", value) } 16 17 /** The remote audio URLs, one per line, with {term} and {reading}. */ 18 var remoteUrls: String 19 get() = prefs.getString("remote_urls", DEFAULT_REMOTE_URLS) ?: DEFAULT_REMOTE_URLS 20 set(value) = prefs.edit { putString("remote_urls", value) } 21 22 /** Off until the user turns it on: a remote source sends the word to a server. */ 23 var remoteEnabled: Boolean 24 get() = prefs.getBoolean("remote_enabled", false) 25 set(value) = prefs.edit { putBoolean("remote_enabled", value) } 26 27 var textSizeSp: Float 28 get() = prefs.getFloat("text_size", 17f) 29 set(value) = prefs.edit { putFloat("text_size", value.coerceIn(11f, 40f)) } 30 31 /** 32 * The android.db of the local audio. In the app folder on the external storage: `adb push` and 33 * a file manager with a USB cable can reach it, and the app needs no permission for it. 34 */ 35 val localAudioFile: File 36 get() = File(context.getExternalFilesDir(null) ?: context.filesDir, "android.db") 37 38 companion object { 39 const val DEFAULT_LOCAL_SOURCES = "jpod, jpod_alternate, nhk16, shinmeikai8, forvo" 40 const val DEFAULT_REMOTE_URLS = 41 "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji={term}&kana={reading}" 42 } 43 }