RootViewController.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // RootViewController.m
  3. // DBRoulette
  4. //
  5. // Created by Brian Smith on 6/29/10.
  6. // Copyright Dropbox, Inc. 2010. All rights reserved.
  7. //
  8. #import "RootViewController.h"
  9. #import <DropboxSDK/DropboxSDK.h>
  10. @interface RootViewController ()
  11. - (void)updateButtons;
  12. @end
  13. @implementation RootViewController
  14. - (id)initWithCoder:(NSCoder *)aDecoder {
  15. if ((self = [super initWithCoder:aDecoder])) {
  16. self.title = @"Link Account";
  17. }
  18. return self;
  19. }
  20. - (void)didPressLink {
  21. if (![[DBSession sharedSession] isLinked]) {
  22. [[DBSession sharedSession] linkFromController:self];
  23. } else {
  24. [[DBSession sharedSession] unlinkAll];
  25. [[[[UIAlertView alloc]
  26. initWithTitle:@"Account Unlinked!" message:@"Your dropbox account has been unlinked"
  27. delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]
  28. autorelease]
  29. show];
  30. [self updateButtons];
  31. }
  32. }
  33. - (IBAction)didPressPhotos {
  34. [self.navigationController pushViewController:photoViewController animated:YES];
  35. }
  36. - (void)viewWillAppear:(BOOL)animated {
  37. [super viewWillAppear:animated];
  38. [self updateButtons];
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
  43. initWithTitle:@"Photos" style:UIBarButtonItemStylePlain
  44. target:self action:@selector(didPressPhotos)] autorelease];
  45. self.title = @"Link Account";
  46. }
  47. - (void)viewDidUnload {
  48. [linkButton release];
  49. linkButton = nil;
  50. }
  51. - (void)dealloc {
  52. [linkButton release];
  53. [photoViewController release];
  54. [super dealloc];
  55. }
  56. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
  57. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  58. return toInterfaceOrientation == UIInterfaceOrientationPortrait;
  59. } else {
  60. return YES;
  61. }
  62. }
  63. #pragma mark private methods
  64. @synthesize linkButton;
  65. @synthesize photoViewController;
  66. - (void)updateButtons {
  67. NSString* title = [[DBSession sharedSession] isLinked] ? @"Unlink Dropbox" : @"Link Dropbox";
  68. [linkButton setTitle:title forState:UIControlStateNormal];
  69. self.navigationItem.rightBarButtonItem.enabled = [[DBSession sharedSession] isLinked];
  70. }
  71. @end