瀏覽代碼

bugfixes + had to move ProfileCell to seperate - before had factory method - but no chance to access profile properties to update cell without reloading full table

nayooti 5 年之前
父節點
當前提交
25f72349d1

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -127,6 +127,7 @@
 		AE25F09022807AD800CDEA66 /* AvatarSelectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE25F08F22807AD800CDEA66 /* AvatarSelectionCell.swift */; };
 		AE25F09022807AD800CDEA66 /* AvatarSelectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE25F08F22807AD800CDEA66 /* AvatarSelectionCell.swift */; };
 		AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B31722672DFC00EC37A1 /* ActionCell.swift */; };
 		AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B31722672DFC00EC37A1 /* ActionCell.swift */; };
 		AE38B31A2267328200EC37A1 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B3192267328200EC37A1 /* Colors.swift */; };
 		AE38B31A2267328200EC37A1 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B3192267328200EC37A1 /* Colors.swift */; };
+		AE406EF0240FF8FF005F7022 /* ProfileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE406EEF240FF8FF005F7022 /* ProfileCell.swift */; };
 		AE4AEE3522B1030D000AA495 /* PreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE4AEE3422B1030D000AA495 /* PreviewController.swift */; };
 		AE4AEE3522B1030D000AA495 /* PreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE4AEE3422B1030D000AA495 /* PreviewController.swift */; };
 		AE52EA19229EB53C00C586C9 /* ContactDetailHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */; };
 		AE52EA19229EB53C00C586C9 /* ContactDetailHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */; };
 		AE52EA20229EB9F000C586C9 /* EditGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */; };
 		AE52EA20229EB9F000C586C9 /* EditGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */; };
@@ -356,6 +357,7 @@
 		AE25F08F22807AD800CDEA66 /* AvatarSelectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarSelectionCell.swift; sourceTree = "<group>"; };
 		AE25F08F22807AD800CDEA66 /* AvatarSelectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarSelectionCell.swift; sourceTree = "<group>"; };
 		AE38B31722672DFC00EC37A1 /* ActionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCell.swift; sourceTree = "<group>"; };
 		AE38B31722672DFC00EC37A1 /* ActionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCell.swift; sourceTree = "<group>"; };
 		AE38B3192267328200EC37A1 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
 		AE38B3192267328200EC37A1 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
+		AE406EEF240FF8FF005F7022 /* ProfileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileCell.swift; sourceTree = "<group>"; };
 		AE4AEE3422B1030D000AA495 /* PreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewController.swift; sourceTree = "<group>"; };
 		AE4AEE3422B1030D000AA495 /* PreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewController.swift; sourceTree = "<group>"; };
 		AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactDetailHeader.swift; sourceTree = "<group>"; };
 		AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactDetailHeader.swift; sourceTree = "<group>"; };
 		AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditGroupViewController.swift; sourceTree = "<group>"; };
 		AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditGroupViewController.swift; sourceTree = "<group>"; };
@@ -692,6 +694,7 @@
 		AE406EEE240FA454005F7022 /* Cell */ = {
 		AE406EEE240FA454005F7022 /* Cell */ = {
 			isa = PBXGroup;
 			isa = PBXGroup;
 			children = (
 			children = (
+				AE406EEF240FF8FF005F7022 /* ProfileCell.swift */,
 			);
 			);
 			path = Cell;
 			path = Cell;
 			sourceTree = "<group>";
 			sourceTree = "<group>";
@@ -1112,6 +1115,7 @@
 				305961DC2346125100C80F33 /* MessagesLayoutDelegate.swift in Sources */,
 				305961DC2346125100C80F33 /* MessagesLayoutDelegate.swift in Sources */,
 				3059620A2346125100C80F33 /* TextMessageSizeCalculator.swift in Sources */,
 				3059620A2346125100C80F33 /* TextMessageSizeCalculator.swift in Sources */,
 				78ED839421D5AF8A00243125 /* QrCodeView.swift in Sources */,
 				78ED839421D5AF8A00243125 /* QrCodeView.swift in Sources */,
+				AE406EF0240FF8FF005F7022 /* ProfileCell.swift in Sources */,
 				305961F02346125100C80F33 /* NSConstraintLayoutSet.swift in Sources */,
 				305961F02346125100C80F33 /* NSConstraintLayoutSet.swift in Sources */,
 				3059620E234614E700C80F33 /* DcContact+Extension.swift in Sources */,
 				3059620E234614E700C80F33 /* DcContact+Extension.swift in Sources */,
 				305961F72346125100C80F33 /* MessageCollectionViewCell.swift in Sources */,
 				305961F72346125100C80F33 /* MessageCollectionViewCell.swift in Sources */,

+ 24 - 10
deltachat-ios/Controller/SettingsController.swift

@@ -43,9 +43,11 @@ internal final class SettingsViewController: UITableViewController {
 
 
     private let profileHeader = ContactDetailHeader()
     private let profileHeader = ContactDetailHeader()
 
 
-    private lazy var profileCell: UITableViewCell = {
-        let cell = customProfileCell()
-        cell.accessoryType = .disclosureIndicator
+    private lazy var profileCell: ProfileCell = {
+        let displayName = DcConfig.displayname ?? String.localized("pref_your_name")
+        let email = (DcConfig.addr ?? "")
+        let selfContact = DcContact(id: Int(DC_CONTACT_ID_SELF))
+        let cell = ProfileCell(contact: selfContact)
         cell.tag = CellTags.profile.rawValue
         cell.tag = CellTags.profile.rawValue
         return cell
         return cell
     }()
     }()
@@ -194,6 +196,11 @@ internal final class SettingsViewController: UITableViewController {
         documentInteractionController.delegate = self as? UIDocumentInteractionControllerDelegate
         documentInteractionController.delegate = self as? UIDocumentInteractionControllerDelegate
     }
     }
 
 
+    override func viewWillAppear(_ animated: Bool) {
+        super.viewWillAppear(animated)
+        updateCells()
+    }
+
     override func viewDidAppear(_ animated: Bool) {
     override func viewDidAppear(_ animated: Bool) {
 
 
         super.viewDidAppear(animated)
         super.viewDidAppear(animated)
@@ -230,11 +237,6 @@ internal final class SettingsViewController: UITableViewController {
         }
         }
     }
     }
 
 
-    override func viewWillAppear(_ animated: Bool) {
-        super.viewWillAppear(animated)
-        // setTable()
-    }
-
     override func viewDidDisappear(_ animated: Bool) {
     override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
         super.viewDidDisappear(animated)
 
 
@@ -488,17 +490,20 @@ internal final class SettingsViewController: UITableViewController {
 
 
     private func handleNotificationToggle() {
     private func handleNotificationToggle() {
         notificationSwitch.isOn = !notificationSwitch.isOn
         notificationSwitch.isOn = !notificationSwitch.isOn
-        UserDefaults.standard.set(notificationSwitch.isOn, forKey: "notifications_disabled")
+        UserDefaults.standard.set(!notificationSwitch.isOn, forKey: "notifications_disabled")
+        UserDefaults.standard.synchronize()
     }
     }
 
 
     private func handleReceiptConfirmationToggle() {
     private func handleReceiptConfirmationToggle() {
         receiptConfirmationSwitch.isOn = !receiptConfirmationSwitch.isOn
         receiptConfirmationSwitch.isOn = !receiptConfirmationSwitch.isOn
-        UserDefaults.standard.set(receiptConfirmationSwitch.isOn, forKey: "notifications_disabled")
+        DcConfig.mdnsEnabled = receiptConfirmationSwitch.isOn
+        dc_configure(mailboxPointer)
     }
     }
 
 
     private func handleAutocryptPreferencesToggle() {
     private func handleAutocryptPreferencesToggle() {
         autocryptSwitch.isOn = !autocryptSwitch.isOn
         autocryptSwitch.isOn = !autocryptSwitch.isOn
         DcConfig.e2eeEnabled = autocryptSwitch.isOn
         DcConfig.e2eeEnabled = autocryptSwitch.isOn
+        dc_configure(mailboxPointer)
     }
     }
 
 
     private func sendAutocryptSetupMessage() {
     private func sendAutocryptSetupMessage() {
@@ -531,4 +536,13 @@ internal final class SettingsViewController: UITableViewController {
         askAlert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
         askAlert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
         present(askAlert, animated: true, completion: nil)
         present(askAlert, animated: true, completion: nil)
     }
     }
+
+    // MARK: - updates
+    private func updateCells() {
+        let selfContact = DcContact(id: Int(DC_CONTACT_ID_SELF))
+        profileCell.update(contact: selfContact)
+
+        chatPreferenceCell.detailTextLabel?.text = SettingsClassicViewController.getValString(val: DcConfig.showEmails)
+
+    }
 }
 }

+ 38 - 0
deltachat-ios/View/Cell/ProfileCell.swift

@@ -0,0 +1,38 @@
+import UIKit
+
+class ProfileCell: UITableViewCell {
+
+    private let detailView = ContactDetailHeader()
+
+    init(contact: DcContact) {
+        super.init(style: .default, reuseIdentifier: nil)
+        accessoryType = .disclosureIndicator
+        setupSubviews()
+        update(contact: contact)
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    private func setupSubviews() {
+        contentView.addSubview(detailView)
+        detailView.translatesAutoresizingMaskIntoConstraints = false
+        detailView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 0).isActive = true
+        detailView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0).isActive = true
+        detailView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 0).isActive = true
+        detailView.trailingAnchor.constraint(equalTo: accessoryView?.trailingAnchor ?? contentView.trailingAnchor, constant: 0).isActive = true
+        detailView.heightAnchor.constraint(equalToConstant: ContactDetailHeader.headerHeight).isActive = true
+    }
+
+    func update(contact: DcContact) {
+        let displayName = DcConfig.displayname
+        let email = DcConfig.addr ?? contact.email
+        detailView.updateDetails(title: displayName ?? contact.displayName, subtitle: email)
+        if let image = contact.profileImage {
+            detailView.setImage(image)
+        } else {
+            detailView.setBackupImage(name: displayName ?? email, color: contact.color)
+        }
+    }
+}