CollectionViewController.m revision 2229ffbfe08c2cd606c305f8934e627548002c9e
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
*
* Portions Copyright 2014 Nathaniel McCallum, Red Hat
*/
#import "CollectionViewController.h"
#import "QRCodeScanViewController.h"
#import "BlockActionSheet.h"
#import "FRAOathMechanismCell.h"
#import "FRAIdentityDatabase.h"
#import "FRAOathMechanism.h"
@interface CollectionViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UIPopoverControllerDelegate>
- (FRAOathMechanism *)mechanismForTokenAtCell:(FRAOathMechanismCell*)cell withIndexPath:(NSIndexPath *)indexPath;
- (void)generateCodeForTokenAtCell:(FRAOathMechanismCell *)cell usingMechanism:(FRAOathMechanism *)mechanism;
- (void)showEditActionSheetForTokenAtCell:(FRAOathMechanismCell *)cell withIndexPath:(NSIndexPath *)indexPath usingMechanism:(FRAOathMechanism *)mechanism;
@end
}
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
case 1024: // iPad
case 768: // iPad
case 568: // iPhone5 landscape
case 320: // iPhone* portrait
case 480: // iPhone4 landscape
default:
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
case 1024: // iPad
case 768: // iPad
name = @"iPad";
break;
case 568: // iPhone5 landscape
case 320: // iPhone* portrait
name = @"iPhone5";
break;
case 480: // iPhone4 landscape
default:
name = @"iPhone4";
break;
}
FRAOathMechanismCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:name forIndexPath:indexPath];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// If the device is smaller than an iPhone5,
// then reload the data to pick up the new cell size.
// This is unfortunate because it resets token UI state.
// However, this works until we get completely dynamic resizing.
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// Perform animation.
// Get the current cell and mechanism
FRAOathMechanismCell* cell = (FRAOathMechanismCell*)[collectionView cellForItemAtIndexPath:indexPath];
// If we are not in edit mode, generate the token.
} else {
// If we are in edit mode, show the action sheet for deletion.
}
}
- (FRAOathMechanism *)mechanismForTokenAtCell:(FRAOathMechanismCell*)cell withIndexPath:(NSIndexPath *)indexPath {
return nil;
}
}
- (void)generateCodeForTokenAtCell:(FRAOathMechanismCell *)cell usingMechanism:(FRAOathMechanism *)mechanism {
// Get the code and save the mechanism state.
// Show the code.
// Copy the code to the clipboard.
}
}
- (void)showEditActionSheetForTokenAtCell:(FRAOathMechanismCell *)cell withIndexPath:(NSIndexPath *)indexPath usingMechanism:(FRAOathMechanism *)mechanism {
// Create the action sheet.
// On iPads, the sheet points to the token.
// Otherwise, add a title to make the context clear.
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
}
// Add the remaining buttons.
switch (offset) {
case 1: { // Delete
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
as.title = [NSString stringWithFormat:@"%@\n\n%@\n%@", as.title, cell.issuer.text, cell.label.text];
}
if (offset != 1) {
return;
}
};
break;
}
}
};
}
}
}
break;
default:
break;
}
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Setup store.
// Setup collection view.
// Setup buttons.
id scan = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(scanClicked:)];
}
[super viewWillAppear:animated];
}
@end