Skip to content

Commit

Permalink
#159 #160 feat: 다크모드 로직을 DarkModeManager로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
LEEYOONJONG committed Dec 6, 2022
1 parent 34f46b0 commit 64c1ac3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
12 changes: 12 additions & 0 deletions Segno/Segno.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
7940FB31292E065100276EFC /* DiaryDetailEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7940FB30292E065100276EFC /* DiaryDetailEndpoint.swift */; };
7940FB33292E065F00276EFC /* DiaryDetailUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */; };
79767E64293E2A1200E489DD /* DiaryDeleteEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79767E63293E2A1200E489DD /* DiaryDeleteEndpoint.swift */; };
98003E0E293F20F6009FBC35 /* DarkModeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98003E0D293F20F6009FBC35 /* DarkModeManager.swift */; };
9825F41B29377875005F2163 /* ChangeNicknameUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41A29377875005F2163 /* ChangeNicknameUseCase.swift */; };
9825F41D29377ACF005F2163 /* SettingsRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41C29377ACF005F2163 /* SettingsRepository.swift */; };
982A2A472924AE74006F6ACD /* UserDefaultsKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */; };
Expand Down Expand Up @@ -162,6 +163,7 @@
7940FB30292E065100276EFC /* DiaryDetailEndpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailEndpoint.swift; sourceTree = "<group>"; };
7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailUseCase.swift; sourceTree = "<group>"; };
79767E63293E2A1200E489DD /* DiaryDeleteEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDeleteEndpoint.swift; sourceTree = "<group>"; };
98003E0D293F20F6009FBC35 /* DarkModeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DarkModeManager.swift; sourceTree = "<group>"; };
9825F41A29377875005F2163 /* ChangeNicknameUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeNicknameUseCase.swift; sourceTree = "<group>"; };
9825F41C29377ACF005F2163 /* SettingsRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRepository.swift; sourceTree = "<group>"; };
982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsKey.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -253,6 +255,7 @@
4F317791291BEB490019BDFC /* Data */ = {
isa = PBXGroup;
children = (
98003E0C293F20E7009FBC35 /* Manager */,
4FCAC5C3292B792200BF9CDD /* Session */,
4F3177A0291BF1810019BDFC /* Repository */,
4F31779F291BF1780019BDFC /* Network */,
Expand Down Expand Up @@ -477,6 +480,14 @@
path = Font;
sourceTree = "<group>";
};
98003E0C293F20E7009FBC35 /* Manager */ = {
isa = PBXGroup;
children = (
98003E0D293F20F6009FBC35 /* DarkModeManager.swift */,
);
path = Manager;
sourceTree = "<group>";
};
9894EAF629375272005F2B15 /* Utility */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -592,6 +603,7 @@
66A8CF6D29379A9900C17F84 /* UserDetailEndpoint.swift in Sources */,
4FEBFAAD291CF62E00E78139 /* DiaryDetail.swift in Sources */,
4FEBFAB1291CFB5500E78139 /* SHMediaItem+.swift in Sources */,
98003E0E293F20F6009FBC35 /* DarkModeManager.swift in Sources */,
66A8CF692937945300C17F84 /* UserDetailUseCase.swift in Sources */,
988414AE2922235B007C9132 /* LocalUtilityRepository.swift in Sources */,
66A8CF612935F44100C17F84 /* MyPageViewModel.swift in Sources */,
Expand Down
41 changes: 41 additions & 0 deletions Segno/Segno/Data/Manager/DarkModeManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DarkModeManager.swift
// Segno
//
// Created by YOONJONG on 2022/12/06.
//

import UIKit

import RxSwift

class DarkModeManager {
static let shared = DarkModeManager()

let repository: LocalUtilityRepository

private init() {
self.repository = LocalUtilityRepositoryImpl()
}

func getDarkMode() -> Int {
if let mode = repository.getUserDefaultsObject(forKey: .darkmode) as? Int {
debugPrint("SettingsUseCase - getDarkMode : 키가 있습니다 - \(mode)")
return mode
} else {
repository.setUserDefaults(DarkMode.system.rawValue, forKey: .darkmode)
debugPrint("SettingsUseCase - getDarkMode : 키가 없어 \(DarkMode.system.rawValue) 로 설정합니다.")
return DarkMode.system.rawValue
}
}

func changeDarkMode(to mode: Int) {
repository.setUserDefaults(mode, forKey: .darkmode)
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else { return }

window.overrideUserInterfaceStyle = UIUserInterfaceStyle(rawValue: mode) ?? .unspecified
debugPrint("SettingsUseCase - changeDarkMode : \(mode)로 설정")

}
}
20 changes: 4 additions & 16 deletions Segno/Segno/Domain/UseCase/SettingsUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protocol SettingsUseCase {
func getAutoPlayMode() -> Bool
func changeAutoPlayMode(to mode: Bool)
func getDarkMode() -> Int
func changeDarkMode(to mode: Int) -> Single<Int>
func changeDarkMode(to mode: Int)
}

final class SettingsUseCaseImpl: SettingsUseCase {
Expand Down Expand Up @@ -39,22 +39,10 @@ final class SettingsUseCaseImpl: SettingsUseCase {
}

func getDarkMode() -> Int {
if let mode = repository.getUserDefaultsObject(forKey: .darkmode) as? Int {
debugPrint("SettingsUseCase - getDarkMode : 키가 있습니다 - \(mode)")
return mode
} else {
repository.setUserDefaults(DarkMode.system.rawValue, forKey: .darkmode)
debugPrint("SettingsUseCase - getDarkMode : 키가 없어 \(DarkMode.system.rawValue) 로 설정합니다.")
return DarkMode.system.rawValue
}
return DarkModeManager.shared.getDarkMode()
}

func changeDarkMode(to mode: Int) -> Single<Int> {
repository.setUserDefaults(mode, forKey: .darkmode)
debugPrint("SettingsUseCase - changeDarkMode : \(mode)로 설정")
return Single.create { observer in
observer(.success(mode))
return Disposables.create()
}
func changeDarkMode(to mode: Int) {
DarkModeManager.shared.changeDarkMode(to: mode)
}
}
4 changes: 2 additions & 2 deletions Segno/Segno/Presentation/ViewModel/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class SettingsViewModel {
return settingsUseCase.getDarkMode()
}

func changeDarkMode(to mode: Int) -> Single<Int> {
return settingsUseCase.changeDarkMode(to: mode)
func changeDarkMode(to mode: Int) {
settingsUseCase.changeDarkMode(to: mode)
}
}

0 comments on commit 64c1ac3

Please sign in to comment.