rotating the device lost the selection state of the home view tableview (#3906)

* rotating the device lost the selection state of the home view tableview

* changed indexpath based selection state restoration to uniqueIds of associated threads

* unified table data reload method call
This commit is contained in:
Martin Böttcher 2022-01-20 08:57:06 +01:00 committed by GitHub
parent 8163c9074c
commit 6f92b5eb7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -749,7 +749,7 @@ NSString *const kArchiveButtonPseudoGroup = @"kArchiveButtonPseudoGroup";
if (self.viewState.multiSelectState.isActive) {
[self.tableView setEditing:YES animated:NO];
[self.tableView reloadData];
[self reloadTableData];
[self willEnterMultiselectMode];
} else {
[self applyDefaultBackButton];

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -22,7 +22,30 @@ public extension HomeViewController {
func reloadTableData() {
AssertIsOnMainThread()
var selectedThreadIds: Set<String> = []
for indexPath in tableView.indexPathsForSelectedRows ?? [] {
if let key = tableDataSource.threadViewModel(forIndexPath: indexPath, expectsSuccess: false)?.threadRecord.uniqueId {
selectedThreadIds.insert(key)
}
}
tableView.reloadData()
if !selectedThreadIds.isEmpty {
var threadIdsToBeSelected = selectedThreadIds
for section in 0..<tableDataSource.numberOfSections(in: tableView) {
for row in 0..<tableDataSource.tableView(tableView, numberOfRowsInSection: section) {
let indexPath = IndexPath(row: row, section: section)
if let key = tableDataSource.threadViewModel(forIndexPath: indexPath, expectsSuccess: false)?.threadRecord.uniqueId, threadIdsToBeSelected.contains(key) {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
threadIdsToBeSelected.remove(key)
if threadIdsToBeSelected.isEmpty {
break
}
}
}
}
}
}
func updateCellVisibility() {