Auto-save without sync if sync is not possible

This commit is contained in:
korelstar 2017-07-31 18:39:29 +02:00 committed by Niedermann IT-Dienstleistungen
parent 141a3373f3
commit 92917f0cce
4 changed files with 37 additions and 19 deletions

View file

@ -108,24 +108,22 @@ public class EditNoteActivity extends AppCompatActivity implements CategoryDialo
@Override
public void afterTextChanged(final Editable s) {
if(db.getNoteServerSyncHelper().isSyncPossible()) {
if(timer != null) {
timer.cancel();
}
if(!saveActive) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
autoSave();
}
});
}
}, DELAY);
}
if(timer != null) {
timer.cancel();
}
if(!saveActive) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
autoSave();
}
});
}
}, DELAY);
}
}
});
@ -288,6 +286,15 @@ public class EditNoteActivity extends AppCompatActivity implements CategoryDialo
saveData(new ICallback() {
@Override
public void onFinish() {
onSaved();
}
@Override
public void onScheduled() {
onSaved();
}
public void onSaved() {
// AFTER SYNCHRONIZATION
Log.d(LOG_TAG, "...sync finished");
actionBar.setTitle(note.getTitle());

View file

@ -67,7 +67,11 @@ public class NotesListViewActivity extends AppCompatActivity implements
refreshList();
swipeRefreshLayout.setRefreshing(false);
}
};
@Override
public void onScheduled() {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {

View file

@ -184,8 +184,14 @@ public class NoteServerSyncHelper {
} else if(!onlyLocalChanges) {
Log.d(getClass().getSimpleName(), "... scheduled");
syncScheduled = true;
for (ICallback callback : callbacksPush) {
callback.onScheduled();
}
} else {
Log.d(getClass().getSimpleName(), "... do nothing");
for (ICallback callback : callbacksPush) {
callback.onScheduled();
}
}
}

View file

@ -6,4 +6,5 @@ package it.niedermann.owncloud.notes.util;
*/
public interface ICallback {
void onFinish();
void onScheduled();
}