1.3 Beta working settings !!!
This commit is contained in:
@@ -10,6 +10,8 @@ import androidx.compose.foundation.gestures.detectTapGestures
|
|||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.*
|
||||||
@@ -65,6 +67,7 @@ fun ReaderScreen(
|
|||||||
|
|
||||||
var showControls by remember { mutableStateOf(true) }
|
var showControls by remember { mutableStateOf(true) }
|
||||||
var showChapterList by remember { mutableStateOf(false) }
|
var showChapterList by remember { mutableStateOf(false) }
|
||||||
|
var showSettings by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val backgroundColor = MaterialTheme.colorScheme.background.toArgb()
|
val backgroundColor = MaterialTheme.colorScheme.background.toArgb()
|
||||||
val textColor = MaterialTheme.colorScheme.onBackground.toArgb()
|
val textColor = MaterialTheme.colorScheme.onBackground.toArgb()
|
||||||
@@ -170,7 +173,7 @@ fun ReaderScreen(
|
|||||||
IconButton(onClick = { showChapterList = true }) {
|
IconButton(onClick = { showChapterList = true }) {
|
||||||
Icon(Icons.Default.List, contentDescription = "Chapters")
|
Icon(Icons.Default.List, contentDescription = "Chapters")
|
||||||
}
|
}
|
||||||
IconButton(onClick = { /* TODO: Add settings dialog */ }) {
|
IconButton(onClick = { showSettings = true }) {
|
||||||
Icon(Icons.Default.Settings, contentDescription = "Settings")
|
Icon(Icons.Default.Settings, contentDescription = "Settings")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,7 +200,6 @@ fun ReaderScreen(
|
|||||||
webViewClient = WebViewClient()
|
webViewClient = WebViewClient()
|
||||||
this.settings.apply {
|
this.settings.apply {
|
||||||
javaScriptEnabled = true
|
javaScriptEnabled = true
|
||||||
defaultFontSize = currentSettings.fontSize.toInt()
|
|
||||||
builtInZoomControls = true
|
builtInZoomControls = true
|
||||||
displayZoomControls = false
|
displayZoomControls = false
|
||||||
}
|
}
|
||||||
@@ -213,6 +215,7 @@ fun ReaderScreen(
|
|||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: ${currentSettings.fontFamily};
|
font-family: ${currentSettings.fontFamily};
|
||||||
|
font-size: ${currentSettings.fontSize}px;
|
||||||
line-height: ${currentSettings.lineHeight};
|
line-height: ${currentSettings.lineHeight};
|
||||||
padding: ${currentSettings.padding}px;
|
padding: ${currentSettings.padding}px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@@ -325,4 +328,164 @@ fun ReaderScreen(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add Settings Dialog
|
||||||
|
if (showSettings) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { showSettings = false },
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
"Reader Settings",
|
||||||
|
style = MaterialTheme.typography.headlineSmall
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.verticalScroll(rememberScrollState()),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
|
) {
|
||||||
|
// Font Size Slider
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"Font Size",
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"${currentSettings.fontSize.toInt()}sp",
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Slider(
|
||||||
|
value = currentSettings.fontSize,
|
||||||
|
onValueChange = { newSize ->
|
||||||
|
scope.launch {
|
||||||
|
val newSettings = currentSettings.copy(fontSize = newSize)
|
||||||
|
settingsStore.saveSettings(newSettings)
|
||||||
|
currentSettings = newSettings
|
||||||
|
}
|
||||||
|
},
|
||||||
|
valueRange = 12f..24f,
|
||||||
|
steps = 11
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line Height Slider
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"Line Height",
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"%.1fx".format(currentSettings.lineHeight),
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Slider(
|
||||||
|
value = currentSettings.lineHeight,
|
||||||
|
onValueChange = { newHeight ->
|
||||||
|
scope.launch {
|
||||||
|
val newSettings = currentSettings.copy(lineHeight = newHeight)
|
||||||
|
settingsStore.saveSettings(newSettings)
|
||||||
|
currentSettings = newSettings
|
||||||
|
}
|
||||||
|
},
|
||||||
|
valueRange = 1f..2f,
|
||||||
|
steps = 9
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Padding Slider
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"Margin",
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"${currentSettings.padding.toInt()}dp",
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Slider(
|
||||||
|
value = currentSettings.padding,
|
||||||
|
onValueChange = { newPadding ->
|
||||||
|
scope.launch {
|
||||||
|
val newSettings = currentSettings.copy(padding = newPadding)
|
||||||
|
settingsStore.saveSettings(newSettings)
|
||||||
|
currentSettings = newSettings
|
||||||
|
}
|
||||||
|
},
|
||||||
|
valueRange = 8f..32f,
|
||||||
|
steps = 11
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Font Family Dropdown
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
"Font Family",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
modifier = Modifier.padding(bottom = 8.dp)
|
||||||
|
)
|
||||||
|
val fontFamilies = listOf("Georgia", "Roboto", "Times New Roman", "Arial", "Verdana")
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
ExposedDropdownMenuBox(
|
||||||
|
expanded = expanded,
|
||||||
|
onExpandedChange = { expanded = !expanded }
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = currentSettings.fontFamily,
|
||||||
|
onValueChange = {},
|
||||||
|
readOnly = true,
|
||||||
|
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
||||||
|
modifier = Modifier
|
||||||
|
.menuAnchor()
|
||||||
|
.fillMaxWidth()
|
||||||
|
)
|
||||||
|
ExposedDropdownMenu(
|
||||||
|
expanded = expanded,
|
||||||
|
onDismissRequest = { expanded = false }
|
||||||
|
) {
|
||||||
|
fontFamilies.forEach { font ->
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(font) },
|
||||||
|
onClick = {
|
||||||
|
scope.launch {
|
||||||
|
val newSettings = currentSettings.copy(fontFamily = font)
|
||||||
|
settingsStore.saveSettings(newSettings)
|
||||||
|
currentSettings = newSettings
|
||||||
|
}
|
||||||
|
expanded = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = { showSettings = false }) {
|
||||||
|
Text("Close")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user