Skip to content

Commit

Permalink
Add "Change Avatar" button to account settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pinarol committed May 17, 2024
1 parent b14d535 commit eec048c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
20 changes: 20 additions & 0 deletions podcasts/AccountViewController+TableView.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import PocketCastsDataModel
import SafariServices
import PocketCastsServer
import UIKit

extension AccountViewController: UITableViewDataSource, UITableViewDelegate {

private var changeAvatarURL: URL? {
// TODO: Update when the URL is determined
URL(string: "https://gravatar.com/embed/?email=\(headerViewModel.profile.email ?? "")&features=avatars")
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard section == 0 else {
return UITableView.automaticDimension
Expand Down Expand Up @@ -82,6 +89,14 @@ extension AccountViewController: UITableViewDataSource, UITableViewDelegate {
}
cell.showsDisclosureIndicator = true
return cell
case .changeAvatar:
let cell = tableView.dequeueReusableCell(withIdentifier: AccountViewController.actionCellId, for: indexPath) as! AccountActionCell
cell.cellLabel.text = L10n.settingsChangeAvatar
cell.cellImage.image = UIImage(named: "settings-avatar")?.withRenderingMode(.alwaysTemplate)
cell.iconStyle = .primaryInteractive01
cell.counterView.isHidden = true
cell.showsDisclosureIndicator = false
return cell
case .changeEmail:
let cell = tableView.dequeueReusableCell(withIdentifier: AccountViewController.actionCellId, for: indexPath) as! AccountActionCell
cell.cellLabel.text = L10n.accountChangeEmail
Expand Down Expand Up @@ -172,6 +187,11 @@ extension AccountViewController: UITableViewDataSource, UITableViewDelegate {
case .supporterContributions:
let supporterVC = SupporterContributionsViewController()
navigationController?.pushViewController(supporterVC, animated: true)
case .changeAvatar:
guard let changeAvatarURL else { return }
let safariViewController = SFSafariViewController(url: changeAvatarURL)
safariViewController.modalPresentationStyle = .automatic
present(safariViewController, animated: true)
case .changeEmail:
let changeEmailVC = ChangeEmailViewController()
changeEmailVC.delegate = self
Expand Down
6 changes: 4 additions & 2 deletions podcasts/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PocketCastsUtils
import UIKit

class AccountViewController: UIViewController, ChangeEmailDelegate {
enum TableRow { case upgradeView, changeEmail, changePassword, upgradeAccount, newsletter, cancelSubscription, logout, deleteAccount, privacyPolicy, termsOfUse, supporterContributions }
enum TableRow { case upgradeView, changeAvatar, changeEmail, changePassword, upgradeAccount, newsletter, cancelSubscription, logout, deleteAccount, privacyPolicy, termsOfUse, supporterContributions }
var tableData: [[TableRow]] = [[.changeEmail, .changePassword, .newsletter], [.privacyPolicy, .termsOfUse], [.logout], [.deleteAccount]]

static let newsletterCellId = "NewsletterCellId"
Expand Down Expand Up @@ -106,7 +106,9 @@ class AccountViewController: UIViewController, ChangeEmailDelegate {
} else {
accountOptions = [upgradeRow, .newsletter].compactMap { $0 }
}

if headerViewModel.profile.isLoggedIn {
accountOptions.insert(.changeAvatar, safelyAt: 0)
}
if SubscriptionHelper.hasActiveSubscription() {
var newTableRows: [[TableRow]] = [accountOptions, [.privacyPolicy, .termsOfUse], [.logout], [.deleteAccount]]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "profile-change-avatar.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions podcasts/Strings+Generated.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions podcasts/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,9 @@
/* Fun informational message about the skip options available in the settings. */
"settings_skip_msg" = "Skip intro and outro music like the power user you were born to be.";

/* Title for the button that open a page to change the avatar(a.k.a. profile picture). */
"settings_change_avatar" = "Change Avatar";

/* A common string used throughout the app. Refers to the Stats settings menu */
"settings_stats" = "Stats";

Expand Down

0 comments on commit eec048c

Please sign in to comment.