Skip to content

Commit

Permalink
Merge branch 'main' into T384746
Browse files Browse the repository at this point in the history
  • Loading branch information
l-olson1214 authored Jan 28, 2025
2 parents 479c46b + b9c45ed commit 8336fb8
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 22 deletions.
21 changes: 1 addition & 20 deletions Wikipedia/Code/ArticleFetchedResultsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,12 @@ class ArticleFetchedResultsViewController: ArticleCollectionViewController, Coll
var deleteAllConfirmationText: String? = nil
var deleteAllCancelText: String? = nil
var deleteAllText: String? = nil
var isDeleteAllVisible: Bool = false

open func deleteAll() {

}

fileprivate final func updateDeleteButton() {
guard isDeleteAllVisible else {
navigationItem.rightBarButtonItem = nil
return
}

if navigationItem.rightBarButtonItem == nil {
navigationItem.rightBarButtonItem = UIBarButtonItem(title: deleteAllButtonText, style: .plain, target: self, action: #selector(deleteButtonPressed(_:)))
}

navigationItem.rightBarButtonItem?.isEnabled = !isEmpty
}

@objc fileprivate final func deleteButtonPressed(_ sender: UIBarButtonItem) {
@objc final func deleteButtonPressed(_ sender: UIBarButtonItem) {
let alertController = UIAlertController(title: deleteAllConfirmationText, message: nil, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: deleteAllText, style: .destructive, handler: { (action) in
self.deleteAll()
Expand All @@ -91,11 +77,6 @@ class ArticleFetchedResultsViewController: ArticleCollectionViewController, Coll
func collectionViewUpdater<T: NSFetchRequestResult>(_ updater: CollectionViewUpdater<T>, updateItemAtIndexPath indexPath: IndexPath, in collectionView: UICollectionView) {

}

override func isEmptyDidChange() {
super.isEmptyDidChange()
updateDeleteButton()
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
Expand Down
104 changes: 102 additions & 2 deletions Wikipedia/Code/HistoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,48 @@ class HistoryViewController: ArticleFetchedResultsViewController, WMFNavigationB

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 All @@ -32,7 +74,6 @@ class HistoryViewController: ArticleFetchedResultsViewController, WMFNavigationB
deleteAllConfirmationText = WMFLocalizedString("history-clear-confirmation-heading", value: "Are you sure you want to delete all your recent items?", comment: "Heading text of delete all confirmation dialog")
deleteAllCancelText = WMFLocalizedString("history-clear-cancel", value: "Cancel", comment: "Button text for cancelling delete all action {{Identical|Cancel}}")
deleteAllText = WMFLocalizedString("history-clear-delete-all", value: "Yes, delete all", comment: "Button text for confirming delete all action")
isDeleteAllVisible = true

setupTopSafeAreaOverlay(scrollView: collectionView)
}
Expand Down Expand Up @@ -137,8 +178,45 @@ class HistoryViewController: ArticleFetchedResultsViewController, WMFNavigationB
}

let hideNavigationBarOnScroll = !isEmpty

let deleteButton = UIBarButtonItem(title: deleteAllButtonText, style: .plain, target: self, action: #selector(deleteButtonPressed(_:)))
deleteButton.isEnabled = !isEmpty

let profileButtonConfig: WMFNavigationBarProfileButtonConfig?
if let dataStore {
profileButtonConfig = self.profileButtonConfig(target: self, action: #selector(userDidTapProfile), dataStore: dataStore, yirDataController: yirDataController, leadingBarButtonItem: deleteButton, trailingBarButtonItem: nil)
} 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 {
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 +262,28 @@ class HistoryViewController: ArticleFetchedResultsViewController, WMFNavigationB
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

0 comments on commit 8336fb8

Please sign in to comment.