From 4c4beb73850ce164424899aa25507cb206438bc7 Mon Sep 17 00:00:00 2001 From: krugerk <4656811+krugerk@users.noreply.github.com> Date: Thu, 3 Oct 2024 04:46:37 +0200 Subject: [PATCH] Bugfix 477 timer shows goal name (#481) fixes #477 by displaying the name (_"slug"_) of the goal on the timer view controller --- .github/workflows/fastlane-tests.yml | 2 +- BeeSwift/GoalViewController.swift | 4 +--- BeeSwift/TimerViewController.swift | 27 ++++++++++++++------------- fastlane/Fastfile | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.github/workflows/fastlane-tests.yml b/.github/workflows/fastlane-tests.yml index f2eb3ccbf..0ca07fca0 100644 --- a/.github/workflows/fastlane-tests.yml +++ b/.github/workflows/fastlane-tests.yml @@ -9,7 +9,7 @@ concurrency: jobs: build: - runs-on: macos-14 + runs-on: macos-15 steps: - uses: maxim-lobanov/setup-xcode@v1 diff --git a/BeeSwift/GoalViewController.swift b/BeeSwift/GoalViewController.swift index 452ad2a18..4709aac7b 100644 --- a/BeeSwift/GoalViewController.swift +++ b/BeeSwift/GoalViewController.swift @@ -322,9 +322,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl } @objc func timerButtonPressed() { - let controller = TimerViewController() - controller.slug = self.goal.slug - controller.goal = self.goal + let controller = TimerViewController(goal: self.goal) controller.modalPresentationStyle = .fullScreen do { let hoursRegex = try NSRegularExpression(pattern: "(hr|hour)s?") diff --git a/BeeSwift/TimerViewController.swift b/BeeSwift/TimerViewController.swift index 96ef8a93c..50c2920f3 100644 --- a/BeeSwift/TimerViewController.swift +++ b/BeeSwift/TimerViewController.swift @@ -13,13 +13,20 @@ 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() - var goal : Goal? + var goal: Goal var timingSince: Date? var timer: Timer? - var slug: String? var units: String? var accumulatedSeconds = 0 @@ -64,7 +71,7 @@ class TimerViewController: UIViewController { } addDatapointButton.backgroundColor = .clear addDatapointButton.addTarget(self, action: #selector(self.addDatapointButtonPressed), for: .touchUpInside) - addDatapointButton.setTitle("Add Datapoint", for: .normal) + addDatapointButton.setTitle("Add Datapoint to \(self.goal.slug)", for: .normal) let resetButton = BSButton() self.view.addSubview(resetButton) @@ -77,11 +84,6 @@ class TimerViewController: UIViewController { resetButton.setTitle("Reset", for: .normal) resetButton.backgroundColor = .clear } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } @objc func exitButtonPressed() { self.presentingViewController?.dismiss(animated: true, completion: nil) @@ -138,13 +140,13 @@ class TimerViewController: UIViewController { let calendar = Calendar.current let components = (calendar as NSCalendar).components([.hour, .minute], from: now) let currentHour = components.hour - if self.goal!.deadline > 0 && currentHour! < 6 && self.goal!.deadline/3600 < currentHour! { + if self.goal.deadline > 0 && currentHour! < 6 && self.goal.deadline/3600 < currentHour! { offset = -1 } // if the goal's deadline is before midnight and has already passed for this calendar day, default to entering data for the "next" day - if self.goal!.deadline < 0 { - let deadlineSecondsAfterMidnight = 24*3600 + self.goal!.deadline + if self.goal.deadline < 0 { + let deadlineSecondsAfterMidnight = 24*3600 + self.goal.deadline let deadlineHour = deadlineSecondsAfterMidnight/3600 let deadlineMinute = (deadlineSecondsAfterMidnight % 3600)/60 let currentMinute = components.minute @@ -167,14 +169,13 @@ class TimerViewController: UIViewController { } @objc func addDatapointButtonPressed() { - if self.slug == nil { return } let hud = MBProgressHUD.showAdded(to: self.view, animated: true) hud.mode = .indeterminate Task { @MainActor in do { let params = ["urtext": self.urtext(), "requestid": UUID().uuidString] - let _ = try await ServiceLocator.requestManager.post(url: "api/v1/users/{username}/goals/\(self.slug!)/datapoints.json", parameters: params) + let _ = try await ServiceLocator.requestManager.post(url: "api/v1/users/{username}/goals/\(self.goal.slug)/datapoints.json", parameters: params) hud.mode = .text hud.label.text = "Added!" DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: { diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 6f33dbbc9..1652feac4 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -24,15 +24,25 @@ platform :ios do ) end lane :ci do + sh("xcrun simctl list devices") + sleep 1 + sh("xcrun simctl delete all") - sh("xcrun simctl create Test-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-15 com.apple.CoreSimulator.SimRuntime.iOS-17-2") + sleep 5 + + sh("xcrun simctl list devicetypes") + sh("xcrun simctl list runtimes") + + sh("xcrun simctl create Test-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-16-Pro com.apple.CoreSimulator.SimRuntime.iOS-18-0") + sleep 5 + sh("xcrun simctl list devices") + run_tests( scheme: "BeeSwift", reset_simulator: true, include_simulator_logs: true, buildlog_path: "fastlane/test_output", xcodebuild_formatter: "xcpretty", - devices: ["Test-iPhone"], ensure_devices_found: true, ) end