Sfoglia il codice sorgente

WIP: in SettingsController instead of alert pop up user will edit DisplayName and Status on a different viewcontroller - experiencing weird issues when calling dc_configure (jumps to chats tab unasked after a while)

Bastian van de Wetering 6 anni fa
parent
commit
49348ca5ea

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

@@ -107,6 +107,7 @@
 		AEE6EC382281AF2D00EDC689 /* InitialsBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC372281AF2D00EDC689 /* InitialsBadge.swift */; };
 		AEE6EC3F2282C59C00EDC689 /* GroupMembersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */; };
 		AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */; };
+		AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC472283045D00EDC689 /* EditSettingsController.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -303,6 +304,7 @@
 		AEE6EC372281AF2D00EDC689 /* InitialsBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsBadge.swift; sourceTree = "<group>"; };
 		AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupMembersViewController.swift; sourceTree = "<group>"; };
 		AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailboxViewController.swift; sourceTree = "<group>"; };
+		AEE6EC472283045D00EDC689 /* EditSettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditSettingsController.swift; sourceTree = "<group>"; };
 		FECB35E2B04CD5F5D02C157A /* Pods-deltachat-iosTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-deltachat-iosTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-deltachat-iosTests/Pods-deltachat-iosTests.release.xcconfig"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -603,6 +605,7 @@
 				AE851ACF227DF50900ED86F0 /* SingleChatDetailViewController.swift */,
 				AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */,
 				AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */,
+				AEE6EC472283045D00EDC689 /* EditSettingsController.swift */,
 			);
 			path = Controller;
 			sourceTree = "<group>";
@@ -984,6 +987,7 @@
 				7070FB7320FF345F000DC258 /* dc_aheader.c in Sources */,
 				7070FB6120FF345F000DC258 /* dc_securejoin.c in Sources */,
 				78ED838F21D5927A00243125 /* ProfileViewController.swift in Sources */,
+				AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */,
 				78E45E4221D3DB4000D4B15E /* UIViewController+Extension.swift in Sources */,
 				7A9FB1441FB061E2001FEA36 /* AppDelegate.swift in Sources */,
 				AEE56D7D2253ADB4007DC082 /* HudHandler.swift in Sources */,

+ 87 - 0
deltachat-ios/Controller/EditSettingsController.swift

@@ -0,0 +1,87 @@
+//
+//  EditSettingsController.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 08.05.19.
+//  Copyright © 2019 Jonas Reinsch. All rights reserved.
+//
+
+import UIKit
+
+class EditSettingsController: UITableViewController {
+
+	private var displayNameBackup: String?
+	private var statusCellBackup: String?
+
+	private lazy var displayNameCell: TextFieldCell = {
+		let cell = TextFieldCell(description: "Display Name", placeholder: "Display Name")
+		cell.setText(text: MRConfig.displayname ?? nil)
+		return cell
+	}()
+
+	private lazy var statusCell: TextFieldCell = {
+		let cell = TextFieldCell(description: "Status", placeholder: "Your Status")
+		cell.setText(text: MRConfig.selfstatus ?? nil)
+		return cell
+	}()
+
+	init() {
+		super.init(style: .grouped)
+	}
+
+	required init?(coder aDecoder: NSCoder) {
+		fatalError("init(coder:) has not been implemented")
+	}
+
+	override func viewDidLoad() {
+		super.viewDidLoad()
+		// Uncomment the following line to preserve selection between presentations
+		// self.clearsSelectionOnViewWillAppear = false
+
+		// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+		// self.navigationItem.rightBarButtonItem = self.editButtonItem
+	}
+
+	override func viewWillAppear(_ animated: Bool) {
+		displayNameBackup = MRConfig.displayname
+		statusCellBackup = MRConfig.selfstatus
+	}
+
+	override func viewWillDisappear(_ animated: Bool) {
+		if displayNameBackup != displayNameCell.getText() || statusCellBackup != displayNameCell.getText() {
+			MRConfig.selfstatus = statusCell.getText()
+			MRConfig.displayname = displayNameCell.getText()	
+			dc_configure(mailboxPointer)
+		}
+	}
+
+	// MARK: - Table view data source
+
+	override func numberOfSections(in tableView: UITableView) -> Int {
+		// #warning Incomplete implementation, return the number of sections
+		return 2
+	}
+
+	override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+		// #warning Incomplete implementation, return the number of rows
+		return 1
+	}
+
+	override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+		let section = indexPath.section
+		if section == 0 {
+			return displayNameCell
+		} else {
+			return statusCell
+		}
+	}
+
+	func activateField(option: SettingsEditOption) {
+		switch option {
+		case .DISPLAYNAME:
+			displayNameCell.textField.becomeFirstResponder()
+		case .STATUS:
+			statusCell.textField.becomeFirstResponder()
+		}
+	}
+}

+ 16 - 5
deltachat-ios/Controller/SettingsController.swift

@@ -28,12 +28,13 @@ internal final class SettingsViewController: QuickTableViewController {
     super.viewDidLoad()
     title = "Settings"
     documentInteractionController.delegate = self as? UIDocumentInteractionControllerDelegate
-    setTable()
   }
 
+
   override func viewDidAppear(_ animated: Bool) {
+
     super.viewDidAppear(animated)
-    let nc = NotificationCenter.default
+		let nc = NotificationCenter.default
     backupProgressObserver = nc.addObserver(
       forName: dcNotificationBackupProgress,
       object: nil,
@@ -68,7 +69,7 @@ internal final class SettingsViewController: QuickTableViewController {
 
   override func viewWillAppear(_ animated: Bool) {
     super.viewWillAppear(animated)
-
+		setTable()
     if #available(iOS 11.0, *) {
       navigationController?.navigationBar.prefersLargeTitles = true
     }
@@ -104,8 +105,8 @@ internal final class SettingsViewController: QuickTableViewController {
       Section(
         title: "User Details",
         rows: [
-          NavigationRow(text: "Display Name", detailText: .value1(MRConfig.displayname ?? ""), action: editCell()),
-          NavigationRow(text: "Status", detailText: .value1(MRConfig.selfstatus ?? ""), action: editCell()),
+					NavigationRow(text: "Display Name", detailText: .value1(MRConfig.displayname ?? ""), action: { [weak self] in self?.editNameAndStatus($0)}),
+          NavigationRow(text: "Status", detailText: .value1(MRConfig.selfstatus ?? ""), action: { [weak self] in self?.editNameAndStatus($0)}),
           TapActionRow(text: "Configure my Account", action: { [weak self] in self?.presentAccountSetup($0) }),
         ]
       ),
@@ -277,4 +278,14 @@ internal final class SettingsViewController: QuickTableViewController {
   private func presentAccountSetup(_: Row) {
     coordinator?.showAccountSetupController()
   }
+
+	private func editNameAndStatus(_ row: Row) {
+		guard let option = SettingsEditOption(rawValue: row.text) else { return }
+		coordinator?.showEditSettingsController(option: option)
+	}
+}
+
+enum SettingsEditOption: String {
+	case DISPLAYNAME = "Display Name"
+	case STATUS = "Status"
 }

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

@@ -177,6 +177,12 @@ class SettingsCoordinator: Coordinator {
     let accountSetupVC = AccountSetupController()
     navigationController.pushViewController(accountSetupVC, animated: true)
   }
+
+	func showEditSettingsController(option: SettingsEditOption) {
+		let editController = EditSettingsController()
+		editController.activateField(option: option)
+		navigationController.pushViewController(editController, animated: true)
+	}
 }
 
 class NewChatCoordinator: Coordinator {