Search in sources :

Example 1 with CollectAbstractActivity

use of org.odk.collect.android.activities.CollectAbstractActivity in project collect by opendatakit.

the class AppListFragment method setupBottomSheet.

private void setupBottomSheet() {
    CollectAbstractActivity activity = (CollectAbstractActivity) getActivity();
    if (activity == null) {
        Timber.e("Activity is null");
        return;
    }
    bottomSheetDialog = new BottomSheetDialog(activity);
    View sheetView = getActivity().getLayoutInflater().inflate(R.layout.bottom_sheet, null);
    final RecyclerView recyclerView = sheetView.findViewById(R.id.recyclerView);
    final SortDialogAdapter adapter = new SortDialogAdapter(getActivity(), 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(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    bottomSheetDialog.setContentView(sheetView);
}
Also used : CollectAbstractActivity(org.odk.collect.android.activities.CollectAbstractActivity) BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) SortDialogAdapter(org.odk.collect.android.adapters.SortDialogAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(androidx.appcompat.widget.SearchView) ListView(android.widget.ListView) RecyclerViewClickListener(org.odk.collect.android.listeners.RecyclerViewClickListener) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 2 with CollectAbstractActivity

use of org.odk.collect.android.activities.CollectAbstractActivity in project collect by opendatakit.

the class ResetDialogPreferenceFragmentCompat method handleResult.

private void handleResult(final List<Integer> resetActions, List<Integer> failedResetActions) {
    final StringBuilder resultMessage = new StringBuilder();
    for (int action : resetActions) {
        switch(action) {
            case RESET_PREFERENCES:
                if (failedResetActions.contains(action)) {
                    resultMessage.append(String.format(context.getString(R.string.reset_settings_result), context.getString(R.string.error_occured)));
                } else {
                    resultMessage.append(String.format(context.getString(R.string.reset_settings_result), context.getString(R.string.success)));
                }
                break;
            case ProjectResetter.ResetAction.RESET_INSTANCES:
                if (failedResetActions.contains(action)) {
                    resultMessage.append(String.format(context.getString(R.string.reset_saved_forms_result), context.getString(R.string.error_occured)));
                } else {
                    resultMessage.append(String.format(context.getString(R.string.reset_saved_forms_result), context.getString(R.string.success)));
                }
                break;
            case ProjectResetter.ResetAction.RESET_FORMS:
                if (failedResetActions.contains(action)) {
                    resultMessage.append(String.format(context.getString(R.string.reset_blank_forms_result), context.getString(R.string.error_occured)));
                } else {
                    resultMessage.append(String.format(context.getString(R.string.reset_blank_forms_result), context.getString(R.string.success)));
                }
                break;
            case ProjectResetter.ResetAction.RESET_CACHE:
                if (failedResetActions.contains(action)) {
                    resultMessage.append(String.format(context.getString(R.string.reset_cache_result), context.getString(R.string.error_occured)));
                } else {
                    resultMessage.append(String.format(context.getString(R.string.reset_cache_result), context.getString(R.string.success)));
                }
                break;
            case ProjectResetter.ResetAction.RESET_LAYERS:
                if (failedResetActions.contains(action)) {
                    resultMessage.append(String.format(context.getString(R.string.reset_layers_result), context.getString(R.string.error_occured)));
                } else {
                    resultMessage.append(String.format(context.getString(R.string.reset_layers_result), context.getString(R.string.success)));
                }
                break;
        }
        if (resetActions.indexOf(action) < resetActions.size() - 1) {
            resultMessage.append("\n\n");
        }
    }
    if (!((CollectAbstractActivity) context).isInstanceStateSaved()) {
        ((CollectAbstractActivity) context).runOnUiThread(() -> {
            if (resetActions.contains(RESET_PREFERENCES)) {
                ((CollectAbstractActivity) context).recreate();
            }
            ResetSettingsResultDialog resetSettingsResultDialog = ResetSettingsResultDialog.newInstance(String.valueOf(resultMessage));
            try {
                resetSettingsResultDialog.show(((CollectAbstractActivity) context).getSupportFragmentManager(), RESET_SETTINGS_RESULT_DIALOG_TAG);
            } catch (ClassCastException e) {
                Timber.i(e);
            }
        });
    }
    context = null;
}
Also used : CollectAbstractActivity(org.odk.collect.android.activities.CollectAbstractActivity) ResetSettingsResultDialog(org.odk.collect.android.fragments.dialogs.ResetSettingsResultDialog)

Aggregations

CollectAbstractActivity (org.odk.collect.android.activities.CollectAbstractActivity)2 View (android.view.View)1 ListView (android.widget.ListView)1 SearchView (androidx.appcompat.widget.SearchView)1 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 BottomSheetDialog (com.google.android.material.bottomsheet.BottomSheetDialog)1 SortDialogAdapter (org.odk.collect.android.adapters.SortDialogAdapter)1 ResetSettingsResultDialog (org.odk.collect.android.fragments.dialogs.ResetSettingsResultDialog)1 RecyclerViewClickListener (org.odk.collect.android.listeners.RecyclerViewClickListener)1