Search in sources :

Example 6 with OpeningMonth

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);
}
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 7 with OpeningMonth

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);
}
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 8 with OpeningMonth

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();
}
Also used : OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth)

Example 9 with OpeningMonth

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);
}
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 10 with OpeningMonth

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;
}
Also used : OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningTime(io.jawg.osmcontributor.model.utils.OpeningTime)

Aggregations

OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)21 Test (org.junit.Test)16 OpeningHours (io.jawg.osmcontributor.model.utils.OpeningHours)12 OpeningTime (io.jawg.osmcontributor.model.utils.OpeningTime)12 LocalTime (org.joda.time.LocalTime)6 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 BindView (butterknife.BindView)1 OpeningMonthAdapter (io.jawg.osmcontributor.ui.adapters.OpeningMonthAdapter)1 EditMonthsDialogFragment (io.jawg.osmcontributor.ui.dialogs.EditMonthsDialogFragment)1 PleaseApplyOpeningTimeChange (io.jawg.osmcontributor.ui.events.edition.PleaseApplyOpeningTimeChange)1 DividerItemDecoration (io.jawg.osmcontributor.ui.utils.views.DividerItemDecoration)1