Przeglądaj źródła

first implementation basic gallery (docs/audio, images/gif/video)

cyberta 5 lat temu
rodzic
commit
06aa51e5cd

+ 25 - 4
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -3,11 +3,14 @@ import UIKit
 class GroupChatDetailViewController: UIViewController {
 
     enum ProfileSections {
+        case attachments
         case memberManagement // add member, qr invideCode
         case members // contactCells
         case chatActions // archive, leave, delete
     }
 
+    private let attachmentsRowGallery = 0
+    private let attachmentsRowDocuments = 1
     private let memberManagementRowAddMembers = 0
     private let memberManagementRowQrInvite = 1
     private let chatActionsRowArchiveChat = 0
@@ -17,7 +20,7 @@ class GroupChatDetailViewController: UIViewController {
     private let context: DcContext
     weak var coordinator: GroupChatDetailCoordinator?
 
-    private let sections: [ProfileSections] = [.memberManagement, .members, .chatActions]
+    private let sections: [ProfileSections] = [.attachments, .memberManagement, .members, .chatActions]
 
     private var currentUser: DcContact? {
         let myId = groupMemberIds.filter { DcContact(id: $0).email == DcConfig.addr }.first
@@ -168,6 +171,8 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
     func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
         let sectionType = sections[section]
         switch sectionType {
+        case .attachments:
+            return 2
         case .memberManagement:
             return 2
         case .members:
@@ -180,12 +185,10 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
         let sectionType = sections[indexPath.section]
         switch sectionType {
-        case .memberManagement:
+        case .attachments, .memberManagement, .chatActions:
             return Constants.defaultCellHeight
         case .members:
             return ContactCell.cellHeight
-        case .chatActions:
-            return Constants.defaultCellHeight
         }
     }
 
@@ -193,6 +196,18 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let row = indexPath.row
         let sectionType = sections[indexPath.section]
         switch sectionType {
+        case .attachments:
+            guard let actionCell = tableView.dequeueReusableCell(withIdentifier: "actionCell", for: indexPath) as? ActionCell else {
+                safe_fatalError("could not dequeue action cell")
+                break
+            }
+            if row == attachmentsRowGallery {
+                actionCell.actionTitle = String.localized("gallery")
+                actionCell.actionColor = UIColor.systemBlue
+            } else if row == attachmentsRowDocuments {
+                actionCell.actionTitle = String.localized("documents")
+                actionCell.actionColor = UIColor.systemBlue
+            }
         case .memberManagement:
             guard let actionCell = tableView.dequeueReusableCell(withIdentifier: "actionCell", for: indexPath) as? ActionCell else {
                 safe_fatalError("could not dequeu action cell")
@@ -235,6 +250,12 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let row = indexPath.row
 
         switch sectionType {
+        case .attachments:
+            if row == attachmentsRowGallery {
+                coordinator?.showGallery(chatId: chat.id)
+            } else if row == attachmentsRowDocuments {
+                coordinator?.showDocuments(chatId: chat.id)
+            }
         case .memberManagement:
             if row == memberManagementRowAddMembers {
                 coordinator?.showAddGroupMember(chatId: chat.id)

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

@@ -394,6 +394,35 @@ class GroupChatDetailCoordinator: Coordinator {
         navigationController.pushViewController(contactDetailController, animated: true)
     }
 
+    func showDocuments(chatId: Int) {
+        let messageIds = dcContext.getChatMedia(chatId: chatId, messageType: DC_MSG_FILE, messageType2: DC_MSG_AUDIO, messageType3: 0)
+        var mediaUrls: [URL] = []
+        for messageId in messageIds {
+            let message = DcMsg.init(id: messageId)
+            if let url = message.fileURL {
+                logger.debug("add file url: \(url.absoluteString)")
+                mediaUrls.insert(url, at: 0)
+            }
+        }
+        // these are the files user will be able to swipe trough
+        let previewController = PreviewController(currentIndex: 0, urls: mediaUrls)
+        navigationController.present(previewController.qlController, animated: true, completion: nil)
+    }
+
+    func showGallery(chatId: Int) {
+        let messageIds = dcContext.getChatMedia(chatId: chatId, messageType: DC_MSG_GIF, messageType2: DC_MSG_IMAGE, messageType3: DC_MSG_VIDEO)
+        var mediaUrls: [URL] = []
+        for messageId in messageIds {
+            let message = DcMsg.init(id: messageId)
+            if let url = message.fileURL {
+                mediaUrls.insert(url, at: 0)
+            }
+        }
+        // these are the files user will be able to swipe trough
+        let previewController = PreviewController(currentIndex: 0, urls: mediaUrls)
+        navigationController.present(previewController.qlController, animated: true, completion: nil)
+    }
+
     func deleteChat() {
         /*
         app will navigate to chatlist or archive and delete the chat there