Browse Source

rename profile-attachment-section to chat-options, make it less static

B. Petersen 5 năm trước cách đây
mục cha
commit
0ab91015c9

+ 3 - 3
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -136,7 +136,7 @@ class ContactDetailViewController: UITableViewController {
         let row = indexPath.row
         let cellType = viewModel.typeFor(section: indexPath.section)
         switch cellType {
-        case .attachments:
+        case .chatOptions:
             switch viewModel.attachmentActionFor(row: row) {
             case .documents:
                 return documentsCell
@@ -170,7 +170,7 @@ class ContactDetailViewController: UITableViewController {
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         let type = viewModel.typeFor(section: indexPath.section)
         switch type {
-        case .attachments:
+        case .chatOptions:
             handleAttachmentAction(for: indexPath.row)
         case .chatActions:
             handleCellAction(for: indexPath.row)
@@ -186,7 +186,7 @@ class ContactDetailViewController: UITableViewController {
     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
         let type = viewModel.typeFor(section: indexPath.section)
         switch type {
-        case .chatActions, .startChat, .attachments:
+        case .chatActions, .startChat, .chatOptions:
             return Constants.defaultCellHeight
         case .sharedChats:
             return ContactCell.cellHeight

+ 22 - 13
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -4,11 +4,16 @@ import DcCore
 class GroupChatDetailViewController: UIViewController {
 
     enum ProfileSections {
-        case attachments
+        case chatOptions
         case members
         case chatActions
     }
 
+    enum ChatOption {
+        case gallery
+        case documents
+    }
+
     enum ChatAction {
         case ephemeralMessages
         case muteChat
@@ -17,6 +22,10 @@ class GroupChatDetailViewController: UIViewController {
         case deleteChat
     }
 
+    private lazy var chatOptions: [ChatOption] = {
+        return [.gallery, .documents]
+    }()
+
     private lazy var chatActions: [ChatAction] = {
         var actions: [ChatAction] = [.muteChat, .archiveChat, .leaveGroup, .deleteChat]
         if UserDefaults.standard.bool(forKey: "ephemeral_messages") || dcContext.getChatEphemeralTimer(chatId: chatId) > 0 {
@@ -25,15 +34,13 @@ class GroupChatDetailViewController: UIViewController {
         return actions
     }()
 
-    private let attachmentsRowGallery = 0
-    private let attachmentsRowDocuments = 1
     private let membersRowAddMembers = 0
     private let membersRowQrInvite = 1
     private let memberManagementRows = 2
 
     private let dcContext: DcContext
 
-    private let sections: [ProfileSections] = [.attachments, .members, .chatActions]
+    private let sections: [ProfileSections] = [.chatOptions, .members, .chatActions]
 
     private var currentUser: DcContact? {
         let myId = groupMemberIds.filter { DcContact(id: $0).email == dcContext.addr }.first
@@ -287,8 +294,8 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
     func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
         let sectionType = sections[section]
         switch sectionType {
-        case .attachments:
-            return 2
+        case .chatOptions:
+            return chatOptions.count
         case .members:
             return groupMemberIds.count + memberManagementRows
         case .chatActions:
@@ -300,7 +307,7 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let sectionType = sections[indexPath.section]
         let row = indexPath.row
         switch sectionType {
-        case .attachments, .chatActions:
+        case .chatOptions, .chatActions:
             return Constants.defaultCellHeight
         case .members:
             switch row {
@@ -316,10 +323,11 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let row = indexPath.row
         let sectionType = sections[indexPath.section]
         switch sectionType {
-        case .attachments:
-            if row == attachmentsRowGallery {
+        case .chatOptions:
+            switch chatOptions[row] {
+            case .gallery:
                 return galleryCell
-            } else if row == attachmentsRowDocuments {
+            case .documents:
                 return documentsCell
             }
         case .members:
@@ -373,10 +381,11 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let row = indexPath.row
 
         switch sectionType {
-        case .attachments:
-            if row == attachmentsRowGallery {
+        case .chatOptions:
+            switch chatOptions[row] {
+            case .gallery:
                 showGallery()
-            } else if row == attachmentsRowDocuments {
+            case .documents:
                 showDocuments()
             }
         case .members:

+ 11 - 11
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -7,11 +7,16 @@ class ContactDetailViewModel {
 
     enum ProfileSections {
         case startChat
-        case attachments
+        case chatOptions
         case sharedChats
         case chatActions //  archive chat, block chat, delete chats
     }
 
+    enum ChatOption {
+        case gallery
+        case documents
+    }
+
     enum ChatAction {
         case ephemeralMessages
         case muteChat
@@ -20,11 +25,6 @@ class ContactDetailViewModel {
         case deleteChat
     }
 
-    enum AttachmentAction {
-        case gallery
-        case documents
-    }
-
     var contactId: Int
 
     var contact: DcContact {
@@ -35,7 +35,7 @@ class ContactDetailViewModel {
     private let sharedChats: DcChatlist
     private var sections: [ProfileSections] = []
     private var chatActions: [ChatAction] = []
-    private var attachmentActions: [AttachmentAction] = [.gallery, .documents]
+    private var chatOptions: [ChatOption] = [.gallery, .documents]
 
     init(dcContext: DcContext, contactId: Int) {
         self.context = dcContext
@@ -43,7 +43,7 @@ class ContactDetailViewModel {
         self.chatId = dcContext.getChatIdByContactId(contactId: contactId)
         self.sharedChats = context.getChatlist(flags: 0, queryString: nil, queryId: contactId)
 
-        sections.append(.attachments)
+        sections.append(.chatOptions)
         sections.append(.startChat)
         if sharedChats.length > 0 {
             sections.append(.sharedChats)
@@ -68,8 +68,8 @@ class ContactDetailViewModel {
         return chatActions[row]
     }
 
-    func attachmentActionFor(row: Int) -> ContactDetailViewModel.AttachmentAction {
-        return attachmentActions[row]
+    func attachmentActionFor(row: Int) -> ContactDetailViewModel.ChatOption {
+        return chatOptions[row]
     }
 
     var chatIsArchived: Bool {
@@ -86,7 +86,7 @@ class ContactDetailViewModel {
 
     func numberOfRowsInSection(_ section: Int) -> Int {
         switch sections[section] {
-        case .attachments: return 2
+        case .chatOptions: return chatOptions.count
         case .sharedChats: return sharedChats.length
         case .startChat: return 1
         case .chatActions: return chatActions.count