#101 Option to synchronise notes when opening the app

This commit is contained in:
Stefan Niedermann 2016-03-24 22:30:30 +01:00
parent b9f5182640
commit 6275006b45

View file

@ -64,7 +64,6 @@ public class NotesListViewActivity extends AppCompatActivity implements
// Display Data
db = new NoteSQLiteOpenHelper(this);
db.synchronizeWithServer();
setListView(db.getNotes());
// Pull to Refresh
@ -72,18 +71,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
db.getNoteServerSyncHelper().addCallback(new ICallback() {
@Override
public void onFinish() {
swipeRefreshLayout.setRefreshing(false);
adapter.clearSelection();
if (mActionMode != null) {
mActionMode.finish();
}
setListView(db.getNotes());
}
});
db.synchronizeWithServer();
refresh();
}
});
@ -91,6 +79,34 @@ public class NotesListViewActivity extends AppCompatActivity implements
findViewById(R.id.fab_create).setOnClickListener(this);
}
/**
* Perform refresh on every time the activity gets visible
*/
@Override
protected void onResume() {
refresh();
super.onResume();
}
/**
* Performs a server synchronization and set the RecyclerView
*/
private void refresh() {
swipeRefreshLayout.setRefreshing(true);
db.getNoteServerSyncHelper().addCallback(new ICallback() {
@Override
public void onFinish() {
swipeRefreshLayout.setRefreshing(false);
adapter.clearSelection();
if (mActionMode != null) {
mActionMode.finish();
}
setListView(db.getNotes());
}
});
db.synchronizeWithServer();
}
/**
* Click listener for <strong>Floating Action Button</strong>
* <p/>