Skip to content

feat(iOS): settings #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions apps/mobile/metro-now/metro-now.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
2D001BAA2CC8099B00C6B4F8 /* metro-now */,
2D001BBC2CC8099C00C6B4F8 /* metro-now Watch App */,
2D7FEC782CE96F300073FF5B /* metro-nowTests */,
2D8EBE2C2CE93DC9004D5F5B /* Frameworks */,
2D001BA92CC8099B00C6B4F8 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -159,13 +158,6 @@
name = Products;
sourceTree = "<group>";
};
2D8EBE2C2CE93DC9004D5F5B /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -471,7 +463,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"metro-now Watch App/Preview Content\"";
DEVELOPMENT_TEAM = R6WU5ABNG2;
ENABLE_PREVIEWS = YES;
Expand All @@ -485,15 +477,15 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.3.2;
MARKETING_VERSION = 0.3.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.krystof.metro-now.watchkitapp";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 10;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
};
name = Debug;
};
Expand All @@ -503,7 +495,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"metro-now Watch App/Preview Content\"";
DEVELOPMENT_TEAM = R6WU5ABNG2;
ENABLE_PREVIEWS = YES;
Expand All @@ -517,7 +509,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.3.2;
MARKETING_VERSION = 0.3.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.krystof.metro-now.watchkitapp";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
Expand All @@ -526,7 +518,7 @@
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 4;
VALIDATE_PRODUCT = YES;
WATCHOS_DEPLOYMENT_TARGET = 10;
WATCHOS_DEPLOYMENT_TARGET = 10.0;
};
name = Release;
};
Expand All @@ -536,7 +528,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"metro-now/Preview Content\"";
DEVELOPMENT_TEAM = R6WU5ABNG2;
ENABLE_PREVIEWS = YES;
Expand All @@ -554,7 +546,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.3.2;
MARKETING_VERSION = 0.3.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.krystof.metro-now";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -570,7 +562,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"metro-now/Preview Content\"";
DEVELOPMENT_TEAM = R6WU5ABNG2;
ENABLE_PREVIEWS = YES;
Expand All @@ -588,7 +580,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.3.2;
MARKETING_VERSION = 0.3.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.krystof.metro-now";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down
18 changes: 17 additions & 1 deletion apps/mobile/metro-now/metro-now/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ struct ContentView: View {
ZStack {
NavigationStack {
ClosestStopPageView()
.toolbar {
ToolbarItem(placement: .topBarLeading) {
NavigationLink {
SettingsPageView()
} label: {
Label("Settings", systemImage: "gearshape")
}
}
// ToolbarItem(placement: .topBarTrailing) {
// NavigationLink {
// SettingsPageView()
// } label: {
// Label("Search", systemImage: "magnifyingglass")
// }
// }
}
}
.sheet(
isPresented: $showWelcomeScreen,
onDismiss: dismissWelcomeScreen
) {
WelcomeScreenView(handleDismiss: dismissWelcomeScreen)
WelcomePageView(handleDismiss: dismissWelcomeScreen)
.presentationDetents([.medium])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class ClosestStopPageViewModel: NSObject, ObservableObject, CLLocationManagerDel
stopPeriodicRefresh()
}

func refresh() {
let stopIds = [closestMetroStop?.id ?? "", closestStop?.id ?? ""]

getDepartures(
stopsIds: stopIds.filter { !$0.isEmpty },
platformsIds: []
)
}

private func startPeriodicRefresh() {
stopPeriodicRefresh() // Stop any existing timer to avoid duplication.
refreshTimer = Timer.scheduledTimer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import SwiftUI

struct ClosestStopPageView: View {
@StateObject private var viewModel = ClosestStopPageViewModel()
@AppStorage(
AppStorageKeys.showMetroOnly.rawValue
) var showMetroOnly = false

var body: some View {
if viewModel.metroStops != nil || viewModel.allStops != nil {
Expand All @@ -18,29 +21,42 @@ struct ClosestStopPageView: View {
}
}

if let closestStop = viewModel.closestStop {
let platforms = closestStop.platforms
.filter { platform in
platform.routes.contains(where: {
let routeName = $0.name.uppercased()
let containsMetro = METRO_LINES.contains(routeName)
if showMetroOnly {
Button("Show all public transport departures") {
showMetroOnly.toggle()
}
} else {
if let closestStop = viewModel.closestStop {
let platforms = closestStop.platforms
.filter { platform in
platform.routes.contains(where: {
let routeName = $0.name.uppercased()
let containsMetro = METRO_LINES.contains(routeName)

return !containsMetro
return !containsMetro
})
}
.sorted(by: {
getPlatformLabel($0) < getPlatformLabel($1)
})
}
.sorted(by: {
getPlatformLabel($0) < getPlatformLabel($1)
})

ForEach(platforms, id: \.id) { platform in
PlatformDeparturesListView(
platform: platform,
departures: viewModel.departures
)
ForEach(platforms, id: \.id) { platform in
PlatformDeparturesListView(
platform: platform,
departures: viewModel.departures
)
}
}
}
}
.navigationTitle(viewModel.closestMetroStop?.name ?? "")
.navigationTitle(viewModel.closestMetroStop?.name ?? "Departures")
.refreshable {
do {
print("Refreshing")

viewModel.refresh()
}
}
} else {
ProgressView()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

private let reportBugUrl = URL(
string: "https://github.com/krystxf/metro-now/issues/new?assignees=&labels=&projects=&template=bug_report.md&title="
)

private let requestFeatureUrl = URL(
string: "https://github.com/krystxf/metro-now/issues/new?assignees=&labels=&projects=&template=feature_request.md&title="
)

private let appStoreUrl = URL(
string: "https://apps.apple.com/cz/app/metro-now/id6504659402?platform=iphone"
)

private let appStoreReviewUrl = URL(
string: "https://itunes.apple.com/us/app/metro-now/id6504659402?mt=8&action=write-review"
)

struct SettingsPageAboutSectionView: View {
var body: some View {
Section(
header: Label("About", systemImage: "info.circle")
) {
if let appStoreUrl {
ShareLink(item: appStoreUrl) {
Label(
"Share metro-now",
systemImage: "square.and.arrow.up"
)
}
}

if let appStoreReviewUrl {
Link(
destination: appStoreReviewUrl
) {
Label(
"Give us a rating",
systemImage: "star"
)
}
.accessibilityHint("Opens app rating in app store")
}

if let reportBugUrl {
Link(destination: reportBugUrl) {
Label(
"Report bug",
systemImage: "bubble.left.and.exclamationmark.bubble.right"
)
}
.accessibilityHint("Opens Github issue form")
}

if let requestFeatureUrl {
Link(destination: requestFeatureUrl) {
Label(
"Feature request",
systemImage: "star.bubble"
)
}
.accessibilityHint("Opens Github feature request form")
}
}
}
}

#Preview {
List {
SettingsPageAboutSectionView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

struct SettingsPageFooterView: View {
var body: some View {
VStack {
let versionNumber = Bundle.main.versionNumber ?? ""
let buildNumber = Bundle.main.buildNumber ?? ""
let formattedVersion = "\(versionNumber)(\(buildNumber))"

Text("metro-now")

Text("version: ")
+ Text(formattedVersion).fontDesign(.monospaced)

Text(
"[source code](https://github.com/krystxf/metro-now)"
)
}
}
}

#Preview {
Spacer()
SettingsPageFooterView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

struct SettingsPageGeneralSectionView: View {
@AppStorage(
AppStorageKeys.showMetroOnly.rawValue
) var showMetroOnly = false

var body: some View {
Section(
header:
Label("General", systemImage: "gear"),
footer:
Text("Other means of transport will be hidden")
) {
Toggle(isOn: $showMetroOnly) {
Text("Show only metro")
}
}
}
}

#Preview {
List {
SettingsPageGeneralSectionView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

struct SettingsPageView: View {
var body: some View {
VStack {
List {
SettingsPageGeneralSectionView()
SettingsPageAboutSectionView()
}
Spacer()
SettingsPageFooterView()
}
.background(Color(UIColor.systemGroupedBackground))
.navigationTitle("Settings")
}
}

#Preview {
NavigationStack {
SettingsPageView()
}
}
Loading
Loading