Search in sources :

Example 1 with OpeningTime

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

the class OpeningTimeValueParserTest method parseDays3.

@Test
public void parseDays3() {
    OpeningTime openingTime = new OpeningTime();
    OpeningMonth openingMonth = new OpeningMonth();
    OpeningHours openingHours = new OpeningHours();
    openingMonth.addOpeningHours(openingHours);
    openingHours.setDayActivated(0, true);
    openingHours.setDayActivated(1, true);
    openingHours.setDayActivated(2, true);
    openingHours.setDayActivated(3, true);
    openingHours.setDayActivated(4, true);
    openingHours.setDayActivated(5, true);
    openingHours.setDayActivated(6, true);
    openingHours.setDayActivated(5, false);
    openingTime.addOpeningMonth(openingMonth);
    Assert.assertEquals(parser.toValue(openingTime), "Mo-Fr,Su 08:00-18:00");
}
Also used : OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningTime(io.jawg.osmcontributor.model.utils.OpeningTime) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours) Test(org.junit.Test)

Example 2 with OpeningTime

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

the class OpeningTimeValueParserTest method parseOpeningHours1.

@Test
public void parseOpeningHours1() {
    OpeningTime openingTime = new OpeningTime();
    OpeningMonth openingMonth = new OpeningMonth();
    OpeningHours openingHours1 = new OpeningHours();
    OpeningHours openingHours2 = new OpeningHours();
    openingMonth.addOpeningHours(openingHours1);
    openingMonth.addOpeningHours(openingHours2);
    openingMonth.setMonthActivated(2, true);
    openingHours1.setAllDaysActivated(false);
    openingHours1.setDayActivated(2, true);
    openingHours2.setAllDaysActivated(false);
    openingHours2.setDayActivated(5, true);
    openingHours2.setFromTime(new LocalTime(5, 30));
    openingHours2.setToTime(new LocalTime(17, 30));
    openingTime.addOpeningMonth(openingMonth);
    Assert.assertEquals(parser.toValue(openingTime), "Mar: We 08:00-18:00, Sa 05:30-17:30");
}
Also used : LocalTime(org.joda.time.LocalTime) OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningTime(io.jawg.osmcontributor.model.utils.OpeningTime) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours) Test(org.junit.Test)

Example 3 with OpeningTime

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

the class OpeningTimeValueParserTest method fromValue1.

@Test
public void fromValue1() {
    String value = "Apr-May: Mo-Fr 10:15-01:30";
    OpeningTime openingTime = parser.fromValue(value);
    OpeningTime openingTimeExpected = new OpeningTime();
    OpeningMonth openingMonth = new OpeningMonth();
    openingTimeExpected.addOpeningMonth(openingMonth);
    openingMonth.setMonthActivated(3, true);
    openingMonth.setMonthActivated(4, true);
    OpeningHours openingHours = new OpeningHours();
    openingMonth.addOpeningHours(openingHours);
    openingHours.setFromTime(new LocalTime(10, 15));
    openingHours.setToTime(new LocalTime(1, 30));
    Assert.assertEquals(openingTimeExpected, openingTime);
}
Also used : LocalTime(org.joda.time.LocalTime) OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningTime(io.jawg.osmcontributor.model.utils.OpeningTime) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours) Test(org.junit.Test)

Example 4 with OpeningTime

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

the class OpeningHoursViewBinder method onBindViewHolder.

@Override
public void onBindViewHolder(TagItemOpeningTimeViewHolder holder, TagItem tagItem) {
    // Save holder
    this.content = holder.getContent();
    holder.getTextViewKey().setText(ParserManager.parseTagName(tagItem.getKey(), holder.getContent().getContext()));
    OpeningTime openingTime = null;
    try {
        openingTime = openingTimeValueParser.fromValue(tagItem.getValue());
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        tagItem.setConform(false);
    }
    if (openingTime == null) {
        openingTime = new OpeningTime();
    }
    final OpeningMonthAdapter adapter = new OpeningMonthAdapter(openingTime, activity.get());
    adapter.setTime(tagItem.getValue());
    if (tagItem.getTagType() == TagItem.Type.TIME) {
        adapter.hideMonth(true);
    }
    holder.getOpeningTimeRecyclerView().setAdapter(adapter);
    holder.getOpeningTimeRecyclerView().setLayoutManager(new LinearLayoutManager(activity.get()));
    holder.getOpeningTimeRecyclerView().setHasFixedSize(false);
    RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator();
    itemAnimator.setAddDuration(300);
    holder.getOpeningTimeRecyclerView().setItemAnimator(itemAnimator);
    holder.getOpeningTimeRecyclerView().addItemDecoration(new DividerItemDecoration(activity.get()));
    final OpeningTime finalOpeningTime = openingTime;
    holder.getAddButton().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            finalOpeningTime.addOpeningMonth(new OpeningMonth());
            adapter.notifyItemInserted(adapter.getItemCount() - 1);
        }
    });
    showInvalidityMessage(tagItem);
}
Also used : OpeningMonthAdapter(io.jawg.osmcontributor.ui.adapters.OpeningMonthAdapter) OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningTime(io.jawg.osmcontributor.model.utils.OpeningTime) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(io.jawg.osmcontributor.ui.utils.views.DividerItemDecoration) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 5 with OpeningTime

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

the class OpeningTimeValueParser method fromValue.

@Override
public OpeningTime fromValue(String data) {
    if (data == null || data.trim().isEmpty()) {
        return null;
    }
    OpeningTime openingTime = new OpeningTime();
    String[] openingTimes = data.split(RULESET_SEP);
    for (String s : openingTimes) {
        OpeningMonth openingMonth = openingMonthValueParser.fromValue(s);
        if (openingMonth != null) {
            openingTime.addOpeningMonth(openingMonth);
        }
    }
    return openingTime;
}
Also used : OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningTime(io.jawg.osmcontributor.model.utils.OpeningTime)

Aggregations

OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)12 OpeningTime (io.jawg.osmcontributor.model.utils.OpeningTime)12 Test (org.junit.Test)10 OpeningHours (io.jawg.osmcontributor.model.utils.OpeningHours)9 LocalTime (org.joda.time.LocalTime)4 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 OpeningMonthAdapter (io.jawg.osmcontributor.ui.adapters.OpeningMonthAdapter)1 DividerItemDecoration (io.jawg.osmcontributor.ui.utils.views.DividerItemDecoration)1