Search in sources :

Example 1 with OpeningMonthAdapter

use of io.jawg.osmcontributor.ui.adapters.OpeningMonthAdapter 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)

Aggregations

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 OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)1 OpeningTime (io.jawg.osmcontributor.model.utils.OpeningTime)1 OpeningMonthAdapter (io.jawg.osmcontributor.ui.adapters.OpeningMonthAdapter)1 DividerItemDecoration (io.jawg.osmcontributor.ui.utils.views.DividerItemDecoration)1