Skip to content

Commit

Permalink
Merge pull request #5305 from grzesiek2010/COLLECT-5195
Browse files Browse the repository at this point in the history
Allow sorting blank forms by last saved
  • Loading branch information
grzesiek2010 authored Nov 15, 2022
2 parents 40dddb2 + 67b7d9d commit 81d3e52
Show file tree
Hide file tree
Showing 24 changed files with 578 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@
import android.widget.ProgressBar;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.core.view.MenuItemCompat;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.bottomsheet.BottomSheetDialog;

import org.odk.collect.android.R;
import org.odk.collect.android.adapters.SortDialogAdapter;
import org.odk.collect.android.database.instances.DatabaseInstanceColumns;
import org.odk.collect.android.listeners.RecyclerViewClickListener;
import org.odk.collect.android.utilities.SnackbarUtils;
import org.odk.collect.android.formlists.sorting.FormListSortingBottomSheetDialog;
import org.odk.collect.android.formlists.sorting.FormListSortingOption;
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard;

import java.util.ArrayList;
Expand All @@ -61,22 +54,18 @@ abstract class AppListActivity extends CollectAbstractActivity {

protected CursorAdapter listAdapter;
protected LinkedHashSet<Long> selectedInstances = new LinkedHashSet<>();
protected int[] sortingOptions;
protected List<FormListSortingOption> sortingOptions;
protected Integer selectedSortingOrder;
protected ListView listView;
protected LinearLayout llParent;
protected ProgressBar progressBar;
private BottomSheetDialog bottomSheetDialog;

private String filterText;
private String savedFilterText;
private boolean isSearchBoxShown;

private SearchView searchView;

private boolean canHideProgressBar;
private boolean progressBarVisible;

// toggles to all checked or all unchecked
// returns:
// true if result is all checked
Expand Down Expand Up @@ -221,20 +210,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}

switch (item.getItemId()) {
case R.id.menu_sort:
showBottomSheetDialog();
return true;
if (item.getItemId() == R.id.menu_sort) {
new FormListSortingBottomSheetDialog(
this,
sortingOptions,
selectedSortingOrder,
selectedOption -> {
saveSelectedSortingOrder(selectedOption);
updateAdapter();
}
).show();
return true;
}

return super.onOptionsItemSelected(item);
}

private void performSelectedSearch(int position) {
saveSelectedSortingOrder(position);
updateAdapter();
}

protected void checkPreviouslyCheckedItems() {
listView.clearChoices();
List<Integer> selectedPositions = new ArrayList<>();
Expand Down Expand Up @@ -291,50 +282,15 @@ protected void clearSearchView() {
searchView.setQuery("", false);
}

private void showBottomSheetDialog() {
bottomSheetDialog = new BottomSheetDialog(this);
final View sheetView = getLayoutInflater().inflate(R.layout.bottom_sheet, null);
final RecyclerView recyclerView = sheetView.findViewById(R.id.recyclerView);

final SortDialogAdapter adapter = new SortDialogAdapter(this, recyclerView, sortingOptions, getSelectedSortingOrder(), new RecyclerViewClickListener() {
@Override
public void onItemClicked(SortDialogAdapter.ViewHolder holder, int position) {
holder.updateItemColor(selectedSortingOrder);
performSelectedSearch(position);
bottomSheetDialog.dismiss();
}
});
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());

bottomSheetDialog.setContentView(sheetView);
bottomSheetDialog.show();
}

protected void showSnackbar(@NonNull String result) {
SnackbarUtils.showShortSnackbar(llParent, result);
}

protected void hideProgressBarIfAllowed() {
if (canHideProgressBar && progressBarVisible) {
hideProgressBar();
}
}

protected void hideProgressBarAndAllow() {
this.canHideProgressBar = true;
hideProgressBar();
}

private void hideProgressBar() {
progressBar.setVisibility(View.GONE);
progressBarVisible = false;
}

protected void showProgressBar() {
progressBar.setVisibility(View.VISIBLE);
progressBarVisible = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.odk.collect.android.activities.viewmodels.FormDownloadListViewModel;
import org.odk.collect.android.adapters.FormDownloadListAdapter;
import org.odk.collect.android.formentry.RefreshFormListDialogFragment;
import org.odk.collect.android.formlists.sorting.FormListSortingOption;
import org.odk.collect.android.formmanagement.FormDownloadException;
import org.odk.collect.android.formmanagement.FormDownloader;
import org.odk.collect.android.formmanagement.FormSourceExceptionMapper;
Expand All @@ -64,6 +65,7 @@
import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -246,9 +248,16 @@ && getLastCustomNonConfigurationInstance() == null
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemsCanFocus(false);

sortingOptions = new int[]{
R.string.sort_by_name_asc, R.string.sort_by_name_desc
};
sortingOptions = Arrays.asList(
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_asc
),
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_desc
)
);
}

private void clearChoices() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.odk.collect.android.dao.CursorLoaderFactory;
import org.odk.collect.android.database.instances.DatabaseInstanceColumns;
import org.odk.collect.android.external.InstancesContract;
import org.odk.collect.android.formlists.sorting.FormListSortingOption;
import org.odk.collect.android.injection.DaggerUtils;
import org.odk.collect.android.projects.CurrentProjectProvider;
import org.odk.collect.android.utilities.ApplicationConstants;
Expand All @@ -46,6 +47,8 @@
import org.odk.collect.forms.Form;
import org.odk.collect.forms.instances.Instance;

import java.util.Arrays;

import javax.inject.Inject;

/**
Expand Down Expand Up @@ -79,18 +82,53 @@ public void onCreate(Bundle savedInstanceState) {

setTitle(getString(R.string.review_data));
editMode = true;
sortingOptions = new int[]{
R.string.sort_by_name_asc, R.string.sort_by_name_desc,
R.string.sort_by_date_desc, R.string.sort_by_date_asc,
R.string.sort_by_status_asc, R.string.sort_by_status_desc
};
sortingOptions = Arrays.asList(
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_asc
),
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_desc
),
new FormListSortingOption(
R.drawable.ic_access_time,
R.string.sort_by_date_desc
),
new FormListSortingOption(
R.drawable.ic_access_time,
R.string.sort_by_date_asc
),
new FormListSortingOption(
R.drawable.ic_assignment_turned_in,
R.string.sort_by_status_asc
),
new FormListSortingOption(
R.drawable.ic_assignment_late,
R.string.sort_by_status_desc
)
);
} else {
setTitle(getString(R.string.view_sent_forms));

sortingOptions = new int[]{
R.string.sort_by_name_asc, R.string.sort_by_name_desc,
R.string.sort_by_date_desc, R.string.sort_by_date_asc
};
sortingOptions = Arrays.asList(
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_asc
),
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_desc
),
new FormListSortingOption(
R.drawable.ic_access_time,
R.string.sort_by_date_desc
),
new FormListSortingOption(
R.drawable.ic_access_time,
R.string.sort_by_date_asc
)
);
((TextView) findViewById(android.R.id.empty)).setText(R.string.no_items_display_sent_forms);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.odk.collect.android.backgroundwork.InstanceSubmitScheduler;
import org.odk.collect.android.dao.CursorLoaderFactory;
import org.odk.collect.android.databinding.InstanceUploaderListBinding;
import org.odk.collect.android.formlists.sorting.FormListSortingOption;
import org.odk.collect.android.gdrive.GoogleSheetsUploaderActivity;
import org.odk.collect.android.injection.DaggerUtils;
import org.odk.collect.androidshared.network.NetworkStateProvider;
Expand All @@ -55,6 +56,7 @@
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard;
import org.odk.collect.settings.keys.ProjectKeys;

import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;
Expand Down Expand Up @@ -168,10 +170,24 @@ void init() {
binding.uploadButton.setEnabled(areCheckedItems());
});

sortingOptions = new int[]{
R.string.sort_by_name_asc, R.string.sort_by_name_desc,
R.string.sort_by_date_desc, R.string.sort_by_date_asc
};
sortingOptions = Arrays.asList(
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_asc
),
new FormListSortingOption(
R.drawable.ic_sort_by_alpha,
R.string.sort_by_name_desc
),
new FormListSortingOption(
R.drawable.ic_access_time,
R.string.sort_by_date_desc
),
new FormListSortingOption(
R.drawable.ic_access_time,
R.string.sort_by_date_asc
)
);

getSupportLoaderManager().initLoader(LOADER_ID, null, this);

Expand Down
Loading

0 comments on commit 81d3e52

Please sign in to comment.