Skip to content

Commit

Permalink
Add share option to multiselect menu (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchowning authored Jul 24, 2023
1 parent 2acae9f commit a569c20
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 7 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
-----
* New Feature:
* Added 3 episodes on the Filter AutoDownload
([#1169])(https://github.com/Automattic/pocket-casts-android/pull/1169)
([#1169](https://github.com/Automattic/pocket-casts-android/pull/1169))
* Added capability to deselect all/below and above on the multiselect feature
([#1172](https://github.com/Automattic/pocket-casts-android/pull/1172))
* Added share option to episode swipe menu
([#1190](https://github.com/Automattic/pocket-casts-android/pull/1190))
* Added share option to episode swipe and multiselect menus
([#1190](https://github.com/Automattic/pocket-casts-android/pull/1190)),
([#1191](https://github.com/Automattic/pocket-casts-android/pull/1191))

7.43
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum class SourceView(val analyticsValue: String) {
ONBOARDING_RECOMMENDATIONS_SEARCH("onboarding_recommendations_search"),
UNKNOWN("unknown"),
TASKER("tasker"),
EPISODE_SWIPE_ACTION("episode_swipe_action");
EPISODE_SWIPE_ACTION("episode_swipe_action"),
MULTI_SELECT("multi_select");

fun skipTracking() = this in listOf(AUTO_PLAY, AUTO_PAUSE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ open class PlaybackManager @Inject constructor(
SourceView.DISCOVER_RANKED_LIST,
SourceView.FULL_SCREEN_VIDEO,
SourceView.MINIPLAYER,
SourceView.MULTI_SELECT,
SourceView.ONBOARDING_RECOMMENDATIONS,
SourceView.ONBOARDING_RECOMMENDATIONS_SEARCH,
SourceView.PODCAST_LIST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ShareDialog(
}
}

// If the share dialog is not appearing, make sure you're setting an appropriate fragmentManager
// when constructing this class, i.e., you might need a parentFragmentManager instead of a childFragmentManager
fun show(sourceView: SourceView) {
if (fragmentManager == null || context == null) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MultiSelectBottomSheet : BaseDialogFragment() {
}

private fun onClick(item: MultiSelectAction) {
multiSelectHelper?.onMenuItemSelected(item.actionId, resources, childFragmentManager)
multiSelectHelper?.onMenuItemSelected(item.actionId, resources, parentFragmentManager)
dismiss()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ sealed class MultiSelectEpisodeAction(
R.drawable.ic_delete,
"delete"
)
object Share : MultiSelectEpisodeAction(
groupId = R.id.menu_share,
actionId = R.id.menu_share,
title = LR.string.share,
iconRes = IR.drawable.ic_share,
analyticsValue = "share",
)
object MarkAsUnplayed : MultiSelectEpisodeAction(
R.id.menu_mark_played,
UR.id.menu_markasunplayed,
Expand Down Expand Up @@ -104,7 +111,7 @@ sealed class MultiSelectEpisodeAction(
)

companion object {
val STANDARD = listOf(Download, Archive, MarkAsPlayed, PlayNext, PlayLast, Star)
val STANDARD = listOf(Download, Archive, MarkAsPlayed, PlayNext, PlayLast, Star, Share)
val ALL = STANDARD + listOf(DeleteDownload, DeleteUserEpisode, MarkAsUnplayed, Unstar, Unarchive)
val STANDARD_BY_ID = STANDARD.associateBy { it.actionId }
val ALL_BY_ID = ALL.associateBy { it.actionId }
Expand Down Expand Up @@ -156,6 +163,11 @@ sealed class MultiSelectEpisodeAction(
}
R.id.menu_playnext -> return PlayNext
R.id.menu_playlast -> return PlayLast
R.id.menu_share -> {
if (selected.size == 1 &&
selected.firstOrNull() is PodcastEpisode
) return Share
}
}

return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package au.com.shiftyjelly.pocketcasts.views.multiselect

import android.content.res.Resources
import android.widget.Toast
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LiveData
import androidx.lifecycle.map
import androidx.lifecycle.toLiveData
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTrackerWrapper
import au.com.shiftyjelly.pocketcasts.analytics.EpisodeAnalytics
import au.com.shiftyjelly.pocketcasts.analytics.SourceView
import au.com.shiftyjelly.pocketcasts.localization.extensions.getStringPlural
import au.com.shiftyjelly.pocketcasts.models.entity.BaseEpisode
import au.com.shiftyjelly.pocketcasts.models.entity.PodcastEpisode
Expand All @@ -18,8 +21,10 @@ import au.com.shiftyjelly.pocketcasts.repositories.podcast.EpisodeManager
import au.com.shiftyjelly.pocketcasts.repositories.podcast.PodcastManager
import au.com.shiftyjelly.pocketcasts.repositories.podcast.UserEpisodeManager
import au.com.shiftyjelly.pocketcasts.utils.combineLatest
import au.com.shiftyjelly.pocketcasts.utils.log.LogBuffer
import au.com.shiftyjelly.pocketcasts.views.R
import au.com.shiftyjelly.pocketcasts.views.dialog.ConfirmationDialog
import au.com.shiftyjelly.pocketcasts.views.dialog.ShareDialog
import au.com.shiftyjelly.pocketcasts.views.helper.CloudDeleteHelper
import au.com.shiftyjelly.pocketcasts.views.helper.DeleteState
import io.reactivex.BackpressureStrategy
Expand All @@ -42,6 +47,7 @@ class MultiSelectEpisodesHelper @Inject constructor(
val podcastManager: PodcastManager,
val playbackManager: PlaybackManager,
val downloadManager: DownloadManager,
val analyticsTracker: AnalyticsTrackerWrapper,
val settings: Settings,
private val episodeAnalytics: EpisodeAnalytics
) : MultiSelectHelper<BaseEpisode>() {
Expand Down Expand Up @@ -77,6 +83,10 @@ class MultiSelectEpisodesHelper @Inject constructor(
delete(resources, fragmentManager)
true
}
R.id.menu_share -> {
share(fragmentManager)
true
}
R.id.menu_download -> {
download(resources, fragmentManager)
true
Expand Down Expand Up @@ -381,6 +391,42 @@ class MultiSelectEpisodesHelper @Inject constructor(
CloudDeleteHelper.getDeleteDialog(episodes, deleteState, deleteFunction, resources).show(fragmentManager, "delete_warning")
}

fun share(fragmentManager: FragmentManager) {

val episode = selectedList.let { list ->
if (list.size != 1) {
LogBuffer.e(LogBuffer.TAG_INVALID_STATE, "Can only share one episode, but trying to share ${selectedList.size} episodes when multi selecting")
return
} else {
list.first()
}
}

if (episode !is PodcastEpisode) {
LogBuffer.e(LogBuffer.TAG_INVALID_STATE, "Can only share a ${PodcastEpisode::class.java.simpleName}")
Toast.makeText(context, LR.string.podcasts_share_failed, Toast.LENGTH_SHORT).show()
return
}

launch {
val podcast = podcastManager.findPodcastByUuidSuspend(episode.podcastUuid) ?: run {
LogBuffer.e(LogBuffer.TAG_INVALID_STATE, "Share failed because unable to find podcast from uuid")
return@launch
}

ShareDialog(
episode = episode,
podcast = podcast,
fragmentManager = fragmentManager,
context = context,
shouldShowPodcast = false,
analyticsTracker = analyticsTracker,
).show(sourceView = SourceView.MULTI_SELECT)
}

closeMultiSelect()
}

fun removeFromUpNext(resources: Resources) {
val list = selectedList.toList()
launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
android:icon="@drawable/ic_delete"
android:title="@string/delete"
app:showAsAction="always" />
<item android:id="@+id/menu_share"
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="always" />
<item android:id="@+id/menu_mark_played"
android:icon="@drawable/ic_markasplayed"
android:title="@string/mark_as_played"
Expand All @@ -39,4 +43,4 @@
<item android:id="@+id/menu_unselect_all"
android:title="@string/select_none"
app:showAsAction="never" />
</menu>
</menu>

0 comments on commit a569c20

Please sign in to comment.