diff --git a/JCAlerts.xcodeproj/project.pbxproj b/JCAlerts.xcodeproj/project.pbxproj index 1cbcf73..8caa72f 100644 --- a/JCAlerts.xcodeproj/project.pbxproj +++ b/JCAlerts.xcodeproj/project.pbxproj @@ -650,7 +650,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = JCAlerts/JCAlerts.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2023122901; + CURRENT_PROJECT_VERSION = 2023122902; DEVELOPMENT_TEAM = 2JDGUK4DRH; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = JCAlerts/Info.plist; @@ -683,7 +683,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = JCAlerts/JCAlerts.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2023122901; + CURRENT_PROJECT_VERSION = 2023122902; DEVELOPMENT_TEAM = 2JDGUK4DRH; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = JCAlerts/Info.plist; diff --git a/JCAlerts/models/firebase/fcm/FCMTopic.swift b/JCAlerts/models/firebase/fcm/FCMTopic.swift index f173c2b..c39d1a6 100644 --- a/JCAlerts/models/firebase/fcm/FCMTopic.swift +++ b/JCAlerts/models/firebase/fcm/FCMTopic.swift @@ -7,7 +7,7 @@ import Foundation -enum FCMTopic: String { +enum FCMTopic: String, CaseIterable { case ALL = "jc-alerts-all" case PETFINDER = "jc-alerts-petfinder" diff --git a/JCAlerts/services/FCMTopicService.swift b/JCAlerts/services/FCMTopicService.swift index 0c9838b..2e87f2e 100644 --- a/JCAlerts/services/FCMTopicService.swift +++ b/JCAlerts/services/FCMTopicService.swift @@ -101,4 +101,10 @@ class FCMTopicService { } UserDefaults.standard.set(topicsList, forKey: TOPIC_KEY) } + + func subscribeToAllTopic() { + FCMTopic.allCases.forEach { topic in + subscribe(toTopic: topic) + } + } } diff --git a/JCAlerts/services/UserSettingService.swift b/JCAlerts/services/UserSettingService.swift index 98f6ab1..f1dd9c0 100644 --- a/JCAlerts/services/UserSettingService.swift +++ b/JCAlerts/services/UserSettingService.swift @@ -16,6 +16,8 @@ class UserSettingService { private var textViewFontSize: Int + private var firstTimeRunning: Bool + private init() { // check if UserDefaults has username defined if let username = userDefaults.string(forKey: "currentUsername") { @@ -34,6 +36,21 @@ class UserSettingService { textViewFontSize = 14 userDefaults.setValue(textViewFontSize, forKey: "textViewFontSize") } + + if let firstTime = userDefaults.string(forKey: "firstTimeRunning") { + firstTimeRunning = Bool(firstTime)! + } else { + firstTimeRunning = true + } + } + + func getFirstTimeRunning() -> Bool { + return firstTimeRunning + } + + func setFirstTimeRunningToFalse() { + firstTimeRunning = false + userDefaults.set("false", forKey: "firstTimeRunning") } func getTextViewFontSize() -> Int { diff --git a/JCAlerts/swiftuis/ContentView.swift b/JCAlerts/swiftuis/ContentView.swift index ac4dcad..1fcae10 100644 --- a/JCAlerts/swiftuis/ContentView.swift +++ b/JCAlerts/swiftuis/ContentView.swift @@ -8,6 +8,13 @@ import SwiftUI struct ContentView: View { + @State private var isFirstTimeRunning = UserSettingService.instance.getFirstTimeRunning() + + private let WELCOME_MSG = "Welcome to JCAlerts!" + private let WELCOME_MSG_BODY = """ +For the first time setup, please go to the Settings tab and configure notification subscriptions +""" + var body: some View { TabView { LandingPageView() @@ -20,6 +27,19 @@ struct ContentView: View { Label("Settings", systemImage: "gear") } } + .alert(WELCOME_MSG, isPresented: $isFirstTimeRunning) { + Button(role: .cancel) { + // handle action + isFirstTimeRunning = false + FCMTopicService.instance.subscribeToAllTopic() + UserSettingService.instance.setFirstTimeRunningToFalse() + } label: { + Text("OK") + } + + } message: { + Text(WELCOME_MSG_BODY) + } } } diff --git a/JCAlerts/swiftuis/home/LandingPageView.swift b/JCAlerts/swiftuis/home/LandingPageView.swift index 0544484..15234a0 100644 --- a/JCAlerts/swiftuis/home/LandingPageView.swift +++ b/JCAlerts/swiftuis/home/LandingPageView.swift @@ -16,35 +16,38 @@ struct LandingPageView: View { var body: some View { NavigationView { - VStack { - ScrollView(.horizontal) { - HStack(spacing: 15) { - ForEach(cfService.trimmedNotificationPayloads) { data in - Card(payload: data) + ScrollView { + VStack { + ScrollView(.horizontal) { + HStack(spacing: 15) { + ForEach(cfService.trimmedNotificationPayloads) { data in + Card(payload: data) + } + MoreCard() + Spacer() } - MoreCard() - Spacer() + .padding() } + .scrollIndicators(.hidden) .padding() - } - .scrollIndicators(.hidden) - .padding() - - NavigationLink(destination: UKAlertsView()) { - Text("More...") - .foregroundStyle(Color(K.Colors.inverseTextColor, bundle: nil)) - .font(.headline) - .frame(width: (UIScreen.current?.bounds.size.width)! * 0.75) - .padding() - .background(Color(K.Colors.backgroundColor, bundle: nil)) - .cornerRadius(15) - } - .frame(maxWidth: .infinity, alignment: .center) - Spacer() + NavigationLink(destination: UKAlertsView()) { + Text("More...") + .foregroundStyle(Color(K.Colors.inverseTextColor, bundle: nil)) + .font(.headline) + .frame(width: (UIScreen.current?.bounds.size.width)! * 0.75) + .padding() + .background(Color(K.Colors.backgroundColor, bundle: nil)) + .cornerRadius(15) + } + .frame(maxWidth: .infinity, alignment: .center) + + Spacer() + } + .navigationTitle("Welcome") + .navigationBarTitleDisplayMode(.large) } - .navigationTitle("Welcome") - .navigationBarTitleDisplayMode(.large) + } } }