Sfoglia il codice sorgente

Merge pull request #310 from deltachat/add_self_avatar_beside_settings_profile

add self avatar beside settings profile (#302)
björn petersen 5 anni fa
parent
commit
df62c9545c
1 ha cambiato i file con 69 aggiunte e 9 eliminazioni
  1. 69 9
      deltachat-ios/Controller/SettingsController.swift

+ 69 - 9
deltachat-ios/Controller/SettingsController.swift

@@ -5,6 +5,8 @@ import UIKit
 internal final class SettingsViewController: QuickTableViewController {
     weak var coordinator: SettingsCoordinator?
 
+    private let sectionProfileInfo = 0
+    private let rowProfile = 0
     private var dcContext: DcContext
 
     let documentInteractionController = UIDocumentInteractionController()
@@ -86,14 +88,70 @@ internal final class SettingsViewController: QuickTableViewController {
         }
     }
 
-    private func setTable() {
-        let addr = (DcConfig.addr ?? "")
-        let status = (DcConfig.selfstatus ?? "-")
-        var subtitle = addr
-        if !addr.isEmpty && !status.isEmpty {
-            subtitle += ", " + String.localized("pref_default_status_label") + ": "
+    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        if indexPath.section == sectionProfileInfo && indexPath.row == rowProfile {
+            return customProfileCell(tableView, indexPath: indexPath)
+        } else {
+            return super.tableView(tableView, cellForRowAt: indexPath)
         }
-        subtitle += status
+    }
+
+    private func customProfileCell(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
+        let cell = super.tableView(tableView, cellForRowAt: indexPath)
+        let badge = createProfileBadge()
+        let nameLabel = createNameLabel()
+        let signatureLabel = createSubtitle()
+
+        cell.contentView.addSubview(badge)
+        cell.contentView.addSubview(nameLabel)
+        cell.contentView.addSubview(signatureLabel)
+
+        let badgeConstraints = [badge.constraintAlignLeadingTo(cell.contentView, paddingLeading: 16),
+                                badge.constraintCenterYTo(cell.contentView),
+                                badge.constraintAlignTopTo(cell.contentView, paddingTop: 8),
+                                badge.constraintAlignBottomTo(cell.contentView, paddingBottom: 8)]
+        let textViewConstraints = [nameLabel.constraintToTrailingOf(badge, paddingLeading: 8),
+                                   nameLabel.constraintAlignTrailingTo(cell.contentView, paddingTrailing: 16),
+                                   nameLabel.constraintAlignTopTo(cell.contentView, paddingTop: 8)]
+        let subtitleViewConstraints = [signatureLabel.constraintToTrailingOf(badge, paddingLeading: 8),
+                                       signatureLabel.constraintAlignTrailingTo(cell.contentView, paddingTrailing: 16),
+                                       signatureLabel.constraintToBottomOf(nameLabel, paddingTop: 2),
+                                       signatureLabel.constraintAlignBottomTo(cell.contentView, paddingBottom: 8)]
+
+        cell.contentView.addConstraints(badgeConstraints)
+        cell.contentView.addConstraints(textViewConstraints)
+        cell.contentView.addConstraints(subtitleViewConstraints)
+
+        return cell
+    }
+
+    private func createProfileBadge() -> InitialsBadge {
+        let selfContact = DcContact(id: Int(DC_CONTACT_ID_SELF))
+        if let image = selfContact.profileImage {
+            return  InitialsBadge(image: image, size: 35)
+        } else {
+            return  InitialsBadge(name: DcConfig.displayname ?? selfContact.email, color: selfContact.color, size: 35)
+        }
+    }
+
+    private func createNameLabel() -> UILabel {
+        let nameLabel = UILabel.init()
+        nameLabel.translatesAutoresizingMaskIntoConstraints = false
+        nameLabel.text = DcConfig.displayname ?? String.localized("pref_your_name")
+        return nameLabel
+    }
+
+    private func createSubtitle() -> UILabel {
+        let subtitle = (DcConfig.addr ?? "")
+        let subtitleView = UILabel.init()
+        subtitleView.translatesAutoresizingMaskIntoConstraints = false
+        subtitleView.text = subtitle
+        subtitleView.font = UIFont.systemFont(ofSize: 12)
+        subtitleView.lineBreakMode = .byTruncatingTail
+        return subtitleView
+    }
+
+    private func setTable() {
 
         var appNameAndVersion = "Delta Chat"
         if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
@@ -104,8 +162,10 @@ internal final class SettingsViewController: QuickTableViewController {
             Section(
                 title: String.localized("pref_profile_info_headline"),
                 rows: [
-                    NavigationRow(text: DcConfig.displayname ?? String.localized("pref_your_name"),
-                        detailText: .subtitle(subtitle),
+                    //The profile row has a custom view and is set in
+                    //tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
+                    NavigationRow(text: "",
+                        detailText: .none,
                         action: { _ in
                             self.coordinator?.showEditSettingsController()
                     }),