captains-log

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

ContentView.swift (4090B)


      1 //
      2 //  ContentView.swift
      3 //  captainsLog
      4 //
      5 //  Created by Benjamin Welner on 10/16/19.
      6 //  Copyright © 2019 FIGBERT Industries. All rights reserved.
      7 //
      8 
      9 import SwiftUI
     10 
     11 struct ContentView: View {
     12     @EnvironmentObject var globalVars: GlobalVars
     13     @ObservedObject var audioRecorder: AudioRecorder
     14     @State private var timeElapsed: Double = 0.00
     15     @State private var timer:Timer?
     16     @State private var msg: String = ""
     17     let timeBuffer: Double = 1
     18     
     19     var body: some View {
     20         NavigationView {
     21             VStack {
     22                 Spacer()
     23                 VStack {
     24                     Button(action: {
     25                         if (!self.audioRecorder.recording) {
     26                             self.audioRecorder.startRecording()
     27                             self.timer = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true, block: { timer in
     28                                 self.timeElapsed += 0.01
     29                                 if (self.globalVars.dateListPos < self.globalVars.iterateMessage.count) {
     30                                     if (self.timeElapsed <= Double(self.globalVars.dateListPos+1)*self.timeBuffer) {
     31                                         self.msg = self.globalVars.iterateMessage[self.globalVars.dateListPos]
     32                                     } else {
     33                                         self.globalVars.dateListPos += 1
     34                                     }
     35                                 } else {
     36                                     self.msg = ""
     37                                 }
     38                             })
     39                         } else {
     40                             self.audioRecorder.pauseRecording()
     41                             self.timer?.invalidate()
     42                         }
     43                     }) {
     44                         Image(
     45                             uiImage: UIImage(
     46                                 systemName: audioRecorder.recording ? "mic.fill" : "mic",
     47                                 withConfiguration: UIImage.SymbolConfiguration(
     48                                     pointSize: CGFloat.init(100),
     49                                     weight: .regular,
     50                                     scale: .large
     51                                 )
     52                             )!
     53                         )
     54                     }
     55                         .foregroundColor(Color.primary)
     56                         .animation(.none)
     57                     Text("\(timeElapsed, specifier: "%.2f") sec")
     58                 }
     59                 Spacer()
     60                 VStack {
     61                     if (audioRecorder.recording) {
     62                         Text("\(self.msg)")
     63                             .font(.system(size: 24, weight: .regular, design: .rounded))
     64                     } else {
     65                         Button(action: {
     66                             if (self.audioRecorder.hasRecorded) {
     67                                 self.timeElapsed = 0.00
     68                                 self.audioRecorder.endRecording()
     69                                 self.globalVars.dateListPos = 0
     70                             }
     71                         }) {
     72                             imgTextButtonStyle(sysImg: "waveform", imgSize: 15, buttonText: "Save")
     73                         }
     74                         NavigationLink(destination: PreviousRecordings(audioRecorder: AudioRecorder())) {
     75                             imgTextButtonStyle(sysImg: "tray.full", imgSize: 15,  buttonText: "Previous")
     76                         }
     77                         NavigationLink(destination: Settings()) {
     78                             imgTextButtonStyle(sysImg: "gear", imgSize: 15, buttonText: "Settings")
     79                         }.simultaneousGesture(TapGesture().onEnded{
     80                             self.globalVars.dateListPos = 0
     81                         })
     82                     }
     83                 }
     84                 Spacer()
     85             }
     86         }
     87     }
     88 }
     89 
     90 struct ContentView_Previews: PreviewProvider {
     91     static var previews: some View {
     92         ContentView(audioRecorder: AudioRecorder()).environmentObject(GlobalVars())
     93             //.colorScheme(.dark)
     94     }
     95 }