Jelajahi Sumber

add UI to block and accept contact requests

cyberta 3 tahun lalu
induk
melakukan
29926a9e11

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

@@ -27,6 +27,7 @@
 		302B84CE2397F6CD001C261F /* URL+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302B84CD2397F6CD001C261F /* URL+Extension.swift */; };
 		302D5450268B6B2300A8B271 /* MessageUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302D544F268B6B2300A8B271 /* MessageUtils.swift */; };
 		302D5454268B84CB00A8B271 /* SettingsVideoChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302D5453268B84CB00A8B271 /* SettingsVideoChatViewController.swift */; };
+		302D546A2693591700A8B271 /* ChatContactRequestBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302D54692693591700A8B271 /* ChatContactRequestBar.swift */; };
 		302E1BB4252B5AB4008F4264 /* PlayButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302E1BB3252B5AB4008F4264 /* PlayButtonView.swift */; };
 		30349291256441E200A523D0 /* QuotePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30349290256441E200A523D0 /* QuotePreview.swift */; };
 		303492952565AABC00A523D0 /* DraftModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 303492942565AABC00A523D0 /* DraftModel.swift */; };
@@ -241,6 +242,7 @@
 		302B84CD2397F6CD001C261F /* URL+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Extension.swift"; sourceTree = "<group>"; };
 		302D544F268B6B2300A8B271 /* MessageUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageUtils.swift; sourceTree = "<group>"; };
 		302D5453268B84CB00A8B271 /* SettingsVideoChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsVideoChatViewController.swift; sourceTree = "<group>"; };
+		302D54692693591700A8B271 /* ChatContactRequestBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatContactRequestBar.swift; sourceTree = "<group>"; };
 		302E1BB3252B5AB4008F4264 /* PlayButtonView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PlayButtonView.swift; path = "deltachat-ios/Chat/Views/PlayButtonView.swift"; sourceTree = SOURCE_ROOT; };
 		30349290256441E200A523D0 /* QuotePreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotePreview.swift; sourceTree = "<group>"; };
 		303492942565AABC00A523D0 /* DraftModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftModel.swift; sourceTree = "<group>"; };
@@ -599,6 +601,7 @@
 				303492CE2587C2DC00A523D0 /* ChatInputBar.swift */,
 				3067AA4B2666310E00525036 /* ChatInputTextView.swift */,
 				307A82CB25B8D26700748B57 /* ChatEditingBar.swift */,
+				302D54692693591700A8B271 /* ChatContactRequestBar.swift */,
 				302E1BB3252B5AB4008F4264 /* PlayButtonView.swift */,
 				30F8817524DA97DA0023780E /* BackgroundContainer.swift */,
 				3008CB7324F9436C00E6A617 /* AudioPlayerView.swift */,
@@ -1364,6 +1367,7 @@
 				7A451DB01FB1F84900177250 /* AppCoordinator.swift in Sources */,
 				AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */,
 				AE9DAF0D22C1215D004C9591 /* EditContactController.swift in Sources */,
+				302D546A2693591700A8B271 /* ChatContactRequestBar.swift in Sources */,
 				305DDD8725DD97BF00974489 /* DynamicFontButton.swift in Sources */,
 				785BE16821E247F1003BE98C /* MessageInfoViewController.swift in Sources */,
 				AED423D3249F578B00B6B2BB /* AddGroupMembersViewController.swift in Sources */,

+ 44 - 7
deltachat-ios/Chat/ChatViewController.swift

@@ -54,6 +54,13 @@ class ChatViewController: UITableViewController {
         return view
     }()
 
+    public lazy var contactRequestBar: ChatContactRequestBar = {
+        let view = ChatContactRequestBar()
+        view.delegate = self
+        view.translatesAutoresizingMaskIntoConstraints = false
+        return view
+    }()
+
     open override var shouldAutorotate: Bool {
         return false
     }
@@ -239,7 +246,8 @@ class ChatViewController: UITableViewController {
     }
 
     override func loadView() {
-        self.tableView = ChatTableView(messageInputBar: self.disableWriting ? nil : messageInputBar)
+        let inputBar = self.disableWriting && !dcContext.getChat(chatId: chatId).isContactRequest ? nil : messageInputBar
+        self.tableView = ChatTableView(messageInputBar: inputBar)
         self.tableView.delegate = self
         self.tableView.dataSource = self
         self.view = self.tableView
@@ -266,15 +274,20 @@ class ChatViewController: UITableViewController {
         configureEmptyStateView()
 
         if !disableWriting {
-            configureMessageInputBar()
-            draft.parse(draftMsg: dcContext.getDraft(chatId: chatId))
-            messageInputBar.inputTextView.text = draft.text
-            configureDraftArea(draft: draft, animated: false)
-            editingBar.delegate = self
-            tableView.allowsMultipleSelectionDuringEditing = true
+            configureUIForWriting()
+        } else if dcContext.getChat(chatId: chatId).isContactRequest {
+            configureContactRequestBar()
         }
     }
 
+    private func configureUIForWriting() {
+        configureMessageInputBar()
+        draft.parse(draftMsg: dcContext.getDraft(chatId: chatId))
+        messageInputBar.inputTextView.text = draft.text
+        configureDraftArea(draft: draft, animated: false)
+        tableView.allowsMultipleSelectionDuringEditing = true
+    }
+
     private func getTopInsetHeight() -> CGFloat {
         return UIApplication.shared.statusBarFrame.height + (navigationController?.navigationBar.bounds.height ?? 0)
     }
@@ -614,6 +627,14 @@ class ChatViewController: UITableViewController {
         markSeenMessagesInVisibleArea()
     }
 
+    private func configureContactRequestBar() {
+        messageInputBar.setMiddleContentView(contactRequestBar, animated: false)
+        messageInputBar.setLeftStackViewWidthConstant(to: 0, animated: false)
+        messageInputBar.setRightStackViewWidthConstant(to: 0, animated: false)
+        messageInputBar.padding = UIEdgeInsets(top: 6, left: 0, bottom: 6, right: 0)
+        messageInputBar.setStackViewItems([], forStack: .top, animated: false)
+    }
+
     private func configureDraftArea(draft: DraftModel, animated: Bool = true) {
         draftArea.configure(draft: draft)
         if draft.isEditing {
@@ -1658,6 +1679,22 @@ extension ChatViewController: ChatEditingDelegate {
     }
 }
 
+// MARK: - ChatContactRequestBar
+extension ChatViewController: ChatContactRequestDelegate {
+    func onAcceptPressed() {
+        dcContext.acceptChat(chatId: chatId)
+        disableWriting = !dcContext.getChat(chatId: chatId).canSend
+        if !disableWriting {
+            configureUIForWriting()
+        }
+    }
+
+    func onBlockPressed() {
+        dcContext.blockChat(chatId: chatId)
+        self.navigationController?.popViewController(animated: true)
+    }
+}
+
 // MARK: - QLPreviewControllerDelegate
 extension ChatViewController: QLPreviewControllerDelegate {
     @available(iOS 13.0, *)

+ 88 - 0
deltachat-ios/Chat/Views/ChatContactRequestBar.swift

@@ -0,0 +1,88 @@
+import UIKit
+import InputBarAccessoryView
+import DcCore
+
+public protocol ChatContactRequestDelegate: class {
+    func onAcceptPressed()
+    func onBlockPressed()
+}
+
+public class ChatContactRequestBar: UIView, InputItem {
+    public var inputBarAccessoryView: InputBarAccessoryView?
+    public var parentStackViewPosition: InputStackView.Position?
+    public func textViewDidChangeAction(with textView: InputTextView) {}
+    public func keyboardSwipeGestureAction(with gesture: UISwipeGestureRecognizer) {}
+    public func keyboardEditingEndsAction() {}
+    public func keyboardEditingBeginsAction() {}
+
+    weak var delegate: ChatContactRequestDelegate?
+
+    private lazy var acceptButton: UIButton = {
+        let view = UIButton()
+        view.setTitle(String.localized("accept"), for: .normal)
+        view.setTitleColor(.systemBlue, for: .normal)
+        view.translatesAutoresizingMaskIntoConstraints = false
+        return view
+    }()
+
+    private lazy var blockButton: UIButton = {
+        let view = UIButton()
+        view.setTitle(String.localized("block"), for: .normal)
+        view.setTitleColor(.systemBlue, for: .normal)
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.isUserInteractionEnabled = true
+        return view
+    }()
+
+    private lazy var mainContentView: UIStackView = {
+        let view = UIStackView(arrangedSubviews: [acceptButton, blockButton])
+        view.axis = .horizontal
+        view.distribution = .fillEqually
+        view.alignment = .center
+        view.translatesAutoresizingMaskIntoConstraints = false
+        return view
+    }()
+
+    convenience init() {
+        self.init(frame: .zero)
+
+    }
+
+    public override init(frame: CGRect) {
+        super.init(frame: frame)
+        self.setupSubviews()
+    }
+
+    required init(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    public func setupSubviews() {
+        addSubview(mainContentView)
+
+        addConstraints([
+            mainContentView.constraintAlignTopTo(self, paddingTop: 4),
+            mainContentView.constraintAlignBottomTo(self, paddingBottom: 4),
+            mainContentView.constraintAlignLeadingTo(self),
+            mainContentView.constraintAlignTrailingTo(self),
+        ])
+
+        backgroundColor = DcColors.chatBackgroundColor
+
+        let acceptGestureListener = UITapGestureRecognizer(target: self, action: #selector(onAcceptPressed))
+        acceptButton.addGestureRecognizer(acceptGestureListener)
+
+        let blockGestureListener = UITapGestureRecognizer(target: self, action: #selector(onBlockPressed))
+        blockButton.addGestureRecognizer(blockGestureListener)
+
+    }
+
+    @objc func onAcceptPressed() {
+        delegate?.onAcceptPressed()
+    }
+
+    @objc func onBlockPressed() {
+        delegate?.onBlockPressed()
+    }
+}
+

+ 1 - 0
deltachat-ios/en.lproj/Localizable.strings

@@ -801,3 +801,4 @@
 
 "perm_ios_explain_access_to_camera_denied" = "To take photos, capture videos or use the QR-Code scanner, open the system settings and enable \"Camera\".";
 "open_settings" = "Open Settings";
+"accept" = "Accept";

+ 1 - 0
scripts/untranslated.xml

@@ -12,4 +12,5 @@
     
     <string name="perm_ios_explain_access_to_camera_denied">To take photos, capture videos or use the QR-Code scanner, open the system settings and enable \"Camera\".</string>
     <string name="open_settings">Open Settings</string>
+    <string name="accept">Accept</string>
 </resources>