Skip to content

Commit

Permalink
Added ability to import old notes from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
leathalman committed May 24, 2022
1 parent dbcdd63 commit eab19a2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
Binary file not shown.
7 changes: 0 additions & 7 deletions Jotify/Controller/NoteCollectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ class NoteCollectionController: UICollectionViewController {
enableAutomaticStatusBarStyle()
resetAppBadgeIfAllRemindersCleared()
setupSearchBar()

//when opening from notecollection, there is no data present
//TEMP fix for making loading less horrible
// if noteCollection == nil {
// noteCollection = NoteCollection()
// noteCollection?.FBNotes = [FBNote(content: "Loading...", timestamp: 0, id: "", color: "caeruleum1", reminder: "", reminderTimestamp: 0)]
// }
}

override func viewDidLoad() {
Expand Down
4 changes: 2 additions & 2 deletions Jotify/Controller/PageBoyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class PageBoyController: PageboyViewController, PageboyViewControllerDataSource
print("Has migrated: \(User.settings?.hasMigrated ?? false)")
if !(settings!.hasMigrated) && !UserDefaults.standard.bool(forKey: "hasMigrated") {
//ask user if they want to migrate notes
let alertController = UIAlertController(title: "Migrate Notes", message: "Jotify found notes from a previous version. Would you like to migrate your notes, so you can continue to access them?", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "No", style: .destructive, handler: {(action) in
let alertController = UIAlertController(title: "Have you used Jotify before?", message: "If you have, Jotify can automatically import your notes from previous verions. Do you want to import your old notes?", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "No", style: .default, handler: {(action) in
//set these values, so this prompt does not appear on every launch
UserDefaults.standard.setValue(true, forKey: "hasMigrated")
DataManager.updateUserSettings(setting: "hasMigrated", value: true) { (success) in }
Expand Down
21 changes: 16 additions & 5 deletions Jotify/Controller/Settings/AccountSettingsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AccountSettingsController: SettingsController {
super.viewDidLoad()
super.sections = [AuthManager().email, "Data"]
super.section1 = ["Reset Password", "Change Email", "Logout"]
super.section2 = ["Reset Settings", "Delete All Notes", "Delete Jotify Account"]
super.section2 = ["Migrate Data from Old Versions", "Reset Settings", "Delete All Notes", "Delete Jotify Account"]
navigationItem.title = "Account"
}

Expand Down Expand Up @@ -87,6 +87,15 @@ class AccountSettingsController: SettingsController {
case 1:
switch indexPath.row {
case 0:
let alertController = UIAlertController(title: "Migrate Notes", message: "If you have notes from a previous version of Jotify, you can import them here! Would you like to begin the transfer process? You can continue to use Jotify, and you will be prompted to restore your notes the next time you launch the app.", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "No", style: .default, handler: nil))
alertController.addAction(UIAlertAction(title: "Yes", style: .default, handler: {(action) in
DataManager.updateUserSettings(setting: "hasMigrated", value: false) { success in
//
}
}))
self.present(alertController, animated: true, completion: nil)
case 1:
let alertController = UIAlertController(title: "Reset User Settings", message: "Are you sure? This will reset settings to default.", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
alertController.addAction(UIAlertAction(title: "Reset", style: .destructive, handler: {(action) in
Expand All @@ -111,7 +120,7 @@ class AccountSettingsController: SettingsController {
}
}))
self.present(alertController, animated: true, completion: nil)
case 1:
case 2:
let alertController = UIAlertController(title: "Delete All Notes", message: "Do you really want to delete ALL of your notes? This action CANNOT be undone.", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
alertController.addAction(UIAlertAction(title: "Yes", style: .destructive, handler: {(action) in
Expand All @@ -133,7 +142,7 @@ class AccountSettingsController: SettingsController {
self.present(alertController, animated: true, completion: nil)
}))
self.present(alertController, animated: true, completion: nil)
case 2:
case 3:
let alertController = UIAlertController(title: "Delete Jotify Account", message: "Do you really want to delete your Jotify account? This action cannot be undone under any circumstance.", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
alertController.addAction(UIAlertAction(title: "Yes", style: .destructive, handler: {(action) in
Expand Down Expand Up @@ -187,6 +196,9 @@ class AccountSettingsController: SettingsController {
case 1:
cell.textLabel?.text = "\(super.section2[indexPath.row])"
cell.textLabel?.textColor = .systemRed
if indexPath.row == 0 {
cell.textLabel?.textColor = .systemBlue
}
default:
return cell
}
Expand All @@ -213,12 +225,11 @@ class AccountSettingsController: SettingsController {
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
switch section {
case 0:
return "Changing account credentials maybe require you to logout and sign back into Jotify for security purposes."
return "Changing account credentials may require you to logout and sign back into Jotify for security purposes."
case 1:
return "Delete all data from Jotify's servers. Your notes are permanently deleted, so they cannot be recovered under any circumstance."
default:
return ""
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CustomizationSettingsController: SettingsController {
super.viewDidLoad()
super.sections = ["Privacy", "Visual", "Miscellaneous"]
super.section1 = ["Enable Biometric Unlock"]
super.section2 = ["Custom Placeholder", "App Icon"]
super.section2 = ["Custom Placeholder"]
super.section3 = ["Default View", "Use Haptics", "Delete Expired Notes"]
navigationItem.title = "Customization"
}
Expand Down
4 changes: 3 additions & 1 deletion Jotify/Model/Firebase/DataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class DataManager {
if (diff.type == .added) {
// print("New note: \(diff.document.data())")
collection.FBNotes.insert(note, at: 0)

}

if (diff.type == .modified) {
// print("Modified note: \(diff.document.data())")
if let noteIndex = collection.FBNotes.firstIndex(where: { $0.id == id}) {
Expand All @@ -206,10 +206,12 @@ class DataManager {
}
collection.FBNotes.sort { ($0.timestamp) > ($1.timestamp) }
}

if (diff.type == .removed) {
// print("Removed note: \(diff.document.data())")
collection.FBNotes = collection.FBNotes.filter {$0.id != diff.document.documentID }
}

completionHandler(collection, true)
}
}
Expand Down

0 comments on commit eab19a2

Please sign in to comment.