Skip to content

Commit

Permalink
Update multi select toolbars setup (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiagr authored Sep 4, 2023
1 parent e75648a commit ec22b40
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
([#1234](https://github.com/Automattic/pocket-casts-android/pull/1234))
* Improved handling of enabling/disabling new episode notifications
([#1264](https://github.com/Automattic/pocket-casts-android/pull/1264))
* Fixed the artwork not appearing on the onboarding page
* Fixed the artwork not appearing on the onboarding page
([#1299](https://github.com/Automattic/pocket-casts-android/pull/1299))
* Improved multi-select toolbars setup
([#1338](https://github.com/Automattic/pocket-casts-android/pull/1338))

7.46
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private fun BookmarksView(
isSelected = state.isSelected,
onPlayClick = onPlayClick,
modifier = Modifier
.pointerInput(state.isSelected(bookmark)) {
.pointerInput(bookmark.adapterId) {
detectTapGestures(
onLongPress = { onRowLongPressed(bookmark) },
onTap = { state.onRowClick(bookmark) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTrackerWrapper
import au.com.shiftyjelly.pocketcasts.analytics.FirebaseAnalyticsTracker
import au.com.shiftyjelly.pocketcasts.analytics.SourceView
import au.com.shiftyjelly.pocketcasts.featureflag.Feature
import au.com.shiftyjelly.pocketcasts.featureflag.FeatureFlag
import au.com.shiftyjelly.pocketcasts.localization.extensions.getStringPlural
import au.com.shiftyjelly.pocketcasts.models.entity.BaseEpisode
import au.com.shiftyjelly.pocketcasts.models.entity.Bookmark
Expand Down Expand Up @@ -74,6 +76,7 @@ import au.com.shiftyjelly.pocketcasts.views.helper.UiUtil
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectBookmarksHelper
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectEpisodesHelper
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectHelper
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectToolbar
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -644,17 +647,32 @@ class PodcastFragment : BaseFragment(), Toolbar.OnMenuItemClickListener, Corouti

binding.episodesRecyclerView.requestFocus()

multiSelectEpisodesHelper.setUp()
multiSelectBookmarksHelper.setUp()

return binding.root
}

fun <T> MultiSelectHelper<T>.setUp() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding?.setupMultiSelect()
}

private fun FragmentPodcastBinding.setupMultiSelect() {
multiSelectEpisodesHelper.setUp(multiSelectEpisodesToolbar)
if (FeatureFlag.isEnabled(Feature.BOOKMARKS_ENABLED)) {
multiSelectBookmarksHelper.setUp(multiSelectBookmarksToolbar)
}
}

fun <T> MultiSelectHelper<T>.setUp(multiSelectToolbar: MultiSelectToolbar) {
multiSelectToolbar.setup(
lifecycleOwner = viewLifecycleOwner,
multiSelectHelper = this,
menuRes = null,
fragmentManager = parentFragmentManager,
)
isMultiSelectingLive.observe(viewLifecycleOwner) {
val episodeContainerFragment = parentFragmentManager.findFragmentByTag(EPISODE_CARD)
if (episodeContainerFragment != null) return@observe
binding?.multiSelectToolbar?.isVisible = it
multiSelectToolbar.isVisible = it
binding?.toolbar?.isVisible = !it
adapter?.notifyDataSetChanged()
}
Expand Down Expand Up @@ -747,13 +765,6 @@ class PodcastFragment : BaseFragment(), Toolbar.OnMenuItemClickListener, Corouti
addPaddingForEpisodeSearch(state.episodes)
when (state.showTab) {
PodcastTab.EPISODES -> {
binding?.multiSelectToolbar?.setup(
lifecycleOwner = viewLifecycleOwner,
multiSelectHelper = multiSelectEpisodesHelper,
menuRes = null,
fragmentManager = parentFragmentManager,
)

adapter?.setEpisodes(
episodes = state.episodes,
showingArchived = state.showingArchived,
Expand All @@ -767,13 +778,6 @@ class PodcastFragment : BaseFragment(), Toolbar.OnMenuItemClickListener, Corouti
)
}
PodcastTab.BOOKMARKS -> {
binding?.multiSelectToolbar?.setup(
lifecycleOwner = viewLifecycleOwner,
multiSelectHelper = multiSelectBookmarksHelper,
menuRes = null,
fragmentManager = parentFragmentManager,
)

adapter?.setBookmarks(
bookmarks = state.bookmarks,
searchTerm = state.searchBookmarkTerm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BookmarkViewHolder(
isSelected = data.isSelected,
onPlayClick = { data.onBookmarkPlayClicked(it) },
modifier = Modifier
.pointerInput(data.isSelected(data.bookmark)) {
.pointerInput(data.bookmark.adapterId) {
detectTapGestures(
onLongPress = { data.onBookmarkRowLongPress(data.bookmark) },
onTap = { data.onBookmarkRowClick(data.bookmark, bindingAdapterPosition) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class PodcastViewModel
}

fun onTabClicked(tab: PodcastTab) {
when (tab) {
PodcastTab.EPISODES -> multiSelectBookmarksHelper.closeMultiSelect()
PodcastTab.BOOKMARKS -> multiSelectEpisodesHelper.closeMultiSelect()
}
analyticsTracker.track(AnalyticsEvent.PODCASTS_SCREEN_TAB_TAPPED, mapOf("value" to tab.analyticsValue))
_uiState.value = (uiState.value as? UiState.Loaded)?.copy(showTab = tab)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectToolbar
android:id="@+id/multiSelectToolbar"
android:id="@+id/multiSelectEpisodesToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
app:navigationIcon="?attr/homeAsUpIndicator"
android:visibility="gone"/>

<au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectToolbar
android:id="@+id/multiSelectBookmarksToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
Expand Down

0 comments on commit ec22b40

Please sign in to comment.