mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
ea32e407a9
Updated the HomeVC, SettingsVC and GlobalSearch UI to use theming Removed the "fade view" gradients from the various screens Added a simple log to the PagedDatabaseObserver to make debugging easier Updated the FullConversationCell to also show the "read" state for messages Updated the read receipt icons to use SFSymbols directly Updated the PlaceholderIcon to use the PrimaryColour's as it's colour options
92 lines
3.1 KiB
Swift
92 lines
3.1 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import UIKit
|
|
import SessionMessagingKit
|
|
|
|
@objc(SNUserSelectionVC)
|
|
final class UserSelectionVC: BaseVC, UITableViewDataSource, UITableViewDelegate {
|
|
private let navBarTitle: String
|
|
private let usersToExclude: Set<String>
|
|
private let completion: (Set<String>) -> Void
|
|
private var selectedUsers: Set<String> = []
|
|
|
|
private lazy var users: [Profile] = {
|
|
return Profile
|
|
.fetchAllContactProfiles(excluding: usersToExclude)
|
|
}()
|
|
|
|
// MARK: - Components
|
|
|
|
@objc private lazy var tableView: UITableView = {
|
|
let result: UITableView = UITableView()
|
|
result.dataSource = self
|
|
result.delegate = self
|
|
result.separatorStyle = .none
|
|
result.backgroundColor = .clear
|
|
result.showsVerticalScrollIndicator = false
|
|
result.alwaysBounceVertical = false
|
|
result.register(view: UserCell.self)
|
|
|
|
return result
|
|
}()
|
|
|
|
// MARK: - Lifecycle
|
|
|
|
@objc(initWithTitle:excluding:completion:)
|
|
init(with title: String, excluding usersToExclude: Set<String>, completion: @escaping (Set<String>) -> Void) {
|
|
self.navBarTitle = title
|
|
self.usersToExclude = usersToExclude
|
|
self.completion = completion
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder: NSCoder) { preconditionFailure("Use UserSelectionVC.init(excluding:) instead.") }
|
|
override init(nibName: String?, bundle: Bundle?) { preconditionFailure("Use UserSelectionVC.init(excluding:) instead.") }
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
setNavBarTitle(navBarTitle)
|
|
|
|
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(handleDoneButtonTapped))
|
|
view.addSubview(tableView)
|
|
tableView.pin(to: view)
|
|
}
|
|
|
|
// MARK: - UITableViewDataSource
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return users.count
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell: UserCell = tableView.dequeue(type: UserCell.self, for: indexPath)
|
|
cell.update(
|
|
with: users[indexPath.row].id,
|
|
profile: users[indexPath.row],
|
|
isZombie: false,
|
|
accessory: .tick(isSelected: selectedUsers.contains(users[indexPath.row].id))
|
|
)
|
|
|
|
return cell
|
|
}
|
|
|
|
// MARK: - Interaction
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
if !selectedUsers.contains(users[indexPath.row].id) {
|
|
selectedUsers.insert(users[indexPath.row].id)
|
|
}
|
|
else {
|
|
selectedUsers.remove(users[indexPath.row].id)
|
|
}
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
tableView.reloadRows(at: [indexPath], with: .none)
|
|
}
|
|
|
|
@objc private func handleDoneButtonTapped() {
|
|
completion(selectedUsers)
|
|
navigationController!.popViewController(animated: true)
|
|
}
|
|
}
|