Skip to content

Commit

Permalink
feat(app): macos init
Browse files Browse the repository at this point in the history
  • Loading branch information
krystxf committed Nov 26, 2024
1 parent 1971bb6 commit d612e83
Show file tree
Hide file tree
Showing 30 changed files with 1,345 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "icon-1024x1024.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
74 changes: 74 additions & 0 deletions apps/mobile/metro-now/metro-now Mac App/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

struct ContentView: View {
@StateObject private var networkMonitor = NetworkMonitor()
@State private var showNoInternetBanner = false

@AppStorage(
AppStorageKeys.hasSeenWelcomeScreen.rawValue
) var hasSeenWelcomeScreen = false
@State private var showWelcomeScreen: Bool = false

var body: some 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
) {
WelcomePageView(handleDismiss: dismissWelcomeScreen)
.presentationDetents([.medium])
}

VStack {
Spacer()
if showNoInternetBanner {
NoInternetBannerView()
.transition(getBannerTransition(.bottom))
}
}
}
.onAppear {
showWelcomeScreen = !hasSeenWelcomeScreen
}
.onReceive(networkMonitor.$isConnected) { isConnected in
setShowNoInternetBanner(!isConnected)
}
}

private func setShowNoInternetBanner(_ value: Bool) {
withAnimation {
showNoInternetBanner = value
}
}

private func dismissWelcomeScreen() {
showWelcomeScreen = false
hasSeenWelcomeScreen = true
}
}

#Preview {
ContentView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

func getBannerTransition(_ edge: Edge) -> some Transition {
MoveTransition
.move(edge: edge)
.combined(with: .opacity)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

struct BannerView: View {
let label: String
let systemImage: String
let color: Color

init(
label: String,
systemImage: String,
color: Color? = nil
) {
self.label = label
self.systemImage = systemImage
self.color = color?.opacity(0.5) ?? Color.accentColor.opacity(0)
}

var body: some View {
Label(label, systemImage: systemImage)
.font(.footnote.bold())
.frame(maxWidth: .infinity)
.padding(.vertical, 8)
.background(color)
.background(
.ultraThinMaterial,
in: RoundedRectangle(cornerRadius: 10)
)
.padding()
}
}

#Preview {
VStack {
Spacer()
BannerView(
label: "No Internet Connection",
systemImage: "antenna.radiowaves.left.and.right.slash",
color: .red
)

BannerView(
label: "Tips and tricks",
systemImage: "info.circle"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

struct NoInternetBannerView: View {
var body: some View {
BannerView(
label: "No Internet Connection",
systemImage: "antenna.radiowaves.left.and.right.slash",
color: .red
)
}
}

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

import SwiftUI

struct ClosestStopPageListItemPlaceholderView: View {
let routeLabel: String? // route label will be blured if not specified
let routeLabelBackground: Color

init(
routeLabel: String? = nil,
routeLabelBackground: Color = .gray
) {
self.routeLabel = routeLabel
self.routeLabelBackground = routeLabelBackground
}

var body: some View {
if let routeLabel {
HStack(
alignment: .top,
spacing: 8
) {
RouteNameIconView(
label: routeLabel,
background: routeLabelBackground
)

VStack(alignment: .trailing, spacing: 4) {
HStack {
Text("Loading...")
Spacer()
CountdownView(targetDate: .now + 10 * 60)
}

HStack {
Spacer()
CountdownView(
targetDate: .now + 15 * 60
) {
"Also in \($0)"
}
}
.foregroundStyle(.secondary)
.font(.footnote)
}
.fontWeight(.semibold)
.redacted(reason: .placeholder)
}
} else {
ClosestStopPageListItemView(
routeLabel: "74",
routeLabelBackground: routeLabelBackground,
headsign: "Loading...",
departure: .now + 10 * 60,
nextHeadsign: "Loading...",
nextDeparture: .now + 15 * 60
)
.redacted(reason: .placeholder)
}
}
}

#Preview {
List {
ClosestStopPageListItemPlaceholderView(
routeLabel: "A",
routeLabelBackground: getRouteColor("A")
)
ClosestStopPageListItemPlaceholderView(
routeLabel: "A",
routeLabelBackground: getRouteColor("A")
)
ClosestStopPageListItemPlaceholderView(
routeLabel: "C",
routeLabelBackground: getRouteColor("C")
)
ClosestStopPageListItemPlaceholderView(
routeLabel: "C",
routeLabelBackground: getRouteColor("C")
)
ClosestStopPageListItemPlaceholderView(
routeLabel: nil,
routeLabelBackground: getRouteColor("49")
)
ClosestStopPageListItemPlaceholderView(
routeLabel: nil,
routeLabelBackground: getRouteColor("149")
)
ClosestStopPageListItemPlaceholderView(
routeLabel: nil,
routeLabelBackground: getRouteColor("P2")
)
ClosestStopPageListItemPlaceholderView(
routeLabel: nil,
routeLabelBackground: getRouteColor("LD")
)
}
}
Loading

0 comments on commit d612e83

Please sign in to comment.