|
@@ -10,6 +10,7 @@ import FMDB
|
|
|
import NexilisLite
|
|
|
import Speech
|
|
|
import QuickLook
|
|
|
+import SDWebImage
|
|
|
|
|
|
class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate, UITextFieldDelegate, UICollectionViewDelegate, UICollectionViewDataSource, QLPreviewControllerDataSource {
|
|
|
var isChooser: ((String, String) -> ())?
|
|
@@ -118,14 +119,17 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
case UNREAD_TAG :
|
|
|
fillteredData = self.chats.filter { $0.counter != "0" }
|
|
|
break
|
|
|
- case PHOTOS_TAG, VIDEOS_TAG :
|
|
|
- fillteredData = Chat.getData(isImage: selectedTag == PHOTOS_TAG, isVideo: selectedTag == VIDEOS_TAG)
|
|
|
+ case PHOTOS_TAG, VIDEOS_TAG, GIFS_TAG :
|
|
|
+ fillteredData = Chat.getData(isImage: selectedTag == PHOTOS_TAG, isVideo: selectedTag == VIDEOS_TAG, isGIF: selectedTag == GIFS_TAG)
|
|
|
if fillteredData.count > 0 {
|
|
|
if gridImage != nil && gridImage.isDescendant(of: self.view) {
|
|
|
gridImage.removeFromSuperview()
|
|
|
}
|
|
|
let width = self.view.frame.width / 3 - 2
|
|
|
- let cellSize = CGSize(width:width, height:width)
|
|
|
+ var cellSize = CGSize(width:width, height:width)
|
|
|
+ if selectedTag == GIFS_TAG {
|
|
|
+ cellSize = CGSize(width:self.view.frame.width / 2 - 2, height:self.view.frame.width / 2 - 62)
|
|
|
+ }
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
|
layout.scrollDirection = .vertical
|
|
|
layout.itemSize = cellSize
|
|
@@ -149,8 +153,6 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
case DOCUMENTS_TAG :
|
|
|
fillteredData = Chat.getData(isDoc: true)
|
|
|
break
|
|
|
- case GIFS_TAG :
|
|
|
- break
|
|
|
case LINKS_TAG :
|
|
|
fillteredData = Chat.getData(isLink: true)
|
|
|
break
|
|
@@ -2090,12 +2092,49 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
let thumb = data.thumb
|
|
|
let imgData = data.image
|
|
|
let vidData = data.video
|
|
|
+ let gifData = data.gif
|
|
|
let image = UIImageView()
|
|
|
- cell.contentView.addSubview(image)
|
|
|
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
|
if let dirPath = paths.first {
|
|
|
+ if selectedTag == GIFS_TAG {
|
|
|
+ let gifURL = URL(fileURLWithPath: dirPath).appendingPathComponent(gifData)
|
|
|
+ if !FileManager.default.fileExists(atPath: gifURL.path) && !FileEncryption.shared.isSecureExists(filename: gifData) {
|
|
|
+ Download().startHTTP(forKey: gifData, isImage: false) { (name, progress) in
|
|
|
+ guard progress == 100 else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ collectionView.reloadItems(at: [indexPath])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let imageGif = SDAnimatedImageView()
|
|
|
+ cell.contentView.addSubview(imageGif)
|
|
|
+ imageGif.contentMode = .scaleAspectFill
|
|
|
+ imageGif.clipsToBounds = true
|
|
|
+ imageGif.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ imageGif.anchor(top: cell.contentView.topAnchor, left: cell.contentView.leftAnchor, bottom: cell.contentView.bottomAnchor, right: cell.contentView.rightAnchor)
|
|
|
+ if FileManager.default.fileExists(atPath: gifURL.path) {
|
|
|
+ imageGif.image = SDAnimatedImage(contentsOfFile: gifURL.path)
|
|
|
+// imageGif.shouldCustomLoopCount = true
|
|
|
+// imageGif.animationRepeatCount = 4
|
|
|
+ } else if FileEncryption.shared.isSecureExists(filename: gifData){
|
|
|
+ do {
|
|
|
+ let data = try FileEncryption.shared.readSecure(filename: gifData)
|
|
|
+ if let imageData = SDAnimatedImage(data: data!) {
|
|
|
+ imageGif.image = imageData
|
|
|
+// imageGif.shouldCustomLoopCount = true
|
|
|
+// imageGif.animationRepeatCount = 4
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch {
|
|
|
+ print("Error reading secure file")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+ cell.contentView.addSubview(image)
|
|
|
let thumbURL = URL(fileURLWithPath: dirPath).appendingPathComponent(thumb)
|
|
|
let imageT : UIImage? = {
|
|
|
if let img = Nexilis.imageCache.object(forKey: thumb as NSString) {
|
|
@@ -2148,6 +2187,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
let data = fillteredData[indexPath.row] as! Chat
|
|
|
let imgData = data.image
|
|
|
let vidData = data.video
|
|
|
+ let gifData = data.gif
|
|
|
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
@@ -2175,7 +2215,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else if selectedTag == VIDEOS_TAG {
|
|
|
let videoURL = URL(fileURLWithPath: dirPath).appendingPathComponent(vidData)
|
|
|
if FileManager.default.fileExists(atPath: videoURL.path) {
|
|
|
APIS.openVideoNexilis(videoURL: videoURL)
|
|
@@ -2200,6 +2240,24 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ let gifURL = URL(fileURLWithPath: dirPath).appendingPathComponent(gifData)
|
|
|
+ if FileManager.default.fileExists(atPath: gifURL.path) {
|
|
|
+ do {
|
|
|
+ let data = try Data(contentsOf: gifURL)
|
|
|
+ APIS.openImageNexilis(image: UIImage(), data: data, isGIF: true)
|
|
|
+ } catch {
|
|
|
+
|
|
|
+ }
|
|
|
+ } else if FileEncryption.shared.isSecureExists(filename: gifData) {
|
|
|
+ do {
|
|
|
+ if let secureData = try FileEncryption.shared.readSecure(filename: gifData) {
|
|
|
+ APIS.openImageNexilis(image: UIImage(), data: secureData, isGIF: true)
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|