Search in sources :

Example 1 with EditMonthsDialogFragment

use of io.jawg.osmcontributor.ui.dialogs.EditMonthsDialogFragment in project osm-contributor by jawg.

the class OpeningMonthAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final OpeningTimeHolder holder, int position) {
    final OpeningMonth openingMonth = openingTime.getOpeningMonths().get(position);
    holder.getTextInputLayout().setVisibility(hasToHide ? View.INVISIBLE : View.VISIBLE);
    String[] split = openingMonthValueParser.toValue(openingMonth).split(OpeningMonthValueParser.MONTH_SEP);
    if (split.length > 1) {
        holder.getTextViewMonthValue().setText(openingMonthValueParser.toValue(openingMonth).split(OpeningMonthValueParser.MONTH_SEP)[0]);
    }
    // When the months input text is clicked, we start the dialog to pick
    // the opening months
    holder.getTextViewMonthValue().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditMonthsDialogFragment fragment = new EditMonthsDialogFragment();
            fragment.setOpeningMonth(openingMonth);
            fragment.setOnEditMonthsListener(new EditMonthsDialogFragment.OnEditMonthsTagListener() {

                @Override
                public void onOpeningMonthChanged(OpeningMonth o) {
                    openingMonth.setMonths(o.getMonths());
                    String[] split = openingMonthValueParser.toValue(openingMonth).split(OpeningMonthValueParser.MONTH_SEP);
                    if (split.length > 1) {
                        holder.getTextViewMonthValue().setText(openingMonthValueParser.toValue(openingMonth).split(OpeningMonthValueParser.MONTH_SEP)[0]);
                    }
                    eventBus.post(new PleaseApplyOpeningTimeChange(openingTime));
                }
            });
            fragment.show(activity.getFragmentManager(), EditDaysDialogFragment.class.getSimpleName());
        }
    });
    holder.getDeleteButton().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openingTime.getOpeningMonths().remove(openingMonth);
            eventBus.post(new PleaseApplyOpeningTimeChange(openingTime));
            notifyDataSetChanged();
        }
    });
    holder.getOpeningHoursLayout().removeAllViews();
    new OpeningHoursLinearLayoutAdapter(openingTime, openingMonth.getOpeningHours(), holder.getOpeningHoursLayout(), activity, hasToHide);
}
Also used : PleaseApplyOpeningTimeChange(io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange) OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) EditMonthsDialogFragment(io.jawg.osmcontributor.ui.dialogs.EditMonthsDialogFragment) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BindView (butterknife.BindView)1 OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)1 EditMonthsDialogFragment (io.jawg.osmcontributor.ui.dialogs.EditMonthsDialogFragment)1 PleaseApplyOpeningTimeChange (io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange)1