From da27091d8bd1302a8845c9abbefae9b7e1b98ac2 Mon Sep 17 00:00:00 2001 From: Gil Eluard Date: Fri, 5 Aug 2022 14:56:19 +0200 Subject: [PATCH] Conditionally hide room list tabs (#6533) * Conditionally hide room list tabs --- .../Recents/DataSources/RecentsDataSource.m | 6 ++++- .../MatrixSDK/RecentsListService.swift | 6 ++--- .../AllChatsFilterOptionListView.swift | 12 ++++++--- .../Home/AllChats/AllChatsFilterOptions.swift | 26 ++++++++++++++++++- changelog.d/6515.bugfix | 1 + 5 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 changelog.d/6515.bugfix diff --git a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m index 29aac7808..dcf25b5cd 100644 --- a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m +++ b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m @@ -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; } } diff --git a/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift b/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift index c0474a17b..64c19bb1a 100644 --- a/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift +++ b/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift @@ -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 diff --git a/Riot/Modules/Common/SectionHeaders/AllChatsFilterOptionListView.swift b/Riot/Modules/Common/SectionHeaders/AllChatsFilterOptionListView.swift index f0c681636..a13015853 100644 --- a/Riot/Modules/Common/SectionHeaders/AllChatsFilterOptionListView.swift +++ b/Riot/Modules/Common/SectionHeaders/AllChatsFilterOptionListView.swift @@ -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) } diff --git a/Riot/Modules/Home/AllChats/AllChatsFilterOptions.swift b/Riot/Modules/Home/AllChats/AllChatsFilterOptions.swift index 82917b0c7..b79aa59c1 100644 --- a/Riot/Modules/Home/AllChats/AllChatsFilterOptions.swift +++ b/Riot/Modules/Home/AllChats/AllChatsFilterOptions.swift @@ -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 } diff --git a/changelog.d/6515.bugfix b/changelog.d/6515.bugfix new file mode 100644 index 000000000..2c37e186e --- /dev/null +++ b/changelog.d/6515.bugfix @@ -0,0 +1 @@ +App Layout: Conditionally hide favourite and people list tabs