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-07-08 23:06:29 +00:00
|
|
|
|
2021-06-29 12:03:57 +00:00
|
|
|
#import "ThemeService.h"
|
2021-10-14 09:05:28 +00:00
|
|
|
|
|
|
|
#ifdef IS_SHARE_EXTENSION
|
2021-06-29 12:03:57 +00:00
|
|
|
#import "RiotShareExtension-Swift.h"
|
2021-10-14 09:05:28 +00:00
|
|
|
#else
|
|
|
|
#import "Riot-Swift.h"
|
|
|
|
#endif
|
2021-06-29 12:03:57 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
@interface ShareViewController () <MXKRecentListViewControllerDelegate>
|
2017-07-24 12:56:31 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
@property (nonatomic, assign, readonly) ShareViewControllerType type;
|
2017-07-24 12:56:31 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
@property (nonatomic, assign) ShareViewControllerAccountState state;
|
|
|
|
@property (nonatomic, strong) ShareDataSource *roomDataSource;
|
|
|
|
@property (nonatomic, strong) ShareDataSource *peopleDataSource;
|
2017-07-24 12:56:31 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
@property (nonatomic, weak) IBOutlet UIView *masterContainerView;
|
|
|
|
@property (nonatomic, weak) IBOutlet UIButton *cancelButton;
|
|
|
|
@property (nonatomic, weak) IBOutlet UILabel *titleLabel;
|
|
|
|
@property (nonatomic, weak) IBOutlet UIButton *shareButton;
|
|
|
|
@property (nonatomic, weak) IBOutlet UIView *contentView;
|
2017-07-24 12:56:31 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
@property (nonatomic, strong) SegmentedViewController *segmentedViewController;
|
2017-08-25 09:55:37 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
@property (nonatomic, strong) MXKPieChartHUD *hudView;
|
2017-07-24 12:56:31 +00:00
|
|
|
|
|
|
|
@end
|
2017-07-08 23:06:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@implementation ShareViewController
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
- (instancetype)initWithType:(ShareViewControllerType)type
|
|
|
|
currentState:(ShareViewControllerAccountState)state
|
|
|
|
{
|
|
|
|
if (self = [super init])
|
|
|
|
{
|
|
|
|
_type = type;
|
|
|
|
_state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
2017-07-08 23:06:29 +00:00
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
2017-09-29 08:37:54 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.masterContainerView setBackgroundColor:ThemeService.shared.theme.baseColor];
|
|
|
|
[self.masterContainerView.layer setCornerRadius:7.0];
|
2021-06-29 12:03:57 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.titleLabel setTextColor:ThemeService.shared.theme.textPrimaryColor];
|
2017-09-29 08:37:54 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.cancelButton setTintColor:ThemeService.shared.theme.tintColor];
|
|
|
|
[self.cancelButton setTitle:[VectorL10n cancel] forState:UIControlStateNormal];
|
2017-09-29 08:37:54 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.shareButton setTintColor:ThemeService.shared.theme.tintColor];
|
|
|
|
|
|
|
|
[self configureWithState:self.state roomDataSource:self.roomDataSource peopleDataSource:self.peopleDataSource];
|
2017-07-24 12:56:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
- (void)configureWithState:(ShareViewControllerAccountState)state
|
|
|
|
roomDataSource:(ShareDataSource *)roomDataSource
|
|
|
|
peopleDataSource:(ShareDataSource *)peopleDataSource
|
2017-07-24 12:56:31 +00:00
|
|
|
{
|
2021-10-14 09:05:28 +00:00
|
|
|
self.state = state;
|
|
|
|
self.roomDataSource = roomDataSource;
|
|
|
|
self.peopleDataSource = peopleDataSource;
|
2017-07-08 23:06:29 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
if (!self.isViewLoaded) {
|
|
|
|
return;
|
2017-08-25 09:55:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
[self configureViews];
|
2017-08-25 09:55:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:57:32 +00:00
|
|
|
- (void)showProgressIndicator
|
|
|
|
{
|
|
|
|
if (!self.hudView)
|
|
|
|
{
|
|
|
|
self.parentViewController.view.userInteractionEnabled = NO;
|
|
|
|
self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:[VectorL10n sending]];
|
|
|
|
[self.hudView setProgress:0.0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setProgress:(CGFloat)progress
|
|
|
|
{
|
|
|
|
[self.hudView setProgress:progress];
|
|
|
|
}
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
#pragma mark - MXKRecentListViewControllerDelegate
|
|
|
|
|
|
|
|
- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController
|
|
|
|
didSelectRoom:(NSString *)roomId
|
|
|
|
inMatrixSession:(MXSession *)mxSession
|
2017-08-25 09:55:37 +00:00
|
|
|
{
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.delegate shareViewControllerDidRequestShare:self forRoomIdentifier:roomId];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController
|
|
|
|
didSelectSuggestedRoom:(MXSpaceChildInfo *)childInfo
|
|
|
|
{
|
|
|
|
[self.delegate shareViewControllerDidRequestShare:self forRoomIdentifier:childInfo.childRoomId];
|
|
|
|
}
|
|
|
|
|
2017-08-25 09:55:37 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
|
|
|
- (void)configureViews
|
|
|
|
{
|
|
|
|
[self resetContentView];
|
2017-08-18 15:30:38 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
if (self.state == ShareViewControllerAccountStateConfigured)
|
2017-07-30 17:29:38 +00:00
|
|
|
{
|
2021-09-28 05:40:01 +00:00
|
|
|
self.titleLabel.text = [VectorL10n sendTo:@""];
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.shareButton setTitle:[VectorL10n roomEventActionForward] forState:UIControlStateNormal];
|
|
|
|
|
2017-07-30 17:29:38 +00:00
|
|
|
[self configureSegmentedViewController];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-14 09:05:28 +00:00
|
|
|
self.titleLabel.text = [AppInfo.current displayName];
|
2017-07-30 17:29:38 +00:00
|
|
|
[self configureFallbackViewController];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureSegmentedViewController
|
|
|
|
{
|
2017-08-21 12:07:49 +00:00
|
|
|
RoomsListViewController *roomsViewController = [RoomsListViewController recentListViewController];
|
2021-10-14 09:05:28 +00:00
|
|
|
[roomsViewController displayList:self.roomDataSource];
|
|
|
|
[roomsViewController setDelegate:self];
|
2017-08-10 22:38:47 +00:00
|
|
|
|
2017-08-21 12:07:49 +00:00
|
|
|
RoomsListViewController *peopleViewController = [RoomsListViewController recentListViewController];
|
2021-10-14 09:05:28 +00:00
|
|
|
[peopleViewController setDelegate:self];
|
|
|
|
[peopleViewController displayList:self.peopleDataSource];
|
2017-08-10 22:38:47 +00:00
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
self.segmentedViewController = [SegmentedViewController segmentedViewController];
|
|
|
|
[self.segmentedViewController initWithTitles:@[[VectorL10n titleRooms], [VectorL10n titlePeople]]
|
|
|
|
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];
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.contentView vc_addSubViewMatchingParent:self.segmentedViewController.view];
|
2017-07-24 12:56:31 +00:00
|
|
|
[self.segmentedViewController didMoveToParentViewController:self];
|
2017-07-30 17:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureFallbackViewController
|
|
|
|
{
|
|
|
|
FallbackViewController *fallbackVC = [FallbackViewController new];
|
|
|
|
[self addChildViewController:fallbackVC];
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.contentView vc_addSubViewMatchingParent:fallbackVC.view];
|
2017-07-30 17:29:38 +00:00
|
|
|
[fallbackVC didMoveToParentViewController:self];
|
|
|
|
}
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
- (void)resetContentView
|
2017-07-30 17:29:38 +00:00
|
|
|
{
|
2021-10-14 09:05:28 +00:00
|
|
|
NSArray *subviews = self.contentView.subviews;
|
|
|
|
for (UIView *subview in subviews)
|
|
|
|
{
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.segmentedViewController)
|
|
|
|
{
|
|
|
|
[self.segmentedViewController removeFromParentViewController];
|
|
|
|
|
|
|
|
[self.segmentedViewController destroy];
|
|
|
|
self.segmentedViewController = nil;
|
|
|
|
}
|
2017-07-24 12:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
- (IBAction)onCancelButtonTap:(UIButton *)sender
|
2017-07-24 12:56:31 +00:00
|
|
|
{
|
2021-10-14 09:05:28 +00:00
|
|
|
[self.delegate shareViewControllerDidRequestDismissal:self];
|
2017-07-08 23:06:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
- (IBAction)onShareButtonTap:(UIButton *)sender
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2017-07-08 23:06:29 +00:00
|
|
|
|
|
|
|
@end
|