Selaa lähdekoodia

location streaming indicator now as separate item

nayooti 5 vuotta sitten
vanhempi
commit
becf79c2ec

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -159,6 +159,7 @@
 		AEC67A1C241CE9E4007DDBE1 /* AppStateRestorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */; };
 		AEC67A1E241FCFE0007DDBE1 /* ChatListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */; };
 		AECEF03E244F2D55006C90DA /* QrPageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECEF03D244F2D55006C90DA /* QrPageController.swift */; };
+		AED62BCE247687E6009E220D /* LocationStreamingIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED62BCD247687E6009E220D /* LocationStreamingIndicator.swift */; };
 		AEE56D762253431E007DC082 /* AccountSetupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D752253431E007DC082 /* AccountSetupController.swift */; };
 		AEE56D7D2253ADB4007DC082 /* HudHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7C2253ADB4007DC082 /* HudHandler.swift */; };
 		AEE56D80225504DB007DC082 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7F225504DB007DC082 /* Extensions.swift */; };
@@ -435,6 +436,7 @@
 		AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateRestorer.swift; sourceTree = "<group>"; };
 		AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListViewModel.swift; sourceTree = "<group>"; };
 		AECEF03D244F2D55006C90DA /* QrPageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QrPageController.swift; sourceTree = "<group>"; };
+		AED62BCD247687E6009E220D /* LocationStreamingIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationStreamingIndicator.swift; sourceTree = "<group>"; };
 		AEE56D752253431E007DC082 /* AccountSetupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSetupController.swift; sourceTree = "<group>"; tabWidth = 4; };
 		AEE56D7C2253ADB4007DC082 /* HudHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HudHandler.swift; sourceTree = "<group>"; };
 		AEE56D7F225504DB007DC082 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
@@ -932,6 +934,7 @@
 				305FE03523A81B4C0053BE90 /* EmptyStateLabel.swift */,
 				AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */,
 				AEB54C7E246DBA610004624C /* FlexLabel.swift */,
+				AED62BCD247687E6009E220D /* LocationStreamingIndicator.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -1287,6 +1290,7 @@
 				AE406EF0240FF8FF005F7022 /* ProfileCell.swift in Sources */,
 				305961F02346125100C80F33 /* NSConstraintLayoutSet.swift in Sources */,
 				3059620E234614E700C80F33 /* DcContact+Extension.swift in Sources */,
+				AED62BCE247687E6009E220D /* LocationStreamingIndicator.swift in Sources */,
 				305961F72346125100C80F33 /* MessageCollectionViewCell.swift in Sources */,
 				AE851AC9227C77CF00ED86F0 /* Media.swift in Sources */,
 				AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */,

+ 34 - 13
deltachat-ios/Controller/ChatViewController.swift

@@ -55,6 +55,30 @@ class ChatViewController: MessagesViewController {
         UITapGestureRecognizer(target: self, action: #selector(chatProfilePressed))
     }()
 
+    private var locationStreamingItem: UIBarButtonItem = {
+        let indicator = LocationStreamingIndicator()
+        return UIBarButtonItem(customView: indicator)
+    }()
+
+    private lazy var badgeItem: UIBarButtonItem = {
+        let badge: InitialsBadge
+        let chat = dcContext.getChat(chatId: chatId)
+        if let image = chat.profileImage {
+            badge = InitialsBadge(image: image, size: 28, accessibilityLabel: String.localized("menu_view_profile"))
+        } else {
+            badge = InitialsBadge(
+                name: chat.name,
+                color: chat.color,
+                size: 28,
+                accessibilityLabel: String.localized("menu_view_profile")
+            )
+            badge.setLabelFont(UIFont.systemFont(ofSize: 14))
+        }
+        badge.setVerified(chat.isVerified)
+        badge.accessibilityTraits = .button
+        return UIBarButtonItem(customView: badge)
+    }()
+
     /// The `BasicAudioController` controll the AVAudioPlayer state (play, pause, stop) and udpate audio cell UI accordingly.
     open lazy var audioController = BasicAudioController(messageCollectionView: messagesCollectionView)
 
@@ -235,12 +259,14 @@ class ChatViewController: MessagesViewController {
     override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
         let lastSectionVisibleBeforeTransition = self.isLastSectionVisible()
         coordinator.animate(
-            alongsideTransition: { _ in
-                if self.showCustomNavBar, let titleView = self.navigationItem.titleView as? ChatTitleView {
-                    titleView.hideLocationStreamingIndicator()
+            alongsideTransition: { [weak self] _ in
+                guard let self = self else { return }
+                if self.showCustomNavBar {
+                    self.navigationItem.setRightBarButton(self.badgeItem, animated: true)
                 }
             },
-            completion: { _ in
+            completion: {[weak self] _ in
+                guard let self = self else { return }
                 self.updateTitle(chat: self.dcContext.getChat(chatId: self.chatId))
                 self.messagesCollectionView.reloadDataAndKeepOffset()
                 if lastSectionVisibleBeforeTransition {
@@ -268,19 +294,14 @@ class ChatViewController: MessagesViewController {
             }
         }
         
-        titleView.updateTitleView(title: chat.name, subtitle: subtitle, isLocationStreaming: chat.isSendingLocations)
+        titleView.updateTitleView(title: chat.name, subtitle: subtitle)
         navigationItem.titleView = titleView
 
-        let badge: InitialsBadge
-        if let image = chat.profileImage {
-            badge =  InitialsBadge(image: image, size: 28, accessibilityLabel: String.localized("menu_view_profile"))
+        if chat.isSendingLocations {
+            navigationItem.rightBarButtonItems = [badgeItem, locationStreamingItem]
         } else {
-            badge =  InitialsBadge(name: chat.name, color: chat.color, size: 28, accessibilityLabel: String.localized("menu_view_profile"))
-            badge.setLabelFont(UIFont.systemFont(ofSize: 14))
+            navigationItem.rightBarButtonItem = badgeItem
         }
-        badge.setVerified(chat.isVerified)
-        badge.accessibilityTraits = .button
-        navigationItem.rightBarButtonItem = UIBarButtonItem(customView: badge)
     }
 
     @objc

+ 1 - 22
deltachat-ios/View/ChatTitleView.swift

@@ -21,17 +21,6 @@ class ChatTitleView: UIView {
         return subtitleLabel
     }()
 
-    private let locationStreamingIndicator: UIImageView = {
-        let view = UIImageView()
-        view.tintColor = DcColors.checkmarkGreen
-        view.translatesAutoresizingMaskIntoConstraints = false
-        view.constraintHeightTo(28).isActive = true
-        view.constraintWidthTo(28).isActive = true
-        view.image = #imageLiteral(resourceName: "ic_location").withRenderingMode(.alwaysTemplate)
-        view.isHidden = true
-        return view
-    }()
-
     private let paddingNaviationButtons = 120
     private let sizeStreamingIndicator = 28
 
@@ -65,22 +54,12 @@ class ChatTitleView: UIView {
                                        subtitleLabel.constraintAlignLeadingTo(containerView),
                                        subtitleLabel.constraintAlignTrailingTo(containerView),
                                        subtitleLabel.constraintAlignBottomTo(containerView)])
-        addSubview(locationStreamingIndicator)
-        addConstraints([
-                         locationStreamingIndicator.constraintCenterYTo(self),
-                         locationStreamingIndicator.constraintAlignTrailingTo(self),
-                         locationStreamingIndicator.constraintToTrailingOf(containerView)])
     }
 
-    func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = DcColors.defaultTextColor, isLocationStreaming: Bool) {
+    func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = DcColors.defaultTextColor) {
         subtitleLabel.textColor = baseColor.withAlphaComponent(0.95)
         titleLabel.textColor = baseColor
         titleLabel.text = title
         subtitleLabel.text = subtitle
-        locationStreamingIndicator.isHidden = !isLocationStreaming
-    }
-
-    func hideLocationStreamingIndicator() {
-        locationStreamingIndicator.isHidden = true
     }
 }

+ 27 - 0
deltachat-ios/View/LocationStreamingIndicator.swift

@@ -0,0 +1,27 @@
+import UIKit
+import DcCore
+
+class LocationStreamingIndicator: UIImageView {
+
+    convenience init() {
+        self.init(frame: .zero)
+    }
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        let size: CGFloat = frame == .zero ? 28 : frame.height
+        setup(size: size)
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    private func setup(size: CGFloat) {
+        tintColor = DcColors.checkmarkGreen
+        image =  #imageLiteral(resourceName: "ic_location").withRenderingMode(.alwaysTemplate)
+        translatesAutoresizingMaskIntoConstraints = false
+        heightAnchor.constraint(equalToConstant: size).isActive = true
+        widthAnchor.constraint(equalToConstant: size).isActive = true
+    }
+}