mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-25 11:02:48 +02:00
MESSENGER-2762 Initial Merge
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) 2021 BWI GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#import "RecentsBannerViewController.h"
|
||||
#import "GeneratedInterface-Swift.h"
|
||||
|
||||
@interface RecentsBannerViewController ()
|
||||
{
|
||||
TopBannerViewController *topBannerViewController;
|
||||
bool bannersInitialized;
|
||||
bool isBannerVisible;
|
||||
}
|
||||
- (void)setTopBannerViewConstraints;
|
||||
- (void)showTopBanner;
|
||||
- (void)hideTopBanner;
|
||||
@end
|
||||
|
||||
@implementation RecentsBannerViewController
|
||||
|
||||
+ (bool)isBannerHidden {
|
||||
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
|
||||
NSString *version = [info objectForKey:@"CFBundleShortVersionString"];
|
||||
if( [version isEqual:[[NSUserDefaults standardUserDefaults] objectForKey:@"de.bwi.messenger.top_banner_confirmation"]] )
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
bannersInitialized = FALSE;
|
||||
isBannerVisible = FALSE;
|
||||
}
|
||||
|
||||
- (void)onMatrixSessionChange
|
||||
{
|
||||
[super onMatrixSessionChange];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
if( [BuildSettings showTopBanner] ) {
|
||||
[self showTopBanner];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
if( bannersInitialized && [BuildSettings showTopBanner] ) {
|
||||
[self hideTopBanner];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTopBannerViewConstraints
|
||||
{
|
||||
NSLayoutConstraint *alignTopConstraint = [NSLayoutConstraint
|
||||
constraintWithItem:topBannerViewController.view
|
||||
attribute:NSLayoutAttributeTop
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.view
|
||||
attribute:NSLayoutAttributeTop
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
[[self view] addConstraint:alignTopConstraint];
|
||||
|
||||
NSLayoutConstraint *alignLeadingConstraint = [NSLayoutConstraint
|
||||
constraintWithItem:topBannerViewController.view
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.view
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
[[self view] addConstraint:alignLeadingConstraint];
|
||||
|
||||
NSLayoutConstraint *alignTrailingConstraint = [NSLayoutConstraint
|
||||
constraintWithItem:topBannerViewController.view
|
||||
attribute:NSLayoutAttributeTrailing
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.view
|
||||
attribute:NSLayoutAttributeTrailing
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
[[self view] addConstraint:alignTrailingConstraint];
|
||||
|
||||
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint
|
||||
constraintWithItem:topBannerViewController.view
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:NULL
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1.0
|
||||
constant:130];
|
||||
[[self view] addConstraint:heightConstraint];
|
||||
}
|
||||
|
||||
- (void)setupTopBanner
|
||||
{
|
||||
NSMutableArray *bannerControllers = [NSMutableArray array];
|
||||
|
||||
MXSession* session = [self mainSession];
|
||||
if( !session || bannersInitialized)
|
||||
return;
|
||||
|
||||
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
||||
|
||||
FeatureBannerVisibilityService *service = [[FeatureBannerVisibilityService alloc] initWithMxSession:session];
|
||||
[service isUnreadWithVersion:version completion:^(BOOL unread) {
|
||||
if (unread) {
|
||||
[bannerControllers addObject:[[FeatureBannerViewController alloc] initWithSession:session version:version]];
|
||||
|
||||
self->topBannerViewController = [[TopBannerViewController alloc] initWithControllers: bannerControllers];
|
||||
|
||||
// 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.hide_top_banner" object:NULL queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
|
||||
[self hideTopBanner];
|
||||
[self->topBannerViewController removeAdvertiseViewControllers];
|
||||
}];
|
||||
|
||||
self->bannersInitialized = TRUE;
|
||||
|
||||
if( [BuildSettings showTopBanner] ) {
|
||||
[self showTopBanner];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)showTopBanner
|
||||
{
|
||||
if( isBannerVisible ) {
|
||||
return; // nothing to do because the banner is already visible for the user
|
||||
}
|
||||
|
||||
if( [topBannerViewController.advertiseViewControllers count] > 0 )
|
||||
{
|
||||
// add child view controller
|
||||
[self addChildViewController:topBannerViewController];
|
||||
[[topBannerViewController view] setTranslatesAutoresizingMaskIntoConstraints:FALSE];
|
||||
[[topBannerViewController view] setBounds:CGRectMake(0, 0, self.view.bounds.size.width, 100)];
|
||||
[[self view] addSubview:[topBannerViewController view]];
|
||||
[topBannerViewController didMoveToParentViewController:self];
|
||||
|
||||
[self setTopBannerViewConstraints];
|
||||
|
||||
isBannerVisible = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hideTopBanner
|
||||
{
|
||||
if( [[topBannerViewController advertiseViewControllers] count] > 0 )
|
||||
{
|
||||
// remove child view controller
|
||||
[topBannerViewController willMoveToParentViewController:nil];
|
||||
[topBannerViewController.view removeFromSuperview];
|
||||
[topBannerViewController removeFromParentViewController];
|
||||
}
|
||||
|
||||
isBannerVisible = FALSE;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user