Edit delete recordings
This commit is contained in:
@@ -230,6 +230,7 @@ class DBWrapper {
|
|||||||
|
|
||||||
func recordingStop(_ r: inout Recording) { AppDB?.stopRecording(&r) }
|
func recordingStop(_ r: inout Recording) { AppDB?.stopRecording(&r) }
|
||||||
func recordingPersist(_ r: Recording) { AppDB?.persistRecordingLogs(r) }
|
func recordingPersist(_ r: Recording) { AppDB?.persistRecordingLogs(r) }
|
||||||
|
func recordingDetails(_ r: Recording) -> [RecordLog] { AppDB?.getRecordingsLogs(r) ?? [] }
|
||||||
|
|
||||||
func recordingUpdate(_ r: Recording) {
|
func recordingUpdate(_ r: Recording) {
|
||||||
AppDB?.updateRecording(r)
|
AppDB?.updateRecording(r)
|
||||||
@@ -242,8 +243,8 @@ class DBWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordingDetails(_ r: Recording) -> [(domain: String?, count: Int32)]? {
|
func recordingDeleteDetails(_ r: Recording, domain: String?) -> Bool {
|
||||||
AppDB?.getRecordingsLogs(r)
|
((try? AppDB?.deleteRecordingLogs(r.id, matchingDomain: domain)) ?? 0) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -441,9 +441,9 @@ extension SQLiteDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func deleteRecordingLogs(_ recId: sqlite3_int64) throws -> Int32 {
|
func deleteRecordingLogs(_ recId: sqlite3_int64, matchingDomain d: String? = nil) throws -> Int32 {
|
||||||
try run(sql: "DELETE FROM recLog WHERE rid = ?;", bind: {
|
try run(sql: "DELETE FROM recLog WHERE rid = ? \(d==nil ? "" : "AND domain = ?");", bind: {
|
||||||
self.bindInt64($0, 1, recId)
|
self.bindInt64($0, 1, recId) && (d==nil ? true : self.bindTextOrNil($0, 2,d))
|
||||||
}) {
|
}) {
|
||||||
try ifStep($0, SQLITE_DONE)
|
try ifStep($0, SQLITE_DONE)
|
||||||
return sqlite3_changes(dbPointer)
|
return sqlite3_changes(dbPointer)
|
||||||
@@ -452,7 +452,7 @@ extension SQLiteDatabase {
|
|||||||
|
|
||||||
// MARK: read
|
// MARK: read
|
||||||
|
|
||||||
func getRecordingsLogs(_ r: Recording) -> [(domain: String?, count: Int32)]? {
|
func getRecordingsLogs(_ r: Recording) -> [RecordLog]? {
|
||||||
try? run(sql: "SELECT domain, COUNT() FROM recLog WHERE rid = ? GROUP BY domain;", bind: {
|
try? run(sql: "SELECT domain, COUNT() FROM recLog WHERE rid = ? GROUP BY domain;", bind: {
|
||||||
self.bindInt64($0, 1, r.id)
|
self.bindInt64($0, 1, r.id)
|
||||||
}) {
|
}) {
|
||||||
@@ -460,3 +460,5 @@ extension SQLiteDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typealias RecordLog = (domain: String?, count: Int32)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class TVCPreviousRecords: UITableViewController {
|
class TVCPreviousRecords: UITableViewController, EditActionsRemove {
|
||||||
private var dataSource: [Recording] = []
|
private var dataSource: [Recording] = []
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
@@ -72,4 +72,12 @@ class TVCPreviousRecords: UITableViewController {
|
|||||||
cell.detailTextLabel?.text = "at \(x.start.asDateTime()), duration: \(x.durationString ?? "?")"
|
cell.detailTextLabel?.text = "at \(x.start.asDateTime()), duration: \(x.durationString ?? "?")"
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - Editing
|
||||||
|
|
||||||
|
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
|
||||||
|
DBWrp.recordingDelete(self.dataSource[index.row])
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class TVCRecordingDetails: UITableViewController {
|
class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||||
var record: Recording!
|
var record: Recording!
|
||||||
private var dataSource: [(domain: String?, count: Int32)]!
|
private var dataSource: [RecordLog]!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
title = record.title ?? record.fallbackTitle
|
title = record.title ?? record.fallbackTitle
|
||||||
dataSource = DBWrp.recordingDetails(record) ?? []
|
dataSource = DBWrp.recordingDetails(record)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -23,4 +23,15 @@ class TVCRecordingDetails: UITableViewController {
|
|||||||
cell.detailTextLabel?.text = "\(x.count)"
|
cell.detailTextLabel?.text = "\(x.count)"
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - Editing
|
||||||
|
|
||||||
|
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
|
||||||
|
if DBWrp.recordingDeleteDetails(record, domain: self.dataSource[index.row].domain) {
|
||||||
|
self.dataSource.remove(at: index.row)
|
||||||
|
self.tableView.deleteRows(at: [index], with: .automatic)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,3 +123,23 @@ extension TVCFilter : EditableRows {
|
|||||||
getRowActionsIOS11(indexPath)
|
getRowActionsIOS11(indexPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension TVCPreviousRecords : EditableRows {
|
||||||
|
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
|
||||||
|
getRowActionsIOS9(indexPath)
|
||||||
|
}
|
||||||
|
@available(iOS 11.0, *)
|
||||||
|
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
|
getRowActionsIOS11(indexPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension TVCRecordingDetails : EditableRows {
|
||||||
|
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
|
||||||
|
getRowActionsIOS9(indexPath)
|
||||||
|
}
|
||||||
|
@available(iOS 11.0, *)
|
||||||
|
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
|
getRowActionsIOS11(indexPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user