diff --git a/SodaLive/Resources/Assets.xcassets/btn_audition_notification_normal.imageset/Contents.json b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_normal.imageset/Contents.json new file mode 100644 index 0000000..1880b04 --- /dev/null +++ b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_normal.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "btn_audition_notification_normal.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SodaLive/Resources/Assets.xcassets/btn_audition_notification_normal.imageset/btn_audition_notification_normal.png b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_normal.imageset/btn_audition_notification_normal.png new file mode 100644 index 0000000..c178d15 Binary files /dev/null and b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_normal.imageset/btn_audition_notification_normal.png differ diff --git a/SodaLive/Resources/Assets.xcassets/btn_audition_notification_selected.imageset/Contents.json b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_selected.imageset/Contents.json new file mode 100644 index 0000000..a6140d8 --- /dev/null +++ b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_selected.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "btn_audition_notification_selected.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SodaLive/Resources/Assets.xcassets/btn_audition_notification_selected.imageset/btn_audition_notification_selected.png b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_selected.imageset/btn_audition_notification_selected.png new file mode 100644 index 0000000..cb999c1 Binary files /dev/null and b/SodaLive/Resources/Assets.xcassets/btn_audition_notification_selected.imageset/btn_audition_notification_selected.png differ diff --git a/SodaLive/Sources/Audition/AuditionView.swift b/SodaLive/Sources/Audition/AuditionView.swift index e1ba075..03d2aea 100644 --- a/SodaLive/Sources/Audition/AuditionView.swift +++ b/SodaLive/Sources/Audition/AuditionView.swift @@ -10,11 +10,17 @@ import SwiftUI struct AuditionView: View { @StateObject var viewModel = AuditionViewModel() + @AppStorage("isAuditionNotification") private var isAuditionNotification: Bool = UserDefaults.bool(forKey: .isAuditionNotification) var body: some View { BaseView(isLoading: $viewModel.isLoading) { VStack(spacing: 0) { - HomeNavigationBar(title: "오디션") {} + HomeNavigationBar(title: "오디션") { + Image(isAuditionNotification ? "btn_audition_notification_selected" : "btn_audition_notification_normal") + .onTapGesture { + viewModel.updateNotificationSettings() + } + } ScrollView(.vertical, showsIndicators: false) { LazyVStack(alignment: .leading, spacing: 25) { diff --git a/SodaLive/Sources/Audition/AuditionViewModel.swift b/SodaLive/Sources/Audition/AuditionViewModel.swift index ae18024..a259f20 100644 --- a/SodaLive/Sources/Audition/AuditionViewModel.swift +++ b/SodaLive/Sources/Audition/AuditionViewModel.swift @@ -11,6 +11,7 @@ import Combine final class AuditionViewModel: ObservableObject { private let repository = AuditionRepository() + private let userRepository = UserRepository() private var subscription = Set() @Published var errorMessage = "" @@ -80,4 +81,30 @@ final class AuditionViewModel: ObservableObject { .store(in: &subscription) } } + + func updateNotificationSettings() { + let isAuditionNotification = UserDefaults.bool(forKey: .isAuditionNotification) + + userRepository.updateNotificationSettings(audition: !isAuditionNotification) + .sink { result in + switch result { + case .finished: + DEBUG_LOG("finish") + case .failure(let error): + ERROR_LOG(error.localizedDescription) + } + } receiveValue: { response in + let responseData = response.data + + do { + let jsonDecoder = JSONDecoder() + let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData) + + if decoded.success { + UserDefaults.set(!isAuditionNotification, forKey: .isAuditionNotification) + } + } catch {} + } + .store(in: &subscription) + } } diff --git a/SodaLive/Sources/Extensions/UserDefaultsExtension.swift b/SodaLive/Sources/Extensions/UserDefaultsExtension.swift index 1f03f75..51379c7 100644 --- a/SodaLive/Sources/Extensions/UserDefaultsExtension.swift +++ b/SodaLive/Sources/Extensions/UserDefaultsExtension.swift @@ -25,6 +25,7 @@ enum UserDefaultsKey: String, CaseIterable { case notShowingEventPopupId case isAdultContentVisible case contentPreference + case isAuditionNotification } extension UserDefaults { diff --git a/SodaLive/Sources/Main/Home/HomeViewModel.swift b/SodaLive/Sources/Main/Home/HomeViewModel.swift index 1cfd66e..6e332a1 100644 --- a/SodaLive/Sources/Main/Home/HomeViewModel.swift +++ b/SodaLive/Sources/Main/Home/HomeViewModel.swift @@ -92,6 +92,7 @@ final class HomeViewModel: ObservableObject { UserDefaults.set(data.can, forKey: .can) UserDefaults.set(data.isAuth, forKey: .auth) UserDefaults.set(data.role.rawValue, forKey: .role) + UserDefaults.set(data.auditionNotice ?? false, forKey: .isAuditionNotification) if data.followingChannelLiveNotice == nil && data.followingChannelUploadContentNotice == nil && data.messageNotice == nil { AppState.shared.isShowNotificationSettingsDialog = true } diff --git a/SodaLive/Sources/Settings/Notification/GetMemberInfoResponse.swift b/SodaLive/Sources/Settings/Notification/GetMemberInfoResponse.swift index c7be304..ba6b933 100644 --- a/SodaLive/Sources/Settings/Notification/GetMemberInfoResponse.swift +++ b/SodaLive/Sources/Settings/Notification/GetMemberInfoResponse.swift @@ -18,4 +18,5 @@ struct GetMemberInfoResponse: Decodable { let messageNotice: Bool? let followingChannelLiveNotice: Bool? let followingChannelUploadContentNotice: Bool? + let auditionNotice: Bool? } diff --git a/SodaLive/Sources/Settings/Notification/UpdateNotificationSettingRequest.swift b/SodaLive/Sources/Settings/Notification/UpdateNotificationSettingRequest.swift index f150a88..a33e101 100644 --- a/SodaLive/Sources/Settings/Notification/UpdateNotificationSettingRequest.swift +++ b/SodaLive/Sources/Settings/Notification/UpdateNotificationSettingRequest.swift @@ -11,4 +11,5 @@ struct UpdateNotificationSettingRequest: Encodable { var live: Bool? = nil var uploadContent: Bool? = nil var message: Bool? = nil + var audition: Bool? = nil } diff --git a/SodaLive/Sources/User/UserRepository.swift b/SodaLive/Sources/User/UserRepository.swift index 1ab68b0..29cf755 100644 --- a/SodaLive/Sources/User/UserRepository.swift +++ b/SodaLive/Sources/User/UserRepository.swift @@ -41,13 +41,14 @@ final class UserRepository { return api.requestPublisher(.getMemberInfo) } - func updateNotificationSettings(live: Bool? = nil, uploadContent: Bool? = nil, message: Bool? = nil) -> AnyPublisher { + func updateNotificationSettings(live: Bool? = nil, uploadContent: Bool? = nil, message: Bool? = nil, audition: Bool? = nil) -> AnyPublisher { return api.requestPublisher( .notification( request: UpdateNotificationSettingRequest( live: live, uploadContent: uploadContent, - message: message + message: message, + audition: audition ) ) )