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

Merge pull request #110 from deltachat/PhotoSwipe

[ChatView] - tap Image Gallery
nayooti 6 жил өмнө
parent
commit
a99c019fe7

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

@@ -43,6 +43,7 @@
 		AE25F09022807AD800CDEA66 /* GroupNameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */; };
 		AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B31722672DFC00EC37A1 /* ActionCell.swift */; };
 		AE38B31A2267328200EC37A1 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B3192267328200EC37A1 /* Colors.swift */; };
+		AE4AEE3522B1030D000AA495 /* PreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE4AEE3422B1030D000AA495 /* PreviewController.swift */; };
 		AE52EA19229EB53C00C586C9 /* ContactDetailHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */; };
 		AE52EA20229EB9F000C586C9 /* EditGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */; };
 		AE728F15229D5C390047565B /* PhotoPickerAlertAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE728F14229D5C390047565B /* PhotoPickerAlertAction.swift */; };
@@ -122,6 +123,7 @@
 		AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupNameCell.swift; sourceTree = "<group>"; };
 		AE38B31722672DFC00EC37A1 /* ActionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCell.swift; sourceTree = "<group>"; };
 		AE38B3192267328200EC37A1 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
+		AE4AEE3422B1030D000AA495 /* PreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewController.swift; sourceTree = "<group>"; };
 		AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactDetailHeader.swift; sourceTree = "<group>"; };
 		AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditGroupViewController.swift; sourceTree = "<group>"; };
 		AE728F14229D5C390047565B /* PhotoPickerAlertAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPickerAlertAction.swift; sourceTree = "<group>"; };
@@ -293,6 +295,7 @@
 				AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */,
 				AEE6EC472283045D00EDC689 /* EditSettingsController.swift */,
 				AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */,
+				AE4AEE3422B1030D000AA495 /* PreviewController.swift */,
 			);
 			path = Controller;
 			sourceTree = "<group>";
@@ -614,6 +617,7 @@
 				78ED839421D5AF8A00243125 /* QrCodeView.swift in Sources */,
 				AE851AC9227C77CF00ED86F0 /* Media.swift in Sources */,
 				AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */,
+				AE4AEE3522B1030D000AA495 /* PreviewController.swift in Sources */,
 				7070FB9B2101ECBB000DC258 /* GroupNameController.swift in Sources */,
 				AE52EA19229EB53C00C586C9 /* ContactDetailHeader.swift in Sources */,
 				78E45E4421D3F14A00D4B15E /* UIImage+Extension.swift in Sources */,

+ 25 - 20
deltachat-ios/Controller/ChatViewController.swift

@@ -790,7 +790,31 @@ extension ChatViewController: MessageCellDelegate {
 			let message = messageList[indexPath.section]
 
 			if let url = message.fileURL {
-				previewController = PreviewController(urls: [url])
+				// find all other messages with same message type
+				var previousUrls: [URL] = []
+				var nextUrls: [URL] = []
+
+				var prev: Int = Int(dc_get_next_media(mailboxPointer, UInt32(message.id), -1, Int32(message.type), 0, 0))
+				while prev != 0 {
+					let prevMessage = MRMessage(id: prev)
+					if let url = prevMessage.fileURL {
+						previousUrls.insert(url, at: 0)
+					}
+					prev = Int(dc_get_next_media(mailboxPointer, UInt32(prevMessage.id), -1, Int32(prevMessage.type), 0, 0))
+				}
+
+				var next: Int = Int(dc_get_next_media(mailboxPointer, UInt32(message.id), 1, Int32(message.type), 0, 0))
+				while next != 0 {
+					let nextMessage = MRMessage(id: next)
+					if let url = nextMessage.fileURL {
+						nextUrls.insert(url, at: 0)
+					}
+					next = Int(dc_get_next_media(mailboxPointer, UInt32(nextMessage.id), 1, Int32(nextMessage.type), 0, 0))
+				}
+
+				let mediaUrls: [URL] = previousUrls + [url] + nextUrls
+
+				previewController = PreviewController(currentIndex: previousUrls.count, urls: mediaUrls)
 				present(previewController!.qlController, animated: true)
 			}
 		}
@@ -809,25 +833,6 @@ extension ChatViewController: MessageCellDelegate {
 	}
 }
 
-class PreviewController: QLPreviewControllerDataSource {
-	var urls: [URL]
-	var qlController: QLPreviewController
-
-	init(urls: [URL]) {
-		self.urls = urls
-		qlController = QLPreviewController()
-		qlController.dataSource = self
-	}
-
-	func numberOfPreviewItems(in _: QLPreviewController) -> Int {
-		return urls.count
-	}
-
-	func previewController(_: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
-		return urls[index] as QLPreviewItem
-	}
-}
-
 // MARK: - MessageLabelDelegate
 extension ChatViewController: MessageLabelDelegate {
 	func didSelectAddress(_ addressComponents: [String: String]) {

+ 30 - 0
deltachat-ios/Controller/PreviewController.swift

@@ -0,0 +1,30 @@
+//
+//  PreviewController.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 12.06.19.
+//  Copyright © 2019 Jonas Reinsch. All rights reserved.
+//
+
+import QuickLook
+import UIKit
+
+class PreviewController: QLPreviewControllerDataSource {
+	var urls: [URL]
+	var qlController: QLPreviewController
+
+	init(currentIndex: Int, urls: [URL]) {
+		self.urls = urls
+		qlController = QLPreviewController()
+		qlController.dataSource = self
+		qlController.currentPreviewItemIndex = currentIndex
+	}
+
+	func numberOfPreviewItems(in _: QLPreviewController) -> Int {
+		return urls.count
+	}
+
+	func previewController(_: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
+		return urls[index] as QLPreviewItem
+	}
+}

+ 7 - 0
deltachat-ios/Helper/Extensions.swift

@@ -186,3 +186,10 @@ extension UIImage {
 		return UIImage(data: imageData!)
 	}
 }
+
+extension UIView {
+	func makeBorder(color: UIColor = UIColor.red) {
+		self.layer.borderColor = color.cgColor
+		self.layer.borderWidth = 2
+	}
+}