|
@@ -16,11 +16,12 @@
|
|
|
#import "CPDFColorUtils.h"
|
|
|
#import "CStampButton.h"
|
|
|
#import "CStampTextViewController.h"
|
|
|
-#import "AAPLCustomPresentationController.h"
|
|
|
#import "CStampTextViewController.h"
|
|
|
#import "CCustomizeStampTableViewCell.h"
|
|
|
+#import "CStampPreview.h"
|
|
|
|
|
|
#import <ComPDFKit/ComPDFKit.h>
|
|
|
+#import <compdfkit_tools/AAPLCustomPresentationController.h>
|
|
|
|
|
|
#define kStamp_Cell_Height 60
|
|
|
|
|
@@ -32,7 +33,7 @@ PDFAnnotationStampKey const PDFAnnotationStampKeyShowTime = @"PDFAnnotationStamp
|
|
|
PDFAnnotationStampKey const PDFAnnotationStampKeyStyle = @"PDFAnnotationStampKeyStyle";
|
|
|
PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKeyShape";
|
|
|
|
|
|
-@interface CPDFStampViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITableViewDelegate, UITableViewDataSource>
|
|
|
+@interface CPDFStampViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITableViewDelegate, UITableViewDataSource, CStampTextViewControllerDelegate, CCustomizeStampTableViewCellDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) UICollectionView *collectView;
|
|
|
|
|
@@ -337,6 +338,7 @@ PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKey
|
|
|
NSMutableDictionary *tStampItem = [[NSMutableDictionary alloc] init];
|
|
|
[tStampItem setObject:tPath forKey:@"path"];
|
|
|
[self.stampFileManager insertStampItem:tStampItem type:PDFStampCustomType_Image];
|
|
|
+ [self.tableView reloadData];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -379,13 +381,10 @@ PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKey
|
|
|
|
|
|
AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
|
|
|
CStampTextViewController *stampTextVC = [[CStampTextViewController alloc] init];
|
|
|
+ stampTextVC.delegate = self;
|
|
|
presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:stampTextVC presentingViewController:self];
|
|
|
stampTextVC.transitioningDelegate = presentationController;
|
|
|
[self presentViewController:stampTextVC animated:YES completion:nil];
|
|
|
-
|
|
|
- if (self.delegate && [self.delegate respondsToSelector:@selector(stampViewController:)]) {
|
|
|
- [self.delegate stampViewController:self];
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- (void)buttonItemClicked_image:(id)sender {
|
|
@@ -412,6 +411,16 @@ PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKey
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
+#pragma mark - UICollectionViewDelegate
|
|
|
+
|
|
|
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(stampViewController:selectedIndex:stamp:)]) {
|
|
|
+ [self.delegate stampViewController:self selectedIndex:indexPath.row stamp:[NSDictionary dictionary]];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - UITableViewDataSource
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
@@ -436,6 +445,16 @@ PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKey
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
|
|
|
+ if (section == 0) {
|
|
|
+ return NSLocalizedString(@"Text Stamp", nil);
|
|
|
+ } else if (section == 1) {
|
|
|
+ return NSLocalizedString(@"Image Stamp", nil);
|
|
|
+ } else {
|
|
|
+ return @"";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
CCustomizeStampTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
|
|
|
if (cell == nil) {
|
|
@@ -443,7 +462,22 @@ PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKey
|
|
|
}
|
|
|
if (self.customTextArray.count>0 || self.customImageArray.count>0) {
|
|
|
if (0 == indexPath.section) {
|
|
|
- cell.customizeStampImageView.image = self.customTextArray[indexPath.row];
|
|
|
+ NSDictionary *tDic = _customTextArray[indexPath.item];
|
|
|
+ NSString *tText = [tDic objectForKey:@"text"];
|
|
|
+ NSInteger tStyle = [[tDic objectForKey:@"style"] integerValue];
|
|
|
+ NSInteger tColorStyle = [[tDic objectForKey:@"colorStyle"] integerValue];
|
|
|
+ BOOL tHaveDate = [[tDic objectForKey:@"haveDate"] boolValue];
|
|
|
+ BOOL tHaveTime = [[tDic objectForKey:@"haveTime"] boolValue];
|
|
|
+
|
|
|
+ CStampPreview *tPreview = [[CStampPreview alloc] initWithFrame:CGRectMake(0, 0, 320, kStamp_Cell_Height)];
|
|
|
+ [tPreview setTextStampText:tText];
|
|
|
+ [tPreview setTextStampColorStyle:tColorStyle];
|
|
|
+ [tPreview setTextStampStyle:tStyle];
|
|
|
+ [tPreview setTextStampHaveDate:tHaveDate];
|
|
|
+ [tPreview setTextStampHaveTime:tHaveTime];
|
|
|
+ tPreview.leftMargin = 0;
|
|
|
+ UIImage *tImg = [tPreview renderImage];
|
|
|
+ cell.customizeStampImageView.image = tImg;
|
|
|
} else {
|
|
|
NSDictionary *tDic = self.customImageArray[indexPath.item];
|
|
|
UIImage *img = [self.imgDicCache objectForKey:tDic];
|
|
@@ -458,8 +492,110 @@ PDFAnnotationStampKey const PDFAnnotationStampKeyShape = @"PDFAnnotationStampKey
|
|
|
cell.customizeStampImageView.image = img;
|
|
|
}
|
|
|
}
|
|
|
+ cell.deleteDelegate = self;
|
|
|
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
+#pragma mark - UITableViewDelegate
|
|
|
+
|
|
|
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ if (indexPath.section == 0) {
|
|
|
+ NSDictionary *tDic = _customTextArray[indexPath.item];
|
|
|
+ NSString *tText = [tDic objectForKey:@"text"];
|
|
|
+ NSInteger tStyle = [[tDic objectForKey:@"style"] integerValue];
|
|
|
+ NSInteger tColorStyle = [[tDic objectForKey:@"colorStyle"] integerValue];
|
|
|
+ BOOL tHaveDate = [[tDic objectForKey:@"haveDate"] boolValue];
|
|
|
+ BOOL tHaveTime = [[tDic objectForKey:@"haveTime"] boolValue];
|
|
|
+ NSInteger stampStype = 0;
|
|
|
+ NSInteger stampShape = 0;
|
|
|
+
|
|
|
+ switch (tColorStyle) {
|
|
|
+ case TextStampColorTypeBlack:
|
|
|
+ {
|
|
|
+ stampShape = 0;
|
|
|
+ stampStype = 0;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case TextStampColorTypeRed:
|
|
|
+ {
|
|
|
+ stampStype = 1;
|
|
|
+ if (TextStampTypeRight== tStyle) {
|
|
|
+ stampShape = 2;
|
|
|
+ } else if (TextStampTypeLeft == tStyle) {
|
|
|
+ stampShape = 1;
|
|
|
+ } else {
|
|
|
+ stampShape = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case TextStampColorTypeGreen:
|
|
|
+ {
|
|
|
+ stampStype = 2;
|
|
|
+ if (TextStampTypeRight== tStyle) {
|
|
|
+ stampShape = 2;
|
|
|
+ } else if (TextStampTypeLeft == tStyle) {
|
|
|
+ stampShape = 1;
|
|
|
+ } else {
|
|
|
+ stampShape = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case TextStampColorTypeBlue:
|
|
|
+ {
|
|
|
+ stampStype = 3;
|
|
|
+ if (TextStampTypeRight== tStyle) {
|
|
|
+ stampShape = 2;
|
|
|
+ } else if (TextStampTypeLeft == tStyle) {
|
|
|
+ stampShape = 1;
|
|
|
+ } else {
|
|
|
+ stampShape = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(stampViewController:selectedIndex:stamp:)]) {
|
|
|
+ [self.delegate stampViewController:self selectedIndex:indexPath.row stamp:@{PDFAnnotationStampKeyText : tText,
|
|
|
+ PDFAnnotationStampKeyShowDate : @(tHaveDate),
|
|
|
+ PDFAnnotationStampKeyShowTime : @(tHaveTime),
|
|
|
+ PDFAnnotationStampKeyStyle : @(stampStype),
|
|
|
+ PDFAnnotationStampKeyShape : @(stampShape)}];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ } else if (indexPath.section == 1) {
|
|
|
+ NSDictionary *tDict = self.customImageArray[indexPath.row];
|
|
|
+ NSString *tPath = [tDict objectForKey:@"path"];
|
|
|
+ NSString *tFileName = [[NSFileManager defaultManager] displayNameAtPath:tPath];
|
|
|
+ NSString *tRealPath = [NSString stringWithFormat:@"%@/%@",kPDFStampDataFolder,tFileName];
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
+ if (self.delegate && [self.delegate respondsToSelector:@selector(stampViewController:selectedIndex:stamp:)]) {
|
|
|
+ [self.delegate stampViewController:self selectedIndex:indexPath.row stamp:@{PDFAnnotationStampKeyImagePath : tRealPath}];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - CCustomizeStampTableViewCellDelegate
|
|
|
+
|
|
|
+- (void)customizeStampTableViewCell:(CCustomizeStampTableViewCell *)customizeStampTableViewCell {
|
|
|
+ NSIndexPath *select = [self.tableView indexPathForCell:customizeStampTableViewCell];
|
|
|
+
|
|
|
+ if (select.section == 0) {
|
|
|
+ [self.stampFileManager removeStampItem:select.row type:PDFStampCustomType_Text];
|
|
|
+ } else if (select.section == 1) {
|
|
|
+ [self.stampFileManager removeStampItem:select.row type:PDFStampCustomType_Image];
|
|
|
+ }
|
|
|
+
|
|
|
+ [self.tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - CStampTextViewControllerDelegate
|
|
|
+
|
|
|
+- (void)stampTextViewController:(CStampTextViewController *)stampTextViewController dictionary:(NSDictionary *)dictionary {
|
|
|
+ [self.stampFileManager insertStampItem:dictionary type:PDFStampCustomType_Text];
|
|
|
+ [self.tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
@end
|