From e310595e4c08cdd7f88288fbedb2b9051045306d Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 29 Jan 2018 23:26:47 -0800 Subject: [PATCH] added ability to tag friend --- Podfile.lock | 2 +- TSWeChat.xcodeproj/project.pbxproj | 50 ++++++++++++++++++- .../TSChatViewController+Interaction.swift | 27 ++++++++++ .../Contacts/TSContactsViewController.swift | 37 ++++++++++++-- 4 files changed, 110 insertions(+), 6 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 9d50090..4960663 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -79,4 +79,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 00f851ab2cafeab39b5ffb648f84b8cbdc34cb13 -COCOAPODS: 1.2.0 +COCOAPODS: 1.3.1 diff --git a/TSWeChat.xcodeproj/project.pbxproj b/TSWeChat.xcodeproj/project.pbxproj index af2d2b0..9d5a37e 100644 --- a/TSWeChat.xcodeproj/project.pbxproj +++ b/TSWeChat.xcodeproj/project.pbxproj @@ -848,13 +848,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-TSWeChat-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; A4299EA1E4F2C96BC7D82600 /* [CP] Embed Pods Frameworks */ = { @@ -863,9 +866,54 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-TSWeChat/Pods-TSWeChat-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework", + "${BUILT_PRODUCTS_DIR}/BSGridCollectionViewLayout/BSGridCollectionViewLayout.framework", + "${BUILT_PRODUCTS_DIR}/BSImagePicker/BSImagePicker.framework", + "${BUILT_PRODUCTS_DIR}/Cent/Cent.framework", + "${BUILT_PRODUCTS_DIR}/Dollar/Dollar.framework", + "${BUILT_PRODUCTS_DIR}/INTULocationManager/INTULocationManager.framework", + "${BUILT_PRODUCTS_DIR}/KeychainAccess/KeychainAccess.framework", + "${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework", + "${BUILT_PRODUCTS_DIR}/ObjectMapper/ObjectMapper.framework", + "${BUILT_PRODUCTS_DIR}/RxBlocking/RxBlocking.framework", + "${BUILT_PRODUCTS_DIR}/RxCocoa/RxCocoa.framework", + "${BUILT_PRODUCTS_DIR}/RxSwift/RxSwift.framework", + "${BUILT_PRODUCTS_DIR}/SVProgressHUD/SVProgressHUD.framework", + "${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework", + "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework", + "${BUILT_PRODUCTS_DIR}/TSVoiceConverter/TSVoiceConverter.framework", + "${BUILT_PRODUCTS_DIR}/TimedSilver/TimedSilver.framework", + "${BUILT_PRODUCTS_DIR}/UIColor_Hex_Swift/UIColor_Hex_Swift.framework", + "${BUILT_PRODUCTS_DIR}/UIImageViewModeScaleAspect/UIImageViewModeScaleAspect.framework", + "${BUILT_PRODUCTS_DIR}/XCGLogger/XCGLogger.framework", + "${BUILT_PRODUCTS_DIR}/XLActionController/XLActionController.framework", + "${BUILT_PRODUCTS_DIR}/YYText/YYText.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/BSGridCollectionViewLayout.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/BSImagePicker.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cent.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Dollar.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/INTULocationManager.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeychainAccess.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kingfisher.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectMapper.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxBlocking.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxCocoa.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxSwift.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SVProgressHUD.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TSVoiceConverter.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TimedSilver.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/UIColor_Hex_Swift.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/UIImageViewModeScaleAspect.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/XCGLogger.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/XLActionController.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YYText.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift b/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift index a93ab78..132ad2b 100644 --- a/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift +++ b/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift @@ -14,6 +14,13 @@ import MobileCoreServices // 分享更多里面的 Button 交互 extension TSChatViewController: ChatShareMoreViewDelegate { + //提朋友 + func tagFriend() { + let viewController = TSContactsViewController.ts_initFromNib() as! TSContactsViewController + viewController.delegate = self + self.ts_presentViewController(viewController, completion: nil) + } + //选择打开相册 func chatShareMoreViewPhotoTaped() { self.ts_presentImagePickerController( @@ -224,6 +231,9 @@ extension TSChatViewController: ChatEmotionInputViewDelegate { // MARK: - @protocol UITextViewDelegate extension TSChatViewController: UITextViewDelegate { func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { + if text == "@" { + tagFriend() + } if text == "\n" { //点击发送文字,包含表情 self.chatSendText() @@ -316,6 +326,23 @@ extension TSChatViewController: TSChatCellDelegate { } } +protocol TagContactDelegate { + func didTag(_ contact: String) +} + +extension TSChatViewController: TagContactDelegate { + func didTag(_ contact: String) { + self.dismiss(animated: true, completion: nil) + self.chatActionBarView.inputTextView.becomeFirstResponder() + let pinedContact = "@" + contact + " " + if let text = self.chatActionBarView.inputTextView.text { + self.chatActionBarView.inputTextView.text = text + " " + pinedContact + } else { + self.chatActionBarView.inputTextView.text = pinedContact + } + } +} + diff --git a/TSWeChat/Classes/Contacts/TSContactsViewController.swift b/TSWeChat/Classes/Contacts/TSContactsViewController.swift index 009234a..2c82db8 100644 --- a/TSWeChat/Classes/Contacts/TSContactsViewController.swift +++ b/TSWeChat/Classes/Contacts/TSContactsViewController.swift @@ -22,6 +22,8 @@ class TSContactsViewController: UIViewController { fileprivate var sortedkeys = [String]() //UITableView 右侧索引栏的 value fileprivate var dataDict: Dictionary? + var delegate: TagContactDelegate? + override func viewDidLoad() { super.viewDidLoad() self.title = "通讯录" @@ -31,7 +33,8 @@ class TSContactsViewController: UIViewController { self.listTableView.estimatedRowHeight = 54 self.listTableView.sectionIndexColor = UIColor.darkGray self.listTableView.tableFooterView = self.footerView - + + self.setUpNavBar() self.fetchContactList() } @@ -94,6 +97,31 @@ class TSContactsViewController: UIViewController { self.listTableView.reloadData() } } + + func handleCancel() { + self.dismiss(animated: true, completion: nil) + } + + func setUpNavBar() { + var isModal: Bool { + if presentingViewController != nil { + return true + } + if navigationController?.presentingViewController?.presentedViewController === navigationController { + return true + } + if let presentingVC = tabBarController?.presentingViewController, presentingVC is UITabBarController { + return true + } + return false + } + + if isModal { + self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(handleCancel)) + } else { + self.navigationItem.rightBarButtonItem = nil + } + } deinit { log.verbose("deinit") @@ -124,8 +152,9 @@ extension TSContactsViewController: UITableViewDelegate { tableView.deselectRow(at: indexPath, animated: true) let section = indexPath.section let row = indexPath.row -// let key = self.sortedkeys[indexPath.section] -// let dataArray: NSMutableArray = self.dataDict![key]! + let key = self.sortedkeys[indexPath.section] + let dataArray: NSMutableArray = self.dataDict![key]! + let model = dataArray[indexPath.row] as! ContactModel if section == 0 { let type = ContactModelEnum(rawValue: row)! @@ -140,7 +169,7 @@ extension TSContactsViewController: UITableViewDelegate { break } } else { - + delegate?.didTag(model.chineseName!) } } }