package com.jonasgerdes.schauburgr.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jonasgerdes.schauburgr.R;
import com.jonasgerdes.schauburgr.model.schauburg.ExtraMapper;
import com.jonasgerdes.schauburgr.util.ViewUtils;

import java.util.List;

/**
 * View which displays attributes (of a movie) in an horizontal list.
 * Generally behaves like a {@link LinearLayout}, which it extends from.
 *
 * @author Jonas Gerdes <dev@jonasgerdes.com>
 * @since 31.03.2017
 */


public class MovieAttributeView extends LinearLayout {
    public MovieAttributeView(Context context) {
        super(context);
        init();
    }

    public MovieAttributeView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MovieAttributeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public MovieAttributeView(Context context, AttributeSet attrs, int defStyleAttr, int
            defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    /**
     * Setups view by setting orientation.
     */
    private void init() {
        setOrientation(HORIZONTAL);
    }

    /**
     * Set attributes to show. Creates a {@link TextView} for each attribute, applies style
     * and add it as child.
     *
     * @param attributes attributes titles to show
     */
    public void setAttributes(List<String> attributes) {
        //remove existing extras
        removeAllViews();
        //add new ones
        for (String attributeName : attributes) {
            @StringRes int attribute = ExtraMapper.getExtraString(attributeName);
            if (attribute == ExtraMapper.NONE) {
                return;
            }
            TextView attributeView = new TextView(getContext(), null, 0, R.style.movie_attribute);
            LinearLayoutCompat.LayoutParams layout = new LinearLayoutCompat.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT
            );
            int horizontalMarginDp = ViewUtils.dpToPx(getContext(), 4);
            layout.setMargins(horizontalMarginDp, 0, horizontalMarginDp, 0);
            attributeView.setLayoutParams(layout);
            attributeView.setText(attribute);
            addView(attributeView);
        }
    }
}

@@ -175,43 +175,24 @@
 oid.
-support.v7.widget.LinearLayoutCompa
+util.AttributeSe
 t;%0Ai
@@ -206,36 +206,27 @@
 ndroid.util.
-AttributeSet
+Log
 ;%0Aimport and
@@ -2154,38 +2154,32 @@
     LinearLayout
-Compat
 .LayoutParams la
@@ -2205,14 +2205,8 @@
 yout
-Compat
 .Lay
@@ -2582,32 +2582,108 @@
 ext(attribute);%0A
+            Log.d(%22MovieAttrView%22, %22setAttributes: %22 + horizontalMarginDp);%0A
             addV

Fix missing margin on MovieAttributeView items on Lollipop