@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setUpViews(); BoxStore boxStore = ((App) getApplication()).getBoxStore(); notesBox = boxStore.boxFor(Note.class); // query all notes, sorted a-z by their text (https://docs.objectbox.io/queries) notesQuery = notesBox.query().order(Note_.text).build(); updateNotes(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setUpViews(); // get the note DAO DaoSession daoSession = ((App) getApplication()).getDaoSession(); noteDao = daoSession.getNoteDao(); // query all notes notesQuery = noteDao.queryBuilder().orderAsc(Properties.Text).build(); updateNotes(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_paged); setUpViews(); BoxStore boxStore = ((App) getApplication()).getBoxStore(); notesBox = boxStore.boxFor(Note.class); NotePagedViewModel model = ViewModelProviders.of(this).get(NotePagedViewModel.class); model.getNoteLiveDataPaged(notesBox).observe(this, new Observer<PagedList<Note>>() { @Override public void onChanged(@Nullable PagedList<Note> notes) { notesAdapter.submitList(notes); } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setUpViews(); BoxStore boxStore = ((App) getApplication()).getBoxStore(); notesBox = boxStore.boxFor(Note.class); NoteViewModel model = ViewModelProviders.of(this).get(NoteViewModel.class); model.getNoteLiveData(notesBox).observe(this, new Observer<List<Note>>() { @Override public void onChanged(@Nullable List<Note> notes) { notesAdapter.setNotes(notes); } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setUpViews(); notesBox = ((App) getApplication()).getBoxStore().boxFor(Note.class); // query all notes, sorted a-z by their text (https://docs.objectbox.io/queries) notesQuery = notesBox.query().order(Note_.text).build(); // Reactive query (https://docs.objectbox.io/data-observers-and-rx) notesQuery.subscribe(subscriptions).on(AndroidScheduler.mainThread()) .observer(new DataObserver<List<Note>>() { @Override public void onData(List<Note> notes) { notesAdapter.setNotes(notes); } }); }