BookInfoScreen: Removed Author and Description update(only manual changes).

This commit is contained in:
acclorite 2024-07-09 18:31:35 +03:00
parent 4f521bcd1e
commit d81810f3aa
7 changed files with 84 additions and 164 deletions

View file

@ -167,7 +167,6 @@ private fun BookInfoScreen(
}
if (state.value.showConfirmUpdateDialog) {
BookInfoConfirmUpdateDialog(
state = state,
snackbarHostState = snackbarState,
onEvent = onEvent,
onLibraryUpdateEvent = onLibraryEvent,

View file

@ -4,22 +4,25 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Update
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
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.BookInfoState
import ua.acclorite.book_story.presentation.screens.history.data.HistoryEvent
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
fun BookInfoConfirmUpdateDialog(
state: State<BookInfoState>,
snackbarHostState: SnackbarHostState,
onEvent: (BookInfoEvent) -> Unit,
onLibraryUpdateEvent: (LibraryEvent.OnUpdateBook) -> Unit,
@ -27,7 +30,7 @@ fun BookInfoConfirmUpdateDialog(
) {
val context = LocalContext.current
CustomDialogWithLazyColumn(
CustomDialogWithContent(
title = stringResource(id = R.string.confirm_update),
imageVectorIcon = Icons.Default.Update,
description = stringResource(
@ -48,24 +51,7 @@ fun BookInfoConfirmUpdateDialog(
)
)
},
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))
}
}
}
withDivider = false
)
}

View file

@ -76,10 +76,7 @@ sealed class BookInfoEvent {
data object OnDismissConfirmUpdateDialog : BookInfoEvent()
data class OnShowConfirmUpdateDialog(
val updatedBook: Pair<Book, List<String>>,
val authorUpdated: Boolean,
val descriptionUpdated: Boolean,
val textUpdated: Boolean,
val updatedText: List<String>
) : BookInfoEvent()
data object OnCancelUpdate : BookInfoEvent()

View file

@ -12,10 +12,7 @@ data class BookInfoState(
val isLoadingUpdate: Boolean = false,
val isRefreshing: Boolean = false,
val showConfirmUpdateDialog: Boolean = false,
val updatedBook: Pair<Book, List<String>>? = null,
val authorChanged: Boolean = false,
val descriptionChanged: Boolean = false,
val textChanged: Boolean = false,
val updatedText: List<String>? = null,
val editTitle: Boolean = false,
val hasTitleFocused: Boolean = false,

View file

@ -529,20 +529,8 @@ class BookInfoViewModel @Inject constructor(
val book = _state.value.book
var authorUpdated = false
var descriptionUpdated = 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 text = getText.execute(book.textPath)
@ -551,7 +539,7 @@ class BookInfoViewModel @Inject constructor(
}
yield()
if (!authorUpdated && !descriptionUpdated && !textUpdated) {
if (!textUpdated) {
onEvent(
BookInfoEvent.OnShowSnackbar(
event.context.getString(R.string.nothing_changed),
@ -572,10 +560,7 @@ class BookInfoViewModel @Inject constructor(
yield()
onEvent(
BookInfoEvent.OnShowConfirmUpdateDialog(
updatedBook = updatedBook.book to updatedBook.text,
authorUpdated = authorUpdated,
descriptionUpdated = descriptionUpdated,
textUpdated = textUpdated
updatedText = updatedBook.text,
)
)
@ -591,10 +576,7 @@ class BookInfoViewModel @Inject constructor(
_state.update {
it.copy(
showConfirmUpdateDialog = false,
updatedBook = null,
authorChanged = false,
descriptionChanged = false,
textChanged = false
updatedText = null
)
}
}
@ -603,10 +585,7 @@ class BookInfoViewModel @Inject constructor(
_state.update {
it.copy(
showConfirmUpdateDialog = true,
updatedBook = event.updatedBook,
authorChanged = event.authorUpdated,
descriptionChanged = event.descriptionUpdated,
textChanged = event.textUpdated
updatedText = event.updatedText
)
}
}
@ -620,7 +599,7 @@ class BookInfoViewModel @Inject constructor(
)
}
if (_state.value.updatedBook == null) {
if (_state.value.updatedText == null) {
onEvent(
BookInfoEvent.OnShowSnackbar(
text = event.context.getString(
@ -648,111 +627,75 @@ class BookInfoViewModel @Inject constructor(
return@launch
}
val book = _state.value.book
val updatedBook = _state.value.updatedBook ?: return@launch
val updatedText = _state.value.updatedText ?: return@launch
val isSuccess = updateBookWithText.execute(
book = _state.value.book,
text = updatedText
)
val author = if (_state.value.authorChanged) {
updatedBook.first.author
} else {
book.author
if (!isSuccess) {
onEvent(
BookInfoEvent.OnShowSnackbar(
text = event.context.getString(
R.string.error_something_went_wrong_with_file
),
action = event.context.getString(R.string.retry),
onAction = {
onEvent(
BookInfoEvent.OnLoadUpdate(
snackbarState = event.snackbarState,
context = event.context
)
)
},
durationMillis = 4000L,
snackbarState = event.snackbarState
)
)
delay(500)
_state.update {
it.copy(
isRefreshing = false
)
}
return@launch
}
val description = if (_state.value.descriptionChanged) {
updatedBook.first.description
} else {
book.description
val newBook = getBookById.execute(_state.value.book.id)
if (newBook == null) {
onEvent(
BookInfoEvent.OnShowSnackbar(
text = event.context.getString(
R.string.error_something_went_wrong_with_file
),
action = event.context.getString(R.string.retry),
onAction = {
onEvent(
BookInfoEvent.OnLoadUpdate(
snackbarState = event.snackbarState,
context = event.context
)
)
},
durationMillis = 4000L,
snackbarState = event.snackbarState
)
)
delay(500)
_state.update {
it.copy(
isRefreshing = false
)
}
return@launch
}
_state.update {
it.copy(
book = it.book.copy(
author = author,
description = description
)
book = newBook,
updatedText = null
)
}
if (_state.value.textChanged) {
val isSuccess = updateBookWithText.execute(
book = _state.value.book,
text = updatedBook.second
)
if (!isSuccess) {
onEvent(
BookInfoEvent.OnShowSnackbar(
text = event.context.getString(
R.string.error_something_went_wrong_with_file
),
action = event.context.getString(R.string.retry),
onAction = {
onEvent(
BookInfoEvent.OnLoadUpdate(
snackbarState = event.snackbarState,
context = event.context
)
)
},
durationMillis = 4000L,
snackbarState = event.snackbarState
)
)
delay(500)
_state.update {
it.copy(
isRefreshing = false
)
}
return@launch
}
} else {
updateBooks.execute(
listOf(
_state.value.book
)
)
}
if (_state.value.textChanged) {
val newBook = getBookById.execute(_state.value.book.id)
if (newBook == null) {
onEvent(
BookInfoEvent.OnShowSnackbar(
text = event.context.getString(
R.string.error_something_went_wrong_with_file
),
action = event.context.getString(R.string.retry),
onAction = {
onEvent(
BookInfoEvent.OnLoadUpdate(
snackbarState = event.snackbarState,
context = event.context
)
)
},
durationMillis = 4000L,
snackbarState = event.snackbarState
)
)
delay(500)
_state.update {
it.copy(
isRefreshing = false
)
}
return@launch
}
_state.update {
it.copy(
book = newBook,
authorChanged = false,
descriptionChanged = false,
textChanged = false,
updatedBook = null
)
}
}
event.refreshList(_state.value.book)
onEvent(

View file

@ -70,9 +70,8 @@
Після видалення всієї історії порядок книг буде скинутий.
</string>
<string name="confirm_update_description">
При підтвердженні ця книга буде оновлена.
При підтвердженні текст цієї книги буде оновлений.
Будь ласка, запам\'ятайте де ви зупинилися перед оновленням тексту.
Наступне буде оновлено:
</string>
<string name="update_app_description">
Нова версія Історії Книги була знайдена.
@ -301,8 +300,8 @@
<!-- Snackbar messages -->
<string name="history_element_deleted">Елемент історії був успішно видалений.</string>
<string name="file_not_found">Файл \"%1$s\" не знайдено.</string>
<string name="book_updated">Текст, автор та опис книги були успішно оновлені.</string>
<string name="nothing_changed">Книга актуальна.</string>
<string name="book_updated">Текст книги був успішно оновлений.</string>
<string name="nothing_changed">Текст книги актуальний.</string>
<!-- DropDown properties -->
<string name="move_this_book">Перемістити</string>

View file

@ -89,9 +89,8 @@
After deleting the whole history, the order of the books will be reset.
</string>
<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.
Following will be updated:
</string>
<string name="update_app_description">
New version of Book\'s Story was found.
@ -321,8 +320,8 @@
<!-- Snackbar messages -->
<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="book_updated">Book text, author and description were successfully updated.</string>
<string name="nothing_changed">Book is up to date.</string>
<string name="book_updated">Book\'s text was successfully updated.</string>
<string name="nothing_changed">Book\'s text is up to date.</string>
<!-- DropDown properties -->
<string name="move_this_book">Move</string>