From d439520e1ff67a374407e3988a522444611c8d01 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 15 Jun 2023 15:28:39 +0200 Subject: [PATCH] Fix Index out of range for imagesGridCollectionView --- .../Chat/Views/MultilineMessageCell.swift | 175 +++++++++--------- linphone.xcodeproj/project.pbxproj | 16 +- 2 files changed, 97 insertions(+), 94 deletions(-) diff --git a/Classes/Swift/Chat/Views/MultilineMessageCell.swift b/Classes/Swift/Chat/Views/MultilineMessageCell.swift index c40cb72a7..8c75eda91 100644 --- a/Classes/Swift/Chat/Views/MultilineMessageCell.swift +++ b/Classes/Swift/Chat/Views/MultilineMessageCell.swift @@ -1676,51 +1676,70 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource, let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellImagesGridMessage", for: indexPath) let indexPathWithoutNil = indexPath.row + imagesGridCollectionViewNil let indexPathWithoutNilWithRecording = indexPathWithoutNil + (messageWithRecording ? 1 : 0) - if ((indexPathWithoutNil <= imagesGridCollectionView.count - 1) && (imagesGridCollectionView[indexPathWithoutNil] != nil) && (chatMessage?.contents[indexPathWithoutNilWithRecording].isFile == true || chatMessage?.contents[indexPathWithoutNilWithRecording].isFileTransfer == true)) { - let viewCell: UIView = UIView(frame: cell.contentView.frame) - cell.addSubview(viewCell) - if (chatMessage?.isOutgoing == false && (chatMessage?.contents[indexPathWithoutNilWithRecording].filePath == "" || chatMessage?.contents[indexPathWithoutNilWithRecording].isFileTransfer == true)) { - let downloadView = DownloadMessageCell() - downloadContentCollection.append(downloadView) - downloadView.content = chatMessage?.contents[indexPathWithoutNilWithRecording] - downloadView.size(w: 138, h: 138).done() - viewCell.addSubview(downloadView) + if (imagesGridCollectionView.indices.contains(indexPathWithoutNil) == true && chatMessage?.contents.indices.contains(indexPathWithoutNilWithRecording) == true){ + if ((indexPathWithoutNil <= imagesGridCollectionView.count - 1) && (imagesGridCollectionView[indexPathWithoutNil] != nil) && (chatMessage?.contents[indexPathWithoutNilWithRecording].isFile == true || chatMessage?.contents[indexPathWithoutNilWithRecording].isFileTransfer == true)) { + let viewCell: UIView = UIView(frame: cell.contentView.frame) + cell.addSubview(viewCell) + if (chatMessage?.isOutgoing == false && (chatMessage?.contents[indexPathWithoutNilWithRecording].filePath == "" || chatMessage?.contents[indexPathWithoutNilWithRecording].isFileTransfer == true)) { + let downloadView = DownloadMessageCell() + downloadContentCollection.append(downloadView) + downloadView.content = chatMessage?.contents[indexPathWithoutNilWithRecording] + downloadView.size(w: 138, h: 138).done() + viewCell.addSubview(downloadView) - downloadView.downloadNameLabel.text = chatMessage?.contents[indexPathWithoutNilWithRecording].name.replacingOccurrences(of: ((chatMessage?.contents[indexPathWithoutNilWithRecording].name.dropFirst(6).dropLast(8))!), with: "...") - downloadView.setFileType(fileName: (chatMessage?.contents[indexPathWithoutNilWithRecording].name)!) - - let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.thick.rawValue] - let underlineAttributedString = NSAttributedString(string: "\(VoipTexts.bubble_chat_download_file) (\(String(format: "%.1f", Float(((chatMessage?.contents[indexPathWithoutNilWithRecording].fileSize)!)) / 1000000)) Mo)", attributes: underlineAttribute) - downloadView.downloadButtonLabel.attributedText = underlineAttributedString - downloadView.downloadButtonLabel.onClick { - self.chatMessage?.contents[indexPathWithoutNilWithRecording].filePath = LinphoneManager.imagesDirectory() + (((self.chatMessage?.contents[indexPathWithoutNilWithRecording].name)!)) - let _ = self.chatMessage!.downloadContent(content: (self.chatMessage?.contents[indexPathWithoutNilWithRecording])!) - } - downloadView.downloadButtonLabel.isUserInteractionEnabled = true - - if((linphone_core_get_max_size_for_auto_download_incoming_files(LinphoneManager.getLc()) > -1 && self.chatMessage!.isFileTransferInProgress) || self.chatMessage!.isOutgoing){ - downloadView.downloadButtonLabel.isHidden = true - } - } else if imagesGridCollectionView[indexPathWithoutNil] != nil { - downloadContentCollection.append(nil) - - let myImageView = UIImageView() - - - myImageView.image = getImageFrom(chatMessage?.contents[indexPathWithoutNilWithRecording], forReplyBubble: false) - - myImageView.size(w: (viewCell.frame.width), h: (viewCell.frame.height)).done() - viewCell.addSubview(myImageView) - - myImageView.contentMode = .scaleAspectFill - myImageView.clipsToBounds = true - - if (chatMessage?.isOutgoing == true && (chatMessage?.contents[indexPathWithoutNilWithRecording].filePath == "" || chatMessage?.isFileTransferInProgress == true)){ - let uploadView = UploadMessageCell() - uploadContentCollection.append(uploadView) - uploadView.content = chatMessage?.contents[indexPathWithoutNilWithRecording] - uploadView.size(w: 138, h: 138).done() + downloadView.downloadNameLabel.text = chatMessage?.contents[indexPathWithoutNilWithRecording].name.replacingOccurrences(of: ((chatMessage?.contents[indexPathWithoutNilWithRecording].name.dropFirst(6).dropLast(8))!), with: "...") + downloadView.setFileType(fileName: (chatMessage?.contents[indexPathWithoutNilWithRecording].name)!) + let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.thick.rawValue] + let underlineAttributedString = NSAttributedString(string: "\(VoipTexts.bubble_chat_download_file) (\(String(format: "%.1f", Float(((chatMessage?.contents[indexPathWithoutNilWithRecording].fileSize)!)) / 1000000)) Mo)", attributes: underlineAttribute) + downloadView.downloadButtonLabel.attributedText = underlineAttributedString + downloadView.downloadButtonLabel.onClick { + self.chatMessage?.contents[indexPathWithoutNilWithRecording].filePath = LinphoneManager.imagesDirectory() + (((self.chatMessage?.contents[indexPathWithoutNilWithRecording].name)!)) + let _ = self.chatMessage!.downloadContent(content: (self.chatMessage?.contents[indexPathWithoutNilWithRecording])!) + } + downloadView.downloadButtonLabel.isUserInteractionEnabled = true + + if((linphone_core_get_max_size_for_auto_download_incoming_files(LinphoneManager.getLc()) > -1 && self.chatMessage!.isFileTransferInProgress) || self.chatMessage!.isOutgoing){ + downloadView.downloadButtonLabel.isHidden = true + } + } else if imagesGridCollectionView[indexPathWithoutNil] != nil { + downloadContentCollection.append(nil) + + let myImageView = UIImageView() + + + myImageView.image = getImageFrom(chatMessage?.contents[indexPathWithoutNilWithRecording], forReplyBubble: false) + + myImageView.size(w: (viewCell.frame.width), h: (viewCell.frame.height)).done() + viewCell.addSubview(myImageView) + + myImageView.contentMode = .scaleAspectFill + myImageView.clipsToBounds = true + + if (chatMessage?.isOutgoing == true && (chatMessage?.contents[indexPathWithoutNilWithRecording].filePath == "" || chatMessage?.isFileTransferInProgress == true)){ + let uploadView = UploadMessageCell() + uploadContentCollection.append(uploadView) + uploadView.content = chatMessage?.contents[indexPathWithoutNilWithRecording] + uploadView.size(w: 138, h: 138).done() + + if(chatMessage?.contents[indexPathWithoutNilWithRecording].type == "video"){ + var imagePlay = UIImage() + if #available(iOS 13.0, *) { + imagePlay = (UIImage(named: "vr_play")!.withTintColor(.white)) + } else { + imagePlay = UIImage(named: "vr_play")! + } + let myImagePlayView = UIImageView(image: imagePlay) + viewCell.addSubview(myImagePlayView) + myImagePlayView.size(w: viewCell.frame.width/4, h: viewCell.frame.height/4).done() + myImagePlayView.alignHorizontalCenterWith(viewCell).alignVerticalCenterWith(viewCell).done() + } + + viewCell.addSubview(uploadView) + + } + } + if(imagesGridCollectionView[indexPathWithoutNil] != nil){ if(chatMessage?.contents[indexPathWithoutNilWithRecording].type == "video"){ var imagePlay = UIImage() if #available(iOS 13.0, *) { @@ -1733,32 +1752,14 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource, myImagePlayView.size(w: viewCell.frame.width/4, h: viewCell.frame.height/4).done() myImagePlayView.alignHorizontalCenterWith(viewCell).alignVerticalCenterWith(viewCell).done() } - - viewCell.addSubview(uploadView) - - } - } - if(imagesGridCollectionView[indexPathWithoutNil] != nil){ - if(chatMessage?.contents[indexPathWithoutNilWithRecording].type == "video"){ - var imagePlay = UIImage() - if #available(iOS 13.0, *) { - imagePlay = (UIImage(named: "vr_play")!.withTintColor(.white)) - } else { - imagePlay = UIImage(named: "vr_play")! - } - let myImagePlayView = UIImageView(image: imagePlay) - viewCell.addSubview(myImagePlayView) - myImagePlayView.size(w: viewCell.frame.width/4, h: viewCell.frame.height/4).done() - myImagePlayView.alignHorizontalCenterWith(viewCell).alignVerticalCenterWith(viewCell).done() - } - if chatMessage?.contents[indexPathWithoutNilWithRecording].filePath != "" { - viewCell.onClick { - ChatConversationTableViewModel.sharedModel.onGridClick(indexMessage: self.selfIndexMessage, index: indexPathWithoutNil) + if chatMessage?.contents[indexPathWithoutNilWithRecording].filePath != "" { + viewCell.onClick { + ChatConversationTableViewModel.sharedModel.onGridClick(indexMessage: self.selfIndexMessage, index: indexPathWithoutNil) + } } } } } - return cell } } @@ -2008,29 +2009,31 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource, } } DispatchQueue.main.async(execute: { [self] in - if (offset == total) { - if(indexUploadTransferProgress >= 0){ - uploadContentCollection[indexUploadTransferProgress]!.circularProgressBarView.isHidden = true - } - if indexUploadTransferProgress <= (imagesGridCollectionView.count) + (messageWithRecording ? 1 : 0) { - indexUploadTransferProgress += 1 - }else{ - indexUploadTransferProgress = -1 - DispatchQueue.main.asyncAfter(deadline: .now() + 1) { - ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() + if uploadContentCollection.indices.contains(indexUploadTransferProgress){ + if (offset == total) { + if(indexUploadTransferProgress >= 0){ + uploadContentCollection[indexUploadTransferProgress]!.circularProgressBarView.isHidden = true + } + if indexUploadTransferProgress <= (imagesGridCollectionView.count) + (messageWithRecording ? 1 : 0) { + indexUploadTransferProgress += 1 + }else{ + indexUploadTransferProgress = -1 + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() + } + } + } else { + if((imagesGridCollectionView.count) > 0 && indexUploadTransferProgress > -1){ + uploadContentCollection[indexUploadTransferProgress]!.circularProgressBarView.isHidden = false + uploadContentCollection[indexUploadTransferProgress]!.setUpCircularProgressBarView(toValue: p) + } + if (indexUploadTransferProgress == -1 && imagesGridCollectionView.count == 1 && messageWithRecording){ + indexUploadTransferProgress = 0 + uploadContentCollection[indexUploadTransferProgress]!.circularProgressBarView.isHidden = false + uploadContentCollection[indexUploadTransferProgress]!.setUpCircularProgressBarView(toValue: p) } } - } else { - if((imagesGridCollectionView.count) > 0 && indexUploadTransferProgress > -1){ - uploadContentCollection[indexUploadTransferProgress]!.circularProgressBarView.isHidden = false - uploadContentCollection[indexUploadTransferProgress]!.setUpCircularProgressBarView(toValue: p) - } - if (indexUploadTransferProgress == -1 && imagesGridCollectionView.count == 1 && messageWithRecording){ - indexUploadTransferProgress = 0 - uploadContentCollection[indexUploadTransferProgress]!.circularProgressBarView.isHidden = false - uploadContentCollection[indexUploadTransferProgress]!.setUpCircularProgressBarView(toValue: p) - } - } + } }) } if((imagesGridCollectionView.count) == 1){ diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 1afd9f00e..c04b431ef 100644 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -605,7 +605,7 @@ 63E27A321C4FECD000D332AE /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 63E27A311C4FECD000D332AE /* LaunchScreen.xib */; }; 63E27A521C50EDB000D332AE /* hold.mkv in Resources */ = {isa = PBXBuildFile; fileRef = 63E27A511C50EB2700D332AE /* hold.mkv */; }; 63E59A3F1ADE70D900646FB3 /* InAppProductsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */; }; - 63E802DB1C625AEF000D5509 /* (null) in Resources */ = {isa = PBXBuildFile; }; + 63E802DB1C625AEF000D5509 /* BuildFile in Resources */ = {isa = PBXBuildFile; }; 63EC8D391D7438660066547B /* AssistantLinkView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 63EC8D3B1D7438660066547B /* AssistantLinkView.xib */; }; 63F1DF441BCE618E00EDED90 /* UIAddressTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F1DF431BCE618E00EDED90 /* UIAddressTextField.m */; }; 63FB30351A680E73008CA393 /* UIRoundedImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 63FB30341A680E73008CA393 /* UIRoundedImageView.m */; }; @@ -2591,7 +2591,7 @@ path = LinphoneUI; sourceTree = ""; }; - 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { + 29B97314FDCFA39411CA2CEA = { isa = PBXGroup; children = ( 8C23BCB71D82AAC3005F19BB /* linphone.entitlements */, @@ -4075,7 +4075,7 @@ fr, hu, ); - mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; + mainGroup = 29B97314FDCFA39411CA2CEA; productRefGroup = 19C28FACFE9D520D11CA2CBB /* Products */; projectDirPath = ""; projectRoot = ""; @@ -4147,7 +4147,7 @@ 633FEEE01D3CD55A0014B822 /* numpad_8_over~ipad@2x.png in Resources */, 633FEDDC1D3CD5590014B822 /* call_start_body_disabled~ipad.png in Resources */, C63F72FF285A31DA0066163B /* Roboto-Bold.ttf in Resources */, - 63E802DB1C625AEF000D5509 /* (null) in Resources */, + 63E802DB1C625AEF000D5509 /* BuildFile in Resources */, 633FEE2E1D3CD5590014B822 /* color_F.png in Resources */, 633FEDC51D3CD5590014B822 /* call_hangup_disabled@2x.png in Resources */, 633FEEDF1D3CD55A0014B822 /* numpad_8_over~ipad.png in Resources */, @@ -5818,7 +5818,7 @@ "-DENABLE_QRCODE=TRUE", "-DENABLE_SMS_INVITE=TRUE", "$(inherited)", - "-DLINPHONE_SDK_VERSION=\\\"5.2.68-pre.2+b096e8a01\\\"", + "-DLINPHONE_SDK_VERSION=\\\"5.2.70\\\"", ); OTHER_SWIFT_FLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = org.linphone.phone; @@ -5944,7 +5944,7 @@ "-DENABLE_QRCODE=TRUE", "-DENABLE_SMS_INVITE=TRUE", "$(inherited)", - "-DLINPHONE_SDK_VERSION=\\\"5.2.68-pre.2+b096e8a01\\\"", + "-DLINPHONE_SDK_VERSION=\\\"5.2.70\\\"", ); OTHER_SWIFT_FLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = org.linphone.phone; @@ -6069,7 +6069,7 @@ "-DENABLE_QRCODE=TRUE", "-DENABLE_SMS_INVITE=TRUE", "$(inherited)", - "-DLINPHONE_SDK_VERSION=\\\"5.2.68-pre.2+b096e8a01\\\"", + "-DLINPHONE_SDK_VERSION=\\\"5.2.70\\\"", ); OTHER_SWIFT_FLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = org.linphone.phone; @@ -6193,7 +6193,7 @@ "-DENABLE_QRCODE=TRUE", "-DENABLE_SMS_INVITE=TRUE", "$(inherited)", - "-DLINPHONE_SDK_VERSION=\\\"5.2.68-pre.2+b096e8a01\\\"", + "-DLINPHONE_SDK_VERSION=\\\"5.2.70\\\"", ); OTHER_SWIFT_FLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = org.linphone.phone;