Skip to content

Commit

Permalink
Tracks Audit: Add events for podcast screen selection (#3415)
Browse files Browse the repository at this point in the history
  • Loading branch information
mebarbosa authored Jan 9, 2025
1 parent 052dafd commit e13fa83
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ enum class AnalyticsEvent(val key: String) {
SETTINGS_AUTO_DOWNLOAD_STOP_ALL_DOWNLOADS("settings_auto_download_stop_all_downloads"),
SETTINGS_AUTO_DOWNLOAD_CLEAR_DOWNLOAD_ERRORS("settings_auto_download_clear_download_errors"),

/* Settings - Select Podcasts */
SETTINGS_SELECT_PODCASTS_SHOWN("settings_select_podcasts_shown"),
SETTINGS_SELECT_PODCASTS_SELECT_ALL_TAPPED("settings_select_podcasts_select_all_tapped"),
SETTINGS_SELECT_PODCASTS_SELECT_NONE_TAPPED("settings_select_podcasts_select_none_tapped"),
SETTINGS_SELECT_PODCASTS_PODCAST_TOGGLED("settings_select_podcasts_podcast_toggled"),

/* Settings - Files */
SETTINGS_FILES_SHOWN("settings_files_shown"),
SETTINGS_FILES_AUTO_ADD_UP_NEXT_TOGGLED("settings_files_auto_add_up_next_toggled"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class PodcastSelectFragment : BaseFragment() {

source = args.source

analyticsTracker.track(AnalyticsEvent.SETTINGS_SELECT_PODCASTS_SHOWN, source.toEventProperty())

val imageRequestFactory = PocketCastsImageRequestFactory(requireContext()).themed()
binding.toolbarLayout.isVisible = args.showToolbar
if (binding.toolbarLayout.isVisible) {
Expand All @@ -127,13 +129,21 @@ class PodcastSelectFragment : BaseFragment() {
.subscribeBy(
onError = { Timber.e(it) },
onSuccess = {
val adapter = PodcastSelectAdapter(it, args.tintColor, imageRequestFactory) {
val selectedList = it.map { it.uuid }
binding.lblPodcastsChosen.text =
resources.getStringPluralPodcastsSelected(selectedList.size)
listener.podcastSelectFragmentSelectionChanged(selectedList)
userChanged = true
}
val adapter = PodcastSelectAdapter(
it,
args.tintColor,
imageRequestFactory,
onPodcastToggled = { podcastUuid, enabled ->
analyticsTracker.track(AnalyticsEvent.SETTINGS_SELECT_PODCASTS_PODCAST_TOGGLED, source.toEventProperty() + mapOf("uuid" to podcastUuid, "enabled" to enabled))
},
onSelectionChanged = {
val selectedList = it.map { it.uuid }
binding.lblPodcastsChosen.text =
resources.getStringPluralPodcastsSelected(selectedList.size)
listener.podcastSelectFragmentSelectionChanged(selectedList)
userChanged = true
},
)

val selected = it.filter { it.selected }
binding.lblPodcastsChosen.text =
Expand All @@ -144,8 +154,10 @@ class PodcastSelectFragment : BaseFragment() {
updateSelectButtonText(adapter.selectedPodcasts.size, adapter.list.size)
binding.btnSelect.setOnClickListener {
if (adapter.selectedPodcasts.size == adapter.list.size) { // Everything is selected
analyticsTracker.track(AnalyticsEvent.SETTINGS_SELECT_PODCASTS_SELECT_NONE_TAPPED, source.toEventProperty())
adapter.deselectAll()
} else {
analyticsTracker.track(AnalyticsEvent.SETTINGS_SELECT_PODCASTS_SELECT_ALL_TAPPED, source.toEventProperty())
adapter.selectAll()
}

Expand Down Expand Up @@ -220,7 +232,7 @@ class PodcastSelectFragment : BaseFragment() {
}

private data class SelectablePodcast(val podcast: Podcast, var selected: Boolean)
private class PodcastSelectAdapter(val list: List<SelectablePodcast>, @ColorInt val tintColor: Int?, imageRequestFactory: PocketCastsImageRequestFactory, val onSelectionChanged: (selected: List<Podcast>) -> Unit) : RecyclerView.Adapter<PodcastSelectAdapter.PodcastViewHolder>() {
private class PodcastSelectAdapter(val list: List<SelectablePodcast>, @ColorInt val tintColor: Int?, imageRequestFactory: PocketCastsImageRequestFactory, val onPodcastToggled: (uuid: String, enabled: Boolean) -> Unit, val onSelectionChanged: (selected: List<Podcast>) -> Unit) : RecyclerView.Adapter<PodcastSelectAdapter.PodcastViewHolder>() {
val imageRequestFactory = imageRequestFactory.smallSize()

class PodcastViewHolder(val binding: SettingsRowPodcastBinding) : RecyclerView.ViewHolder(binding.root)
Expand Down Expand Up @@ -251,6 +263,7 @@ private class PodcastSelectAdapter(val list: List<SelectablePodcast>, @ColorInt
}
holder.binding.checkbox.setOnCheckedChangeListener { _, isChecked ->
item.selected = isChecked
onPodcastToggled(item.podcast.uuid, isChecked)
onSelectionChanged(selectedPodcasts)
}

Expand All @@ -277,6 +290,10 @@ private class PodcastSelectAdapter(val list: List<SelectablePodcast>, @ColorInt
}
}

private fun PodcastSelectFragmentSource?.toEventProperty(): Map<String, String> {
return this?.name?.let { mapOf("source" to it.lowercase()) } ?: emptyMap()
}

@Parcelize
private data class PodcastSelectFragmentArgs(
val tintColor: Int?,
Expand Down

0 comments on commit e13fa83

Please sign in to comment.