Skip to content

Commit

Permalink
Make sure that we're batching multiselect updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mchowning committed Aug 28, 2023
1 parent 1aa79d9 commit 548bedc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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()
}
}
Expand All @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,21 @@ class UpNextFragment : BaseFragment(), UpNextListener, UpNextTouchCallback.ItemT
multiSelectHelper.listener = object : MultiSelectHelper.Listener<BaseEpisode> {
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()
Expand All @@ -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()
Expand All @@ -276,15 +278,17 @@ 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()
}

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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit 548bedc

Please sign in to comment.