Skip to content

Commit

Permalink
Make MultSelectBookmarksHelper not a singleton (#1580)
Browse files Browse the repository at this point in the history
Co-authored-by: ashiagr <[email protected]>
  • Loading branch information
mchowning and ashiagr authored Dec 13, 2023
1 parent 335fd30 commit d24a1a8
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 75 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* Fix text being cut off in discover search bar at high zoom
([#1601](https://github.com/Automattic/pocket-casts-android/pull/1601))
* Fix issues where multi-select on one screen would affect another screen
([#1579](https://github.com/Automattic/pocket-casts-android/pull/1579))
([#1579](https://github.com/Automattic/pocket-casts-android/pull/1579),
[#1580](https://github.com/Automattic/pocket-casts-android/pull/1580))
* Updates:
* Display dynamic colors for widget
([#1588](https://github.com/Automattic/pocket-casts-android/pull/1588))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
import androidx.viewpager2.adapter.FragmentStateAdapter
Expand All @@ -27,6 +28,7 @@ import au.com.shiftyjelly.pocketcasts.player.databinding.FragmentPlayerContainer
import au.com.shiftyjelly.pocketcasts.player.view.bookmark.BookmarksFragment
import au.com.shiftyjelly.pocketcasts.player.view.chapters.ChaptersFragment
import au.com.shiftyjelly.pocketcasts.player.view.chapters.ChaptersViewModel
import au.com.shiftyjelly.pocketcasts.player.viewmodel.BookmarksViewModel
import au.com.shiftyjelly.pocketcasts.player.viewmodel.PlayerViewModel
import au.com.shiftyjelly.pocketcasts.preferences.Settings
import au.com.shiftyjelly.pocketcasts.repositories.playback.UpNextSource
Expand All @@ -38,7 +40,6 @@ import au.com.shiftyjelly.pocketcasts.utils.featureflag.Feature
import au.com.shiftyjelly.pocketcasts.utils.featureflag.FeatureFlag
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseFragment
import au.com.shiftyjelly.pocketcasts.views.helper.HasBackstack
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectBookmarksHelper
import au.com.shiftyjelly.pocketcasts.views.tour.TourStep
import au.com.shiftyjelly.pocketcasts.views.tour.TourViewTag
import com.google.android.material.bottomsheet.BottomSheetBehavior
Expand All @@ -54,7 +55,7 @@ import au.com.shiftyjelly.pocketcasts.views.R as VR
class PlayerContainerFragment : BaseFragment(), HasBackstack {
@Inject lateinit var settings: Settings
@Inject lateinit var analyticsTracker: AnalyticsTrackerWrapper
@Inject lateinit var multiSelectHelper: MultiSelectBookmarksHelper
private val bookmarksViewModel: BookmarksViewModel by viewModels()

lateinit var upNextBottomSheetBehavior: BottomSheetBehavior<View>

Expand All @@ -71,7 +72,7 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
override fun onDestroyView() {
super.onDestroyView()
binding = null
multiSelectHelper.context = null
bookmarksViewModel.multiSelectHelper.context = null
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -128,7 +129,7 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
if (state == SCROLL_STATE_IDLE) {
(activity as? FragmentHostListener)?.updatePlayerView()
}
viewPager.isUserInputEnabled = !multiSelectHelper.isMultiSelecting
viewPager.isUserInputEnabled = !bookmarksViewModel.multiSelectHelper.isMultiSelecting
}

override fun onPageSelected(position: Int) {
Expand Down Expand Up @@ -196,14 +197,14 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
}
}

multiSelectHelper.isMultiSelectingLive.observe(viewLifecycleOwner) { isMultiSelecting ->
bookmarksViewModel.multiSelectHelper.isMultiSelectingLive.observe(viewLifecycleOwner) { isMultiSelecting ->
binding.multiSelectToolbar.isVisible = isMultiSelecting
binding.multiSelectToolbar.setNavigationIcon(IR.drawable.ic_arrow_back)
}
multiSelectHelper.context = context
bookmarksViewModel.multiSelectHelper.context = context
binding.multiSelectToolbar.setup(
lifecycleOwner = viewLifecycleOwner,
multiSelectHelper = multiSelectHelper,
multiSelectHelper = bookmarksViewModel.multiSelectHelper,
menuRes = null,
fragmentManager = parentFragmentManager,
)
Expand Down Expand Up @@ -274,7 +275,7 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {

override fun getBackstackCount(): Int {
return if (upNextBottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED ||
multiSelectHelper.isMultiSelecting
bookmarksViewModel.multiSelectHelper.isMultiSelecting
) 1 else 0
}

Expand All @@ -284,8 +285,8 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
upNextBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
true
}
multiSelectHelper.isMultiSelecting -> {
multiSelectHelper.closeMultiSelect()
bookmarksViewModel.multiSelectHelper.isMultiSelecting -> {
bookmarksViewModel.multiSelectHelper.closeMultiSelect()
binding?.viewPager?.isUserInputEnabled = true
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import androidx.activity.OnBackPressedCallback
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.viewModels
import au.com.shiftyjelly.pocketcasts.analytics.SourceView
import au.com.shiftyjelly.pocketcasts.images.R
import au.com.shiftyjelly.pocketcasts.player.databinding.FragmentBookmarksContainerBinding
import au.com.shiftyjelly.pocketcasts.player.viewmodel.BookmarksViewModel
import au.com.shiftyjelly.pocketcasts.ui.extensions.getThemeColor
import au.com.shiftyjelly.pocketcasts.ui.helper.StatusBarColor
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseDialogFragment
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectBookmarksHelper
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import au.com.shiftyjelly.pocketcasts.ui.R as UR

@AndroidEntryPoint
Expand Down Expand Up @@ -54,9 +54,7 @@ class BookmarksContainerFragment :
)

var binding: FragmentBookmarksContainerBinding? = null

@Inject
lateinit var multiSelectHelper: MultiSelectBookmarksHelper
private val bookmarksViewModel: BookmarksViewModel by viewModels()

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -74,8 +72,8 @@ class BookmarksContainerFragment :
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (multiSelectHelper.isMultiSelecting) {
multiSelectHelper.isMultiSelecting = false
if (bookmarksViewModel.multiSelectHelper.isMultiSelecting) {
bookmarksViewModel.multiSelectHelper.isMultiSelecting = false
return
}
dismiss()
Expand Down Expand Up @@ -116,14 +114,14 @@ class BookmarksContainerFragment :
}

private fun FragmentBookmarksContainerBinding.setupMultiSelectHelper() {
multiSelectHelper.isMultiSelectingLive.observe(viewLifecycleOwner) { isMultiSelecting ->
bookmarksViewModel.multiSelectHelper.isMultiSelectingLive.observe(viewLifecycleOwner) { isMultiSelecting ->
multiSelectToolbar.isVisible = isMultiSelecting
multiSelectToolbar.setNavigationIcon(R.drawable.ic_arrow_back)
}
multiSelectHelper.context = context
bookmarksViewModel.multiSelectHelper.context = context
multiSelectToolbar.setup(
lifecycleOwner = viewLifecycleOwner,
multiSelectHelper = multiSelectHelper,
multiSelectHelper = bookmarksViewModel.multiSelectHelper,
menuRes = null,
fragmentManager = parentFragmentManager,
)
Expand All @@ -132,7 +130,9 @@ class BookmarksContainerFragment :
override fun onDestroyView() {
super.onDestroyView()
binding = null
multiSelectHelper.isMultiSelecting = false
multiSelectHelper.context = null
with(bookmarksViewModel.multiSelectHelper) {
isMultiSelecting = false
context = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import au.com.shiftyjelly.pocketcasts.utils.featureflag.FeatureTier
import au.com.shiftyjelly.pocketcasts.views.R
import au.com.shiftyjelly.pocketcasts.views.dialog.OptionsDialog
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseFragment
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectBookmarksHelper
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
Expand Down Expand Up @@ -63,10 +62,7 @@ class BookmarksFragment : BaseFragment() {
}

private val playerViewModel: PlayerViewModel by activityViewModels()
private val bookmarksViewModel: BookmarksViewModel by viewModels()

@Inject
lateinit var multiSelectHelper: MultiSelectBookmarksHelper
private val bookmarksViewModel: BookmarksViewModel by viewModels({ requireParentFragment() })

@Inject
lateinit var settings: Settings
Expand Down Expand Up @@ -108,9 +104,9 @@ class BookmarksFragment : BaseFragment() {
textColor = requireNotNull(textColor(listData)),
sourceView = sourceView,
bookmarksViewModel = bookmarksViewModel,
multiSelectHelper = multiSelectHelper,
multiSelectHelper = bookmarksViewModel.multiSelectHelper,
onRowLongPressed = { bookmark ->
multiSelectHelper.defaultLongPress(
bookmarksViewModel.multiSelectHelper.defaultLongPress(
multiSelectable = bookmark,
fragmentManager = childFragmentManager,
forceDarkTheme = sourceView == SourceView.PLAYER,
Expand Down Expand Up @@ -165,7 +161,7 @@ class BookmarksFragment : BaseFragment() {
titleId = LR.string.bookmarks_select_option,
imageId = IR.drawable.ic_multiselect,
click = {
multiSelectHelper.isMultiSelecting = true
bookmarksViewModel.multiSelectHelper.isMultiSelecting = true
}
)
.addTextOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BookmarksViewModel
private val bookmarkManager: BookmarkManager,
private val episodeManager: EpisodeManager,
private val podcastManager: PodcastManager,
private val multiSelectHelper: MultiSelectBookmarksHelper,
val multiSelectHelper: MultiSelectBookmarksHelper,
private val settings: Settings,
private val playbackManager: PlaybackManager,
private val theme: Theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import au.com.shiftyjelly.pocketcasts.images.R
import au.com.shiftyjelly.pocketcasts.models.entity.PodcastEpisode
import au.com.shiftyjelly.pocketcasts.models.type.EpisodeViewSource
import au.com.shiftyjelly.pocketcasts.player.view.bookmark.BookmarksFragment
import au.com.shiftyjelly.pocketcasts.player.viewmodel.BookmarksViewModel
import au.com.shiftyjelly.pocketcasts.podcasts.databinding.FragmentEpisodeContainerBinding
import au.com.shiftyjelly.pocketcasts.ui.extensions.getThemeColor
import au.com.shiftyjelly.pocketcasts.ui.helper.StatusBarColor
Expand All @@ -33,13 +34,11 @@ import au.com.shiftyjelly.pocketcasts.ui.theme.ThemeColor
import au.com.shiftyjelly.pocketcasts.utils.featureflag.Feature
import au.com.shiftyjelly.pocketcasts.utils.featureflag.FeatureFlag
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseDialogFragment
import au.com.shiftyjelly.pocketcasts.views.multiselect.MultiSelectBookmarksHelper
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import javax.inject.Inject
import au.com.shiftyjelly.pocketcasts.localization.R as LR
import au.com.shiftyjelly.pocketcasts.ui.R as UR

Expand Down Expand Up @@ -120,9 +119,9 @@ class EpisodeContainerFragment :
get() = if (forceDarkTheme && theme.isLightTheme) Theme.ThemeType.DARK else theme.activeTheme

private lateinit var adapter: ViewPagerAdapter
@Inject
lateinit var multiSelectHelper: MultiSelectBookmarksHelper

private val viewModel: EpisodeContainerFragmentViewModel by viewModels()
private val bookmarksViewModel: BookmarksViewModel by viewModels()

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
if (!forceDarkTheme || theme.isDarkTheme) {
Expand All @@ -149,8 +148,8 @@ class EpisodeContainerFragment :
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (multiSelectHelper.isMultiSelecting) {
multiSelectHelper.isMultiSelecting = false
if (bookmarksViewModel.multiSelectHelper.isMultiSelecting) {
bookmarksViewModel.multiSelectHelper.isMultiSelecting = false
return
}
dismiss()
Expand Down Expand Up @@ -206,7 +205,7 @@ class EpisodeContainerFragment :
viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageScrollStateChanged(state: Int) {
super.onPageScrollStateChanged(state)
viewPager.isUserInputEnabled = !multiSelectHelper.isMultiSelecting
viewPager.isUserInputEnabled = !bookmarksViewModel.multiSelectHelper.isMultiSelecting
}

override fun onPageSelected(position: Int) {
Expand All @@ -219,14 +218,14 @@ class EpisodeContainerFragment :
}

private fun FragmentEpisodeContainerBinding.setupMultiSelectHelper() {
multiSelectHelper.isMultiSelectingLive.observe(viewLifecycleOwner) { isMultiSelecting ->
bookmarksViewModel.multiSelectHelper.isMultiSelectingLive.observe(viewLifecycleOwner) { isMultiSelecting ->
multiSelectToolbar.isVisible = isMultiSelecting
multiSelectToolbar.setNavigationIcon(R.drawable.ic_arrow_back)
}
multiSelectHelper.context = context
bookmarksViewModel.multiSelectHelper.context = context
multiSelectToolbar.setup(
lifecycleOwner = viewLifecycleOwner,
multiSelectHelper = multiSelectHelper,
multiSelectHelper = bookmarksViewModel.multiSelectHelper,
menuRes = null,
fragmentManager = parentFragmentManager,
)
Expand All @@ -235,9 +234,11 @@ class EpisodeContainerFragment :
override fun onDestroyView() {
super.onDestroyView()
binding = null
multiSelectHelper.isMultiSelecting = false
multiSelectHelper.context = null
multiSelectHelper.listener = null
with(bookmarksViewModel.multiSelectHelper) {
isMultiSelecting = false
context = null
listener = null
}
}

private class ViewPagerAdapter(
Expand Down
Loading

0 comments on commit d24a1a8

Please sign in to comment.