Commit 5de6f5ff authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[CRD iOS] Updating the side menu of the open source variant

This CL updates the open source implementation of the side menu so that
it also shows items from SideMenuItemsProvider. This make it easier for
developer to debug CRD for iOS on Chromium without checking out
ios_internal.

Bug: 786625
Change-Id: I784032e905cfdd78eeef122f302f464b443d2153
Reviewed-on: https://chromium-review.googlesource.com/780151Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519859}
parent 452bf634
......@@ -17,7 +17,7 @@ static HelpAndFeedback* g_helpAndFeedback;
#pragma mark - Public
- (void)presentFeedbackFlowWithContext:(NSString*)context {
NOTREACHED() << "This should be implemented by a subclass.";
NOTIMPLEMENTED() << "This should be implemented by a subclass.";
}
#pragma mark - Static Properties
......
......@@ -11,10 +11,12 @@
#import "ios/third_party/material_components_ios/src/components/AppBar/src/MaterialAppBar.h"
#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h"
#import "remoting/ios/app/remoting_theme.h"
#import "remoting/ios/app/side_menu_items.h"
#import "remoting/ios/facade/remoting_authentication.h"
#import "remoting/ios/facade/remoting_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "google_apis/google_api_keys.h"
#include "net/base/escape.h"
#include "remoting/base/string_resources.h"
......@@ -28,6 +30,7 @@ static UIColor* kBackgroundColor =
[UIColor colorWithRed:0.f green:0.67f blue:0.55f alpha:1.f];
namespace {
const char kChromotingAuthScopeValues[] =
"https://www.googleapis.com/auth/chromoting "
"https://www.googleapis.com/auth/googletalk "
......@@ -56,23 +59,18 @@ std::string GetAuthorizationCodeUri() {
@interface RemotingMenuViewController () {
MDCAppBar* _appBar;
NSMutableArray* _content;
NSArray<NSArray<SideMenuItem*>*>* _content;
}
@end
// This is the chromium version of the menu view controller. This will
// launch a web view to login and collect an oauth token to be able to login to
// the app without the standard google login flow.
// the app without the standard google login flow. It also loads and shows all
// other menu items from SideMenuItemsProvider.
//
// This class is majority boiler plate code to get a collection view.
// It will be replaced with a sidebar-like view in the future, but in
// chromium this is how we get an oauth token to login to the app.
// The official app's implementation is in //ios_internal.
//
// Note: this class is not localized, it will not be shipped to production.
//
// TODO(nicholss): This class needs to be split into a shareable view
// for chromium and prod to share.
//
@implementation RemotingMenuViewController
- (id)init {
......@@ -117,23 +115,38 @@ std::string GetAuthorizationCodeUri() {
self.styler.cellStyle = MDCCollectionViewCellStyleCard;
_content = [NSMutableArray array];
[_content addObject:@[
l10n_util::GetNSString(IDS_SIGN_IN_BUTTON),
l10n_util::GetNSString(IDS_SIGN_OUT_BUTTON)
]];
// Add the account management section to the beginning of the content.
__weak __typeof(self) weakSelf = self;
NSArray<SideMenuItem*>* accountManagementSection = @[
[[SideMenuItem alloc]
initWithTitle:l10n_util::GetNSString(IDS_SIGN_IN_BUTTON)
icon:nil
action:^{
[weakSelf didTapGetAccessCode];
}],
[[SideMenuItem alloc]
initWithTitle:l10n_util::GetNSString(IDS_SIGN_OUT_BUTTON)
icon:nil
action:^{
[weakSelf didTapLogout];
}]
];
NSMutableArray<NSArray<SideMenuItem*>*>* mutableContent =
[NSMutableArray arrayWithArray:SideMenuItemsProvider.sideMenuItems];
[mutableContent insertObject:accountManagementSection atIndex:0];
_content = mutableContent;
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:
(UICollectionView*)collectionView {
return (NSInteger)[_content count];
return _content.count;
}
- (NSInteger)collectionView:(UICollectionView*)collectionView
numberOfItemsInSection:(NSInteger)section {
return (NSInteger)[_content[(NSUInteger)section] count];
return _content[section].count;
}
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
......@@ -141,30 +154,9 @@ std::string GetAuthorizationCodeUri() {
MDCCollectionViewTextCell* cell = [collectionView
dequeueReusableCellWithReuseIdentifier:kReusableIdentifierItem
forIndexPath:indexPath];
cell.textLabel.text =
_content[(NSUInteger)indexPath.section][(NSUInteger)indexPath.item];
if (indexPath.section == 0 && indexPath.item == 0) {
MDCRaisedButton* accessCodeButton = [[MDCRaisedButton alloc] init];
[accessCodeButton setTitle:@"Get Access Code"
forState:UIControlStateNormal];
[accessCodeButton sizeToFit];
[accessCodeButton addTarget:self
action:@selector(didTapGetAccessCode:)
forControlEvents:UIControlEventTouchUpInside];
accessCodeButton.translatesAutoresizingMaskIntoConstraints = NO;
cell.accessoryView = accessCodeButton;
} else if (indexPath.section == 0 && indexPath.item == 1) {
MDCRaisedButton* logoutButton = [[MDCRaisedButton alloc] init];
[logoutButton setTitle:l10n_util::GetNSString(IDS_SIGN_OUT_BUTTON)
forState:UIControlStateNormal];
[logoutButton sizeToFit];
[logoutButton addTarget:self
action:@selector(didTapLogout:)
forControlEvents:UIControlEventTouchUpInside];
logoutButton.translatesAutoresizingMaskIntoConstraints = NO;
cell.accessoryView = logoutButton;
}
SideMenuItem* item = _content[indexPath.section][indexPath.item];
cell.textLabel.text = item.title;
cell.imageView.image = item.icon;
return cell;
}
......@@ -185,12 +177,24 @@ std::string GetAuthorizationCodeUri() {
return supplementaryView;
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView*)collectionView
didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
[super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
_content[indexPath.section][indexPath.item].action();
}
#pragma mark - <UICollectionViewDelegateFlowLayout>
- (CGSize)collectionView:(UICollectionView*)collectionView
layout:
(UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section {
// Only show the title if it's the account manangement section.
if (section != 0) {
return CGSizeZero;
}
return CGSizeMake(collectionView.bounds.size.width,
MDCCellDefaultOneLineHeight);
}
......@@ -201,10 +205,8 @@ std::string GetAuthorizationCodeUri() {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didTapGetAccessCode:(id)sender {
NSString* authUri =
[NSString stringWithCString:GetAuthorizationCodeUri().c_str()
encoding:[NSString defaultCStringEncoding]];
- (void)didTapGetAccessCode {
NSString* authUri = base::SysUTF8ToNSString(GetAuthorizationCodeUri());
if (@available(iOS 10, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:authUri]
options:@{}
......@@ -217,7 +219,7 @@ std::string GetAuthorizationCodeUri() {
#endif
}
- (void)didTapLogout:(id)sender {
- (void)didTapLogout {
[RemotingService.instance.authentication logout];
}
......
......@@ -12,6 +12,10 @@ typedef void (^SideMenuItemAction)(void);
// Represents an item on the side menu.
@interface SideMenuItem : NSObject
- (instancetype)initWithTitle:(NSString*)title
icon:(UIImage*)icon
action:(SideMenuItemAction)action;
@property(nonatomic, readonly) NSString* title;
@property(nonatomic, readonly) UIImage* icon;
@property(nonatomic, readonly) SideMenuItemAction action;
......
......@@ -20,14 +20,6 @@ static NSString* const kFeedbackContext = @"SideMenuFeedbackContext";
#pragma mark - SideMenuItem
@interface SideMenuItem ()
- (instancetype)initWithTitle:(NSString*)title
icon:(UIImage*)icon
action:(SideMenuItemAction)action;
@end
@implementation SideMenuItem
@synthesize title = _title;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment