fixes & removed settings
This commit is contained in:
@@ -31,8 +31,6 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import inhale.rip.epook.data.BookStore
|
import inhale.rip.epook.data.BookStore
|
||||||
import inhale.rip.epook.data.Settings
|
|
||||||
import inhale.rip.epook.data.SettingsStore
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
@@ -70,9 +68,7 @@ fun ReaderScreen(
|
|||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val bookStore = remember { BookStore(context) }
|
val bookStore = remember { BookStore(context) }
|
||||||
val settingsStore = remember { SettingsStore(context) }
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
var currentSettings by remember { mutableStateOf(Settings()) }
|
|
||||||
|
|
||||||
var currentChapterIndex by remember { mutableStateOf(0) }
|
var currentChapterIndex by remember { mutableStateOf(0) }
|
||||||
var chapters by remember { mutableStateOf<List<Chapter>>(emptyList()) }
|
var chapters by remember { mutableStateOf<List<Chapter>>(emptyList()) }
|
||||||
@@ -80,21 +76,12 @@ 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) }
|
|
||||||
|
|
||||||
var currentX by remember { mutableStateOf(0f) }
|
var currentX by remember { mutableStateOf(0f) }
|
||||||
|
|
||||||
var extractedPath by remember { mutableStateOf<String?>(null) }
|
var extractedPath by remember { mutableStateOf<String?>(null) }
|
||||||
var webView by remember { mutableStateOf<WebView?>(null) }
|
var webView by remember { mutableStateOf<WebView?>(null) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
try {
|
|
||||||
currentSettings = settingsStore.getSettings()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "Error loading settings")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LaunchedEffect(bookId) {
|
LaunchedEffect(bookId) {
|
||||||
try {
|
try {
|
||||||
currentChapterIndex = bookStore.getReadingPosition(bookId).first()
|
currentChapterIndex = bookStore.getReadingPosition(bookId).first()
|
||||||
@@ -274,30 +261,42 @@ fun ReaderScreen(
|
|||||||
.padding(bottom = if (showControls) SWIPE_AREA_HEIGHT.dp else 0.dp)
|
.padding(bottom = if (showControls) SWIPE_AREA_HEIGHT.dp else 0.dp)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add swipe area at the bottom
|
// Add swipe area at the bottom with tap gesture
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(SWIPE_AREA_HEIGHT.dp)
|
.height(SWIPE_AREA_HEIGHT.dp)
|
||||||
.align(Alignment.BottomCenter)
|
.align(Alignment.BottomCenter)
|
||||||
.background(MaterialTheme.colorScheme.surface.copy(alpha = 0.1f))
|
|
||||||
.pointerInput(Unit) {
|
.pointerInput(Unit) {
|
||||||
detectHorizontalDragGestures { _, dragAmount ->
|
detectTapGestures(
|
||||||
currentX += dragAmount
|
onTap = { showControls = !showControls }
|
||||||
when {
|
)
|
||||||
currentX > 100 -> {
|
}
|
||||||
if (currentChapterIndex > 0) {
|
.pointerInput(Unit) {
|
||||||
currentChapterIndex--
|
var initialX = 0f
|
||||||
}
|
detectHorizontalDragGestures(
|
||||||
currentX = 0f
|
onDragStart = { offset ->
|
||||||
}
|
initialX = offset.x
|
||||||
currentX < -100 -> {
|
},
|
||||||
if (currentChapterIndex < chapters.size - 1) {
|
onDragEnd = {
|
||||||
|
val dragThreshold = size.width * 0.2f // 20% of screen width
|
||||||
|
val dragDistance = initialX - currentX
|
||||||
|
|
||||||
|
when {
|
||||||
|
dragDistance > dragThreshold && currentChapterIndex < chapters.size - 1 -> {
|
||||||
|
// Swiped left - next chapter
|
||||||
currentChapterIndex++
|
currentChapterIndex++
|
||||||
}
|
}
|
||||||
currentX = 0f
|
dragDistance < -dragThreshold && currentChapterIndex > 0 -> {
|
||||||
|
// Swiped right - previous chapter
|
||||||
|
currentChapterIndex--
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
currentX = 0f
|
||||||
}
|
}
|
||||||
|
) { change, dragAmount ->
|
||||||
|
currentX = change.position.x
|
||||||
|
change.consume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -418,164 +417,4 @@ 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