mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
save font preference in datastore
This commit is contained in:
parent
49df480e2b
commit
0ec409cad4
3 changed files with 18 additions and 13 deletions
|
|
@ -117,8 +117,8 @@ fun WebPreferencesView(webReaderViewModel: WebReaderViewModel) {
|
|||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clickable(onClick = {
|
||||
selectedWebFontRawValue.value = it.rawValue
|
||||
webReaderViewModel.applyWebFont(it)
|
||||
selectedWebFontRawValue.value = it.rawValue
|
||||
})
|
||||
) {
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package app.omnivore.omnivore.ui.reader
|
||||
|
||||
import android.util.Log
|
||||
import app.omnivore.omnivore.models.Highlight
|
||||
import app.omnivore.omnivore.models.LinkedItem
|
||||
import com.google.gson.Gson
|
||||
|
|
@ -15,7 +14,6 @@ enum class WebFont(val displayText: String, val rawValue: String) {
|
|||
ROBOTO("Roboto", "Roboto"),
|
||||
CRIMSON_TEXT("Crimson Text", "Crimson Text"),
|
||||
SOURCE_SERIF_PRO("Source Serif Pro", "Source Serif Pro"),
|
||||
Inter("Inter", "Inter"),
|
||||
}
|
||||
|
||||
enum class ArticleContentStatus(val rawValue: String) {
|
||||
|
|
@ -48,17 +46,19 @@ data class WebReaderContent(
|
|||
// TODO: Kotlinize these three values (pasted from Swift)
|
||||
val savedAt = "new Date(1662571290735.0).toISOString()"
|
||||
val createdAt = "new Date().toISOString()"
|
||||
val publishedAt = "new Date().toISOString()" //if (item.publishDate != null) "new Date((item.publishDate!.timeIntervalSince1970 * 1000)).toISOString()" else "undefined"
|
||||
val publishedAt =
|
||||
"new Date().toISOString()" //if (item.publishDate != null) "new Date((item.publishDate!.timeIntervalSince1970 * 1000)).toISOString()" else "undefined"
|
||||
val textFontSize = preferences.textFontSize
|
||||
val highlightCssFilePath = "highlight${if (themeKey == "Gray") "-dark" else ""}.css"
|
||||
|
||||
val content = """
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no' />
|
||||
<style>
|
||||
@import url("highlight${if (themeKey == "Gray") "-dark" else ""}.css");
|
||||
@import url("highlightCssFilePath");
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -106,7 +106,5 @@ data class WebReaderContent(
|
|||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
return content
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,15 +127,18 @@ class WebReaderViewModel @Inject constructor(
|
|||
val storedFontSize = datastoreRepo.getInt(DatastoreKeys.preferredWebFontSize)
|
||||
val storedLineHeight = datastoreRepo.getInt(DatastoreKeys.preferredWebLineHeight)
|
||||
val storedMaxWidth = datastoreRepo.getInt(DatastoreKeys.preferredWebMaxWidthPercentage)
|
||||
val storedFontFamily = datastoreRepo.getString(DatastoreKeys.preferredWebFontFamily)
|
||||
|
||||
val storedFontFamily = datastoreRepo.getString(DatastoreKeys.preferredWebFontFamily) ?: WebFont.SYSTEM.rawValue
|
||||
val storedWebFont = WebFont.values().first { it.rawValue == storedFontFamily }
|
||||
|
||||
val prefersHighContrastFont = datastoreRepo.getString(DatastoreKeys.prefersWebHighContrastText) == "true"
|
||||
|
||||
WebPreferences(
|
||||
textFontSize = storedFontSize ?: 12,
|
||||
lineHeight = storedLineHeight ?: 150,
|
||||
maxWidthPercentage = storedMaxWidth ?: 100,
|
||||
themeKey = "LightGray",
|
||||
fontFamily = WebFont.SYSTEM,
|
||||
themeKey = "LightGray", // TODO: match system value
|
||||
fontFamily = storedWebFont,
|
||||
prefersHighContrastText = prefersHighContrastFont
|
||||
)
|
||||
}
|
||||
|
|
@ -195,7 +198,11 @@ class WebReaderViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun applyWebFont(font: WebFont) {
|
||||
// TODO: update value in datastore and dispatch update to web view
|
||||
Log.d("Font", "Web Font selected: ${font.displayText}")
|
||||
runBlocking {
|
||||
datastoreRepo.putString(DatastoreKeys.preferredWebFontFamily, font.rawValue)
|
||||
}
|
||||
|
||||
val script = "var event = new Event('updateFontFamily');event.fontFamily = '${font.rawValue}';document.dispatchEvent(event);"
|
||||
enqueueScript(script)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue