|
@@ -12,9 +12,19 @@ class ChatListController: UITableViewController {
|
|
|
private var msgChangedObserver: NSObjectProtocol?
|
|
|
private var msgsNoticedObserver: NSObjectProtocol?
|
|
|
private var incomingMsgObserver: NSObjectProtocol?
|
|
|
+ private var connectivityChangedObserver: NSObjectProtocol?
|
|
|
|
|
|
private weak var timer: Timer?
|
|
|
|
|
|
+ private lazy var titleView: UILabel = {
|
|
|
+ let view = UILabel()
|
|
|
+ let navTapGesture = UITapGestureRecognizer(target: self, action: #selector(onNavigationTitleTapped))
|
|
|
+ view.addGestureRecognizer(navTapGesture)
|
|
|
+ view.isUserInteractionEnabled = true
|
|
|
+
|
|
|
+ return view
|
|
|
+ }()
|
|
|
+
|
|
|
private lazy var searchController: UISearchController = {
|
|
|
let searchController = UISearchController(searchResultsController: nil)
|
|
|
searchController.searchResultsUpdater = viewModel
|
|
@@ -82,7 +92,9 @@ class ChatListController: UITableViewController {
|
|
|
dcContext.addDeviceMessage(label: "update_1_20b_ios", msg: msg)
|
|
|
|
|
|
// create view
|
|
|
+ navigationItem.titleView = titleView
|
|
|
updateTitle()
|
|
|
+
|
|
|
viewModel.refreshData()
|
|
|
|
|
|
if RelayHelper.sharedInstance.isForwarding() {
|
|
@@ -113,6 +125,12 @@ class ChatListController: UITableViewController {
|
|
|
queue: nil) { [weak self] _ in
|
|
|
self?.refreshInBg()
|
|
|
}
|
|
|
+ connectivityChangedObserver = nc.addObserver(forName: dcNotificationConnectivityChanged,
|
|
|
+ object: nil,
|
|
|
+ queue: nil) { [weak self] _ in
|
|
|
+ self?.updateTitle()
|
|
|
+ }
|
|
|
+
|
|
|
nc.addObserver(
|
|
|
self,
|
|
|
selector: #selector(applicationDidBecomeActive(_:)),
|
|
@@ -140,6 +158,9 @@ class ChatListController: UITableViewController {
|
|
|
if let msgsNoticedObserver = self.msgsNoticedObserver {
|
|
|
nc.removeObserver(msgsNoticedObserver)
|
|
|
}
|
|
|
+ if let connectivityChangedObserver = self.connectivityChangedObserver {
|
|
|
+ nc.removeObserver(connectivityChangedObserver)
|
|
|
+ }
|
|
|
// remove non-block observers
|
|
|
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
|
|
|
NotificationCenter.default.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
|
|
@@ -150,6 +171,26 @@ class ChatListController: UITableViewController {
|
|
|
emptySearchStateLabel.addCenteredTo(parentView: view)
|
|
|
}
|
|
|
|
|
|
+ @objc
|
|
|
+ public func onNavigationTitleTapped() {
|
|
|
+ logger.debug("on navigation title tapped")
|
|
|
+ }
|
|
|
+
|
|
|
+ func getConnectivityString(conenctedString: String) -> String {
|
|
|
+ let connectivity = dcContext.getConnectivity()
|
|
|
+ if connectivity >= DC_CONNECTIVITY_CONNECTED {
|
|
|
+ return conenctedString
|
|
|
+ } else if connectivity >= DC_CONNECTIVITY_WORKING {
|
|
|
+ return String.localized("connectivity_getting_new_msgs")
|
|
|
+ } else if connectivity >= DC_CONNECTIVITY_CONNECTING {
|
|
|
+ return String.localized("connectivity_connecting")
|
|
|
+ } else {
|
|
|
+ return String.localized("connectivity_not_connected")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// MARK: - configuration
|
|
|
private func configureTableView() {
|
|
|
tableView.register(ContactCell.self, forCellReuseIdentifier: chatCellReuseIdentifier)
|
|
@@ -341,15 +382,17 @@ class ChatListController: UITableViewController {
|
|
|
// MARK: updates
|
|
|
private func updateTitle() {
|
|
|
if RelayHelper.sharedInstance.isForwarding() {
|
|
|
- title = String.localized("forward_to")
|
|
|
+ titleView.text = String.localized("forward_to")
|
|
|
if !viewModel.isArchive {
|
|
|
navigationItem.setLeftBarButton(cancelButton, animated: true)
|
|
|
}
|
|
|
} else {
|
|
|
- title = viewModel.isArchive ? String.localized("chat_archived_chats_title") :
|
|
|
- String.localized("pref_chats")
|
|
|
+ let connectedText: String = viewModel.isArchive ? String.localized("chat_archived_chats_title") :
|
|
|
+ String.localized("app_name")
|
|
|
+ titleView.text = getConnectivityString(conenctedString: connectedText)
|
|
|
navigationItem.setLeftBarButton(nil, animated: true)
|
|
|
}
|
|
|
+ titleView.sizeToFit()
|
|
|
}
|
|
|
|
|
|
func handleChatListUpdate() {
|