feat(notification): 알림 수신 설정 페이지와 이동 경로를 추가한다
This commit is contained in:
@@ -41,6 +41,8 @@ enum AppStep {
|
||||
case privacy
|
||||
|
||||
case notificationSettings
|
||||
|
||||
case notificationReceiveSettings
|
||||
|
||||
case contentViewSettings
|
||||
|
||||
|
||||
@@ -147,6 +147,9 @@ struct AppStepLayerView: View {
|
||||
case .notificationSettings:
|
||||
NotificationSettingsView()
|
||||
|
||||
case .notificationReceiveSettings:
|
||||
NotificationReceiveSettingsView()
|
||||
|
||||
case .contentViewSettings:
|
||||
ContentSettingsView()
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ struct PushNotificationListView: View {
|
||||
Image("ic_bell_settings")
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
AppState.shared.setAppStep(step: .notificationSettings)
|
||||
AppState.shared.setAppStep(step: .notificationReceiveSettings)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
@@ -113,3 +113,219 @@ struct NotificationSettingsView_Previews: PreviewProvider {
|
||||
NotificationSettingsView()
|
||||
}
|
||||
}
|
||||
|
||||
struct NotificationReceiveSettingsView: View {
|
||||
|
||||
@StateObject var viewModel = NotificationReceiveSettingsViewModel()
|
||||
|
||||
@State private var isInitialized = false
|
||||
@State private var isShowFollowNotifyDialog = false
|
||||
@State private var creatorId = 0
|
||||
@State private var selectedItemIndex = -1
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: "알림 수신 설정")
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text("서비스 알림")
|
||||
.appFont(size: 16.7, weight: .bold)
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
.padding(.top, 26.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
VStack(spacing: 0) {
|
||||
NotificationReceiveServiceRowView(
|
||||
title: "라이브 알림",
|
||||
isOn: viewModel.followingChannelLive,
|
||||
onTapToggle: {
|
||||
viewModel.followingChannelLive.toggle()
|
||||
}
|
||||
)
|
||||
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(Color(hex: "909090").opacity(0.3))
|
||||
|
||||
NotificationReceiveServiceRowView(
|
||||
title: "콘텐츠 업로드 알림",
|
||||
isOn: viewModel.followingChannelUploadContent,
|
||||
onTapToggle: {
|
||||
viewModel.followingChannelUploadContent.toggle()
|
||||
}
|
||||
)
|
||||
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(Color(hex: "909090").opacity(0.3))
|
||||
|
||||
NotificationReceiveServiceRowView(
|
||||
title: "메시지 알림",
|
||||
isOn: viewModel.message,
|
||||
onTapToggle: {
|
||||
viewModel.message.toggle()
|
||||
}
|
||||
)
|
||||
}
|
||||
.padding(.vertical, 6.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
.background(Color(hex: "222222"))
|
||||
.cornerRadius(10)
|
||||
.padding(.top, 13.3)
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
Text("팔로잉 채널")
|
||||
.appFont(size: 16.7, weight: .bold)
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
.padding(.top, 26.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
HStack(spacing: 0) {
|
||||
Text("총")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
|
||||
Text(" \(viewModel.totalCount) ")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.mainRed3)
|
||||
|
||||
Text("명")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 13.3)
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
if viewModel.totalCount > 0 {
|
||||
VStack(spacing: 13.3) {
|
||||
ForEach(0..<viewModel.creatorList.count, id: \.self) { index in
|
||||
let creator = viewModel.creatorList[index]
|
||||
|
||||
FollowCreatorItemView(
|
||||
creator: creator,
|
||||
onClickFollow: {
|
||||
viewModel.creatorFollow(creatorId: $0, index: index)
|
||||
},
|
||||
showCreatorFollowNotifyDialog: {
|
||||
creatorId = $0
|
||||
selectedItemIndex = index
|
||||
isShowFollowNotifyDialog = true
|
||||
}
|
||||
)
|
||||
.padding(.horizontal, 20)
|
||||
.onTapGesture {
|
||||
AppState.shared
|
||||
.setAppStep(step: .creatorDetail(userId: creator.creatorId))
|
||||
}
|
||||
.onAppear {
|
||||
if index == viewModel.creatorList.count - 1 {
|
||||
viewModel.getFollowedCreatorAllList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.top, 13.3)
|
||||
} else {
|
||||
Text("팔로우 중인 채널이 없습니다.")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
.padding(.top, 13.3)
|
||||
.padding(.horizontal, 20)
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if !isInitialized {
|
||||
viewModel.initialize()
|
||||
isInitialized = true
|
||||
}
|
||||
}
|
||||
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
|
||||
GeometryReader { geo in
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(viewModel.errorMessage)
|
||||
.padding(.vertical, 13.3)
|
||||
.padding(.horizontal, 6.7)
|
||||
.frame(width: geo.size.width - 66.7, alignment: .center)
|
||||
.appFont(size: 12, weight: .medium)
|
||||
.background(Color(hex: "3bb9f1"))
|
||||
.foregroundColor(Color.white)
|
||||
.multilineTextAlignment(.leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(20)
|
||||
.padding(.top, 66.7)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if isShowFollowNotifyDialog {
|
||||
CreatorFollowNotifyDialog(
|
||||
isShowing: $isShowFollowNotifyDialog,
|
||||
onClickNotifyAll: {
|
||||
viewModel.creatorFollow(
|
||||
creatorId: creatorId,
|
||||
index: selectedItemIndex,
|
||||
follow: true,
|
||||
notify: true
|
||||
)
|
||||
creatorId = 0
|
||||
selectedItemIndex = -1
|
||||
},
|
||||
onClickNotifyNone: {
|
||||
viewModel.creatorFollow(
|
||||
creatorId: creatorId,
|
||||
index: selectedItemIndex,
|
||||
follow: true,
|
||||
notify: false
|
||||
)
|
||||
creatorId = 0
|
||||
selectedItemIndex = -1
|
||||
},
|
||||
onClickUnFollow: {
|
||||
viewModel.creatorFollow(
|
||||
creatorId: creatorId,
|
||||
index: selectedItemIndex,
|
||||
follow: false,
|
||||
notify: false
|
||||
)
|
||||
creatorId = 0
|
||||
selectedItemIndex = -1
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NotificationReceiveServiceRowView: View {
|
||||
|
||||
let title: String
|
||||
let isOn: Bool
|
||||
let onTapToggle: () -> Void
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
Text(title)
|
||||
.appFont(size: 15, weight: .bold)
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(isOn ? "btn_toggle_on_big" : "btn_toggle_off_big")
|
||||
.resizable()
|
||||
.frame(width: 44, height: 27)
|
||||
.onTapGesture {
|
||||
onTapToggle()
|
||||
}
|
||||
}
|
||||
.frame(height: 50)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,3 +91,243 @@ final class NotificationSettingsViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class NotificationReceiveSettingsViewModel: ObservableObject {
|
||||
|
||||
private let userRepository = UserRepository()
|
||||
private let followRepository = FollowCreatorRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var followingChannelLive = false {
|
||||
didSet {
|
||||
submit(live: followingChannelLive)
|
||||
}
|
||||
}
|
||||
|
||||
@Published var followingChannelUploadContent = false {
|
||||
didSet {
|
||||
submit(uploadContent: followingChannelUploadContent)
|
||||
}
|
||||
}
|
||||
|
||||
@Published var message = false {
|
||||
didSet {
|
||||
submit(message: message)
|
||||
}
|
||||
}
|
||||
|
||||
@Published var isLoading = false
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var creatorList = [GetCreatorFollowingAllListItem]()
|
||||
@Published var totalCount = 0
|
||||
|
||||
private var page = 1
|
||||
private var isLast = false
|
||||
private let pageSize = 20
|
||||
private var isMemberInfoLoading = false
|
||||
private var isFollowLoading = false
|
||||
|
||||
func initialize() {
|
||||
getMemberInfo()
|
||||
getFollowedCreatorAllList(reset: true)
|
||||
}
|
||||
|
||||
func getFollowedCreatorAllList(reset: Bool = false) {
|
||||
if reset {
|
||||
page = 1
|
||||
isLast = false
|
||||
totalCount = 0
|
||||
creatorList.removeAll()
|
||||
}
|
||||
|
||||
if isLast || isFollowLoading {
|
||||
return
|
||||
}
|
||||
|
||||
isFollowLoading = true
|
||||
updateLoading()
|
||||
|
||||
followRepository.getFollowedCreatorAllList(page: page, size: pageSize)
|
||||
.sink { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
|
||||
case .failure(let error):
|
||||
self.isFollowLoading = false
|
||||
self.updateLoading()
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.isFollowLoading = false
|
||||
self.updateLoading()
|
||||
|
||||
do {
|
||||
let decoded = try JSONDecoder().decode(
|
||||
ApiResponse<GetCreatorFollowingAllListResponse>.self,
|
||||
from: response.data
|
||||
)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
if self.page == 1 {
|
||||
self.creatorList.removeAll()
|
||||
}
|
||||
|
||||
self.totalCount = data.totalCount
|
||||
|
||||
if !data.items.isEmpty {
|
||||
self.page += 1
|
||||
self.creatorList.append(contentsOf: data.items)
|
||||
} else {
|
||||
self.isLast = true
|
||||
}
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func creatorFollow(creatorId: Int, index: Int, follow: Bool = true, notify: Bool = true) {
|
||||
if index < 0 || index >= creatorList.count {
|
||||
return
|
||||
}
|
||||
|
||||
isFollowLoading = true
|
||||
updateLoading()
|
||||
|
||||
userRepository.creatorFollow(creatorId: creatorId, follow: follow, notify: notify)
|
||||
.sink { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
|
||||
case .failure(let error):
|
||||
self.isFollowLoading = false
|
||||
self.updateLoading()
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.isFollowLoading = false
|
||||
self.updateLoading()
|
||||
|
||||
do {
|
||||
let decoded = try JSONDecoder().decode(ApiResponseWithoutData.self, from: response.data)
|
||||
|
||||
if decoded.success {
|
||||
var creator = self.creatorList[index]
|
||||
creator.isFollow = follow
|
||||
creator.isNotify = notify
|
||||
self.creatorList.remove(at: index)
|
||||
self.creatorList.insert(creator, at: index)
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func getMemberInfo() {
|
||||
isMemberInfoLoading = true
|
||||
updateLoading()
|
||||
|
||||
userRepository.getMemberInfo()
|
||||
.sink { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
|
||||
case .failure(let error):
|
||||
self.isMemberInfoLoading = false
|
||||
self.updateLoading()
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.isMemberInfoLoading = false
|
||||
self.updateLoading()
|
||||
|
||||
do {
|
||||
let decoded = try JSONDecoder().decode(ApiResponse<GetMemberInfoResponse>.self, from: response.data)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.followingChannelLive = data.followingChannelLiveNotice ?? false
|
||||
self.followingChannelUploadContent = data.followingChannelUploadContentNotice ?? false
|
||||
self.message = data.messageNotice ?? false
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func submit(live: Bool? = nil, uploadContent: Bool? = nil, message: Bool? = nil) {
|
||||
if isMemberInfoLoading || (live == nil && uploadContent == nil && message == nil) {
|
||||
return
|
||||
}
|
||||
|
||||
userRepository
|
||||
.updateNotificationSettings(live: live, uploadContent: uploadContent, message: message)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { _ in
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func updateLoading() {
|
||||
isLoading = isMemberInfoLoading || isFollowLoading
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user