Room user indicators

Signed-off-by: Andy Uhnak <andyuhnak@gmail.com>
This commit is contained in:
Andy Uhnak
2022-02-23 09:47:35 +00:00
parent 2bec561b1f
commit 3f82e61723
28 changed files with 458 additions and 329 deletions
@@ -0,0 +1,54 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import CommonKit
/// A convenience objc-compatible wrapper around `UserIndicatorTypePresenterProtocol`.
///
/// This class wraps swift-only protocol by exponsing multiple methods instead of accepting struct types
/// and it keeps a track of `UserIndicator`s instead of returning them to the caller.
@objc final class UserIndicatorPresenterWrapper: NSObject {
private let presenter: UserIndicatorTypePresenterProtocol
private var loadingIndicator: UserIndicator?
private var otherIndicators = [UserIndicator]()
init(presenter: UserIndicatorTypePresenterProtocol) {
self.presenter = presenter
}
@objc func presentActivityIndicator() {
presentActivityIndicator(label: VectorL10n.homeSyncing)
}
@objc func presentActivityIndicator(label: String) {
guard loadingIndicator == nil else {
// The app is very liberal with calling `presentActivityIndicator` (often not matched by corresponding `removeCurrentActivityIndicator`),
// so there is no reason to keep adding new indiciators if there is one already showing.
return
}
loadingIndicator = presenter.present(.loading(label: label, isInteractionBlocking: false))
}
@objc func dismissActivityIndicator() {
loadingIndicator = nil
}
@objc func presentSuccess(label: String) {
presenter.present(.success(label: label)).store(in: &otherIndicators)
}
}