scan archive UI improvements, phase 2
authorchristian.brunschen <christian.brunschen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 24 Jun 2008 14:18:11 +0000 (14:18 +0000)
committerchristian.brunschen <christian.brunschen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 24 Jun 2008 14:18:11 +0000 (14:18 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@470 59b500cc-1b3d-0410-9834-0bbf25fbcc57

iphone/Classes/AddContactAction.m
iphone/Classes/ArchiveController.m
iphone/Classes/DecoderViewController.m
iphone/Classes/OpenUrlAction.m
iphone/Classes/ResultAction.h
iphone/Classes/ResultAction.m
iphone/Classes/ScanViewController.h [new file with mode: 0644]
iphone/Classes/ScanViewController.m [new file with mode: 0644]
iphone/ZXing.xcodeproj/project.pbxproj

index 6d381ee..113c60a 100644 (file)
@@ -52,7 +52,8 @@
   return NSLocalizedString(@"Add Contact", @"Add Contact");
 }
 
-- (void)performActionWithController:(UIViewController *)controller {
+- (void)performActionWithController:(UIViewController *)controller 
+                      shouldConfirm:(bool)confirm {
   CFErrorRef *error = NULL;
   NSCharacterSet *whitespaceSet = [NSCharacterSet whitespaceCharacterSet];
   
index 772a491..3b37967 100644 (file)
@@ -24,6 +24,7 @@
 #import "Scan.h"
 #import "ParsedResult.h"
 #import "DecoderViewController.h"
+#import "ScanViewController.h"
 
 #define IMAGE_VIEW_TAG 0x17
 #define DATE_VIEW_TAG 0x18
 }
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-  [decoderViewController showScan:[scans objectAtIndex:[self scanIndexForRow:indexPath.row]]];
+  //[decoderViewController showScan:[scans objectAtIndex:[self scanIndexForRow:indexPath.row]]];
+  Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]];
+  ParsedResult *result = [ParsedResult parsedResultForString:scan.text];
+  ScanViewController *scanViewController = [[ScanViewController alloc] initWithResult:result forScan:scan];
+  [self.navigationController pushViewController:scanViewController animated:YES];
+  [scanViewController release];
 }
 
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 
 - (void)viewDidLoad {
        [super viewDidLoad];
-  self.title = @"Scan Archive";
+  self.title = NSLocalizedString(@"Scan Archive", "scan archive title");
   self.navigationItem.rightBarButtonItem = [self editButtonItem];
 }
 
index 6156e5d..31037e2 100644 (file)
   // no-op
 }
 
+- (void)performAction:(ResultAction *)action {
+  [action performActionWithController:self shouldConfirm:NO];
+}
+
+- (void)confirmAndPerformAction:(ResultAction *)action {
+  [action performActionWithController:self shouldConfirm:YES];
+}
+
 
 - (IBAction)performResultAction:(id)sender {
   if (self.result == nil) {
     ResultAction *action = [self.actions lastObject];
     NSLog(@"Result has the single action, (%@)  '%@', performing it",
           NSStringFromClass([action class]), [action title]);
-    [action performSelector:@selector(performActionWithController:) 
-                 withObject:self 
+    [self performSelector:@selector(confirmAndPerformAction:) 
+                 withObject:action 
                  afterDelay:0.0];
   } else {
     NSLog(@"Result has multiple actions, popping up an action sheet");
   if (buttonIndex < self.actions.count) {
     int actionIndex = buttonIndex;
     ResultAction *action = [self.actions objectAtIndex:actionIndex];
-    [action performSelector:@selector(performActionWithController:) 
-                 withObject:self 
+    [self performSelector:@selector(performAction:) 
+                 withObject:action 
                  afterDelay:0.0];
   }
 }
index 8941611..ab9c8ff 100644 (file)
   return NSLocalizedString(@"Open", @"alert button title");
 }
 
-- (void)performActionWithController:(UIViewController *)controller {
-  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil 
-                                                      message:[self alertMessage] 
-                                                     delegate:self 
-                                            cancelButtonTitle:NSLocalizedString(@"Cancel", @"cancel button title") 
-                                            otherButtonTitles:[self alertButtonTitle], nil];
-  [alertView show];
-  [alertView release];
+- (void)performActionWithController:(UIViewController *)controller 
+                      shouldConfirm:(bool)shouldConfirm {
+  if (shouldConfirm) {
+    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil 
+                                                        message:[self alertMessage] 
+                                                       delegate:self 
+                                              cancelButtonTitle:NSLocalizedString(@"Cancel", @"cancel button title") 
+                                              otherButtonTitles:[self alertButtonTitle], nil];
+    [alertView show];
+    [alertView release];
+  } else {
+    [self openURL];
+  }
 }
 
 - (void)openURL {
index f95a66e..5a8e214 100644 (file)
@@ -26,6 +26,7 @@
 }
 
 - (NSString *)title;
-- (void)performActionWithController:(UIViewController *)controller;
+- (void)performActionWithController:(UIViewController *)controller
+                      shouldConfirm:(bool)confirm;
 
 @end
index 6423f5e..d0b61d3 100644 (file)
@@ -28,7 +28,8 @@
   return @"Abstract Action";
 }
 
-- (void)performActionWithController:(UIViewController *)controller {
+- (void)performActionWithController:(UIViewController *)controller
+                      shouldConfirm:(bool)confirm {
   NSLog(@"Abstract Action performed");
 }
 
diff --git a/iphone/Classes/ScanViewController.h b/iphone/Classes/ScanViewController.h
new file mode 100644 (file)
index 0000000..6b29e04
--- /dev/null
@@ -0,0 +1,23 @@
+//
+//  ScanViewController.h
+//  ZXing
+//
+//  Created by Christian Brunschen on 24/06/2008.
+//  Copyright 2008 Google Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "Scan.h"
+#import "ParsedResult.h"
+
+@interface ScanViewController : UITableViewController {
+  IBOutlet ParsedResult *result;
+  IBOutlet Scan *scan;
+}
+
+@property (nonatomic, retain) ParsedResult *result;
+@property (nonatomic, retain) Scan *scan;
+
+- (id)initWithResult:(ParsedResult *)r forScan:(Scan *)s;
+
+@end
diff --git a/iphone/Classes/ScanViewController.m b/iphone/Classes/ScanViewController.m
new file mode 100644 (file)
index 0000000..2362a5e
--- /dev/null
@@ -0,0 +1,189 @@
+//
+//  ScanViewController.m
+//  ZXing
+//
+//  Created by Christian Brunschen on 24/06/2008.
+//  Copyright 2008 Google Inc. All rights reserved.
+//
+
+#import "ScanViewController.h"
+#import "ResultAction.h"
+
+
+#define TEXT_VIEW_TAG 0x17
+#define TITLE_HEIGHT 60
+#define BODY_HEIGHT 100
+
+@implementation ScanViewController
+
+@synthesize result;
+@synthesize scan;
+
+- (id)initWithResult:(ParsedResult *)r forScan:(Scan *)s {
+       if (self = [super initWithStyle:UITableViewStyleGrouped]) {
+    self.result = r;
+    self.scan = s;
+    self.title = NSLocalizedString(@"Scan", @"scan view controller title");
+       }
+       return self;
+}
+
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+       return [[result actions] count] ? 2 : 1;
+}
+
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+  switch (section) {
+    case 0:
+      return 2;
+    case 1:
+      return [[result actions] count];
+    default:
+      return 0;
+  }
+}
+
+- (UITableViewCell *)cellWithIdentifier:(NSString *)identifier inTableView:(UITableView *)tableView {
+       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
+       if (cell == nil) {
+               cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease];
+       }
+  return cell;
+}
+
+- (UITableViewCell *)titleCellInTableView:(UITableView *)tableView {
+       static NSString *TitleIdentifier = @"ScanViewTitleIdentifier";
+  return [self cellWithIdentifier:TitleIdentifier inTableView:tableView];
+}
+
+- (UITableViewCell *)bodyCellInTableView:(UITableView *)tableView {
+       static NSString *BodyIdentifier = @"ScanViewBodyIdentifier";
+       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:BodyIdentifier];
+       if (cell == nil) {
+               cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, BODY_HEIGHT) reuseIdentifier:BodyIdentifier] autorelease];
+    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(cell.contentView.bounds, 6, 6)];
+    [textView setTag:TEXT_VIEW_TAG];
+    textView.editable = NO;
+    [textView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [cell.contentView addSubview:textView];
+    [textView release];
+       }
+  return cell;
+}
+
+- (UITableViewCell *)buttonCellInTableView:(UITableView *)tableView {
+       static NSString *ButtonIdentifier = @"ScanViewButtonIdentifier";
+  return [self cellWithIdentifier:ButtonIdentifier inTableView:tableView];
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+  if (indexPath.section == 0) {
+    if (indexPath.row == 0) {
+      return TITLE_HEIGHT;
+    } else if (indexPath.row == 1) {
+      return BODY_HEIGHT;
+    }
+  }
+  return tableView.rowHeight;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+       
+  UITableViewCell *cell;
+  
+  if (indexPath.section == 0) {
+    if (indexPath.row == 0) {
+      cell = [self titleCellInTableView:tableView];
+      cell.image = [result icon];
+      cell.text = [[result class] typeName];
+    } else if (indexPath.row == 1) {
+      cell = [self bodyCellInTableView:tableView];
+      UITextView *textView = (UITextView *)[cell viewWithTag:TEXT_VIEW_TAG];
+      textView.text = [result stringForDisplay];
+    }
+  } else if (indexPath.section == 1) {
+    cell = [self buttonCellInTableView:tableView];
+    ResultAction *action = [[result actions] objectAtIndex:indexPath.row];
+    cell.text = [action title];
+  }
+       
+       return cell;
+}
+
+- (void)performAction:(ResultAction *)action {
+  [action performActionWithController:self shouldConfirm:NO];
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+  if (indexPath.section == 1) {
+    ResultAction *action = [[result actions] objectAtIndex:indexPath.row];
+    [self performSelector:@selector(performAction:) withObject:action afterDelay:0.0];
+  }
+}
+
+/*
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
+       
+       if (editingStyle == UITableViewCellEditingStyleDelete) {
+       }
+       if (editingStyle == UITableViewCellEditingStyleInsert) {
+       }
+}
+*/
+
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
+       return NO;
+}
+
+/*
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
+}
+*/
+
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
+       return NO;
+}
+
+- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+  if (indexPath.section != 1) {
+    return nil;
+  }
+  return indexPath;
+}
+
+
+- (void)dealloc {
+  [result release];
+  [scan release];
+       [super dealloc];
+}
+
+
+- (void)viewDidLoad {
+       [super viewDidLoad];
+}
+
+
+- (void)viewWillAppear:(BOOL)animated {
+       [super viewWillAppear:animated];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+       [super viewDidAppear:animated];
+}
+
+- (void)viewWillDisappear:(BOOL)animated {
+}
+
+- (void)viewDidDisappear:(BOOL)animated {
+}
+
+- (void)didReceiveMemoryWarning {
+       [super didReceiveMemoryWarning];
+}
+
+
+@end
+
index 7263613..458ead8 100755 (executable)
@@ -91,6 +91,7 @@
                855A66BD0DF5E8D6007B394F /* libsqlite3.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 855A66BC0DF5E8D6007B394F /* libsqlite3.0.dylib */; };
                855A66BF0DF5E8F8007B394F /* libiconv.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 855A66BE0DF5E8F8007B394F /* libiconv.2.dylib */; };
                855A66D20DF5E954007B394F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 855A66D10DF5E954007B394F /* CoreGraphics.framework */; };
+               85D937270E11064700B785E0 /* ScanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 85D937260E11064700B785E0 /* ScanViewController.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                857D36400DF60E37000E0C89 /* Exception.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Exception.cpp; sourceTree = "<group>"; };
                857D368E0DF613F3000E0C89 /* GrayBytesMonochromeBitmapSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GrayBytesMonochromeBitmapSource.h; sourceTree = "<group>"; };
                857D368F0DF613F3000E0C89 /* GrayBytesMonochromeBitmapSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GrayBytesMonochromeBitmapSource.cpp; sourceTree = "<group>"; };
+               85D937250E11064700B785E0 /* ScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScanViewController.h; sourceTree = "<group>"; };
+               85D937260E11064700B785E0 /* ScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScanViewController.m; sourceTree = "<group>"; };
                8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
                080E96DDFE201D6D7F000001 /* Classes */ = {
                        isa = PBXGroup;
                        children = (
+                               85D937250E11064700B785E0 /* ScanViewController.h */,
+                               85D937260E11064700B785E0 /* ScanViewController.m */,
                                85096CCE0E06D45400D660F9 /* SMSAction.h */,
                                85096CCF0E06D45400D660F9 /* SMSAction.m */,
                                852683C00DF8562B005DD4C0 /* ShowMapAction.h */,
                                852683A20DF851ED005DD4C0 /* GeoParsedResult.m in Sources */,
                                852683C20DF8562B005DD4C0 /* ShowMapAction.m in Sources */,
                                85096CD00E06D45400D660F9 /* SMSAction.m in Sources */,
+                               85D937270E11064700B785E0 /* ScanViewController.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };