diff --git a/Linphone/GeneratedGit.swift b/Linphone/GeneratedGit.swift index 55b76b223..757db7c38 100644 --- a/Linphone/GeneratedGit.swift +++ b/Linphone/GeneratedGit.swift @@ -2,6 +2,6 @@ import Foundation public enum AppGitInfo { public static let branch = "master" - public static let commit = "b753b5925" + public static let commit = "304651d77" public static let tag = "6.1.0-alpha" } diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationDocumentsListFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationDocumentsListFragment.swift index bab4c68a9..fcf928d69 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationDocumentsListFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationDocumentsListFragment.swift @@ -75,6 +75,11 @@ struct ConversationDocumentsListFragment: View { .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) .listRowSeparator(.hidden) .listRowBackground(Color.clear) + .onAppear { + if file == conversationDocumentsListViewModel.documentsList.last { + conversationDocumentsListViewModel.loadMoreData(totalItemsCount: conversationDocumentsListViewModel.documentsList.count) + } + } } } .safeAreaInset(edge: .top, content: { @@ -98,6 +103,11 @@ struct ConversationDocumentsListFragment: View { .frame(maxWidth: .infinity) } .background(Color.gray100) + + if conversationDocumentsListViewModel.operationInProgress { + PopupLoadingView() + .background(.black.opacity(0.65)) + } } .navigationTitle("") .navigationBarHidden(true) diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationMediaListFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationMediaListFragment.swift index cd8a7c699..475692242 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationMediaListFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationMediaListFragment.swift @@ -69,6 +69,11 @@ struct ConversationMediaListFragment: View { ConversationMediaGridView(viewModel: conversationMediaListViewModel) } .background(Color.gray100) + + if conversationMediaListViewModel.operationInProgress { + PopupLoadingView() + .background(.black.opacity(0.65)) + } } .navigationTitle("") .navigationBarHidden(true) @@ -92,7 +97,7 @@ struct ConversationMediaGridView: View { var body: some View { VStack(spacing: 0) { - if !viewModel.mediaList.isEmpty && !viewModel.operationInProgress { + if !viewModel.mediaList.isEmpty { GeometryReader { geometry in let totalSpacing = spacing * CGFloat(columns - 1) let itemWidth = (geometry.size.width - totalSpacing) / CGFloat(columns) @@ -128,6 +133,8 @@ struct ConversationMediaGridView: View { .multilineTextAlignment(.center) .default_text_style_800(styleSize: 16) Spacer() + } else { + Spacer() } } } diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationDocumentsListViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationDocumentsListViewModel.swift index 8edc6713b..29aeb0ed7 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationDocumentsListViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationDocumentsListViewModel.swift @@ -41,30 +41,46 @@ final class ConversationDocumentsListViewModel: ObservableObject { // MARK: - Loading private func loadDocumentsList() { - operationInProgress = true - totalDocumentsCount = self.conversationModel.chatRoom.documentContentsSize - - let contentsToLoad = min(totalDocumentsCount, Self.CONTENTS_PER_PAGE) - let contents = self.conversationModel.chatRoom.getDocumentContentsRange(begin: 0, end: contentsToLoad) - - documentsList = getFileModelsList(from: contents) - operationInProgress = false + self.operationInProgress = true + CoreContext.shared.doOnCoreQueue { _ in + self.totalDocumentsCount = self.conversationModel.chatRoom.documentContentsSize + + let contentsToLoad = min(self.totalDocumentsCount, Self.CONTENTS_PER_PAGE) + let contents = self.conversationModel.chatRoom.getDocumentContentsRange(begin: 0, end: contentsToLoad) + + let documentsListTmp = self.getFileModelsList(from: contents) + + DispatchQueue.main.async { + self.documentsList = documentsListTmp + self.operationInProgress = false + } + } } func loadMoreData(totalItemsCount: Int) { - guard totalItemsCount < totalDocumentsCount else { return } - - var upperBound = totalItemsCount + Self.CONTENTS_PER_PAGE - if upperBound > totalDocumentsCount { - upperBound = totalDocumentsCount - } - - let contents = self.conversationModel.chatRoom.getDocumentContentsRange(begin: totalItemsCount, end: upperBound) - let newModels = getFileModelsList(from: contents) - - DispatchQueue.main.async { - self.documentsList.append(contentsOf: newModels) + self.operationInProgress = true + CoreContext.shared.doOnCoreQueue { _ in + guard totalItemsCount < self.totalDocumentsCount else { + DispatchQueue.main.async { + self.operationInProgress = false + } + return + } + + var upperBound = totalItemsCount + Self.CONTENTS_PER_PAGE + if upperBound > self.totalDocumentsCount { + upperBound = self.totalDocumentsCount + } + + let contents = self.conversationModel.chatRoom.getDocumentContentsRange(begin: totalItemsCount, end: upperBound) + let newModels = self.getFileModelsList(from: contents) + + DispatchQueue.main.async { + self.documentsList.append(contentsOf: newModels) + self.operationInProgress = false + } } + } // MARK: - Mapping Content -> FileModel diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationMediaListViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationMediaListViewModel.swift index db9576dc0..105ccbc83 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationMediaListViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationMediaListViewModel.swift @@ -42,28 +42,36 @@ final class ConversationMediaListViewModel: ObservableObject { // MARK: - Loading private func loadMediaList() { - operationInProgress = true - Log.info("\(Self.TAG) Loading media contents for conversation \(conversationModel.chatRoom.identifier ?? "No ID")") - - totalMediaCount = conversationModel.chatRoom.mediaContentsSize - Log.info("\(Self.TAG) Media contents size is [\(totalMediaCount)]") - - let contentsToLoad = min(totalMediaCount, Self.CONTENTS_PER_PAGE) - let contents = conversationModel.chatRoom.getMediaContentsRange(begin: 0, end: contentsToLoad) - - Log.info("\(Self.TAG) \(contents.count) media have been fetched") - - DispatchQueue.main.async { - self.mediaList = self.getFileModelsList(from: contents) - self.operationInProgress = false + self.operationInProgress = true + CoreContext.shared.doOnCoreQueue { _ in + Log.info("\(Self.TAG) Loading media contents for conversation \(self.conversationModel.chatRoom.identifier ?? "No ID")") + + self.totalMediaCount = self.conversationModel.chatRoom.mediaContentsSize + Log.info("\(Self.TAG) Media contents size is [\(self.totalMediaCount)]") + + let contentsToLoad = min(self.totalMediaCount, Self.CONTENTS_PER_PAGE) + let contents = self.conversationModel.chatRoom.getMediaContentsRange(begin: 0, end: contentsToLoad) + + Log.info("\(Self.TAG) \(contents.count) media have been fetched") + + DispatchQueue.main.async { + self.mediaList = self.getFileModelsList(from: contents) + self.operationInProgress = false + } } } func loadMoreData(totalItemsCount: Int) { - CoreContext.shared.doOnCoreQueue { core in + self.operationInProgress = true + CoreContext.shared.doOnCoreQueue { _ in Log.info("\(Self.TAG) Loading more data, current total is \(totalItemsCount), max size is \(self.totalMediaCount)") - guard totalItemsCount < self.totalMediaCount else { return } + guard totalItemsCount < self.totalMediaCount else { + DispatchQueue.main.async { + self.operationInProgress = false + } + return + } var upperBound = totalItemsCount + Self.CONTENTS_PER_PAGE if upperBound > self.totalMediaCount { @@ -77,6 +85,7 @@ final class ConversationMediaListViewModel: ObservableObject { DispatchQueue.main.async { self.mediaList.append(contentsOf: newModels) + self.operationInProgress = false } } }