use of io.jawg.osmcontributor.model.utils.OpeningMonth 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.OpeningMonth 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);
}
use of io.jawg.osmcontributor.model.utils.OpeningMonth in project osm-contributor by jawg.
the class OpeningTimeValueParser method toValue.
@Override
public String toValue(OpeningTime openingTime) {
StringBuilder builder = new StringBuilder();
for (OpeningMonth openingMonth : openingTime.getOpeningMonths()) {
builder.append(builder.length() == 0 || builder.substring(builder.length() - 2).equals(RULESET_SEP) ? "" : RULESET_SEP);
builder.append(openingMonthValueParser.toValue(openingMonth));
}
return builder.toString();
}
use of io.jawg.osmcontributor.model.utils.OpeningMonth 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.OpeningMonth 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