@@ -2,6 +2,7 @@ import UIKit
22import AVFoundation
33import Vision
44import CoreImage
5+ import SwiftUI
56import Combine
67
78class CameraViewController : UIViewController , UINavigationControllerDelegate {
@@ -67,8 +68,7 @@ class CameraViewController: UIViewController, UINavigationControllerDelegate {
6768 private var captureModesLabel : UILabel !
6869 private var recordingTimer : Timer ?
6970 private var recordingDuration : TimeInterval = 0
70- private var connectionStatusIcon : UIButton !
71- private var connectionSecureIcon : UIButton !
71+ private var connectionHostingController : UIHostingController < ConnectionStatusButton > !
7272
7373 override func viewDidLoad( ) {
7474 super. viewDidLoad ( )
@@ -78,13 +78,12 @@ class CameraViewController: UIViewController, UINavigationControllerDelegate {
7878
7979 setupSwitchCameraButton ( )
8080 setupTimerLabel ( )
81- setupConnectionStatusIcon ( )
81+ setupConnectionStatusButton ( )
8282 setupCamera ( )
8383 setupPrivacyFiltering ( )
8484
8585 // ConnectionManager is a singleton, so we just ensure it's connected and observe it
8686 ConnectionManager . shared. connect ( )
87- setupConnectionObserver ( )
8887 setupCommandObserver ( )
8988 }
9089
@@ -140,7 +139,7 @@ class CameraViewController: UIViewController, UINavigationControllerDelegate {
140139 let label = UILabel ( )
141140 label. text = " Initializing Privacy Models... "
142141 label. textColor = . white
143- label. font = . systemFont( ofSize: 16 , weight: . medium)
142+ label. font = . systemFont( ofSize: AppConstants . UI . fontSizeStandard , weight: . medium)
144143 label. translatesAutoresizingMaskIntoConstraints = false
145144
146145 let stack = UIStackView ( arrangedSubviews: [ indicator, label] )
@@ -261,94 +260,20 @@ class CameraViewController: UIViewController, UINavigationControllerDelegate {
261260 ] )
262261 }
263262
264- private func setupConnectionStatusIcon( ) {
265- connectionStatusIcon = UIButton ( type: . system)
266- connectionStatusIcon. translatesAutoresizingMaskIntoConstraints = false
267- connectionStatusIcon. tintColor = . white
268- connectionStatusIcon. backgroundColor = AppConstants . Colors. backgroundBaseUI. withAlphaComponent ( AppConstants . UI. buttonBackgroundAlpha)
269- connectionStatusIcon. layer. cornerRadius = AppConstants . UI. cornerRadiusLarge
270- connectionStatusIcon. isUserInteractionEnabled = false // Disable interaction, just display
271-
272- view. addSubview ( connectionStatusIcon)
273-
274- NSLayoutConstraint . activate ( [
275- connectionStatusIcon. topAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. topAnchor, constant: AppConstants . UI. paddingStandard) ,
276- connectionStatusIcon. trailingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. trailingAnchor, constant: AppConstants . UI. offsetTrailingStatus) ,
277- connectionStatusIcon. widthAnchor. constraint ( equalToConstant: AppConstants . UI. buttonSizeMedium) ,
278- connectionStatusIcon. heightAnchor. constraint ( equalToConstant: AppConstants . UI. buttonSizeMedium)
279- ] )
280-
281- // Setup lock icon overlay for secure connection indicator
282- connectionSecureIcon = UIButton ( type: . system)
283- connectionSecureIcon. translatesAutoresizingMaskIntoConstraints = false
284- connectionSecureIcon. tintColor = . systemGreen
285- connectionSecureIcon. isUserInteractionEnabled = false // Disable interaction, just display
286- connectionSecureIcon. isHidden = true // Initially hidden
287-
288- if let lockImage = UIImage ( systemName: " lock.fill " ) {
289- let config = UIImage . SymbolConfiguration ( pointSize: AppConstants . UI. iconSizeSecurePoint, weight: . semibold, scale: . default)
290- connectionSecureIcon. setImage ( lockImage. withConfiguration ( config) , for: . normal)
291- }
292-
293- view. addSubview ( connectionSecureIcon)
294-
263+ private func setupConnectionStatusButton( ) {
264+ let buttonView = ConnectionStatusButton ( )
265+ connectionHostingController = UIHostingController ( rootView: buttonView)
266+ connectionHostingController. view. translatesAutoresizingMaskIntoConstraints = false
267+ connectionHostingController. view. backgroundColor = . clear
268+
269+ addChild ( connectionHostingController)
270+ view. addSubview ( connectionHostingController. view)
271+ connectionHostingController. didMove ( toParent: self )
272+
295273 NSLayoutConstraint . activate ( [
296- connectionSecureIcon. bottomAnchor. constraint ( equalTo: connectionStatusIcon. bottomAnchor, constant: AppConstants . UI. paddingMicro) ,
297- connectionSecureIcon. trailingAnchor. constraint ( equalTo: connectionStatusIcon. trailingAnchor, constant: AppConstants . UI. paddingMicro) ,
298- connectionSecureIcon. widthAnchor. constraint ( equalToConstant: AppConstants . UI. iconSizeSecure) ,
299- connectionSecureIcon. heightAnchor. constraint ( equalToConstant: AppConstants . UI. iconSizeSecure)
274+ connectionHostingController. view. topAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. topAnchor, constant: AppConstants . UI. paddingStandard) ,
275+ connectionHostingController. view. trailingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. trailingAnchor, constant: AppConstants . UI. offsetTrailingStatus)
300276 ] )
301-
302- updateConnectionStatusIcon ( )
303- }
304-
305- private func updateConnectionStatusIcon( ) {
306- DispatchQueue . main. async { [ weak self] in
307- guard let self = self else { return }
308-
309- if ConnectionManager . shared. isConnected {
310- // Connected - green
311- if let image = UIImage ( systemName: " wifi " ) {
312- self . connectionStatusIcon. setImage ( image, for: . normal)
313- self . connectionStatusIcon. tintColor = AppConstants . Colors. statusConnectedUI
314- }
315- // Show lock icon if using secure protocol
316- self . connectionSecureIcon. isHidden = !ConnectionManager. shared. isSecureProtocol
317- } else if ConnectionManager . shared. isAttemptingConnection {
318- // Attempting connection - amber/orange
319- if let image = UIImage ( systemName: " wifi " ) {
320- self . connectionStatusIcon. setImage ( image, for: . normal)
321- self . connectionStatusIcon. tintColor = AppConstants . Colors. statusConnectingUI
322- }
323- // Hide lock icon while attempting
324- self . connectionSecureIcon. isHidden = true
325- } else {
326- // Disconnected - red
327- if let image = UIImage ( systemName: " wifi.slash " ) {
328- self . connectionStatusIcon. setImage ( image, for: . normal)
329- self . connectionStatusIcon. tintColor = AppConstants . Colors. statusDisconnectedUI
330- }
331- // Hide lock icon when disconnected
332- self . connectionSecureIcon. isHidden = true
333- }
334- }
335- }
336-
337- private func setupConnectionObserver( ) {
338- // Observe connection state changes
339- ConnectionManager . shared. $isConnected
340- . receive ( on: DispatchQueue . main)
341- . sink { [ weak self] _ in
342- self ? . updateConnectionStatusIcon ( )
343- }
344- . store ( in: & cancellables)
345-
346- ConnectionManager . shared. $isAttemptingConnection
347- . receive ( on: DispatchQueue . main)
348- . sink { [ weak self] _ in
349- self ? . updateConnectionStatusIcon ( )
350- }
351- . store ( in: & cancellables)
352277 }
353278
354279 private func setupCommandObserver( ) {
0 commit comments