| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- //
- // JCSingleSettingViewController.swift
- // JChat
- //
- // Created by deng on 2017/4/5.
- // Copyright © 2017年 HXHG. All rights reserved.
- //
- import UIKit
- import JMessage
- class JCSingleSettingViewController: UIViewController, CustomNavigation {
-
- var user: JMSGUser!
- override func viewDidLoad() {
- super.viewDidLoad()
- _init()
- }
- private lazy var tableView: UITableView = {
- var tableView = UITableView(frame: CGRect(x: 0, y: 0, width: self.view.width, height: self.view.height), style: .grouped)
- tableView.separatorStyle = .none
- tableView.delegate = self
- tableView.dataSource = self
- tableView.sectionIndexColor = UIColor(netHex: 0x2dd0cf)
- tableView.sectionIndexBackgroundColor = .clear
- tableView.register(JCSingleSettingCell.self, forCellReuseIdentifier: "JCSingleSettingCell")
- tableView.register(JCButtonCell.self, forCellReuseIdentifier: "JCButtonCell")
- tableView.register(JCMineInfoCell.self, forCellReuseIdentifier: "JCMineInfoCell")
- return tableView
- }()
-
- fileprivate lazy var leftButton = UIButton(frame: CGRect(x: 0, y: 0, width: 60, height: 65 / 3))
-
- //MARK: - private func
- private func _init() {
- self.title = "聊天设置"
- view.backgroundColor = .white
- view.addSubview(tableView)
- customLeftBarButton(delegate: self)
- }
- }
- extension JCSingleSettingViewController: UITableViewDelegate, UITableViewDataSource {
-
- func numberOfSections(in tableView: UITableView) -> Int {
- return 3
- }
-
- public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-
- switch section {
- case 0:
- return 1
- case 1:
- return 3
- case 2:
- return 1
- default:
- return 0
- }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- switch indexPath.section {
- case 0:
- return 105
- case 1:
- return 45
- case 2:
- return 40
- default:
- return 45
- }
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- if section == 0 {
- return 0.0001
- }
- return 10
- }
-
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if indexPath.section == 0 {
- return tableView.dequeueReusableCell(withIdentifier: "JCSingleSettingCell", for: indexPath)
- }
- if indexPath.section == 2 {
- return tableView.dequeueReusableCell(withIdentifier: "JCButtonCell", for: indexPath)
- }
- return tableView.dequeueReusableCell(withIdentifier: "JCMineInfoCell", for: indexPath)
- }
-
- func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
- cell.selectionStyle = .none
- if indexPath.section == 2 {
- guard let cell = cell as? JCButtonCell else {
- return
- }
- if !user.isFriend {
- cell.buttonColor = UIColor(netHex: 0xFB4747)
- cell.buttonTitle = "添加好友"
- cell.delegate = self
- } else {
- cell.buttonColor = UIColor(netHex: 0xFB4747)
- cell.buttonTitle = "删除好友"
- cell.delegate = self
- }
- return
- }
- cell.accessoryType = .disclosureIndicator
- if indexPath.section == 0 {
- guard let cell = cell as? JCSingleSettingCell else {
- return
- }
- cell.bindData(user)
- cell.delegate = self
- cell.accessoryType = .none
- return
- }
- guard let cell = cell as? JCMineInfoCell else {
- return
- }
- if indexPath.section == 1 && indexPath.row == 1 {
- cell.delegate = self
- cell.accessoryType = .none
- cell.isShowSwitch = true
- }
- switch indexPath.row {
- case 0:
- cell.title = "聊天文件"
- case 1:
- cell.isSwitchOn = user.isNoDisturb
- cell.title = "消息免打扰"
- // case 1:
- // cell.isSwitchOn = JMessage.isSetGlobalNoDisturb()
- // cell.title = "清理缓存"
- case 2:
- cell.title = "清空聊天记录"
- default:
- break
- }
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- tableView.deselectRow(at: indexPath, animated: true)
- if indexPath.section == 1 {
- switch indexPath.row {
- case 0:
- let vc = FileManagerViewController()
- let conv = JMSGConversation.singleConversation(withUsername: user.username)
- vc.conversation = conv
- navigationController?.pushViewController(vc, animated: true)
- case 2:
- let actionSheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "清空聊天记录")
- actionSheet.tag = 1001
- actionSheet.show(in: view)
- case 3:
- break
- default:
- break
- }
- }
- }
- }
- extension JCSingleSettingViewController: UIActionSheetDelegate {
- func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAt buttonIndex: Int) {
- // if actionSheet.tag == 1001 {
- // // SDK 暂无该功能
- // }
-
- if actionSheet.tag == 1001 {
- if buttonIndex == 1 {
- let conv = JMSGConversation.singleConversation(withUsername: user.username)
- conv?.deleteAllMessages()
- NotificationCenter.default.post(name: Notification.Name(rawValue: kDeleteAllMessage), object: nil)
- MBProgressHUD_JChat.show(text: "成功清空", view: view)
- }
- }
- }
-
- }
- extension JCSingleSettingViewController: JCMineInfoCellDelegate {
- func mineInfoCell(clickSwitchButton button: UISwitch, indexPath: IndexPath?) {
- if user.isNoDisturb != button.isOn {
- MBProgressHUD_JChat.showMessage(message: "修改中", toView: view)
- user.setIsNoDisturb(button.isOn, handler: { (result, error) in
- MBProgressHUD_JChat.hide(forView: self.view, animated: true)
- if error == nil {
- MBProgressHUD_JChat.show(text: "修改成功", view: self.view)
- } else {
- MBProgressHUD_JChat.show(text: "修改失败", view: self.view)
- }
- })
- }
- }
- }
- extension JCSingleSettingViewController: JCButtonCellDelegate {
- func buttonCell(clickButton button: UIButton) {
- if user.isFriend {
- let alertView = UIAlertView(title: "删除好友", message: "是否确认删除该好友?", delegate: self, cancelButtonTitle: "取消", otherButtonTitles: "删除")
- alertView.show()
- } else {
- let vc = JCAddFriendViewController()
- vc.user = user
- navigationController?.pushViewController(vc, animated: true)
- }
- }
- }
- extension JCSingleSettingViewController: UIAlertViewDelegate {
- func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
- if buttonIndex == 1 {
- JMSGFriendManager.removeFriend(withUsername: user.username, appKey: user.appKey, completionHandler: { (result, error) in
- if error == nil {
- let conv = JMSGConversation.singleConversation(withUsername: self.user.username)
- if conv != nil {
- JMSGConversation.deleteSingleConversation(withUsername: self.user.username)
- }
- NotificationCenter.default.post(name: Notification.Name(rawValue: kUpdateFriendList), object: nil)
- self.navigationController?.popToRootViewController(animated: true)
- } else {
- MBProgressHUD_JChat.show(text: "\(String.errorAlert(error! as NSError))", view: self.view)
- }
- })
- }
- }
- }
- extension JCSingleSettingViewController: JCSingleSettingCellDelegate {
- func singleSettingCell(clickAddButton button: UIButton) {
- let vc = JCUpdateMemberViewController()
- vc.isAddMember = false
- vc.currentUser = user
- navigationController?.pushViewController(vc, animated: true)
- }
-
- func singleSettingCell(clickAvatorButton button: UIButton) {
- let vc = JCUserInfoViewController()
- vc.user = user
- vc.isOnConversation = true
- navigationController?.pushViewController(vc, animated: true)
- }
- }
- extension JCSingleSettingViewController: UIGestureRecognizerDelegate {
- public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
- return true
- }
- }
|