264 lines
13 KiB
Swift
264 lines
13 KiB
Swift
//
|
|
// SettingsView.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 2023/08/10.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SettingsView: View {
|
|
@State private var isShowLogoutDialog = false
|
|
@State private var isShowLogoutAllDeviceDialog = false
|
|
|
|
@StateObject var viewModel = SettingsViewModel()
|
|
@StateObject var recentContentViewModel = RecentContentViewModel()
|
|
|
|
var body: some View {
|
|
let cardWidth = screenSize().width - 26.7
|
|
let isAuth = UserDefaults.bool(forKey: .auth)
|
|
let normalizedCountryCode = UserDefaults
|
|
.string(forKey: .countryCode)
|
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
.uppercased()
|
|
let isNonKoreanCountry = !normalizedCountryCode.isEmpty && normalizedCountryCode != "KR"
|
|
|
|
BaseView(isLoading: $viewModel.isLoading) {
|
|
GeometryReader { geo in
|
|
VStack(spacing: 0) {
|
|
DetailNavigationBar(title: I18n.Settings.title)
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
VStack(spacing: 0) {
|
|
VStack(spacing: 0) {
|
|
HStack(spacing: 0) {
|
|
Text(I18n.Settings.notificationSettings)
|
|
.appFont(size: 14.7, weight: .bold)
|
|
.foregroundColor(Color.grayee)
|
|
|
|
Spacer()
|
|
|
|
Image("ic_forward")
|
|
.resizable()
|
|
.frame(width: 20, height: 20)
|
|
}
|
|
.padding(.horizontal, 3.3)
|
|
.frame(width: cardWidth - 26.7, height: 50)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .notificationSettings)
|
|
}
|
|
|
|
Rectangle()
|
|
.frame(width: cardWidth - 26.7, height: 0.3)
|
|
.foregroundColor(Color.gray90)
|
|
|
|
HStack(spacing: 0) {
|
|
Text(I18n.Settings.languageSettings)
|
|
.appFont(size: 14.7, weight: .bold)
|
|
.foregroundColor(Color.grayee)
|
|
|
|
Spacer()
|
|
|
|
Image("ic_forward")
|
|
.resizable()
|
|
.frame(width: 20, height: 20)
|
|
}
|
|
.padding(.horizontal, 3.3)
|
|
.frame(width: cardWidth - 26.7, height: 50)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .languageSettings)
|
|
}
|
|
|
|
if isAuth || isNonKoreanCountry {
|
|
Rectangle()
|
|
.frame(width: cardWidth - 26.7, height: 0.3)
|
|
.foregroundColor(Color.gray90)
|
|
|
|
HStack(spacing: 0) {
|
|
Text(I18n.Settings.contentViewSettings)
|
|
.appFont(size: 14.7, weight: .bold)
|
|
.foregroundColor(Color.grayee)
|
|
|
|
Spacer()
|
|
|
|
Image("ic_forward")
|
|
.resizable()
|
|
.frame(width: 20, height: 20)
|
|
}
|
|
.padding(.horizontal, 3.3)
|
|
.frame(width: cardWidth - 26.7, height: 50)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .contentViewSettings)
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, 13.3)
|
|
.frame(width: cardWidth)
|
|
.background(Color.gray22)
|
|
.cornerRadius(6.7)
|
|
.padding(.top, 26.7)
|
|
|
|
VStack(spacing: 0) {
|
|
HStack(spacing: 0) {
|
|
Text(I18n.Settings.termsOfService)
|
|
.appFont(size: 14.7, weight: .bold)
|
|
.foregroundColor(Color.grayee)
|
|
|
|
Spacer()
|
|
|
|
Image("ic_forward")
|
|
.resizable()
|
|
.frame(width: 20, height: 20)
|
|
}
|
|
.padding(.horizontal, 3.3)
|
|
.frame(width: cardWidth - 26.7, height: 50)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .terms)
|
|
}
|
|
|
|
Rectangle()
|
|
.frame(width: cardWidth - 26.7, height: 0.3)
|
|
.foregroundColor(Color.gray90)
|
|
|
|
HStack(spacing: 0) {
|
|
Text(I18n.Settings.privacyPolicy)
|
|
.appFont(size: 14.7, weight: .bold)
|
|
.foregroundColor(Color.grayee)
|
|
|
|
Spacer()
|
|
|
|
Image("ic_forward")
|
|
.resizable()
|
|
.frame(width: 20, height: 20)
|
|
}
|
|
.padding(.horizontal, 3.3)
|
|
.frame(width: cardWidth - 26.7, height: 50)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .privacy)
|
|
}
|
|
}
|
|
.padding(.horizontal, 13.3)
|
|
.frame(width: cardWidth)
|
|
.background(Color.gray22)
|
|
.cornerRadius(6.7)
|
|
.padding(.top, 13.3)
|
|
|
|
HStack(spacing: 0) {
|
|
Text(I18n.Settings.appVersionInfo)
|
|
.appFont(size: 14.7, weight: .bold)
|
|
.foregroundColor(Color.grayee)
|
|
|
|
Spacer()
|
|
|
|
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
|
|
|
|
Text("Ver \(version!)")
|
|
.appFont(size: 13.3, weight: .medium)
|
|
.foregroundColor(Color.grayee)
|
|
}
|
|
.padding(.horizontal, 16.7)
|
|
.frame(width: cardWidth, height: 50)
|
|
.background(Color.gray22)
|
|
.cornerRadius(6.7)
|
|
.padding(.top, 13.3)
|
|
|
|
Text(I18n.Settings.companyInfo)
|
|
.appFont(size: 11, weight: .medium)
|
|
.foregroundColor(Color.gray77)
|
|
.frame(width: cardWidth, alignment: .leading)
|
|
.padding(.top, 13.3)
|
|
|
|
Text(I18n.Settings.logout)
|
|
.appFont(size: 14.7, weight: .bold)
|
|
.foregroundColor(Color.grayee)
|
|
.frame(width: cardWidth, height: 50)
|
|
.background(Color.gray22)
|
|
.cornerRadius(6.7)
|
|
.onTapGesture {
|
|
isShowLogoutDialog = true
|
|
}
|
|
.padding(.top, 46.7)
|
|
|
|
Text(I18n.Settings.logoutAllDevices)
|
|
.appFont(size: 14.7, weight: .medium)
|
|
.foregroundColor(Color.gray77)
|
|
.padding(.top, 13.3)
|
|
.onTapGesture {
|
|
isShowLogoutAllDeviceDialog = true
|
|
}
|
|
|
|
Text(I18n.Settings.signOut)
|
|
.appFont(size: 14.7, weight: .medium)
|
|
.foregroundColor(Color.gray77)
|
|
.underline()
|
|
.padding(.vertical, 26.7)
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .signOut)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if isShowLogoutDialog {
|
|
SodaDialog(
|
|
title: I18n.Settings.alertTitle,
|
|
desc: I18n.Settings.logoutQuestion,
|
|
confirmButtonTitle: I18n.Common.confirm,
|
|
confirmButtonAction: {
|
|
ContentPlayManager.shared.stopAudio()
|
|
ContentPlayerPlayManager.shared.resetPlayer()
|
|
viewModel.logout {
|
|
self.isShowLogoutDialog = false
|
|
|
|
UserDefaults.reset()
|
|
recentContentViewModel.truncate()
|
|
|
|
AppState.shared.isRestartApp = true
|
|
AppState.shared.setAppStep(step: .splash)
|
|
}
|
|
},
|
|
cancelButtonTitle: I18n.Common.cancel,
|
|
cancelButtonAction: {
|
|
self.isShowLogoutDialog = false
|
|
}
|
|
)
|
|
}
|
|
|
|
if isShowLogoutAllDeviceDialog {
|
|
SodaDialog(
|
|
title: I18n.Settings.alertTitle,
|
|
desc: I18n.Settings.logoutAllQuestion,
|
|
confirmButtonTitle: I18n.Common.confirm,
|
|
confirmButtonAction: {
|
|
ContentPlayManager.shared.stopAudio()
|
|
ContentPlayerPlayManager.shared.resetPlayer()
|
|
viewModel.logoutAllDevice {
|
|
self.isShowLogoutAllDeviceDialog = false
|
|
UserDefaults.reset()
|
|
AppState.shared.isRestartApp = true
|
|
AppState.shared.setAppStep(step: .splash)
|
|
}
|
|
},
|
|
cancelButtonTitle: I18n.Common.cancel,
|
|
cancelButtonAction: {
|
|
self.isShowLogoutAllDeviceDialog = false
|
|
}
|
|
)
|
|
}
|
|
}
|
|
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2)
|
|
}
|
|
}
|
|
|
|
struct SettingsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SettingsView()
|
|
}
|
|
}
|