Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e91c49f
Improved presentation of errors if login (SettingsActivity) or synchr…
korelstar Jun 26, 2016
37724e9
Show icon if a note is not synchronized (hint to a possible error)
korelstar Jun 29, 2016
367e601
Refactoring: move common code to new private method getNotesRawQuery(…
korelstar Jul 1, 2016
5f455f6
last part from the previous refactoring
korelstar Jul 2, 2016
a69909c
Merge branch 'error-treatment' into sync-bugfix-refactoring
korelstar Jul 2, 2016
b031f47
use material design icon and remove old holo icon
korelstar Jul 5, 2016
38b6c99
Merge branch 'sync-icon' into sync-bugfix-refactoring
korelstar Jul 5, 2016
1acb034
Refactoring NoteSQLiteOpenHelper and NoteServerSyncHelper in order to…
korelstar Jul 10, 2016
594dc5f
Show icon if a note is not synchronized (hint to a possible error)
korelstar Jun 29, 2016
b6ae80d
Refactoring: move common code to new private method getNotesRawQuery(…
korelstar Jul 1, 2016
c66c3d6
last part from the previous refactoring
korelstar Jul 2, 2016
7186778
use material design icon and remove old holo icon
korelstar Jul 5, 2016
8042561
Refactoring NoteSQLiteOpenHelper and NoteServerSyncHelper in order to…
korelstar Jul 10, 2016
db6a695
Merge remote-tracking branch 'origin/sync-bugfix-refactoring' into sy…
korelstar Jul 10, 2016
93eb7e9
only pull remote changes if this was demanded by the caller
korelstar Jul 10, 2016
7fe474d
restructure the communication between synchronization task and user i…
korelstar Jul 11, 2016
6b22030
updateNoteAndSync(): only make database changes, if the content reall…
korelstar Jul 12, 2016
5d4384b
javadoc and cleanup
korelstar Jul 12, 2016
defbd22
Bugfix for EditNoteActivity: invoke callbacks directly if note wasn't…
korelstar Jul 13, 2016
dd6d6eb
Make sure, that saveDataWithUI is not called, when the previous saveA…
korelstar Jul 13, 2016
3d5348a
rename auto-sync method; adjust DELAYs
korelstar Jul 14, 2016
6458f30
Quick Bugfix: Toast in AsyncTask have to be in onPostExecute
korelstar Jul 18, 2016
3b8648d
Bugfix: save edited note in offline mode, too
korelstar Aug 1, 2016
559f5b0
Bugfix: Show error message in UI thread
korelstar Aug 1, 2016
df744dd
reduce writes to local storage
korelstar Aug 1, 2016
fb30746
reduce logging
korelstar Aug 1, 2016
63bbdc4
Refactor: remove recurrent code
korelstar Aug 3, 2016
26a051f
UI enhancement when editing notes (with no changes)
korelstar Aug 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class NoteTest extends TestCase {

public void testMarkDownStrip() {
Note note = new Note(0, Calendar.getInstance(), "#Title", "");
OwnCloudNote note = new OwnCloudNote(0, Calendar.getInstance(), "#Title", "");
assertTrue("Title".equals(note.getTitle()));
note.setTitle("* Aufzählung");
assertTrue("Aufzählung".equals(note.getTitle()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MenuItem;
import android.widget.EditText;

Expand All @@ -16,28 +17,32 @@
import java.util.concurrent.TimeUnit;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.model.Note;
import it.niedermann.owncloud.notes.model.DBNote;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
import it.niedermann.owncloud.notes.util.ICallback;
import it.niedermann.owncloud.notes.util.NoteUtil;

public class EditNoteActivity extends AppCompatActivity {
private final long DELAY = 1000; // in ms
private static final String LOG_TAG = "EditNote/SAVE";
private final long DELAY = 2000; // in ms
private final long DELAY_AFTER_SYNC = 5000; // in ms
private EditText content = null;
private Note note = null;
private Timer timer = new Timer();
private DBNote note = null;
private Timer timer, timerNextSync;
private boolean saveActive = false;
private ActionBar actionBar;
private NoteSQLiteOpenHelper db;

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
note = (Note) getIntent().getSerializableExtra(
note = (DBNote) getIntent().getSerializableExtra(
NoteActivity.EDIT_NOTE);
content = (EditText) findViewById(R.id.editContent);
content.setEnabled(false);
content.setText(note.getContent());
content.setEnabled(true);
db = new NoteSQLiteOpenHelper(this);
actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(note.getTitle());
Expand All @@ -53,86 +58,130 @@ public void beforeTextChanged(CharSequence s, int start, int count,
@Override
public void onTextChanged(final CharSequence s, int start, int before,
int count) {
if (timer != null)
if (timer != null) {
timer.cancel();
timer = null;
}
}

@Override
public void afterTextChanged(final Editable s) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
if(db.getNoteServerSyncHelper().isSyncPossible()) {
if(timer != null) {
timer.cancel();
}
if(!saveActive) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
saveData();
runOnUiThread(new Runnable() {
@Override
public void run() {
autoSave();
}
});
}
});
}, DELAY);
}
}, DELAY);
}
}
});
}

@Override
public void onBackPressed() {
content.setEnabled(false);
saveData();
Intent data = new Intent();
data.setAction(Intent.ACTION_VIEW);
data.putExtra(NoteActivity.EDIT_NOTE, note);
setResult(RESULT_OK, data);
finish();
saveAndClose();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
content.setEnabled(false);
saveData();
Intent data = new Intent();
data.setAction(Intent.ACTION_VIEW);
data.putExtra(NoteActivity.EDIT_NOTE, note);
setResult(RESULT_OK, data);
finish();
saveAndClose();
return true;
}
return super.onOptionsItemSelected(item);
}

private void saveData() {
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setSubtitle(getResources().getString(R.string.action_edit_saving));
/**
* Saves all changes and closes the Activity
*/
private void saveAndClose() {
content.setEnabled(false);
if(timer!=null) {
timer.cancel();
timer = null;
}
if(timerNextSync!=null) {
timerNextSync.cancel();
timerNextSync = null;
}
saveData(null);
Intent data = new Intent();
data.setAction(Intent.ACTION_VIEW);
data.putExtra(NoteActivity.EDIT_NOTE, note);
setResult(RESULT_OK, data);
finish();
}

/**
* Gets the current content of the EditText field in the UI.
* @return String of the current content.
*/
private String getContent() {
return ((EditText) findViewById(R.id.editContent)).getText().toString();
}

/**
* Saves the current changes and show the status in the ActionBar
*/
private void autoSave() {
Log.d(LOG_TAG, "START save+sync");
saveActive = true;
if (actionBar != null) {
actionBar.setSubtitle(getString(R.string.action_edit_saving));
}
// #74
note.setModified(Calendar.getInstance());
note.setContent(((EditText) findViewById(R.id.editContent)).getText().toString());
// #80
note.setTitle(NoteUtil.generateNoteTitle(note.getContent()));
NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(this);
db.getNoteServerSyncHelper().addCallback(new ICallback() {
final String content = getContent();
saveData(new ICallback() {
@Override
public void onFinish() {
runOnUiThread(new Runnable() {
// AFTER SYNCHRONIZATION
Log.d(LOG_TAG, "...sync finished");
actionBar.setTitle(note.getTitle());
actionBar.setSubtitle(getResources().getString(R.string.action_edit_saved));
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
@Override
public void run() {
getSupportActionBar().setSubtitle(getResources().getString(R.string.action_edit_saved));
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
runOnUiThread(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
getSupportActionBar().setSubtitle(null);
}
});
// AFTER 1 SECOND: set ActionBar to default title
actionBar.setSubtitle(getString(R.string.action_edit_editing));
}
}, 1, TimeUnit.SECONDS);
});
}
}, 1, TimeUnit.SECONDS);

timerNextSync = new Timer();
timerNextSync.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// AFTER "DELAY_AFTER_SYNC" SECONDS: allow next auto-save or start it directly
if(getContent().equals(content)) {
saveActive = false;
Log.d(LOG_TAG, "FINISH, no new changes");
} else {
Log.d(LOG_TAG, "content has changed meanwhile -> restart save");
autoSave();
}
}
});
}
});
}, DELAY_AFTER_SYNC);

/* TODO Notify widgets

Expand All @@ -143,6 +192,13 @@ public void run() {
}*/
}
});
db.updateNoteAndSync(note);
}

/**
* Save the current state in the database and schedule synchronization if needed.
* @param callback
*/
private void saveData(ICallback callback) {
note = db.updateNoteAndSync(note, getContent(), callback);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import android.widget.TextView;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.model.Note;
import it.niedermann.owncloud.notes.model.DBNote;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;

public class NoteActivity extends AppCompatActivity implements View.OnClickListener {
public final static String EDIT_NOTE = "it.niedermann.owncloud.notes.edit_note_id";
public final static int EDIT_NOTE_CMD = 1;
private Note note = null;
private DBNote note = null;
private int notePosition = 0;
private TextView noteContent = null;
private ActionBar actionBar = null;
Expand All @@ -27,10 +27,10 @@ public class NoteActivity extends AppCompatActivity implements View.OnClickListe
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_note);
note = (Note) getIntent().getSerializableExtra(
note = (DBNote) getIntent().getSerializableExtra(
NotesListViewActivity.SELECTED_NOTE);
if (savedInstanceState != null) {
note = (Note) savedInstanceState.getSerializable("note");
note = (DBNote) savedInstanceState.getSerializable("note");
}
notePosition = getIntent().getIntExtra(
NotesListViewActivity.SELECTED_NOTE_POSITION, 0);
Expand Down Expand Up @@ -114,7 +114,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == EDIT_NOTE_CMD) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
Note editedNote = (Note) data.getExtras().getSerializable(
DBNote editedNote = (DBNote) data.getExtras().getSerializable(
EDIT_NOTE);
if (editedNote != null) {
note = editedNote;
Expand Down
Loading