Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ (LekaApp): Triggers reinforcer on editing care receiver reinforcers #730

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CarereceiverView: View {
.fill(Color(uiColor: UIColor.systemGray6))
}
.overlay {
Image(uiImage: self.rootOwnerViewModel.getReinforcerFor(index: self.carereceiver.reinforcer))
Image(uiImage: self.rootOwnerViewModel.getImageFor(reinforcer: self.carereceiver.robotReinforcer))
.resizable()
.aspectRatio(contentMode: .fit)
.padding(5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import AccountKit
import DesignKit
import SwiftUI
import RobotKit

class RootOwnerViewModel: ObservableObject {
// MARK: Lifecycle
Expand Down Expand Up @@ -47,21 +48,21 @@ class RootOwnerViewModel: ObservableObject {
]

@Published var mockCarereceiversSet: [Carereceiver] = [
Carereceiver(id: UUID().uuidString, username: "Peet", avatar: Avatars.categories[2].avatars[2], reinforcer: 1),
Carereceiver(id: UUID().uuidString, username: "Rounhaa", avatar: Avatars.categories[4].avatars[0], reinforcer: 3),
Carereceiver(id: UUID().uuidString, username: "Selug", avatar: Avatars.categories[5].avatars[1], reinforcer: 4),
Carereceiver(id: UUID().uuidString, username: "Luther", avatar: Avatars.categories[1].avatars[2], reinforcer: 5),
Carereceiver(id: UUID().uuidString, username: "Abel", avatar: Avatars.categories[2].avatars[3], reinforcer: 2),
Carereceiver(id: UUID().uuidString, username: "Peet", avatar: Avatars.categories[2].avatars[2], reinforcer: 0x51),
Carereceiver(id: UUID().uuidString, username: "Rounhaa", avatar: Avatars.categories[4].avatars[0], reinforcer: 0x52),
Carereceiver(id: UUID().uuidString, username: "Selug", avatar: Avatars.categories[5].avatars[1], reinforcer: 0x53),
Carereceiver(id: UUID().uuidString, username: "Luther", avatar: Avatars.categories[1].avatars[2], reinforcer: 0x54),
Carereceiver(id: UUID().uuidString, username: "Abel", avatar: Avatars.categories[2].avatars[3], reinforcer: 0x52),
]
// swiftlint:enable line_length

func getReinforcerFor(index: Int) -> UIImage {
switch index {
case 2: DesignKitAsset.Reinforcers.spinBlinkBlueViolet.image
case 3: DesignKitAsset.Reinforcers.fire.image
case 4: DesignKitAsset.Reinforcers.sprinkles.image
case 5: DesignKitAsset.Reinforcers.rainbow.image
default: DesignKitAsset.Reinforcers.spinBlinkGreenOff.image
func getImageFor(reinforcer: Robot.Reinforcer) -> UIImage {
switch reinforcer {
case .spinBlinkGreenOff: DesignKitAsset.Reinforcers.spinBlinkGreenOff.image
case .spinBlinkBlueViolet: DesignKitAsset.Reinforcers.spinBlinkBlueViolet.image
case .fire: DesignKitAsset.Reinforcers.fire.image
case .sprinkles: DesignKitAsset.Reinforcers.sprinkles.image
case .rainbow: DesignKitAsset.Reinforcers.rainbow.image
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct CarereceiverAvatarCell: View {
.fill(Color(uiColor: UIColor.systemGray6))
}
.overlay {
Image(uiImage: self.rootOwnerViewModel.getReinforcerFor(index: self.carereceiver.reinforcer))
Image(uiImage: self.rootOwnerViewModel.getImageFor(reinforcer: self.carereceiver.robotReinforcer))
.resizable()
.aspectRatio(contentMode: .fit)
.padding(5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import AccountKit
import DesignKit
import LocalizationKit
import RobotKit
import SwiftUI

// MARK: - ReinforcerPicker
Expand All @@ -13,21 +14,23 @@ struct ReinforcerPicker: View {
// MARK: Internal

@Binding var carereceiver: Carereceiver
let robot = Robot.shared

var body: some View {
HStack {
ForEach(1...5, id: \.self) { number in
Image(uiImage: self.rootOwnerViewModel.getReinforcerFor(index: number))
ForEach(Robot.Reinforcer.allCases, id: \.self) { reinforcer in
Image(uiImage: self.rootOwnerViewModel.getImageFor(reinforcer: reinforcer))
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 50)
.padding(5)
.background(
Circle()
.stroke(self.styleManager.accentColor!, lineWidth: self.carereceiver.reinforcer == number ? 2 : 0)
.stroke(self.styleManager.accentColor!, lineWidth: self.carereceiver.reinforcer == reinforcer.rawValue ? 2 : 0)
)
.onTapGesture {
self.carereceiver.reinforcer = number
self.carereceiver.reinforcer = reinforcer.rawValue
self.robot.run(reinforcer)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public extension Carereceiver {
rootOwnerUid: String = "",
username: String = "",
avatar: String = "",
reinforcer: Int = 1)
reinforcer: UInt8 = 0x51)
{
self.id = id
self.rootOwnerUid = rootOwnerUid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

import FirebaseFirestore
import RobotKit
import SwiftUI

public struct Carereceiver: AccountDocument, Hashable {
Expand All @@ -15,7 +16,11 @@ public struct Carereceiver: AccountDocument, Hashable {
public var rootOwnerUid: String
public var username: String
public var avatar: String
public var reinforcer: Int
public var reinforcer: UInt8

public var robotReinforcer: Robot.Reinforcer {
Robot.Reinforcer(rawValue: self.reinforcer) ?? .rainbow
}

// MARK: Internal

Expand Down
Loading