|
@@ -12,11 +12,6 @@ import Speech
|
|
|
|
|
|
class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
|
|
|
|
|
|
- deinit {
|
|
|
- print(#function, ">>>> TADAA")
|
|
|
- NotificationCenter.default.removeObserver(self)
|
|
|
- }
|
|
|
-
|
|
|
var isChooser: ((String, String) -> ())?
|
|
|
|
|
|
var isAdmin: Bool = false
|
|
@@ -32,24 +27,24 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
var voiceItem = UIBarButtonItem()
|
|
|
|
|
|
var childrenMenu = [UIAction]()
|
|
|
+
|
|
|
+ var groupMap: [String:Int] = [:]
|
|
|
|
|
|
lazy var searchController: UISearchController = {
|
|
|
var searchController = UISearchController(searchResultsController: nil)
|
|
|
searchController.delegate = self
|
|
|
searchController.searchResultsUpdater = self
|
|
|
-// searchController.searchBar.showsBookmarkButton = true
|
|
|
searchController.searchBar.autocapitalizationType = .none
|
|
|
searchController.searchBar.delegate = self
|
|
|
- searchController.searchBar.placeholder = "Search chats & messages".localized()
|
|
|
searchController.searchBar.barTintColor = .secondaryColor
|
|
|
searchController.searchBar.searchTextField.backgroundColor = .secondaryColor
|
|
|
searchController.obscuresBackgroundDuringPresentation = false
|
|
|
+
|
|
|
return searchController
|
|
|
}()
|
|
|
|
|
|
lazy var segment: UISegmentedControl = {
|
|
|
- print("Chat".localized())
|
|
|
- var segment = UISegmentedControl(items: ["Chat".localized(), "Group".localized()])
|
|
|
+ var segment = UISegmentedControl(items: ["Chats".localized(), "Groups".localized()])
|
|
|
segment.sizeToFit()
|
|
|
segment.selectedSegmentIndex = 0
|
|
|
segment.addTarget(self, action: #selector(segmentChanged(sender:)), for: .valueChanged)
|
|
@@ -118,46 +113,10 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// navigationController?.title = "Start Conversation"
|
|
|
+ cancelSearchButton = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(cancel(sender:)))
|
|
|
|
|
|
- // navigationController?.navigationBar.prefersLargeTitles = true
|
|
|
+ var childrenMenu : [UIAction] = []
|
|
|
|
|
|
- cancelSearchButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancel(sender:)))
|
|
|
-
|
|
|
- var childrenMenu : [UIAction] = [
|
|
|
-// UIAction(title: "Create Group", image: UIImage(systemName: "person.and.person"), handler: {[weak self](_) in
|
|
|
-// let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "createGroupNav") as! UINavigationController
|
|
|
-// let vc = controller.topViewController as! GroupCreateViewController
|
|
|
-// vc.isDismiss = { id in
|
|
|
-// let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "groupDetailView") as! GroupDetailViewController
|
|
|
-// controller.data = id
|
|
|
-// self?.navigationController?.show(controller, sender: nil)
|
|
|
-// }
|
|
|
-// self?.navigationController?.present(controller, animated: true, completion: nil)
|
|
|
-// }),
|
|
|
-// UIAction(title: "Add Friends", image: UIImage(systemName: "person.badge.plus"), handler: {[weak self](_) in
|
|
|
-// let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "addFriendNav") as! UINavigationController
|
|
|
-// if let vc = controller.viewControllers.first as? AddFriendTableViewController {
|
|
|
-// vc.isDismiss = {
|
|
|
-// self?.getContacts {
|
|
|
-// DispatchQueue.main.async {
|
|
|
-// self?.tableView.reloadData()
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// self?.navigationController?.present(controller, animated: true, completion: nil)
|
|
|
-// }),
|
|
|
-// UIAction(title: "Configure Email", image: UIImage(systemName: "mail"), handler: {[weak self](_) in
|
|
|
-//
|
|
|
-// }),
|
|
|
-// UIAction(title: "Favorite Messages", image: UIImage(systemName: "star"), handler: {[weak self](_) in
|
|
|
-// let editorStaredVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "staredVC") as! EditorStarMessages
|
|
|
-// self?.navigationController?.show(editorStaredVC, sender: nil)
|
|
|
-// }),
|
|
|
- ]
|
|
|
- //debug only
|
|
|
-// isAdmin = true
|
|
|
if(isAdmin){
|
|
|
childrenMenu.append(UIAction(title: "Broadcast Message", image: UIImage(systemName: "envelope.open"), handler: {[weak self](_) in
|
|
|
let controller = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "broadcastNav")
|
|
@@ -165,16 +124,12 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
}))
|
|
|
}
|
|
|
|
|
|
-// let menu = UIMenu(title: "", children: childrenMenu)
|
|
|
menuItem = UIBarButtonItem(image: UIImage(systemName: "square.and.pencil"), style: .plain, target: self, action: #selector(startConversation))
|
|
|
voiceItem = UIBarButtonItem(image: UIImage(systemName: "mic.fill"), style: .plain, target: self, action: #selector(recordAudio))
|
|
|
|
|
|
-// tabBarController?.navigationItem.leftBarButtonItem = cancelSearchButton
|
|
|
tabBarController?.navigationItem.leftBarButtonItem = voiceItem
|
|
|
tabBarController?.navigationItem.rightBarButtonItem = menuItem
|
|
|
tabBarController?.navigationItem.searchController = searchController
|
|
|
-// navigationItem.searchController = searchController
|
|
|
-// navigationItem.hidesSearchBarWhenScrolling = true
|
|
|
|
|
|
definesPresentationContext = true
|
|
|
|
|
@@ -300,6 +255,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
// tabBarController?.navigationItem.leftBarButtonItem = cancelSearchButton
|
|
|
self.navigationController?.navigationBar.topItem?.title = Bundle.main.displayName
|
|
|
+ self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
|
|
|
let cpaasMode = PrefsUtil.getCpaasMode()
|
|
|
let isBurger = cpaasMode == PrefsUtil.CPAAS_MODE_BURGER
|
|
|
navigationController?.navigationBar.backgroundColor = .clear
|
|
@@ -311,9 +267,15 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
tabBarController?.navigationItem.leftBarButtonItem = voiceItem
|
|
|
tabBarController?.navigationItem.searchController = searchController
|
|
|
tabBarController?.navigationItem.rightBarButtonItem = menuItem
|
|
|
- let randomInt = Int.random(in: 1..<2)
|
|
|
+ let randomInt = Int.random(in: 1..<10)
|
|
|
backgroundImage.image = UIImage(named: "pb_lbackground_\(randomInt)")
|
|
|
getData()
|
|
|
+ searchController.searchBar.placeholder = "Search chats & messages".localized()
|
|
|
+ searchController.searchBar.setValue("Cancel".localized(), forKey: "cancelButtonText")
|
|
|
+ if segment.numberOfSegments == 2 {
|
|
|
+ segment.setTitle("Chats".localized(), forSegmentAt: 0)
|
|
|
+ segment.setTitle("Groups".localized(), forSegmentAt: 1)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
@@ -394,18 +356,22 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
getChats {
|
|
|
self.getContacts {
|
|
|
self.getGroups { g1 in
|
|
|
- self.getOpenGroups(listGroups: g1, completion: { g in
|
|
|
- self.groups.removeAll()
|
|
|
- self.groups.append(contentsOf: g1)
|
|
|
- for og in g {
|
|
|
- if self.groups.first(where: { $0.id == og.id }) == nil {
|
|
|
- self.groups.append(og)
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ self.getOpenGroups(listGroups: g1, completion: { g in
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.groups.removeAll()
|
|
|
+ self.groups.append(contentsOf: g1)
|
|
|
+ for og in g {
|
|
|
+ if self.groups.first(where: { $0.id == og.id }) == nil {
|
|
|
+ self.groups.append(og)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.tableView.reloadData()
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.tableView.reloadData()
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -500,9 +466,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
if group.official == "1" {
|
|
|
let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
|
|
|
- if cursorUser.string(forColumnIndex: 0) == "23" || cursorUser.string(forColumnIndex: 0) == "24" {
|
|
|
- group.childs.append(contentsOf: getGroupRecursive(fmdb: fmdb, parent: group.id))
|
|
|
- }
|
|
|
+ group.childs.append(contentsOf: getGroupRecursive(fmdb: fmdb, parent: group.id))
|
|
|
cursorUser.close()
|
|
|
}
|
|
|
} else if group.official != "1"{
|
|
@@ -641,6 +605,52 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
}
|
|
|
group.isSelected = !group.isSelected
|
|
|
+ if !group.isSelected{
|
|
|
+ var sects = 0
|
|
|
+ var sect = indexPath.section
|
|
|
+ var id = group.id
|
|
|
+ if let e = groupMap[id] {
|
|
|
+ var loooop = true
|
|
|
+ repeat {
|
|
|
+ let c = sect + 1
|
|
|
+ if isFilltering {
|
|
|
+ if let o = self.fillteredData[c] as? Group {
|
|
|
+ if o.parent == id {
|
|
|
+ sects = sects + 1
|
|
|
+ sect = c
|
|
|
+ id = o.id
|
|
|
+ (self.fillteredData[c] as! Group).isSelected = false
|
|
|
+ self.groupMap.removeValue(forKey: (self.fillteredData[c] as! Group).id)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ loooop = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if self.groups[c].parent == id {
|
|
|
+ sects = sects + 1
|
|
|
+ sect = c
|
|
|
+ id = self.groups[c].id
|
|
|
+ self.groups[c].isSelected = false
|
|
|
+ self.groupMap.removeValue(forKey: self.groups[c].id)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ loooop = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } while(loooop)
|
|
|
+ }
|
|
|
+ for i in stride(from: sects, to: 0, by: -1){
|
|
|
+ if isFilltering {
|
|
|
+ self.fillteredData.remove(at: indexPath.section + i)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.groups.remove(at: indexPath.section + i)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ groupMap.removeValue(forKey: group.id)
|
|
|
+ }
|
|
|
if group.groupType == "NOTJOINED" {
|
|
|
let alert = UIAlertController(title: "Do you want to join this group?".localized(), message: "Groups : \(group.name)\nMembers: \(group.by)".localized(), preferredStyle: .alert)
|
|
|
alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
|
|
@@ -648,6 +658,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
self.joinOpenGroup(groupId: group.id, completion: { result in
|
|
|
if result {
|
|
|
DispatchQueue.main.async {
|
|
|
+ self.groupMap.removeAll()
|
|
|
let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorGroupVC") as! EditorGroup
|
|
|
editorGroupVC.hidesBottomBarWhenPushed = true
|
|
|
editorGroupVC.unique_l_pin = group.id
|
|
@@ -666,6 +677,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
return
|
|
|
}
|
|
|
+ self.groupMap.removeAll()
|
|
|
let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorGroupVC") as! EditorGroup
|
|
|
editorGroupVC.hidesBottomBarWhenPushed = true
|
|
|
editorGroupVC.unique_l_pin = groupId
|
|
@@ -676,13 +688,21 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
} else {
|
|
|
getGroups(id: group.id) { g in
|
|
|
DispatchQueue.main.async {
|
|
|
+ print("index path section: \(indexPath.section)")
|
|
|
+ print("index path row: \(indexPath.row)")
|
|
|
+// print("index path item: \(indexPath.item)")
|
|
|
if self.isFilltering {
|
|
|
- self.fillteredData.remove(at: indexPath.section)
|
|
|
- self.fillteredData.insert(contentsOf: g, at: indexPath.section)
|
|
|
+// self.fillteredData.remove(at: indexPath.section)
|
|
|
+ if self.fillteredData[indexPath.section] is Group {
|
|
|
+ self.groupMap[(self.fillteredData[indexPath.section] as! Group).id] = 1
|
|
|
+ self.fillteredData.insert(contentsOf: g, at: indexPath.section + 1)
|
|
|
+ }
|
|
|
} else {
|
|
|
- self.groups.remove(at: indexPath.section)
|
|
|
- self.groups.insert(contentsOf: g, at: indexPath.section)
|
|
|
+// self.groups.remove(at: indexPath.section)
|
|
|
+ self.groupMap[self.groups[indexPath.section].id] = 1
|
|
|
+ self.groups.insert(contentsOf: g, at: indexPath.section + 1)
|
|
|
}
|
|
|
+ print("groupMap: \(self.groupMap)")
|
|
|
tableView.reloadData()
|
|
|
}
|
|
|
}
|
|
@@ -714,14 +734,18 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
var value = 0
|
|
|
if isFilltering {
|
|
|
- if segment.selectedSegmentIndex == 1, let groups = fillteredData as? [Group] {
|
|
|
+ if segment.selectedSegmentIndex == 2, let groups = fillteredData as? [Group] {
|
|
|
let group = groups[section]
|
|
|
if group.isSelected {
|
|
|
- value = group.childs.count + 1
|
|
|
+ if let g = groupMap[group.id] {
|
|
|
+ value = 1
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ value = group.childs.count + 1
|
|
|
+ }
|
|
|
} else {
|
|
|
value = 1
|
|
|
}
|
|
|
- return value
|
|
|
}
|
|
|
return fillteredData.count
|
|
|
}
|
|
@@ -731,7 +755,12 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
case 1:
|
|
|
let group = groups[section]
|
|
|
if group.isSelected {
|
|
|
- value = group.childs.count + 1
|
|
|
+ if let g = groupMap[group.id] {
|
|
|
+ value = 1
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ value = group.childs.count + 1
|
|
|
+ }
|
|
|
} else {
|
|
|
value = 1
|
|
|
}
|
|
@@ -775,14 +804,8 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
imageView.image = UIImage(named: "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
|
|
|
}
|
|
|
} else {
|
|
|
- getImage(name: data.profile, placeholderImage: UIImage(named: data.pin == "-999" ? "pb_ball" : "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, completion: { result, isDownloaded, image in
|
|
|
+ getImage(name: data.profile, placeholderImage: UIImage(named: data.pin == "-999" ? "pb_button" : "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, tableView: tableView, indexPath: indexPath, completion: { result, isDownloaded, image in
|
|
|
imageView.image = image
|
|
|
- if !result {
|
|
|
- imageView.tintColor = .mainColor
|
|
|
- }
|
|
|
- if isDownloaded {
|
|
|
- tableView.reloadRows(at: [indexPath], with: .none)
|
|
|
- }
|
|
|
})
|
|
|
}
|
|
|
let titleView = UILabel()
|
|
@@ -883,10 +906,19 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
} else {
|
|
|
content.text = group.name
|
|
|
}
|
|
|
+ if group.childs.count > 0 {
|
|
|
+ let iconName = (group.isSelected) ? "chevron.up.circle" : "chevron.down.circle"
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: iconName))
|
|
|
+ imageView.tintColor = .black
|
|
|
+ cell.accessoryView = imageView
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ cell.accessoryView = nil
|
|
|
+ cell.accessoryType = .none
|
|
|
+ }
|
|
|
content.imageProperties.maximumSize = CGSize(width: 40, height: 40)
|
|
|
- getImage(name: group.profile, placeholderImage: UIImage(named: "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true) { result, isDownloaded, image in
|
|
|
+ getImage(name: group.profile, placeholderImage: UIImage(named: "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, tableView: tableView, indexPath: indexPath) { result, isDownloaded, image in
|
|
|
content.image = image
|
|
|
- tableView.reloadRows(at: [indexPath], with: .none)
|
|
|
}
|
|
|
cell.contentConfiguration = content
|
|
|
default:
|