123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //
- // NCHud.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 04/09/24.
- // Copyright © 2024 Marino Faggiana. All rights reserved.
- //
- import Foundation
- import UIKit
- import JGProgressHUD
- class NCHud: NSObject {
- private let hud = JGProgressHUD()
- private var view: UIView?
- public init(_ view: UIView? = nil) {
- if let view {
- self.view = view
- }
- super.init()
- }
- func initHud(view: UIView? = nil, text: String? = nil, detailText: String? = nil) {
- DispatchQueue.main.async {
- if let view {
- self.view = view
- }
- self.hud.indicatorView = JGProgressHUDIndicatorView()
- self.hud.textLabel.text = text
- self.hud.textLabel.textColor = NCBrandColor.shared.iconImageColor
- self.hud.detailTextLabel.text = detailText
- self.hud.detailTextLabel.textColor = NCBrandColor.shared.iconImageColor2
- if let view = self.view {
- self.hud.show(in: view)
- }
- }
- }
- func initHudRing(view: UIView? = nil, text: String? = nil, detailText: String? = nil, tapToCancelDetailText: Bool = false, tapOperation: (() -> Void)? = nil) {
- DispatchQueue.main.async {
- self.hud.tapOnHUDViewBlock = { hud in
- if let tapOperation {
- tapOperation()
- hud.dismiss()
- }
- }
- if let view {
- self.view = view
- }
- self.hud.indicatorView = JGProgressHUDRingIndicatorView()
- self.hud.progress = 0.0
- let indicatorView = self.hud.indicatorView as? JGProgressHUDRingIndicatorView
- indicatorView?.ringWidth = 1.5
- indicatorView?.ringColor = NCBrandColor.shared.iconImageColor
- self.hud.textLabel.text = text
- self.hud.textLabel.textColor = NCBrandColor.shared.iconImageColor
- if tapToCancelDetailText {
- self.hud.detailTextLabel.text = NSLocalizedString("_tap_to_cancel_", comment: "")
- } else {
- self.hud.detailTextLabel.text = detailText
- }
- self.hud.detailTextLabel.textColor = NCBrandColor.shared.iconImageColor2
- if let view = self.view {
- self.hud.show(in: view)
- }
- }
- }
- func dismiss() {
- DispatchQueue.main.async {
- self.hud.dismiss()
- }
- }
- func show() {
- DispatchQueue.main.async {
- if let view = self.view {
- self.hud.show(in: view)
- }
- }
- }
- func progress(num: Float, total: Float) {
- DispatchQueue.main.async {
- self.hud.progress = num / total
- }
- }
- func progress(_ progress: Double) {
- DispatchQueue.main.async {
- self.hud.progress = Float(progress)
- }
- }
- func success() {
- DispatchQueue.main.async {
- self.hud.indicatorView = JGProgressHUDSuccessIndicatorView()
- self.hud.indicatorView?.tintColor = .green
- self.hud.textLabel.text = NSLocalizedString("_success_", comment: "")
- self.hud.detailTextLabel.text = nil
- self.hud.dismiss(afterDelay: 1.0)
- }
- }
- func error(text: String?) {
- DispatchQueue.main.async {
- self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
- self.hud.indicatorView?.tintColor = .red
- self.hud.textLabel.text = text
- self.hud.dismiss(afterDelay: 2.0)
- }
- }
- func setText(text: String?, detailText: String? = nil) {
- DispatchQueue.main.async {
- self.hud.textLabel.text = text
- self.hud.detailTextLabel.text = detailText
- }
- }
- }
|