Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping! #883

Merged
merged 12 commits into from Sep 18, 2020
80 changes: 2 additions & 78 deletions Simplenote/Classes/MigrationsHandler.swift
Expand Up @@ -11,14 +11,9 @@ class MigrationsHandler: NSObject {

/// Stores the last known version.
///
/// - Note: When this property is empty, we'll tamper into the `WordPress-Ratings-iOS` framework's internal UserDefaults key.
/// Why? Because we ... really need to. *Do NOT* attempt this at home.
///
private var lastKnownVersion: String {
get {
return UserDefaults.standard.string(forKey: .lastKnownVersion)
?? UserDefaults.standard.string(forKey: .lastKnownVersionByRatingsFramework)
?? String()
UserDefaults.standard.string(forKey: .lastKnownVersion) ?? String()
}
set {
UserDefaults.standard.set(newValue, forKey: .lastKnownVersion)
Expand Down Expand Up @@ -46,77 +41,6 @@ private extension MigrationsHandler {
/// Handles a migration *from* a given version, *towards* a given version
///
func processMigrations(from: String, to: String) {
switch (from, to) {
case (SimplenoteVersion.mk4_8_0, _):
processMigrationFromMark4_8_0()
default:
break
}
}
}


// MARK: - Migration from 4.8.0
//
private extension MigrationsHandler {

/// Display the Sort Options Reset Alert whenever:
///
/// A. The user comes from 4.8.0
/// B. The user is actually logged
/// C. The "bad Sort Mode" flag is detected
///
func processMigrationFromMark4_8_0() {
let simperium = SPAppDelegate.shared().simperium
guard Options.shared.listSortMode == .alphabeticallyDescending,
simperium.user.authenticated() == true
else {
return
}

presentSortOptionsResetAlert()
}

/// Presents the Sort Options Alert
///
func presentSortOptionsResetAlert() {
let title = String()
let message = NSLocalizedString("Our update may have changed the order in which your notes appear. Would you like to review sort settings?",
comment: "AlertController's Payload for the broken Sort Options Fix")

let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)

let cancelText = NSLocalizedString("No", comment: "Alert's Cancel Action")
controller.addActionWithTitle(cancelText, style: .cancel)

let okText = NSLocalizedString("Yes", comment: "Alert's Accept Action")
controller.addActionWithTitle(okText, style: .default) { _ in
self.presentSortOptionsViewController()
}

controller.presentFromRootViewController()
// NO-OP: Keeping this around for future proof!
}

/// Presents (Modally) the SortOptions Interface
///
func presentSortOptionsViewController() {
let sortingViewController = SPSortOrderViewController()
sortingViewController.displaysDismissButton = true
sortingViewController.selectedMode = Options.shared.listSortMode
sortingViewController.onChange = { newMode in
Options.shared.listSortMode = newMode
}

let navigationController = SPNavigationController(rootViewController: sortingViewController)
navigationController.modalPresentationStyle = .formSheet
navigationController.presentFromRootViewController()
}
}


// MARK: - Known App Versions
//
private enum SimplenoteVersion {
static let mk4_8_0 = "4.8.0"
static let mk4_8_1 = "4.8.1"
}
7 changes: 2 additions & 5 deletions Simplenote/Classes/NSUserActivity+Simplenote.swift
Expand Up @@ -23,10 +23,7 @@ extension NSUserActivity {
self.title = title
isEligibleForSearch = true
isEligibleForHandoff = false

if #available(iOS 12.0, *) {
isEligibleForPrediction = true
self.suggestedInvocationPhrase = suggestedInvocationPhrase ?? title
}
isEligibleForPrediction = true
self.suggestedInvocationPhrase = suggestedInvocationPhrase ?? title
}
}
20 changes: 1 addition & 19 deletions Simplenote/Classes/NotesListFilter.swift
Expand Up @@ -3,7 +3,7 @@ import Foundation

// MARK: - NotesListFilter
//
enum NotesListFilter {
enum NotesListFilter: Equatable {
case everything
case deleted
case untagged
Expand Down Expand Up @@ -52,21 +52,3 @@ extension NotesListFilter {
}
}
}


// MARK: - Equality
//
func ==(lhs: NotesListFilter, rhs: NotesListFilter) -> Bool {
switch (lhs, rhs) {
case (.everything, .everything), (.deleted, .deleted), (.untagged, .untagged):
return true
case let (.tag(lName), .tag(rName)):
return lName == rName
default:
return false
}
}

func !=(lhs: NotesListFilter, rhs: NotesListFilter) -> Bool {
return !(lhs == rhs)
}
20 changes: 1 addition & 19 deletions Simplenote/Classes/NotesListState.swift
Expand Up @@ -3,7 +3,7 @@ import Foundation

// MARK: - NotesListState
//
enum NotesListState {
enum NotesListState: Equatable {
case results
case searching(keyword: String)
}
Expand Down Expand Up @@ -141,21 +141,3 @@ extension NotesListState {
]
}
}


// MARK: - Equality
//
func ==(lhs: NotesListState, rhs: NotesListState) -> Bool {
switch (lhs, rhs) {
case (.results, .results):
return true
case let (.searching(lKeyword), .searching(rKeyword)):
return lKeyword == rKeyword
default:
return false
}
}

func !=(lhs: NotesListState, rhs: NotesListState) -> Bool {
return !(lhs == rhs)
}
8 changes: 4 additions & 4 deletions Simplenote/Classes/SPOptionsViewController.m
Expand Up @@ -480,7 +480,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

- (BOOL)pinLockIsEnabled {
NSString *pin = [[SPAppDelegate sharedDelegate] getPin:NO];
NSString *pin = [[SPAppDelegate sharedDelegate] getPin];

return pin != nil && pin.length > 0;
}
Expand Down Expand Up @@ -596,7 +596,7 @@ - (void)refreshTableViewCellStyle:(UITableViewCell *)cell

- (void)showPinLockViewController
{
NSString *pin = [[SPAppDelegate sharedDelegate] getPin:NO];
NSString *pin = [[SPAppDelegate sharedDelegate] getPin];
PinLockControllerMode mode = pin.length ? PinLockControllerModeRemovePin : PinLockControllerModeSetPin;

DTPinLockController *controller = [[DTPinLockController alloc] initWithMode:mode];
Expand Down Expand Up @@ -641,7 +641,7 @@ - (void)pinLockControllerDidFinishRemovingPin
- (void)pinLockControllerDidCancel
{
// Make sure the UI is consistent
NSString *pin = [[SPAppDelegate sharedDelegate] getPin:false];
NSString *pin = [[SPAppDelegate sharedDelegate] getPin];
if (pin.length == 0) {
[[SPAppDelegate sharedDelegate] setAllowBiometryInsteadOfPin:NO];
}
Expand Down Expand Up @@ -728,7 +728,7 @@ - (void)touchIdSwitchDidChangeValue:(UISwitch *)sender
{
[[SPAppDelegate sharedDelegate] setAllowBiometryInsteadOfPin:sender.on];

NSString *pin = [[SPAppDelegate sharedDelegate] getPin:NO];
NSString *pin = [[SPAppDelegate sharedDelegate] getPin];
if (pin.length == 0) {
[self showPinLockViewController];
}
Expand Down
10 changes: 4 additions & 6 deletions Simplenote/Classes/SPSimpleTextPrintFormatter.swift
Expand Up @@ -4,12 +4,10 @@ class SPSimpleTextPrintFormatter: UISimpleTextPrintFormatter {
override init(text: String) {
super.init(text: text)

//Check for darkmode
//If dark mode is enabled change the text color to black before printing
if #available(iOS 12.0, *) {
if SPUserInterface.isDark {
self.color = UIColor.black
}
// Check for darkmode
// If dark mode is enabled change the text color to black before printing
if SPUserInterface.isDark {
self.color = .black
}
}
}
6 changes: 2 additions & 4 deletions Simplenote/Classes/ShortcutsHandler.swift
Expand Up @@ -40,10 +40,8 @@ class ShortcutsHandler: NSObject {
///
@objc
func unregisterSimplenoteActivities() {
if #available(iOS 12.0, *) {
NSUserActivity.deleteAllSavedUserActivities {
// No-Op: The SDK's API... doesn't take a nil callback. Neat!
}
NSUserActivity.deleteAllSavedUserActivities {
// No-Op: The SDK's API... doesn't take a nil callback. Neat!
}
}

Expand Down
2 changes: 1 addition & 1 deletion Simplenote/Classes/UserDefaults+Simplenote.swift
Expand Up @@ -6,8 +6,8 @@ import Foundation
extension UserDefaults {
enum Key: String {
case condensedNotes = "SPCondensedNoteListPref"
case firstLaunch = "SPFirstLaunch"
case lastKnownVersion
case lastKnownVersionByRatingsFramework = "WPRatingsCurrentVersion"
case listSortMode
case listSortModeLegacy = "SPAlphabeticalSortPref"
case searchSortMode
Expand Down
12 changes: 12 additions & 0 deletions Simplenote/Options.swift
Expand Up @@ -46,6 +46,18 @@ extension Options {
}
}

/// Indicates if it's the First Launch event was already handled
///
@objc
var firstLaunch: Bool {
get {
defaults.bool(forKey: .firstLaunch)
}
set {
defaults.set(newValue, forKey: .firstLaunch)
}
}

/// Returns the target Sort Mode for the Notes List
///
@objc
Expand Down
2 changes: 1 addition & 1 deletion Simplenote/SPAppDelegate.h
Expand Up @@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)save;
- (void)logoutAndReset:(id)sender;

- (NSString *)getPin:(BOOL)checkLegacy;
- (nullable NSString *)getPin;
- (void)setPin:(NSString *)newPin;
- (void)removePin;

Expand Down