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

Standardize Headers: History #5169

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
100 changes: 99 additions & 1 deletion Wikipedia/Code/HistoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,48 @@

var topSafeAreaOverlayHeightConstraint: NSLayoutConstraint?
var topSafeAreaOverlayView: UIView?

// Properties needed for Profile Button

private var _yirCoordinator: YearInReviewCoordinator?
var yirCoordinator: YearInReviewCoordinator? {

guard let navigationController,
let yirDataController,
let dataStore else {
return nil
}

guard let existingYirCoordinator = _yirCoordinator else {
_yirCoordinator = YearInReviewCoordinator(navigationController: navigationController, theme: theme, dataStore: dataStore, dataController: yirDataController)
_yirCoordinator?.badgeDelegate = self
return _yirCoordinator
}

return existingYirCoordinator
}

private var _profileCoordinator: ProfileCoordinator?
private var profileCoordinator: ProfileCoordinator? {

guard let navigationController,
let yirCoordinator = self.yirCoordinator,
let dataStore else {
return nil
}

guard let existingProfileCoordinator = _profileCoordinator else {
_profileCoordinator = ProfileCoordinator(navigationController: navigationController, theme: theme, dataStore: dataStore, donateSouce: .savedProfile, logoutDelegate: self, sourcePage: ProfileCoordinatorSource.saved, yirCoordinator: yirCoordinator)
_profileCoordinator?.badgeDelegate = self
return _profileCoordinator
}

return existingProfileCoordinator
}

private var yirDataController: WMFYearInReviewDataController? {
return try? WMFYearInReviewDataController()
}

override var headerStyle: ColumnarCollectionViewController.HeaderStyle {
return .sections
Expand Down Expand Up @@ -137,8 +179,42 @@
}

let hideNavigationBarOnScroll = !isEmpty

let profileButtonConfig: WMFNavigationBarProfileButtonConfig?
if let dataStore {
profileButtonConfig = self.profileButtonConfig(target: self, action: #selector(userDidTapProfile), dataStore: dataStore, yirDataController: yirDataController, leadingBarButtonItem: nil, trailingBarButtonItem: nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code so far looks good - I noticed the Clear button disappeared though, unfortunately. I did a bit of digging and for mysterious reasons of the past that logic is buried in the superclass ArticleFetchedResultsViewController, but only this subclass takes advantage of it (due to it setting isDeleteAllVisible = true).

Can you move the Clear button-related logic out of ArticleFetchedResultsViewController and into HistoryViewController? Then on this line you can hopefully set the leadingBarButtonItem parameter to a clear button lazy property on self.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

Went through a small journey to get to the ultimately few line answer, but really awesome catch! Thanks :)

} else {
profileButtonConfig = nil
}

configureNavigationBar(titleConfig: titleConfig, closeButtonConfig: nil, profileButtonConfig: profileButtonConfig, searchBarConfig: nil, hideNavigationBarOnScroll: hideNavigationBarOnScroll)
}

private func updateProfileButton() {

configureNavigationBar(titleConfig: titleConfig, closeButtonConfig: nil, profileButtonConfig: nil, searchBarConfig: nil, hideNavigationBarOnScroll: hideNavigationBarOnScroll)
guard let dataStore else {
return
}

let config = self.profileButtonConfig(target: self, action: #selector(userDidTapProfile), dataStore: dataStore, yirDataController: yirDataController, leadingBarButtonItem: nil, trailingBarButtonItem: nil)
updateNavigationBarProfileButton(needsBadge: config.needsBadge, needsBadgeLabel: CommonStrings.profileButtonBadgeTitle, noBadgeLabel: CommonStrings.profileButtonTitle)
}

@objc func userDidTapProfile() {

guard let dataStore else {
return
}

guard let languageCode = dataStore.languageLinkController.appLanguage?.languageCode,
let metricsID = DonateCoordinator.metricsID(for: .savedProfile, languageCode: languageCode) else {

Check notice on line 210 in Wikipedia/Code/HistoryViewController.swift

View check run for this annotation

Xcode Cloud / Wikipedia | Run Tests | Test - iOS (Wikipedia)

Wikipedia/Code/HistoryViewController.swift#L210

Immutable value 'metricsID' was never used; consider replacing with '_' or removing it
return
}

// TODO: Do we need logging like this?
// DonateFunnel.shared.logExploreProfile(metricsID: metricsID)

profileCoordinator?.start()
}

func titleForHeaderInSection(_ section: Int) -> String? {
Expand Down Expand Up @@ -184,6 +260,28 @@
override func apply(theme: Theme) {
super.apply(theme: theme)

updateProfileButton()
profileCoordinator?.theme = theme

themeTopSafeAreaOverlay()
}
}

extension HistoryViewController: LogoutCoordinatorDelegate {
func didTapLogout() {

guard let dataStore else {
return
}

wmf_showKeepSavedArticlesOnDevicePanelIfNeeded(triggeredBy: .logout, theme: theme) {
dataStore.authenticationManager.logout(initiatedBy: .user)
}
}
}

extension HistoryViewController: YearInReviewBadgeDelegate {
func updateYIRBadgeVisibility() {
updateProfileButton()
}
}
1 change: 1 addition & 0 deletions Wikipedia/Code/SearchViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit
import WMFComponents
import WMFData

class SearchViewController: ArticleCollectionViewController, WMFNavigationBarConfiguring, WMFNavigationBarHiding {

Expand Down
Loading