Skip to content

Commit

Permalink
BAL-183-GP-BPM-CONFIGURATION
Browse files Browse the repository at this point in the history
  • Loading branch information
gperissetcelteeka committed Oct 24, 2023
1 parent ea6b6e4 commit ff599b5
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Balance/Balance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ struct Balance: App {
if !userModel.existLocalUser(uid: demoID) {
userModel.createDemoUser()
}
if (UserDefaults.standard.value(forKey: bpmKEY) == nil) {

Check failure on line 59 in Balance/Balance.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
UserDefaults.standard.setValue(defaultBPM, forKey: bpmKEY)
}
})
.onChange(of: scenePhase) { phase in
switch phase {
Expand Down
3 changes: 2 additions & 1 deletion Balance/Chill/ChillCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct ChillCellView: View {
}
}
.padding(EdgeInsets(top: 24, leading: 24, bottom: 24, trailing: 0))
.frame(maxWidth: 311, maxHeight: 114)
.frame(maxWidth: UIScreen.screenWidth - 20)
.frame(height: 120)

Check warning on line 40 in Balance/Chill/ChillCellView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Chill/ChillCellView.swift#L39-L40

Added lines #L39 - L40 were not covered by tests
.foregroundColor(darkBlueColor)
.background(RoundedRectangle(cornerRadius: 20).fill(.white))
.clipped()
Expand Down
3 changes: 2 additions & 1 deletion Balance/Distraction/DistractionCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct DistractionCellView: View {
Spacer()
}
}
.frame(maxWidth: 311, maxHeight: 120)
.frame(maxWidth: UIScreen.screenWidth - 20)
.frame(height: 120)

Check warning on line 29 in Balance/Distraction/DistractionCellView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/DistractionCellView.swift#L28-L29

Added lines #L28 - L29 were not covered by tests
.foregroundColor(darkBlueColor)
.background(RoundedRectangle(cornerRadius: 20).fill(.white))
.clipped()
Expand Down
15 changes: 11 additions & 4 deletions Balance/Distraction/Drawing/DrawView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct DrawingView: UIViewRepresentable {
canvas.maximumZoomScale = 10
canvas.contentSize = CGSize(width: 1000, height: 1000)
canvas.contentInset = UIEdgeInsets(top: 500, left: 500, bottom: 500, right: 500)
canvas.isScrollEnabled = false

Check warning on line 32 in Balance/Distraction/Drawing/DrawView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Drawing/DrawView.swift#L32

Added line #L32 was not covered by tests
return canvas
}

Expand Down Expand Up @@ -64,7 +65,7 @@ struct DrawView: View {
@State var eraserWidth: Double = 99.0
@State var lineWidth: CGFloat = 1.0
@State var showLineWith = false

var body: some View {
ZStack {
Color.white.edgesIgnoringSafeArea(.all)
Expand Down Expand Up @@ -125,7 +126,9 @@ struct DrawView: View {
if self.title.isEmpty {
self.emptyDrawAlert = true
} else {
saveImage()
Task {
await saveImage()
}

Check warning on line 131 in Balance/Distraction/Drawing/DrawView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Drawing/DrawView.swift#L129-L131

Added lines #L129 - L131 were not covered by tests
}
} label: {
Text("Save")
Expand All @@ -143,7 +146,11 @@ struct DrawView: View {
.buttonStyle(ActivityLogButtonStyle(activityDescription: isColoring == true ? "Coloring Draw SAVED" : "Draw SAVED"))
.alert("Enter the title of the drawing", isPresented: $emptyDrawAlert) {
TextField("Title", text: $title)
Button("OK", action: saveImage)
Button("OK") {
Task {
await saveImage()
}
}

Check warning on line 153 in Balance/Distraction/Drawing/DrawView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Drawing/DrawView.swift#L149-L153

Added lines #L149 - L153 were not covered by tests
}
}

Expand Down Expand Up @@ -377,7 +384,7 @@ struct DrawView: View {
}
}

func saveImage() {
func saveImage() async {

Check warning on line 387 in Balance/Distraction/Drawing/DrawView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Drawing/DrawView.swift#L387

Added line #L387 was not covered by tests
let newDraw = Draw(
id: currentDraw.id,
title: title,
Expand Down
8 changes: 4 additions & 4 deletions Balance/Distraction/Drawing/Sketch/Classes/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina6_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -45,7 +45,7 @@
<outlet property="delegate" destination="vXZ-lx-hvc" id="u92-QC-S2R"/>
</connections>
</scrollView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vWS-wj-bz5">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vWS-wj-bz5">
<rect key="frame" x="40" y="786" width="334" height="36"/>
<color key="tintColor" red="0.2666509151" green="0.78627187009999999" blue="0.94962674380000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<state key="normal" title="Button"/>
Expand All @@ -54,7 +54,7 @@
<fragment content="Save">
<attributes>
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
<font key="NSFont" size="18" name="Montserrat-Regular"/>
<font key="NSFont" metaFont="system" size="18"/>
<font key="NSOriginalFont" size="12" name="Helvetica"/>
</attributes>
</fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ class SketchViewController: UIViewController, ButtonViewInterface, UIScrollViewD
alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { [weak alert] (_) in
let textField = alert?.textFields![0]
self.draw?.title = textField!.text!
self.save()
Task {
await self.save()
}

Check warning on line 68 in Balance/Distraction/Drawing/Sketch/Classes/SketchViewController.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Drawing/Sketch/Classes/SketchViewController.swift#L66-L68

Added lines #L66 - L68 were not covered by tests
}))

self.present(alert, animated: true, completion: nil)
} else {
save()
Task {
await save()
}

Check warning on line 75 in Balance/Distraction/Drawing/Sketch/Classes/SketchViewController.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Drawing/Sketch/Classes/SketchViewController.swift#L73-L75

Added lines #L73 - L75 were not covered by tests
}
}

func save() {
func save() async{

Check warning on line 79 in Balance/Distraction/Drawing/Sketch/Classes/SketchViewController.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Drawing/Sketch/Classes/SketchViewController.swift#L79

Added line #L79 was not covered by tests
let imageData = (self.sketchView.image?.pngData())!
self.draw?.image = imageData
self.coloringStore!.saveDraw((self.draw)!)
Expand Down
3 changes: 2 additions & 1 deletion Balance/Distraction/Games/GamesCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ struct GamesCellView: View {
iconView
textView
}
.frame(maxWidth: 311, maxHeight: 120)
.frame(maxWidth: UIScreen.screenWidth - 20)
.frame(height: 120)

Check warning on line 20 in Balance/Distraction/Games/GamesCellView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Distraction/Games/GamesCellView.swift#L19-L20

Added lines #L19 - L20 were not covered by tests
.foregroundColor(darkBlueColor)
.background(RoundedRectangle(cornerRadius: 20).fill(.white))
.clipped()
Expand Down
3 changes: 2 additions & 1 deletion Balance/Home/CellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ struct CellView: View {
iconView
textView
}
.frame(maxWidth: 311, maxHeight: 120)
.frame(maxWidth: UIScreen.screenWidth - 20)
.frame(height: 120)

Check warning on line 20 in Balance/Home/CellView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Home/CellView.swift#L19-L20

Added lines #L19 - L20 were not covered by tests
.foregroundColor(darkBlueColor)
.background(RoundedRectangle(cornerRadius: 20).fill(.white))
.clipped()
Expand Down
2 changes: 1 addition & 1 deletion Balance/Home/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct HomeView: View {
}
}
.onChange(of: counter.count, perform: { _ in
if counter.count > 100 {
if counter.count > UserDefaults.standard.double(forKey: bpmKEY) {

Check warning on line 49 in Balance/Home/Home.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Home/Home.swift#L49

Added line #L49 was not covered by tests
print(counter.count)
alertHeartRate()
}
Expand Down
3 changes: 2 additions & 1 deletion Balance/Home/NavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct NavView: View {
.frame(maxWidth: .infinity)
}
.padding(EdgeInsets(top: 24, leading: 24, bottom: 24, trailing: 0))
.frame(maxWidth: 311, maxHeight: 114)
.frame(maxWidth: UIScreen.screenWidth - 20)
.frame(height: 120)

Check warning on line 32 in Balance/Home/NavigationView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Home/NavigationView.swift#L31-L32

Added lines #L31 - L32 were not covered by tests
.foregroundColor(darkBlueColor)
.background(RoundedRectangle(cornerRadius: 20).fill(.white))
.clipped()
Expand Down
2 changes: 1 addition & 1 deletion Balance/Profile/ProfileCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ProfileCellView: View {
iconView
textView
}
.frame(maxWidth: 300)
.frame(maxWidth: UIScreen.screenWidth - 20)

Check warning on line 19 in Balance/Profile/ProfileCellView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileCellView.swift#L19

Added line #L19 was not covered by tests
.frame(height: 60)
.foregroundColor(darkBlueColor)
.background(RoundedRectangle(cornerRadius: 20).fill(.white))
Expand Down
94 changes: 93 additions & 1 deletion Balance/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ struct ProfileView: View {
@State private var showAlert = false
@State private var logs = [ActivityLogEntry]()
@State private var logsIsEmpty = true

@State private var sliderValue: Float = 0.0
@State private var isEditing = false
@State private var sliderStringValue: String = ""

Check warning on line 36 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L34-L36

Added lines #L34 - L36 were not covered by tests

var body: some View {
ZStack {
VStack(alignment: .center, spacing: 0) {
HeaderMenu(title: "")
.background(primaryColor)
avatarChangeView
userData
bpmView

Check warning on line 45 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L45

Added line #L45 was not covered by tests
cellsView
Spacer()
}
}
.onAppear {
loadBPM()

Check warning on line 51 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L51

Added line #L51 was not covered by tests
#if DEMO
loadUserLocal()
loadLogs()
Expand All @@ -61,6 +66,29 @@ struct ProfileView: View {
}
}

var bpmView: some View {
VStack(spacing: 20) {
Text("BPM Alert at: \(sliderStringValue)")
.font(.custom("Nunito-Bold", size: 20))
.foregroundColor(darkBlueColor)
Slider(value: $sliderValue, in: 0...4, step: 1) {
Text("Slider")
} minimumValueLabel: {
Text("80")
.font(.custom("Montserrat-Thin", size: 20))
.foregroundColor(darkBlueColor)
} maximumValueLabel: {
Text("120")
.font(.custom("Montserrat-Thin", size: 20))
.foregroundColor(darkBlueColor)
} onEditingChanged: { editing in
isEditing = editing
readBPM()
}.tint(primaryColor)
.padding(.horizontal, 50)
}
}

Check warning on line 90 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L69-L90

Added lines #L69 - L90 were not covered by tests

var userData: some View {
Group {
Spacer().frame(height: 50)
Expand Down Expand Up @@ -88,6 +116,7 @@ struct ProfileView: View {
var cellsView: some View {
ScrollView(.vertical) {
VStack(spacing: 20) {
Spacer().frame(height: 10)

Check warning on line 119 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L119

Added line #L119 was not covered by tests
#if !DEMO
infoOption
updateOption
Expand Down Expand Up @@ -206,6 +235,8 @@ struct ProfileView: View {
// coloringStore.removeStore()
// #endif
// dismiss()

UserDefaults.standard.setValue(defaultBPM, forKey: bpmKEY)

Check warning on line 239 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L238-L239

Added lines #L238 - L239 were not covered by tests
authModel.signOut()
completedOnboardingFlow = false
// account.signedIn = false
Expand Down Expand Up @@ -267,6 +298,67 @@ struct ProfileView: View {
.accessibility(hidden: true)
}

func saveBPM() {
var value = 100.0
switch sliderValue {
case 0:
value = 80.0
case 1:
value = 90.0
case 2:
value = 100.0
case 3:
value = 110.0
case 4:
value = 120.0
default:
value = 100.0
}
UserDefaults.standard.set(value, forKey: bpmKEY)

Check failure on line 318 in Balance/Profile/ProfileView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Vertical Whitespace before Closing Braces Violation: Don't include vertical whitespace (empty line) before closing braces (vertical_whitespace_closing_braces)
}

Check warning on line 319 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L301-L319

Added lines #L301 - L319 were not covered by tests

func readBPM() {
switch sliderValue {
case 0:
sliderStringValue = "80"
case 1:
sliderStringValue = "90"
case 2:
sliderStringValue = "100"
case 3:
sliderStringValue = "110"
case 4:
sliderStringValue = "120"
default:
sliderStringValue = "100"
}
saveBPM()
}

Check warning on line 337 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L321-L337

Added lines #L321 - L337 were not covered by tests

func loadBPM() {
switch UserDefaults.standard.float(forKey: bpmKEY) {
case 80.0:
sliderValue = 0
sliderStringValue = "80"
case 90.0:
sliderValue = 1
sliderStringValue = "90"
case 100.0:
sliderValue = 2
sliderStringValue = "100"
case 110.0:
sliderValue = 3
sliderStringValue = "110"
case 120.0:
sliderValue = 4
sliderStringValue = "120"
default:
sliderValue = 2
sliderStringValue = "100"
}
}

Check warning on line 360 in Balance/Profile/ProfileView.swift

View check run for this annotation

Codecov / codecov/patch

Balance/Profile/ProfileView.swift#L339-L360

Added lines #L339 - L360 were not covered by tests

func loadUser() {
authModel.listenAuthentificationState()
UserProfileRepository.shared.fetchCurrentProfile { profileUser, error in
Expand Down
6 changes: 6 additions & 0 deletions Balance/Utils/BalanceExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,9 @@ extension DateFormatter {
return dateFormatter
}()
}

extension UIScreen{

Check failure on line 156 in Balance/Utils/BalanceExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
static let screenWidth = UIScreen.main.bounds.size.width
static let screenHeight = UIScreen.main.bounds.size.height
static let screenSize = UIScreen.main.bounds.size
}
3 changes: 3 additions & 0 deletions Balance/Utils/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ let coinsValue = 5
let coinsTime = 15

let demoID = "0"

let bpmKEY = "bpmKEY"
let defaultBPM = 100.0

0 comments on commit ff599b5

Please sign in to comment.