Explorar el Código

Merge pull request #178 from deltachat/tweak-import

tweak import
björn petersen hace 6 años
padre
commit
8fc7185a78

+ 61 - 68
deltachat-ios/Controller/AccountSetupController.swift

@@ -7,12 +7,14 @@ class AccountSetupController: UITableViewController {
     weak var coordinator: AccountSetupCoordinator?
 
     private var skipOauth = false
-
     private var backupProgressObserver: Any?
     private var configureProgressObserver: Any?
     private var oauth2Observer: Any?
 
-    lazy var configProgressIndicator: UICircularProgressRing = {
+
+    // the progress dialog
+
+    private lazy var configProgressIndicator: UICircularProgressRing = {
         let progress = UICircularProgressRing()
         progress.style = UICircularRingStyle.inside
         progress.outerRingColor = UIColor.clear
@@ -25,9 +27,9 @@ class AccountSetupController: UITableViewController {
         return progress
     }()
 
-    lazy var configProgressAlert: UIAlertController = {
-        let alert = UIAlertController(title: String.localized("configuring_account"), message: "\n\n\n", preferredStyle: .alert)
-        // temp workaround: add 3 newlines to let alertbox grow to fit progressview
+    private lazy var configProgressAlert: UIAlertController = {
+        let alert = UIAlertController(title: String.localized("one_moment"), message: "\n\n\n", preferredStyle: .alert)
+        // workaround: add 3 newlines to let alertbox grow to fit progressview
         let progressView = configProgressIndicator
         progressView.translatesAutoresizingMaskIntoConstraints = false
         alert.view.addSubview(progressView)
@@ -39,6 +41,48 @@ class AccountSetupController: UITableViewController {
         return alert
     }()
 
+    private func showProgressHud() {
+        configProgressAlert.actions[0].isEnabled = true
+        configProgressAlert.title = String.localized("one_moment")
+        configProgressAlert.message = "\n\n\n" // workaround to create space for progress indicator
+        configProgressIndicator.alpha = 1
+        configProgressIndicator.value = 0
+        present(configProgressAlert, animated: true, completion: nil)
+    }
+
+    private func updateProgressHud(error message: String?) {
+        configProgressAlert.title = String.localized("login_error_title")
+        configProgressAlert.message = message
+        configProgressIndicator.alpha = 0
+    }
+
+    private func updateProgressHudSuccess() {
+        updateProgressHudValue(value: 1000)
+        DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
+            self.configProgressAlert.dismiss(animated: true) {
+                self.handleLoginSuccess()
+            }
+        })
+    }
+
+    private func updateProgressHudValue(value: Int?) {
+        if let value = value {
+            print("progress hud: \(value)")
+            configProgressIndicator.value = CGFloat(value / 10)
+        }
+    }
+
+    private func loginCancelled(_ action: UIAlertAction) {
+        DcConfig.addr = nil
+        DcConfig.mailPw = nil
+        DispatchQueue.global(qos: .background).async {
+            dc_stop_ongoing_process(mailboxPointer)        // this function freezes UI so execute in background thread
+        }
+    }
+
+
+    // account setup
+
     private lazy var emailCell: TextFieldCell = {
         let cell = TextFieldCell.makeEmailCell(delegate: self)
         cell.textField.tag = 0
@@ -204,7 +248,6 @@ class AccountSetupController: UITableViewController {
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         addProgressHudEventListener()
-        // loginButton.isEnabled = false
     }
 
     override func viewWillDisappear(_ animated: Bool) {
@@ -295,7 +338,6 @@ class AccountSetupController: UITableViewController {
         }
     }
 
-    // FIXME: replace if-else-if with switch-case
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         guard let tappedCell = tableView.cellForRow(at: indexPath) else { return }
         // handle tap on password -> show oAuthDialogue
@@ -441,7 +483,7 @@ class AccountSetupController: UITableViewController {
     private func addProgressHudEventListener() {
         let nc = NotificationCenter.default
         backupProgressObserver = nc.addObserver(
-            forName: dcNotificationBackupProgress,
+            forName: dcNotificationImexProgress,
             object: nil,
             queue: nil
         ) {
@@ -450,7 +492,7 @@ class AccountSetupController: UITableViewController {
                 if ui["error"] as! Bool {
                     self.updateProgressHud(error: ui["errorMessage"] as? String)
                 } else if ui["done"] as! Bool {
-                    self.updateProgressHudSuccess(callback: self.handleLoginSuccess)
+                    self.updateProgressHudSuccess()
                 } else {
                     self.updateProgressHudValue(value: ui["progress"] as? Int)
                 }
@@ -466,7 +508,7 @@ class AccountSetupController: UITableViewController {
                 if ui["error"] as! Bool {
                     self.updateProgressHud(error: ui["errorMessage"] as? String)
                 } else if ui["done"] as! Bool {
-                    self.updateProgressHudSuccess(callback: self.handleLoginSuccess)
+                    self.updateProgressHudSuccess()
                 } else {
                     self.updateProgressHudValue(value: ui["progress"] as? Int)
                 }
@@ -516,19 +558,17 @@ class AccountSetupController: UITableViewController {
 
             if let file = dc_imex_has_backup(mailboxPointer, documents[0]) {
                 logger.info("restoring backup: \(String(cString: file))")
-
-                // hudHandler.showBackupHud("Restoring Backup")
+                showProgressHud()
                 dc_imex(mailboxPointer, DC_IMEX_IMPORT_BACKUP, file, nil)
-
-                return
             }
-
-            let alert = UIAlertController(title: String.localized("import_backup_title"), message: String.localizedStringWithFormat(String.localized("import_backup_no_backup_found"), "DUMMYPATH TBD"), preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .cancel, handler: { _ in
-
-            }))
-            present(alert, animated: true, completion: nil)
-            return
+            else {
+                let alert = UIAlertController(title: String.localized("import_backup_title"),
+                    message: String.localizedStringWithFormat(String.localized("import_backup_no_backup_found"),
+                        "iTunes / <Your Device> / File Sharing / Delta Chat"), // TOOD: maybe better use an iOS-specific string here
+                    preferredStyle: .alert)
+                alert.addAction(UIAlertAction(title: String.localized("ok"), style: .cancel))
+                present(alert, animated: true)
+            }
         }
 
         logger.error("no documents directory found")
@@ -641,50 +681,3 @@ class AdvancedSectionHeader: UIView {
         handleTap?(toggleButton)
     }
 }
-
-extension AccountSetupController {
-
-    func showProgressHud() {
-        configProgressAlert.actions[0].isEnabled = true
-        configProgressAlert.title = String.localized("configuring_account")
-        configProgressAlert.message = "\n\n\n"	// workaround to create space for progress indicator
-        configProgressIndicator.alpha = 1
-        configProgressIndicator.value = 0
-        present(configProgressAlert, animated: true, completion: nil)
-
-    }
-
-    func updateProgressHud(error message: String?) {
-        configProgressAlert.title = String.localized("login_error_title")
-        configProgressAlert.message = message
-        configProgressIndicator.alpha = 0
-    }
-
-    func updateProgressHudSuccess(callback: (()->())?) {
-        configProgressAlert.actions[0].isEnabled = false
-        configProgressIndicator.alpha = 0
-        configProgressAlert.title = String.localized("login_successful_title")
-        configProgressAlert.message = String.localized("login_successful_message")
-        loginButton.isEnabled = dc_is_configured(mailboxPointer) == 0
-        DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
-            self.configProgressAlert.dismiss(animated: true) {
-                self.handleLoginSuccess()
-            }
-        })
-    }
-
-    private func updateProgressHudValue(value: Int?) {
-        if let value = value {
-            print("progress hud: \(value)")
-            configProgressIndicator.value = CGFloat(value / 10)
-        }
-    }
-
-    func loginCancelled(_ action: UIAlertAction) {
-        DcConfig.addr = nil
-        DcConfig.mailPw = nil
-        DispatchQueue.global(qos: .background).async {
-            dc_stop_ongoing_process(mailboxPointer)		// this function freezes UI so execute in background thread
-        }
-    }
-}

+ 1 - 1
deltachat-ios/Controller/SettingsController.swift

@@ -34,7 +34,7 @@ internal final class SettingsViewController: QuickTableViewController {
         super.viewDidAppear(animated)
         let nc = NotificationCenter.default
         backupProgressObserver = nc.addObserver(
-            forName: dcNotificationBackupProgress,
+            forName: dcNotificationImexProgress,
             object: nil,
             queue: nil
         ) { notification in

+ 16 - 19
deltachat-ios/DC/events.swift

@@ -4,7 +4,7 @@ import UserNotifications
 let dcNotificationChanged = Notification.Name(rawValue: "MrEventMsgsChanged")
 let dcNotificationStateChanged = Notification.Name(rawValue: "MrEventStateChanged")
 let dcNotificationIncoming = Notification.Name(rawValue: "MrEventIncomingMsg")
-let dcNotificationBackupProgress = Notification.Name(rawValue: "MrEventBackupProgress")
+let dcNotificationImexProgress = Notification.Name(rawValue: "dcNotificationImexProgress")
 let dcNotificationConfigureProgress = Notification.Name(rawValue: "MrEventConfigureProgress")
 let dcNotificationSecureJoinerProgress = Notification.Name(rawValue: "MrEventSecureJoinerProgress")
 let dcNotificationSecureInviterProgress = Notification.Name(rawValue: "MrEventSecureInviterProgress")
@@ -52,6 +52,21 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
             }
         }
 
+    case DC_EVENT_IMEX_PROGRESS:
+        let nc = NotificationCenter.default
+        DispatchQueue.main.async {
+            nc.post(
+                name: dcNotificationImexProgress,
+                object: nil,
+                userInfo: [
+                    "progress": Int(data1),
+                    "error": Int(data1) == 0,
+                    "done": Int(data1) == 1000,
+                    "errorMessage": AppDelegate.lastErrorDuringConfig as Any,
+                ]
+            )
+        }
+
     case DC_EVENT_ERROR_NETWORK:
         let msg = String(cString: data2String)
         if data1 == 1 {
@@ -130,24 +145,6 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
     case DC_EVENT_MSG_DELIVERED:
         logger.info("message delivered: \(data1)-\(data2)")
 
-    case DC_EVENT_IMEX_PROGRESS:
-        let nc = NotificationCenter.default
-        DispatchQueue.main.async {
-            nc.post(
-                name: dcNotificationBackupProgress,
-                object: nil,
-                userInfo: [
-                    "progress": Int(data1),
-                    "error": Int(data1) == 0,
-                    "done": Int(data1) == 1000,
-                    "errorMessage": AppDelegate.lastErrorDuringConfig as Any,
-                ]
-            )
-        }
-
-    case DC_EVENT_IMEX_FILE_WRITTEN:
-        logger.info("backup file written: \(String(cString: data1String))")
-
     case DC_EVENT_SECUREJOIN_INVITER_PROGRESS:
         logger.info("securejoin inviter progress \(data1)")
 

+ 0 - 4
deltachat-ios/Helper/Constants.swift

@@ -1,10 +1,6 @@
 import UIKit
 
 struct Constants {
-    // see: https://core.telegram.org/blackberry/chat
-    static let chatColors: [UIColor] = [
-        "#ee4928", "#41a903", "#e09602", "#0f94ed",
-        "#8f3bf7", "#fc4380", "#00a1c4", "#eb7002"].map { s in UIColor(hexString: s) }
     struct Color {
         static let bubble = UIColor(netHex: 0xEFFFDE)
     }

+ 0 - 3
deltachat-ios/en.lproj/Localizable.strings

@@ -632,11 +632,8 @@
 "imap_password" = "your IMAP password";
 "success" = "Success";
 "videos" = "Videos";
-"configuring_account" = "Configuring Account";
 "hide" = "Hide";
 "login_error_title" = "Unable to login!";
-"login_successful_title" = "Login successful!";
-"login_successful_message" = "\"You are ready to use Delta Chat.\"";
 "start_chat" = "Start Chat";
 "dismiss" = "Dismiss";
 "photo" = "Photo";

+ 0 - 3
tools/untranslated.xml

@@ -7,11 +7,8 @@
     <string name="imap_password">your IMAP password</string>
     <string name="success">Success</string>
     <string name="videos">Videos</string>
-    <string name="configuring_account">Configuring Account</string>
     <string name="hide">Hide</string>
     <string name="login_error_title">Unable to login!</string>
-    <string name="login_successful_title">Login successful!</string>
-    <string name="login_successful_message">"You are ready to use Delta Chat."</string>
     <string name="start_chat">Start Chat</string>
     <string name="dismiss">Dismiss</string>
     <string name="photo">Photo</string>