/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.examples.todolist.newtask;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import io.spine.examples.todolist.LabelDetails;
import io.spine.examples.todolist.LabelId;
import io.spine.examples.todolist.R;
import io.spine.examples.todolist.model.Colors;
import io.spine.examples.todolist.q.projection.LabelledTasksView;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static com.google.common.collect.Sets.newHashSet;
import static io.spine.examples.todolist.model.Colors.toRgb;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableCollection;

final class ReadonlyLabelsAdapter extends RecyclerView.Adapter<ReadonlyLabelsAdapter.ViewBinder> {

    private final List<LabelDetails> data;

    ReadonlyLabelsAdapter(List<LabelDetails> data) {
        this.data = data;
    }

    @Override
    public ViewBinder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View root = LayoutInflater.from(parent.getContext())
                                        .inflate(R.layout.item_label, parent, false);
        return new ViewBinder(root);
    }

    @Override
    public void onBindViewHolder(ViewBinder holder, int position) {
        final LabelDetails element = data.get(position);
        holder.bind(element);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    static class ViewBinder extends RecyclerView.ViewHolder {

        private final TextView titleLabel;
        private final View colorView;

        private ViewBinder(View itemView) {
            super(itemView);
            this.titleLabel = itemView.findViewById(R.id.label_title);
            this.colorView = itemView.findViewById(R.id.label_color_stripe);
        }

        private void bind(LabelDetails label) {
            final String text = label.getTitle();
            final int colorRgb = toRgb(label.getColor());
            titleLabel.setText(text);
            colorView.setBackgroundColor(colorRgb);

        }
    }
}

@@ -1106,33 +1106,8 @@
 ew;%0A
-import android.util.Log;%0A
 impo
@@ -1168,50 +1168,8 @@
 ew;%0A
-import android.view.View.OnClickListener;%0A
 impo
@@ -1313,551 +1313,95 @@
 ist.
-LabelId;%0Aimport io.spine.examples.todolist.R;%0Aimport io.spine.examples.todolist.model.Colors;%0Aimport io.spine.examples.todolist.q.projection.LabelledTasksView;%0A%0Aimport java.util.Collection;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.Future;%0A%0Aimport static com.google.common.collect.Sets.newHashSet;%0Aimport static io.spine.examples.todolist.model.Colors.toRgb;%0Aimport static java.util.Collections.emptyList;%0Aimport static java.util.Collections.unmodifiableCollection
+R;%0A%0Aimport java.util.List;%0A%0Aimport static io.spine.examples.todolist.model.Colors.toRgb
 ;%0A%0Af
@@ -2795,17 +2795,16 @@
 orRgb);%0A
-%0A
         

Remove redundant imports.