Sort order

This commit is contained in:
relikd
2020-06-08 23:38:09 +02:00
parent e13b3df2c4
commit 946acc2460
7 changed files with 197 additions and 59 deletions

View File

@@ -26,3 +26,16 @@ extension UIEdgeInsets {
self.init(top: top ?? all, left: left ?? all, bottom: bottom ?? all, right: right ?? all)
}
}
infix operator =? : ComparisonPrecedence
extension Equatable {
/// Assign a new value to `lhs` if the `newValue` differs from the previous value. Return whether the new value was set.
/// - Returns: `true` if `lhs` was overwritten with another value
static func =?(lhs: inout Self, newValue: Self) -> Bool {
if lhs != newValue {
lhs = newValue
return true
}
return false
}
}

View File

@@ -3,6 +3,7 @@ import Foundation
let NotifyVPNStateChanged = NSNotification.Name("GlassVPNStateChanged") // VPNState!
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!

View File

@@ -8,24 +8,40 @@ public enum VPNState : Int {
}
struct 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) }
struct DidShowTutorial {
static var Welcome: Bool {
get { UserDefaults.standard.bool(forKey: "didShowTutorialAppWelcome") }
set { UserDefaults.standard.set(newValue, forKey: "didShowTutorialAppWelcome") }
get { Pref.Bool("didShowTutorialAppWelcome") }
set { Pref.Bool(newValue, "didShowTutorialAppWelcome") }
}
static var Recordings: Bool {
get { UserDefaults.standard.bool(forKey: "didShowTutorialRecordings") }
set { UserDefaults.standard.set(newValue, forKey: "didShowTutorialRecordings") }
get { Pref.Bool("didShowTutorialRecordings") }
set { Pref.Bool(newValue, "didShowTutorialRecordings") }
}
}
struct DateFilter {
static var Kind: DateFilterKind {
get { DateFilterKind(rawValue: UserDefaults.standard.integer(forKey: "dateFilterType"))! }
set { UserDefaults.standard.set(newValue.rawValue, forKey: "dateFilterType") }
get { DateFilterKind(rawValue: Pref.Int("dateFilterType"))! }
set { Pref.Int(newValue.rawValue, "dateFilterType") }
}
/// Default: `0` (disabled)
static var LastXMin: Int {
get { UserDefaults.standard.integer(forKey: "dateFilterLastXMin") }
set { UserDefaults.standard.set(newValue, forKey: "dateFilterLastXMin") }
get { Pref.Int("dateFilterLastXMin") }
set { Pref.Int(newValue, "dateFilterLastXMin") }
}
/// default: `.Date`
static var OrderBy: DateFilterOrderBy {
get { DateFilterOrderBy(rawValue: Pref.Int("dateFilterOderType"))! }
set { Pref.Int(newValue.rawValue, "dateFilterOderType") }
}
/// default: `false` (Desc)
static var OrderAsc: Bool {
get { Pref.Bool("dateFilterOderAsc") }
set { Pref.Bool(newValue, "dateFilterOderAsc") }
}
/// Return selected timestamp filter or `nil` if filtering is disabled.
@@ -39,3 +55,6 @@ struct Pref {
enum DateFilterKind: Int {
case Off = 0, LastXMin = 1, ABRange = 2;
}
enum DateFilterOrderBy: Int {
case Date = 0, Name = 1, Count = 2;
}