mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
Mark as read when detect the bottom of collectionView
Change IMDN icon with ChatMessageState Callback
This commit is contained in:
parent
94721fad50
commit
6275697028
2 changed files with 57 additions and 24 deletions
|
|
@ -112,17 +112,21 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
|
||||
collectionView.reloadData()
|
||||
ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject)
|
||||
self.floatingScrollButton?.isHidden = true
|
||||
self.floatingScrollBackground?.isHidden = true
|
||||
scrollBadge!.text = "0"
|
||||
}
|
||||
|
||||
func scrollToBottomNewMessage(){
|
||||
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: true)
|
||||
ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject)
|
||||
self.floatingScrollButton?.isHidden = true
|
||||
self.floatingScrollBackground?.isHidden = true
|
||||
scrollBadge!.text = "0"
|
||||
}
|
||||
|
||||
func scrollToBottomWithRelaod(){
|
||||
let isDisplayingBottomOfTable = collectionView.indexPathsForVisibleItems.sorted().first?.row == 0
|
||||
let isDisplayingBottomOfTable = collectionView.contentOffset.y <= 20
|
||||
collectionView.reloadData()
|
||||
if isDisplayingBottomOfTable {
|
||||
self.collectionView.scrollToItem(at: IndexPath(item: 1, section: 0), at: .top, animated: false)
|
||||
|
|
@ -138,7 +142,7 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
|
||||
func refreshData(){
|
||||
let indexBottom = collectionView.indexPathsForVisibleItems.sorted().first?.row
|
||||
let isDisplayingBottomOfTable = collectionView.indexPathsForVisibleItems.sorted().first?.row == 0
|
||||
let isDisplayingBottomOfTable = collectionView.contentOffset.y <= 20
|
||||
let sizeCell = (self.collectionView.cellForItem(at: IndexPath(row: indexBottom!, section: 0))?.frame.size.height)
|
||||
collectionView.reloadData()
|
||||
|
||||
|
|
@ -155,20 +159,30 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
scrollBadge!.text = "\(ChatConversationViewModel.sharedModel.chatRoom?.unreadMessagesCount ?? 0)"
|
||||
}
|
||||
}
|
||||
|
||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
let contentOffsetY = scrollView.contentOffset.y
|
||||
if contentOffsetY <= 20 /* Needed offset */ {
|
||||
self.floatingScrollButton?.isHidden = true
|
||||
self.floatingScrollBackground?.isHidden = true
|
||||
self.scrollBadge?.text = "0"
|
||||
ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject)
|
||||
} else {
|
||||
self.floatingScrollButton?.isHidden = false
|
||||
self.floatingScrollBackground?.isHidden = false;
|
||||
if(self.scrollBadge?.text == "0"){
|
||||
self.scrollBadge?.isHidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDataSource -
|
||||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MultilineMessageCell.reuseId, for: indexPath) as! MultilineMessageCell
|
||||
|
||||
if(indexPath.row < 1) {
|
||||
self.floatingScrollButton?.isHidden = true
|
||||
self.floatingScrollBackground?.isHidden = true;
|
||||
self.scrollBadge?.text = "0"
|
||||
}
|
||||
|
||||
|
||||
if let event = ChatConversationTableViewModel.sharedModel.getMessage(index: indexPath.row){
|
||||
cell.configure(event: event, selfIndexPathConfigure: indexPath)
|
||||
|
||||
|
||||
if (event.chatMessage != nil){
|
||||
cell.onLongClickOneClick {
|
||||
self.initDataSource(message: event.chatMessage!)
|
||||
|
|
@ -192,12 +206,6 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
if cell.isPlayingVoiceRecording {
|
||||
AudioPlayer.stopSharedPlayer()
|
||||
}
|
||||
|
||||
if(indexPath.row < 1) {
|
||||
self.floatingScrollButton?.isHidden = false
|
||||
self.floatingScrollBackground?.isHidden = false;
|
||||
self.scrollBadge?.isHidden = true
|
||||
}
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
let contentBubble: UIView = UIView(frame: .zero)
|
||||
let bubble: UIView = UIView(frame: .zero)
|
||||
let imageUser: UIView = UIView(frame: .zero)
|
||||
let chatRead = UIImageView(image: UIImage(named: "chat_read.png"))
|
||||
let chatRead = UIImageView(image: UIImage(named: "chat_delivered.png"))
|
||||
|
||||
let labelInset = UIEdgeInsets(top: 10, left: 10, bottom: -10, right: -10)
|
||||
|
||||
|
|
@ -542,13 +542,12 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
constraintTrailingBubble?.isActive = false
|
||||
imageUser.isHidden = false
|
||||
bubble.backgroundColor = UIColor("D").withAlphaComponent(0.2)
|
||||
chatRead.isHidden = true
|
||||
}else{
|
||||
constraintLeadingBubble?.isActive = false
|
||||
constraintTrailingBubble?.isActive = true
|
||||
imageUser.isHidden = true
|
||||
bubble.backgroundColor = UIColor("A").withAlphaComponent(0.2)
|
||||
chatRead.isHidden = false
|
||||
displayImdnStatus(message: event.chatMessage!, state: event.chatMessage!.state)
|
||||
}
|
||||
|
||||
if event.chatMessage!.isForward {
|
||||
|
|
@ -824,7 +823,6 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
constraintLeadingBubble?.isActive = false
|
||||
constraintTrailingBubble?.isActive = false
|
||||
imageUser.isHidden = true
|
||||
chatRead.isHidden = true
|
||||
|
||||
eventMessageView.isHidden = false
|
||||
NSLayoutConstraint.activate(constraintEventMesssage)
|
||||
|
|
@ -845,9 +843,15 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
|
||||
func addMessageDelegate(){
|
||||
chatMessageDelegate = ChatMessageDelegateStub(
|
||||
onMsgStateChanged: { (message: ChatMessage, state: ChatMessage.State) -> Void in
|
||||
self.displayImdnStatus(message: message, state: state)
|
||||
},
|
||||
onFileTransferProgressIndication: { (message: ChatMessage, content: Content, offset: Int, total: Int) -> Void in
|
||||
self.file_transfer_progress_indication_recv(message: message, content: content, offset: offset, total: total)
|
||||
}
|
||||
},
|
||||
onParticipantImdnStateChanged: { (message: ChatMessage, state: ParticipantImdnState) -> Void in
|
||||
//self.file_transfer_progress_indication_recv(message: message, content: content, offset: offset, total: total)
|
||||
}
|
||||
)
|
||||
chatMessage?.addDelegate(delegate: chatMessageDelegate!)
|
||||
}
|
||||
|
|
@ -1218,8 +1222,10 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
}
|
||||
}
|
||||
|
||||
downloadContentCollection[indexTransferProgress]!.downloadButtonLabel.isHidden = true
|
||||
downloadContentCollection[indexTransferProgress]!.circularProgressBarView.isHidden = false
|
||||
if downloadContentCollection[indexTransferProgress] != nil {
|
||||
downloadContentCollection[indexTransferProgress]!.downloadButtonLabel.isHidden = true
|
||||
downloadContentCollection[indexTransferProgress]!.circularProgressBarView.isHidden = false
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async(execute: { [self] in
|
||||
|
|
@ -1249,10 +1255,29 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
indexTransferProgress = -1
|
||||
}
|
||||
} else {
|
||||
downloadContentCollection[indexTransferProgress]!.setUpCircularProgressBarView(toValue: p)
|
||||
if downloadContentCollection[indexTransferProgress] != nil {
|
||||
downloadContentCollection[indexTransferProgress]!.setUpCircularProgressBarView(toValue: p)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func displayImdnStatus(message: ChatMessage, state: ChatMessage.State) {
|
||||
if message.isOutgoing {
|
||||
if (state == ChatMessage.State.DeliveredToUser) {
|
||||
chatRead.image = UIImage(named: "chat_delivered.png")
|
||||
chatRead.isHidden = false
|
||||
} else if (state == ChatMessage.State.Displayed) {
|
||||
chatRead.image = UIImage(named: "chat_read.png")
|
||||
chatRead.isHidden = false
|
||||
} else if (state == ChatMessage.State.NotDelivered || state == ChatMessage.State.FileTransferError) {
|
||||
chatRead.image = UIImage(named: "chat_error")
|
||||
chatRead.isHidden = false
|
||||
} else {
|
||||
chatRead.isHidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DynamicHeightCollectionView: UICollectionView {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue