diff --git a/skunkworks_crow/src/main/java/org/odk/share/views/ui/instance/adapter/InstanceAdapter.java b/skunkworks_crow/src/main/java/org/odk/share/views/ui/instance/adapter/InstanceAdapter.java index 21dcee31..9b7c2564 100644 --- a/skunkworks_crow/src/main/java/org/odk/share/views/ui/instance/adapter/InstanceAdapter.java +++ b/skunkworks_crow/src/main/java/org/odk/share/views/ui/instance/adapter/InstanceAdapter.java @@ -101,6 +101,9 @@ public static String getDisplaySubtext(Context context, String state, Date date) @Override public int getItemCount() { + if (cursor == null) { + return 0; + } return !cursor.isClosed() ? cursor.getCount() : 0; } @@ -108,6 +111,10 @@ public Cursor getCursor() { return cursor; } + public void setCursor(Cursor cursor) { + this.cursor = cursor; + } + public interface OnItemClickListener { void onItemClick(View v, int position); } diff --git a/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/BlankFormsFragment.java b/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/BlankFormsFragment.java index 740bc0de..fade419c 100644 --- a/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/BlankFormsFragment.java +++ b/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/BlankFormsFragment.java @@ -99,6 +99,8 @@ public void onResume() { @NonNull @Override public Loader onCreateLoader(int id, Bundle args) { + formAdapter = new FormsAdapter(getActivity(), null, this, selectedForms, instancesDao, transferDao); + recyclerView.setAdapter(formAdapter); return formsDao.getFormsCursorLoader(getFilterText(), getSortingOrder()); } @@ -106,8 +108,7 @@ public Loader onCreateLoader(int id, Bundle args) { public void onLoadFinished(@NonNull Loader loader, Cursor cursor) { if (cursor != null) { cursor.moveToFirst(); - formAdapter = new FormsAdapter(getActivity(), cursor, this, selectedForms, instancesDao, transferDao); - recyclerView.setAdapter(formAdapter); + formAdapter.swapCursor(cursor); setEmptyViewVisibility(cursor.getCount()); if (formAdapter.getItemCount() > 0) { toggleButton.setText(getString(R.string.select_all)); @@ -122,6 +123,7 @@ public void onLoadFinished(@NonNull Loader loader, Cursor cursor) { @Override public void onLoaderReset(@NonNull Loader loader) { + formAdapter.swapCursor(null); } @Override diff --git a/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/FilledFormsFragment.java b/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/FilledFormsFragment.java index 1763b83e..58ab1a4b 100644 --- a/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/FilledFormsFragment.java +++ b/skunkworks_crow/src/main/java/org/odk/share/views/ui/send/fragment/FilledFormsFragment.java @@ -92,6 +92,8 @@ public void onResume() { @NonNull @Override public Loader onCreateLoader(int id, Bundle args) { + instanceAdapter = new InstanceAdapter(getActivity(), null, this::onListItemClick, selectedInstances); + recyclerView.setAdapter(instanceAdapter); return instancesDao.getSavedInstancesCursorLoader(getFilterText(), getSortingOrder()); } @@ -99,8 +101,7 @@ public Loader onCreateLoader(int id, Bundle args) { public void onLoadFinished(@NonNull Loader loader, Cursor cursor) { if (cursor != null) { cursor.moveToFirst(); - instanceAdapter = new InstanceAdapter(getActivity(), cursor, this::onListItemClick, selectedInstances); - recyclerView.setAdapter(instanceAdapter); + instanceAdapter.setCursor(cursor); setEmptyViewVisibility(cursor.getCount()); if (instanceAdapter.getItemCount() > 0) { toggleButton.setText(getString(R.string.select_all)); @@ -115,6 +116,7 @@ public void onLoadFinished(@NonNull Loader loader, Cursor cursor) { @Override public void onLoaderReset(@NonNull Loader loader) { + instanceAdapter.setCursor(null); } private void onListItemClick(View view, int position) {