Fix pdf viewer and plain text file

This commit is contained in:
Benoit Martins 2023-06-27 15:34:00 +02:00
parent 6a8a35bad6
commit 54e772a47f
4 changed files with 94 additions and 59 deletions

View file

@ -70,7 +70,7 @@ extension ChatConversationTableViewSwift {
keyWindow.addSubview(self.floatingScrollBackground!)
keyWindow.addSubview(floatingButton)
keyWindow.trailingAnchor.constraint(equalTo: floatingButton.trailingAnchor, constant: Constants.trailingValue).isActive = true
floatingButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -25).isActive = true
floatingButton.bottomAnchor.constraint(equalTo: keyWindow.bottomAnchor, constant: -25).isActive = true
floatingButton.widthAnchor.constraint(equalToConstant:
Constants.buttonWidth).isActive = true
floatingButton.heightAnchor.constraint(equalToConstant:

View file

@ -217,16 +217,20 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let contentOffsetY = scrollView.contentOffset.y
if contentOffsetY <= 20{
floatingScrollButton?.isHidden = true
floatingScrollBackground?.isHidden = true
scrollBadge?.text = "0"
ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject)
if floatingScrollButton != nil && floatingScrollBackground != nil {
floatingScrollButton?.isHidden = true
floatingScrollBackground?.isHidden = true
scrollBadge?.text = "0"
ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject)
}
} else {
floatingScrollButton?.isHidden = false
floatingScrollBackground?.isHidden = false;
if(scrollBadge?.text == "0"){
scrollBadge?.isHidden = true
}
if floatingScrollButton != nil && floatingScrollBackground != nil {
floatingScrollButton?.isHidden = false
floatingScrollBackground?.isHidden = false;
if(scrollBadge?.text == "0"){
scrollBadge?.isHidden = true
}
}
}
}

View file

@ -1000,7 +1000,9 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
meetingView.isHidden = true
event.chatMessage!.contents.forEach { content in
print("chatMessagecontentschatMessagecontents content.type \(eventMessage?.chatMessage?.contentType)")
if (content.isFileTransfer && content.name != "" && !content.isVoiceRecording) {
print("chatMessagecontentschatMessagecontents 1")
imagesGridCollectionView.append(getImageFrom(content, forReplyBubble: false)!)
collectionViewImagesGrid.reloadData()
@ -1012,6 +1014,7 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
}
if (event.chatMessage?.isOutgoing == true && content.isFileTransfer && event.chatMessage?.isFileTransferInProgress == true && !content.isVoiceRecording) {
print("chatMessagecontentschatMessagecontents 2")
var filePath = ""
if VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) {
filePath = content.exportPlainFile()
@ -1098,8 +1101,8 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
}
}
if content.type == "text"{
//label.text = content.utf8Text.trimmingCharacters(in: .whitespacesAndNewlines)
if content.type == "text" && !content.isFile{
print("chatMessagecontentschatMessagecontents 3 text \(content.isFile)")
if event.chatMessage!.contents.count > 1 {
NSLayoutConstraint.deactivate(labelConstraints)
NSLayoutConstraint.activate(labelTopConstraints)
@ -1107,36 +1110,32 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
NSLayoutConstraint.activate(labelConstraints)
NSLayoutConstraint.deactivate(labelTopConstraints)
}
if imagesGridCollectionView.count == 0 {
if imagesGridCollectionView.count == 0 {
//imagesGridCollectionView.append(nil)
imagesGridCollectionViewNil += 1
}
imagesGridCollectionViewNil += 1
}
label.font = label.font.withSize(17)
if (content.utf8Text.trimmingCharacters(in: .whitespacesAndNewlines).unicodeScalars.first?.properties.isEmojiPresentation == true){
var onlyEmojis = true
content.utf8Text.trimmingCharacters(in: .whitespacesAndNewlines).unicodeScalars.forEach { emoji in
if !emoji.properties.isEmojiPresentation && !emoji.properties.isWhitespace{
onlyEmojis = false
}
}
if onlyEmojis {
label.font = label.font.withSize(51)
}
}
if (content.utf8Text.trimmingCharacters(in: .whitespacesAndNewlines).unicodeScalars.first?.properties.isEmojiPresentation == true){
var onlyEmojis = true
content.utf8Text.trimmingCharacters(in: .whitespacesAndNewlines).unicodeScalars.forEach { emoji in
if !emoji.properties.isEmojiPresentation && !emoji.properties.isWhitespace{
onlyEmojis = false
}
}
if onlyEmojis {
label.font = label.font.withSize(51)
}
}
checkIfIsLinkOrPhoneNumber(content: content.utf8Text)
NSLayoutConstraint.deactivate(labelHiddenConstraints)
label.isHidden = false
}else if content.type == "image"{
print("chatMessagecontentschatMessagecontents 4 image")
if imagesGridCollectionView.count > 1 {
if(content.isFile){
imagesGridCollectionView.append(getImageFrom(content, forReplyBubble: false)!)
@ -1171,6 +1170,7 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
}
}else if content.type == "video"{
print("chatMessagecontentschatMessagecontents 5 video")
if imagesGridCollectionView.count > 1 {
if(content.isFile){
imagesGridCollectionView.append(getImageFrom(content, forReplyBubble: false)!)
@ -1205,6 +1205,7 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
}
}else if content.isVoiceRecording {
print("chatMessagecontentschatMessagecontents 6 recording")
recordingView.subviews.forEach({ view in
view.removeFromSuperview()
})
@ -1213,6 +1214,7 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
messageWithRecording = true
}
}else{
print("chatMessagecontentschatMessagecontents 7 file")
if(content.isFile && !content.isText){
var filePath = ""
if VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) {
@ -1308,9 +1310,35 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
imageViewBubble.image = nil
NSLayoutConstraint.deactivate(imageConstraints)
imageViewBubble.isHidden = true
} else {
var filePathString = VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) ? content.exportPlainFile() : content.filePath
if let urlEncoded = filePathString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
if !urlEncoded.isEmpty {
if let urlFile = URL(string: "file://" + urlEncoded){
do {
let text = try String(contentsOf: urlFile, encoding: .utf8)
print("chatMessagecontentschatMessagecontents filetextfiletext \(text)")
imagesGridCollectionView.append(SwiftUtil.textToImage(drawText: "Error", inImage: UIImage(named: "file_default")!, forReplyBubble: true))
collectionViewImagesGrid.reloadData()
collectionViewImagesGrid.isHidden = false
NSLayoutConstraint.activate(imagesGridConstraints)
imageViewBubble.image = nil
NSLayoutConstraint.deactivate(imageConstraints)
imageViewBubble.isHidden = true
} catch {}
}
}
}
if VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) {
ChatConversationViewModel.sharedModel.removeTmpFile(filePath: filePathString)
filePathString = ""
}
}
}
}}
}
}
if imagesGridCollectionView.count > 0 {
self.collectionViewImagesGrid.layoutIfNeeded()
}

View file

@ -44,6 +44,9 @@ class MediaViewer: BackNextNavigationView, UICompositeViewDelegate, UIScrollVie
var player: AVPlayer? = AVPlayer()
var playerLayer = AVPlayerLayer()
//PDF
let pdfView = PDFView()
override func viewDidLoad() {
super.viewDidLoad(
backAction: {
@ -69,38 +72,14 @@ class MediaViewer: BackNextNavigationView, UICompositeViewDelegate, UIScrollVie
imageViewViewer.removeFromSuperview()
imageScrollView.removeFromSuperview()
playerLayer.removeFromSuperlayer()
pdfView.removeFromSuperview()
if contentType == "image" {
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
}
}
}
displayPDF()
}
}
@ -227,6 +206,30 @@ class MediaViewer: BackNextNavigationView, UICompositeViewDelegate, UIScrollVie
}
}
func displayPDF() {
if let urlEncoded = imagePathViewer.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
if !urlEncoded.isEmpty {
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
pdfView.autoScales = true
if let urlEncoded = imagePathViewer.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
if let path = URL(string: "file://" + urlEncoded) {
if let document = PDFDocument(url: path) {
pdfView.document = document
}
}
}
}
}
}
@objc func videoTapped(){
if let urlEncoded = imagePathViewer.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
if !urlEncoded.isEmpty {