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");
}
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");
}
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);
}
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);
}
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;
}
Aggregations