forked from mirrors/linphone-iphone
Fix TextViewer and add popup for other file types
This commit is contained in:
parent
54e772a47f
commit
9bdd7f65fe
7 changed files with 91 additions and 27 deletions
|
|
@ -323,6 +323,7 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
LpConfig *conf = LinphoneManager.instance.configDb;
|
||||
char *config = linphone_config_dump(conf);
|
||||
view.textViewer = [NSString stringWithUTF8String: config];
|
||||
view.textNameViewer = @"";
|
||||
[PhoneMainView.instance popToView:view.compositeViewDescription];
|
||||
}];
|
||||
|
||||
|
|
|
|||
|
|
@ -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: keyWindow.bottomAnchor, constant: -25).isActive = true
|
||||
floatingButton.bottomAnchor.constraint(equalTo: keyWindow.bottomAnchor, constant: -(25 + 66)).isActive = true
|
||||
floatingButton.widthAnchor.constraint(equalToConstant:
|
||||
Constants.buttonWidth).isActive = true
|
||||
floatingButton.heightAnchor.constraint(equalToConstant:
|
||||
|
|
|
|||
|
|
@ -607,30 +607,93 @@ 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")){
|
||||
var viewer: MediaViewer = VIEW(MediaViewer.compositeViewDescription())
|
||||
|
||||
var image = UIImage()
|
||||
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)!
|
||||
var text = ""
|
||||
var filePathString = VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) ? chatMessage!.contents[index].exportPlainFile() : chatMessage!.contents[index].filePath
|
||||
if let urlEncoded = filePathString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
|
||||
if !urlEncoded.isEmpty {
|
||||
if let urlFile = URL(string: "file://" + urlEncoded){
|
||||
do {
|
||||
text = try String(contentsOf: urlFile, encoding: .utf8)
|
||||
let viewer: TextViewer = VIEW(TextViewer.compositeViewDescription())
|
||||
|
||||
if chatMessage != nil {
|
||||
|
||||
viewer.textViewer = text
|
||||
viewer.textNameViewer = chatMessage!.contents[index].name.isEmpty ? "" : chatMessage!.contents[index].name
|
||||
PhoneMainView.instance().changeCurrentView(viewer.compositeViewDescription())
|
||||
}
|
||||
|
||||
} catch {
|
||||
if text == "" && (chatMessage!.contents[index].type == "image" || chatMessage!.contents[index].type == "video" || chatMessage!.contents[index].name.lowercased().components(separatedBy: ".").last == "pdf"){
|
||||
let viewer: MediaViewer = VIEW(MediaViewer.compositeViewDescription())
|
||||
|
||||
var image = UIImage()
|
||||
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())
|
||||
}
|
||||
} else {
|
||||
let exportView = UIAlertController(
|
||||
title: VoipTexts.chat_message_cant_open_file_in_app_dialog_title,
|
||||
message: VoipTexts.chat_message_cant_open_file_in_app_dialog_message,
|
||||
preferredStyle: .alert)
|
||||
|
||||
let cancelAction = UIAlertAction(
|
||||
title: VoipTexts.cancel,
|
||||
style: .default,
|
||||
handler: { action in
|
||||
})
|
||||
|
||||
let exportAction = UIAlertAction(
|
||||
title: VoipTexts.chat_message_cant_open_file_in_app_dialog_export_button,
|
||||
style: .destructive,
|
||||
handler: { action in
|
||||
let previewController = QLPreviewController()
|
||||
self.previewItems = []
|
||||
|
||||
self.previewItems.append(self.getPreviewItem(filePath: filePathString))
|
||||
|
||||
|
||||
self.afterPreviewIndex = indexMessage
|
||||
|
||||
previewController.dataSource = self
|
||||
previewController.currentPreviewItemIndex = index
|
||||
previewController.delegate = self
|
||||
PhoneMainView.instance().mainViewController.present(previewController, animated: true, completion: nil)
|
||||
})
|
||||
|
||||
exportView.addAction(cancelAction)
|
||||
exportView.addAction(exportAction)
|
||||
PhoneMainView.instance()!.present(exportView, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
/*
|
||||
if VFSUtil.vfsEnabled(groupName: kLinphoneMsgNotificationAppGroupId) {
|
||||
ChatConversationViewModel.sharedModel.removeTmpFile(filePath: filePathString)
|
||||
filePathString = ""
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
let previewController = QLPreviewController()
|
||||
self.previewItems = []
|
||||
|
|
|
|||
|
|
@ -1317,8 +1317,6 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
|
|||
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()
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class TextViewer: BackNextNavigationView, UICompositeViewDelegate {
|
|||
func compositeViewDescription() -> UICompositeViewDescription! { return type(of: self).compositeDescription }
|
||||
|
||||
@objc var textViewer = ""
|
||||
@objc var textNameViewer = ""
|
||||
let textViewViewer = UITextView()
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
|
@ -60,21 +61,18 @@ class TextViewer: BackNextNavigationView, UICompositeViewDelegate {
|
|||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
textViewViewer.text = textViewer
|
||||
titleLabel.text = textNameViewer
|
||||
}
|
||||
|
||||
@objc func shareMediaButton(_ sender: UIButton) {
|
||||
// text to share
|
||||
let text = textViewer
|
||||
|
||||
// set up activity view controller
|
||||
let textToShare = [ text ]
|
||||
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
|
||||
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
|
||||
|
||||
// exclude some activity types from the list (optional)
|
||||
activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop, UIActivity.ActivityType.postToFacebook ]
|
||||
|
||||
// present the view controller
|
||||
self.present(activityViewController, animated: true, completion: nil)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,6 +214,10 @@ import UIKit
|
|||
@objc static let chat_room_presence_last_seen_online = NSLocalizedString("Online on ",comment:"")
|
||||
@objc static let chat_room_presence_away = NSLocalizedString("Away",comment:"")
|
||||
|
||||
@objc static let chat_message_cant_open_file_in_app_dialog_title = NSLocalizedString("It seems we can't display the file",comment:"")
|
||||
@objc static let chat_message_cant_open_file_in_app_dialog_message = NSLocalizedString("Would you like to open it as text or export it (unencrypted) to a third party app if available?",comment:"")
|
||||
@objc static let chat_message_cant_open_file_in_app_dialog_export_button = NSLocalizedString("Export",comment:"")
|
||||
|
||||
// FROM ANDROID END
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue