Skip to content

Commit 415cc12

Browse files
author
mklepp
committed
Merge branch 'feature/autosave' into develop
2 parents 92d3709 + b1dfebc commit 415cc12

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

OwnCloud Notes/DetailViewController.m

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ - (void)viewDidLoad
7272
[self configureView];
7373
}
7474

75+
- (void) viewWillDisappear:(BOOL)animated {
76+
[super viewWillDisappear:animated];
77+
78+
// autosave Note when the note is new or when there are changes
79+
if (!self.detailItem || (self.detailItem && ![self.detailContentTextView.text isEqualToString:[self.detailItem valueForKey:kNotesContent]])) {
80+
[self saveNote];
81+
}
82+
}
83+
7584
- (void)keyboardWasShown:(NSNotification*)aNotification
7685
{
7786
NSDictionary* info = [aNotification userInfo];
@@ -97,7 +106,7 @@ - (void)keyboardWillBeHidden:(NSNotification*)aNotification
97106
self.detailContentTextView.scrollIndicatorInsets = contentInsets;
98107
}
99108

100-
- (void) saveAndClose:(id)sender
109+
- (BOOL) saveNote
101110
{
102111
NSNumber* modifiedDate = [NSNumber numberWithInt:[[NSDate date] timeIntervalSince1970]];
103112

@@ -110,13 +119,11 @@ - (void) saveAndClose:(id)sender
110119
if (!content) {
111120
content = @"";
112121
}
113-
122+
114123
if ([[content stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@""]) {
115-
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No Content", @"No Content warning") message:@"" delegate:self cancelButtonTitle:NSLocalizedString(@"OK", @"OK") otherButtonTitles:nil];
116-
[alert show];
124+
return NO;
117125
}
118126
else {
119-
120127
NSString* noteId = nil;
121128

122129
NSMutableDictionary* note = [NSMutableDictionary dictionary];
@@ -139,10 +146,22 @@ - (void) saveAndClose:(id)sender
139146
forKey:kNotesNotificationItem];
140147
[[NSNotificationCenter defaultCenter] postNotificationName:kNotesShouldUpdateNotification object:self userInfo:dataDict];
141148

142-
149+
return YES;
150+
}
151+
152+
153+
}
154+
155+
- (void) saveAndClose:(id)sender
156+
{
157+
if ([self saveNote]) {
143158
// Dismiss the modal view to return to the main list
144159
[self.navigationController popViewControllerAnimated:YES];
145160
}
161+
else {
162+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No Content", @"No Content warning") message:@"" delegate:self cancelButtonTitle:NSLocalizedString(@"OK", @"OK") otherButtonTitles:nil];
163+
[alert show];
164+
}
146165
}
147166

148167
- (void)didReceiveMemoryWarning

0 commit comments

Comments
 (0)