Search in sources :

Example 1 with LabelDialogItem

use of com.github.pockethub.android.ui.item.dialog.LabelDialogItem in project PocketHub by pockethub.

the class LabelsDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    selectedChoices = getArguments().getBooleanArray(ARG_SELECTED_CHOICES);
    ArrayList<Label> choices = getChoices();
    List<String> selected = new ArrayList<>();
    if (selectedChoices != null) {
        for (int i = 0; i < choices.size(); i++) {
            if (selectedChoices[i]) {
                selected.add(choices.get(i).name());
            }
        }
    }
    adapter = new GroupAdapter();
    for (Label label : getChoices()) {
        adapter.add(new LabelDialogItem(label, selected.contains(label.name())));
    }
    adapter.setOnItemClickListener(this);
    return createDialogBuilder().adapter(adapter, null).negativeText(R.string.cancel).neutralText(R.string.clear).positiveText(R.string.apply).onNeutral((dialog, which) -> {
        Arrays.fill(getArguments().getBooleanArray(ARG_SELECTED_CHOICES), false);
        onResult(RESULT_OK);
    }).onPositive((dialog, which) -> onResult(RESULT_OK)).build();
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) RESULT_OK(android.app.Activity.RESULT_OK) Dialog(android.app.Dialog) DialogFragmentHelper(com.github.pockethub.android.ui.base.DialogFragmentHelper) GroupAdapter(com.xwray.groupie.GroupAdapter) ArrayList(java.util.ArrayList) BaseActivity(com.github.pockethub.android.ui.base.BaseActivity) List(java.util.List) Item(com.xwray.groupie.Item) Label(com.meisolsson.githubsdk.model.Label) View(android.view.View) R(com.github.pockethub.android.R) OnItemClickListener(com.xwray.groupie.OnItemClickListener) LabelDialogItem(com.github.pockethub.android.ui.item.dialog.LabelDialogItem) GroupAdapter(com.xwray.groupie.GroupAdapter) Label(com.meisolsson.githubsdk.model.Label) ArrayList(java.util.ArrayList) LabelDialogItem(com.github.pockethub.android.ui.item.dialog.LabelDialogItem) NonNull(androidx.annotation.NonNull)

Example 2 with LabelDialogItem

use of com.github.pockethub.android.ui.item.dialog.LabelDialogItem in project PocketHub by pockethub.

the class LabelsDialogFragment method onItemClick.

@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
    if (item instanceof LabelDialogItem) {
        LabelDialogItem labelDialogItem = (LabelDialogItem) item;
        labelDialogItem.toggleSelected();
        selectedChoices[adapter.getAdapterPosition(item)] = labelDialogItem.isSelected();
        item.notifyChanged();
    }
}
Also used : LabelDialogItem(com.github.pockethub.android.ui.item.dialog.LabelDialogItem)

Aggregations

LabelDialogItem (com.github.pockethub.android.ui.item.dialog.LabelDialogItem)2 RESULT_OK (android.app.Activity.RESULT_OK)1 Dialog (android.app.Dialog)1 Bundle (android.os.Bundle)1 View (android.view.View)1 NonNull (androidx.annotation.NonNull)1 R (com.github.pockethub.android.R)1 BaseActivity (com.github.pockethub.android.ui.base.BaseActivity)1 DialogFragmentHelper (com.github.pockethub.android.ui.base.DialogFragmentHelper)1 Label (com.meisolsson.githubsdk.model.Label)1 GroupAdapter (com.xwray.groupie.GroupAdapter)1 Item (com.xwray.groupie.Item)1 OnItemClickListener (com.xwray.groupie.OnItemClickListener)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1