-
Notifications
You must be signed in to change notification settings - Fork 2
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
SettingsUseCase 및 ChangeUserNameUseCase 작성 #129
Changes from all commits
36f068a
6d2002f
7cbf069
af236d8
9908d4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// SettingsRepository.swift | ||
// Segno | ||
// | ||
// Created by YOONJONG on 2022/11/30. | ||
// | ||
|
||
import RxSwift | ||
|
||
protocol SettingsRepository { | ||
|
||
} | ||
|
||
final class SettingsRepositoryImpl: SettingsRepository { | ||
|
||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ChangeUserNameUseCase.swift | ||
// Segno | ||
// | ||
// Created by YOONJONG on 2022/11/30. | ||
// | ||
|
||
import RxSwift | ||
|
||
protocol ChangeUserNameUseCase { | ||
func requestChangeNickname(to nickname: String) -> Bool | ||
} | ||
|
||
final class ChangeUserNameUseCaseImpl: ChangeUserNameUseCase { | ||
let repository: SettingsRepository | ||
private let disposeBag = DisposeBag() | ||
|
||
init(repository: SettingsRepository = SettingsRepositoryImpl()) { | ||
self.repository = repository | ||
} | ||
|
||
func requestChangeNickname(to nickname: String) -> Bool { | ||
// 임시 처리입니다. | ||
debugPrint("SettingsUseCase - requestChangeNickname : \(nickname)으로 변경") | ||
return true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// SettingsUseCase.swift | ||
// Segno | ||
// | ||
// Created by YOONJONG on 2022/11/30. | ||
// | ||
|
||
import RxSwift | ||
|
||
protocol SettingsUseCase { | ||
func getAutoPlayMode() -> Bool | ||
func changeAutoPlayMode(to mode: Bool) | ||
func getDarkMode() -> Int | ||
func changeDarkMode(to mode: Int) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 처음엔 change to dark mode여야 하지 않나 했습니다만, 생각해 보니 두 가지가 아닌 세 가지의 상태가 있었죠. 문제없어보입니다. |
||
} | ||
|
||
final class SettingsUseCaseImpl: SettingsUseCase { | ||
let repository: LocalUtilityRepository | ||
private let disposeBag = DisposeBag() | ||
|
||
init(repository: LocalUtilityRepository = LocalUtilityRepositoryImpl()) { | ||
self.repository = repository | ||
} | ||
|
||
func getAutoPlayMode() -> Bool { | ||
if let isEnabled = repository.getUserDefaultsObject(forKey: .isAutoPlayEnabled) as? Bool { | ||
debugPrint("SettingsUseCase - getAutoPlayMode : 키가 있습니다 - \(isEnabled)") | ||
return isEnabled | ||
} else { | ||
repository.setUserDefaults(true, forKey: .isAutoPlayEnabled) | ||
debugPrint("SettingsUseCase - getAutoPlayMode : 키가 없어 true 로 설정합니다.") | ||
return true | ||
} | ||
} | ||
|
||
func changeAutoPlayMode(to mode: Bool) { | ||
repository.setUserDefaults(mode, forKey: .isAutoPlayEnabled) | ||
debugPrint("SettingsUseCase - changeAutoPlayMode : \(mode)로 설정") | ||
} | ||
|
||
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) | ||
debugPrint("SettingsUseCase - changeDarkMode : \(mode)로 설정") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// DarkMode.swift | ||
// Segno | ||
// | ||
// Created by YOONJONG on 2022/11/30. | ||
// | ||
|
||
import Foundation | ||
|
||
enum DarkMode: Int, CaseIterable { | ||
case system | ||
case light | ||
case dark | ||
|
||
var title: String { | ||
switch self { | ||
case .system: | ||
return "시스템 설정" | ||
case .light: | ||
return "항상 밝게" | ||
case .dark: | ||
return "항상 어둡게" | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 분리되어 있으니 깔끔하네요! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,49 +10,43 @@ import Foundation | |
import RxSwift | ||
|
||
final class SettingsViewModel { | ||
let dataSource = Observable<[SettingsCellModel]>.just([ | ||
lazy var dataSource = Observable<[SettingsCellModel]>.just([ | ||
.nickname, | ||
.settingsSwitch(title: "음악 자동 재생", isOn: true), // TODO: isOn은 로컬 디비로부터 불러와야 합니다. | ||
.settingsActionSheet(title: "다크 모드") | ||
.settingsSwitch(title: "음악 자동 재생", isOn: settingsUseCase.getAutoPlayMode()), | ||
.settingsActionSheet(title: "다크 모드", mode: settingsUseCase.getDarkMode()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 데이터 소스의 해법을 이렇게 찾으셨군요..! 어쩌면 이것이 PublishSubject보다 좋을지도 모르겠습니다. |
||
]) | ||
|
||
init() { | ||
|
||
private let settingsUseCase: SettingsUseCase | ||
private let changeUserNameUseCase: ChangeUserNameUseCase | ||
|
||
init(settingsUseCase: SettingsUseCase = SettingsUseCaseImpl(), | ||
changeUserNameUseCase: ChangeUserNameUseCase = ChangeUserNameUseCaseImpl() | ||
) { | ||
self.settingsUseCase = settingsUseCase | ||
self.changeUserNameUseCase = changeUserNameUseCase | ||
} | ||
|
||
// TODO: 닉네임 변경 로직 | ||
func changeNickname(to nickname: String) -> Observable<Bool> { | ||
// return useCase.requestChangeNickname(to: nickname) | ||
|
||
// 임시 처리입니다. | ||
return Observable.create { emitter in | ||
emitter.onNext(true) | ||
let result = self.changeUserNameUseCase.requestChangeNickname(to: nickname) | ||
emitter.onNext(result) | ||
return Disposables.create() | ||
} | ||
} | ||
|
||
// TODO: 음악 자동 재생 여부 불러오기 / 클릭 시 반영하기 | ||
func getAutoPlayMode() -> Bool { | ||
// return useCase.getAutoPlayMode() | ||
|
||
return true | ||
return settingsUseCase.getAutoPlayMode() | ||
} | ||
|
||
func changeAutoPlayMode(to mode: Bool) { | ||
// useCase.changeAutoPlayMode(to: mode) | ||
|
||
debugPrint("changeAutoPlayMode에서 \(mode)로 변경합니다") | ||
settingsUseCase.changeAutoPlayMode(to: mode) | ||
} | ||
|
||
// TODO: 다크모드 설정 불러오기 / 액션 시트 선택 시 반영하기 | ||
func getDarkMode() -> Int { | ||
// return useCase.getDarkMode() | ||
|
||
return 0 | ||
return settingsUseCase.getDarkMode() | ||
} | ||
|
||
func changeDarkMode(to mode: Int) { | ||
// TODO: 액션 시트를 띄워야 합니다. | ||
debugPrint("changeDarkMode에서 \(mode)로 변경합니다") | ||
settingsUseCase.changeDarkMode(to: mode) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구조 바꾼 대로 잘 반영해 주셨군요, 좋습니다.