diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift index ac0183a..7420dcd 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift @@ -116,6 +116,12 @@ public final class HomeViewController: HomeBottomSheetViewController { self.navigationController?.isNavigationBarHidden = true } + public override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + self.viewModel.trigger(.viewNeedsReloaded) + } + // MARK: - Combine Binding private func bind() { diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift index d70982f..559795b 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift @@ -22,6 +22,7 @@ public final class HomeViewModel { public enum Action { case viewNeedsLoaded + case viewNeedsReloaded case startButtonDidTap(Coordinate) case refreshButtonDidTap(visibleCoordinates: (minCoordinate: Coordinate, maxCoordinate: Coordinate)) case backButtonDidTap @@ -67,16 +68,19 @@ public final class HomeViewModel { func trigger(_ action: Action) { switch action { case .viewNeedsLoaded: - #if DEBUG - self.isFirstLaunch = true - try? self.keychain.deleteAll() - #endif +// #if DEBUG +// self.isFirstLaunch = true +// try? self.keychain.deleteAll() +// #endif let firstLaunchMessage = self.isFirstLaunch ? "앱이 처음 실행되었습니다." : "앱 첫 실행이 아닙니다." MSLogger.make(category: .userDefaults).log("\(firstLaunchMessage)") if self.isFirstLaunch { self.createNewUser() } + case .viewNeedsReloaded: + let isRecording = self.journeyRepository.fetchIsRecording() + self.state.isRecording.send(isRecording) case .startButtonDidTap(let coordinate): #if DEBUG MSLogger.make(category: .home).debug("Start 버튼 탭: \(coordinate)") diff --git a/iOS/Features/SaveJourney/Sources/SaveJourney/Presentation/SaveJourneyViewModel.swift b/iOS/Features/SaveJourney/Sources/SaveJourney/Presentation/SaveJourneyViewModel.swift index 437a2d5..e6b21c2 100644 --- a/iOS/Features/SaveJourney/Sources/SaveJourney/Presentation/SaveJourneyViewModel.swift +++ b/iOS/Features/SaveJourney/Sources/SaveJourney/Presentation/SaveJourneyViewModel.swift @@ -111,6 +111,7 @@ private extension SaveJourneyViewModel { #if DEBUG MSLogger.make(category: .saveJourney).log("\(journeyID)가 저장되었습니다.") #endif + self.state.endJourneySucceed.send(journey) case .failure(let error): MSLogger.make(category: .saveJourney).error("\(error)") } diff --git a/iOS/MSCoreKit/Sources/MSPersistentStorage/FileManager/FileManagerStorage.swift b/iOS/MSCoreKit/Sources/MSPersistentStorage/FileManager/FileManagerStorage.swift index 63165fb..4c54136 100644 --- a/iOS/MSCoreKit/Sources/MSPersistentStorage/FileManager/FileManagerStorage.swift +++ b/iOS/MSCoreKit/Sources/MSPersistentStorage/FileManager/FileManagerStorage.swift @@ -146,15 +146,15 @@ extension FileManagerStorage { func storageURL(create: Bool = false) -> URL? { let directoryURL: URL? if #available(iOS 16.0, *) { - let storageDirectoryURL = try? self.fileManager.url(for: .applicationDirectory, + let storageDirectoryURL = try? self.fileManager.url(for: .cachesDirectory, in: .userDomainMask, - appropriateFor: .applicationDirectory, + appropriateFor: .cachesDirectory, create: false) directoryURL = storageDirectoryURL? .appending(path: Constants.appBundleIdentifier, directoryHint: .isDirectory) } else { let cacheDirectoryURL = self.fileManager - .urls(for: .applicationDirectory, in: .userDomainMask) + .urls(for: .cachesDirectory, in: .userDomainMask) .first directoryURL = cacheDirectoryURL? .appendingPathComponent(Constants.appBundleIdentifier, isDirectory: true) diff --git a/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift b/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift index cc4003e..9d9d604 100644 --- a/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift +++ b/iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift @@ -17,6 +17,8 @@ import MSUserDefaults public protocol JourneyRepository: Persistable { + func fetchIsRecording() -> Bool + mutating func updateIsRecording(_ isRecording: Bool) -> Bool func fetchRecordingJourneyID() -> String? func fetchRecordingJourney(forID id: String) -> RecordingJourney? func fetchJourneyList(userID: UUID, @@ -36,6 +38,9 @@ public struct JourneyRepositoryImplementation: JourneyRepository { private let networking: MSNetworking public let storage: MSPersistentStorage + @UserDefaultsWrapped(UserDefaultsKey.isRecording, defaultValue: false) + private var isRecording: Bool + @UserDefaultsWrapped(UserDefaultsKey.recordingJourneyID, defaultValue: nil) private var recordingJourneyID: String? @@ -49,6 +54,16 @@ public struct JourneyRepositoryImplementation: JourneyRepository { // MARK: - Functions + public func fetchIsRecording() -> Bool { + return self.isRecording + } + + @discardableResult + public mutating func updateIsRecording(_ isRecording: Bool) -> Bool { + self.isRecording = isRecording + return self.isRecording + } + public func fetchRecordingJourneyID() -> String? { guard let recordingJourneyID = self.recordingJourneyID else { MSLogger.make(category: .userDefaults).error("기록 중인 여정 정보를 가져오는데 실패했습니다.") @@ -118,6 +133,7 @@ public struct JourneyRepositoryImplementation: JourneyRepository { self.saveToLocal(value: recordingJourney.id) self.saveToLocal(value: recordingJourney.startTimestamp) + self.isRecording = true self.recordingJourneyID = recordingJourney.id #if DEBUG @@ -168,6 +184,7 @@ public struct JourneyRepositoryImplementation: JourneyRepository { switch result { case .success(let responseDTO): self.recordingJourneyID = nil + self.isRecording = false return .success(responseDTO.id) case .failure(let error): return .failure(error) @@ -182,6 +199,7 @@ public struct JourneyRepositoryImplementation: JourneyRepository { switch result { case .success(let responseDTO): self.recordingJourneyID = nil + self.isRecording = false return .success(responseDTO.id) case .failure(let error): return .failure(error) diff --git a/iOS/MSUIKit/Sources/MSUIKit/Cells/JourneyCell/JourneyCell.swift b/iOS/MSUIKit/Sources/MSUIKit/Cells/JourneyCell/JourneyCell.swift index d95b160..4b5b148 100644 --- a/iOS/MSUIKit/Sources/MSUIKit/Cells/JourneyCell/JourneyCell.swift +++ b/iOS/MSUIKit/Sources/MSUIKit/Cells/JourneyCell/JourneyCell.swift @@ -80,6 +80,8 @@ public final class JourneyCell: UICollectionViewCell { @MainActor public func addImageView(count: Int) { + guard count != .zero else { return } + (1...count).forEach { _ in let imageView = SpotPhotoImageView() self.spotImageStack.addArrangedSubview(imageView)