captains-log

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

commit 8b0e9b92ace66fa4cf8f40609180e2f29f42b683
parent d63835c508f9961f1794fad3646f9218bbf8c41e
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Fri, 25 Oct 2019 19:21:27 -0700

Date functions, default name, and previous recordings button

Diffstat:
AGlobalVars.swift | 41+++++++++++++++++++++++++++++++++++++++++
MSettings.swift | 6++++--
AcaptainsLog.xcodeproj/xcuserdata/figbert.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist | 6++++++
McaptainsLog/ContentView.swift | 12+++++++-----
McaptainsLog/Elements.swift | 155+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
5 files changed, 210 insertions(+), 10 deletions(-)

diff --git a/GlobalVars.swift b/GlobalVars.swift @@ -0,0 +1,41 @@ +// +// File.swift +// captainsLog +// +// Created by Benjamin Welner on 10/21/19. +// Copyright © 2019 FIGBERT Industries. All rights reserved. +// + +import Foundation +import GameKit +import Combine +import SwiftUI + +class SettingsVars: ObservableObject { + let objectWillChange = PassthroughSubject<settingsVars,Never>() + var saveLocally = true { + didSet { + objectWillChange.send(self) + } + } + var saveICloud = true { + didSet { + objectWillChange.send(self) + } + } + var currentDateFormat = 0 { + didSet { + objectWillChange.send(self) + } + } + var currentMessage = 0 { + didSet { + objectWillChange.send(self) + } + } + var name: String = GKPlayer.init().alias { + didSet { + objectWillChange.send(self) + } + } +} diff --git a/Settings.swift b/Settings.swift @@ -7,13 +7,14 @@ // import SwiftUI +import GameKit struct Settings: View { @State private var saveLocally = true @State private var saveICloud = true @State private var currentDateFormat = 0 @State private var currentMessage = 0 - @State private var name = "User" + @State private var name = GKPlayer.init().alias var dateFormats = [ "Stardate", "Gregorian date", @@ -31,6 +32,7 @@ struct Settings: View { "Here's the tea, sis", "Rise and grind, gamers" ] + var body: some View { Form { Section(header: Text("Save")) { @@ -58,7 +60,7 @@ struct Settings: View { } } .navigationBarTitle( - Text("Captain's Log Settings"), + Text("Settings"), displayMode: .inline ) } diff --git a/captainsLog.xcodeproj/xcuserdata/figbert.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/captainsLog.xcodeproj/xcuserdata/figbert.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Bucket + uuid = "D0D69465-7F7D-4A35-AB35-4F38A40F58AD" + type = "1" + version = "2.0"> +</Bucket> diff --git a/captainsLog/ContentView.swift b/captainsLog/ContentView.swift @@ -13,7 +13,6 @@ struct ContentView: View { @State private var timeElapsed: Double = 0.00 @State private var timer:Timer? @State private var msg: String = "" - @State private var date = Date() var body: some View { NavigationView { @@ -32,7 +31,7 @@ struct ContentView: View { } else if (self.timeElapsed <= 2.25) { self.msg = "stardate" } else if (self.timeElapsed <= 5) { - self.msg = "\(self.date.stardate())" + self.msg = "\(Date().stardate())" } else { self.msg = "" } @@ -74,10 +73,15 @@ struct ContentView: View { .foregroundColor(Color.primary) } else { Button(action: { - print("TODO") + 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: Settings()) { imgTextButtonStyle(sysImg: "gear", imgSize: 15, buttonText: "Settings") } @@ -85,8 +89,6 @@ struct ContentView: View { } Spacer() } - //Does this look good? I don't know - .navigationBarTitle(Text("Home")) } } } diff --git a/captainsLog/Elements.swift b/captainsLog/Elements.swift @@ -17,8 +17,8 @@ extension Double { } } extension Date { - func stardate() -> Double { - let calendar = Calendar.current + func stardate() -> String { + let calendar: Calendar = Calendar.init(identifier: .gregorian) let year = calendar.component(.year, from: self) let month = calendar.component(.month, from: self) let day = calendar.component(.day, from: self) @@ -44,7 +44,156 @@ extension Date { let stageOne = Double(1000*(year-b)) let stageTwo = (1000.0/Double(n))*(monthValue + Double(day) - 1.0) let stageThree = c + stageOne + stageTwo - return Double(round(100*stageThree)/100) + let stardate = Double(round(100*stageThree)/100).withCommas() + return "stardate \(stardate)" + } + func multi(type: String) -> String { + let calendar_list: [String: [String]] = [ + "jewish": [ + "Tishrei", + "Cheshvan", + "Kislev", + "Tevet", + "Shevat", + "Adar", + "Adar II", + "Nisan", + "Iyar", + "Sivan", + "Tamuz", + "Av", + "Elul" + ], + "islamic": [ + "Muharram", + "Safar", + "Rabi al-Awwal", + "Rabi al-Thani", + "Jumada al-Ula", + "Jumada al-Akhirah", + "Rajab", + "Sha'ban", + "Ramadan", + "Shawwal", + "Zulqiddah", + "Zulhijjah" + ], + "persian": [ + "Farvardin", + "Ordibehesht", + "Khordad", + "Tir", + "Mordad", + "Shahrivar", + "Mehr", + "Aban", + "Azar", + "Dey", + "Bahman", + "Esfand" + ], + "indian": [ + "Vaisakha", + "Jyeshtha", + "Ashadha", + "Shraavana", + "Bhadra", + "Ashvin", + "Kartik", + "Agahana", + "Pausha", + "Magha", + "Phalguna", + "Chaitra" + ], + "coptic": [ + "Thout", + "Paopi", + "Hathor", + "Koiak", + "Tobi", + "Meshir", + "Paremhat", + "Parmouti", + "Pashons", + "Paoni", + "Epip", + "Mesori", + "Pi Kogi Enavot" + ], + "chinese": [ + "yínyuè", + "mǎoyuè", + "chényuè", + "sìyuè", + "wǔyuè", + "wèiyuè", + "shēnyuè", + "yǒuyuè", + "xūyuè", + "hàiyuè", + "zǐyuè", + "chǒuyuè" + ], + "japanese": [ + "Mutsuki", + "Kisaragi", + "Yayoi", + "Uzuki", + "Satsuki", + "Minazuki", + "Fumizuki", + "Hazuki", + "Nagatsuki", + "Kannazuki", + "Shimotsuki", + "Shiwasu" + ], + "ethiopian": [ + "Mäskäräm", + "Ṭəqəmt", + "Ḫədar", + "Taḫśaś", + "Ṭərr", + "Yäkatit", + "Mägabit", + "Miyazya", + "Gənbo", + "Säne", + "Ḥamle", + "Nähase", + "Ṗagume" + ] + ] + var calendar: Calendar + switch type { + case "jewish": + calendar = Calendar.init(identifier: .hebrew) + case "islamic": + calendar = Calendar.init(identifier: .islamic) + case "persian": + calendar = Calendar.init(identifier: .persian) + case "indian": + calendar = Calendar.init(identifier: .indian) + case "coptic": + calendar = Calendar.init(identifier: .coptic) + case "ethiopian": + calendar = Calendar.init(identifier: .ethiopicAmeteAlem) + case "chinese": + calendar = Calendar.init(identifier: .chinese) + case "japanese": + calendar = Calendar.init(identifier: .japanese) + default: + calendar = Calendar.init(identifier: .gregorian) + } + let year = calendar.component(.year, from: self) + let numMonth = calendar.component(.month, from: self) + let month = calendar_list["\(type)"]?[numMonth-1] + 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)" } }