From 1313fa35926ca248cf53a75844ea899050aa0230 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Mon, 28 Aug 2023 15:03:20 -0400 Subject: [PATCH 1/2] Make sure that we're batching multiselect updates --- .../filters/FilterEpisodeListFragment.kt | 6 +++--- .../pocketcasts/player/view/UpNextFragment.kt | 16 ++++++++++------ .../player/viewmodel/BookmarksViewModel.kt | 6 +++--- .../podcasts/view/ProfileEpisodeListFragment.kt | 8 +++++--- .../profile/cloud/CloudFilesFragment.kt | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/features/filters/src/main/java/au/com/shiftyjelly/pocketcasts/filters/FilterEpisodeListFragment.kt b/modules/features/filters/src/main/java/au/com/shiftyjelly/pocketcasts/filters/FilterEpisodeListFragment.kt index c1ac31afdff..bf32d0d3e31 100644 --- a/modules/features/filters/src/main/java/au/com/shiftyjelly/pocketcasts/filters/FilterEpisodeListFragment.kt +++ b/modules/features/filters/src/main/java/au/com/shiftyjelly/pocketcasts/filters/FilterEpisodeListFragment.kt @@ -463,7 +463,7 @@ class FilterEpisodeListFragment : BaseFragment() { override fun multiSelectSelectNone() { val episodes = viewModel.episodesList.value if (episodes != null) { - episodes.forEach { multiSelectHelper.deselect(it) } + multiSelectHelper.deselectAllInList(episodes) adapter.notifyDataSetChanged() } } @@ -488,7 +488,7 @@ class FilterEpisodeListFragment : BaseFragment() { val startIndex = episodes.indexOf(multiSelectable) if (startIndex > -1) { val episodesBelow = episodes.subList(startIndex, episodes.size) - episodesBelow.forEach { multiSelectHelper.deselect(it) } + multiSelectHelper.deselectAllInList(episodesBelow) adapter.notifyDataSetChanged() } } @@ -501,7 +501,7 @@ class FilterEpisodeListFragment : BaseFragment() { val startIndex = episodes.indexOf(multiSelectable) if (startIndex > -1) { val episodesAbove = episodes.subList(0, startIndex + 1) - episodesAbove.forEach { multiSelectHelper.deselect(it) } + multiSelectHelper.deselectAllInList(episodesAbove) adapter.notifyDataSetChanged() } } diff --git a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/UpNextFragment.kt b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/UpNextFragment.kt index c3cddc45c51..da504f814ef 100644 --- a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/UpNextFragment.kt +++ b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/UpNextFragment.kt @@ -245,20 +245,21 @@ class UpNextFragment : BaseFragment(), UpNextListener, UpNextTouchCallback.ItemT multiSelectHelper.listener = object : MultiSelectHelper.Listener { override fun multiSelectSelectAll() { trackUpNextEvent(AnalyticsEvent.UP_NEXT_SELECT_ALL_TAPPED, mapOf(SELECT_ALL_KEY to true)) - upNextEpisodes.forEach { multiSelectHelper.select(it) } + multiSelectHelper.selectAllInList(upNextEpisodes) adapter.notifyDataSetChanged() } override fun multiSelectSelectNone() { trackUpNextEvent(AnalyticsEvent.UP_NEXT_SELECT_ALL_TAPPED, mapOf(SELECT_ALL_KEY to false)) - upNextEpisodes.forEach { multiSelectHelper.deselect(it) } + multiSelectHelper.deselectAllInList(upNextEpisodes) adapter.notifyDataSetChanged() } override fun multiSelectSelectAllUp(multiSelectable: BaseEpisode) { val startIndex = upNextEpisodes.indexOf(multiSelectable) if (startIndex > -1) { - upNextEpisodes.subList(0, startIndex + 1).forEach { multiSelectHelper.select(it) } + val episodesAbove = upNextEpisodes.subList(0, startIndex + 1) + multiSelectHelper.selectAllInList(episodesAbove) } adapter.notifyDataSetChanged() @@ -267,7 +268,8 @@ class UpNextFragment : BaseFragment(), UpNextListener, UpNextTouchCallback.ItemT override fun multiSelectSelectAllDown(multiSelectable: BaseEpisode) { val startIndex = upNextEpisodes.indexOf(multiSelectable) if (startIndex > -1) { - upNextEpisodes.subList(startIndex, upNextEpisodes.size).forEach { multiSelectHelper.select(it) } + val episodesBelow = upNextEpisodes.subList(startIndex, upNextEpisodes.size) + multiSelectHelper.selectAllInList(episodesBelow) } adapter.notifyDataSetChanged() @@ -276,7 +278,8 @@ class UpNextFragment : BaseFragment(), UpNextListener, UpNextTouchCallback.ItemT override fun multiDeselectAllBelow(multiSelectable: BaseEpisode) { val startIndex = upNextEpisodes.indexOf(multiSelectable) if (startIndex > -1) { - upNextEpisodes.subList(startIndex, upNextEpisodes.size).forEach { multiSelectHelper.deselect(it) } + val episodesBelow = upNextEpisodes.subList(startIndex, upNextEpisodes.size) + multiSelectHelper.deselectAllInList(episodesBelow) } adapter.notifyDataSetChanged() } @@ -284,7 +287,8 @@ class UpNextFragment : BaseFragment(), UpNextListener, UpNextTouchCallback.ItemT override fun multiDeselectAllAbove(multiSelectable: BaseEpisode) { val startIndex = upNextEpisodes.indexOf(multiSelectable) if (startIndex > -1) { - upNextEpisodes.subList(0, startIndex + 1).forEach { multiSelectHelper.deselect(it) } + val episdesAbove = upNextEpisodes.subList(0, startIndex + 1) + multiSelectHelper.deselectAllInList(episdesAbove) } adapter.notifyDataSetChanged() } diff --git a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/viewmodel/BookmarksViewModel.kt b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/viewmodel/BookmarksViewModel.kt index 94653f0e3cb..1ecf5c3e754 100644 --- a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/viewmodel/BookmarksViewModel.kt +++ b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/viewmodel/BookmarksViewModel.kt @@ -110,7 +110,7 @@ class BookmarksViewModel override fun multiSelectSelectNone() { (_uiState.value as? UiState.Loaded)?.bookmarks?.let { bookmarks -> - bookmarks.forEach { multiSelectHelper.deselect(it) } + multiSelectHelper.deselectAllInList(bookmarks) } } @@ -128,8 +128,8 @@ class BookmarksViewModel (_uiState.value as? UiState.Loaded)?.bookmarks?.let { bookmarks -> val startIndex = bookmarks.indexOf(multiSelectable) if (startIndex > -1) { - bookmarks.subList(startIndex, bookmarks.size) - .forEach { multiSelectHelper.deselect(it) } + val bookmarksBelow = bookmarks.subList(startIndex, bookmarks.size) + multiSelectHelper.deselectAllInList(bookmarksBelow) } } } diff --git a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/view/ProfileEpisodeListFragment.kt b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/view/ProfileEpisodeListFragment.kt index 5c150a4bee0..c17b6250589 100644 --- a/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/view/ProfileEpisodeListFragment.kt +++ b/modules/features/podcasts/src/main/java/au/com/shiftyjelly/pocketcasts/podcasts/view/ProfileEpisodeListFragment.kt @@ -252,7 +252,7 @@ class ProfileEpisodeListFragment : BaseFragment(), Toolbar.OnMenuItemClickListen override fun multiSelectSelectNone() { val episodes = viewModel.episodeList.value if (episodes != null) { - episodes.forEach { multiSelectHelper.deselect(it) } + multiSelectHelper.deselectAllInList(episodes) adapter.notifyDataSetChanged() trackSelectAll(false) } @@ -289,7 +289,8 @@ class ProfileEpisodeListFragment : BaseFragment(), Toolbar.OnMenuItemClickListen if (episodes != null) { val startIndex = episodes.indexOf(multiSelectable) if (startIndex > -1) { - episodes.subList(startIndex, episodes.size).forEach { multiSelectHelper.deselect(it) } + val episodesBelow = episodes.subList(startIndex, episodes.size) + multiSelectHelper.deselectAllInList(episodesBelow) adapter.notifyDataSetChanged() } } @@ -300,7 +301,8 @@ class ProfileEpisodeListFragment : BaseFragment(), Toolbar.OnMenuItemClickListen if (episodes != null) { val startIndex = episodes.indexOf(multiSelectable) if (startIndex > -1) { - episodes.subList(0, startIndex + 1).forEach { multiSelectHelper.deselect(it) } + val episodesAbove = episodes.subList(0, startIndex + 1) + multiSelectHelper.deselectAllInList(episodesAbove) adapter.notifyDataSetChanged() } } diff --git a/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/CloudFilesFragment.kt b/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/CloudFilesFragment.kt index 467f28bcaa7..2eb6874b015 100644 --- a/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/CloudFilesFragment.kt +++ b/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/CloudFilesFragment.kt @@ -253,7 +253,7 @@ class CloudFilesFragment : BaseFragment(), Toolbar.OnMenuItemClickListener { override fun multiSelectSelectNone() { val episodes = viewModel.cloudFilesList.value if (episodes != null) { - episodes.forEach { multiSelectHelper.deselect(it) } + multiSelectHelper.deselectAllInList(episodes) adapter.notifyDataSetChanged() analyticsTracker.track(AnalyticsEvent.UPLOADED_FILES_SELECT_ALL_TAPPED, mapOf(SELECT_ALL_KEY to false)) } From 3d377513a7489a889890983838874e382039c5ca Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Mon, 28 Aug 2023 16:31:12 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81918857628..2f2f57c3c22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ 7.46 ----- +7.45.1 +----- +* Bug Fixes: + * Fixed issue where that could cause app freeze when using multiselect + ([#1315](https://github.com/Automattic/pocket-casts-android/pull/1315)) 7.45 -----