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

[iOS] 여정 완료 후 홈으로 돌아가지 않는 현상 수정 #294

Merged
merged 3 commits into from
Dec 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 8 additions & 4 deletions iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions iOS/MSData/Sources/MSData/Repository/JourneyRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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?

Expand All @@ -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("기록 중인 여정 정보를 가져오는데 실패했습니다.")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading