|
|
@@ -9,6 +9,7 @@
|
|
|
#import "BasicModeViewController.h"
|
|
|
#import "ScannerViewController.h"
|
|
|
#import "PhotoListViewController.h"
|
|
|
+#import "UploadViewController.h"
|
|
|
|
|
|
@interface BasicModeViewController ()<UITextFieldDelegate>
|
|
|
|
|
|
@@ -19,6 +20,10 @@
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
|
+ self.photoCount = 0;
|
|
|
+
|
|
|
+ UIBarButtonItem *uploadListItem = [[UIBarButtonItem alloc] initWithTitle:@"Upload List" style:UIBarButtonItemStylePlain target:self action:@selector(showUploadList)];
|
|
|
+ self.navigationItem.rightBarButtonItem = uploadListItem;
|
|
|
}
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
@@ -28,7 +33,20 @@
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
[super viewWillAppear:animated];
|
|
|
- [self loadSavedPhotoCount];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (NSMutableArray *)photos {
|
|
|
+ if (!_photos) {
|
|
|
+ _photos = [NSMutableArray array];
|
|
|
+ }
|
|
|
+ return _photos;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showUploadList {
|
|
|
+
|
|
|
+ UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
|
|
|
+ [self.navigationController pushViewController:upVC animated:YES];
|
|
|
}
|
|
|
|
|
|
- (void)showPhotoList {
|
|
|
@@ -113,45 +131,56 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
-- (void)saveImage:(UIImage *)img {
|
|
|
+- (NSString *)saveImage:(UIImage *)img {
|
|
|
NSString *dir = [NSString stringWithFormat:@"%@/%@",[RAUtils appCacheDirectory],self.name];
|
|
|
|
|
|
NSDate * date = [NSDate date];
|
|
|
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
- [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
|
|
+ [dateFormatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];
|
|
|
NSString * name = [[dateFormatter stringFromDate:date] stringByAppendingPathExtension:@"png"];
|
|
|
|
|
|
+// NSString *name = [[NSUUID UUID] UUIDString];
|
|
|
+// name = [name stringByAppendingPathExtension:@"png"];
|
|
|
NSString *path = [dir stringByAppendingPathComponent:name];
|
|
|
|
|
|
- [RAUtils saveData:UIImagePNGRepresentation(img) toPath:path];
|
|
|
+ if ([RAUtils saveData:UIImagePNGRepresentation(img) toPath:path]) {
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil;
|
|
|
}
|
|
|
|
|
|
-- (void)loadSavedPhotoCount {
|
|
|
- NSString *dir = [NSString stringWithFormat:@"%@/%@",[RAUtils appCacheDirectory],self.name];
|
|
|
- NSFileManager *manager = [NSFileManager defaultManager];
|
|
|
- NSArray *files = [manager contentsOfDirectoryAtPath:dir error:nil];
|
|
|
- if (files.count) {
|
|
|
- NSMutableArray *photos = [NSMutableArray array];
|
|
|
- for (NSString *name in files) {
|
|
|
- if ([name hasSuffix:@".png"]) {
|
|
|
- NSString *path = [dir stringByAppendingPathComponent:name];
|
|
|
- UIImage *img = [UIImage imageWithContentsOfFile:path];
|
|
|
- NSString *md5 = [RAUtils md5WithFile:path];
|
|
|
- NSDictionary *photoDic = @{
|
|
|
- @"photo" : img,
|
|
|
- @"check" : @(NO),
|
|
|
- @"path" : path,
|
|
|
- @"md5" : md5
|
|
|
- };
|
|
|
- [photos addObject:photoDic];
|
|
|
- }
|
|
|
- }
|
|
|
- self.photoCount = photos.count;
|
|
|
- self.photos = photos;
|
|
|
- } else {
|
|
|
- self.photoCount = 0;
|
|
|
- self.photos = nil;
|
|
|
- }
|
|
|
+//- (void)loadSavedPhotoCount {
|
|
|
+// NSString *dir = [NSString stringWithFormat:@"%@/%@",[RAUtils appCacheDirectory],self.name];
|
|
|
+// NSFileManager *manager = [NSFileManager defaultManager];
|
|
|
+// NSArray *files = [manager contentsOfDirectoryAtPath:dir error:nil];
|
|
|
+// if (files.count) {
|
|
|
+// NSMutableArray *photos = [NSMutableArray array];
|
|
|
+// for (NSString *name in files) {
|
|
|
+// if ([name hasSuffix:@".png"]) {
|
|
|
+// NSString *path = [dir stringByAppendingPathComponent:name];
|
|
|
+// UIImage *img = [UIImage imageWithContentsOfFile:path];
|
|
|
+// NSString *md5 = [RAUtils md5WithFile:path];
|
|
|
+// NSDictionary *photoDic = @{
|
|
|
+// @"photo" : img,
|
|
|
+// @"check" : @(NO),
|
|
|
+// @"path" : path,
|
|
|
+// @"md5" : md5
|
|
|
+// };
|
|
|
+// [photos addObject:photoDic];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// self.photoCount = photos.count;
|
|
|
+// self.photos = photos;
|
|
|
+// } else {
|
|
|
+// self.photoCount = 0;
|
|
|
+// self.photos = nil;
|
|
|
+// }
|
|
|
+//}
|
|
|
+
|
|
|
+- (void)clearPhotos {
|
|
|
+ [self.photos removeAllObjects];
|
|
|
+ self.photoCount = 0;
|
|
|
}
|
|
|
|
|
|
#pragma mark - Public Method
|
|
|
@@ -196,9 +225,21 @@
|
|
|
image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
|
|
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
}
|
|
|
- [self saveImage:image];
|
|
|
- [self receiveImage:image];
|
|
|
-
|
|
|
+ NSString *path = [self saveImage:image];
|
|
|
+ if (path) {// 保存成功
|
|
|
+ [self receiveImage:image];
|
|
|
+ NSString *md5 = [RAUtils md5WithFile:path];
|
|
|
+ NSDictionary *photoDic = @{
|
|
|
+ @"photo" : image,
|
|
|
+ @"check" : @(NO),
|
|
|
+ @"file" : [path lastPathComponent],
|
|
|
+ @"md5" : md5
|
|
|
+ };
|
|
|
+ [self.photos addObject:photoDic];
|
|
|
+ self.photoCount++;
|
|
|
+ } else {
|
|
|
+ [RAUtils message_alert:@"Save photo failed" title:@"Warning" controller:self];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|