Skip to content

Commit

Permalink
fix: 홈 애니메이션, 푸시알림 그리고 푸른수염의 아내
Browse files Browse the repository at this point in the history
  • Loading branch information
enebin committed Aug 19, 2023
1 parent dd0a3b2 commit adb5779
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 56 deletions.
Binary file modified Encrypted/Secrets/GoogleService-Info.plist.encrypted
Binary file not shown.
2 changes: 1 addition & 1 deletion Projects/Core/Util/Sources/KFImageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class KFImageManager {
public func toImage(url: String) -> KFImage {
return KFImage(URL(string: url))
.placeholder {
Image(systemName: "x.circle.fill")
Image(systemName: "questionmark.circle.fill")
}
.retry(maxCount: 3, interval: .seconds(3))
.onFailure { error in print("Kingfisher Error: \(error)") }
Expand Down
6 changes: 3 additions & 3 deletions Projects/Domain/Sources/Model/KeymeTestsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public struct KeymeTestsModel: Equatable {
}

public struct IconModel: Equatable, Hashable {
public let image: String
public let imageURL: String
public let color: Color

public static var EMPTY: IconModel = .init(image: "", color: Color.hex(""))
public static let EMPTY: IconModel = .init(imageURL: "", color: Color.hex(""))
}

public extension KeymeTestsDTO {
func toIconModel() -> KeymeTestsModel {
let nickname = data.owner.nickname
let icons = data.questions.map {
IconModel(image: $0.category.iconUrl,
IconModel(imageURL: $0.category.iconUrl,
color: Color.hex($0.category.color))
}
return KeymeTestsModel(nickname: nickname ?? "키미",
Expand Down
2 changes: 1 addition & 1 deletion Projects/Domain/Sources/Model/TestResultModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public extension ResultDTO {
return TestResultModel(
title: keyword,
score: score,
icon: IconModel(image: category.iconUrl,
icon: IconModel(imageURL: category.iconUrl,
color: Color.hex(category.color))
)
}
Expand Down
23 changes: 16 additions & 7 deletions Projects/Features/Sources/Home/KeymeTestsStartFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct KeymeTestsStartFeature: Reducer {
public var keymeTests: KeymeTestsFeature.State?
public var isAnimating: Bool = false
public var nickname: String?
public var testId: Int = 0
public var testId: Int = 5 // TODO: change
public var icon: IconModel = .EMPTY

public init() { }
Expand All @@ -25,6 +25,7 @@ public struct KeymeTestsStartFeature: Reducer {
public enum Action {
case viewWillAppear
case fetchDailyTests(TaskResult<KeymeTestsModel>)
case startAnimation([IconModel])
case setIcon(IconModel)
case startButtonDidTap
case keymeTests(KeymeTestsFeature.Action)
Expand All @@ -41,28 +42,36 @@ public struct KeymeTestsStartFeature: Reducer {
case .viewWillAppear:
return .run { send in
await send(.fetchDailyTests(
TaskResult { try await self.keymeTestsClient.fetchDailyTests() }
TaskResult {
try await self.keymeTestsClient.fetchDailyTests()
}
))
}

case let .fetchDailyTests(.success(tests)):
state.nickname = tests.nickname
state.testId = tests.testId
state.isAnimating.toggle()
state.isAnimating = true

return .send(.startAnimation(tests.icons))

case .fetchDailyTests(.failure):
state.nickname = "키미" // TODO: 변경
return .send(.startAnimation([IconModel.EMPTY]))

case .startAnimation(let icons):
return .run { send in
repeat {
for icon in tests.icons {
for icon in icons {
await send(.setIcon(icon))
try await self.clock.sleep(for: .seconds(1.595))
}
} while true
}

case .fetchDailyTests(.failure):
state.nickname = nil

case let .setIcon(icon):
state.icon = icon
state.isAnimating = true

case .startButtonDidTap:
let url = "https://keyme-frontend.vercel.app/test/\(state.testId)"
Expand Down
12 changes: 7 additions & 5 deletions Projects/Features/Sources/Home/KeymeTestsStartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public struct KeymeTestsStartView: View {
}

func welcomeText(_ viewStore: ViewStore<KeymeTestsStartFeature.State, KeymeTestsStartFeature.Action>) -> some View {
Text.keyme("환영해요 \(viewStore.nickname ?? "키미")님!\n이제 문제를 풀어볼까요?", font: .heading1) // TODO: 닉변
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(Padding.insets(leading: 16))
Text.keyme(
"환영해요 \(viewStore.nickname ?? "키미")님!\n이제 문제를 풀어볼까요?",
font: .heading1) // TODO: 닉변
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(Padding.insets(leading: 16))
}

func startTestsButton(_ viewStore: ViewStore<KeymeTestsStartFeature.State,
Expand All @@ -81,7 +83,7 @@ public struct KeymeTestsStartView: View {
.scaleEffect(viewStore.isAnimating ? 1.0 : 0.001)
.animation(.spring(response: 0.8).repeatForever(), value: viewStore.isAnimating)

KFImageManager.shared.toImage(url:viewStore.icon.image)
KFImageManager.shared.toImage(url: viewStore.icon.imageURL)
.frame(width: 30, height: 30)
.scaledToFit()
.scaleEffect(viewStore.isAnimating ? 1.0 : 0.001)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,19 @@ public struct KeymeCardView: View {
Spacer()
.frame(height: 8)

Text.keyme("\(testResult.nickname)\(testResult.title) 정도는?", font: .heading1)
Text.keyme("\(testResult.nickname)애정표현 정도는?", font: .heading1)
.foregroundColor(.white)
.multilineTextAlignment(.leading)

Divider()
.background(.white.opacity(0.1))

HStack(alignment: .bottom) {
HStack {
Text.keyme("0\(testResult.score)", font: .checkResult)
.foregroundColor(.white.opacity(0.6))

Text.keyme("", font: .caption1)
.foregroundColor(.white.opacity(0.6))
.padding(Padding.insets(bottom: 8))

Spacer()
}
Expand All @@ -88,9 +87,10 @@ public struct KeymeCardView: View {

Circle()
.foregroundColor(testResult.icon.color)
.frame(width: scoreToRadius(score: testResult.score), height: scoreToRadius(score: testResult.score))
.frame(width: scoreToRadius(score: testResult.score),
height: scoreToRadius(score: testResult.score))

KFImageManager.shared.toImage(url: testResult.icon.image)
KFImageManager.shared.toImage(url: testResult.icon.imageURL)
.resizable()
.scaledToFit()
.frame(height: 40)
Expand Down
21 changes: 1 addition & 20 deletions Projects/Features/Sources/MainPage/MainPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct KeymeMainView: View {
}

var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
WithViewStore(store, observe: { $0 }) { _ in
TabView(selection: $selectedTab) {
KeymeTestsStartView(store: Store(
initialState: KeymeTestsStartFeature.State()) {
Expand Down Expand Up @@ -72,25 +72,6 @@ struct KeymeMainView: View {
tabBar.scrollEdgeAppearance = tabBar.standardAppearance
}
}
.introspect(.tabView, on: .iOS(.v16, .v17)) { tabViewController in
let tabBar = tabViewController.tabBar

let barAppearance = UITabBarAppearance()
barAppearance.configureWithDefaultBackground()
barAppearance.backgroundColor = UIColor(Color.hex("232323"))

let itemAppearance = UITabBarItemAppearance()
itemAppearance.selected.iconColor = .white
itemAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.white]
itemAppearance.normal.iconColor = .gray
itemAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.gray]

tabBar.standardAppearance = barAppearance
tabBar.standardAppearance.inlineLayoutAppearance = itemAppearance
tabBar.standardAppearance.stackedLayoutAppearance = itemAppearance
tabBar.standardAppearance.compactInlineLayoutAppearance = itemAppearance
tabBar.scrollEdgeAppearance = tabBar.standardAppearance
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions Projects/Features/Sources/Onboarding/OnboardingFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public struct OnboardingFeature: Reducer {
public var testResultState: TestResultFeature.State?
public var status: Status = .notDetermined

public var testId: Int = 0
public var lottieType: LottieType = .splash1 // TODO:
public var testId: Int = 4 // TODO: 바꾸기
public var lottieType: LottieType = .splash1
public var isButtonShown: Bool = false
public var isLoop: Bool = false
public var isBlackBackground: Bool = false
Expand Down Expand Up @@ -118,8 +118,8 @@ public struct OnboardingFeature: Reducer {

case .startButtonDidTap:
// TODO: url 주석단거로 바꾸기
// let url = "https://keyme-frontend.vercel.app/test/\(state.testId)"
let url = "https://keyme-frontend.vercel.app/test/5"
let url = "https://keyme-frontend.vercel.app/test/\(state.testId)"
// let url = "https://keyme-frontend.vercel.app/test/5"
state.keymeTestsState = KeymeTestsFeature.State(url: url)

case .keymeTests(.presented(.showResult(let data))):
Expand Down
31 changes: 21 additions & 10 deletions Projects/Keyme/Sources/KeymeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct KeymeApp: App {
}
}

class AppDelegate: UIResponder, UIApplicationDelegate {
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
Expand All @@ -30,12 +30,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
KeymeAPIManager.shared.registerAuthorizationToken(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhY2Nlc3NUb2tlbiIsImlhdCI6MTY5MTg0MjM1NiwiZXhwIjoxNjk0NDM0MzU2LCJtZW1iZXJJZCI6Miwicm9sZSI6IlJPTEVfVVNFUiJ9.bLUl_ObvXr2pkLGNBZYWbJgLZLo3P0xB2pawckRGYZM"
)


UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, _ in
guard granted else { return }

// 푸시토큰 애플 서버에 등록하기
self.getNotificationSettings()

UNUserNotificationCenter.current().getNotificationSettings { settings in
guard settings.authorizationStatus == .authorized else { return }

DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
return true
}
Expand All @@ -54,12 +62,15 @@ extension AppDelegate: MessagingDelegate {
}

extension AppDelegate {
private func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
Messaging.messaging().setAPNSToken(deviceToken, type: .unknown)

print("firebase Device Token: \(token)")
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("firebase Failed to register for remote notifications: \(error)")
}
}

0 comments on commit adb5779

Please sign in to comment.