瀏覽代碼

move delete-account to account-setttings

B. Petersen 5 年之前
父節點
當前提交
f60007bdbe

+ 55 - 0
deltachat-ios/Controller/AccountSetupController.swift

@@ -101,6 +101,14 @@ class AccountSetupController: UITableViewController {
         return cell
     }()
 
+    private lazy var deleteAccountCell: ActionCell = {
+        let cell = ActionCell(frame: .zero)
+        cell.actionTitle = String.localized("delete_account")
+        cell.actionColor = UIColor.red
+        cell.accessibilityIdentifier = "deleteAccountCell"
+        return cell
+    }()
+
     lazy var imapServerCell: TextFieldCell = {
         let cell = TextFieldCell(descriptionID: "login_imap_server",
                                  placeholder: DcConfig.mailServer ?? DcConfig.configuredMailServer,
@@ -201,6 +209,7 @@ class AccountSetupController: UITableViewController {
     let basicSection = 0
     let restoreSection = 1
     let advancedSection = 2
+    let dangerSection = 3
     private var sections = [Int]()
 
     private lazy var basicSectionCells: [UITableViewCell] = [emailCell, passwordCell]
@@ -216,6 +225,7 @@ class AccountSetupController: UITableViewController {
         smtpPasswordCell,
         smtpSecurityCell
     ]
+    private lazy var dangerCells: [UITableViewCell] = [deleteAccountCell]
 
     private var advancedSectionShowing: Bool = false
 
@@ -227,6 +237,10 @@ class AccountSetupController: UITableViewController {
             self.sections.append(restoreSection)
         }
         self.sections.append(advancedSection)
+        if editView {
+            self.sections.append(dangerSection)
+        }
+
         super.init(style: .grouped)
         hidesBottomBarWhenPushed = true
     }
@@ -284,6 +298,8 @@ class AccountSetupController: UITableViewController {
             return basicSectionCells.count
         } else if sections[section] == restoreSection {
             return restoreCells.count
+        } else if sections[section] == dangerSection {
+            return dangerCells.count
         } else {
             return advancedSectionShowing ? advancedSectionCells.count : 0
         }
@@ -292,6 +308,8 @@ class AccountSetupController: UITableViewController {
     override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
         if sections[section] == advancedSection {
             return String.localized("menu_advanced")
+        } else if sections[section] == dangerSection {
+            return String.localized("danger")
         } else {
             return nil
         }
@@ -336,6 +354,8 @@ class AccountSetupController: UITableViewController {
             return basicSectionCells[row]
         } else if sections[section] == restoreSection {
             return restoreCells[row]
+        } else if sections[section] == dangerSection {
+            return dangerCells[row]
         } else {
             return advancedSectionCells[row]
         }
@@ -354,6 +374,8 @@ class AccountSetupController: UITableViewController {
 
         if tappedCell.accessibilityIdentifier == "restoreCell" {
             restoreBackup()
+        } else if tappedCell.accessibilityIdentifier == "deleteAccountCell" {
+            deleteAccount()
         } else if tappedCell.accessibilityIdentifier == "IMAPPortCell" {
             coordinator?.showImapPortOptions()
         } else if tappedCell.accessibilityIdentifier == "SMTPPortCell" {
@@ -580,6 +602,39 @@ class AccountSetupController: UITableViewController {
         logger.error("no documents directory found")
     }
 
+    private func deleteAccount() {
+        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
+            return
+        }
+
+        let dbfile = appDelegate.dbfile()
+        let dburl = URL(fileURLWithPath: dbfile, isDirectory: false)
+        let alert = UIAlertController(title: String.localized("delete_account_message"),
+                                      message: nil,
+                                      preferredStyle: .actionSheet)
+
+        alert.addAction(UIAlertAction(title: String.localized("delete_account"), style: .destructive, handler: { _ in
+            appDelegate.stop()
+            appDelegate.close()
+            do {
+                try FileManager.default.removeItem(at: dburl)
+            } catch {
+                logger.error("failed to delete db: \(error)")
+            }
+
+            appDelegate.open()
+            appDelegate.start()
+
+            self.coordinator?.navigationController.popToRootViewController(animated: true)
+            appDelegate.appCoordinator.presentLoginController()
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
+        present(alert, animated: true, completion: nil)
+
+
+        coordinator?.navigationController.popToRootViewController(animated: true)
+    }
+
     private func handleLoginSuccess() {
         // used when login hud successfully went trough
         dismiss(animated: true, completion: nil)

+ 0 - 41
deltachat-ios/Controller/SettingsController.swift

@@ -184,13 +184,6 @@ internal final class SettingsViewController: QuickTableViewController {
                 ],
                 footer: String.localized("pref_backup_explain")
             ),
-
-            Section(
-                title: String.localized("danger"),
-                rows: [
-                    TapActionRow(text: String.localized("delete_account"), action: { [weak self] in self?.deleteAccount($0) }),
-                ]
-            ),
         ]
     }
 
@@ -256,38 +249,4 @@ internal final class SettingsViewController: QuickTableViewController {
         hudHandler.showHud(String.localized("configuring_account"))
         dc_configure(mailboxPointer)
     }
-
-    private func deleteAccount(_: Row) {
-        logger.info("deleting account")
-        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
-            return
-        }
-
-        let dbfile = appDelegate.dbfile()
-        let dburl = URL(fileURLWithPath: dbfile, isDirectory: false)
-        let alert = UIAlertController(title: String.localized("delete_account_message"),
-                                      message: nil,
-                                      preferredStyle: .actionSheet)
-
-        alert.addAction(UIAlertAction(title: String.localized("delete_account"), style: .destructive, handler: { _ in
-            appDelegate.stop()
-            appDelegate.close()
-            do {
-                try FileManager.default.removeItem(at: dburl)
-            } catch {
-                logger.error("failed to delete db: \(error)")
-            }
-
-            appDelegate.open()
-            appDelegate.start()
-
-            // refresh our view
-            self.setTable()
-            self.tableView.reloadData()
-            self.dismiss(animated: false, completion: nil)
-            self.coordinator?.showLoginController()
-        }))
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
-        present(alert, animated: true, completion: nil)
-    }
 }

+ 0 - 9
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -200,15 +200,6 @@ class SettingsCoordinator: Coordinator {
         navigationController.pushViewController(editController, animated: true)
     }
 
-    func showLoginController() {
-        let accountSetupVC = AccountSetupController(dcContext: dcContext, editView: false)
-        let coordinator = AccountSetupCoordinator(dcContext: dcContext, navigationController: navigationController)
-        childCoordinators.append(coordinator)
-        accountSetupVC.coordinator = coordinator
-        let accountSetupNavigationController = DcNavigationController(rootViewController: accountSetupVC)
-        navigationController.present(accountSetupNavigationController, animated: true, completion: nil)
-    }
-
     func showClassicMail() {
         let settingsClassicViewController = SettingsClassicViewController(dcContext: dcContext)
         navigationController.pushViewController(settingsClassicViewController, animated: true)