mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
Add pdf viewer
This commit is contained in:
parent
cdca235f39
commit
6a8a35bad6
2 changed files with 50 additions and 15 deletions
|
|
@ -603,25 +603,30 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
Log.i("Messsage not delivered")
|
||||
} else {
|
||||
if (VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) || ConfigManager.instance().lpConfigBoolForKey(key: "use_in_app_file_viewer_for_non_encrypted_files", section: "app")){
|
||||
let view: ImageView = VIEW(ImageView.compositeViewDescription())
|
||||
var viewer: MediaViewer = VIEW(MediaViewer.compositeViewDescription())
|
||||
|
||||
var image = UIImage()
|
||||
if chatMessage!.contents[index].type == "image" {
|
||||
if VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) {
|
||||
var plainFile = chatMessage!.contents[index].exportPlainFile()
|
||||
|
||||
image = UIImage(contentsOfFile: plainFile)!
|
||||
|
||||
ChatConversationViewModel.sharedModel.removeTmpFile(filePath: plainFile)
|
||||
plainFile = ""
|
||||
|
||||
}else {
|
||||
image = UIImage(contentsOfFile: chatMessage!.contents[index].filePath)!
|
||||
if chatMessage != nil {
|
||||
if chatMessage!.contents[index].type == "image" {
|
||||
if VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) {
|
||||
var plainFile = chatMessage!.contents[index].exportPlainFile()
|
||||
|
||||
image = UIImage(contentsOfFile: plainFile)!
|
||||
|
||||
ChatConversationViewModel.sharedModel.removeTmpFile(filePath: plainFile)
|
||||
plainFile = ""
|
||||
|
||||
}else {
|
||||
image = UIImage(contentsOfFile: chatMessage!.contents[index].filePath)!
|
||||
}
|
||||
}
|
||||
|
||||
viewer.imageViewer = image
|
||||
viewer.imageNameViewer = chatMessage!.contents[index].name.isEmpty ? "" : chatMessage!.contents[index].name
|
||||
viewer.imagePathViewer = chatMessage!.contents[index].exportPlainFile()
|
||||
viewer.contentType = chatMessage!.contents[index].type
|
||||
PhoneMainView.instance().changeCurrentView(viewer.compositeViewDescription())
|
||||
}
|
||||
|
||||
PhoneMainView.instance().changeCurrentView(view.compositeViewDescription())
|
||||
view.image = image
|
||||
} else {
|
||||
let previewController = QLPreviewController()
|
||||
self.previewItems = []
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
import Foundation
|
||||
import AVFoundation
|
||||
import AVKit
|
||||
import PDFKit
|
||||
|
||||
class MediaViewer: BackNextNavigationView, UICompositeViewDelegate, UIScrollViewDelegate, QLPreviewControllerDelegate, QLPreviewControllerDataSource {
|
||||
|
||||
|
|
@ -72,6 +73,35 @@ class MediaViewer: BackNextNavigationView, UICompositeViewDelegate, UIScrollVie
|
|||
setUpImageView()
|
||||
} else if contentType == "video" {
|
||||
setUpPlayerContainerView()
|
||||
} else if contentType == "file" {
|
||||
if imageNameViewer.lowercased().components(separatedBy: ".").last == "pdf" {
|
||||
/*
|
||||
let pdfView = PDFView()
|
||||
|
||||
//pdfView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(pdfView)
|
||||
pdfView.backgroundColor = .red
|
||||
pdfView.frame = CGRectMake(0, 0, UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height-20)
|
||||
*/
|
||||
|
||||
let pdfView = PDFView()
|
||||
|
||||
pdfView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(pdfView)
|
||||
|
||||
pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
|
||||
pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
|
||||
pdfView.topAnchor.constraint(equalTo: super.topBar.bottomAnchor).isActive = true
|
||||
pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
|
||||
|
||||
if let urlEncoded = imagePathViewer.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
|
||||
if let urlPDF = URL(string: urlEncoded){
|
||||
if let document = PDFDocument(url: urlPDF) {
|
||||
pdfView.document = document
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try! AVAudioSession.sharedInstance().setActive(true)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue