Optimized Reader loading speed and performance.
This commit is contained in:
parent
0e5c4a13e8
commit
2cf5899fbf
6 changed files with 12 additions and 23 deletions
|
|
@ -1,15 +1,11 @@
|
|||
package ua.acclorite.book_story.domain.use_case
|
||||
|
||||
import ua.acclorite.book_story.domain.model.ReaderLine
|
||||
import ua.acclorite.book_story.domain.repository.BookRepository
|
||||
import ua.acclorite.book_story.domain.util.ID
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetText @Inject constructor(private val repository: BookRepository) {
|
||||
|
||||
suspend fun execute(textPath: String): Map<ID, ReaderLine> {
|
||||
return repository.getBookText(textPath = textPath).withIndex().associate {
|
||||
it.index to ReaderLine(line = it.value)
|
||||
}
|
||||
suspend fun execute(textPath: String): List<String> {
|
||||
return repository.getBookText(textPath = textPath)
|
||||
}
|
||||
}
|
||||
|
|
@ -534,7 +534,7 @@ class BookInfoViewModel @Inject constructor(
|
|||
val updatedText = updatedBook.text
|
||||
val text = getText.execute(book.textPath)
|
||||
|
||||
if (updatedText != text.map { it.value.line }) {
|
||||
if (updatedText != text) {
|
||||
textUpdated = true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ import ua.acclorite.book_story.domain.util.Constants
|
|||
import ua.acclorite.book_story.domain.util.OnNavigate
|
||||
import ua.acclorite.book_story.presentation.components.CustomAnimatedVisibility
|
||||
import ua.acclorite.book_story.presentation.components.CustomSelectionContainer
|
||||
import ua.acclorite.book_story.presentation.components.customItems
|
||||
import ua.acclorite.book_story.presentation.components.customItemsIndexed
|
||||
import ua.acclorite.book_story.presentation.components.is_messages.IsError
|
||||
import ua.acclorite.book_story.presentation.data.LocalNavigator
|
||||
import ua.acclorite.book_story.presentation.data.MainEvent
|
||||
|
|
@ -188,9 +188,6 @@ private fun ReaderScreen(
|
|||
}
|
||||
}
|
||||
|
||||
val text = remember(state.value.text) {
|
||||
state.value.text.toList().sortedBy { it.first }
|
||||
}
|
||||
val fontFamily = remember(mainState.value.fontFamily) {
|
||||
Constants.FONTS.find {
|
||||
it.id == mainState.value.fontFamily
|
||||
|
|
@ -359,11 +356,11 @@ private fun ReaderScreen(
|
|||
Spacer(modifier = Modifier.height(18.dp))
|
||||
}
|
||||
|
||||
customItems(
|
||||
text, key = { key -> key.first }
|
||||
) { line ->
|
||||
customItemsIndexed(
|
||||
state.value.text, key = { _, index -> index }
|
||||
) { _, line ->
|
||||
ReaderTextParagraph(
|
||||
line = line.second,
|
||||
line = line,
|
||||
context = context,
|
||||
fontFamily = fontFamily,
|
||||
fontColor = fontColor.value,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import androidx.compose.ui.unit.Dp
|
|||
import androidx.compose.ui.unit.TextUnit
|
||||
import ua.acclorite.book_story.R
|
||||
import ua.acclorite.book_story.domain.model.FontWithName
|
||||
import ua.acclorite.book_story.domain.model.ReaderLine
|
||||
import ua.acclorite.book_story.presentation.screens.reader.data.ReaderEvent
|
||||
|
||||
/**
|
||||
|
|
@ -44,7 +43,7 @@ import ua.acclorite.book_story.presentation.screens.reader.data.ReaderEvent
|
|||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun LazyItemScope.ReaderTextParagraph(
|
||||
line: ReaderLine,
|
||||
line: String,
|
||||
context: Context,
|
||||
fontFamily: FontWithName,
|
||||
fontColor: Color,
|
||||
|
|
@ -72,7 +71,7 @@ fun LazyItemScope.ReaderTextParagraph(
|
|||
append(" ")
|
||||
}
|
||||
|
||||
append(line.line)
|
||||
append(line)
|
||||
},
|
||||
modifier = Modifier.then(
|
||||
if (
|
||||
|
|
@ -85,7 +84,7 @@ fun LazyItemScope.ReaderTextParagraph(
|
|||
onDoubleClick = {
|
||||
onEvent(
|
||||
ReaderEvent.OnOpenTranslator(
|
||||
textToTranslate = line.line,
|
||||
textToTranslate = line,
|
||||
context = context as ComponentActivity,
|
||||
noAppsFound = {
|
||||
Toast.makeText(
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@ package ua.acclorite.book_story.presentation.screens.reader.data
|
|||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.runtime.Immutable
|
||||
import ua.acclorite.book_story.domain.model.Book
|
||||
import ua.acclorite.book_story.domain.model.ReaderLine
|
||||
import ua.acclorite.book_story.domain.util.Constants
|
||||
import ua.acclorite.book_story.domain.util.ID
|
||||
import ua.acclorite.book_story.domain.util.UIText
|
||||
|
||||
@Immutable
|
||||
data class ReaderState(
|
||||
val book: Book = Constants.EMPTY_BOOK,
|
||||
val text: Map<ID, ReaderLine> = emptyMap(),
|
||||
val text: List<String> = emptyList(),
|
||||
val words: Int = 0,
|
||||
val letters: Int = 0,
|
||||
val listState: LazyListState = LazyListState(),
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ class ReaderViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
val textAsLine = text
|
||||
.map { it.value.line }
|
||||
.joinToString(
|
||||
separator = "\n"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue