mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-27 11:46:58 +02:00
Display sync progress on the loading screen
This commit is contained in:
@@ -30,12 +30,20 @@ final class LaunchLoadingView: UIView, NibLoadable, Themable {
|
||||
// MARK: - Properties
|
||||
|
||||
@IBOutlet private weak var animationView: ElementView!
|
||||
@IBOutlet private weak var statusLabel: UILabel!
|
||||
|
||||
private var animationTimeline: Timeline_1!
|
||||
private let numberFormatter: NumberFormatter = {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.numberStyle = .ordinal
|
||||
return formatter
|
||||
}()
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
static func instantiate() -> LaunchLoadingView {
|
||||
static func instantiate(syncProgress: MXSessionSyncProgress?) -> LaunchLoadingView {
|
||||
let view = LaunchLoadingView.loadFromNib()
|
||||
syncProgress?.delegate = view
|
||||
return view
|
||||
}
|
||||
|
||||
@@ -45,6 +53,8 @@ final class LaunchLoadingView: UIView, NibLoadable, Themable {
|
||||
let animationTimeline = Timeline_1(view: self.animationView, duration: LaunchAnimation.duration, repeatCount: LaunchAnimation.repeatCount)
|
||||
animationTimeline.play()
|
||||
self.animationTimeline = animationTimeline
|
||||
|
||||
self.statusLabel.isHidden = !MXSDKOptions.sharedInstance().enableSyncProgress
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -54,3 +64,31 @@ final class LaunchLoadingView: UIView, NibLoadable, Themable {
|
||||
self.animationView.backgroundColor = theme.backgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
extension LaunchLoadingView: MXSessionSyncProgressDelegate {
|
||||
func sessionDidUpdateSyncState(_ state: MXSessionSyncState) {
|
||||
guard MXSDKOptions.sharedInstance().enableSyncProgress else {
|
||||
return
|
||||
}
|
||||
|
||||
// Sync may be doing a lot of heavy work on the main thread and the status text
|
||||
// does not update reliably enough without explicitly refreshing
|
||||
CATransaction.begin()
|
||||
statusLabel.text = statusText(for: state)
|
||||
CATransaction.commit()
|
||||
}
|
||||
|
||||
private func statusText(for state: MXSessionSyncState) -> String {
|
||||
switch state {
|
||||
case .serverSyncing(let attempts):
|
||||
if attempts > 1, let nth = numberFormatter.string(from: NSNumber(value: attempts)) {
|
||||
return VectorL10n.launchLoadingServerSyncingNthAttempt(nth)
|
||||
} else {
|
||||
return VectorL10n.launchLoadingServerSyncing
|
||||
}
|
||||
case .processingResponse(let progress):
|
||||
let percent = Int(floor(progress * 100))
|
||||
return VectorL10n.launchLoadingProcessingResponse("\(percent)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user