Skip to content

Commit

Permalink
note list
Browse files Browse the repository at this point in the history
  • Loading branch information
liaojinxing committed Jun 11, 2014
1 parent c49433b commit 7da8f2b
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Voice2Note/Resource/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
"ActionSheetMail" = "发送邮件";
"ActionSheetWeixin" = "分享到朋友圈";

"AddTitleForNote" = "给笔记加个标题?";
"Sure" = "确定";

"DeleteFileSuccess" = "删除成功";

"SendEmailSuccess" = "邮件发送成功";
"SendEmailFail" = "邮件发送失败";
"CanNoteSendMail" = "当前设备不支持发送邮件";

57 changes: 36 additions & 21 deletions Voice2Note/Source/Controller/HomeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
static const CGFloat kTextViewHeight = 320;
static const CGFloat kToolbarHeight = 30;

@interface HomeController ()<IFlyRecognizerViewDelegate, UIActionSheetDelegate, MFMailComposeViewControllerDelegate>
@interface HomeController ()<IFlyRecognizerViewDelegate, UIActionSheetDelegate,
MFMailComposeViewControllerDelegate, UIAlertViewDelegate>
{
UITextView *_textView;
UIButton *_recognizeButton;
Expand Down Expand Up @@ -151,7 +152,7 @@ - (void)onResult:(NSArray *)resultArray isLast:(BOOL)isLast

- (void)onError:(IFlySpeechError *)error
{
NSLog(@"errorCode:%d", [error errorCode]);
NSLog(@"errorCode:%@", [error errorDesc]);
}

#pragma mark - Keyboard
Expand Down Expand Up @@ -196,55 +197,68 @@ - (void)hideKeyboard

#pragma mark - Action

- (void)gotoListView
{
if ([_textView isFirstResponder]) {
[_textView resignFirstResponder];
}
NoteListController *listController = [[NoteListController alloc] init];
[self.navigationController pushViewController:listController animated:YES];
}

#pragma mark - More Action

- (void)moreActionButtonPressed
{
[self hideKeyboard];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"ActionSheetTitle", @"")
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:NSLocalizedString(@"ActionSheetCancel", @"")
destructiveButtonTitle:NSLocalizedString(@"ActionSheetSave", @"")
otherButtonTitles:NSLocalizedString(@"ActionSheetMail", @""),
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"ActionSheetSave", @""), NSLocalizedString(@"ActionSheetMail", @""),
NSLocalizedString(@"ActionSheetWeixin", @""), nil];
[actionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
[self saveNote];
[self addTitleForNote];
} else if (buttonIndex == 1) {
if ([MFMailComposeViewController canSendMail]) {
[self email];
[self sendEmail];
}
} else if (buttonIndex == 2) {
NSLog(@"朋友圈");
}
}

- (void)gotoListView
{
if ([_textView isFirstResponder]) {
[_textView resignFirstResponder];
}
NoteListController *listController = [[NoteListController alloc] init];
[self.navigationController pushViewController:listController animated:YES];
}

#pragma mark - Save

- (void)saveNote
- (void)addTitleForNote
{
NSString *title = _textView.text;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"AddTitleForNote", @"")
message:nil
delegate:self
cancelButtonTitle:NSLocalizedString(@"Sure", @"")
otherButtonTitles:nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *title = [alertView textFieldAtIndex:0].text;
NSString *content = _textView.text;
NSDate *createdDate = [NSDate date];
VNNote *note = [[VNNote alloc] initWithTitle:title
content:content
createdDate:createdDate];
content:content
createdDate:createdDate];
[note Persistence];
}

#pragma mark - Eail

- (void)email
- (void)sendEmail
{
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc]init];
[composer setMailComposeDelegate:self];
Expand All @@ -254,6 +268,7 @@ - (void)email
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:composer animated:YES completion:nil];
} else {
[SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"CanNoteSendMail", @"")];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Voice2Note/Source/Controller/NoteListController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

#import <UIKit/UIKit.h>

@interface NoteListController : UIViewController
@interface NoteListController : UITableViewController

@end
102 changes: 102 additions & 0 deletions Voice2Note/Source/Controller/NoteListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,109 @@
//

#import "NoteListController.h"
#import "VNNoteManager.h"
#import "NoteDetailController.h"
#import "VNNote.h"

static const CGFloat kListCellHeight = 44.0f;

@interface NoteListController ()

@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation NoteListController

- (void)viewDidLoad
{
[super viewDidLoad];
[self setupNavigationBar];

NSLog(@"%@", self.dataSource);
}

- (void)setupNavigationBar
{
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Add"
style:UIBarButtonItemStylePlain
target:self
action:@selector(createTask)];
self.navigationItem.rightBarButtonItem = item;
self.navigationItem.title = @"NoteList";

}

- (NSMutableArray *)dataSource
{
if (!_dataSource) {
_dataSource = [[VNNoteManager sharedManager] readAllNotes];
}
return _dataSource;
}

- (void)createTask
{
[self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - DataSource & Delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return kListCellHeight;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ListCell"];
}
VNNote *note = [self.dataSource objectAtIndex:indexPath.row];
cell.textLabel.text = note.title;
[cell.textLabel setFont:[UIFont boldSystemFontOfSize:17]];
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//VNNote *note = [self.dataSource objectAtIndex:indexPath.row];
NoteDetailController *controller = [[NoteDetailController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}

#pragma mark - EditMode

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
VNNote *note = [self.dataSource objectAtIndex:indexPath.row];
[[VNNoteManager sharedManager] deleteNote:note];

[self.dataSource removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}

@end
2 changes: 1 addition & 1 deletion Voice2Note/Source/Model/VNNote.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (id)initWithTitle:(NSString *)title
_createdDate = createdDate;
if (_title == nil || _title.length == 0) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyMMdd:"];
[formatter setDateFormat:@"yyMMdd-HH:mm:ss"];
_title = [formatter stringFromDate:_createdDate];
}
if (_content == nil || _content.length == 0) {
Expand Down
1 change: 1 addition & 0 deletions Voice2Note/Source/Model/VNNoteManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

- (VNNote *)readNoteWithTitle:(NSString *)title;
- (BOOL)storeNote:(VNNote *)note;
- (void)deleteNote:(VNNote *)note;

+ (instancetype)sharedManager;

Expand Down

0 comments on commit 7da8f2b

Please sign in to comment.