BookInfoScreen: Removed Author and Description update(only manual changes).
This commit is contained in:
parent
4f521bcd1e
commit
d81810f3aa
7 changed files with 84 additions and 164 deletions
|
|
@ -167,7 +167,6 @@ private fun BookInfoScreen(
|
||||||
}
|
}
|
||||||
if (state.value.showConfirmUpdateDialog) {
|
if (state.value.showConfirmUpdateDialog) {
|
||||||
BookInfoConfirmUpdateDialog(
|
BookInfoConfirmUpdateDialog(
|
||||||
state = state,
|
|
||||||
snackbarHostState = snackbarState,
|
snackbarHostState = snackbarState,
|
||||||
onEvent = onEvent,
|
onEvent = onEvent,
|
||||||
onLibraryUpdateEvent = onLibraryEvent,
|
onLibraryUpdateEvent = onLibraryEvent,
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,25 @@ import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Update
|
import androidx.compose.material.icons.filled.Update
|
||||||
import androidx.compose.material3.SnackbarHostState
|
import androidx.compose.material3.SnackbarHostState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
import ua.acclorite.book_story.presentation.components.custom_dialog.CustomDialogWithLazyColumn
|
import ua.acclorite.book_story.presentation.components.custom_dialog.CustomDialogWithContent
|
||||||
import ua.acclorite.book_story.presentation.screens.book_info.data.BookInfoEvent
|
import ua.acclorite.book_story.presentation.screens.book_info.data.BookInfoEvent
|
||||||
import ua.acclorite.book_story.presentation.screens.book_info.data.BookInfoState
|
|
||||||
import ua.acclorite.book_story.presentation.screens.history.data.HistoryEvent
|
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.library.data.LibraryEvent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Confirm update dialog. Updates book if action clicked.
|
* Confirm update dialog.
|
||||||
|
* Updates book if action clicked.
|
||||||
|
*
|
||||||
|
* @param snackbarHostState [SnackbarHostState].
|
||||||
|
* @param onEvent [BookInfoEvent] callback.
|
||||||
|
* @param onLibraryUpdateEvent [LibraryEvent] callback.
|
||||||
|
* @param onHistoryUpdateEvent [HistoryEvent] callback.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun BookInfoConfirmUpdateDialog(
|
fun BookInfoConfirmUpdateDialog(
|
||||||
state: State<BookInfoState>,
|
|
||||||
snackbarHostState: SnackbarHostState,
|
snackbarHostState: SnackbarHostState,
|
||||||
onEvent: (BookInfoEvent) -> Unit,
|
onEvent: (BookInfoEvent) -> Unit,
|
||||||
onLibraryUpdateEvent: (LibraryEvent.OnUpdateBook) -> Unit,
|
onLibraryUpdateEvent: (LibraryEvent.OnUpdateBook) -> Unit,
|
||||||
|
|
@ -27,7 +30,7 @@ fun BookInfoConfirmUpdateDialog(
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
CustomDialogWithLazyColumn(
|
CustomDialogWithContent(
|
||||||
title = stringResource(id = R.string.confirm_update),
|
title = stringResource(id = R.string.confirm_update),
|
||||||
imageVectorIcon = Icons.Default.Update,
|
imageVectorIcon = Icons.Default.Update,
|
||||||
description = stringResource(
|
description = stringResource(
|
||||||
|
|
@ -48,24 +51,7 @@ fun BookInfoConfirmUpdateDialog(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
withDivider = false,
|
withDivider = false
|
||||||
items = {
|
|
||||||
if (state.value.authorChanged) {
|
|
||||||
item {
|
|
||||||
BookInfoConfirmUpdateDialogItem(title = stringResource(id = R.string.author))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (state.value.descriptionChanged) {
|
|
||||||
item {
|
|
||||||
BookInfoConfirmUpdateDialogItem(title = stringResource(id = R.string.description))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (state.value.textChanged) {
|
|
||||||
item {
|
|
||||||
BookInfoConfirmUpdateDialogItem(title = stringResource(id = R.string.text))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,10 +76,7 @@ sealed class BookInfoEvent {
|
||||||
data object OnDismissConfirmUpdateDialog : BookInfoEvent()
|
data object OnDismissConfirmUpdateDialog : BookInfoEvent()
|
||||||
|
|
||||||
data class OnShowConfirmUpdateDialog(
|
data class OnShowConfirmUpdateDialog(
|
||||||
val updatedBook: Pair<Book, List<String>>,
|
val updatedText: List<String>
|
||||||
val authorUpdated: Boolean,
|
|
||||||
val descriptionUpdated: Boolean,
|
|
||||||
val textUpdated: Boolean,
|
|
||||||
) : BookInfoEvent()
|
) : BookInfoEvent()
|
||||||
|
|
||||||
data object OnCancelUpdate : BookInfoEvent()
|
data object OnCancelUpdate : BookInfoEvent()
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,7 @@ data class BookInfoState(
|
||||||
val isLoadingUpdate: Boolean = false,
|
val isLoadingUpdate: Boolean = false,
|
||||||
val isRefreshing: Boolean = false,
|
val isRefreshing: Boolean = false,
|
||||||
val showConfirmUpdateDialog: Boolean = false,
|
val showConfirmUpdateDialog: Boolean = false,
|
||||||
val updatedBook: Pair<Book, List<String>>? = null,
|
val updatedText: List<String>? = null,
|
||||||
val authorChanged: Boolean = false,
|
|
||||||
val descriptionChanged: Boolean = false,
|
|
||||||
val textChanged: Boolean = false,
|
|
||||||
|
|
||||||
val editTitle: Boolean = false,
|
val editTitle: Boolean = false,
|
||||||
val hasTitleFocused: Boolean = false,
|
val hasTitleFocused: Boolean = false,
|
||||||
|
|
|
||||||
|
|
@ -529,20 +529,8 @@ class BookInfoViewModel @Inject constructor(
|
||||||
|
|
||||||
val book = _state.value.book
|
val book = _state.value.book
|
||||||
|
|
||||||
var authorUpdated = false
|
|
||||||
var descriptionUpdated = false
|
|
||||||
var textUpdated = false
|
var textUpdated = false
|
||||||
|
|
||||||
if (
|
|
||||||
updatedBook.book!!.author.asString(event.context) !=
|
|
||||||
book.author.asString(event.context)
|
|
||||||
) {
|
|
||||||
authorUpdated = true
|
|
||||||
}
|
|
||||||
if (updatedBook.book.description != book.description) {
|
|
||||||
descriptionUpdated = true
|
|
||||||
}
|
|
||||||
|
|
||||||
val updatedText = updatedBook.text
|
val updatedText = updatedBook.text
|
||||||
val text = getText.execute(book.textPath)
|
val text = getText.execute(book.textPath)
|
||||||
|
|
||||||
|
|
@ -551,7 +539,7 @@ class BookInfoViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
yield()
|
yield()
|
||||||
if (!authorUpdated && !descriptionUpdated && !textUpdated) {
|
if (!textUpdated) {
|
||||||
onEvent(
|
onEvent(
|
||||||
BookInfoEvent.OnShowSnackbar(
|
BookInfoEvent.OnShowSnackbar(
|
||||||
event.context.getString(R.string.nothing_changed),
|
event.context.getString(R.string.nothing_changed),
|
||||||
|
|
@ -572,10 +560,7 @@ class BookInfoViewModel @Inject constructor(
|
||||||
yield()
|
yield()
|
||||||
onEvent(
|
onEvent(
|
||||||
BookInfoEvent.OnShowConfirmUpdateDialog(
|
BookInfoEvent.OnShowConfirmUpdateDialog(
|
||||||
updatedBook = updatedBook.book to updatedBook.text,
|
updatedText = updatedBook.text,
|
||||||
authorUpdated = authorUpdated,
|
|
||||||
descriptionUpdated = descriptionUpdated,
|
|
||||||
textUpdated = textUpdated
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -591,10 +576,7 @@ class BookInfoViewModel @Inject constructor(
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
showConfirmUpdateDialog = false,
|
showConfirmUpdateDialog = false,
|
||||||
updatedBook = null,
|
updatedText = null
|
||||||
authorChanged = false,
|
|
||||||
descriptionChanged = false,
|
|
||||||
textChanged = false
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -603,10 +585,7 @@ class BookInfoViewModel @Inject constructor(
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
showConfirmUpdateDialog = true,
|
showConfirmUpdateDialog = true,
|
||||||
updatedBook = event.updatedBook,
|
updatedText = event.updatedText
|
||||||
authorChanged = event.authorUpdated,
|
|
||||||
descriptionChanged = event.descriptionUpdated,
|
|
||||||
textChanged = event.textUpdated
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -620,7 +599,7 @@ class BookInfoViewModel @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_state.value.updatedBook == null) {
|
if (_state.value.updatedText == null) {
|
||||||
onEvent(
|
onEvent(
|
||||||
BookInfoEvent.OnShowSnackbar(
|
BookInfoEvent.OnShowSnackbar(
|
||||||
text = event.context.getString(
|
text = event.context.getString(
|
||||||
|
|
@ -648,33 +627,10 @@ class BookInfoViewModel @Inject constructor(
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
val book = _state.value.book
|
val updatedText = _state.value.updatedText ?: return@launch
|
||||||
val updatedBook = _state.value.updatedBook ?: return@launch
|
|
||||||
|
|
||||||
val author = if (_state.value.authorChanged) {
|
|
||||||
updatedBook.first.author
|
|
||||||
} else {
|
|
||||||
book.author
|
|
||||||
}
|
|
||||||
val description = if (_state.value.descriptionChanged) {
|
|
||||||
updatedBook.first.description
|
|
||||||
} else {
|
|
||||||
book.description
|
|
||||||
}
|
|
||||||
|
|
||||||
_state.update {
|
|
||||||
it.copy(
|
|
||||||
book = it.book.copy(
|
|
||||||
author = author,
|
|
||||||
description = description
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_state.value.textChanged) {
|
|
||||||
val isSuccess = updateBookWithText.execute(
|
val isSuccess = updateBookWithText.execute(
|
||||||
book = _state.value.book,
|
book = _state.value.book,
|
||||||
text = updatedBook.second
|
text = updatedText
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isSuccess) {
|
if (!isSuccess) {
|
||||||
|
|
@ -704,17 +660,8 @@ class BookInfoViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
updateBooks.execute(
|
|
||||||
listOf(
|
|
||||||
_state.value.book
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_state.value.textChanged) {
|
|
||||||
val newBook = getBookById.execute(_state.value.book.id)
|
val newBook = getBookById.execute(_state.value.book.id)
|
||||||
|
|
||||||
if (newBook == null) {
|
if (newBook == null) {
|
||||||
onEvent(
|
onEvent(
|
||||||
BookInfoEvent.OnShowSnackbar(
|
BookInfoEvent.OnShowSnackbar(
|
||||||
|
|
@ -746,13 +693,9 @@ class BookInfoViewModel @Inject constructor(
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
book = newBook,
|
book = newBook,
|
||||||
authorChanged = false,
|
updatedText = null
|
||||||
descriptionChanged = false,
|
|
||||||
textChanged = false,
|
|
||||||
updatedBook = null
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
event.refreshList(_state.value.book)
|
event.refreshList(_state.value.book)
|
||||||
|
|
||||||
onEvent(
|
onEvent(
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,8 @@
|
||||||
Після видалення всієї історії порядок книг буде скинутий.
|
Після видалення всієї історії порядок книг буде скинутий.
|
||||||
</string>
|
</string>
|
||||||
<string name="confirm_update_description">
|
<string name="confirm_update_description">
|
||||||
При підтвердженні ця книга буде оновлена.
|
При підтвердженні текст цієї книги буде оновлений.
|
||||||
Будь ласка, запам\'ятайте де ви зупинилися перед оновленням тексту.
|
Будь ласка, запам\'ятайте де ви зупинилися перед оновленням тексту.
|
||||||
Наступне буде оновлено:
|
|
||||||
</string>
|
</string>
|
||||||
<string name="update_app_description">
|
<string name="update_app_description">
|
||||||
Нова версія Історії Книги була знайдена.
|
Нова версія Історії Книги була знайдена.
|
||||||
|
|
@ -301,8 +300,8 @@
|
||||||
<!-- Snackbar messages -->
|
<!-- Snackbar messages -->
|
||||||
<string name="history_element_deleted">Елемент історії був успішно видалений.</string>
|
<string name="history_element_deleted">Елемент історії був успішно видалений.</string>
|
||||||
<string name="file_not_found">Файл \"%1$s\" не знайдено.</string>
|
<string name="file_not_found">Файл \"%1$s\" не знайдено.</string>
|
||||||
<string name="book_updated">Текст, автор та опис книги були успішно оновлені.</string>
|
<string name="book_updated">Текст книги був успішно оновлений.</string>
|
||||||
<string name="nothing_changed">Книга актуальна.</string>
|
<string name="nothing_changed">Текст книги актуальний.</string>
|
||||||
|
|
||||||
<!-- DropDown properties -->
|
<!-- DropDown properties -->
|
||||||
<string name="move_this_book">Перемістити</string>
|
<string name="move_this_book">Перемістити</string>
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,8 @@
|
||||||
After deleting the whole history, the order of the books will be reset.
|
After deleting the whole history, the order of the books will be reset.
|
||||||
</string>
|
</string>
|
||||||
<string name="confirm_update_description">
|
<string name="confirm_update_description">
|
||||||
By confirming this book will be updated.
|
By confirming this book\'s text will be updated.
|
||||||
Please remember where you left before updating text.
|
Please remember where you left before updating text.
|
||||||
Following will be updated:
|
|
||||||
</string>
|
</string>
|
||||||
<string name="update_app_description">
|
<string name="update_app_description">
|
||||||
New version of Book\'s Story was found.
|
New version of Book\'s Story was found.
|
||||||
|
|
@ -321,8 +320,8 @@
|
||||||
<!-- Snackbar messages -->
|
<!-- Snackbar messages -->
|
||||||
<string name="history_element_deleted">History element was successfully deleted.</string>
|
<string name="history_element_deleted">History element was successfully deleted.</string>
|
||||||
<string name="file_not_found">File \"%1$s\" was not found.</string>
|
<string name="file_not_found">File \"%1$s\" was not found.</string>
|
||||||
<string name="book_updated">Book text, author and description were successfully updated.</string>
|
<string name="book_updated">Book\'s text was successfully updated.</string>
|
||||||
<string name="nothing_changed">Book is up to date.</string>
|
<string name="nothing_changed">Book\'s text is up to date.</string>
|
||||||
|
|
||||||
<!-- DropDown properties -->
|
<!-- DropDown properties -->
|
||||||
<string name="move_this_book">Move</string>
|
<string name="move_this_book">Move</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue