Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/code cleanup #955

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extension UIViewController {
navigationItem.standardAppearance = navigationBarAppearance
navigationItem.scrollEdgeAppearance = navigationItem.standardAppearance
}

func setDefaultAppearanceNavigationBar(with barTintColor: UIColor) {
// It is recommended by apple to set the appearance for the navigation
// item when configuring the navigation appearance of a specific view controller
Expand Down
10 changes: 5 additions & 5 deletions UpcomingMovies/Helpers/Protocols/Models/UserProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ protocol UserProtocol: ImageConfigurable {
}

struct UserModel: UserProtocol {

let id: Int
let name: String
let username: String
let includeAdult: Bool

private let avatarPath: String?

var avatarImageURL: URL? {
guard let avatarPath, let avatarImageBaseURLString else { return nil }
let urlString = avatarImageBaseURLString.appending(avatarPath)
return URL(string: urlString)
}

init(_ user: User) {
self.id = user.id
self.name = user.name
self.username = user.username
self.includeAdult = user.includeAdult
self.avatarPath = user.avatarPath
}

func hasUpdatedInfo(_ newUserInfo: UserProtocol) -> Bool {
self.id != newUserInfo.id ||
self.name != newUserInfo.name ||
Expand Down
3 changes: 3 additions & 0 deletions UpcomingMovies/Scenes/Account/Profile/ProfileProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ protocol ProfileViewModelProtocol {
var didUpdateAuthenticationState: AnyBehaviorBindable<AuthenticationState?> { get }
var didReceiveError: AnyPublishBindable<Void> { get }

var signOutTitle: String? { get }
var signOutConfirmationTitle: String? { get }

func section(at index: Int) -> ProfileSection
func numberOfSections() -> Int
func numberOfRows(for section: Int) -> Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ final class ProfileViewController: UITableViewController, Storyboarded {
}

private func showSignOutActionSheet() {
let signOutAction = UIAlertAction(title: LocalizedStrings.signOut(),
let signOutAction = UIAlertAction(title: viewModel?.signOutTitle,
style: .destructive) { _ in
self.viewModel?.signOutCurrentUser()
}
showSimpleActionSheet(title: LocalizedStrings.signOutConfirmationTitle(),
showSimpleActionSheet(title: viewModel?.signOutConfirmationTitle,
message: nil, action: signOutAction)
}

Expand Down
8 changes: 8 additions & 0 deletions UpcomingMovies/Scenes/Account/Profile/ProfileViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
ProfileAccountInfoCellViewModel(userAccount: userAccount)
}

var signOutTitle: String? {
LocalizedStrings.signOut()

Check warning on line 30 in UpcomingMovies/Scenes/Account/Profile/ProfileViewModel.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Account/Profile/ProfileViewModel.swift#L29-L30

Added lines #L29 - L30 were not covered by tests
}

var signOutConfirmationTitle: String? {
LocalizedStrings.signOutConfirmationTitle()

Check warning on line 34 in UpcomingMovies/Scenes/Account/Profile/ProfileViewModel.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Account/Profile/ProfileViewModel.swift#L33-L34

Added lines #L33 - L34 were not covered by tests
}

// MARK: - Initializers

init(userAccount: UserProtocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ final class MockProfileViewModel: ProfileViewModelProtocol {
var didUpdateAuthenticationState = BehaviorBindable<AuthenticationState?>(nil).eraseToAnyBindable()
var didReceiveError = PublishBindable<Void>().eraseToAnyBindable()

var signOutTitle: String? = "Sign out"
var signOutConfirmationTitle: String? = "Sign Out Confirmation"

var sectionAtIndexResult: ProfileSection = .accountInfo
private(set) var sectionAtIndexCallCount = 0
func section(at index: Int) -> ProfileSection {
Expand Down
Loading