Skip to content

Commit 1c0a23e

Browse files
committed
Put in TabView, added basic list
1 parent 1a17246 commit 1c0a23e

6 files changed

Lines changed: 153 additions & 37 deletions

File tree

Elsewhen.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
5EB23BA426E406B900203153 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5EB23BA326E406B900203153 /* Preview Assets.xcassets */; };
1515
5EB31FB726E6390D00826907 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB31FB626E6390D00826907 /* SearchBar.swift */; };
1616
5EE70E2226EC9AA600F3F164 /* TimeZoneFlags.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EE70E2126EC9AA500F3F164 /* TimeZoneFlags.swift */; };
17+
5EE70E2426ECBEED00F3F164 /* MykeMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EE70E2326ECBEED00F3F164 /* MykeMode.swift */; };
18+
5EE70E2726ECCC0700F3F164 /* TimeCodeGeneratorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EE70E2626ECCC0700F3F164 /* TimeCodeGeneratorView.swift */; };
1719
635C8FA726E66E8300361B08 /* DiscordFormattedDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635C8FA626E66E8300361B08 /* DiscordFormattedDate.swift */; };
1820
6378397E26EA5FD60055A10D /* UIApplication+clearLaunchScreenCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6378397D26EA5FD60055A10D /* UIApplication+clearLaunchScreenCache.swift */; };
1921
6378398026EA61AB0055A10D /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6378397F26EA61AB0055A10D /* Launch Screen.storyboard */; };
@@ -74,6 +76,8 @@
7476
5EB23BA326E406B900203153 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
7577
5EB31FB626E6390D00826907 /* SearchBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
7678
5EE70E2126EC9AA500F3F164 /* TimeZoneFlags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZoneFlags.swift; sourceTree = "<group>"; };
79+
5EE70E2326ECBEED00F3F164 /* MykeMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MykeMode.swift; sourceTree = "<group>"; };
80+
5EE70E2626ECCC0700F3F164 /* TimeCodeGeneratorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeCodeGeneratorView.swift; sourceTree = "<group>"; };
7781
635C8FA626E66E8300361B08 /* DiscordFormattedDate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscordFormattedDate.swift; sourceTree = "<group>"; };
7882
6378397D26EA5FD60055A10D /* UIApplication+clearLaunchScreenCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+clearLaunchScreenCache.swift"; sourceTree = "<group>"; };
7983
6378397F26EA61AB0055A10D /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
@@ -145,10 +149,12 @@
145149
5EB23B9B26E406B600203153 /* Elsewhen */ = {
146150
isa = PBXGroup;
147151
children = (
152+
5EE70E2526ECCBF400F3F164 /* Views */,
148153
6378398126EB7F510055A10D /* Elements */,
149154
6378397C26EA5FA50055A10D /* Extensions */,
150155
5EB23B9C26E406B600203153 /* ElsewhenApp.swift */,
151156
5EB23B9E26E406B600203153 /* ContentView.swift */,
157+
5EE70E2326ECBEED00F3F164 /* MykeMode.swift */,
152158
6378398426EB80F50055A10D /* DateHelpers.swift */,
153159
5EB31FB626E6390D00826907 /* SearchBar.swift */,
154160
5EE70E2126EC9AA500F3F164 /* TimeZoneFlags.swift */,
@@ -167,6 +173,14 @@
167173
path = "Preview Content";
168174
sourceTree = "<group>";
169175
};
176+
5EE70E2526ECCBF400F3F164 /* Views */ = {
177+
isa = PBXGroup;
178+
children = (
179+
5EE70E2626ECCC0700F3F164 /* TimeCodeGeneratorView.swift */,
180+
);
181+
path = Views;
182+
sourceTree = "<group>";
183+
};
170184
6378397C26EA5FA50055A10D /* Extensions */ = {
171185
isa = PBXGroup;
172186
children = (
@@ -358,9 +372,11 @@
358372
files = (
359373
5EE70E2226EC9AA600F3F164 /* TimeZoneFlags.swift in Sources */,
360374
5EB23B9F26E406B600203153 /* ContentView.swift in Sources */,
375+
5EE70E2426ECBEED00F3F164 /* MykeMode.swift in Sources */,
361376
5EB31FB726E6390D00826907 /* SearchBar.swift in Sources */,
362377
6378397E26EA5FD60055A10D /* UIApplication+clearLaunchScreenCache.swift in Sources */,
363378
5EAB48DD26E624CD00B04A60 /* TimezoneChoiceView.swift in Sources */,
379+
5EE70E2726ECCC0700F3F164 /* TimeCodeGeneratorView.swift in Sources */,
364380
6378398726EBA7C60055A10D /* DateTimeSelection.swift in Sources */,
365381
6378398326EB80C30055A10D /* ResultSheet.swift in Sources */,
366382
6378398526EB80F50055A10D /* DateHelpers.swift in Sources */,

Elsewhen/ContentView.swift

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,19 @@ let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "times")
1414

1515
struct ContentView: View {
1616

17-
@State private var selectedDate = Date()
18-
@State private var selectedFormatStyle: DateFormat = dateFormats[0]
19-
@State private var selectedTimeZone: String = TimeZone.current.identifier
20-
@State private var showLocalTimeInstead: Bool = false
21-
22-
private var discordFormat: String {
23-
var timeIntervalSince1970 = Int(selectedDate.timeIntervalSince1970)
24-
25-
if let tz = TimeZone(identifier: selectedTimeZone) {
26-
timeIntervalSince1970 = Int(convertSelectedDate(from: tz, to: TimeZone.current).timeIntervalSince1970)
27-
} else {
28-
logger.warning("\(selectedTimeZone, privacy: .public) is not a valid timezone identifier!")
29-
}
30-
31-
return "<t:\(timeIntervalSince1970):\(selectedFormatStyle.code.rawValue)>"
32-
}
17+
@State private var selectedTab: Int = 1
3318

3419
var body: some View {
35-
NavigationView {
36-
VStack(spacing: 0) {
37-
38-
ScrollView(showsIndicators: true) {
39-
DateTimeSelection(selectedFormatStyle: $selectedFormatStyle, selectedDate: $selectedDate, selectedTimeZone: $selectedTimeZone)
40-
}
41-
42-
ResultSheet(selectedDate: selectedDate, selectedTimeZone: selectedTimeZone, discordFormat: discordFormat, showLocalTimeInstead: $showLocalTimeInstead, selectedFormatStyle: $selectedFormatStyle)
43-
44-
}
45-
.edgesIgnoringSafeArea([.bottom, .horizontal])
46-
.navigationTitle("Discord Time Code Generator")
47-
.navigationBarTitleDisplayMode(.inline)
48-
}
49-
.navigationViewStyle(StackNavigationViewStyle())
50-
.onChange(of: selectedTimeZone) { _ in
51-
showLocalTimeInstead = false
20+
TabView(selection: $selectedTab) {
21+
TimeCodeGeneratorView()
22+
.tabItem { Label("Time Codes", systemImage: "clock") }
23+
.tag(0)
24+
MykeMode()
25+
.tabItem { Label("Myke Mode", systemImage: "keyboard") }
26+
.tag(1)
5227
}
5328
}
5429

55-
func convertSelectedDate(from initialTimezone: TimeZone, to targetTimezone: TimeZone) -> Date {
56-
return convert(date: selectedDate, from: initialTimezone, to: targetTimezone)
57-
}
5830
}
5931

6032
struct ContentView_Previews: PreviewProvider {

Elsewhen/Elements/ResultSheet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct ResultSheet: View {
133133
.frame(minWidth: 0, maxWidth: .infinity)
134134
.background(
135135
Color(UIColor.secondarySystemBackground)
136-
.shadow(radius: 10)
136+
.shadow(radius: 5, x: 0, y: -5)
137137
)
138138
}
139139

Elsewhen/MykeMode.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// MykeMode.swift
3+
// MykeMode
4+
//
5+
// Created by Ben Cardy on 11/09/2021.
6+
//
7+
8+
import SwiftUI
9+
10+
struct MykeMode: View {
11+
12+
@State private var selectedDate: Date = Date(timeIntervalSince1970: TimeInterval(1631892600))
13+
@State private var selectedTimeZones: [TimeZone] = [
14+
TimeZone(identifier: "America/Los_Angeles")!,
15+
TimeZone(identifier: "America/New_York")!,
16+
TimeZone(identifier: "Europe/London")!,
17+
TimeZone(identifier: "Europe/Budapest")!,
18+
]
19+
20+
func selectedTimeInZone(_ zone: TimeZone) -> String {
21+
let df = DateFormatter()
22+
df.dateStyle = .none
23+
df.timeStyle = .short
24+
df.timeZone = zone
25+
df.locale = Locale(identifier: "en/us")
26+
return df.string(from: selectedDate)
27+
}
28+
29+
var body: some View {
30+
31+
VStack(alignment: .leading, spacing: 20) {
32+
33+
Text("\(selectedDate)")
34+
35+
List {
36+
ForEach(selectedTimeZones, id: \.self) { tz in
37+
HStack {
38+
Text("\(flagForTimeZone(tz)) \(selectedTimeInZone(tz))")
39+
Spacer()
40+
if let abbreviation = tz.abbreviation() {
41+
Text(abbreviation)
42+
.foregroundColor(.secondary)
43+
}
44+
}
45+
}
46+
.onMove(perform: move)
47+
}
48+
49+
}
50+
51+
}
52+
53+
func move(from source: IndexSet, to destination: Int) {
54+
selectedTimeZones.move(fromOffsets: source, toOffset: destination)
55+
}
56+
57+
}
58+
59+
struct MykeMode_Previews: PreviewProvider {
60+
static var previews: some View {
61+
MykeMode()
62+
}
63+
}

Elsewhen/TimeZoneFlags.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import Foundation
99

10+
func flagForTimeZone(_ zone: TimeZone) -> String {
11+
return flagForTimeZone(zone.identifier)
12+
}
13+
1014
func flagForTimeZone(_ zone: String) -> String {
1115
return timeZoneFlags[zone] ?? "🏳️"
1216
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// TimeCodeGeneratorView.swift
3+
// TimeCodeGeneratorView
4+
//
5+
// Created by Ben Cardy on 11/09/2021.
6+
//
7+
8+
import SwiftUI
9+
import MobileCoreServices
10+
import UniformTypeIdentifiers
11+
12+
struct TimeCodeGeneratorView: View {
13+
14+
@State private var selectedDate = Date()
15+
@State private var selectedFormatStyle: DateFormat = dateFormats[0]
16+
@State private var selectedTimeZone: String = TimeZone.current.identifier
17+
@State private var showLocalTimeInstead: Bool = false
18+
19+
private var discordFormat: String {
20+
var timeIntervalSince1970 = Int(selectedDate.timeIntervalSince1970)
21+
22+
if let tz = TimeZone(identifier: selectedTimeZone) {
23+
timeIntervalSince1970 = Int(convertSelectedDate(from: tz, to: TimeZone.current).timeIntervalSince1970)
24+
} else {
25+
logger.warning("\(selectedTimeZone, privacy: .public) is not a valid timezone identifier!")
26+
}
27+
28+
return "<t:\(timeIntervalSince1970):\(selectedFormatStyle.code.rawValue)>"
29+
}
30+
31+
var body: some View {
32+
NavigationView {
33+
VStack(spacing: 0) {
34+
35+
ScrollView(showsIndicators: true) {
36+
DateTimeSelection(selectedFormatStyle: $selectedFormatStyle, selectedDate: $selectedDate, selectedTimeZone: $selectedTimeZone)
37+
}
38+
39+
ResultSheet(selectedDate: selectedDate, selectedTimeZone: selectedTimeZone, discordFormat: discordFormat, showLocalTimeInstead: $showLocalTimeInstead, selectedFormatStyle: $selectedFormatStyle)
40+
41+
}
42+
.edgesIgnoringSafeArea(.horizontal)
43+
.navigationTitle("Discord Time Code Generator")
44+
.navigationBarTitleDisplayMode(.inline)
45+
}
46+
.navigationViewStyle(StackNavigationViewStyle())
47+
.onChange(of: selectedTimeZone) { _ in
48+
showLocalTimeInstead = false
49+
}
50+
}
51+
52+
func convertSelectedDate(from initialTimezone: TimeZone, to targetTimezone: TimeZone) -> Date {
53+
return convert(date: selectedDate, from: initialTimezone, to: targetTimezone)
54+
}
55+
}
56+
57+
struct TimeCodeGeneratorView_Previews: PreviewProvider {
58+
static var previews: some View {
59+
TimeCodeGeneratorView()
60+
}
61+
}

0 commit comments

Comments
 (0)