Skip to content

Commit

Permalink
Bugfix 477 timer shows goal name (#481)
Browse files Browse the repository at this point in the history
fixes #477 by displaying the name (_"slug"_) of the goal on the timer
view controller
  • Loading branch information
krugerk authored Oct 3, 2024
1 parent 670d46b commit 4c4beb7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fastlane-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ concurrency:

jobs:
build:
runs-on: macos-14
runs-on: macos-15

steps:
- uses: maxim-lobanov/setup-xcode@v1
Expand Down
4 changes: 1 addition & 3 deletions BeeSwift/GoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
Expand Down
27 changes: 14 additions & 13 deletions BeeSwift/TimerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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: {
Expand Down
14 changes: 12 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c4beb7

Please sign in to comment.