package jp.cordea.switter;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.twitter.sdk.android.core.models.MediaEntity;

import java.util.List;

import butterknife.Bind;

/**
 * Created by Yoshihiro Tanaka on 16/04/21.
 */
public class TimelineImageView extends LinearLayout {

    @Bind(R.id.container_start)
    View startContainer;

    @Bind(R.id.container_end)
    View endContainer;

    @Bind(R.id.image_view_start_top)
    ImageView startTopImageView;

    @Bind(R.id.image_view_start_bottom)
    ImageView startBottomImageView;

    @Bind(R.id.image_view_end_top)
    ImageView endTopImageView;

    @Bind(R.id.image_view_end_bottom)
    ImageView endBottomImageView;


    public TimelineImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate(context, R.layout.view_timeline_image, this);
    }

    public void setImages(List<MediaEntity> mediaEntities) {
        // TODO
        switch (mediaEntities.size()) {
            case 1:
                oneImageLayout();
                break;
            case 2:
                twoImageLayout();
                break;
            case 3:
                threeImageLayout();
                break;
            case 4:
                break;
        }
    }

    private void oneImageLayout() {
        LayoutParams layoutParams = (LayoutParams) endContainer.getLayoutParams();
        layoutParams.weight = 0;
        endContainer.setLayoutParams(layoutParams);
        layoutParams = (LayoutParams) startBottomImageView.getLayoutParams();
        layoutParams.weight = 0;
        startBottomImageView.setLayoutParams(layoutParams);
    }

    private void threeImageLayout() {
        LayoutParams layoutParams = (LayoutParams) startBottomImageView.getLayoutParams();
        layoutParams.weight = 0;
        startBottomImageView.setLayoutParams(layoutParams);
    }

    private void twoImageLayout() {
        LayoutParams layoutParams = (LayoutParams) startBottomImageView.getLayoutParams();
        layoutParams.weight = 0;
        startBottomImageView.setLayoutParams(layoutParams);
        layoutParams = (LayoutParams) endBottomImageView.getLayoutParams();
        layoutParams.weight = 0;
        endBottomImageView.setLayoutParams(layoutParams);
    }
}

@@ -117,39 +117,8 @@
 ew;%0A
-import android.view.ViewGroup;%0A
 impo
@@ -288,16 +288,48 @@
 fe.Bind;
+%0Aimport butterknife.ButterKnife;
 %0A%0A/**%0A *
@@ -987,24 +987,56 @@
 age, this);%0A
+        ButterKnife.bind(this);%0A
     %7D%0A%0A    p
@@ -1107,16 +1107,48 @@
 // TODO%0A
+        setVisibility(VISIBLE);%0A
         
@@ -1222,32 +1222,45 @@
  oneImageLayout(
+mediaEntities
 );%0A             
@@ -1312,32 +1312,45 @@
  twoImageLayout(
+mediaEntities
 );%0A             
@@ -1412,16 +1412,29 @@
 eLayout(
+mediaEntities
 );%0A     
@@ -1471,16 +1471,64 @@
 case 4:%0A
+                fourImageLayout(mediaEntities);%0A
         
@@ -1583,32 +1583,63 @@
  oneImageLayout(
+List%3CMediaEntity%3E mediaEntities
 ) %7B%0A        Layo
@@ -1990,20 +1990,18 @@
 e void t
-hree
+wo
 ImageLay
@@ -1996,32 +1996,63 @@
  twoImageLayout(
+List%3CMediaEntity%3E mediaEntities
 ) %7B%0A        Layo
@@ -2240,34 +2240,36 @@
   private void t
-wo
+hree
 ImageLayout() %7B%0A
@@ -2264,16 +2264,47 @@
 eLayout(
+List%3CMediaEntity%3E mediaEntities
 ) %7B%0A    

fix visibility, add fourImageLayout