Skip to content
Open
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
51 changes: 0 additions & 51 deletions BeeSwift/Gallery/ChooseGoalSortViewController.swift

This file was deleted.

32 changes: 26 additions & 6 deletions BeeSwift/Gallery/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class GalleryViewController: UIViewController {
)
self.view.addSubview(self.stackView)
stackView.snp.makeConstraints { (make) -> Void in make.edges.equalToSuperview() }

NotificationCenter.default.addObserver(
self,
selector: #selector(self.keyboardWillShow),
Expand All @@ -158,7 +157,6 @@ class GalleryViewController: UIViewController {
name: UIResponder.keyboardWillHideNotification,
object: nil
)

configureDataSource()
self.view.backgroundColor = .systemBackground
self.title = "Goals"
Expand All @@ -171,7 +169,13 @@ class GalleryViewController: UIViewController {
style: UIBarButtonItem.Style.plain,
target: self,
action: #selector(self.settingsButtonPressed)
)
),
UIBarButtonItem(
image: UIImage(systemName: "text.line.magnify"),
style: UIBarButtonItem.Style.plain,
target: self,
action: #selector(self.pickSortTapped)
),
]
stackView.addArrangedSubview(self.freshnessIndicator)
self.updateLastUpdatedLabel()
Expand Down Expand Up @@ -273,7 +277,6 @@ class GalleryViewController: UIViewController {
let lastUpdated = currentUserManager.user(context: viewContext)?.lastUpdatedLocal ?? .distantPast
self.freshnessIndicator.update(with: lastUpdated)
}

func setupHealthKit() {
Task { @MainActor in
do { try await healthStoreManager.ensureGoalsUpdateRegularly() } catch {
Expand Down Expand Up @@ -333,7 +336,6 @@ class GalleryViewController: UIViewController {
)
self.navigationItem.leftBarButtonItem = searchItem
}

private func updateEmptyStateBackground() {
guard self.filteredGoals.isEmpty else {
self.collectionView.backgroundView = nil
Expand Down Expand Up @@ -418,7 +420,6 @@ class GalleryViewController: UIViewController {
}
)
}

private func configureDataSource() {
let cellRegistration = UICollectionView.CellRegistration<GoalCollectionViewCell, NSManagedObjectID> {
[weak self] cell, indexPath, goalObjectId in
Expand Down Expand Up @@ -453,6 +454,25 @@ extension GalleryViewController: SFSafariViewControllerDelegate {
controller.dismiss(animated: true, completion: nil)
self.fetchGoals()
}
@objc private func pickSortTapped() {
let alert = UIAlertController(title: "Gallery Sort Method", message: nil, preferredStyle: .actionSheet)
Constants.goalSortOptions.forEach { sortOption in
let isSelectedAlready =
UserDefaults.standard.value(forKey: Constants.selectedGoalSortKey) as? String == sortOption
let title = isSelectedAlready ? "--> " + sortOption : "" + sortOption
let action = UIAlertAction(title: title, style: .default) { [weak self] _ in
UserDefaults.standard.set(sortOption, forKey: Constants.selectedGoalSortKey)
UserDefaults.standard.synchronize()
Task {
self?.fetchedResultsController.fetchRequest.sortDescriptors = Self.preferredSort
try? self?.fetchedResultsController.performFetch()
}
}
alert.addAction(action)
}
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}

extension GalleryViewController: UISearchBarDelegate {
Expand Down
4 changes: 0 additions & 4 deletions BeeSwift/MainCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ class MainCoordinator {
controller.modalPresentationStyle = .fullScreen
navigationController.present(controller, animated: true, completion: nil)
}
func showChooseGallerySortAlgorithm() {
let controller = ChooseGoalSortViewController()
navigationController.pushViewController(controller, animated: true)
}
func showConfigureNotifications() {
let controller = ConfigureNotificationsViewController(
goalManager: goalManager,
Expand Down
17 changes: 5 additions & 12 deletions BeeSwift/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class SettingsViewController: UIViewController {
Task { @MainActor [weak self] in
self?.tableView.isUserInteractionEnabled = false
try? await self?.goalManager.refreshGoals()

self?.tableView.reloadData()
self?.tableView.layoutIfNeeded()
self?.tableView.refreshControl?.endRefreshing()
Expand Down Expand Up @@ -137,25 +136,20 @@ extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
cell.isUserInteractionEnabled = HKHealthStore.isHealthDataAvailable()
return cell
case 1:
let selectedGoalSort = UserDefaults.standard.value(forKey: Constants.selectedGoalSortKey) as? String
cell.title = "Sort goals by: \(selectedGoalSort ?? "")"
cell.imageName = "arrow.up.arrow.down"
cell.accessoryType = .disclosureIndicator
case 2:
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
DispatchQueue.main.async {
cell.title = "Emergency notifications: \(settings.authorizationStatus == .authorized ? "on" : "off")"
}
}
cell.imageName = "app.badge"
cell.accessoryType = .disclosureIndicator
case 3:
case 2:
let user = currentUserManager.user(context: viewContext)
let timezone = user?.timezone ?? "Unknown"
cell.title = "Time zone: \(timezone)"
cell.imageName = "clock"
cell.accessoryType = .none
case 4:
case 3:
cell.title = "Sign out"
cell.imageName = "rectangle.portrait.and.arrow.right"
cell.accessoryType = .none
Expand All @@ -166,10 +160,9 @@ extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.section {
case 0 where HKHealthStore.isHealthDataAvailable(): coordinator?.showConfigureHealthKitIntegration()
case 1: coordinator?.showChooseGallerySortAlgorithm()
case 2: coordinator?.showConfigureNotifications()
case 3: print("nothing")
case 4: self.signOutButtonPressed()
case 1: coordinator?.showConfigureNotifications()
case 2: print("nothing")
case 3: self.signOutButtonPressed()
default: break
}
}
Expand Down
Loading