Search in sources :

Example 1 with PleaseApplyOpeningTimeChange

use of io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange 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)

Example 2 with PleaseApplyOpeningTimeChange

use of io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange in project osm-contributor by jawg.

the class OpeningHoursLinearLayoutAdapter method initEditOpeningHours.

private void initEditOpeningHours(final List<OpeningHours> originalHoursList) {
    View openingHoursItem = LayoutInflater.from(activity).inflate(R.layout.item_opening_hours, linearLayout, false);
    final EditText textViewDaysValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_days_value);
    final EditText textViewHoursValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_hours_value);
    // When the days input text is clicked, we start the dialog to pick
    // the opening days and hours
    View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditDaysDialogFragment fragment = new EditDaysDialogFragment();
            fragment.setOnEditDaysListener(new EditDaysDialogFragment.OnEditDaysListener() {

                @Override
                public void onOpeningTimeChanged(OpeningHours openingHours) {
                    addOpeningHours(openingHours);
                    originalHoursList.add(openingHours);
                    eventBus.post(new PleaseApplyOpeningTimeChange(openingTime));
                }
            });
            fragment.show(activity.getFragmentManager(), EditDaysDialogFragment.class.getSimpleName());
        }
    };
    textViewDaysValue.setOnClickListener(onClickListener);
    textViewHoursValue.setOnClickListener(onClickListener);
    if (this.openingHoursList.size() == linearLayout.getChildCount()) {
        linearLayout.addView(openingHoursItem);
    }
}
Also used : EditText(android.widget.EditText) PleaseApplyOpeningTimeChange(io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange) EditDaysDialogFragment(io.jawg.osmcontributor.ui.dialogs.EditDaysDialogFragment) View(android.view.View) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours)

Example 3 with PleaseApplyOpeningTimeChange

use of io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange in project osm-contributor by jawg.

the class OpeningHoursLinearLayoutAdapter method addOpeningHours.

public void addOpeningHours(final OpeningHours openingHours) {
    View openingHoursItem = LayoutInflater.from(activity).inflate(R.layout.item_opening_hours, linearLayout, false);
    openingHoursList.add(openingHours);
    final EditText textViewDaysValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_days_value);
    final EditText textViewHoursValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_hours_value);
    String[] openingHoursPart = openingHoursValueParser.toValue(Collections.singletonList(openingHours)).split(" ");
    if (openingHoursPart.length > 1) {
        String[] days = openingHoursPart[0].split("-");
        if (days.length == 7) {
            textViewDaysValue.setText("7/7");
        } else {
            textViewDaysValue.setText(openingHoursPart[0]);
        }
        String[] hours = openingHoursPart[1].split("-");
        if (hours[0].equals(hours[1])) {
            textViewHoursValue.setText("24/24");
        } else if (hasToHide) {
            textViewHoursValue.setText(openingHoursPart[1].substring(0, 5));
        } else {
            textViewHoursValue.setText(openingHoursPart[1]);
        }
    } else {
        if (openingHoursPart[0].equals("24/7")) {
            textViewDaysValue.setText("7/7");
            textViewHoursValue.setText("24/24");
        }
    }
    // When the days input text is clicked, we start the dialog to pick
    // the opening days and hours
    View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditDaysDialogFragment fragment = new EditDaysDialogFragment();
            fragment.setOpeningHours(openingHours);
            fragment.setOnEditDaysListener(new EditDaysDialogFragment.OnEditDaysListener() {

                @Override
                public void onOpeningTimeChanged(OpeningHours openingHours) {
                    eventBus.post(new PleaseApplyOpeningTimeChange(openingTime));
                    String[] openingHoursPart = openingHoursValueParser.toValue(Collections.singletonList(openingHours)).split(" ");
                    if (openingHoursPart.length > 1) {
                        textViewDaysValue.setText(openingHoursPart[0]);
                        if (hasToHide) {
                            textViewHoursValue.setText(openingHoursPart[1].substring(0, 5));
                        } else {
                            textViewHoursValue.setText(openingHoursPart[1]);
                        }
                    } else if (openingHoursPart[0].equals("24/7")) {
                        textViewDaysValue.setText("7/7");
                        textViewHoursValue.setText("24/24");
                    }
                }
            });
            fragment.show(activity.getFragmentManager(), EditDaysDialogFragment.class.getSimpleName());
        }
    };
    textViewDaysValue.setOnClickListener(onClickListener);
    textViewHoursValue.setOnClickListener(onClickListener);
    linearLayout.addView(openingHoursItem, linearLayout.getChildCount() - 1);
}
Also used : EditText(android.widget.EditText) PleaseApplyOpeningTimeChange(io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange) EditDaysDialogFragment(io.jawg.osmcontributor.ui.dialogs.EditDaysDialogFragment) View(android.view.View) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours)

Aggregations

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