Skip to content

Commit

Permalink
Add the Discover List share button tapped event
Browse files Browse the repository at this point in the history
  • Loading branch information
danielebogo committed Jan 23, 2025
1 parent 7c8efd9 commit 10ce341
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions podcasts/Analytics/AnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ enum AnalyticsEvent: String {
case discoverListEpisodePlay
case discoverListPodcastTapped
case discoverListPodcastSubscribed
case discoverListShareTapped

case discoverFeaturedPageChanged
case discoverSmallListPageChanged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extension DiscoverCollectionViewController: DiscoverDelegate {
collectionListVC.cellStyle = (item.expandedStyle == "descriptive_list") ? CollectionCellStyle.descriptive_list : CollectionCellStyle.grid
navController()?.pushViewController(collectionListVC, animated: true)
} else { // item == expandedStylw == "plain_list" || item.expandedStyle == "ranked_list"
let listView = PodcastHeaderListViewController(podcasts: podcasts)
let listView = PodcastHeaderListViewController(podcasts: podcasts, source: item.source)
listView.title = replaceRegionName(string: item.title?.localized ?? "")
listView.showFeaturedCell = item.expandedStyle == "ranked_list"
listView.showRankingNumber = item.expandedStyle == "ranked_list"
Expand Down
2 changes: 1 addition & 1 deletion podcasts/DiscoverViewController+DiscoverDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension DiscoverViewController: DiscoverDelegate {
collectionListVC.cellStyle = (item.expandedStyle == "descriptive_list") ? CollectionCellStyle.descriptive_list : CollectionCellStyle.grid
navController()?.pushViewController(collectionListVC, animated: true)
} else { // item == expandedStylw == "plain_list" || item.expandedStyle == "ranked_list"
let listView = PodcastHeaderListViewController(podcasts: podcasts)
let listView = PodcastHeaderListViewController(podcasts: podcasts, source: item.source)
listView.title = replaceRegionName(string: item.title?.localized ?? "")
listView.showFeaturedCell = item.expandedStyle == "ranked_list"
listView.showRankingNumber = item.expandedStyle == "ranked_list"
Expand Down
11 changes: 11 additions & 0 deletions podcasts/ExpandedCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class ExpandedCollectionViewController: PCViewController, CollectionHeaderLinkDe
title = item.title?.localized.localizedCapitalized
}

if item.source != nil {
customRightBtn = UIBarButtonItem(image: UIImage(named: "podcast-share"), style: .plain, target: self, action: #selector(handleShare))
}

insetAdjuster.setupInsetAdjustmentsForMiniPlayer(scrollView: collectionView)
}

Expand Down Expand Up @@ -104,4 +108,11 @@ class ExpandedCollectionViewController: PCViewController, CollectionHeaderLinkDe
override var preferredStatusBarStyle: UIStatusBarStyle {
AppTheme.defaultStatusBarStyle()
}

@objc func handleShare() {
guard let source = item.source, let url = URL(string: source)?.deletingPathExtension() else { return }
Analytics.track(.discoverListShareTapped)
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
present(activityViewController, animated: true)
}
}
17 changes: 16 additions & 1 deletion podcasts/PodcastHeaderListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ class PodcastHeaderListViewController: PCViewController, UITableViewDataSource,
private weak var delegate: DiscoverDelegate?
private static let cellId = "DiscoverCell"
private static let featuredCellId = "FeaturedTableViewCell"
private var source: URL?

init(podcasts: [DiscoverPodcast]) {
init(podcasts: [DiscoverPodcast], source: String?) {
self.podcasts = podcasts
if let source {
self.source = URL(string: source)
}

super.init(nibName: "PodcastHeaderListViewController", bundle: nil)
}
Expand All @@ -31,6 +35,10 @@ class PodcastHeaderListViewController: PCViewController, UITableViewDataSource,
chartsTable.register(UINib(nibName: "DiscoverPodcastTableCell", bundle: nil), forCellReuseIdentifier: PodcastHeaderListViewController.cellId)
chartsTable.register(UINib(nibName: "FeaturedTableViewCell", bundle: nil), forCellReuseIdentifier: PodcastHeaderListViewController.featuredCellId)

if source != nil {
customRightBtn = UIBarButtonItem(image: UIImage(named: "podcast-share"), style: .plain, target: self, action: #selector(handleShare))
}

insetAdjuster.setupInsetAdjustmentsForMiniPlayer(scrollView: chartsTable)

chartsTable.updateContentInset(multiSelectEnabled: false)
Expand All @@ -42,6 +50,13 @@ class PodcastHeaderListViewController: PCViewController, UITableViewDataSource,
chartsTable.reloadData()
}

@objc private func handleShare() {
guard let source = source?.deletingPathExtension() else { return }
Analytics.track(.discoverListShareTapped)
let activityViewController = UIActivityViewController(activityItems: [source], applicationActivities: nil)
present(activityViewController, animated: true)
}

// MARK: - UITableView Methods

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
Expand Down

0 comments on commit 10ce341

Please sign in to comment.