Skip to content
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

feat(iOS): settings #51

Merged
merged 9 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 0 additions & 8 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
11 changes: 10 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,21 @@ struct ContentView: View {
ZStack {
NavigationStack {
ClosestStopPageView()
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
NavigationLink {
SettingsPageView()
} label: {
Label("Settings", systemImage: "gearshape")
}
}
}
}
.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,7 +21,7 @@ struct ClosestStopPageView: View {
}
}

if let closestStop = viewModel.closestStop {
if !showMetroOnly, let closestStop = viewModel.closestStop {
let platforms = closestStop.platforms
.filter { platform in
platform.routes.contains(where: {
Expand All @@ -41,6 +44,11 @@ struct ClosestStopPageView: View {
}
}
.navigationTitle(viewModel.closestMetroStop?.name ?? "")
.refreshable {
print("Refreshing")

viewModel.refresh()
}
krystxf marked this conversation as resolved.
Show resolved Hide resolved
} else {
ProgressView()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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 appStoreLink = URL(
string: "https://apps.apple.com/cz/app/metro-now/id6504659402?platform=iphone"
)

struct SettingsPageAboutSectionView: View {
@Environment(\.requestReview) private var requestReview

var body: some View {
Section(
header: Label("About", systemImage: "info.circle")
) {
if let appStoreLink {
ShareLink(item: appStoreLink) {
Label(
"Share app with friends",
systemImage: "square.and.arrow.up"
)
}
}

Label("Rate the app", systemImage: "star")
.foregroundStyle(.link)
.onTapGesture {
requestReview()
}

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

if let requestFeatureUrl {
Link(destination: requestFeatureUrl) {
Label(
"Feature request",
systemImage: "star.bubble"
)
}
}
}
}
}
krystxf marked this conversation as resolved.
Show resolved Hide resolved

#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("Doesn't show buses or any other means of transport, just metro.")
) {
Toggle(isOn: $showMetroOnly) {
Text("Metro only")
}
}
}
}

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

import StoreKit
import SwiftUI

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

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

import Foundation

extension Bundle {
var versionNumber: String? {
infoDictionary?["CFBundleShortVersionString"] as? String
}

var buildNumber: String? {
infoDictionary?["CFBundleVersion"] as? String
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private let headingGradient = LinearGradient(
endPoint: .trailing
)

struct WelcomeScreenView: View {
struct WelcomePageView: View {
let handleDismiss: () -> Void

@State private var showContent = false
Expand Down Expand Up @@ -59,5 +59,5 @@ struct WelcomeScreenView: View {
}

#Preview {
WelcomeScreenView {}
WelcomePageView {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

enum AppStorageKeys: String {
case hasSeenWelcomeScreen
case showMetroOnly
}
Loading