Skip to content

Commit

Permalink
iOS: Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
viere1234 committed Nov 5, 2024
1 parent c79c36a commit 3a15816
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 30 deletions.
16 changes: 16 additions & 0 deletions iosApp/OPass.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
D300355C2C85E31A0049B7B3 /* Shared+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D300355B2C85E31A0049B7B3 /* Shared+Extension.swift */; };
D307A8812C76039D00BB00FB /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D307A8802C76039D00BB00FB /* GoogleService-Info.plist */; };
D307A8842C76055F00BB00FB /* FirebaseAnalyticsWithoutAdIdSupport in Frameworks */ = {isa = PBXBuildFile; productRef = D307A8832C76055F00BB00FB /* FirebaseAnalyticsWithoutAdIdSupport */; };
D307A8862C76055F00BB00FB /* FirebaseAppCheck in Frameworks */ = {isa = PBXBuildFile; productRef = D307A8852C76055F00BB00FB /* FirebaseAppCheck */; };
Expand All @@ -33,6 +34,7 @@
D3D1B8A02C7475A00075A747 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D1B89F2C7475A00075A747 /* SettingsView.swift */; };
D3EBBF672C8454E400A49285 /* EventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3EBBF662C8454E400A49285 /* EventView.swift */; };
D3EBBF692C8454EF00A49285 /* EventViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3EBBF682C8454EF00A49285 /* EventViewModel.swift */; };
D3FA31322C8C457800949ECF /* GeneralSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FA31312C8C457800949ECF /* GeneralSettingsView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -60,6 +62,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
D300355B2C85E31A0049B7B3 /* Shared+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shared+Extension.swift"; sourceTree = "<group>"; };
D307A8802C76039D00BB00FB /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
D307A8922C760F8E00BB00FB /* AppearanceSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceSettingsView.swift; sourceTree = "<group>"; };
D34BEEC72C723BC6008F9A4C /* OPass.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OPass.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -80,6 +83,7 @@
D3D1B89F2C7475A00075A747 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
D3EBBF662C8454E400A49285 /* EventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventView.swift; sourceTree = "<group>"; };
D3EBBF682C8454EF00A49285 /* EventViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventViewModel.swift; sourceTree = "<group>"; };
D3FA31312C8C457800949ECF /* GeneralSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettingsView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -111,10 +115,19 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
D300355A2C85E3010049B7B3 /* Extension */ = {
isa = PBXGroup;
children = (
D300355B2C85E31A0049B7B3 /* Shared+Extension.swift */,
);
path = Extension;
sourceTree = "<group>";
};
D307A8912C760F5100BB00FB /* Settings */ = {
isa = PBXGroup;
children = (
D3D1B89F2C7475A00075A747 /* SettingsView.swift */,
D3FA31312C8C457800949ECF /* GeneralSettingsView.swift */,
D307A8922C760F8E00BB00FB /* AppearanceSettingsView.swift */,
);
path = Settings;
Expand Down Expand Up @@ -148,6 +161,7 @@
D39AC9DA2C7B394600084689 /* SelectEvent */,
D307A8912C760F5100BB00FB /* Settings */,
D3B1E77E2C774609002DBA07 /* General */,
D300355A2C85E3010049B7B3 /* Extension */,
);
path = OPass;
sourceTree = "<group>";
Expand Down Expand Up @@ -370,11 +384,13 @@
files = (
D3D1B8A02C7475A00075A747 /* SettingsView.swift in Sources */,
D34BEECD2C723BC6008F9A4C /* ContentView.swift in Sources */,
D3FA31322C8C457800949ECF /* GeneralSettingsView.swift in Sources */,
D3EBBF692C8454EF00A49285 /* EventViewModel.swift in Sources */,
D39AC9DE2C7B398E00084689 /* SelectEventViewModel.swift in Sources */,
D34BEECB2C723BC6008F9A4C /* OPassApp.swift in Sources */,
D307A8932C760F8E00BB00FB /* AppearanceSettingsView.swift in Sources */,
D39AC9DC2C7B395D00084689 /* SelectEventView.swift in Sources */,
D300355C2C85E31A0049B7B3 /* Shared+Extension.swift in Sources */,
D3B1E7802C774623002DBA07 /* SafariView.swift in Sources */,
D3B1E7822C775E7C002DBA07 /* CenterLabelStyle.swift in Sources */,
D3EBBF672C8454E400A49285 /* EventView.swift in Sources */,
Expand Down
17 changes: 11 additions & 6 deletions iosApp/OPass/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@ import SwiftUI
struct ContentView: View {
// MARK: - Variable
@AppStorage("EventID") private var eventID = ""
@AppStorage("HapticFeedback") private var hapticFeedback = true

@State private var selectEventSheetPresented = false

// MARK: - View
var body: some View {
NavigationStack {
Group {
if eventID.isEmpty {
ProgressView("Loading")
.onAppear { selectEventSheetPresented.toggle() }
loadingView()
} else {
EventView()
}
}
.sensoryFeedback(.selection, trigger: selectEventSheetPresented) { $1 && hapticFeedback }
.sheet(isPresented: $selectEventSheetPresented) { SelectEventView() }
.toolbar { toolbar() }
.sensoryFeedback(.selection, trigger: selectEventSheetPresented) { $1 }
.sheet(isPresented: $selectEventSheetPresented) {
SelectEventView()
}
}
.analyticsScreen(name: "ContentView")
}

@ViewBuilder
private func loadingView() -> some View {
ProgressView("Loading")
.onAppear { selectEventSheetPresented.toggle() }
}

@ToolbarContentBuilder
private func toolbar() -> some ToolbarContent {
ToolbarItem(placement: .topBarLeading) {
Expand Down
26 changes: 20 additions & 6 deletions iosApp/OPass/Event/EventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,42 @@
// 2024 OPass.
//

import Shared
import SwiftUI

@MainActor
struct EventView: View {
// MARK: - Variable
@State private var viewModel = EventViewModel()

@AppStorage("EventID") private var eventID = ""

// MARK: - View
var body: some View {
Group {
if let config = viewModel.config {
VStack {
Text(config.name)
Text(config.logoUrl)
}
eventView(config)
} else {
ProgressView("Loading")
.task { await viewModel.loadEvent() }
loadingView()
}
}
.analyticsScreen(name: "EventView")
}

@ViewBuilder
private func eventView(_ config: EventConfig) -> some View {
VStack {
Text(config.name)
Text(config.logoUrl)
}
.onChange(of: eventID) { viewModel.reset() }
}

@ViewBuilder
private func loadingView() -> some View {
ProgressView("Loading")
.task { await viewModel.loadEvent() }
}
}

#Preview {
Expand Down
13 changes: 9 additions & 4 deletions iosApp/OPass/Event/EventViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ class EventViewModel {
@ObservationIgnored
@AppStorage("EventID") private var eventID = ""

var config: EventConfig?
private(set) var config: EventConfig?

private var error: Error?

func loadEvent() async {
async let cache = portal.getEventConfig(eventId: eventID, forceReload: false)
async let remote = portal.getEventConfig(eventId: eventID, forceReload: true)
func loadEvent(reload: Bool = false) async {
if reload { config = nil }
async let cache = PortalHelper.shared.getEventConfig(eventId: eventID, forceReload: false)
async let remote = PortalHelper.shared.getEventConfig(eventId: eventID, forceReload: true)

do {
config = try? await cache
Expand All @@ -37,4 +38,8 @@ class EventViewModel {
}
}
}

func reset() {
config = nil
}
}
13 changes: 13 additions & 0 deletions iosApp/OPass/Extension/Shared+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Shared+Extension.swift
// OPass
//
// Created by Brian Chang on 2024/9/2.
// 2024 OPass.
//

import Shared

extension Shared.PortalHelper {
static let shared = PortalHelper()
}
3 changes: 0 additions & 3 deletions iosApp/OPass/OPassApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import FirebasePerformance
import FirebaseCrashlytics
import OneSignalFramework

// Shared Portal Object
let portal = PortalHelper()

@main
struct OPassApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
Expand Down
3 changes: 2 additions & 1 deletion iosApp/OPass/SelectEvent/SelectEventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct SelectEventView: View {
@Environment(\.dismiss) private var dismiss

@AppStorage("EventID") private var eventID = ""
@AppStorage("HapticFeedback") private var hapticFeedback = true

// MARK: - View
var body: some View {
Expand Down Expand Up @@ -80,7 +81,7 @@ struct SelectEventView: View {
}
.animation(events.isEmpty ? nil : .default, value: events)
.scrollDismissesKeyboard(.interactively)
.sensoryFeedback(.success, trigger: eventID)
.sensoryFeedback(.success, trigger: eventID) { _, _ in hapticFeedback }
.searchable(text: $viewModel.searchText,
placement: .navigationBarDrawer,
prompt: "Search Event")
Expand Down
4 changes: 2 additions & 2 deletions iosApp/OPass/SelectEvent/SelectEventViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class SelectEventViewModel {
private var events: [Event]?

func loadEvents() async {
async let cache = portal.getEvents(forceReload: false)
async let remote = portal.getEvents(forceReload: true)
async let cache = PortalHelper.shared.getEvents(forceReload: false)
async let remote = PortalHelper.shared.getEvents(forceReload: true)

do {
events = try? await cache
Expand Down
6 changes: 4 additions & 2 deletions iosApp/OPass/Settings/AppearanceSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import SwiftUI

struct AppearanceSettingsView: View {
// MARK: - Variable
@AppStorage("HapticFeedback") private var hapticFeedback = true
@AppStorage("DarkMode") private var darkMode: DarkMode = .system
@Environment(\.colorScheme) private var colorScheme

// MARK: - View
var body: some View {
Form {
Section {
Expand All @@ -31,7 +33,7 @@ struct AppearanceSettingsView: View {
}
.labelStyle(CenterLabelStyle())
}
.sensoryFeedback(.success, trigger: darkMode)
.sensoryFeedback(.success, trigger: darkMode) { _, _ in hapticFeedback }
}

Button("Reset Appearance") {
Expand Down
31 changes: 31 additions & 0 deletions iosApp/OPass/Settings/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// GeneralSettingsView.swift
// OPass
//
// Created by Brian Chang on 2024/9/7.
// 2024 OPass.
//

import SwiftUI

struct GeneralSettingsView: View {
// MARK: - Variable
@AppStorage("HapticFeedback") private var hapticFeedback = true

// MARK: - View
var body: some View {
Form {
Section {
Toggle("Haptic Feedback", systemImage: "hand.tap", isOn: $hapticFeedback)
}
}
.analyticsScreen(name: "GeneralSettingsView")
.navigationBarTitleDisplayMode(.large)
.navigationTitle("General")
.listSectionSpacing(.compact)
}
}

#Preview {
GeneralSettingsView()
}
28 changes: 23 additions & 5 deletions iosApp/OPass/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
import SwiftUI

struct SettingsView: View {
// MARK: - Variable
private let websiteURL = URL(string: "https://opass.app")!
private let gitHubURL = URL(string: "https://github.com/CCIP-App/CCIP-KMP")!
private let policyURL = URL(string: "https://opass.app/privacy-policy.html")!

@Environment(\.colorScheme) private var colorScheme

@AppStorage("HapticFeedback") private var hapticFeedback = true

@State private var safariUrl = URL(string: "https://opass.app")!
@State private var safariPresented = false

// MARK: - Views
// MARK: - View
var body: some View {
Form {
introductionSection()
Expand All @@ -32,18 +36,18 @@ struct SettingsView: View {
.analyticsScreen(name: "SettingsView")
.navigationBarTitleDisplayMode(.large)
.navigationTitle("Settings")
.listSectionSpacing(.compact)
.listSectionSpacing(0)
}

@ViewBuilder
private func introductionSection() -> some View {
VStack(spacing: 5) {
Image(.opassIcon)
.interpolation(.none)
//.interpolation(.high)
.resizable()
.scaledToFit()
.frame(width: 100)
.clipShape(.rect(cornerRadius: 15.625))
.clipShape(.rect(cornerRadius: 22)) // radius = width * 2/9

Text("OPass")
.font(.title2)
Expand All @@ -59,6 +63,20 @@ struct SettingsView: View {
@ViewBuilder
private func generalSection() -> some View {
Section("GENERAL") {
NavigationLink {
GeneralSettingsView()
} label: {
Label {
Text("General")
} icon: {
Image(systemName: "gear")
.resizable()
.scaledToFit()
.foregroundStyle(.gray)
}
.labelStyle(CenterLabelStyle())
}

NavigationLink {
AppearanceSettingsView()
} label: {
Expand Down Expand Up @@ -163,7 +181,7 @@ struct SettingsView: View {
}
.labelStyle(CenterLabelStyle())
}
.sensoryFeedback(.selection, trigger: safariPresented) { $1 }
.sensoryFeedback(.selection, trigger: safariPresented) { $1 && hapticFeedback }
}

@ViewBuilder
Expand Down
Loading

0 comments on commit 3a15816

Please sign in to comment.