captains-log

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

commit dda4c9ad3227c7cbd5f1ae96b21a41abc7934b0b
parent 0eb4e83758623590d615efd918102bf6eeb9e47b
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Tue,  5 Nov 2019 23:00:03 -0800

Fixing date string interpolation in the settings page, updating observableObject syntax

Diffstat:
MAudioRecorder.swift | 17+++--------------
MGlobalVars.swift | 101++++++++++++++++++++++++++++++++++---------------------------------------------
McaptainsLog.xcodeproj/project.pbxproj | 2+-
McaptainsLog/AudioPlayer.swift | 16+++-------------
McaptainsLog/ContentView.swift | 8--------
5 files changed, 50 insertions(+), 94 deletions(-)

diff --git a/AudioRecorder.swift b/AudioRecorder.swift @@ -18,20 +18,10 @@ class AudioRecorder: NSObject, ObservableObject { fetchRecordings() } - let objectWillChange = PassthroughSubject<AudioRecorder, Never>() - var audioRecorder: AVAudioRecorder! - var recordings = [Recording]() - var recording: Bool = false { - didSet { - objectWillChange.send(self) - } - } - var hasRecorded: Bool = false { - didSet { - objectWillChange.send(self) - } - } + @Published var recordings = [Recording]() + @Published var recording: Bool = false + @Published var hasRecorded: Bool = false func startRecording() { if (!hasRecorded) { @@ -94,7 +84,6 @@ class AudioRecorder: NSObject, ObservableObject { recordings.append(recording) } recordings.sort(by: { $0.createdAt.compare($1.createdAt) == .orderedAscending}) - objectWillChange.send(self) } func deleteRecording(urlsToDelete: [URL]) { diff --git a/GlobalVars.swift b/GlobalVars.swift @@ -12,38 +12,47 @@ import Combine import SwiftUI class GlobalVars: ObservableObject { - let objectWillChange = PassthroughSubject<GlobalVars,Never>() - var saveLocally: Bool = true { - didSet { - objectWillChange.send(self) + @Published var saveLocally: Bool = true + @Published var saveICloud: Bool = true + @Published var currentDateFormat: Int = 0 { + willSet { + switch newValue { + case 1: + date = Date().multi(type: "Jewish") + case 2: + date = Date().multi(type: "Islamic") + case 3: + date = Date().multi(type: "Persian") + case 4: + date = Date().multi(type: "Indian") + case 5: + date = Date().multi(type: "Coptic") + case 6: + date = Date().multi(type: "Chinese") + case 7: + date = Date().multi(type: "Japanese") + case 8: + date = Date().multi(type: "Ethiopian") + case 9: + date = Date().multi(type: "Gregorian") + default: + date = Date().stardate() + } + strDate = date.joined(separator: newValue == 0 ? " " : "") + messages[0] = "Captain’s log, \(strDate)" } } - var saveICloud: Bool = true { - didSet { - objectWillChange.send(self) + @Published var dateListPos: Int = 0 + @Published var currentMessage: Int = 0 + @Published var name: String = "Unknown" { + willSet { + messages[1] = "A day in the life of \(name), entry \(1)" + messages[2] = "\(name)'s audio journal, day \(1)" + messages[3] = "Hi, I'm \(name)" + messages[4] = "\(name)'s audio journal, for your ears only." } } - var currentDateFormat: Int = 0 { - didSet { - objectWillChange.send(self) - } - } - var dateListPos: Int = 0 { - didSet { - objectWillChange.send(self) - } - } - var currentMessage: Int = 0 { - didSet { - objectWillChange.send(self) - } - } - var name: String = GKPlayer.init().alias { - didSet { - objectWillChange.send(self) - } - } - var dateFormats = [ + let dateFormats = [ "Stardate", "Jewish", "Islamic", @@ -54,34 +63,10 @@ class GlobalVars: ObservableObject { "Japanese", "Ethiopian", "Gregorian" - ] { - didSet { - objectWillChange.send(self) - } - } - var previousRecordings: [[String: String]] = [ - [ - "title": "Example", - "date": "00 in Forblgartz, 94560", - "length": "0:00", - "number": "1" - ] ] - var messages: [String] { - didSet { - objectWillChange.send(self) - } - } - var date: [String] { - didSet { - objectWillChange.send(self) - } - } - var strDate: String = "" { - didSet { - objectWillChange.send(self) - } - } + @Published var messages: [String] = [""] + @Published var date: [String] = [""] + @Published var strDate: String = "" init() { switch currentDateFormat { case 1: @@ -108,11 +93,11 @@ class GlobalVars: ObservableObject { strDate = date.joined(separator: currentDateFormat == 0 ? " " : "") messages = [ "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)", + "A day in the life of \(name), entry \(1)", + "\(name)'s audio journal, day \(1)", "Hi, I'm \(name)", "\(name)'s audio journal, for your ears only.", - "Random thoughts, entry \(Int(previousRecordings.last!["number"]!)!+1)", + "Random thoughts, entry \(1)", "Here's the tea, sis", "Rise and grind, gamers" ] diff --git a/captainsLog.xcodeproj/project.pbxproj b/captainsLog.xcodeproj/project.pbxproj @@ -71,8 +71,8 @@ 3A35D6DF23579F7B005B7610 /* AppDelegate.swift */, 3A35D6E123579F7B005B7610 /* SceneDelegate.swift */, 3A35D6E323579F7B005B7610 /* ContentView.swift */, - 3A2D60F5236801FD004FA1CD /* PreviousRecordings.swift */, 3A76A1E7235AD08C00964901 /* Settings.swift */, + 3A2D60F5236801FD004FA1CD /* PreviousRecordings.swift */, 3A5D1BF323691F6F00677C61 /* AudioRecorder.swift */, 3A10D50F236A25DC00FD1C96 /* AudioPlayer.swift */, 3A76A1E9235AE6D500964901 /* Elements.swift */, diff --git a/captainsLog/AudioPlayer.swift b/captainsLog/AudioPlayer.swift @@ -13,19 +13,9 @@ import AVFoundation class AudioPlayer: NSObject, ObservableObject, AVAudioPlayerDelegate { - let objectWillChange = PassthroughSubject<AudioPlayer, Never>() - - var audioPlayer: AVAudioPlayer! - var isPlaying = false { - didSet { - objectWillChange.send(self) - } - } - var hasPlayed = false { - didSet { - objectWillChange.send(self) - } - } + @Published var audioPlayer: AVAudioPlayer! + @Published var isPlaying = false + @Published var hasPlayed = false func startPlayback(audio: URL) { if (!hasPlayed) { diff --git a/captainsLog/ContentView.swift b/captainsLog/ContentView.swift @@ -67,14 +67,6 @@ struct ContentView: View { .foregroundColor(.primary) } else { Button(action: { - self.globalVars.previousRecordings.append( - [ - "title": "Temporary", - "date": "\(self.globalVars.strDate)", - "length": "\(self.timeElapsed)", - "number": "\((Int(self.globalVars.previousRecordings.last!["number"]!)!)+1)" - ] - ) self.timeElapsed = 0.00 self.audioRecorder.endRecording() }) {