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

[CAT-217] 알림설정 UserDefault 저장 #41

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
Binary file modified DependencyGraph/mohanyang_dev_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified DependencyGraph/mohanyang_prod_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public struct AnyCat: CatFactoryProtocol, Identifiable, Equatable {

public var id: String { base.id }
public var no: Int { base.no }
public var name: String
public var keyword: String { base.keyword }
public var keywordImage: Image { base.keywordImage }
public var name: String
public var catImage: Image { base.catImage }
public var selectCatRivTrigger: String { base.selectCatRivTrigger }
public var pushNotificationTitle: String { base.pushNotificationTitle }
public var focusEndPushTitle: String { base.focusEndPushTitle }
public var restEndPushTitle: String { base.restEndPushTitle }
public var disturbPushTitle: String { base.disturbPushTitle }

public static func == (lhs: AnyCat, rhs: AnyCat) -> Bool {
lhs.base.id == rhs.base.id
Expand All @@ -49,7 +51,9 @@ public struct CheeseCat: CatFactoryProtocol {
public var keywordImage: Image = DesignSystemAsset.Image._16Star.swiftUIImage
public var catImage: Image = Image(systemName: "star.fill")
public var selectCatRivTrigger: String = "Click_Cheese Cat"
public var pushNotificationTitle: String = "어디갔냐옹..."
public var focusEndPushTitle: String = "집중이 끝났다냥! 이제 나랑 놀아달라냥"
public var restEndPushTitle: String = "이제 다시 집중해볼까냥?"
public var disturbPushTitle: String = "날 두고 어디갔냥.."
}

// MARK: BLACK CAT
Expand All @@ -66,7 +70,9 @@ public struct BlackCat: CatFactoryProtocol {
public var keywordImage: Image = DesignSystemAsset.Image._16Heart.swiftUIImage
public var catImage: Image = Image(systemName: "star")
public var selectCatRivTrigger: String = "Click_Black Cat"
public var pushNotificationTitle: String = "어디갔냐옹..."
public var focusEndPushTitle: String = "집중이 끝났다냥! 이제 나랑 놀아달라냥"
public var restEndPushTitle: String = "이제 다시 집중해볼까냥?"
public var disturbPushTitle: String = "날 두고 어디갔냥.."
}

// MARK: THREE_COLOR CAT
Expand All @@ -83,7 +89,9 @@ public struct ThreeColorCat: CatFactoryProtocol {
public var keywordImage: Image = DesignSystemAsset.Image._16Focus.swiftUIImage
public var catImage: Image = Image(systemName: "star.fill")
public var selectCatRivTrigger: String = "Click_Calico Cat"
public var pushNotificationTitle: String = "내가 여기있는데 어디갔냐옹!"
public var focusEndPushTitle: String = "집중이 끝났다냥! 원하는 만큼 집중했냥?"
public var restEndPushTitle: String = "집중할 시간이다냥! 빨리 들어오라냥"
public var disturbPushTitle: String = "지금 뭐하고 있냥? 내가 감시하고 있다냥"
}

// MARK: MAKE CAT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public protocol CatFactoryProtocol {
var keywordImage: Image { get } // 키워드에 따른 아이콘 이미지
var catImage: Image { get }
var selectCatRivTrigger: String { get }
var pushNotificationTitle: String { get } // 푸시알림 예시 글귀
var focusEndPushTitle: String { get }
var restEndPushTitle: String { get }
var disturbPushTitle: String { get }
}
3 changes: 2 additions & 1 deletion Projects/Domain/PushService/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let project: Project = .makeTMABasedProject(
],
dependencies: [
.sources: [
.dependency(rootModule: Core.self)
.dependency(rootModule: Core.self),
.dependency(module: Domain.CatService)
]
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,36 @@
//

import Foundation
import CatServiceInterface

public enum LocalPushNotificationContent {
case test

case focus(AnyCat)
case rest(AnyCat)
case disturb(AnyCat)

public var title: String {
switch self {
case .test:
return "테스트 집중"
}
return "모하냥"
}

public var body: String {
switch self {
case .test:
return "\(10)시 까지 집중해봐요!"
case .focus(let cat):
return cat.focusEndPushTitle
case .rest(let cat):
return cat.restEndPushTitle
case .disturb(let cat):
return cat.disturbPushTitle
}
}

public var identifier: String {
switch self {
case .test:
return "group1"
case .focus:
return "focus"
case .rest:
return "rest"
case .disturb:
return "disturb"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import SwiftUI

import CatServiceInterface
import DesignSystem

import ComposableArchitecture
Expand Down Expand Up @@ -112,7 +113,7 @@ struct CatPushNotificationExampleView: View {
.foregroundStyle(Alias.Color.Text.secondary)
}
HStack {
Text(selectedCat.pushNotificationTitle)
Text(selectedCat.disturbPushTitle)
.font(Typography.subBodyR)
.foregroundStyle(Alias.Color.Text.primary)
Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import CatFeature
import CatServiceInterface

import ComposableArchitecture

Expand Down
19 changes: 18 additions & 1 deletion Projects/Feature/MyPageFeature/Sources/MyPage/MyPageCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import CatFeature
import APIClientInterface
import UserServiceInterface
import CatServiceInterface
import UserDefaultsClientInterface

import ComposableArchitecture

Expand All @@ -18,7 +20,7 @@ public struct MyPageCore {
public struct State: Equatable {
public init() { }
var cat: AnyCat? = nil
var isFocusTimeAlarmOn: Bool = false
var isTimerAlarmOn: Bool = false
var isDisturbAlarmOn: Bool = false
var isInternetConnected: Bool = false
let feedbackURLString: String = "https://forms.gle/wEUPH9Tvxgua4hCZ9"
Expand All @@ -35,6 +37,9 @@ public struct MyPageCore {

@Dependency(APIClient.self) var apiClient
@Dependency(UserService.self) var userService
@Dependency(UserDefaultsClient.self) var userDefaultsClient
let isTimerAlarmOnKey = "mohanyang_userdefaults_isTimerAlarmOnKey"
let isDisturbAlarmOnKey = "mohanyang_userdefaults_isDisturmAlarmOnKey"

public init() {}

Expand All @@ -49,6 +54,8 @@ public struct MyPageCore {
private func core(state: inout State, action: Action) -> EffectOf<Self> {
switch action {
case .onAppear:
state.isTimerAlarmOn = userDefaultsClient.boolForKey(isTimerAlarmOnKey)
state.isDisturbAlarmOn = userDefaultsClient.boolForKey(isDisturbAlarmOnKey)
return .run { send in
let data = try await userService.getUserInfo(apiClient: apiClient)
await send(._responseUserInfo(data))
Expand All @@ -70,6 +77,16 @@ public struct MyPageCore {
case .myCat:
return .none

case .binding(\.isTimerAlarmOn):
return .run { [isTimerAlarmOn = state.isTimerAlarmOn] _ in
await userDefaultsClient.setBool(isTimerAlarmOn, isTimerAlarmOnKey)
}

case .binding(\.isDisturbAlarmOn):
return .run { [isDisturbAlarmOn = state.isDisturbAlarmOn] _ in
await userDefaultsClient.setBool(isDisturbAlarmOn, isDisturbAlarmOnKey)
}

case .binding:
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct MyPageView: View {
AlarmSectionView(
title: "집중시간 알림받기",
subTitle: "집중・휴식시간이 되면 고양이가 알려줘요",
isOn: $store.isFocusTimeAlarmOn
isOn: $store.isTimerAlarmOn
)
AlarmSectionView(
title: "딴 짓 방해하기",
Expand Down
Loading