Conditionally hide room list tabs (#6533)

* Conditionally hide room list tabs
This commit is contained in:
Gil Eluard 2022-08-05 14:56:19 +02:00 committed by GitHub
parent a809185407
commit da27091d8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 8 deletions

View file

@ -66,7 +66,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
@property (nonatomic, strong) CrossSigningService *crossSigningService;
@property (nonatomic, strong) AllChatsFilterOptions *allChatsFilterOptions;
@property (nonatomic, strong) UIView *allChatsOptionsView;
@property (nonatomic, strong) AllChatsFilterOptionListView *allChatsOptionsView;
@end
@ -966,6 +966,10 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
if (self.allChatsOptionsView)
{
[self.allChatsFilterOptions updateWithFilterOptionListView:self.allChatsOptionsView
unreadsCount:1 // unreads is allways visible
favouritesCount:self.favoriteCellDataArray.count
directRoomsCount:self.peopleCellDataArray.count];
return self.allChatsOptionsView;
}
}

View file

@ -48,7 +48,7 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol {
private var favoritedRoomListDataFetcher: MXRoomListDataFetcher?
private var directRoomListDataFetcher: MXRoomListDataFetcher? {
switch mode {
case .home:
case .home, .allChats:
return directRoomListDataFetcherForHome
case .people:
return directRoomListDataFetcherForPeople
@ -87,7 +87,7 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol {
.favourites: [.favorited],
.people: [.invited, .directPeople],
.rooms: [.invited, .conversationRooms, .suggested],
.allChats: [.breadcrumbs, .favorited, .invited, .allChats, .lowPriority, .serverNotice, .suggested]
.allChats: [.breadcrumbs, .favorited, .directHome, .invited, .allChats, .lowPriority, .serverNotice, .suggested]
]
private var allFetchers: [MXRoomListDataFetcher] {
@ -460,7 +460,7 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol {
private var shouldShowDirect: Bool {
switch mode {
case .home:
case .home, .allChats:
return fetcherTypesForMode[mode]?.contains(.directHome) ?? false
case .people:
return fetcherTypesForMode[mode]?.contains(.directPeople) ?? false

View file

@ -71,6 +71,14 @@ class AllChatsFilterOptionListView: UIView, Themable {
setupView()
}
// MARK: - Public
func setSelectedOptionType(_ optionType: AllChatsLayoutFilterType, animated: Bool) {
UIView.animate(withDuration: animated ? 0.3 : 0) {
self.selectedOptionType = optionType
}
}
// MARK: - Themable
func update(theme: Theme) {
@ -117,9 +125,7 @@ extension AllChatsFilterOptionListView: TabListViewDelegate {
return
}
UIView.animate(withDuration: 0.3) {
self.selectedOptionType = optionType
}
self.setSelectedOptionType(optionType, animated: true)
selectionChanged?(optionType)
}

View file

@ -20,7 +20,7 @@ import UIKit
@objcMembers
class AllChatsFilterOptions: NSObject {
func createFilterListView() -> UIView? {
func createFilterListView() -> AllChatsFilterOptionListView? {
guard optionsCount > 0 else {
return nil
}
@ -47,6 +47,30 @@ class AllChatsFilterOptions: NSObject {
return filterOptionListView
}
func update(filterOptionListView: AllChatsFilterOptionListView, unreadsCount: Int, favouritesCount: Int, directRoomsCount: Int) {
let options = options.filter { option in
switch option.type {
case .all: return true
case .unreads: return unreadsCount > 0
case .favourites: return favouritesCount > 0
case .people: return directRoomsCount > 0
case .rooms: return false
default:
return false
}
}
var filterOptions: [AllChatsFilterOptionListView.Option] = [
AllChatsFilterOptionListView.Option(type: .all, name: VectorL10n.allChatsAllFilter)
]
filterOptions.append(contentsOf: options)
filterOptionListView.options = filterOptions
if !filterOptions.contains(where: { $0.type == filterOptionListView.selectedOptionType }) {
filterOptionListView.setSelectedOptionType(.all, animated: true)
AllChatsLayoutSettingsManager.shared.activeFilters = []
}
}
var optionsCount: Int {
return options.count
}

1
changelog.d/6515.bugfix Normal file
View file

@ -0,0 +1 @@
App Layout: Conditionally hide favourite and people list tabs