Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/Threema/SharedUI/CustomViews/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 2 kB image not shown  

Quelle  StatusNavigationBar.swift   Sprache: JAVA

 

import CocoaLumberjackSwift
import Combine
import Foundation
import GroupCalls
import SwiftUI
import ThreemaFramework
import UIKit

final class StatusNavigationBar: UINavigationBar {
    
    // MARK: - Subviews
    
    private lazy var statusView = UIView(frame: CGRect(x: 0, y: frame.size.height - 2, width: frame.width, height: 2))
    
    // MARK: - Lifecycle
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(statusView)
        configure()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        configure()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        statusView.frame = CGRect(x: 0, y: frame.size.height - 2, width: frame.width, height: 2)
        updateNavigationBar()
    }
    
    private func configure() {
        ServerConnector.shared().registerConnectionStateDelegate(delegate: self)
        statusView.isHidden = true
        addSubview(statusView)
        updateStatusView()
        updateNavigationBar()
    }
    
    // MARK: - Private Functions
    
    private func updateNavigationBar() {
        Task { @MainActor in
            updateStatusView()
        }
    }
    
    @MainActor
    private func updateStatusView() {
        DispatchQueue.main.async { [self] in
            // The display of connection state is delayed because the process coordinator checks
            // whether it can establish a server connection, it takes a little longer to connect.
            var deadline: DispatchTime = .now()
            if statusView.isHidden {
                deadline = .now() + .seconds(1)
            }

            DispatchQueue.main.asyncAfter(deadline: deadline) { [self] in
                switch ServerConnector.shared().connectionState {
                case .disconnecting, .disconnected, .connecting:
                    if ProcessInfoHelper.isRunningForScreenshots {
                        statusView.backgroundColor = .systemGreen
                        statusView.isHidden = true
                    }
                    else {
                        statusView.backgroundColor = .systemRed
                        statusView.isHidden = SharedAppProvider.isAppInBackground
                    }

                case .connected:
                    statusView.backgroundColor = .systemOrange
                    statusView.isHidden = SharedAppProvider.isAppInBackground

                case .loggedIn:
                    statusView.backgroundColor = .systemGreen
                    statusView.isHidden = true
                }
            }
        }
    }
}

// MARK: - ConnectionStateDelegate

extension StatusNavigationBar: ConnectionStateDelegate {
    func changed(connectionState state: ConnectionState) {
        Task { @MainActor in
            updateStatusView()
        }
    }
}

Messung
CHZG
849310092

¤ Dauer der Verarbeitung: 0.2 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.