Share results screen

This commit is contained in:
relikd
2020-08-12 18:15:32 +02:00
parent 41aee797a9
commit 908a909c87
4 changed files with 154 additions and 7 deletions

View File

@@ -4,9 +4,15 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
var record: Recording!
private lazy var isLongRecording: Bool = record.isLongTerm
@IBOutlet private var shareButton: UIBarButtonItem!
private var showRaw: Bool = false
/// Sorted by `ts` in ascending order (oldest first)
private lazy var dataSourceRaw: [DomainTsPair] = RecordingsDB.details(record)
private lazy var dataSourceRaw: [DomainTsPair] = {
let list = RecordingsDB.details(record)
shareButton.isEnabled = list.count > 0
return list
}()
/// Sorted by `count` (descending), then alphabetically
private lazy var dataSourceSum: [(domain: String, count: Int)] = {
var result: [String:Int] = [:]
@@ -28,6 +34,12 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
tableView.reloadData()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let tgt = segue.destination as? VCShareRecording {
tgt.record = self.record
}
}
// MARK: - Table View Data Source
@@ -89,6 +101,7 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
tableView.deleteRows(at: [index], with: .automatic)
}
}
shareButton.isEnabled = dataSourceRaw.count > 0
return true
}
}

View File

@@ -0,0 +1,66 @@
import UIKit
class VCShareRecording : UIViewController {
var record: Recording!
private var jsonData: Data?
@IBOutlet private var text : UITextView!
override func viewDidLoad() {
super.viewDidLoad()
let start = record.start
let comp = Calendar.current.dateComponents([.weekOfYear, .yearForWeekOfYear], from: Date(start))
let wkYear = "\(comp.yearForWeekOfYear ?? 0).\(comp.weekOfYear ?? 0)"
let lenSec = record.duration ?? 0
let res = RecordingsDB.details(record)
var cluster: [String : [Timestamp]] = [:]
for (dom, ts) in res {
if cluster[dom] == nil {
cluster[dom] = []
}
cluster[dom]?.append(ts - start)
}
let domList = cluster.reduce("") {
$0 + "\($1.key) : \($1.value.map{"\($0)"}.joined(separator: ", "))\n"
}
text.attributedText = NSMutableAttributedString()
.h2("Review before sending\n")
.normal("\nRead carefully. " +
"You are about to upload the following information to our servers. " +
"The data is anonymized in regards to device identifiers and time of recording. " +
"It is however not anonymous to the domains requested during the recording." +
"\n\n" +
"If necessary, you can cancel this dialog and return to the recording overview. " +
"Use swipe to delete individual domains." +
"\n\n")
.bold("Send to server:\n")
.italic("\nDate: ", .callout).bold(wkYear, .callout)
.italic("\nRec-Length: ", .callout).bold("\(lenSec) sec", .callout)
.italic("\nApp-Bundle: ", .callout).bold(record.appId ?? "", .callout)
.italic("\nApp-Name: ", .callout).bold(record.title ?? "", .callout)
.italic("\n\n[domain name] : [relative time offsets]\n", .callout)
.bold(domList, .callout)
let json: [String : Any] = [
"v" : 1,
"date" : wkYear,
"duration" : lenSec,
"app-bundle" : record.appId ?? "",
"app-name" : record.title ?? "",
"logs" : cluster
]
jsonData = try? JSONSerialization.data(withJSONObject: json)
}
@IBAction private func closeView() {
dismiss(animated: true)
}
@IBAction private func shareRecording() {
print("\(String(data: jsonData!, encoding: .utf8)!)")
Alert(title: "Not implemented yet", text: nil).presentIn(self)
}
}