Recording details duplicate and display
This commit is contained in:
@@ -8,17 +8,14 @@ class TVCPreviousRecords: UITableViewController {
|
||||
NotifyRecordingChanged.observe(call: #selector(recordingDidChange(_:)), on: self)
|
||||
}
|
||||
|
||||
func stopRecording(_ record: Recording?) {
|
||||
guard let r = record?.stoppedCopy() else {
|
||||
return
|
||||
}
|
||||
func insertAndEditRecording(_ r: Recording) {
|
||||
insertNewRecord(r)
|
||||
editRecord(r, isNewRecording: true)
|
||||
}
|
||||
|
||||
@objc private func recordingDidChange(_ notification: Notification) {
|
||||
let (new, deleted) = notification.object as! (Recording, Bool)
|
||||
if let i = dataSource.firstIndex(where: { $0.start == new.start }) {
|
||||
if let i = dataSource.firstIndex(where: { $0.id == new.id }) {
|
||||
if deleted {
|
||||
dataSource.remove(at: i)
|
||||
tableView.deleteRows(at: [IndexPath(row: i)], with: .automatic)
|
||||
|
||||
@@ -2,14 +2,11 @@ import UIKit
|
||||
|
||||
class TVCRecordingDetails: UITableViewController {
|
||||
var record: Recording!
|
||||
private var dataSource: [(domain: String, count: Int)] = [
|
||||
("apple.com", 3),
|
||||
("cdn.apple.com", 1)
|
||||
]
|
||||
private var dataSource: [(domain: String?, count: Int32)]!
|
||||
|
||||
override func viewDidLoad() {
|
||||
title = record.title ?? record.fallbackTitle
|
||||
// TODO: load db entries
|
||||
dataSource = DBWrp.recordingDetails(record) ?? []
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,24 +35,24 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
|
||||
if deleteOnCancel { // aka newly created
|
||||
// if remains true, `viewDidDisappear` will delete the record
|
||||
deleteOnCancel = false
|
||||
// TODO: copy db entries in new table for editing
|
||||
}
|
||||
QLog.Debug("updating record \(record.start)")
|
||||
QLog.Debug("updating record #\(record.id)")
|
||||
record.title = (inputTitle.text == "") ? nil : inputTitle.text
|
||||
record.notes = (inputNotes.text == "") ? nil : inputNotes.text
|
||||
dismiss(animated: true) {
|
||||
DBWrp.recordingUpdate(self.record)
|
||||
DBWrp.recordingPersist(self.record)
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func didTapCancel(_ sender: UIBarButtonItem) {
|
||||
QLog.Debug("discard edit of record \(record.start)")
|
||||
QLog.Debug("discard edit of record #\(record.id)")
|
||||
dismiss(animated: true)
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
if deleteOnCancel {
|
||||
QLog.Debug("deleting record \(record.start)")
|
||||
QLog.Debug("deleting record #\(record.id)")
|
||||
DBWrp.recordingDelete(record)
|
||||
deleteOnCancel = false
|
||||
}
|
||||
|
||||
@@ -45,9 +45,10 @@ class VCRecordings: UIViewController, UINavigationControllerDelegate {
|
||||
startTimer(animate: true)
|
||||
} else {
|
||||
stopTimer(animate: true)
|
||||
DBWrp.recordingStopAll()
|
||||
DBWrp.recordingStop(¤tRecording!)
|
||||
prevRecController.popToRootViewController(animated: true)
|
||||
(prevRecController.topViewController as! TVCPreviousRecords).stopRecording(currentRecording!)
|
||||
let editVC = (prevRecController.topViewController as! TVCPreviousRecords)
|
||||
editVC.insertAndEditRecording(currentRecording!)
|
||||
currentRecording = nil // otherwise it will restart
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user