diff --git a/app/src/main/java/inhale/rip/epook/ReaderScreen.kt b/app/src/main/java/inhale/rip/epook/ReaderScreen.kt index 43bb0a9..95d0b2f 100644 --- a/app/src/main/java/inhale/rip/epook/ReaderScreen.kt +++ b/app/src/main/java/inhale/rip/epook/ReaderScreen.kt @@ -31,8 +31,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView 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.launch import org.jsoup.Jsoup @@ -70,9 +68,7 @@ fun ReaderScreen( ) { val context = LocalContext.current val bookStore = remember { BookStore(context) } - val settingsStore = remember { SettingsStore(context) } val scope = rememberCoroutineScope() - var currentSettings by remember { mutableStateOf(Settings()) } var currentChapterIndex by remember { mutableStateOf(0) } var chapters by remember { mutableStateOf>(emptyList()) } @@ -80,21 +76,12 @@ fun ReaderScreen( var showControls by remember { mutableStateOf(true) } var showChapterList by remember { mutableStateOf(false) } - var showSettings by remember { mutableStateOf(false) } var currentX by remember { mutableStateOf(0f) } var extractedPath by remember { mutableStateOf(null) } var webView by remember { mutableStateOf(null) } - LaunchedEffect(Unit) { - try { - currentSettings = settingsStore.getSettings() - } catch (e: Exception) { - Timber.e(e, "Error loading settings") - } - } - LaunchedEffect(bookId) { try { currentChapterIndex = bookStore.getReadingPosition(bookId).first() @@ -274,30 +261,42 @@ fun ReaderScreen( .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( modifier = Modifier .fillMaxWidth() .height(SWIPE_AREA_HEIGHT.dp) .align(Alignment.BottomCenter) - .background(MaterialTheme.colorScheme.surface.copy(alpha = 0.1f)) .pointerInput(Unit) { - detectHorizontalDragGestures { _, dragAmount -> - currentX += dragAmount - when { - currentX > 100 -> { - if (currentChapterIndex > 0) { - currentChapterIndex-- - } - currentX = 0f - } - currentX < -100 -> { - if (currentChapterIndex < chapters.size - 1) { + detectTapGestures( + onTap = { showControls = !showControls } + ) + } + .pointerInput(Unit) { + var initialX = 0f + detectHorizontalDragGestures( + onDragStart = { offset -> + initialX = offset.x + }, + 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++ } - 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") - } - } - ) - } } \ No newline at end of file