Permalink
Fetching contributors…
Cannot retrieve contributors at this time
108 lines (81 sloc) 3.86 KB
//
// Copyright 2011 ESCOZ Inc - http://escoz.com
//
// 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.
//
#import "LoginController.h"
#import "LoginInfo.h"
@interface LoginController ()
- (void)onLogin:(QButtonElement *)buttonElement;
- (void)onAbout;
@end
@implementation LoginController
- (QuickDialogController *)initWithRoot:(QRootElement *)rootElement {
self = [super initWithRoot:rootElement];
if (self) {
self.root.appearance = [self.root.appearance copy];
self.root.appearance.tableGroupedBackgroundColor = [UIColor colorWithHue:40/360.f saturation:0.58f brightness:0.90f alpha:1.f];;
((QEntryElement *)[self.root elementWithKey:@"login"]).delegate = self;
QAppearance *fieldsAppearance = [self.root.appearance copy];
fieldsAppearance.backgroundColorEnabled = [UIColor colorWithRed:0.9582 green:0.9104 blue:0.7991 alpha:1.0000];
[self.root elementWithKey:@"login"].appearance = fieldsAppearance;
[self.root elementWithKey:@"password"].appearance = fieldsAppearance;
[self.root elementWithKey:@"button"].appearance = self.root.appearance.copy;
[self.root elementWithKey:@"button"].appearance.backgroundColorEnabled = [UIColor greenColor];
}
return self;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBar.tintColor = nil;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStylePlain target:self action:@selector(onAbout)];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
- (void)loginCompleted:(LoginInfo *)info {
[self loading:NO];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" message:[NSString stringWithFormat: @"Hi %@, I hope you're loving QuickDialog! Here's your pass: %@", info.login, info.password] delegate:self cancelButtonTitle:@"YES!" otherButtonTitles:nil];
[alert show];
}
- (void)onLogin:(QButtonElement *)buttonElement {
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
[self loading:YES];
LoginInfo *info = [[LoginInfo alloc] init];
[self.root fetchValueUsingBindingsIntoObject:info];
[self performSelector:@selector(loginCompleted:) withObject:info afterDelay:2];
}
- (void)onAbout {
QRootElement *details = [LoginController createDetailsForm];
[self displayViewControllerForRoot:details];
}
+ (QRootElement *)createDetailsForm {
QRootElement *details = [[QRootElement alloc] init];
details.presentationMode = QPresentationModeModalForm;
details.title = @"Details";
details.controllerName = @"AboutController";
details.grouped = YES;
QSection *section = [[QSection alloc] initWithTitle:@"Information"];
[section addElement:[[QTextElement alloc] initWithText:@"Here's some more info about this app."]];
[details addSection:section];
return details;
}
- (BOOL)QEntryShouldChangeCharactersInRangeForElement:(QEntryElement *)element andCell:(QEntryTableViewCell *)cell {
NSLog(@"Should change characters");
return YES;
}
- (void)QEntryEditingChangedForElement:(QEntryElement *)element andCell:(QEntryTableViewCell *)cell {
NSLog(@"Editing changed");
}
- (void)QEntryMustReturnForElement:(QEntryElement *)element andCell:(QEntryTableViewCell *)cell {
NSLog(@"Must return");
}
@end