2017-07-10 05:23:55 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Aram Sargsyan
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-07-08 23:06:29 +00:00
|
|
|
|
|
|
|
#import "ShareViewController.h"
|
2017-07-24 12:56:31 +00:00
|
|
|
#import "SegmentedViewController.h"
|
2017-07-30 17:29:38 +00:00
|
|
|
#import "RoomsListViewController.h"
|
|
|
|
#import "FallbackViewController.h"
|
2017-08-26 08:58:17 +00:00
|
|
|
#import "ShareDataSource.h"
|
2017-08-10 22:38:47 +00:00
|
|
|
#import "ShareExtensionManager.h"
|
2017-07-08 23:06:29 +00:00
|
|
|
|
2017-07-24 12:56:31 +00:00
|
|
|
|
|
|
|
@interface ShareViewController ()
|
|
|
|
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *masterContainerView;
|
|
|
|
@property (weak, nonatomic) IBOutlet UILabel *tittleLabel;
|
|
|
|
@property (weak, nonatomic) IBOutlet UIView *contentView;
|
|
|
|
|
|
|
|
@property (nonatomic) SegmentedViewController *segmentedViewController;
|
|
|
|
|
2017-08-25 09:55:37 +00:00
|
|
|
@property (nonatomic) id shareExtensionManagerDidChangeMXSessionObserver;
|
|
|
|
|
2017-07-24 12:56:31 +00:00
|
|
|
|
|
|
|
@end
|
2017-07-08 23:06:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@implementation ShareViewController
|
|
|
|
|
|
|
|
#pragma mark - Lifecycle
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
2017-08-21 20:33:06 +00:00
|
|
|
[self configureViews];
|
2017-07-24 12:56:31 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 09:55:37 +00:00
|
|
|
- (void)destroy
|
2017-07-24 12:56:31 +00:00
|
|
|
{
|
2017-08-25 09:55:37 +00:00
|
|
|
[super destroy];
|
2017-07-08 23:06:29 +00:00
|
|
|
|
2017-08-25 09:55:37 +00:00
|
|
|
if (self.shareExtensionManagerDidChangeMXSessionObserver)
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self.shareExtensionManagerDidChangeMXSessionObserver];
|
|
|
|
self.shareExtensionManagerDidChangeMXSessionObserver = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self resetContentView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resetContentView
|
|
|
|
{
|
2017-08-18 15:30:38 +00:00
|
|
|
// Empty the content view
|
|
|
|
NSArray *subviews = self.contentView.subviews;
|
|
|
|
for (UIView *subview in subviews)
|
|
|
|
{
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release the current segmented view controller if any
|
|
|
|
if (self.segmentedViewController)
|
|
|
|
{
|
2017-08-25 09:55:37 +00:00
|
|
|
[self.segmentedViewController removeFromParentViewController];
|
|
|
|
|
2017-08-21 12:07:49 +00:00
|
|
|
// Release correctly all the existing data source and view controllers.
|
2017-08-18 15:30:38 +00:00
|
|
|
[self.segmentedViewController destroy];
|
|
|
|
self.segmentedViewController = nil;
|
|
|
|
}
|
2017-08-25 09:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Private
|
|
|
|
|
|
|
|
- (void)configureViews
|
|
|
|
{
|
|
|
|
self.masterContainerView.layer.cornerRadius = 7;
|
|
|
|
|
|
|
|
[self resetContentView];
|
2017-08-18 15:30:38 +00:00
|
|
|
|
2017-09-08 15:02:45 +00:00
|
|
|
if ([ShareExtensionManager sharedManager].userAccount)
|
2017-07-30 17:29:38 +00:00
|
|
|
{
|
|
|
|
self.tittleLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), @""];
|
|
|
|
[self configureSegmentedViewController];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSDictionary *infoDictionary = [NSBundle mainBundle].infoDictionary;
|
|
|
|
NSString *bundleDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
|
|
|
|
self.tittleLabel.text = bundleDisplayName;
|
|
|
|
[self configureFallbackViewController];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureSegmentedViewController
|
|
|
|
{
|
2017-07-24 12:56:31 +00:00
|
|
|
self.segmentedViewController = [SegmentedViewController segmentedViewController];
|
2017-07-30 17:29:38 +00:00
|
|
|
|
2017-07-24 22:08:41 +00:00
|
|
|
NSArray *titles = @[NSLocalizedStringFromTable(@"title_rooms", @"Vector", nil) , NSLocalizedStringFromTable(@"title_people", @"Vector", nil)];
|
2017-07-30 17:29:38 +00:00
|
|
|
|
|
|
|
void (^failureBlock)() = ^void() {
|
2017-08-11 16:33:50 +00:00
|
|
|
[self dismissViewControllerAnimated:YES completion:^{
|
2017-08-17 22:27:56 +00:00
|
|
|
[[ShareExtensionManager sharedManager] terminateExtensionCanceled:NO];
|
2017-08-11 16:33:50 +00:00
|
|
|
}];
|
2017-07-30 17:29:38 +00:00
|
|
|
};
|
|
|
|
|
2017-08-26 08:58:17 +00:00
|
|
|
ShareDataSource *roomsDataSource = [[ShareDataSource alloc] initWithMode:DataSourceModeRooms];
|
2017-08-21 12:07:49 +00:00
|
|
|
RoomsListViewController *roomsViewController = [RoomsListViewController recentListViewController];
|
|
|
|
roomsViewController.failureBlock = failureBlock;
|
|
|
|
[roomsViewController displayList:roomsDataSource];
|
2017-08-10 22:38:47 +00:00
|
|
|
|
2017-08-26 08:58:17 +00:00
|
|
|
ShareDataSource *peopleDataSource = [[ShareDataSource alloc] initWithMode:DataSourceModePeople];
|
2017-08-21 12:07:49 +00:00
|
|
|
RoomsListViewController *peopleViewController = [RoomsListViewController recentListViewController];
|
|
|
|
peopleViewController.failureBlock = failureBlock;
|
|
|
|
[peopleViewController displayList:peopleDataSource];
|
2017-08-10 22:38:47 +00:00
|
|
|
|
|
|
|
[self.segmentedViewController initWithTitles:titles viewControllers:@[roomsViewController, peopleViewController] defaultSelected:0];
|
2017-07-10 05:23:55 +00:00
|
|
|
|
2017-07-24 12:56:31 +00:00
|
|
|
[self addChildViewController:self.segmentedViewController];
|
|
|
|
[self.contentView addSubview:self.segmentedViewController.view];
|
|
|
|
[self.segmentedViewController didMoveToParentViewController:self];
|
2017-07-08 23:06:29 +00:00
|
|
|
|
2017-07-30 17:29:38 +00:00
|
|
|
[self autoPinSubviewEdges:self.segmentedViewController.view toSuperviewEdges:self.contentView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureFallbackViewController
|
|
|
|
{
|
|
|
|
FallbackViewController *fallbackVC = [FallbackViewController new];
|
|
|
|
[self addChildViewController:fallbackVC];
|
|
|
|
[self.contentView addSubview:fallbackVC.view];
|
|
|
|
[fallbackVC didMoveToParentViewController:self];
|
|
|
|
|
|
|
|
[self autoPinSubviewEdges:fallbackVC.view toSuperviewEdges:self.contentView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)autoPinSubviewEdges:(UIView *)subview toSuperviewEdges:(UIView *)superview
|
|
|
|
{
|
|
|
|
subview.translatesAutoresizingMaskIntoConstraints = NO;
|
|
|
|
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeWidth multiplier:1 constant:0];
|
2017-07-24 12:56:31 +00:00
|
|
|
widthConstraint.active = YES;
|
2017-07-30 17:29:38 +00:00
|
|
|
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeHeight multiplier:1 constant:0];
|
2017-07-24 12:56:31 +00:00
|
|
|
heightConstraint.active = YES;
|
2017-07-30 17:29:38 +00:00
|
|
|
NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
|
2017-07-24 12:56:31 +00:00
|
|
|
centerXConstraint.active = YES;
|
2017-07-30 17:29:38 +00:00
|
|
|
NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
|
2017-07-24 12:56:31 +00:00
|
|
|
centerYConstraint.active = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
|
|
|
- (IBAction)close:(UIButton *)sender
|
|
|
|
{
|
2017-08-11 16:33:50 +00:00
|
|
|
[self dismissViewControllerAnimated:YES completion:^{
|
2017-08-17 22:27:56 +00:00
|
|
|
[[ShareExtensionManager sharedManager] terminateExtensionCanceled:YES];
|
2017-08-11 16:33:50 +00:00
|
|
|
}];
|
2017-07-08 23:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|