Show "no results" in recordings + mark recording as shared
This commit is contained in:
@@ -2,6 +2,7 @@ import UIKit
|
||||
|
||||
class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
var record: Recording!
|
||||
var noResults: Bool = false
|
||||
private lazy var isLongRecording: Bool = record.isLongTerm
|
||||
|
||||
@IBOutlet private var shareButton: UIBarButtonItem!
|
||||
@@ -10,7 +11,8 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
/// Sorted by `ts` in ascending order (oldest first)
|
||||
private lazy var dataSourceRaw: [DomainTsPair] = {
|
||||
let list = RecordingsDB.details(record)
|
||||
shareButton.isEnabled = list.count > 0
|
||||
noResults = list.count == 0
|
||||
shareButton.isEnabled = !noResults
|
||||
return list
|
||||
}()
|
||||
/// Sorted by `count` (descending), then alphabetically
|
||||
@@ -26,6 +28,14 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
|
||||
override func viewDidLoad() {
|
||||
title = record.title ?? record.fallbackTitle
|
||||
NotifyRecordingChanged.observe(call: #selector(recordingDidChange(_:)), on: self)
|
||||
}
|
||||
|
||||
@objc private func recordingDidChange(_ notification: Notification) {
|
||||
let (rec, deleted) = notification.object as! (Recording, Bool)
|
||||
if rec.id == record.id, !deleted {
|
||||
record = rec // almost exclusively when 'shared' is set true
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction private func toggleDisplayStyle(_ sender: UIBarButtonItem) {
|
||||
@@ -34,6 +44,20 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
||||
if identifier == "openContributeSegue" && record.shared {
|
||||
let alert = Alert(title: nil, text: "You have shared this recording already.")
|
||||
if let bid = record.appId, bid.isValidBundleId() {
|
||||
alert.addAction(UIAlertAction.init(title: "Open results", style: .default, handler: { _ in
|
||||
URL(string: "http://127.0.0.1/redirect.html?id=\(bid)")?.open()
|
||||
}))
|
||||
}
|
||||
alert.presentIn(self)
|
||||
return false
|
||||
}
|
||||
return super.shouldPerformSegue(withIdentifier: identifier, sender: sender)
|
||||
}
|
||||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
if let tgt = segue.destination as? VCShareRecording {
|
||||
tgt.record = self.record
|
||||
@@ -44,12 +68,15 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
// MARK: - Table View Data Source
|
||||
|
||||
override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
|
||||
showRaw ? dataSourceRaw.count : dataSourceSum.count
|
||||
max(1, showRaw ? dataSourceRaw.count : dataSourceSum.count)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell: UITableViewCell
|
||||
if showRaw {
|
||||
if noResults {
|
||||
cell = tableView.dequeueReusableCell(withIdentifier: "RecordNoResultsCell")!
|
||||
cell.textLabel?.text = "– empty recording –"
|
||||
} else if showRaw {
|
||||
let x = dataSourceRaw[indexPath.row]
|
||||
if isLongRecording {
|
||||
cell = tableView.dequeueReusableCell(withIdentifier: "RecordDetailLongCell")!
|
||||
@@ -73,11 +100,11 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
// MARK: - Editing
|
||||
|
||||
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
|
||||
getRowActionsIOS9(indexPath, tableView)
|
||||
noResults ? nil : getRowActionsIOS9(indexPath, tableView)
|
||||
}
|
||||
@available(iOS 11.0, *)
|
||||
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||
getRowActionsIOS11(indexPath)
|
||||
noResults ? nil : getRowActionsIOS11(indexPath)
|
||||
}
|
||||
|
||||
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
|
||||
@@ -101,7 +128,8 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
tableView.deleteRows(at: [index], with: .automatic)
|
||||
}
|
||||
}
|
||||
shareButton.isEnabled = dataSourceRaw.count > 0
|
||||
noResults = dataSourceRaw.count == 0
|
||||
shareButton.isEnabled = !noResults
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,14 @@ class VCShareRecording : UIViewController {
|
||||
private var jsonData: Data?
|
||||
|
||||
@IBOutlet private var text : UITextView!
|
||||
@IBOutlet private var sendButton: UIBarButtonItem!
|
||||
@IBOutlet private var sendActivity : UIActivityIndicatorView!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
sendButton.isEnabled = !record.shared
|
||||
|
||||
let start = record.start
|
||||
let comp = Calendar.current.dateComponents([.weekOfYear, .yearForWeekOfYear], from: Date(start))
|
||||
let wkYear = "\(comp.yearForWeekOfYear ?? 0).\(comp.weekOfYear ?? 0)"
|
||||
@@ -68,6 +71,7 @@ class VCShareRecording : UIViewController {
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "POST"
|
||||
request.httpBody = jsonData
|
||||
var rec = record!
|
||||
|
||||
URLSession.shared.dataTask(with: request) { data, response, error in
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
@@ -87,6 +91,12 @@ class VCShareRecording : UIViewController {
|
||||
self?.banner(.fail, "Server couldn't parse request.\nTry again later.")
|
||||
return
|
||||
}
|
||||
// update db, mark record as shared
|
||||
sender.isEnabled = false
|
||||
rec.shared = true // in case view was closed
|
||||
self?.record = rec // in case view is still open
|
||||
RecordingsDB.update(rec) // rec cause self may not be available
|
||||
// notify user about results
|
||||
var autoHide = true
|
||||
if v == 1, let urlStr = json?["url"] as? String {
|
||||
let nextUpdateIn = json?["when"] as? Int
|
||||
@@ -116,12 +126,10 @@ class VCShareRecording : UIViewController {
|
||||
msg += "shortly. "
|
||||
}
|
||||
msg += "Open results webpage now?"
|
||||
let alert = Alert(title: "Thank you", text: msg, buttonText: "Not now")
|
||||
alert.addAction(UIAlertAction(title: "Show results", style: .default) { _ in
|
||||
AskAlert(title: "Thank you", text: msg, buttonText: "Show results", cancelButton: "Not now") { _ in
|
||||
if let url = URL(string: urlStr) {
|
||||
UIApplication.shared.openURL(url)
|
||||
}
|
||||
})
|
||||
alert.presentIn(self)
|
||||
}.presentIn(self)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user