Skip to content

Commit

Permalink
Merge pull request #229 from APP-iOS2/refactor/appStorage
Browse files Browse the repository at this point in the history
refactor: AppStorage 문자열 에서 STROAGE enum 값으로 리팩토링
  • Loading branch information
hyeonghwan authored May 8, 2024
2 parents 3f27baf + 40c60ea commit 6126a76
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 172 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
if: github.event_name == 'pull_request'
run: |
xcodebuild clean test -project Pickle/Pickle.xcodeproj -scheme Pickle -destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.0.1'
# slack 에 알림 보내기
- name: action-slack
uses: 8398a7/action-slack@v3
Expand All @@ -48,8 +49,8 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.

# # DESCRIBE: 빌드 실패한 경우에만 실행되는 step
# DESCRIBE: 빌드 실패한 경우에만 실행되는 step
- name: If build fail
# 이전 step이 실패한 경우에만 이 step을 실행시키는 syntax
if: ${{ failure() }}
Expand Down
4 changes: 4 additions & 0 deletions Pickle/Pickle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
96A401122BE8D259004C30EC /* HeaderActionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A401112BE8D259004C30EC /* HeaderActionView.swift */; };
96A401142BE8D47B004C30EC /* TodayPizzaSummaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A401132BE8D47B004C30EC /* TodayPizzaSummaryView.swift */; };
96A401162BE8D526004C30EC /* TodayPizzaSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A401152BE8D526004C30EC /* TodayPizzaSheetView.swift */; };
96A9DBE02BEB73B700B40A2A /* STORAGE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A9DBDF2BEB73B700B40A2A /* STORAGE.swift */; };
96AAF8302AFD3A7B00410881 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AAF82F2AFD3A7B00410881 /* Dictionary.swift */; };
96AAF8322AFD509200410881 /* Mediator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AAF8312AFD509200410881 /* Mediator.swift */; };
96AAF8372AFD50F900410881 /* NotiMediator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AAF8362AFD50F900410881 /* NotiMediator.swift */; };
Expand Down Expand Up @@ -445,6 +446,7 @@
96A401112BE8D259004C30EC /* HeaderActionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderActionView.swift; sourceTree = "<group>"; };
96A401132BE8D47B004C30EC /* TodayPizzaSummaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayPizzaSummaryView.swift; sourceTree = "<group>"; };
96A401152BE8D526004C30EC /* TodayPizzaSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayPizzaSheetView.swift; sourceTree = "<group>"; };
96A9DBDF2BEB73B700B40A2A /* STORAGE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STORAGE.swift; sourceTree = "<group>"; };
96AAF82F2AFD3A7B00410881 /* Dictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
96AAF8312AFD509200410881 /* Mediator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mediator.swift; sourceTree = "<group>"; };
96AAF8362AFD50F900410881 /* NotiMediator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotiMediator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -784,6 +786,7 @@
isa = PBXGroup;
children = (
9619E93B2B0594210028348C /* ScrollEnableKey.swift */,
96A9DBDF2BEB73B700B40A2A /* STORAGE.swift */,
);
path = EnvironmentValues;
sourceTree = "<group>";
Expand Down Expand Up @@ -1473,6 +1476,7 @@
9661108B2AFA84CA008A80DE /* PreferenceKey.swift in Sources */,
9661107C2AF800AD008A80DE /* Realm+Combine.swift in Sources */,
966B031E2B07B4CE009B6293 /* HomeViewModel.swift in Sources */,
96A9DBE02BEB73B700B40A2A /* STORAGE.swift in Sources */,
966CD9F12B0A6BA2003AE885 /* Register-extension.swift in Sources */,
96AAF8372AFD50F900410881 /* NotiMediator.swift in Sources */,
96EB8C1E2B029AF20011B973 /* CurrentPizza-extension.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
}
}
],
"version" : 2
"version" : 3
}
4 changes: 2 additions & 2 deletions Pickle/Pickle/Screen/App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import SwiftUI

struct ContentView: View {
@AppStorage("onboarding") var isOnboardingViewActive: Bool = true
@AppStorage("systemTheme") private var systemTheme: Int = SchemeType.allCases.first!.rawValue
@AppStorage(STORAGE.onboarding.id) var isOnboardingViewActive: Bool = true
@AppStorage(STORAGE.systemTheme.id) private var systemTheme: Int = SchemeType.allCases.first!.rawValue

@EnvironmentObject var pizzaStore: PizzaStore
@EnvironmentObject var userStore: UserStore
Expand Down
13 changes: 6 additions & 7 deletions Pickle/Pickle/Screen/App/PickleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ struct PickleApp: App {
@StateObject private var notificationManager = NotificationManager(mediator: NotiMediator.shared)
@StateObject private var timerVM = TimerViewModel()

init() {
Thread.sleep(forTimeInterval: 1)
}

@Environment(\.scenePhase) var scenePhase
@State private var debugDelete: Bool = true
@AppStorage(STORAGE.backgroundNumber.id) var backgroundNumber: Int = 0
@AppStorage(STORAGE.isRunTimer.id) var isRunTimer: Bool = false
@AppStorage(STORAGE.todoId.id) var todoId: String = ""

@AppStorage("backgroundNumber") var backgroundNumber: Int = 0
@AppStorage("isRunTimer") var isRunTimer: Bool = false
@AppStorage("todoId") var todoId: String = ""
init() {
Thread.sleep(forTimeInterval: 1)
}

var body: some Scene {
WindowGroup {
Expand Down
4 changes: 2 additions & 2 deletions Pickle/Pickle/Screen/Calendar/View/TaskRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import SwiftUI
struct TaskRowView: View {

@State private var isShowingReportSheet: Bool = false
@AppStorage("is24HourClock") private var is24HourClock: Bool = true
@AppStorage("timeFormat") private var timeFormat: String = "HH:mm"
@AppStorage(STORAGE.is24HourClock.id) private var is24HourClock: Bool = true
@AppStorage(STORAGE.timeFormat.id) private var timeFormat: String = "HH:mm"

var task: Todo
var indicatorColor: Color {
Expand Down
17 changes: 0 additions & 17 deletions Pickle/Pickle/Screen/Home/HomeView/Util/PreferenceKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,3 @@ struct ScrollOffsetKey: PreferenceKey {
value += nextValue()
}
}

// HomeView 에서 Prefenrence Change를 옵저브 하고 있었지만
// PizzaSeletedView는 modifier로 동일 계층에 ZStack에 올린 View로써 HOmeView가 상위뷰가 아니라 동일계층으로 인식되어
// onPreferenceChange가 호출되지 않음
// .preference(key: PizzaPuchasePresentKey.self,
// value: isPizzaPuchasePresent)
// .onPreferenceChange(PizzaPuchasePresentKey.self) {
// bool in
// Log.debug("onPreferenceChagne: \(bool)")
// isPizzaPuchasePresent = bool
// }

// .onPreferenceChange(PizzaPuchasePresentKey.self) { value in
// Log.error("onPreference value: \(value)")
// }
// .preference(key: PizzaPuchasePresentKey.self,
// value: isPizzaPuchasePresent)
4 changes: 2 additions & 2 deletions Pickle/Pickle/Screen/Home/HomeView/View/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct HomeView: View {
@State private var description: String = ""

@State private var ongoingTodo: Todo = Todo.onGoing
@AppStorage("isRunTimer") var isRunTimer: Bool = false
@AppStorage("todoId") var todoId: String = ""
@AppStorage(STORAGE.isRunTimer.id) var isRunTimer: Bool = false
@AppStorage(STORAGE.todoId.id) var todoId: String = ""

var body: some View {
content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import SwiftUI

struct TodoCellView: View {

@AppStorage("is24HourClock") var is24HourClock: Bool = true
@AppStorage("timeFormat") var timeFormat: String = "HH:mm"
@AppStorage(STORAGE.is24HourClock.id) var is24HourClock: Bool = true
@AppStorage(STORAGE.timeFormat.id) var timeFormat: String = "HH:mm"

@Environment(\.colorScheme) var colorScheme
@EnvironmentObject var navigationStore: NavigationStore
Expand Down
127 changes: 0 additions & 127 deletions Pickle/Pickle/Screen/Home/MissionView/MissionStyleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ struct BehaviorMissionStyleView: View {

struct MissionStyle_Previews: PreviewProvider {
static var previews: some View {
// TimeMissionStyleView(timeMission: .constant(TimeMission(id: "")), showsAlert: .constant(false), showSuccessAlert: .constant(false))
// .environmentObject(MissionStore())
// .environmentObject(UserStore())
BehaviorMissionStyleView(behaviorMission: .constant(BehaviorMission(id: "",
title: "",
status: .ready,
Expand All @@ -331,127 +328,3 @@ struct MissionStyle_Previews: PreviewProvider {
.environmentObject(UserStore())
}
}

// 기상미션 주석처리
// struct TimeMissionStyleView: View {
// @EnvironmentObject var missionStore: MissionStore
// @EnvironmentObject var userStore: UserStore
// @Binding var timeMission: TimeMission
//
// @AppStorage("is24HourClock") var is24HourClock: Bool = true
// @AppStorage("timeFormat") var timeFormat: String = "HH:mm"
//
// @State private var showTimeMissionModal = false
// @Binding var showsAlert: Bool
// @Binding var showSuccessAlert: Bool
//
// var buttonSwitch: Bool {
// switch timeMission.status {
// case .ready, .done, .fail:
// return true
// case .complete:
// return false
// default:
// return false
// }
// }
//
// var body: some View {
// HStack(alignment: .bottom) {
// VStack(alignment: .leading) {
// Text(timeMission.title)
// .font(.nanumEbTitle)
// .foregroundColor(.primary)
// .padding(.bottom, 1)
//
// Button(action: {
// showTimeMissionModal.toggle()
// }, label: {
// HStack {
// Text("\(timeMission.changeWakeupTime.format(timeFormat))")
// .font(.pizzaTitle2)
//
// Image(systemName: "chevron.up.chevron.down")
// }
// .foregroundColor(.secondary)
// })
// .sheet(isPresented: $showTimeMissionModal) {
// TimeMissionSettingView(timeMission: $timeMission,
// title: timeMission.title,
// showTimeMissionModal: $showTimeMissionModal,
// showSuccessAlert: $showSuccessAlert)
// .presentationDetents([.fraction(0.4)])
// }
// }
//
// Spacer(minLength: 10)
//
// MissionButton(status: $timeMission.status, action: {
// timeMission.status = .done
// missionStore.update(mission: .time(TimeMission(id: timeMission.id,
// title: timeMission.title,
// status: .done,
// date: timeMission.date,
// wakeupTime: timeMission.wakeupTime,
// changeWakeupTime: timeMission.changeWakeupTime)))
// withAnimation {
// do {
// try userStore.addPizzaSlice(slice: 1)
//
// } catch {
// Log.error("❌피자 조각 추가 실패❌")
// }
// }
// showsAlert = true
// })
// .disabled(buttonSwitch)
// }
// .onAppear {
// missionComplete()
// }
// .refreshable {
// missionComplete()
// }
// .padding(.horizontal, 20)
// .padding(.vertical, 20)
// .background(.clear)
// .frame(minWidth: 0, maxWidth: .infinity)
// .cornerRadius(20.0)
// .overlay(RoundedRectangle(cornerRadius: 20.0)
// .stroke(Color(.lightGray), lineWidth: 1))
// .padding(.horizontal)
// .padding(.top, 15)
// }
//
// func missionComplete() {
// // 현재 시간과 목표 기상시간 비교 .ready .complete .done .fail
// if Date() >= timeMission.wakeupTime.adding(minutes: -10)
// && Date() <= timeMission.wakeupTime.adding(minutes: 10) {
// if timeMission.status != .done {
// timeMission.status = .complete
// missionStore.update(mission: .time(TimeMission(id: timeMission.id,
// title: timeMission.title,
// status: .complete,
// date: timeMission.date,
// wakeupTime: timeMission.wakeupTime,
// changeWakeupTime: timeMission.changeWakeupTime)))
// }
// } else if Date() < timeMission.wakeupTime.adding(minutes: -10) {
// timeMission.status = .ready
// missionStore.update(mission: .time(TimeMission(id: timeMission.id,
// title: timeMission.title,
// status: .ready,
// date: timeMission.date,
// wakeupTime: timeMission.wakeupTime,
// changeWakeupTime: timeMission.changeWakeupTime)))
// } else {
// timeMission.status = .fail
// missionStore.update(mission: .time(TimeMission(id: timeMission.id,
// title: timeMission.title,
// status: .fail,
// date: timeMission.date,
// wakeupTime: timeMission.wakeupTime,
// changeWakeupTime: timeMission.changeWakeupTime)))
// }
// }
// }
4 changes: 2 additions & 2 deletions Pickle/Pickle/Screen/Home/MissionView/MissionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct MissionView: View {
@EnvironmentObject var missionStore: MissionStore
@EnvironmentObject var healthKitStore: HealthKitStore

@AppStorage("is24HourClock") var is24HourClock: Bool = true
@AppStorage("timeFormat") var timeFormat: String = "HH:mm"
@AppStorage(STORAGE.is24HourClock.id) var is24HourClock: Bool = true
@AppStorage(STORAGE.timeFormat.id) var timeFormat: String = "HH:mm"

@State private var showsAlert: Bool = false
@State private var showSuccessAlert: Bool = false
Expand Down
4 changes: 2 additions & 2 deletions Pickle/Pickle/Screen/Home/TimerView/TimerReportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ struct TimerReportView: View {
@Binding var isShowingReportSheet: Bool
@Binding var isShowingTimerView: Bool

@AppStorage("is24HourClock") var is24HourClock: Bool = true
@AppStorage("timeFormat") var timeFormat: String = "HH:mm"
@AppStorage(STORAGE.is24HourClock.id) var is24HourClock: Bool = true
@AppStorage(STORAGE.timeFormat.id) var timeFormat: String = "HH:mm"

var todo: Todo

Expand Down
6 changes: 3 additions & 3 deletions Pickle/Pickle/Screen/Home/TimerView/TimerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ struct TimerView: View {
@State private var state: TimerState = TimerState()
@Binding var isShowingTimerView: Bool
@State private var wiseSaying: String = ""
@AppStorage("isRunTimer") var isRunTimer: Bool = false
@AppStorage("backgroundNumber") var backgroundNumber: Int = 0
@AppStorage("todoId") var todoId: String = ""
@AppStorage(STORAGE.isRunTimer.id) var isRunTimer: Bool = false
@AppStorage(STORAGE.backgroundNumber.id) var backgroundNumber: Int = 0
@AppStorage(STORAGE.todoId.id) var todoId: String = ""

var body: some View {
ZStack {
Expand Down
23 changes: 23 additions & 0 deletions Pickle/Pickle/Screen/Model/EnvironmentValues/STORAGE.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Env.swift
// Pickle
//
// Created by 박형환 on 5/8/24.
//

import Foundation


enum STORAGE: String {
case backgroundNumber
case isRunTimer
case todoId
case onboarding
case systemTheme
case is24HourClock
case timeFormat

var id: String {
self.rawValue
}
}
2 changes: 1 addition & 1 deletion Pickle/Pickle/Screen/Setting/SettingNotiicationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
struct SettingNotiicationView: View {
@EnvironmentObject var notificationManager: NotificationManager

@AppStorage("onboarding") var isOnboardingViewActive: Bool = true
@AppStorage(STORAGE.onboarding.id) var isOnboardingViewActive: Bool = true

@Binding var isShowingOnboarding: Bool

Expand Down
4 changes: 2 additions & 2 deletions Pickle/Pickle/Screen/Setting/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct SettingView: View {
@Environment(\.colorScheme) var colorScheme
@EnvironmentObject var notificationManager: NotificationManager

@AppStorage("systemTheme") private var systemTheme: Int = SchemeType.allCases.first!.rawValue
@AppStorage("is24HourClock") var is24HourClock: Bool = true
@AppStorage(STORAGE.systemTheme.id) private var systemTheme: Int = SchemeType.allCases.first!.rawValue
@AppStorage(STORAGE.is24HourClock.id) var is24HourClock: Bool = true

@State private var isShowingMoveToSettingAlert: Bool = false
@State private var isShowingEmailAlert: Bool = false
Expand Down

0 comments on commit 6126a76

Please sign in to comment.