🛠️ Remove ReaderStartItem and ReaderEndItem
* Removed start and end items as they cause problems with features implementation
This commit is contained in:
parent
64069afa95
commit
4f20d0a461
4 changed files with 15 additions and 334 deletions
|
|
@ -12,13 +12,17 @@ import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
|
import androidx.compose.foundation.layout.asPaddingValues
|
||||||
|
import androidx.compose.foundation.layout.displayCutout
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.text.selection.DisableSelection
|
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
|
|
@ -42,6 +46,7 @@ import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.coerceAtLeast
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.em
|
import androidx.compose.ui.unit.em
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
@ -322,16 +327,16 @@ private fun ReaderScreen(lazyListState: LazyListState) {
|
||||||
.showToast(context = context, longToast = false)
|
.showToast(context = context, longToast = false)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
verticalArrangement = Arrangement.spacedBy(paragraphHeight)
|
verticalArrangement = Arrangement.spacedBy(paragraphHeight),
|
||||||
|
contentPadding = PaddingValues(
|
||||||
|
top = (WindowInsets.displayCutout.asPaddingValues()
|
||||||
|
.calculateTopPadding() + paragraphHeight)
|
||||||
|
.coerceAtLeast(18.dp),
|
||||||
|
bottom = (WindowInsets.displayCutout.asPaddingValues()
|
||||||
|
.calculateBottomPadding() + paragraphHeight)
|
||||||
|
.coerceAtLeast(18.dp),
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
item {
|
|
||||||
DisableSelection {
|
|
||||||
ReaderStartItem()
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(18.dp))
|
|
||||||
}
|
|
||||||
|
|
||||||
customItemsIndexed(
|
customItemsIndexed(
|
||||||
state.value.text, key = { _, index -> index }
|
state.value.text, key = { _, index -> index }
|
||||||
) { _, line ->
|
) { _, line ->
|
||||||
|
|
@ -351,14 +356,6 @@ private fun ReaderScreen(lazyListState: LazyListState) {
|
||||||
toolbarHidden = toolbarHidden
|
toolbarHidden = toolbarHidden
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
item {
|
|
||||||
Spacer(modifier = Modifier.height(18.dp))
|
|
||||||
|
|
||||||
DisableSelection {
|
|
||||||
ReaderEndItem()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,143 +0,0 @@
|
||||||
package ua.acclorite.book_story.presentation.screens.reader.components
|
|
||||||
|
|
||||||
import androidx.activity.ComponentActivity
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.navigationBarsIgnoringVisibility
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.material3.ButtonDefaults
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import ua.acclorite.book_story.R
|
|
||||||
import ua.acclorite.book_story.domain.model.Category
|
|
||||||
import ua.acclorite.book_story.presentation.core.components.LocalHistoryViewModel
|
|
||||||
import ua.acclorite.book_story.presentation.core.components.LocalLibraryViewModel
|
|
||||||
import ua.acclorite.book_story.presentation.core.components.LocalReaderViewModel
|
|
||||||
import ua.acclorite.book_story.presentation.core.navigation.LocalOnNavigate
|
|
||||||
import ua.acclorite.book_story.presentation.core.navigation.Screen
|
|
||||||
import ua.acclorite.book_story.presentation.core.util.showToast
|
|
||||||
import ua.acclorite.book_story.presentation.screens.history.data.HistoryEvent
|
|
||||||
import ua.acclorite.book_story.presentation.screens.library.data.LibraryEvent
|
|
||||||
import ua.acclorite.book_story.presentation.screens.reader.data.ReaderEvent
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reader end item. Displays at the end of the book.
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
|
||||||
@Composable
|
|
||||||
fun ReaderEndItem(
|
|
||||||
) {
|
|
||||||
val state = LocalReaderViewModel.current.state
|
|
||||||
val onEvent = LocalReaderViewModel.current.onEvent
|
|
||||||
val onLibraryEvent = LocalLibraryViewModel.current.onEvent
|
|
||||||
val onHistoryEvent = LocalHistoryViewModel.current.onEvent
|
|
||||||
val context = LocalContext.current as ComponentActivity
|
|
||||||
val onNavigate = LocalOnNavigate.current
|
|
||||||
|
|
||||||
val buttonText = remember {
|
|
||||||
context.getString(
|
|
||||||
if (state.value.book.category != Category.ALREADY_READ) R.string.move_to_read
|
|
||||||
else R.string.back_to_library
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(MaterialTheme.colorScheme.surfaceContainerLowest)
|
|
||||||
.padding(
|
|
||||||
horizontal = 36.dp,
|
|
||||||
vertical = 108.dp + WindowInsets.navigationBarsIgnoringVisibility
|
|
||||||
.asPaddingValues()
|
|
||||||
.calculateBottomPadding()
|
|
||||||
),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.thanks_for_reading, state.value.book.title),
|
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
|
||||||
Text(
|
|
||||||
stringResource(
|
|
||||||
id = R.string.letters_and_words,
|
|
||||||
state.value.letters,
|
|
||||||
state.value.words
|
|
||||||
),
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
if (state.value.book.category != Category.ALREADY_READ) {
|
|
||||||
onEvent(
|
|
||||||
ReaderEvent.OnMoveBookToAlreadyRead(
|
|
||||||
context = context,
|
|
||||||
onUpdateCategories = {
|
|
||||||
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
|
||||||
onHistoryEvent(HistoryEvent.OnUpdateBook(it))
|
|
||||||
},
|
|
||||||
updatePage = {
|
|
||||||
onLibraryEvent(LibraryEvent.OnUpdateCurrentPage(it))
|
|
||||||
},
|
|
||||||
onNavigate = onNavigate
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
context.getString(R.string.book_moved)
|
|
||||||
.showToast(context = context)
|
|
||||||
} else {
|
|
||||||
onEvent(
|
|
||||||
ReaderEvent.OnGoBack(
|
|
||||||
context = context,
|
|
||||||
refreshList = {
|
|
||||||
onLibraryEvent(LibraryEvent.OnUpdateBook(it))
|
|
||||||
onHistoryEvent(HistoryEvent.OnUpdateBook(it))
|
|
||||||
},
|
|
||||||
navigate = {
|
|
||||||
onNavigate {
|
|
||||||
navigate(Screen.Library, useBackAnimation = true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
contentPadding = PaddingValues(horizontal = 12.dp),
|
|
||||||
colors = ButtonDefaults.textButtonColors(
|
|
||||||
containerColor = Color.Transparent,
|
|
||||||
contentColor = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
buttonText,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,130 +0,0 @@
|
||||||
package ua.acclorite.book_story.presentation.screens.reader.components.start_item
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.statusBarsIgnoringVisibility
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.Image
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import ua.acclorite.book_story.R
|
|
||||||
import ua.acclorite.book_story.presentation.core.components.CustomCoverImage
|
|
||||||
import ua.acclorite.book_story.presentation.core.components.LocalReaderViewModel
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reader start item. Displays at the beginning of the book.
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
|
||||||
@Composable
|
|
||||||
fun ReaderStartItem() {
|
|
||||||
val state = LocalReaderViewModel.current.state
|
|
||||||
|
|
||||||
val statusBarHeight = WindowInsets
|
|
||||||
.statusBarsIgnoringVisibility
|
|
||||||
.asPaddingValues()
|
|
||||||
.calculateTopPadding()
|
|
||||||
|
|
||||||
val itemsHeight = remember(statusBarHeight) {
|
|
||||||
statusBarHeight + 80.dp + 140.dp + 40.dp
|
|
||||||
}
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(MaterialTheme.colorScheme.surfaceContainerLowest)
|
|
||||||
) {
|
|
||||||
if (state.value.book.coverImage != null) {
|
|
||||||
ReaderStartItemBackground(
|
|
||||||
height = itemsHeight,
|
|
||||||
image = state.value.book.coverImage!!
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = statusBarHeight)
|
|
||||||
.padding(horizontal = 24.dp, vertical = 80.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically, modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.height(150.dp)
|
|
||||||
.width(100.dp)
|
|
||||||
.background(
|
|
||||||
MaterialTheme.colorScheme.surfaceContainerLow,
|
|
||||||
RoundedCornerShape(10.dp)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if (state.value.book.coverImage != null) {
|
|
||||||
CustomCoverImage(
|
|
||||||
uri = state.value.book.coverImage!!,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clip(RoundedCornerShape(10.dp))
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Image,
|
|
||||||
contentDescription = stringResource(id = R.string.cover_image_not_found_content_desc),
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.Center)
|
|
||||||
.fillMaxWidth(0.7f)
|
|
||||||
.aspectRatio(1f),
|
|
||||||
tint = MaterialTheme.colorScheme.surfaceContainerHigh
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(18.dp))
|
|
||||||
|
|
||||||
Column(verticalArrangement = Arrangement.Center) {
|
|
||||||
Text(
|
|
||||||
state.value.book.title,
|
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
maxLines = 4,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.happy_reading),
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
package ua.acclorite.book_story.presentation.screens.reader.components.start_item
|
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.blur
|
|
||||||
import androidx.compose.ui.draw.drawWithContent
|
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.unit.Dp
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import ua.acclorite.book_story.presentation.core.components.CustomCoverImage
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Background of the [ReaderStartItem].
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun ReaderStartItemBackground(height: Dp, image: Uri) {
|
|
||||||
val background = MaterialTheme.colorScheme.surfaceContainerLowest
|
|
||||||
|
|
||||||
CustomCoverImage(
|
|
||||||
uri = image,
|
|
||||||
animationDurationMillis = 300,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(height)
|
|
||||||
.drawWithContent {
|
|
||||||
drawContent()
|
|
||||||
drawRect(
|
|
||||||
brush = Brush.verticalGradient(
|
|
||||||
0f to Color.Transparent,
|
|
||||||
0.8f to background
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.blur(5.dp),
|
|
||||||
alpha = 0.4f
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue