ソースを参照

implemented environment to build table - added profile

nayooti 5 年 前
コミット
14f7044e8f

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

@@ -689,6 +689,13 @@
 			path = Assets;
 			sourceTree = "<group>";
 		};
+		AE406EEE240FA454005F7022 /* Cell */ = {
+			isa = PBXGroup;
+			children = (
+			);
+			path = Cell;
+			sourceTree = "<group>";
+		};
 		AE77838B23E32EAA0093EABD /* ViewModel */ = {
 			isa = PBXGroup;
 			children = (
@@ -776,6 +783,7 @@
 		AE851AC3227C695900ED86F0 /* View */ = {
 			isa = PBXGroup;
 			children = (
+				AE406EEE240FA454005F7022 /* Cell */,
 				B26B3BC6236DC3DC008ED35A /* SwitchCell.swift */,
 				78E45E4B21D404AE00D4B15E /* CustomMessageCell.swift */,
 				70B8882D2091B8550074812E /* ContactCell.swift */,

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

@@ -2,7 +2,19 @@ import JGProgressHUD
 import QuickTableViewController
 import UIKit
 
-internal final class SettingsViewController: QuickTableViewController {
+internal final class SettingsViewController: UITableViewController {
+
+    private struct SettingsSection {
+        let headerTitle: String?
+        let footerTitle: String?
+        let cells: [UITableViewCell]
+    }
+
+    private enum CellTags: Int {
+        case profileCell = 0
+    }
+
+
     weak var coordinator: SettingsCoordinator?
 
     private let sectionProfileInfo = 0
@@ -20,9 +32,30 @@ internal final class SettingsViewController: QuickTableViewController {
         return hudHandler
     }()
 
+    // MARK: - cells
+
+    private let profileHeader = ContactDetailHeader()
+
+    private lazy var profileCell: UITableViewCell = {
+        let cell = customProfileCell()
+        cell.accessoryType = .disclosureIndicator
+        cell.tag = CellTags.profileCell.rawValue
+        return cell
+    }()
+
+    private lazy var sections: [SettingsSection] = {
+        let profileSection = SettingsSection(
+            headerTitle: String.localized("pref_profile_info_headline"),
+            footerTitle: nil,
+            cells: [profileCell]
+        )
+        return [profileSection]
+    }()
+
+
     init(dcContext: DcContext) {
         self.dcContext = dcContext
-        super.init(nibName: nil, bundle: nil)
+        super.init(style: .grouped)
     }
 
     required init?(coder _: NSCoder) {
@@ -75,7 +108,7 @@ internal final class SettingsViewController: QuickTableViewController {
 
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
-        setTable()
+        // setTable()
     }
 
     override func viewDidDisappear(_ animated: Bool) {
@@ -90,16 +123,39 @@ internal final class SettingsViewController: QuickTableViewController {
         }
     }
 
+    override func numberOfSections(in tableView: UITableView) -> Int {
+        return sections.count
+    }
+
+    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        return sections[section].cells.count
+    }
+
     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)
+        return sections[indexPath.section].cells[indexPath.row]
+    }
+
+    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        guard let cell = tableView.cellForRow(at: indexPath), let cellTag = CellTags(rawValue: cell.tag) else {
+            safe_fatalError()
+            return
         }
+
+        switch cellTag {
+        case .profileCell: self.coordinator?.showEditSettingsController()
+        }
+    }
+
+    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
+        return sections[section].headerTitle
+    }
+
+    override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
+        return sections[section].footerTitle
     }
 
-    private func customProfileCell(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
-        let cell = super.tableView(tableView, cellForRowAt: indexPath)
+    private func customProfileCell() -> UITableViewCell {
+        let cell = UITableViewCell()
 
         cell.contentView.subviews.forEach({ $0.removeFromSuperview() })
 
@@ -157,6 +213,7 @@ internal final class SettingsViewController: QuickTableViewController {
         return subtitleView
     }
 
+    /*
     private func setTable() {
 
         var appNameAndVersion = "Delta Chat"
@@ -242,6 +299,7 @@ internal final class SettingsViewController: QuickTableViewController {
             ),
         ]
     }
+    */
 
     private func startImex(what: Int32) {
         let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)