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"
|
2021-10-18 13:30:32 +00:00
|
|
|
#import "ShareDataSource.h"
|
2017-07-30 17:29:38 +00:00
|
|
|
#import "RoomsListViewController.h"
|
|
|
|
#import "FallbackViewController.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
|
|
|
|
2021-10-26 15:42:33 +00:00
|
|
|
#import "GeneratedInterface-Swift.h"
|
2021-06-29 12:03:57 +00:00
|
|
|
|
2021-10-18 13:30:32 +00:00
|
|
|
@interface ShareViewController () <MXKRecentListViewControllerDelegate, ShareDataSourceDelegate>
|
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;
|
2021-10-18 13:30:32 +00:00
|
|
|
|
|
|
|
@property (nonatomic, strong) RoomsListViewController *roomListViewController;
|
2021-10-14 09:05:28 +00:00
|
|
|
@property (nonatomic, strong) ShareDataSource *roomDataSource;
|
2021-10-18 13:30:32 +00:00
|
|
|
|
|
|
|
@property (nonatomic, strong) FallbackViewController *fallbackViewController;
|
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) 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];
|
2021-10-18 13:30:32 +00:00
|
|
|
[self.shareButton setEnabled:NO];
|
2021-10-14 09:05:28 +00:00
|
|
|
|
2021-10-18 13:30:32 +00:00
|
|
|
[self configureWithState:self.state roomDataSource:self.roomDataSource];
|
2017-07-24 12:56:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
- (void)configureWithState:(ShareViewControllerAccountState)state
|
|
|
|
roomDataSource:(ShareDataSource *)roomDataSource
|
2017-07-24 12:56:31 +00:00
|
|
|
{
|
2021-10-14 09:05:28 +00:00
|
|
|
self.state = state;
|
|
|
|
self.roomDataSource = roomDataSource;
|
2021-10-18 13:30:32 +00:00
|
|
|
self.roomDataSource.shareDelegate = self;
|
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-18 13:30:32 +00:00
|
|
|
#pragma mark - ShareDataSourceDelegate
|
2021-10-14 09:05:28 +00:00
|
|
|
|
2021-10-18 13:30:32 +00:00
|
|
|
- (void)shareDataSourceDidChangeSelectedRoomIdentifiers:(ShareDataSource *)shareDataSource
|
2021-10-14 09:05:28 +00:00
|
|
|
{
|
2021-10-18 13:30:32 +00:00
|
|
|
self.shareButton.enabled = (shareDataSource.selectedRoomIdentifiers.count > 0);
|
2021-10-14 09:05:28 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
[self configureSegmentedViewController];
|
2021-10-18 13:30:32 +00:00
|
|
|
[self.shareButton setHidden:NO];
|
|
|
|
|
|
|
|
if (self.type == ShareViewControllerTypeSend) {
|
|
|
|
[self.titleLabel setText:[VectorL10n sendTo:@""]];
|
|
|
|
[self.shareButton setTitle:[VectorL10n sendTo:@""] forState:UIControlStateNormal];
|
|
|
|
} else {
|
|
|
|
[self.titleLabel setText:[VectorL10n roomEventActionForward]];
|
|
|
|
[self.shareButton setTitle:[VectorL10n roomEventActionForward] forState:UIControlStateNormal];
|
|
|
|
}
|
2017-07-30 17:29:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self configureFallbackViewController];
|
2021-10-18 13:30:32 +00:00
|
|
|
[self.shareButton setHidden:NO];
|
|
|
|
|
|
|
|
self.titleLabel.text = [AppInfo.current displayName];
|
2017-07-30 17:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureSegmentedViewController
|
|
|
|
{
|
2021-10-18 13:30:32 +00:00
|
|
|
self.roomListViewController = [RoomsListViewController recentListViewController];
|
|
|
|
[self.roomListViewController displayList:self.roomDataSource];
|
|
|
|
|
|
|
|
[self addChildViewController:self.roomListViewController];
|
|
|
|
[self.contentView vc_addSubViewMatchingParent:self.roomListViewController.view];
|
|
|
|
[self.roomListViewController didMoveToParentViewController:self];
|
2017-07-30 17:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureFallbackViewController
|
|
|
|
{
|
2021-10-18 13:30:32 +00:00
|
|
|
self.fallbackViewController = [FallbackViewController new];
|
|
|
|
[self addChildViewController:self.fallbackViewController];
|
|
|
|
[self.contentView vc_addSubViewMatchingParent:self.fallbackViewController.view];
|
|
|
|
[self.fallbackViewController didMoveToParentViewController:self];
|
2017-07-30 17:29:38 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:05:28 +00:00
|
|
|
- (void)resetContentView
|
2017-07-30 17:29:38 +00:00
|
|
|
{
|
2021-10-18 13:30:32 +00:00
|
|
|
[self.roomListViewController willMoveToParentViewController:nil];
|
|
|
|
[self.roomListViewController.view removeFromSuperview];
|
|
|
|
[self.roomListViewController removeFromParentViewController];
|
2021-10-14 09:05:28 +00:00
|
|
|
|
2021-10-18 13:30:32 +00:00
|
|
|
[self.fallbackViewController willMoveToParentViewController:nil];
|
|
|
|
[self.fallbackViewController.view removeFromSuperview];
|
|
|
|
[self.fallbackViewController removeFromParentViewController];
|
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
|
|
|
|
{
|
2021-10-18 13:30:32 +00:00
|
|
|
if (self.roomDataSource.selectedRoomIdentifiers.count == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-14 09:05:28 +00:00
|
|
|
|
2021-10-18 13:30:32 +00:00
|
|
|
[self.delegate shareViewController:self didRequestShareForRoomIdentifiers:self.roomDataSource.selectedRoomIdentifiers];
|
2021-10-14 09:05:28 +00:00
|
|
|
}
|
2017-07-08 23:06:29 +00:00
|
|
|
|
|
|
|
@end
|