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; ...@@ -17,7 +17,7 @@ static HelpAndFeedback* g_helpAndFeedback;
#pragma mark - Public #pragma mark - Public
- (void)presentFeedbackFlowWithContext:(NSString*)context { - (void)presentFeedbackFlowWithContext:(NSString*)context {
NOTREACHED() << "This should be implemented by a subclass."; NOTIMPLEMENTED() << "This should be implemented by a subclass.";
} }
#pragma mark - Static Properties #pragma mark - Static Properties
......
...@@ -11,10 +11,12 @@ ...@@ -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/AppBar/src/MaterialAppBar.h"
#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.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/remoting_theme.h"
#import "remoting/ios/app/side_menu_items.h"
#import "remoting/ios/facade/remoting_authentication.h" #import "remoting/ios/facade/remoting_authentication.h"
#import "remoting/ios/facade/remoting_service.h" #import "remoting/ios/facade/remoting_service.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "google_apis/google_api_keys.h" #include "google_apis/google_api_keys.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "remoting/base/string_resources.h" #include "remoting/base/string_resources.h"
...@@ -28,6 +30,7 @@ static UIColor* kBackgroundColor = ...@@ -28,6 +30,7 @@ static UIColor* kBackgroundColor =
[UIColor colorWithRed:0.f green:0.67f blue:0.55f alpha:1.f]; [UIColor colorWithRed:0.f green:0.67f blue:0.55f alpha:1.f];
namespace { namespace {
const char kChromotingAuthScopeValues[] = const char kChromotingAuthScopeValues[] =
"https://www.googleapis.com/auth/chromoting " "https://www.googleapis.com/auth/chromoting "
"https://www.googleapis.com/auth/googletalk " "https://www.googleapis.com/auth/googletalk "
...@@ -56,23 +59,18 @@ std::string GetAuthorizationCodeUri() { ...@@ -56,23 +59,18 @@ std::string GetAuthorizationCodeUri() {
@interface RemotingMenuViewController () { @interface RemotingMenuViewController () {
MDCAppBar* _appBar; MDCAppBar* _appBar;
NSMutableArray* _content; NSArray<NSArray<SideMenuItem*>*>* _content;
} }
@end @end
// This is the chromium version of the menu view controller. This will // 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 // 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. // The official app's implementation is in //ios_internal.
// 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.
// //
// Note: this class is not localized, it will not be shipped to production. // 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 @implementation RemotingMenuViewController
- (id)init { - (id)init {
...@@ -117,23 +115,38 @@ std::string GetAuthorizationCodeUri() { ...@@ -117,23 +115,38 @@ std::string GetAuthorizationCodeUri() {
self.styler.cellStyle = MDCCollectionViewCellStyleCard; self.styler.cellStyle = MDCCollectionViewCellStyleCard;
_content = [NSMutableArray array]; // Add the account management section to the beginning of the content.
[_content addObject:@[ __weak __typeof(self) weakSelf = self;
l10n_util::GetNSString(IDS_SIGN_IN_BUTTON), NSArray<SideMenuItem*>* accountManagementSection = @[
l10n_util::GetNSString(IDS_SIGN_OUT_BUTTON) [[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 #pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView: - (NSInteger)numberOfSectionsInCollectionView:
(UICollectionView*)collectionView { (UICollectionView*)collectionView {
return (NSInteger)[_content count]; return _content.count;
} }
- (NSInteger)collectionView:(UICollectionView*)collectionView - (NSInteger)collectionView:(UICollectionView*)collectionView
numberOfItemsInSection:(NSInteger)section { numberOfItemsInSection:(NSInteger)section {
return (NSInteger)[_content[(NSUInteger)section] count]; return _content[section].count;
} }
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
...@@ -141,30 +154,9 @@ std::string GetAuthorizationCodeUri() { ...@@ -141,30 +154,9 @@ std::string GetAuthorizationCodeUri() {
MDCCollectionViewTextCell* cell = [collectionView MDCCollectionViewTextCell* cell = [collectionView
dequeueReusableCellWithReuseIdentifier:kReusableIdentifierItem dequeueReusableCellWithReuseIdentifier:kReusableIdentifierItem
forIndexPath:indexPath]; forIndexPath:indexPath];
cell.textLabel.text = SideMenuItem* item = _content[indexPath.section][indexPath.item];
_content[(NSUInteger)indexPath.section][(NSUInteger)indexPath.item]; cell.textLabel.text = item.title;
cell.imageView.image = item.icon;
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;
}
return cell; return cell;
} }
...@@ -185,12 +177,24 @@ std::string GetAuthorizationCodeUri() { ...@@ -185,12 +177,24 @@ std::string GetAuthorizationCodeUri() {
return supplementaryView; 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> #pragma mark - <UICollectionViewDelegateFlowLayout>
- (CGSize)collectionView:(UICollectionView*)collectionView - (CGSize)collectionView:(UICollectionView*)collectionView
layout: layout:
(UICollectionViewLayout*)collectionViewLayout (UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section { 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, return CGSizeMake(collectionView.bounds.size.width,
MDCCellDefaultOneLineHeight); MDCCellDefaultOneLineHeight);
} }
...@@ -201,10 +205,8 @@ std::string GetAuthorizationCodeUri() { ...@@ -201,10 +205,8 @@ std::string GetAuthorizationCodeUri() {
[self dismissViewControllerAnimated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil];
} }
- (void)didTapGetAccessCode:(id)sender { - (void)didTapGetAccessCode {
NSString* authUri = NSString* authUri = base::SysUTF8ToNSString(GetAuthorizationCodeUri());
[NSString stringWithCString:GetAuthorizationCodeUri().c_str()
encoding:[NSString defaultCStringEncoding]];
if (@available(iOS 10, *)) { if (@available(iOS 10, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:authUri] [[UIApplication sharedApplication] openURL:[NSURL URLWithString:authUri]
options:@{} options:@{}
...@@ -217,7 +219,7 @@ std::string GetAuthorizationCodeUri() { ...@@ -217,7 +219,7 @@ std::string GetAuthorizationCodeUri() {
#endif #endif
} }
- (void)didTapLogout:(id)sender { - (void)didTapLogout {
[RemotingService.instance.authentication logout]; [RemotingService.instance.authentication logout];
} }
......
...@@ -12,6 +12,10 @@ typedef void (^SideMenuItemAction)(void); ...@@ -12,6 +12,10 @@ typedef void (^SideMenuItemAction)(void);
// Represents an item on the side menu. // Represents an item on the side menu.
@interface SideMenuItem : NSObject @interface SideMenuItem : NSObject
- (instancetype)initWithTitle:(NSString*)title
icon:(UIImage*)icon
action:(SideMenuItemAction)action;
@property(nonatomic, readonly) NSString* title; @property(nonatomic, readonly) NSString* title;
@property(nonatomic, readonly) UIImage* icon; @property(nonatomic, readonly) UIImage* icon;
@property(nonatomic, readonly) SideMenuItemAction action; @property(nonatomic, readonly) SideMenuItemAction action;
......
...@@ -20,14 +20,6 @@ static NSString* const kFeedbackContext = @"SideMenuFeedbackContext"; ...@@ -20,14 +20,6 @@ static NSString* const kFeedbackContext = @"SideMenuFeedbackContext";
#pragma mark - SideMenuItem #pragma mark - SideMenuItem
@interface SideMenuItem ()
- (instancetype)initWithTitle:(NSString*)title
icon:(UIImage*)icon
action:(SideMenuItemAction)action;
@end
@implementation SideMenuItem @implementation SideMenuItem
@synthesize title = _title; @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