Refactoring II.

- Filter by date range
- SyncUpdate tasks run fully asynchronous in background
- Move tableView manipulations into FilterPipelineDelegate
- Move SyncUpdate notification into SyncUpdateDelegate
- Fix: sync cache before persisting a recording
- Restructuring GroupedDomainDataSource
- Performance: db logs queries use rowids instead of timestamps
- Add 'now' button to DatePickerAlert
This commit is contained in:
relikd
2020-06-17 00:27:22 +02:00
parent 0a53898797
commit e947ad6d4d
20 changed files with 644 additions and 386 deletions

View File

@@ -27,15 +27,34 @@ extension UIEdgeInsets {
}
}
infix operator =? : ComparisonPrecedence
precedencegroup CompareAssignPrecedence {
assignment: true
associativity: left
higherThan: ComparisonPrecedence
}
infix operator <-? : CompareAssignPrecedence
infix operator <-/ : CompareAssignPrecedence
extension Equatable {
/// Assign a new value to `lhs` if the `newValue` differs from the previous value. Return whether the new value was set.
/// Assign a new value to `lhs` if `newValue` differs from the previous value. Return `false` if they are equal.
/// - Returns: `true` if `lhs` was overwritten with another value
static func =?(lhs: inout Self, newValue: Self) -> Bool {
static func <-?(lhs: inout Self, newValue: Self) -> Bool {
if lhs != newValue {
lhs = newValue
return true
}
return false
}
/// Assign a new value to `lhs` if `newValue` differs from the previous value.
/// Return tuple with both values. Or `nil` if they are equal.
/// - Returns: `nil` if `previousValue == newValue`
static func <-/(lhs: inout Self, newValue: Self) -> (previousValue: Self, newValue: Self)? {
let previousValue = lhs
if previousValue != newValue {
lhs = newValue
return (previousValue, newValue)
}
return nil
}
}

View File

@@ -1,12 +1,9 @@
import Foundation
let NotifyVPNStateChanged = NSNotification.Name("GlassVPNStateChanged") // VPNState!
let NotifyDNSFilterChanged = NSNotification.Name("PSIDNSFilterSettingsChanged") // domain: String?
let NotifyDNSFilterChanged = NSNotification.Name("PSIDNSFilterSettingsChanged") // domain: String!
let NotifyDateFilterChanged = NSNotification.Name("PSIDateFilterSettingsChanged") // nil!
let NotifySortOrderChanged = NSNotification.Name("PSIDateFilterSortOrderChanged") // nil!
let NotifyLogHistoryReset = NSNotification.Name("PSILogHistoryReset") // domain: String?
let NotifySyncInsert = NSNotification.Name("PSISyncInsert") // SQLiteRowRange!
let NotifySyncRemove = NSNotification.Name("PSISyncRemove") // SQLiteRowRange!
let NotifyRecordingChanged = NSNotification.Name("PSIRecordingChanged") // (Recording, deleted: Bool)!

View File

@@ -7,13 +7,15 @@ public enum VPNState : Int {
case on = 1, inbetween, off
}
struct Pref {
enum Pref {
static func Int(_ key: String) -> Int { UserDefaults.standard.integer(forKey: key) }
static func Int(_ val: Int, _ key: String) { UserDefaults.standard.set(val, forKey: key) }
static func Bool(_ key: String) -> Bool { UserDefaults.standard.bool(forKey: key) }
static func Bool(_ val: Bool, _ key: String) { UserDefaults.standard.set(val, forKey: key) }
static func `Any`(_ key: String) -> Any? { UserDefaults.standard.object(forKey: key) }
static func `Any`(_ val: Any?, _ key: String) { UserDefaults.standard.set(val, forKey: key) }
struct DidShowTutorial {
enum DidShowTutorial {
static var Welcome: Bool {
get { Pref.Bool("didShowTutorialAppWelcome") }
set { Pref.Bool(newValue, "didShowTutorialAppWelcome") }
@@ -23,7 +25,7 @@ struct Pref {
set { Pref.Bool(newValue, "didShowTutorialRecordings") }
}
}
struct DateFilter {
enum DateFilter {
static var Kind: DateFilterKind {
get { DateFilterKind(rawValue: Pref.Int("dateFilterType"))! }
set { Pref.Int(newValue.rawValue, "dateFilterType") }
@@ -33,6 +35,16 @@ struct Pref {
get { Pref.Int("dateFilterLastXMin") }
set { Pref.Int(newValue, "dateFilterLastXMin") }
}
/// Default: `nil` (disabled)
static var RangeA: Timestamp? {
get { Pref.Any("dateFilterRangeA") as? Timestamp }
set { Pref.Any(newValue, "dateFilterRangeA") }
}
/// Default: `nil` (disabled)
static var RangeB: Timestamp? {
get { Pref.Any("dateFilterRangeB") as? Timestamp }
set { Pref.Any(newValue, "dateFilterRangeB") }
}
/// default: `.Date`
static var OrderBy: DateFilterOrderBy {
get { DateFilterOrderBy(rawValue: Pref.Int("dateFilterOderType"))! }
@@ -44,11 +56,17 @@ struct Pref {
set { Pref.Bool(newValue, "dateFilterOderAsc") }
}
/// Return selected timestamp filter or `nil` if filtering is disabled.
/// - Returns: `Timestamp.now() - LastXMin * 60`
static func lastXMinTimestamp() -> Timestamp? {
if Kind != .LastXMin { return nil }
return Timestamp.past(minutes: Pref.DateFilter.LastXMin)
/// - Returns: Timestamp restriction depending on current selected date filter.
/// - `Off` : `(0, -1)`
/// - `LastXMin` : `(now-LastXMin, -1)`
/// - `ABRange` : `(RangeA, RangeB)`
static func restrictions() -> (type: DateFilterKind, earliest: Timestamp, latest: Timestamp) {
let type = Kind
switch type {
case .Off: return (type, 0, -1)
case .LastXMin: return (type, Timestamp.past(minutes: Pref.DateFilter.LastXMin), -1)
case .ABRange: return (type, Pref.DateFilter.RangeA ?? 0, Pref.DateFilter.RangeB ?? -1)
}
}
}
}

View File

@@ -36,7 +36,7 @@ extension String {
}
}
var listOfSLDs: [String : [String : Bool]] = {
private var listOfSLDs: [String : [String : Bool]] = {
let path = Bundle.main.url(forResource: "third-level", withExtension: "txt")
let content = try! String(contentsOf: path!)
var res: [String : [String : Bool]] = [:]