Эх сурвалжийг харах

change order in group setup process, first select name, second select members

cyberta 5 жил өмнө
parent
commit
80ccda8c1c

+ 39 - 9
deltachat-ios/Controller/GroupMembersViewController.swift

@@ -1,16 +1,36 @@
 import UIKit
 import UIKit
 
 
-class NewGroupViewController: GroupMembersViewController {
-    weak var coordinator: NewGroupCoordinator?
+class NewGroupAddMembersViewController: GroupMembersViewController {
+    weak var coordinator: NewGroupAddMembersCoordinator?
+
+    var onMembersSelected: ((Set<Int>) -> Void)?
+    let isVerifiedGroup: Bool
+
+    private lazy var cancelButton: UIBarButtonItem = {
+        let button = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelButtonPressed))
+        return button
+    }()
+
+   lazy var doneButton: UIBarButtonItem = {
+       let button = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneButtonPressed))
+       return button
+   }()
+
+    init(preselected: Set<Int>, isVerified: Bool) {
+        isVerifiedGroup = isVerified
+        super.init()
+        selectedContactIds = preselected
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
 
 
     override func viewDidLoad() {
     override func viewDidLoad() {
         super.viewDidLoad()
         super.viewDidLoad()
         title = String.localized("group_add_members")
         title = String.localized("group_add_members")
-        let groupCreationNextButton = UIBarButtonItem(title: String.localized("next"),
-                                                      style: .done,
-                                                      target: self,
-                                                      action: #selector(nextButtonPressed))
-        navigationItem.rightBarButtonItem = groupCreationNextButton
+        navigationItem.rightBarButtonItem = doneButton
+        navigationItem.leftBarButtonItem = cancelButton
         contactIds = Utils.getContactIds()
         contactIds = Utils.getContactIds()
     }
     }
 
 
@@ -22,9 +42,19 @@ class NewGroupViewController: GroupMembersViewController {
         super.didReceiveMemoryWarning()
         super.didReceiveMemoryWarning()
     }
     }
 
 
-    @objc func nextButtonPressed() {
-        coordinator?.showGroupNameController(contactIdsForGroup: selectedContactIds)
+    @objc func cancelButtonPressed() {
+        navigationController?.popViewController(animated: true)
     }
     }
+
+    @objc func doneButtonPressed() {
+        if let onMembersSelected = onMembersSelected {
+            selectedContactIds.insert(Int(DC_CONTACT_ID_SELF))
+            onMembersSelected(selectedContactIds)
+        } else {
+            navigationController?.popViewController(animated: true)
+        }
+    }
+
 }
 }
 
 
 class AddGroupMembersViewController: GroupMembersViewController {
 class AddGroupMembersViewController: GroupMembersViewController {

+ 70 - 14
deltachat-ios/Controller/GroupNameController.swift

@@ -7,14 +7,22 @@ class GroupNameController: UITableViewController, MediaPickerDelegate {
     var groupName: String = ""
     var groupName: String = ""
 
 
     var doneButton: UIBarButtonItem!
     var doneButton: UIBarButtonItem!
-    let contactIdsForGroup: Set<Int> // TODO: check if array is sufficient
-    let groupContactIds: [Int]
+    var contactIdsForGroup: Set<Int> // TODO: check if array is sufficient
+    var groupContactIds: [Int]
     var groupImage: UIImage?
     var groupImage: UIImage?
+    let isVerifiedGroup: Bool
 
 
     private let sectionGroupDetails = 0
     private let sectionGroupDetails = 0
     private let sectionGroupDetailsRowAvatar = 0
     private let sectionGroupDetailsRowAvatar = 0
     private let sectionGroupDetailsRowName = 1
     private let sectionGroupDetailsRowName = 1
     private let countSectionGroupDetails = 2
     private let countSectionGroupDetails = 2
+    private let sectionInvite = 1
+    private let sectionInviteRowAddMembers = 0
+    private let sectionInviteRowShowQrCode = 1
+    private lazy var countSectionInvite: Int = {
+        return isVerifiedGroup ? 2 : 1
+    }()
+    private let sectionGroupMembers = 2
 
 
     lazy var groupNameCell: TextFieldCell = {
     lazy var groupNameCell: TextFieldCell = {
         let cell = TextFieldCell(description: String.localized("group_name"), placeholder: String.localized("menu_edit_group_name"))
         let cell = TextFieldCell(description: String.localized("group_name"), placeholder: String.localized("menu_edit_group_name"))
@@ -27,11 +35,16 @@ class GroupNameController: UITableViewController, MediaPickerDelegate {
         cell.hintLabel.text = String.localized("group_avatar")
         cell.hintLabel.text = String.localized("group_avatar")
         cell.onAvatarTapped = onAvatarTapped
         cell.onAvatarTapped = onAvatarTapped
         return cell
         return cell
-    }()    
+    }()
 
 
-    init(contactIdsForGroup: Set<Int>) {
+    convenience init(isVerified: Bool) {
+        self.init(contactIdsForGroup: [Int(DC_CONTACT_ID_SELF)], isVerified: isVerified)
+    }
+
+    init(contactIdsForGroup: Set<Int>, isVerified: Bool) {
         self.contactIdsForGroup = contactIdsForGroup
         self.contactIdsForGroup = contactIdsForGroup
-        groupContactIds = Array(contactIdsForGroup)
+        self.groupContactIds = Array(contactIdsForGroup)
+        self.isVerifiedGroup = isVerified
         super.init(style: .grouped)
         super.init(style: .grouped)
     }
     }
 
 
@@ -47,6 +60,7 @@ class GroupNameController: UITableViewController, MediaPickerDelegate {
         tableView.bounces = false
         tableView.bounces = false
         doneButton.isEnabled = false
         doneButton.isEnabled = false
         tableView.register(ContactCell.self, forCellReuseIdentifier: "contactCell")
         tableView.register(ContactCell.self, forCellReuseIdentifier: "contactCell")
+        tableView.register(ActionCell.self, forCellReuseIdentifier: "actionCell")
     }
     }
 
 
     @objc func doneButtonPressed() {
     @objc func doneButtonPressed() {
@@ -74,20 +88,37 @@ class GroupNameController: UITableViewController, MediaPickerDelegate {
     }
     }
 
 
     override func numberOfSections(in _: UITableView) -> Int {
     override func numberOfSections(in _: UITableView) -> Int {
-        return 2
+        return 3
     }
     }
 
 
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         let section = indexPath.section
         let section = indexPath.section
         let row = indexPath.row
         let row = indexPath.row
 
 
-        if section == sectionGroupDetails {
-            if row == sectionGroupDetailsRowAvatar {
+        switch section {
+        case sectionGroupDetails:
+             if row == sectionGroupDetailsRowAvatar {
                 return avatarSelectionCell
                 return avatarSelectionCell
             } else {
             } else {
                 return groupNameCell
                 return groupNameCell
             }
             }
-        } else {
+        case sectionInvite:
+            if row == sectionInviteRowAddMembers {
+                let cell = tableView.dequeueReusableCell(withIdentifier: "actionCell", for: indexPath)
+                if let actionCell = cell as? ActionCell {
+                    actionCell.actionTitle = String.localized("group_add_members")
+                    actionCell.actionColor = UIColor.systemBlue
+                }
+                return cell
+            } else {
+                let cell = tableView.dequeueReusableCell(withIdentifier: "actionCell", for: indexPath)
+                if let actionCell = cell as? ActionCell {
+                    actionCell.actionTitle = String.localized("qrshow_join_group_title")
+                    actionCell.actionColor = UIColor.systemBlue
+                }
+                return cell
+            }
+        default:
             let cell = tableView.dequeueReusableCell(withIdentifier: "contactCell", for: indexPath)
             let cell = tableView.dequeueReusableCell(withIdentifier: "contactCell", for: indexPath)
             if let contactCell = cell as? ContactCell {
             if let contactCell = cell as? ContactCell {
                 let contact = DcContact(id: groupContactIds[row])
                 let contact = DcContact(id: groupContactIds[row])
@@ -108,33 +139,53 @@ class GroupNameController: UITableViewController, MediaPickerDelegate {
     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
         let section = indexPath.section
         let section = indexPath.section
         let row = indexPath.row
         let row = indexPath.row
-        if section == sectionGroupDetails {
+        switch section {
+        case sectionGroupDetails:
             if row == sectionGroupDetailsRowAvatar {
             if row == sectionGroupDetailsRowAvatar {
                 return AvatarSelectionCell.cellSize
                 return AvatarSelectionCell.cellSize
             } else {
             } else {
                 return Constants.defaultCellHeight
                 return Constants.defaultCellHeight
             }
             }
-        } else {
+        case sectionInvite:
+            return Constants.defaultCellHeight
+        default:
             return ContactCell.cellHeight
             return ContactCell.cellHeight
         }
         }
     }
     }
 
 
     override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
     override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
-        if section == sectionGroupDetails {
+        switch section {
+        case sectionGroupDetails:
             return countSectionGroupDetails
             return countSectionGroupDetails
-        } else {
+        case sectionInvite:
+            return countSectionInvite
+        default:
             return contactIdsForGroup.count
             return contactIdsForGroup.count
         }
         }
     }
     }
 
 
     override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
     override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
-        if section == 1 {
+        if section == sectionGroupMembers {
             return String.localized("in_this_group_desktop")
             return String.localized("in_this_group_desktop")
         } else {
         } else {
             return nil
             return nil
         }
         }
     }
     }
 
 
+    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        let section = indexPath.section
+        let row = indexPath.row
+        if section == sectionInvite {
+            if row == sectionInviteRowAddMembers {
+                var contactsWithoutSelf = contactIdsForGroup
+                contactsWithoutSelf.remove(Int(DC_CONTACT_ID_SELF))
+                coordinator?.showAddMembers(preselectedMembers: contactsWithoutSelf, isVerified: self.isVerifiedGroup)
+            } else {
+                logger.debug("todo: implement me")
+            }
+        }
+    }
+
     private func updateGroupName(textView: UITextField) {
     private func updateGroupName(textView: UITextField) {
         let name = textView.text ?? ""
         let name = textView.text ?? ""
         groupName = name
         groupName = name
@@ -172,4 +223,9 @@ class GroupNameController: UITableViewController, MediaPickerDelegate {
         self.tableView.endUpdates()
         self.tableView.endUpdates()
     }
     }
 
 
+    func updateGroupContactIds(_ members: Set<Int>) {
+        contactIdsForGroup = members
+        groupContactIds = Array(members)
+        self.tableView.reloadData()
+    }
 }
 }

+ 21 - 5
deltachat-ios/Controller/NewChatViewController.swift

@@ -9,8 +9,9 @@ class NewChatViewController: UITableViewController {
 
 
     private let sectionNew = 0
     private let sectionNew = 0
     private let sectionNewRowNewGroup = 0
     private let sectionNewRowNewGroup = 0
-    private let sectionNewRowNewContact = 1
-    private let sectionNewRowCount = 2
+    private let sectionNewRowNewVerifiedGroup = 1
+    private let sectionNewRowNewContact = 2
+    private let sectionNewRowCount = 3
 
 
     private let sectionImportedContacts = 1
     private let sectionImportedContacts = 1
 
 
@@ -180,6 +181,20 @@ class NewChatViewController: UITableViewController {
                 return cell
                 return cell
             }
             }
 
 
+            if row == sectionNewRowNewVerifiedGroup {
+                // new verified group row
+                let cell: UITableViewCell
+                if let c = tableView.dequeueReusableCell(withIdentifier: "newContactCell") {
+                    cell = c
+                } else {
+                    cell = UITableViewCell(style: .default, reuseIdentifier: "newContactCell")
+                }
+                cell.textLabel?.text = String.localized("menu_new_verified_group")
+                cell.textLabel?.textColor = view.tintColor
+
+                return cell
+            }
+
             if row == sectionNewRowNewContact {
             if row == sectionNewRowNewContact {
                 // new contact row
                 // new contact row
                 let cell: UITableViewCell
                 let cell: UITableViewCell
@@ -238,9 +253,10 @@ class NewChatViewController: UITableViewController {
 
 
         if section == sectionNew {
         if section == sectionNew {
             if row == sectionNewRowNewGroup {
             if row == sectionNewRowNewGroup {
-                coordinator?.showNewGroupController()
-            }
-            if row == sectionNewRowNewContact {
+                coordinator?.showNewGroupController(isVerified: false)
+            } else if row == sectionNewRowNewVerifiedGroup {
+                coordinator?.showNewGroupController(isVerified: true)
+            } else if row == sectionNewRowNewContact {
                 coordinator?.showNewContactController()
                 coordinator?.showNewContactController()
             }
             }
         } else if section == sectionImportedContacts {
         } else if section == sectionImportedContacts {

+ 24 - 18
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -291,9 +291,9 @@ class NewChatCoordinator: Coordinator {
         self.navigationController = navigationController
         self.navigationController = navigationController
     }
     }
 
 
-    func showNewGroupController() {
-        let newGroupController = NewGroupViewController()
-        let coordinator = NewGroupCoordinator(dcContext: dcContext, navigationController: navigationController)
+    func showNewGroupController(isVerified: Bool) {
+        let newGroupController = GroupNameController(isVerified: isVerified)
+        let coordinator = GroupNameCoordinator(dcContext: dcContext, navigationController: navigationController)
         childCoordinators.append(coordinator)
         childCoordinators.append(coordinator)
         newGroupController.coordinator = coordinator
         newGroupController.coordinator = coordinator
         navigationController.pushViewController(newGroupController, animated: true)
         navigationController.pushViewController(newGroupController, animated: true)
@@ -454,7 +454,7 @@ class ChatViewCoordinator: NSObject, Coordinator {
     }
     }
 }
 }
 
 
-class NewGroupCoordinator: Coordinator {
+class NewGroupAddMembersCoordinator: Coordinator {
     var dcContext: DcContext
     var dcContext: DcContext
     let navigationController: UINavigationController
     let navigationController: UINavigationController
 
 
@@ -464,14 +464,6 @@ class NewGroupCoordinator: Coordinator {
         self.dcContext = dcContext
         self.dcContext = dcContext
         self.navigationController = navigationController
         self.navigationController = navigationController
     }
     }
-
-    func showGroupNameController(contactIdsForGroup: Set<Int>) {
-        let groupNameController = GroupNameController(contactIdsForGroup: contactIdsForGroup)
-        let coordinator = GroupNameCoordinator(dcContext: dcContext, navigationController: navigationController)
-        childCoordinators.append(coordinator)
-        groupNameController.coordinator = coordinator
-        navigationController.pushViewController(groupNameController, animated: true)
-    }
 }
 }
 
 
 class AddGroupMembersCoordinator: Coordinator {
 class AddGroupMembersCoordinator: Coordinator {
@@ -500,7 +492,6 @@ class GroupNameCoordinator: Coordinator {
     let navigationController: UINavigationController
     let navigationController: UINavigationController
     let mediaPicker: MediaPicker
     let mediaPicker: MediaPicker
 
 
-
     private var childCoordinators: [Coordinator] = []
     private var childCoordinators: [Coordinator] = []
 
 
     init(dcContext: DcContext, navigationController: UINavigationController) {
     init(dcContext: DcContext, navigationController: UINavigationController) {
@@ -519,13 +510,28 @@ class GroupNameCoordinator: Coordinator {
     }
     }
 
 
     func showPhotoPicker(delegate: MediaPickerDelegate) {
     func showPhotoPicker(delegate: MediaPickerDelegate) {
-          mediaPicker.showPhotoGallery(delegate: delegate)
-      }
+        mediaPicker.showPhotoGallery(delegate: delegate)
+    }
 
 
-      func showCamera(delegate: MediaPickerDelegate) {
-          mediaPicker.showCamera(delegate: delegate)
-      }
+    func showCamera(delegate: MediaPickerDelegate) {
+        mediaPicker.showCamera(delegate: delegate)
+    }
 
 
+    func showAddMembers(preselectedMembers: Set<Int>, isVerified: Bool) {
+        let newGroupController = NewGroupAddMembersViewController(preselected: preselectedMembers, isVerified: isVerified)
+        let coordinator = NewGroupAddMembersCoordinator(dcContext: dcContext, navigationController: navigationController)
+        childCoordinators.append(coordinator)
+        newGroupController.coordinator = coordinator
+        newGroupController.onMembersSelected = onGroupMembersSelected
+        navigationController.pushViewController(newGroupController, animated: true)
+    }
+
+    func onGroupMembersSelected(_ memberIds: Set<Int>) {
+        navigationController.popViewController(animated: true)
+        if let groupNameController = navigationController.topViewController as? GroupNameController {
+            groupNameController.updateGroupContactIds(memberIds)
+        }
+    }
 }
 }
 
 
 class ContactDetailCoordinator: Coordinator, ContactDetailCoordinatorProtocol {
 class ContactDetailCoordinator: Coordinator, ContactDetailCoordinatorProtocol {