You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.5 KiB

2 years ago
//
// TelephoneBookViewControllers.swift
// FireBoltt
2 years ago
//
// Created by ecell on 2022/8/25.
// Copyright © 2022 Sheldon. All rights reserved.
//
import UIKit
import Contacts
class TelephoneBookViewControllers: ViewController {
2 years ago
var items:[String] = []
var seleteArr:NSMutableArray = []
var tableView:UITableView?
override func loadView() {
super.loadView()
}
override func makeUI() {
super.makeUI()
let rightItem = UIBarButtonItem.baseBarButtonItem(normalImg: "", highImg: nil, title: MultiLanguageKey_FB.saveFB.localized, target: self, action: #selector(clickSave))
2 years ago
navigationItem.rightBarButtonItem = rightItem
}
override func viewDidLoad() {
super.viewDidLoad()
self.monitor()
//
self.tableView = UITableView(frame: self.view.frame, style:UITableView.Style.plain)
self.tableView!.delegate = self
self.tableView!.dataSource = self
self.tableView!.register(UITableViewCell.self, forCellReuseIdentifier: "SwiftCell")
//
self.tableView!.allowsMultipleSelection = true
self.view.addSubview(self.tableView!)
items = BluetoothToolFireBoltt.contactPeploe() as! [String]
2 years ago
//print(items as Any)
self.tableView!.reloadData()
}
@objc func clickSave() {
if (self.seleteArr.count != 0) {
SVProgressHUD.show()
BluetoothService.shared.syncContactWithBleCmdType(seleteArr: self.seleteArr)
}
else
{
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.selectNoPhoneFB.localized)
2 years ago
}
}
func monitor() {
///
Observable.of(kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdSuccess)),
kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdTimeout)))
.merge()
.subscribe(onNext: { [weak self] notification in
guard let `self` = self, let cmd = notification.object as? BleCMD_FireBoltt else { return }
2 years ago
let isSuccess = notification.name.rawValue == CmdSuccess
switch cmd {
case .syncContact:
if isSuccess {
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.syncDataSucceedFB.localized)
2 years ago
self.navigationController?.popViewController(animated: true)
return
}
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.setFailFB.localized)
2 years ago
default: break
}
})
.disposed(by: rx.disposeBag)
}
}
extension TelephoneBookViewControllers: UITableViewDelegate {
2 years ago
//
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = self.tableView?.cellForRow(at: indexPath)
cell?.accessoryType = .checkmark
self.seleteArr.addObjects(from: [self.items[indexPath.row]])
NSLog("选中%@",self.seleteArr)
}
//
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let cell = self.tableView?.cellForRow(at: indexPath)
cell?.accessoryType = .none
self.seleteArr.removeObjects(in: [self.items[indexPath.row]])
NSLog("取消%@",self.seleteArr)
}
}
extension TelephoneBookViewControllers: UITableViewDataSource {
2 years ago
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identify:String = "SwiftCell"
let cell = tableView.dequeueReusableCell(withIdentifier: identify, for: indexPath)
cell.selectionStyle = UITableViewCell.SelectionStyle.none
cell.textLabel?.numberOfLines = 0;
cell.textLabel?.text = self.items[indexPath.row]
//
// cell.tintColor = UIColor.brown
if let _ = tableView.indexPathsForSelectedRows?.firstIndex(of: indexPath){
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
return cell
}
}