fix: Reloading data #2541

This commit is contained in:
J-Jamet committed 2026-06-08 18:36:43 +02:00
1 parent 432129074a
commit 98feef506e
3 files changed
+45 -29

No files matched your search

@@ -363,6 +363,9 @@ class EntryActivity : DatabaseLockActivity() {
}
}
}
is EntryViewModel.EntryEvent.Close -> {
finish()
}
}
}
}
@@ -426,7 +429,7 @@ class EntryActivity : DatabaseLockActivity() {
}
}
override fun finishActivityIfReloadRequested(): Boolean = true
override fun finishActivityIfReloadRequested(): Boolean = false
override fun viewToInvalidateTimeout(): View? {
return coordinatorLayout
@@ -111,8 +111,11 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
viewModelScope.launch {
mDatabase?.let { database ->
withContext(Dispatchers.IO) {
if (mainEntryId != null) {
_entryUIState.update { entryState ->
entryState.copy(loaded = false)
}
if (mainEntryId != null) {
withContext(Dispatchers.IO) {
database.getEntryById(mainEntryId)?.let { mainEntry ->
val isHistory = historyPosition > -1
val currentEntry = if (isHistory) {
@@ -123,36 +126,42 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
val entryInfo = database.getEntryInfoFrom(currentEntry)
this@EntryViewModel.entryIsHistory = isHistory
_entryEvents.emit(EntryEvent.EntryLoaded(entryInfo))
withContext(Dispatchers.Main) {
_entryEvents.emit(EntryEvent.EntryLoaded(entryInfo))
// Assign colors
backgroundColor =
if (showEntryColors) entryInfo.backgroundColor else null
foregroundColor =
if (showEntryColors) entryInfo.foregroundColor else null
// Assign colors
backgroundColor =
if (showEntryColors) entryInfo.backgroundColor else null
foregroundColor =
if (showEntryColors) entryInfo.foregroundColor else null
// To show Entry UI
_entryUIState.update {
it.copy(
loaded = true,
entryInfo = entryInfo,
isReadOnly = database.isReadOnly,
showFloatingActionButton = !isHistory,
showHistoryView = isHistory,
entryHistory = if (!isHistory)
database.getHistoryEntryInfoFrom(mainEntryId) ?: listOf()
else listOf()
)
}
// Manage entry to populate Magikeyboard and launch keyboard notification if allowed
if (keyboardEntrySelectionEnabled) {
_entryEvents.emit(
EntryEvent.AddToMagikeyboard(
// To show Entry UI
_entryUIState.update {
it.copy(
loaded = true,
entryInfo = entryInfo,
autoSwitch = autoSwitchToMagikeyboard
isReadOnly = database.isReadOnly,
showFloatingActionButton = !isHistory,
showHistoryView = isHistory,
entryHistory = if (!isHistory)
database.getHistoryEntryInfoFrom(mainEntryId) ?: listOf()
else listOf()
)
)
}
// Manage entry to populate Magikeyboard and launch keyboard notification if allowed
if (keyboardEntrySelectionEnabled) {
_entryEvents.emit(
EntryEvent.AddToMagikeyboard(
entryInfo = entryInfo,
autoSwitch = autoSwitchToMagikeyboard
)
)
}
}
} ?: run {
withContext(Dispatchers.Main) {
_entryEvents.emit(EntryEvent.Close)
}
}
}
@@ -288,6 +297,8 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
data class HistorySelected(
val entryHistory: EntryHistory,
) : EntryEvent()
object Close : EntryEvent()
}
/**
@@ -201,6 +201,8 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
_viewEvent.emit(GroupEvent.ShowPosition(showFromPosition))
}
}
} else {
loadPreviousGroup()
}
}
}