package com.jpardogo.android.listbuddies.ui.fragments;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Toast;

import com.jpardogo.android.listbuddies.R;
import com.jpardogo.android.listbuddies.adapters.CircularAdapter;
import com.jpardogo.android.listbuddies.provider.ImagesUrls;
import com.jpardogo.android.listbuddies.ui.ExampleActivity;
import com.jpardogo.listbuddies.lib.views.ListBuddiesLayout;


public class ListBuddiesFragment extends Fragment implements ListBuddiesLayout.OnBuddyItemClickListener {
    private static final String TAG = ListBuddiesFragment.class.getSimpleName();

    private MenuItem mOpenActivities;
    CircularAdapter mAdapterLeft;
    CircularAdapter mAdapterRight;
    public ListBuddiesFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        ListBuddiesLayout listBuddies = (ListBuddiesLayout) rootView.findViewById(R.id.listbuddies);
        mAdapterLeft = new CircularAdapter(getActivity(), getResources().getDimensionPixelSize(R.dimen.item_height_small), ImagesUrls.imageUrls_left);
        mAdapterRight = new CircularAdapter(getActivity(), getResources().getDimensionPixelSize(R.dimen.item_height_tall), ImagesUrls.imageUrls_right);
        listBuddies.setAdapters(mAdapterLeft, mAdapterRight);
        listBuddies.setOnItemClickListener(this);
        return rootView;
    }

    @Override
    public void onBuddyItemClicked(AdapterView<?> parent, View view, int buddy, int position, long id) {
        if (mOpenActivities.isChecked()) {
            Intent intent = new Intent(getActivity(), ExampleActivity.class);
            intent.putExtra(ExampleActivity.EXTRA_URL,getImage(buddy,position));
            startActivity(intent);
        } else {
            Resources resources = getResources();
            Toast.makeText(getActivity(), resources.getString(R.string.list) + ": " + buddy + " " + resources.getString(R.string.position) + ": " + position, Toast.LENGTH_SHORT).show();
        }
    }

    private String getImage(int buddy, int position) {
        return buddy==0?ImagesUrls.imageUrls_left[position]:ImagesUrls.imageUrls_right[position];
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.main, menu);
        super.onCreateOptionsMenu(menu, inflater);
        mOpenActivities = menu.findItem(R.id.item1);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.item1:
                if (item.isChecked()) {
                    item.setChecked(false);
                } else {
                    item.setChecked(true);
                }

                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
@@ -645,23 +645,22 @@
 dies.ui.
-Example
+Detail
 Activity
@@ -723,16 +723,80 @@
 ayout;%0A%0A
+import butterknife.ButterKnife;%0Aimport butterknife.InjectView;%0A%0A
 %0Apublic 
@@ -1014,24 +1014,32 @@
 vities;%0A    
+private 
 CircularAdap
@@ -1060,16 +1060,24 @@
 ft;%0A    
+private 
 Circular
@@ -1103,22 +1103,144 @@
 ht;%0A    
-public
+@InjectView(R.id.listbuddies)%0A    ListBuddiesLayout mListBuddies;%0A%0A    public static Fragment newInstance() %7B%0A        return new
  ListBud
@@ -1253,18 +1253,17 @@
 agment()
- %7B
+;
 %0A    %7D%0A%0A
@@ -1657,98 +1657,41 @@
     
-ListBuddiesLayout listBuddies = (ListBuddiesLayout) rootView.findViewById(R.id.listbuddies
+ButterKnife.inject(this, rootView
 );%0A 
@@ -1992,33 +1992,34 @@
 right);%0A        
-l
+mL
 istBuddies.setAd
@@ -2063,17 +2063,18 @@
         
-l
+mL
 istBuddi
@@ -2354,23 +2354,22 @@
 vity(), 
-Example
+Detail
 Activity
@@ -2409,15 +2409,14 @@
 tra(
-Example
+Detail
 Acti
@@ -2430,16 +2430,17 @@
 TRA_URL,
+ 
 getImage
@@ -2446,16 +2446,17 @@
 e(buddy,
+ 
 position
@@ -2843,12 +2843,16 @@
 uddy
+ 
 ==
-0?
+ 0 ? 
 Imag
@@ -2882,17 +2882,19 @@
 osition%5D
-:
+ : 
 ImagesUr
@@ -3048,20 +3048,36 @@
 (R.menu.
-main
+fragment_listbuddies
 , menu);
@@ -3173,21 +3173,40 @@
 em(R.id.
-item1
+checkbox_open_activities
 );%0A    %7D
@@ -3342,13 +3342,32 @@
 .id.
-item1
+checkbox_open_activities
 :%0A  
@@ -3658,10 +3658,91 @@
  %7D%0A    %7D
+%0A%0A    public void setGap(int value) %7B%0A//        mListBuddies.setGap(value);%0A    %7D
 %0A%7D

Add methos to change the gap of the layout when we receive the data from the customization framgnet