606 lines
23 KiB
Swift
606 lines
23 KiB
Swift
//
|
|
// MyPageView.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 2023/08/09.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
import Bootpay
|
|
import Kingfisher
|
|
import RefreshableScrollView
|
|
|
|
struct MyPageView: View {
|
|
|
|
@Environment(\.locale) private var locale
|
|
|
|
@StateObject var viewModel = MyPageViewModel()
|
|
@StateObject var recentContentViewModel = RecentContentViewModel()
|
|
|
|
@State private var payload = Payload()
|
|
@AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
|
|
|
|
var body: some View {
|
|
let normalizedCountryCode = UserDefaults
|
|
.string(forKey: .countryCode)
|
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
.uppercased()
|
|
let isKoreanCountry = normalizedCountryCode.isEmpty || normalizedCountryCode == "KR"
|
|
let shouldShowCouponRegister = isKoreanCountry || UserDefaults.isAdultContentVisible()
|
|
|
|
BaseView(isLoading: $viewModel.isLoading) {
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty &&
|
|
viewModel.isShowAuthView {
|
|
AuthVerificationView(
|
|
payload: payload,
|
|
onCancel: {},
|
|
onError: {
|
|
viewModel.errorMessage = I18n.Main.Auth.authenticationError
|
|
viewModel.isShowPopup = true
|
|
viewModel.isShowAuthView = false
|
|
},
|
|
onDone: {
|
|
viewModel.authVerify($0)
|
|
viewModel.isShowAuthView = false
|
|
viewModel.presentAuthContentSettings()
|
|
},
|
|
onClose: {
|
|
viewModel.isShowAuthView = false
|
|
}
|
|
)
|
|
} else {
|
|
VStack(spacing: 0) {
|
|
// Header
|
|
MyPageHeaderView(
|
|
isShowButton: !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
|
)
|
|
|
|
if !viewModel.latestNotices.isEmpty {
|
|
// Update Banner
|
|
UpdateBannerView(items: viewModel.latestNotices)
|
|
}
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
VStack(spacing: 32) {
|
|
// Profile Section
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
ProfileSectionView(
|
|
nickname: viewModel.nickname,
|
|
profileUrl: viewModel.profileUrl
|
|
) {
|
|
viewModel.getMypage()
|
|
}
|
|
.padding(.horizontal, 24)
|
|
} else {
|
|
HStack {
|
|
Text(I18n.MyPage.Main.login)
|
|
.appFont(size: 32, weight: .bold)
|
|
.foregroundColor(Color.gray77)
|
|
}
|
|
.padding(.vertical, 12)
|
|
.frame(maxWidth: .infinity)
|
|
.background(Color.gray22)
|
|
.cornerRadius(16)
|
|
.padding(.horizontal, 24)
|
|
.onTapGesture {
|
|
AppState.shared
|
|
.setAppStep(step: .login)
|
|
}
|
|
}
|
|
|
|
if UserDefaults.string(forKey: .role) == MemberRole.CREATOR.rawValue {
|
|
Text(I18n.MyPage.Main.viewMyChannel)
|
|
.appFont(size: 16, weight: .bold)
|
|
.foregroundColor(Color.white)
|
|
.padding(.vertical, 12)
|
|
.frame(maxWidth: .infinity)
|
|
.background(Color.button)
|
|
.cornerRadius(16)
|
|
.padding(.horizontal, 24)
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .creatorDetail(userId: UserDefaults.int(forKey: .userId)))
|
|
}
|
|
}
|
|
|
|
// Can & Point Cards
|
|
CanPointCardsView(
|
|
can: viewModel.chargeCan + viewModel.rewardCan,
|
|
point: viewModel.point,
|
|
token: token,
|
|
refresh: { viewModel.getMypage() }
|
|
)
|
|
.padding(.horizontal, 24)
|
|
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
// Category Buttons
|
|
CategoryButtonsView(
|
|
isShowAuthView: $viewModel.isShowAuthView,
|
|
isAuthenticated: viewModel.isAuth,
|
|
isKoreanCountry: isKoreanCountry,
|
|
shouldShowCouponRegister: shouldShowCouponRegister,
|
|
showMessage: {
|
|
viewModel.errorMessage = $0
|
|
viewModel.isShowPopup = true
|
|
},
|
|
refresh: {
|
|
viewModel.getMypage()
|
|
}
|
|
)
|
|
.padding(.horizontal, 24)
|
|
}
|
|
|
|
if let url = URL(string: "https://forms.gle/5uBThHCf2iM84Vgp6"),
|
|
UIApplication.shared.canOpenURL(url) {
|
|
// SodaLive Banner
|
|
Image(locale.identifier.hasPrefix("ja") ? "img_apply_creator_ja" : "img_apply_creator")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.horizontal, 24)
|
|
.onTapGesture {
|
|
UIApplication.shared.open(url)
|
|
}
|
|
}
|
|
|
|
if let url = URL(string: "https://www.sodalive.net/services"),
|
|
UIApplication.shared.canOpenURL(url) {
|
|
// SodaLive Banner
|
|
Image(locale.identifier.hasPrefix("ja") ? "img_introduce_sodalive_ja" : "img_introduce_sodalive")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.horizontal, 24)
|
|
.onTapGesture {
|
|
UIApplication.shared.open(url)
|
|
}
|
|
}
|
|
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && !recentContentViewModel.recentContents.isEmpty {
|
|
// Recent 10 Section
|
|
RecentContentSection(recentContents: recentContentViewModel.recentContents)
|
|
}
|
|
}
|
|
.padding(.vertical, 32)
|
|
}
|
|
}
|
|
.background(Color(hex: "131313"))
|
|
.onAppear {
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
viewModel.getMypage()
|
|
recentContentViewModel.fetchRecentContents()
|
|
}
|
|
viewModel.getLatestNotices()
|
|
}
|
|
}
|
|
}
|
|
.authContentSettings(viewModel: viewModel)
|
|
.onAppear {
|
|
payload.applicationId = BOOTPAY_APP_ID
|
|
payload.price = 0
|
|
payload.pg = "다날"
|
|
payload.method = "본인인증"
|
|
payload.orderName = "본인인증"
|
|
payload.authenticationId = "\(UserDefaults.string(forKey: .nickname))__\(String(NSTimeIntervalSince1970))"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Header View
|
|
struct MyPageHeaderView: View {
|
|
|
|
let isShowButton: Bool
|
|
|
|
var body: some View {
|
|
HStack(spacing: 20) {
|
|
// Logo
|
|
Image("img_text_logo") // 로고 이미지 위치
|
|
|
|
Spacer()
|
|
|
|
if isShowButton {
|
|
HStack(spacing: 24) {
|
|
// Settings Icon
|
|
Image("ic_settings")
|
|
.foregroundColor(.white)
|
|
.frame(width: 24, height: 24)
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .settings)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, 24)
|
|
.padding(.vertical, 20)
|
|
}
|
|
}
|
|
|
|
// MARK: - Update Banner View
|
|
struct UpdateBannerView: View {
|
|
private static let foregroundColor = Color(hex: "B0BEC5")
|
|
private static let rollInterval: TimeInterval = 5
|
|
private static let transitionDuration: TimeInterval = 0.35
|
|
|
|
let items: [NoticeItem]
|
|
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
|
@State private var roller = MyPageNoticeRoller()
|
|
@State private var rollTimer: Timer?
|
|
@State private var isVisible = false
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
if let item = roller.current {
|
|
Button {
|
|
AppState.shared.setAppStep(step: .noticeDetail(notice: item))
|
|
} label: {
|
|
HStack(spacing: SodaSpacing.s8) {
|
|
ZStack {
|
|
Text(item.title)
|
|
.appFont(.body3)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.id(roller.index)
|
|
.transition(reduceMotion ? .identity : .asymmetric(
|
|
insertion: .move(edge: .bottom),
|
|
removal: .move(edge: .top)
|
|
))
|
|
}
|
|
.clipped()
|
|
|
|
Image(systemName: "chevron.right")
|
|
.frame(width: SodaSpacing.s24, height: SodaSpacing.s24)
|
|
.accessibilityHidden(true)
|
|
}
|
|
.foregroundColor(Self.foregroundColor)
|
|
.padding(.horizontal, SodaSpacing.s24)
|
|
.padding(.vertical, SodaSpacing.s6)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|
|
.clipped()
|
|
.background(Color.black)
|
|
.onAppear {
|
|
isVisible = true
|
|
roller.update(items)
|
|
restartRollTimer(scenePhase: scenePhase, reduceMotion: reduceMotion)
|
|
}
|
|
.onDisappear {
|
|
isVisible = false
|
|
stopRollTimer()
|
|
}
|
|
.onChange(of: items) { items in
|
|
roller.update(items)
|
|
restartRollTimer(scenePhase: scenePhase, reduceMotion: reduceMotion)
|
|
}
|
|
.onChange(of: scenePhase) { scenePhase in
|
|
restartRollTimer(scenePhase: scenePhase, reduceMotion: reduceMotion)
|
|
}
|
|
.onChange(of: reduceMotion) { reduceMotion in
|
|
restartRollTimer(scenePhase: scenePhase, reduceMotion: reduceMotion)
|
|
}
|
|
}
|
|
|
|
private func restartRollTimer(scenePhase: ScenePhase, reduceMotion: Bool) {
|
|
stopRollTimer()
|
|
guard roller.shouldRoll(isVisible: isVisible, isActive: scenePhase == .active) else { return }
|
|
|
|
rollTimer = Timer.scheduledTimer(withTimeInterval: Self.rollInterval, repeats: true) { _ in
|
|
withAnimation(reduceMotion ? nil : .easeOut(duration: Self.transitionDuration)) {
|
|
roller.advance()
|
|
}
|
|
}
|
|
}
|
|
|
|
private func stopRollTimer() {
|
|
rollTimer?.invalidate()
|
|
rollTimer = nil
|
|
}
|
|
}
|
|
|
|
// MARK: - Profile Section View
|
|
struct ProfileSectionView: View {
|
|
|
|
let nickname: String
|
|
let profileUrl: String
|
|
let refresh: () -> Void
|
|
|
|
var body: some View {
|
|
VStack(spacing: 16) {
|
|
HStack(spacing: 20) {
|
|
// Profile Image Placeholder
|
|
DownsampledKFImage(
|
|
url: URL(string: profileUrl),
|
|
size: CGSize(width: 64, height: 64)
|
|
)
|
|
.clipShape(Circle())
|
|
|
|
VStack(alignment: .leading) {
|
|
Text("\(nickname)")
|
|
.appFont(size: 18, weight: .bold)
|
|
.foregroundColor(.white)
|
|
}
|
|
|
|
Spacer()
|
|
|
|
Button(I18n.MyPage.Main.editProfile) {
|
|
if AppState.shared.roomId <= 0 {
|
|
AppState.shared.setAppStep(step: .profileUpdate(refresh: refresh))
|
|
}
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 6)
|
|
.background(Color(hex: "263238"))
|
|
.foregroundColor(.white)
|
|
.cornerRadius(9999)
|
|
.appFont(size: 16)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Can Point Cards View
|
|
struct CanPointCardsView: View {
|
|
|
|
let can: Int
|
|
let point: Int
|
|
let token: String
|
|
let refresh: () -> Void
|
|
|
|
var body: some View {
|
|
// Can & Point Cards
|
|
VStack(spacing: 0) {
|
|
// Can Card
|
|
HStack {
|
|
HStack(spacing: 8) {
|
|
Image("ic_can")
|
|
|
|
Text("\(can)")
|
|
.appFont(size: 18, weight: .bold)
|
|
.foregroundColor(.white)
|
|
|
|
Image(systemName: "chevron.right")
|
|
.foregroundColor(Color(hex: "B0BEC5"))
|
|
.frame(width: 24, height: 24)
|
|
}
|
|
.onTapGesture {
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
AppState.shared.setAppStep(step: .canStatus(refresh: refresh))
|
|
} else {
|
|
AppState.shared
|
|
.setAppStep(step: .login)
|
|
}
|
|
}
|
|
|
|
Spacer()
|
|
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
Button(I18n.MyPage.Can.chargeCansAction) {
|
|
AppState.shared.setAppStep(step: .canCharge(refresh: refresh))
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 11)
|
|
.background(Color.button)
|
|
.cornerRadius(9999)
|
|
.foregroundColor(.white)
|
|
.appFont(size: 16, weight: .bold)
|
|
} else {
|
|
Text("")
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 11)
|
|
.background(Color.clear)
|
|
.foregroundColor(.white)
|
|
.appFont(size: 16, weight: .bold)
|
|
}
|
|
}
|
|
.padding(15)
|
|
|
|
// Point Card
|
|
HStack {
|
|
HStack(spacing: 8) {
|
|
Image("ic_point")
|
|
|
|
Text("\(point)")
|
|
.appFont(size: 18, weight: .bold)
|
|
.foregroundColor(.white)
|
|
|
|
Image(systemName: "chevron.right")
|
|
.foregroundColor(Color(hex: "B0BEC5"))
|
|
.frame(width: 24, height: 24)
|
|
}
|
|
.onTapGesture {
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
AppState.shared.setAppStep(step: .pointStatus(refresh: refresh))
|
|
} else {
|
|
AppState.shared
|
|
.setAppStep(step: .login)
|
|
}
|
|
}
|
|
|
|
Spacer()
|
|
|
|
Text("")
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 11)
|
|
.background(Color.clear)
|
|
.foregroundColor(.white)
|
|
.appFont(size: 16, weight: .bold)
|
|
}
|
|
.padding(15)
|
|
}
|
|
.background(Color(hex: "263238"))
|
|
.cornerRadius(16)
|
|
}
|
|
}
|
|
|
|
// MARK: - Category Buttons View
|
|
struct CategoryButtonsView: View {
|
|
@Binding var isShowAuthView: Bool
|
|
|
|
let isAuthenticated: Bool
|
|
let isKoreanCountry: Bool
|
|
let shouldShowCouponRegister: Bool
|
|
let showMessage: (String) -> Void
|
|
let refresh: () -> Void
|
|
|
|
var body: some View {
|
|
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 4), spacing: 16) {
|
|
if isKoreanCountry && LanguageHeaderProvider.current == "ko" {
|
|
CategoryButtonItem(icon: "ic_my_present", title: I18n.MyPage.Category.giftBox) {
|
|
AppState.shared.setAppStep(step: .giftBoxList)
|
|
}
|
|
}
|
|
|
|
CategoryButtonItem(icon: "ic_my_storage", title: I18n.MyPage.Category.storage) {
|
|
AppState.shared.setAppStep(step: .myBox(currentTab: .orderlist))
|
|
}
|
|
|
|
CategoryButtonItem(icon: "ic_my_block", title: I18n.MyPage.Category.blockList) {
|
|
AppState.shared.setAppStep(step: .blockList)
|
|
}
|
|
|
|
if shouldShowCouponRegister {
|
|
CategoryButtonItem(
|
|
icon: "ic_my_coupon",
|
|
title: I18n.MyPage.Category.couponRegister
|
|
) {
|
|
if isAuthenticated || !isKoreanCountry {
|
|
AppState.shared.setAppStep(step: .canCoupon(refresh: refresh))
|
|
} else {
|
|
showMessage(I18n.MyPage.Auth.verifyRequiredBeforeCoupon)
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
isShowAuthView = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
CategoryButtonItem(icon: "ic_my_notice", title: I18n.MyPage.Category.notice) {
|
|
AppState.shared.setAppStep(step: .notices)
|
|
}
|
|
|
|
CategoryButtonItem(icon: "ic_my_event", title: I18n.MyPage.Category.event) {
|
|
AppState.shared.setAppStep(step: .events)
|
|
}
|
|
|
|
CategoryButtonItem(icon: "ic_my_service_center", title: I18n.MyPage.Category.customerCenter) {
|
|
AppState.shared.setAppStep(step: .serviceCenter)
|
|
}
|
|
|
|
if isKoreanCountry {
|
|
CategoryButtonItem(
|
|
icon: "ic_my_auth",
|
|
title: isAuthenticated ? I18n.MyPage.Auth.verified : I18n.Main.Auth.dialogTitle
|
|
) {
|
|
if !isAuthenticated {
|
|
isShowAuthView = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct CategoryButtonItem: View {
|
|
let icon: String
|
|
let title: String
|
|
let onClick: () -> Void
|
|
|
|
var body: some View {
|
|
VStack(spacing: 12) {
|
|
// Icon Placeholder
|
|
RoundedRectangle(cornerRadius: 16)
|
|
.foregroundColor(Color(hex: "15202F"))
|
|
.frame(width: 76, height: 76)
|
|
.overlay{
|
|
Image(icon)
|
|
}
|
|
|
|
Text(title)
|
|
.appFont(size: 14, weight: .regular)
|
|
.foregroundColor(.white)
|
|
}
|
|
.onTapGesture {
|
|
onClick()
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Recent 10 Content Section
|
|
struct RecentContentSection: View {
|
|
|
|
let recentContents: [RecentContent]
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 14) {
|
|
HStack(spacing: 0) {
|
|
Text(I18n.MyPage.Main.recentlyListenedPrefix)
|
|
.appFont(size: 16, weight: .bold)
|
|
.foregroundColor(Color(hex: "B0BEC5"))
|
|
|
|
Text("\(recentContents.count)")
|
|
.appFont(size: 16, weight: .bold)
|
|
.foregroundColor(Color(hex: "FDC118"))
|
|
}
|
|
.padding(.horizontal, 24)
|
|
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
LazyHStack(spacing: 16) {
|
|
ForEach(0..<recentContents.count, id: \.self) { index in
|
|
RecentItemView(content: recentContents[index])
|
|
}
|
|
}
|
|
.padding(.horizontal, 24)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct RecentItemView: View {
|
|
|
|
let content: RecentContent
|
|
|
|
var body: some View {
|
|
VStack(spacing: 8) {
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
DownsampledKFImage(
|
|
url: URL(string: content.coverImageUrl),
|
|
size: CGSize(width: 160, height: 160)
|
|
)
|
|
.cornerRadius(16)
|
|
|
|
Text(content.title)
|
|
.appFont(size: 18, weight: .regular)
|
|
.foregroundColor(.white)
|
|
.multilineTextAlignment(.leading)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.lineLimit(1)
|
|
.padding(.horizontal, 6)
|
|
.padding(.top, 8)
|
|
|
|
|
|
Text(content.creatorNickname)
|
|
.appFont(size: 14, weight: .regular)
|
|
.foregroundColor(Color(hex: "78909C"))
|
|
.lineLimit(1)
|
|
.padding(.horizontal, 6)
|
|
.padding(.top, 4)
|
|
}
|
|
.frame(width: 160)
|
|
.onTapGesture {
|
|
AppState.shared.setAppStep(step: .contentDetail(contentId: Int(content.contentId)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MyPageView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MyPageView()
|
|
}
|
|
}
|