Previous recordings detail view template

This commit is contained in:
relikd
2020-04-06 23:37:46 +02:00
parent 515c296b26
commit 647eca310f
7 changed files with 197 additions and 73 deletions

View File

@@ -53,6 +53,10 @@ class TVCPreviousRecords: UITableViewController {
let target = segue.destination as! VCEditRecording
target.record = record
target.deleteOnCancel = newlyCreated
} else if segue.identifier == "openRecordDetailsSegue" {
if let i = tableView.indexPathForSelectedRow {
(segue.destination as? TVCRecordingDetails)?.record = dataSource[i.row]
}
}
}

View File

@@ -0,0 +1,29 @@
import UIKit
class TVCRecordingDetails: UITableViewController {
var record: Recording!
private var dataSource: [(domain: String, count: Int)] = [
("apple.com", 3),
("cdn.apple.com", 1)
]
override func viewDidLoad() {
title = record.title ?? record.fallbackTitle
// TODO: load db entries
}
// MARK: - Table View Data Source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
dataSource.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PreviousRecordDetailCell")!
let x = dataSource[indexPath.row]
cell.textLabel?.text = x.domain
cell.detailTextLabel?.text = "\(x.count)"
return cell
}
}

View File

@@ -16,9 +16,9 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
inputTitle.text = record.title
inputNotes.text = record.notes
inputDetails.text = """
Start:\t\t\(record.start.asDateTime())
End:\t\t\(record.stop?.asDateTime() ?? "?")
Duration:\t\(record.durationString ?? "?")
Start: \(record.start.asDateTime())
End: \(record.stop?.asDateTime() ?? "?")
Duration: \(record.durationString ?? "?")
"""
validateSaveButton()
if deleteOnCancel { // mark as destructive
@@ -28,13 +28,8 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
UIResponder.keyboardWillHideNotification.observe(call: #selector(keyboardWillHide), on: self)
}
func textFieldDidChangeSelection(_ _: UITextField) { validateSaveButton() }
func textViewDidChange(_ _: UITextView) { validateSaveButton() }
private func validateSaveButton() {
let changed = (inputTitle.text != record.title ?? "" || inputNotes.text != record.notes ?? "")
buttonSave.isEnabled = changed || deleteOnCancel // always allow save for new recordings
}
// MARK: Save & Cancel Buttons
@IBAction func didTapSave(_ sender: UIBarButtonItem) {
if deleteOnCancel { // aka newly created
@@ -63,13 +58,6 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == inputTitle {
return inputNotes.becomeFirstResponder()
}
return true
}
// MARK: Handle Keyboard & Notes Frame
@@ -116,4 +104,19 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
noteBottom.constant = adjust ? view.frame.height - stack.frame.maxY - keyboardHeight : 0
}
// MARK: TextField & TextView Delegate
func textFieldDidChangeSelection(_ _: UITextField) { validateSaveButton() }
func textViewDidChange(_ _: UITextView) { validateSaveButton() }
private func validateSaveButton() {
let changed = (inputTitle.text != record.title ?? "" || inputNotes.text != record.notes ?? "")
buttonSave.isEnabled = changed || deleteOnCancel // always allow save for new recordings
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField == inputTitle ? inputNotes.becomeFirstResponder() : true
}
}

View File

@@ -1,13 +1,17 @@
import UIKit
class VCRecordings: UIViewController {
class VCRecordings: UIViewController, UINavigationControllerDelegate {
private var currentRecording: Recording?
private var recordingTimer: Timer?
@IBOutlet private var timeLabel: UILabel!
@IBOutlet private var startButton: UIButton!
@IBOutlet private var startNewRecView: UIView!
private var prevRecController: UINavigationController!
override func viewDidLoad() {
prevRecController = (children.first as! UINavigationController)
prevRecController.delegate = self
// Duplicate font attributes but set monospace
let traits = timeLabel.font.fontDescriptor.object(forKey: .traits) as? [UIFontDescriptor.TraitKey: Any] ?? [:]
let weight = traits[.weight] as? CGFloat ?? UIFont.Weight.regular.rawValue
@@ -25,14 +29,25 @@ class VCRecordings: UIViewController {
stopTimer(animate: false)
}
@IBAction private func recordingButtonTapped(_ sender: UIButton) {
func navigationController(_ navigationController: UINavigationController, willShow vc: UIViewController, animated: Bool) {
let isRoot = (vc == navigationController.viewControllers.first)
UIView.animate(withDuration: 0.3) {
self.startNewRecView.isHidden = !isRoot // hide "new recording" if details open
}
}
// MARK: Start New Recording
@IBAction private func startRecordingButtonTapped(_ sender: UIButton) {
if recordingTimer == nil {
currentRecording = DBWrp.recordingStartNew()
startTimer(animate: true)
} else {
stopTimer(animate: true)
DBWrp.recordingStopAll()
(children.first as! TVCPreviousRecords).stopRecording(currentRecording!)
prevRecController.popToRootViewController(animated: true)
(prevRecController.topViewController as! TVCPreviousRecords).stopRecording(currentRecording!)
currentRecording = nil // otherwise it will restart
}
}