Skip to content

Commit

Permalink
Track deletion of bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mchowning committed Aug 17, 2023
1 parent a4f2206 commit 0536709
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class BookmarksFragment : BaseFragment() {
click = {
BookmarksSortByDialog(
settings = settings,
changeSortOrder = { bookmarksViewModel.changeSortOrder(it, sourceView) },
changeSortOrder = bookmarksViewModel::changeSortOrder,
sourceView = SourceView.PLAYER,
forceDarkTheme = true,
).show(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class BookmarksViewModel
val showOptionsDialog = _showOptionsDialog.asSharedFlow()

private var sourceView: SourceView = SourceView.UNKNOWN
set(value) {
field = value
multiSelectHelper.source = value
}

@OptIn(ExperimentalCoroutinesApi::class)
fun loadBookmarks(
Expand Down Expand Up @@ -189,7 +193,7 @@ class BookmarksViewModel
}
}

fun changeSortOrder(order: BookmarksSortType, sourceView: SourceView) {
fun changeSortOrder(order: BookmarksSortType) {
if (order !is BookmarksSortTypeForPlayer) return
settings.setBookmarksSortType(order)
analyticsTracker.track(
Expand All @@ -208,7 +212,7 @@ class BookmarksViewModel
val shouldPlayEpisode = !playbackManager.isPlaying() ||
playbackManager.getCurrentEpisode()?.uuid != bookmarkEpisode.uuid
if (shouldPlayEpisode) {
playbackManager.playNow(it, sourceView = SourceView.PODCAST_LIST)
playbackManager.playNow(it, sourceView = sourceView)
}
}
playbackManager.seekToTimeMs(positionMs = bookmark.timeSecs * 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import au.com.shiftyjelly.pocketcasts.models.type.EpisodePlayingStatus
import au.com.shiftyjelly.pocketcasts.models.type.EpisodeStatusEnum
import au.com.shiftyjelly.pocketcasts.models.type.EpisodeViewSource
import au.com.shiftyjelly.pocketcasts.podcasts.databinding.FragmentEpisodeBinding
import au.com.shiftyjelly.pocketcasts.podcasts.viewmodel.PodcastAndEpisodeDetailsCoordinator
import au.com.shiftyjelly.pocketcasts.preferences.Settings
import au.com.shiftyjelly.pocketcasts.repositories.images.PodcastImageLoader
import au.com.shiftyjelly.pocketcasts.repositories.images.into
Expand Down Expand Up @@ -103,6 +104,7 @@ class EpisodeFragment : BaseFragment() {
@Inject lateinit var settings: Settings
@Inject lateinit var warningsHelper: WarningsHelper
@Inject lateinit var analyticsTracker: AnalyticsTrackerWrapper
@Inject lateinit var podcastAndEpisodeDetailsCoordinator: PodcastAndEpisodeDetailsCoordinator

private val viewModel: EpisodeFragmentViewModel by viewModels()
private var binding: FragmentEpisodeBinding? = null
Expand Down Expand Up @@ -185,6 +187,7 @@ class EpisodeFragment : BaseFragment() {
super.onDestroyView()
if (!viewModel.isFragmentChangingConfigurations) {
analyticsTracker.track(AnalyticsEvent.EPISODE_DETAIL_DISMISSED, mapOf(AnalyticsProp.Key.SOURCE to episodeViewSource.value))
podcastAndEpisodeDetailsCoordinator.onEpisodeDetailsDismissed()
}
webView.cleanup()
webView = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package au.com.shiftyjelly.pocketcasts.podcasts.viewmodel

import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class PodcastAndEpisodeDetailsCoordinator @Inject constructor() {
lateinit var onEpisodeDetailsDismissed: () -> Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class PodcastViewModel
private val bookmarkSearchHandler: BookmarkSearchHandler,
private val multiSelectEpisodesHelper: MultiSelectEpisodesHelper,
private val multiSelectBookmarksHelper: MultiSelectBookmarksHelper,
private val settings: Settings
private val settings: Settings,
private val podcastAndEpisodeDetailsCoordinator: PodcastAndEpisodeDetailsCoordinator,
) : ViewModel(), CoroutineScope {

private val disposables = CompositeDisposable()
Expand All @@ -105,9 +106,14 @@ class PodcastViewModel
override val coroutineContext: CoroutineContext
get() = Dispatchers.Default

init {
podcastAndEpisodeDetailsCoordinator.onEpisodeDetailsDismissed = {
multiSelectBookmarksHelper.source = SourceView.PODCAST_SCREEN
}
}

fun loadPodcast(uuid: String, resources: Resources) {
viewModelScope.launch {

this@PodcastViewModel.podcastUuid = uuid
val episodeSearchResults = episodeSearchHandler.getSearchResultsObservable(uuid)
val bookmarkSearchResults = bookmarkSearchHandler.getSearchResultsObservable(uuid)
Expand Down Expand Up @@ -397,7 +403,7 @@ class PodcastViewModel
val shouldPlayEpisode = !playbackManager.isPlaying() ||
playbackManager.getCurrentEpisode()?.uuid != bookmarkEpisode.uuid
if (shouldPlayEpisode) {
playbackManager.playNow(it, sourceView = SourceView.PODCAST_LIST)
playbackManager.playNow(it, sourceView = SourceView.PODCAST_SCREEN)
}
}
playbackManager.seekToTimeMs(bookmark.timeSecs * 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum class AnalyticsEvent(val key: String) {
BOOKMARKS_EMPTY_GO_TO_HEADPHONE_SETTINGS("bookmarks_empty_go_to_headphone_settings"),
BOOKMARK_PLAY_TAPPED("bookmark_play_tapped"),
BOOKMARKS_SORT_BY_CHANGED("bookmarks_sort_by_changed"),
BOOKMARK_DELETED("bookmark_deleted"),

/* User lifecycle events */
USER_SIGNED_IN("user_signed_in"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.res.Resources
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LiveData
import androidx.lifecycle.map
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTrackerWrapper
import au.com.shiftyjelly.pocketcasts.localization.extensions.getStringPlural
import au.com.shiftyjelly.pocketcasts.models.entity.Bookmark
import au.com.shiftyjelly.pocketcasts.repositories.bookmark.BookmarkManager
Expand All @@ -22,6 +24,7 @@ import au.com.shiftyjelly.pocketcasts.ui.R as UR
@Singleton
class MultiSelectBookmarksHelper @Inject constructor(
private val bookmarkManager: BookmarkManager,
private val analyticsTracker: AnalyticsTrackerWrapper,
) : MultiSelectHelper<Bookmark>() {
override val maxToolbarIcons = 2

Expand Down Expand Up @@ -118,6 +121,10 @@ class MultiSelectBookmarksHelper @Inject constructor(
launch {
bookmarks.forEach {
bookmarkManager.deleteToSync(it.uuid)
analyticsTracker.track(
AnalyticsEvent.BOOKMARK_DELETED,
mapOf("source" to source.analyticsValue)
)
}

withContext(Dispatchers.Main) {
Expand Down

0 comments on commit 0536709

Please sign in to comment.