Add support for media uploading progress

- replace the ProgressTracker with a combination of currentValueSubjects and currentValuePublishers
This commit is contained in:
Stefan Ceriu
2023-06-21 12:55:49 +03:00
committed by Stefan Ceriu
parent 9cf2aba16d
commit 8b11a0a5ec
13 changed files with 130 additions and 150 deletions
@@ -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)