captains-log

[TO-FIX] audiojournaling app
git clone git://git.figbert.com/captains-log.git
Log | Files | Refs

commit 53ec47928b001c82d3689ccf1e2b67a8603a629d
parent da33c93921f4efcf05811455aa3d3039c819f87d
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Tue, 29 Oct 2019 12:47:32 -0700

Adding previous recordings page, fixing dark mode buttons and waveform issues, inital settings string interpolation fix, preparing for dynamic introduction feature

Diffstat:
MGlobalVars.swift | 28+++++++++++++++++++++++-----
McaptainsLog.xcodeproj/project.pbxproj | 4++++
McaptainsLog/ContentView.swift | 38++++++++++++++++++--------------------
McaptainsLog/Elements.swift | 19++++++++++---------
AcaptainsLog/PreviousRecordings.swift | 37+++++++++++++++++++++++++++++++++++++
5 files changed, 92 insertions(+), 34 deletions(-)

diff --git a/GlobalVars.swift b/GlobalVars.swift @@ -28,6 +28,11 @@ class GlobalVars: ObservableObject { objectWillChange.send(self) } } + var dateListPos: Int = 0 { + didSet { + objectWillChange.send(self) + } + } var currentMessage: Int = 0 { didSet { objectWillChange.send(self) @@ -54,12 +59,24 @@ class GlobalVars: ObservableObject { objectWillChange.send(self) } } + var previousRecordings: [[String: String]] = [ + [ + "title": "Example", + "date": "00 in Forblgartz, 94560", + "number": "1" + ] + ] var messages: [String] { didSet { objectWillChange.send(self) } } - var date: String { + var date: [String] { + didSet { + objectWillChange.send(self) + } + } + var strDate: String = "" { didSet { objectWillChange.send(self) } @@ -87,13 +104,14 @@ class GlobalVars: ObservableObject { default: date = Date().stardate() } + strDate = date.joined(separator: currentDateFormat == 0 ? " " : "") messages = [ - "Captain’s log, \(date)", - "A day in the life of \(name), entry [NUM]", - "\(name)'s audio journal, day [NUM]", + "Captain’s log, \(strDate)", + "A day in the life of \(name), entry \(Int(previousRecordings.last!["number"]!)!+1)", + "\(name)'s audio journal, day \(Int(previousRecordings.last!["number"]!)!+1)", "Hi, I'm \(name)", "\(name)'s audio journal, for your ears only.", - "Random thoughts, entry [NUM]", + "Random thoughts, entry \(Int(previousRecordings.last!["number"]!)!+1)", "Here's the tea, sis", "Rise and grind, gamers" ] diff --git a/captainsLog.xcodeproj/project.pbxproj b/captainsLog.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 3A2D60F6236801FD004FA1CD /* PreviousRecordings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2D60F5236801FD004FA1CD /* PreviousRecordings.swift */; }; 3A35D6E023579F7B005B7610 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A35D6DF23579F7B005B7610 /* AppDelegate.swift */; }; 3A35D6E223579F7B005B7610 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A35D6E123579F7B005B7610 /* SceneDelegate.swift */; }; 3A35D6E423579F7B005B7610 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A35D6E323579F7B005B7610 /* ContentView.swift */; }; @@ -19,6 +20,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 3A2D60F5236801FD004FA1CD /* PreviousRecordings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviousRecordings.swift; sourceTree = "<group>"; }; 3A35D6DC23579F7B005B7610 /* captainsLog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = captainsLog.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3A35D6DF23579F7B005B7610 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 3A35D6E123579F7B005B7610 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; }; @@ -66,6 +68,7 @@ 3A35D6E123579F7B005B7610 /* SceneDelegate.swift */, 3A35D6E323579F7B005B7610 /* ContentView.swift */, 3A76A1E7235AD08C00964901 /* Settings.swift */, + 3A2D60F5236801FD004FA1CD /* PreviousRecordings.swift */, 3A76A1E9235AE6D500964901 /* Elements.swift */, 3A64E4F42363E98A00B5389D /* GlobalVars.swift */, 3A35D6E523579F7C005B7610 /* Assets.xcassets */, @@ -159,6 +162,7 @@ 3A35D6E223579F7B005B7610 /* SceneDelegate.swift in Sources */, 3A35D6E423579F7B005B7610 /* ContentView.swift in Sources */, 3A76A1E8235AD08C00964901 /* Settings.swift in Sources */, + 3A2D60F6236801FD004FA1CD /* PreviousRecordings.swift in Sources */, 3A64E4F52363E98A00B5389D /* GlobalVars.swift in Sources */, 3A76A1EA235AE6D500964901 /* Elements.swift in Sources */, ); diff --git a/captainsLog/ContentView.swift b/captainsLog/ContentView.swift @@ -29,12 +29,11 @@ struct ContentView: View { self.msg = "Captain's" } else if (self.timeElapsed <= 1.5) { self.msg = "log" - } else if (self.timeElapsed <= 2.25) { - self.msg = "stardate" - } else if (self.timeElapsed <= 5) { - self.msg = "\(Date().stardate())" } else { - self.msg = "" + self.msg = self.globalVars.date[self.globalVars.dateListPos] + if (self.globalVars.dateListPos+1 <= self.globalVars.date.count-1) { + self.globalVars.dateListPos += 1 + } } }) } else { @@ -61,27 +60,25 @@ struct ContentView: View { if (self.recording) { Text("\(self.msg)") .font(.system(size: 24, weight: .regular, design: .rounded)) - Image( - uiImage: UIImage( - systemName: "waveform", - withConfiguration: UIImage.SymbolConfiguration( - pointSize: CGFloat.init(50), - weight: .medium, - scale: .large - ) - )! - ) - .foregroundColor(Color.primary) + Image(systemName: "waveform") + .font(.system(size: 50, weight: .regular)) + .imageScale(.large) + .foregroundColor(.primary) } else { Button(action: { + self.globalVars.previousRecordings.append( + [ + "title": "Temporary", + "date": "\(self.globalVars.strDate)", + "number": "\((Int(self.globalVars.previousRecordings.last!["number"]!)!)+1)" + ] + ) self.timeElapsed = 0.00 }) { imgTextButtonStyle(sysImg: "waveform", imgSize: 15, buttonText: "Save") } - Button(action: { - print("TODO") - }) { - imgTextButtonStyle(sysImg: "tray.full", imgSize: 15, buttonText: "Previous") + NavigationLink(destination: PreviousRecordings()) { + imgTextButtonStyle(sysImg: "tray.full", imgSize: 15, buttonText: "Previous") } NavigationLink(destination: Settings()) { imgTextButtonStyle(sysImg: "gear", imgSize: 15, buttonText: "Settings") @@ -97,5 +94,6 @@ struct ContentView: View { struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView().environmentObject(GlobalVars()) + //.colorScheme(.dark) } } diff --git a/captainsLog/Elements.swift b/captainsLog/Elements.swift @@ -17,7 +17,7 @@ extension Double { } } extension Date { - func stardate() -> String { + func stardate() -> [String] { let calendar: Calendar = Calendar.init(identifier: .gregorian) let year = calendar.component(.year, from: self) let month = calendar.component(.month, from: self) @@ -44,10 +44,10 @@ extension Date { let stageOne = Double(1000*(year-b)) let stageTwo = (1000.0/Double(n))*(monthValue + Double(day) - 1.0) let stageThree = c + stageOne + stageTwo - let stardate = Double(round(100*stageThree)/100).withCommas() - return "stardate \(stardate)" + let stardate = String(Double(round(100*stageThree)/100).withCommas()) + return ["stardate", stardate] } - func multi(type: String) -> String { + func multi(type: String) -> [String] { let calendar_list: [String: [String]] = [ "Jewish": [ "Tishrei", @@ -200,14 +200,14 @@ extension Date { default: calendar = Calendar.init(identifier: .gregorian) } - let year = calendar.component(.year, from: self) + let year = String(calendar.component(.year, from: self)) let numMonth = calendar.component(.month, from: self) - let month = calendar_list["\(type)"]?[numMonth-1] + let month = calendar_list["\(type)"]?[numMonth-1] ?? "month" let dayNum = calendar.component(.day, from: self) let numberFormatter = NumberFormatter() numberFormatter.numberStyle = .ordinal - let day = numberFormatter.string(from: NSNumber(value: dayNum)) - return "\(day ?? "day") of \(month ?? "month"), \(year)" + let day = String(numberFormatter.string(from: NSNumber(value: dayNum)) ?? "day") + return [day, " of ", month, ", ", year] } } @@ -215,6 +215,7 @@ struct imgTextButtonStyle: View { var sysImg: String var imgSize: Int var buttonText: String + @Environment(\.colorScheme) var colorScheme: ColorScheme var body: some View { HStack { @@ -232,7 +233,7 @@ struct imgTextButtonStyle: View { } .padding() .background(Color.primary) - .foregroundColor(Color.white) + .foregroundColor(colorScheme == .light ? Color.white : Color.black) .cornerRadius(50) } } diff --git a/captainsLog/PreviousRecordings.swift b/captainsLog/PreviousRecordings.swift @@ -0,0 +1,37 @@ +// +// PreviousRecordings.swift +// captainsLog +// +// Created by Benjamin Welner on 10/28/19. +// Copyright © 2019 FIGBERT Industries. All rights reserved. +// + +import SwiftUI + +struct PreviousRecordings: View { + @EnvironmentObject var globalVars: GlobalVars + var body: some View { + Form { + Section { + ForEach(0 ..< globalVars.previousRecordings.count) {pos in + VStack(alignment: .leading) { + Text("\(self.globalVars.previousRecordings[pos]["title"] ?? "Title")") + .font(.headline) + Text("\(self.globalVars.previousRecordings[pos]["date"] ?? "Date")") + .font(.caption) + } + } + } + } + .navigationBarTitle( + Text("Recordings"), + displayMode: .inline + ) + } +} + +struct PreviousRecordings_Previews: PreviewProvider { + static var previews: some View { + PreviousRecordings().environmentObject(GlobalVars()) + } +}