[Android] FileBrowser: fix sort race condition at resume
Duncan McNamara
git at videolan.org
Mon Jul 4 12:36:06 UTC 2022
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Mon Jun 27 18:11:00 2022 +0200| [b8b4adb69b181059b946aeb388db8d6797cc6f24] | committer: Nicolas Pomepuy
FileBrowser: fix sort race condition at resume
On some devices, when first fetching the dataset for the browser,
browseImpl will be called during the reSort that is called by
onResume. This means that the reSort starts with a empty dataset,
browseImpl populates it, and reSort finishes by reassigning an
empty set to dataset.value.
In on Resume if the dataset is empty then it will be populated and
sorted by browseImpl, if it is not, then it has already been
populated, but possibly with the wrong sort as resetSort hasn't
been called. Hence in this case reSort should be called just in case
> https://code.videolan.org/videolan/vlc-android/commit/b8b4adb69b181059b946aeb388db8d6797cc6f24
---
.../src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt | 4 +++-
.../src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt | 3 +--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
index 41385ca47..892170765 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
@@ -130,7 +130,9 @@ open class FileBrowserFragment : BaseBrowserFragment() {
override fun onResume() {
super.onResume()
- viewModel.reSort()
+ viewModel.resetSort()
+ if (viewModel.dataset.value.isNotEmpty())
+ viewModel.reSort()
}
override fun onPrepareOptionsMenu(menu: Menu) {
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index 1c0c1a666..137a7a3c0 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -78,7 +78,6 @@ open class BrowserModel(
*
*/
fun reSort() {
- resetSort()
viewModelScope.launch {
val comp = provider.comparator
dataset.value = withContext(coroutineContextProvider.Default) { dataset.value.apply { sortWith(comp) }.also { provider.computeHeaders(dataset.value) } }
@@ -89,7 +88,7 @@ open class BrowserModel(
* Resets the sorts info from the shared preferences for the model and provider
*
*/
- private fun resetSort() {
+ fun resetSort() {
sort = settings.getInt(sortKey, Medialibrary.SORT_DEFAULT)
desc = settings.getBoolean("${sortKey}_desc", false)
provider.desc = desc
More information about the Android
mailing list