Search in sources :

Example 11 with OpeningHours

use of io.jawg.osmcontributor.model.utils.OpeningHours in project osm-contributor by jawg.

the class OpeningHoursValueParser method fromSingleValue.

public void fromSingleValue(String value, List<OpeningHours> openingHoursList) {
    // TODO: 19/07/16 We,Fr-Sa 10:45-19:15, Tu,Sa-Su 05:30-17:30, We 08:00-18:00
    OpeningHours openingHours = new OpeningHours();
    openingHours.setAllDaysActivated(false);
    String[] openingHoursValues = value.split(DAYS_SEP);
    String daysPart = null;
    String hoursPart = null;
    if (value.equals("24/7")) {
        daysPart = "Mo-Su";
        hoursPart = "24:00-24:00";
    } else if (openingHoursValues.length == 2) {
        daysPart = openingHoursValues[0];
        hoursPart = openingHoursValues[1];
    } else if (openingHoursValues.length == 1) {
        hoursPart = openingHoursValues[0];
    }
    if (daysPart != null) {
        String[] dayPeriods = daysPart.split(RULE_SEP);
        for (String period : dayPeriods) {
            if (isPeriod(period)) {
                OpeningHours.Days[] d = OpeningHours.Days.fromDatas(period.split(RANGE_SEP));
                for (int i = d[0].ordinal(); i <= d[1].ordinal(); i++) {
                    openingHours.setDayActivated(i, true);
                }
            } else {
                openingHours.setDayActivated(OpeningHours.Days.fromData(period).ordinal(), true);
            }
        }
    }
    if (hoursPart != null) {
        String[] hours = hoursPart.split(",");
        if (hours.length > 1) {
            for (String hour : hours) {
                value = daysPart + " " + hour;
                fromSingleValue(value, openingHoursList);
            }
        } else {
            String[] hourPeriod = hoursPart.split(RANGE_SEP);
            LocalTime from = TIME_FORMATTER.parseLocalTime(hourPeriod[0]);
            if (hourPeriod.length > 1) {
                LocalTime to = TIME_FORMATTER.parseLocalTime(hourPeriod[1]);
                openingHours.setToTime(to);
            } else {
                openingHours.setToTime(from.plusMinutes(5));
            }
            openingHours.setFromTime(from);
            openingHoursList.add(openingHours);
        }
    }
// return openingHours;
}
Also used : LocalTime(org.joda.time.LocalTime) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours)

Example 12 with OpeningHours

use of io.jawg.osmcontributor.model.utils.OpeningHours in project osm-contributor by jawg.

the class OpeningMonthValueParser method fromValue.

@Override
public OpeningMonth fromValue(String value) {
    if (value.trim().isEmpty()) {
        return null;
    }
    OpeningMonth openingMonth = new OpeningMonth();
    String[] split = value.split(MONTH_SEP);
    if (isMonthPresent(value)) {
        // Get the left part of the expression
        String monthsValue = split[0];
        String[] periods = monthsValue.split(RULE_SEP);
        for (String period : periods) {
            if (isPeriod(period)) {
                OpeningMonth.Month[] months = OpeningMonth.Month.fromDatas(period.split(RANGE_SEP));
                for (int i = months[0].ordinal(); i <= months[1].ordinal(); i++) {
                    openingMonth.setMonthActivated(i, true);
                }
            } else {
                openingMonth.setMonthActivated(OpeningMonth.Month.fromData(period).ordinal(), true);
            }
        }
    } else {
        List<OpeningHours> openingHours = openingHoursValueParser.fromValue(value);
        if (openingHours != null) {
            openingMonth.addOpeningHours(openingHours);
        }
    }
    if (split.length == 2) {
        String openingHoursValue = split[1];
        if (openingHoursValue != null && !openingHoursValue.trim().isEmpty()) {
            List<OpeningHours> openingHours = openingHoursValueParser.fromValue(openingHoursValue);
            if (openingHours != null) {
                openingMonth.addOpeningHours(openingHours);
            }
        }
    }
    return openingMonth;
}
Also used : OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours)

Example 13 with OpeningHours

use of io.jawg.osmcontributor.model.utils.OpeningHours 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 14 with OpeningHours

use of io.jawg.osmcontributor.model.utils.OpeningHours 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)

Example 15 with OpeningHours

use of io.jawg.osmcontributor.model.utils.OpeningHours in project osm-contributor by jawg.

the class OpeningHoursValueParserTest method isNonStop1.

@Test
public void isNonStop1() {
    OpeningHours openingHours = new OpeningHours();
    openingHours.setFromTime(new LocalTime(0, 0));
    openingHours.setToTime(new LocalTime(0, 0));
    openingHours.setDays(OpeningHours.Days.values());
    Assert.assertTrue(parser.isNonStop(openingHours));
}
Also used : LocalTime(org.joda.time.LocalTime) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours) Test(org.junit.Test)

Aggregations

OpeningHours (io.jawg.osmcontributor.model.utils.OpeningHours)26 Test (org.junit.Test)21 LocalTime (org.joda.time.LocalTime)17 OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)12 OpeningTime (io.jawg.osmcontributor.model.utils.OpeningTime)9 View (android.view.View)2 EditText (android.widget.EditText)2 EditDaysDialogFragment (io.jawg.osmcontributor.ui.dialogs.EditDaysDialogFragment)2 PleaseApplyOpeningTimeChange (io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange)2