Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
align some inconsistencies with providing a goal
to some view controllers that required one
  • Loading branch information
krugerk committed Oct 5, 2024
1 parent 26bf923 commit c02010b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
3 changes: 1 addition & 2 deletions BeeSwift/Gallery/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
}

func openGoal(_ goal: Goal) {
let goalViewController = GoalViewController()
goalViewController.goal = goal
let goalViewController = GoalViewController(goal: goal)
self.navigationController?.pushViewController(goalViewController, animated: true)
}

Expand Down
11 changes: 10 additions & 1 deletion BeeSwift/GoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl

private let logger = Logger(subsystem: "com.beeminder.com", category: "GoalViewController")

var goal : Goal!
let goal: Goal

fileprivate var goalImageView = GoalImageView(isThumbnail: false)
fileprivate var datapointTableController = DatapointTableViewController()
Expand All @@ -40,6 +40,15 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
fileprivate let headerWidth = Double(1.0/3.0)
fileprivate let viewGoalActivityType = "com.beeminder.viewGoal"

init(goal: Goal) {
self.goal = goal
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
self.view.backgroundColor = UIColor.systemBackground
self.title = self.goal.slug
Expand Down
11 changes: 10 additions & 1 deletion BeeSwift/Settings/ChooseHKMetricViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ class ChooseHKMetricViewController: UIViewController {
fileprivate let cellReuseIdentifier = "hkMetricTableViewCell"
fileprivate let headerReusedIdentifier = "hkMetricTableHeader"
fileprivate var tableView = UITableView()
var goal : Goal!
let goal: Goal

init(goal: Goal) {
self.goal = goal
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import BeeKit
class EditGoalNotificationsViewController : EditNotificationsViewController {
private let logger = Logger(subsystem: "com.beeminder.beeminder", category: "EditGoalNotificationsViewController")

var goal : Goal
let goal: Goal
fileprivate var useDefaultsSwitch = UISwitch()

init(goal : Goal) {
Expand Down
6 changes: 2 additions & 4 deletions BeeSwift/Settings/HealthKitConfigViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,10 @@ extension HealthKitConfigViewController: UITableViewDelegate, UITableViewDataSou
let goal = self.goalAt(indexPath)

if !goal.isDataProvidedAutomatically {
let chooseHKMetricViewController = ChooseHKMetricViewController()
chooseHKMetricViewController.goal = goal
let chooseHKMetricViewController = ChooseHKMetricViewController(goal: goal)
self.navigationController?.pushViewController(chooseHKMetricViewController, animated: true)
} else if goal.autodata == "apple" {
let controller = RemoveHKMetricViewController()
controller.goal = goal
let controller = RemoveHKMetricViewController(goal: goal)
self.navigationController?.pushViewController(controller, animated: true)
} else {
let alert: UIAlertController = {
Expand Down
14 changes: 11 additions & 3 deletions BeeSwift/Settings/RemoveHKMetricViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ import BeeKit
class RemoveHKMetricViewController: UIViewController {
private let logger = Logger(subsystem: "com.beeminder.beeminder", category: "RemoveHKMetricViewController")

var goal : Goal!
let goal: Goal

init(goal: Goal) {
self.goal = goal
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -67,14 +76,13 @@ class RemoveHKMetricViewController: UIViewController {
}

@objc func removeButtonPressed() {
guard self.goal != nil else { return }
let params: [String: [String: String?]] = ["ii_params": ["name": nil, "metric": ""]]
let hud = MBProgressHUD.showAdded(to: self.view, animated: true)
hud.mode = .indeterminate

Task { @MainActor in
do {
let _ = try await ServiceLocator.requestManager.put(url: "api/v1/users/{username}/goals/\(self.goal!.slug).json", parameters: params)
let _ = try await ServiceLocator.requestManager.put(url: "api/v1/users/{username}/goals/\(self.goal.slug).json", parameters: params)

try await ServiceLocator.goalManager.refreshGoal(self.goal.objectID)

Expand Down
18 changes: 9 additions & 9 deletions BeeSwift/TimerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import MBProgressHUD
import BeeKit

class TimerViewController: UIViewController {
init(goal: Goal) {
self.goal = goal
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

let timerLabel = BSLabel()
let startStopButton = BSButton(type: .system)
let goal: Goal
Expand All @@ -30,6 +21,15 @@ class TimerViewController: UIViewController {
var units: String?
var accumulatedSeconds = 0

init(goal: Goal) {
self.goal = goal
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .darkGray
Expand Down

0 comments on commit c02010b

Please sign in to comment.