feat: add loading indicator to book info's file loading
This commit is contained in:
parent
24d3e3ba0a
commit
cce3f0fcea
7 changed files with 36 additions and 14 deletions
|
|
@ -257,7 +257,8 @@ class BookInfoModel @Inject constructor(
|
|||
it.copy(
|
||||
book = it.book.copy(
|
||||
filePath = event.path
|
||||
)
|
||||
),
|
||||
loadingFile = true
|
||||
)
|
||||
}
|
||||
updateBookUseCase(_state.value.book)
|
||||
|
|
@ -270,7 +271,8 @@ class BookInfoModel @Inject constructor(
|
|||
val file = getFileFromBookUseCase(_state.value.book.id)
|
||||
_state.update {
|
||||
it.copy(
|
||||
file = file
|
||||
file = file,
|
||||
loadingFile = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -380,7 +382,8 @@ class BookInfoModel @Inject constructor(
|
|||
val file = getFileFromBookUseCase(bookId)
|
||||
_state.update {
|
||||
it.copy(
|
||||
file = file
|
||||
file = file,
|
||||
loadingFile = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ data class BookInfoScreen(val bookId: Int) : Screen, Parcelable {
|
|||
BookInfoContent(
|
||||
book = state.value.book,
|
||||
file = state.value.file,
|
||||
loadingFile = state.value.loadingFile,
|
||||
categories = categories,
|
||||
bottomSheet = state.value.bottomSheet,
|
||||
dialog = state.value.dialog,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ import ua.acclorite.book_story.domain.model.library.Book
|
|||
@Immutable
|
||||
data class BookInfoState(
|
||||
val book: Book = Book.default,
|
||||
|
||||
val file: File? = null,
|
||||
val loadingFile: Boolean = true,
|
||||
|
||||
val canResetCover: Boolean = false,
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ fun BookInfoBottomSheet(
|
|||
bottomSheet: BottomSheet?,
|
||||
book: Book,
|
||||
file: File?,
|
||||
loadingFile: Boolean,
|
||||
canResetCover: Boolean,
|
||||
showPathDialog: (BookInfoEvent.OnShowPathDialog) -> Unit,
|
||||
changeCover: (BookInfoEvent.OnChangeCover) -> Unit,
|
||||
|
|
@ -43,6 +44,7 @@ fun BookInfoBottomSheet(
|
|||
BookInfoDetailsBottomSheet(
|
||||
book = book,
|
||||
file = file,
|
||||
loadingFile = loadingFile,
|
||||
showPathDialog = showPathDialog,
|
||||
dismissBottomSheet = dismissBottomSheet
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import ua.acclorite.book_story.presentation.book_info.BookInfoEvent
|
|||
fun BookInfoContent(
|
||||
book: Book,
|
||||
file: File?,
|
||||
loadingFile: Boolean,
|
||||
categories: List<Category>,
|
||||
bottomSheet: BottomSheet?,
|
||||
dialog: Dialog?,
|
||||
|
|
@ -66,6 +67,7 @@ fun BookInfoContent(
|
|||
bottomSheet = bottomSheet,
|
||||
book = book,
|
||||
file = file,
|
||||
loadingFile = loadingFile,
|
||||
showPathDialog = showPathDialog,
|
||||
canResetCover = canResetCover,
|
||||
changeCover = changeCover,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import java.util.Locale
|
|||
fun BookInfoDetailsBottomSheet(
|
||||
book: Book,
|
||||
file: File?,
|
||||
loadingFile: Boolean,
|
||||
showPathDialog: (BookInfoEvent.OnShowPathDialog) -> Unit,
|
||||
dismissBottomSheet: (BookInfoEvent.OnDismissBottomSheet) -> Unit
|
||||
) {
|
||||
|
|
@ -53,6 +54,7 @@ fun BookInfoDetailsBottomSheet(
|
|||
|
||||
val fileExists = remember(file) {
|
||||
file.let { file ->
|
||||
if (loadingFile) return@let true
|
||||
if (file == null) return@let false
|
||||
if (file.isDirectory) return@let false
|
||||
if (
|
||||
|
|
@ -99,7 +101,8 @@ fun BookInfoDetailsBottomSheet(
|
|||
showPathDialog(BookInfoEvent.OnShowPathDialog)
|
||||
},
|
||||
showError = !fileExists,
|
||||
errorMessage = stringResource(id = R.string.error_no_file)
|
||||
errorMessage = stringResource(id = R.string.error_no_file),
|
||||
loading = loadingFile
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ package ua.acclorite.book_story.ui.book_info
|
|||
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
|
|
@ -15,6 +16,7 @@ import androidx.compose.foundation.layout.padding
|
|||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.EditNote
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.runtime.Composable
|
||||
|
|
@ -25,6 +27,7 @@ import ua.acclorite.book_story.R
|
|||
import ua.acclorite.book_story.ui.common.components.common.IconButton
|
||||
import ua.acclorite.book_story.ui.common.components.common.StyledText
|
||||
import ua.acclorite.book_story.ui.theme.ExpandingTransition
|
||||
import ua.acclorite.book_story.ui.theme.FadeTransitionPreservingSpace
|
||||
|
||||
@Composable
|
||||
fun BookInfoDetailsBottomSheetItem(
|
||||
|
|
@ -33,6 +36,7 @@ fun BookInfoDetailsBottomSheetItem(
|
|||
editable: Boolean,
|
||||
showError: Boolean = false,
|
||||
errorMessage: String? = null,
|
||||
loading: Boolean = false,
|
||||
onEdit: () -> Unit = {}
|
||||
) {
|
||||
Column(
|
||||
|
|
@ -55,18 +59,23 @@ fun BookInfoDetailsBottomSheetItem(
|
|||
isError = showError,
|
||||
label = {
|
||||
StyledText(label)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
if (editable) {
|
||||
IconButton(
|
||||
icon = Icons.Default.EditNote,
|
||||
contentDescription = R.string.edit_content_desc,
|
||||
disableOnClick = false,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(24.dp)
|
||||
) {
|
||||
onEdit()
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
FadeTransitionPreservingSpace(visible = loading) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(24.dp), strokeWidth = 3.2.dp)
|
||||
}
|
||||
FadeTransitionPreservingSpace(visible = !loading && editable) {
|
||||
IconButton(
|
||||
icon = Icons.Default.EditNote,
|
||||
contentDescription = R.string.edit_content_desc,
|
||||
disableOnClick = false,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(24.dp)
|
||||
) {
|
||||
onEdit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue