Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long Press Playback Effect Turns Custom Effect On #1150

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
([#1139](https://github.com/Automattic/pocket-casts-android/pull/1139))
* Adds +- 1 increments to the sleep timer if the custom timer is less than 5 Min
([#1144](https://github.com/Automattic/pocket-casts-android/pull/1144)).
* Adds Long Press Click listener to the playback effect icon, which turns custom effects on.
([#1150](https://github.com/Automattic/pocket-casts-android/pull/1150)).


7.42
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface PlayerClickListener {
fun onSkipForward()
fun onPlayClicked()
fun onSkipForwardLongPress()
fun onEnableLocalPlayBackEffects()
fun onClosePlayer()
fun onEffectsClick()
fun onSleepClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class PlayerHeaderFragment : BaseFragment(), PlayerClickListener {
}

binding.effects.setOnClickListener { onEffectsClick() }
binding.effects.setOnLongClickListener {
onEnableLocalPlayBackEffects()
true
}
binding.previousChapter.setOnClickListener { onPreviousChapter() }
binding.nextChapter.setOnClickListener { onNextChapter() }
binding.sleep.setOnClickListener { onSleepClick() }
Expand Down Expand Up @@ -444,6 +448,12 @@ class PlayerHeaderFragment : BaseFragment(), PlayerClickListener {
LongPressOptionsFragment().show(parentFragmentManager, "longpressoptions")
}

override fun onEnableLocalPlayBackEffects() {
trackShelfAction(ShelfItem.Effects.analyticsValue)
viewModel.updateOverrideGlobalEffects(true)
viewModel.toggleNotifications(requireContext())
}

override fun onEffectsClick() {
trackShelfAction(ShelfItem.Effects.analyticsValue)
EffectsFragment().show(parentFragmentManager, "effects_sheet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.com.shiftyjelly.pocketcasts.player.viewmodel

import android.content.Context
import android.content.res.Resources
import android.widget.Toast
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand Down Expand Up @@ -395,6 +396,28 @@ class PlayerViewModel @Inject constructor(
}
}

fun toggleNotifications(context: Context) {
Toast.makeText(context, LR.string.player_effects_custom_effects_applied, Toast.LENGTH_SHORT).show()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the UI related components like context from ViewModel and move to UI/fragment? We should not use context in viewmodel except UIs because it makes the testing harder.

}

fun updateOverrideGlobalEffects(override: Boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, override looks like a pre-defined naming convention. Can we use self-explanatory name?

val podcast = this.podcast ?: return
launch {
podcastManager.updateOverrideGlobalEffects(podcast, override)
if (shouldUpdatePlaybackManager()) {
val effects = if (override) podcast.playbackEffects else settings.getGlobalPlaybackEffects()
playbackManager.updatePlayerEffects(effects)
}
}
}

private fun shouldUpdatePlaybackManager(): Boolean {
val podcast = this.podcast ?: return false
val currentEpisode = playbackManager.upNextQueue.currentEpisode
val podcastUuid = if (currentEpisode is PodcastEpisode) currentEpisode.podcastUuid else null
return podcastUuid == podcast.uuid
}

fun hasNextEpisode(): Boolean {
return playbackManager.upNextQueue.queueEpisodes.isNotEmpty()
}
Expand Down