MESSENGER-2638 new layout feature banner

This commit is contained in:
JanNiklas Grabowski
2023-03-28 10:38:04 +00:00
parent 89bff2aa64
commit c6396cbd1a
20 changed files with 341 additions and 242 deletions

View File

@@ -56,6 +56,9 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
// Timer to not refresh publicRoomsDirectoryDataSource on every keystroke.
NSTimer *publicRoomsTriggerTimer;
// bwi: new feature banner
bool shouldHideFeatureBanner;
}
@property (nonatomic, strong, readwrite) RecentsDataSourceSections *sections;
@@ -77,6 +80,8 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
- (instancetype)initWithMatrixSession:(MXSession *)mxSession
recentsListService:(id<RecentsListServiceProtocol>)theRecentsListService
{
// bwi: new feature banner
shouldHideFeatureBanner = TRUE;
if (self = [super initWithMatrixSession:mxSession])
{
processingQueue = dispatch_queue_create("RecentsDataSource", DISPATCH_QUEUE_SERIAL);
@@ -101,6 +106,9 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
[self registerAllChatsSettingsUpdateNotification];
self.allChatsFilterOptions = [AllChatsFilterOptions new];
// bwi: new feature banner
[self registerFeatureBannerReadStatusChangedNotification];
[self shouldShowFeatureBanner];
}
return self;
}
@@ -109,6 +117,8 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
{
[self unregisterSpaceServiceDidBuildGraphNotification];
[self unregisterAllChatsSettingsUpdateNotification];
// bwi: new feature banner
[self unregisterFeatureBannerNotification];
}
#pragma mark - Properties
@@ -221,6 +231,11 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
- (RecentsDataSourceSections *)makeDataSourceSections
{
NSMutableArray *types = [NSMutableArray array];
// bwi: add new feature banner
if (!shouldHideFeatureBanner && BWIBuildSettings.shared.showTopBanner){
[types addObject:@(RecentsDataSourceSectionTypeFeatureBanner)];
}
if (self.recentsDataSourceMode == RecentsDataSourceModeRoomInvites)
{
[types addObject:@(RecentsDataSourceSectionTypeInvites)];
@@ -643,6 +658,10 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
NSUInteger count = 0;
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
// bwi: new feature banner
if (sectionType == RecentsDataSourceSectionTypeFeatureBanner) {
count = 1;
}
if (sectionType == RecentsDataSourceSectionTypeCrossSigningBanner && self.crossSigningBannerDisplay != CrossSigningBannerDisplayNone)
{
count = 1;
@@ -725,7 +744,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
(sectionType == RecentsDataSourceSectionTypeInvites && self.recentsDataSourceMode == RecentsDataSourceModeAllChats) ||
(sectionType == RecentsDataSourceSectionTypeAllChats && !self.allChatsFilterOptions.optionsCount) ||
(sectionType == RecentsDataSourceSectionTypeAllChats && self.currentSpace != nil && self.currentSpace.childRoomIds.count == 0) ||
sectionType == RecentsDataSourceSectionTypePersonalNotes )
sectionType == RecentsDataSourceSectionTypePersonalNotes || sectionType == RecentsDataSourceSectionTypeFeatureBanner)
{
return 0.0;
}
@@ -1911,4 +1930,63 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
return NO;
}
#pragma mark - bwi new feature banner
- (void) shouldShowFeatureBanner
{
if (BWIBuildSettings.shared.showTopBanner){
MXSession* session = [self mxSession];
if(!session)
return;
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
FeatureBannerVisibilityService *featureBannerService = [[FeatureBannerVisibilityService alloc] initWithMxSession:session];
[featureBannerService isUnreadWithVersion:version completion:^(BOOL unread) {
if (unread) {
// this notification will be called either if the user clicked on the banner or wants to hide it
[[NSNotificationCenter defaultCenter] addObserverForName:@"de.bwi.messenger.hide_top_banner" object:NULL queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
[self markFeatureBannerAsRead];
}];
// this notification will be called either if the user clicked on the banner or wants to hide it using a swipe gesture
[[NSNotificationCenter defaultCenter] addObserverForName:@"de.bwi.messenger.mark_top_banner_as_read" object:NULL queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
[self markFeatureBannerAsRead];
}];
self->shouldHideFeatureBanner = FALSE;
} else {
self->shouldHideFeatureBanner = TRUE;
}
[self.delegate dataSource:self didCellChange:nil];
}];
} else {
self->shouldHideFeatureBanner = TRUE;
}
}
- (void) registerFeatureBannerReadStatusChangedNotification
{
[[NSNotificationCenter defaultCenter] addObserverForName:@"de.bwi.messenger.mark_top_banner_as_unread" object:NULL queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
[self shouldShowFeatureBanner];
}];
}
- (void) markFeatureBannerAsRead
{
MXSession* session = [self mxSession];
if(!session)
return;
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
FeatureBannerVisibilityService *featureBannerService = [[FeatureBannerVisibilityService alloc] initWithMxSession:session];
[featureBannerService markAsReadWithVersion:version];
self->shouldHideFeatureBanner = TRUE;
[self.delegate dataSource:self didCellChange:nil];
}
- (void)unregisterFeatureBannerNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"de.bwi.messenger.mark_top_banner_as_read" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"de.bwi.messenger.hide_top_banner" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"de.bwi.messenger.mark_top_banner_as_unread" object:nil];
}
@end