mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Add support for media uploading progress
- replace the ProgressTracker with a combination of currentValueSubjects and currentValuePublishers
This commit is contained in:
committed by
Stefan Ceriu
parent
9cf2aba16d
commit
8b11a0a5ec
@@ -60,8 +60,8 @@ final class BugReportScreenCoordinator: CoordinatorProtocol {
|
||||
switch result {
|
||||
case .cancel:
|
||||
self.completion?(.cancel)
|
||||
case let .submitStarted(progressTracker):
|
||||
self.startLoading(label: L10n.commonSending, progressPublisher: progressTracker)
|
||||
case let .submitStarted(progressPublisher):
|
||||
self.startLoading(label: L10n.commonSending, progressPublisher: progressPublisher)
|
||||
case .submitFinished:
|
||||
self.stopLoading()
|
||||
self.completion?(.finish)
|
||||
@@ -85,7 +85,7 @@ final class BugReportScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
private static let loadingIndicatorIdentifier = "BugReportLoading"
|
||||
|
||||
private func startLoading(label: String = L10n.commonLoading, progressPublisher: ProgressPublisher) {
|
||||
private func startLoading(label: String = L10n.commonLoading, progressPublisher: CurrentValuePublisher<Double, Never>) {
|
||||
parameters.userIndicatorController?.submitIndicator(
|
||||
UserIndicator(id: Self.loadingIndicatorIdentifier,
|
||||
type: .modal(progress: .published(progressPublisher), interactiveDismissDisabled: false),
|
||||
|
||||
@@ -19,7 +19,7 @@ import UIKit
|
||||
|
||||
enum BugReportScreenViewModelAction {
|
||||
case cancel
|
||||
case submitStarted(progressTracker: ProgressTracker)
|
||||
case submitStarted(progressPublisher: CurrentValuePublisher<Double, Never>)
|
||||
case submitFinished
|
||||
case submitFailed(error: Error)
|
||||
}
|
||||
|
||||
@@ -62,8 +62,9 @@ class BugReportScreenViewModel: BugReportScreenViewModelType, BugReportScreenVie
|
||||
// MARK: Private
|
||||
|
||||
private func submitBugReport() async {
|
||||
let progressTracker = ProgressTracker()
|
||||
actionsSubject.send(.submitStarted(progressTracker: progressTracker))
|
||||
let progressSubject = CurrentValueSubject<Double, Never>(0.0)
|
||||
|
||||
actionsSubject.send(.submitStarted(progressPublisher: progressSubject.asCurrentValuePublisher()))
|
||||
|
||||
var files: [URL] = []
|
||||
if let screenshot = context.viewState.screenshot,
|
||||
@@ -87,7 +88,7 @@ class BugReportScreenViewModel: BugReportScreenViewModelType, BugReportScreenVie
|
||||
files: files)
|
||||
|
||||
switch await bugReportService.submitBugReport(bugReport,
|
||||
progressListener: progressTracker) {
|
||||
progressListener: progressSubject) {
|
||||
case .success(let response):
|
||||
MXLog.info("Submission uploaded to: \(response.reportUrl)")
|
||||
actionsSubject.send(.submitFinished)
|
||||
|
||||
+13
-10
@@ -14,6 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias MediaUploadPreviewScreenViewModelType = StateStoreViewModel<MediaUploadPreviewScreenViewState, MediaUploadPreviewScreenViewAction>
|
||||
@@ -43,11 +44,13 @@ class MediaUploadPreviewScreenViewModel: MediaUploadPreviewScreenViewModelType,
|
||||
switch viewAction {
|
||||
case .send:
|
||||
Task {
|
||||
startLoading()
|
||||
let progressSubject = CurrentValueSubject<Double, Never>(0.0)
|
||||
|
||||
startLoading(progressPublisher: progressSubject.asCurrentValuePublisher())
|
||||
|
||||
switch await mediaUploadingPreprocessor.processMedia(at: url) {
|
||||
case .success(let mediaInfo):
|
||||
switch await sendAttachment(mediaInfo: mediaInfo) {
|
||||
switch await sendAttachment(mediaInfo: mediaInfo, progressSubject: progressSubject) {
|
||||
case .success:
|
||||
callback?(.dismiss)
|
||||
case .failure(let error):
|
||||
@@ -70,26 +73,26 @@ class MediaUploadPreviewScreenViewModel: MediaUploadPreviewScreenViewModelType,
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func sendAttachment(mediaInfo: MediaInfo) async -> Result<Void, RoomProxyError> {
|
||||
private func sendAttachment(mediaInfo: MediaInfo, progressSubject: CurrentValueSubject<Double, Never>) async -> Result<Void, RoomProxyError> {
|
||||
switch mediaInfo {
|
||||
case let .image(imageURL, thumbnailURL, imageInfo):
|
||||
return await roomProxy.sendImage(url: imageURL, thumbnailURL: thumbnailURL, imageInfo: imageInfo)
|
||||
return await roomProxy.sendImage(url: imageURL, thumbnailURL: thumbnailURL, imageInfo: imageInfo, progressSubject: progressSubject)
|
||||
case let .video(videoURL, thumbnailURL, videoInfo):
|
||||
return await roomProxy.sendVideo(url: videoURL, thumbnailURL: thumbnailURL, videoInfo: videoInfo)
|
||||
return await roomProxy.sendVideo(url: videoURL, thumbnailURL: thumbnailURL, videoInfo: videoInfo, progressSubject: progressSubject)
|
||||
case let .audio(audioURL, audioInfo):
|
||||
return await roomProxy.sendAudio(url: audioURL, audioInfo: audioInfo)
|
||||
return await roomProxy.sendAudio(url: audioURL, audioInfo: audioInfo, progressSubject: progressSubject)
|
||||
case let .file(fileURL, fileInfo):
|
||||
return await roomProxy.sendFile(url: fileURL, fileInfo: fileInfo)
|
||||
return await roomProxy.sendFile(url: fileURL, fileInfo: fileInfo, progressSubject: progressSubject)
|
||||
}
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "MediaUploadPreviewLoading"
|
||||
|
||||
private func startLoading() {
|
||||
private func startLoading(progressPublisher: CurrentValuePublisher<Double, Never>) {
|
||||
userIndicatorController?.submitIndicator(
|
||||
UserIndicator(id: Self.loadingIndicatorIdentifier,
|
||||
type: .modal,
|
||||
title: L10n.commonLoading,
|
||||
type: .modal(progress: .published(progressPublisher), interactiveDismissDisabled: false),
|
||||
title: L10n.commonSending,
|
||||
persistent: true)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user