Loading app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +5 −1 Original line number Diff line number Diff line Loading @@ -100,7 +100,11 @@ public class NotesListViewActivity extends AppCompatActivity implements if (mActionMode != null) { mActionMode.finish(); } if(adapter == null) { setListView(db.getNotes()); } else { // Do not reinstanciate but only update the adapter adapter.checkForUpdates(db.getNotes()); } } }); db.getNoteServerSyncHelper().downloadNotes(); Loading app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +34 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ import android.view.ViewGroup; import android.widget.TextView; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import it.niedermann.owncloud.notes.R; Loading @@ -34,11 +35,42 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { ItemAdapter.noteClickListener = noteClickListener; } public void add(Note createdNote) { itemList.add(0, createdNote); public void add(Note note) { itemList.add(0, note); notifyDataSetChanged(); } /** * Compares the given List of notes to the current internal holded notes and updates the list if necessairy * @param newNotes List of more up to date notes */ public void checkForUpdates(List<Note> newNotes) { for(Note newNote : newNotes) { boolean foundNewNoteInOldList = false; for(Item oldItem : itemList) { if(!oldItem.isSection()) { Note oldNote = (Note) oldItem; if(newNote.getId() == oldNote.getId()) { // Notes have the same id, check which is newer if(newNote.getModified().after(oldNote.getModified())) { Log.v("Note", "Replacing old Note with new Note (new Note is more up to date)"); int indexOfOldNote = itemList.indexOf(oldNote); itemList.remove(indexOfOldNote); itemList.add(indexOfOldNote, newNote); this.notifyDataSetChanged(); } foundNewNoteInOldList = true; break; } } } if(!foundNewNoteInOldList) { Log.v("Note", "new note not found -- adding now.... " + newNote); add(newNote); } } } // Create new views (invoked by the layout manager) @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +5 −1 Original line number Diff line number Diff line Loading @@ -100,7 +100,11 @@ public class NotesListViewActivity extends AppCompatActivity implements if (mActionMode != null) { mActionMode.finish(); } if(adapter == null) { setListView(db.getNotes()); } else { // Do not reinstanciate but only update the adapter adapter.checkForUpdates(db.getNotes()); } } }); db.getNoteServerSyncHelper().downloadNotes(); Loading
app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +34 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ import android.view.ViewGroup; import android.widget.TextView; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import it.niedermann.owncloud.notes.R; Loading @@ -34,11 +35,42 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { ItemAdapter.noteClickListener = noteClickListener; } public void add(Note createdNote) { itemList.add(0, createdNote); public void add(Note note) { itemList.add(0, note); notifyDataSetChanged(); } /** * Compares the given List of notes to the current internal holded notes and updates the list if necessairy * @param newNotes List of more up to date notes */ public void checkForUpdates(List<Note> newNotes) { for(Note newNote : newNotes) { boolean foundNewNoteInOldList = false; for(Item oldItem : itemList) { if(!oldItem.isSection()) { Note oldNote = (Note) oldItem; if(newNote.getId() == oldNote.getId()) { // Notes have the same id, check which is newer if(newNote.getModified().after(oldNote.getModified())) { Log.v("Note", "Replacing old Note with new Note (new Note is more up to date)"); int indexOfOldNote = itemList.indexOf(oldNote); itemList.remove(indexOfOldNote); itemList.add(indexOfOldNote, newNote); this.notifyDataSetChanged(); } foundNewNoteInOldList = true; break; } } } if(!foundNewNoteInOldList) { Log.v("Note", "new note not found -- adding now.... " + newNote); add(newNote); } } } // Create new views (invoked by the layout manager) @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, Loading