Skip to content

Commit

Permalink
Fixes Issue#352: No adapter attached; Skipping layout in BlankFormsFr…
Browse files Browse the repository at this point in the history
…agment and FilledFormsFragment (getodk#353)

* fixed recyclerview: skipping layout

* resolved conflicts

* reverting the curson to null when resetting the loader

* fixed pmd
  • Loading branch information
SaumiaSinghal authored Feb 26, 2020
1 parent 8763f6b commit 6d03204
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,20 @@ 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;
}

public Cursor getCursor() {
return cursor;
}

public void setCursor(Cursor cursor) {
this.cursor = cursor;
}

public interface OnItemClickListener {
void onItemClick(View v, int position);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ public void onResume() {
@NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
formAdapter = new FormsAdapter(getActivity(), null, this, selectedForms, instancesDao, transferDao);
recyclerView.setAdapter(formAdapter);
return formsDao.getFormsCursorLoader(getFilterText(), getSortingOrder());
}

@Override
public void onLoadFinished(@NonNull Loader<Cursor> 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));
Expand All @@ -122,6 +123,7 @@ public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {

@Override
public void onLoaderReset(@NonNull Loader loader) {
formAdapter.swapCursor(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ public void onResume() {
@NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
instanceAdapter = new InstanceAdapter(getActivity(), null, this::onListItemClick, selectedInstances);
recyclerView.setAdapter(instanceAdapter);
return instancesDao.getSavedInstancesCursorLoader(getFilterText(), getSortingOrder());
}

@Override
public void onLoadFinished(@NonNull Loader<Cursor> 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));
Expand All @@ -115,6 +116,7 @@ public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {

@Override
public void onLoaderReset(@NonNull Loader loader) {
instanceAdapter.setCursor(null);
}

private void onListItemClick(View view, int position) {
Expand Down

0 comments on commit 6d03204

Please sign in to comment.