[Android] Bookmarks: fix name update after rename
Duncan McNamara
git at videolan.org
Thu Sep 23 10:26:33 UTC 2021
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Fri Sep 17 18:45:44 2021 +0200| [a0be7d02cde5c23d245b9a1433fe8fb9582a5e0e] | committer: Nicolas Pomepuy
Bookmarks: fix name update after rename
The adapter update causing the ui update after a rename is triggered by
the observer on the BookmarkModel dataset, by then the dataset has
already changed, and the DiffUtilAdapter will compare the dataset and
the new BookmarkList which are equal. To trigger the name update the
adapter.update must be called before the BookmarkModel.refresh that
actuates the dataset, when dataset and the new bookmark list are still
different.
Closes #2177
> https://code.videolan.org/videolan/vlc-android/commit/a0be7d02cde5c23d245b9a1433fe8fb9582a5e0e
---
.../org/videolan/vlc/gui/helpers/BookmarkListDelegate.kt | 4 +++-
.../src/org/videolan/vlc/viewmodels/BookmarkModel.kt | 16 ++++++++++++----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/BookmarkListDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/BookmarkListDelegate.kt
index 0142c6654..155d7348f 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/BookmarkListDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/BookmarkListDelegate.kt
@@ -139,7 +139,9 @@ class BookmarkListDelegate(val activity: FragmentActivity, val service: Playback
dialog.show(activity.supportFragmentManager, RenameDialog::class.simpleName)
dialog.setListener { media, name ->
activity.lifecycleScope.launch {
- bookmarkModel.rename(media as Bookmark, name)
+ val bookmarks = bookmarkModel.rename(media as Bookmark, name)
+ adapter.update(bookmarks)
+ bookmarkModel.refresh()
}
}
true
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/BookmarkModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/BookmarkModel.kt
index 5b8558a4f..ca8d85cd9 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/BookmarkModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/BookmarkModel.kt
@@ -121,10 +121,18 @@ class BookmarkModel : ViewModel(), PlaybackService.Callback {
}
}
- suspend fun rename(bookmark: Bookmark, name: String) {
- withContext(Dispatchers.IO) {
- bookmark.setName(name)
+ suspend fun rename(bookmark: Bookmark, name: String) : List<Bookmark> {
+ var bookmarks: List<Bookmark> = listOf()
+ service?.currentMediaWrapper?.let {
+ viewModelScope.launch {
+ withContext(Dispatchers.IO) {
+ bookmark.setName(name)
+ bookmarks = it.bookmarks.toList()
+ bookmarks[bookmarks.indexOf(bookmark)].setName(name)
+ }
+ }
}
- refresh()
+ return bookmarks
}
+
}
More information about the Android
mailing list