/***********************************************************************************
 * The MIT License (MIT)

 * Copyright (c) 2014 Robin Chutaux

 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ***********************************************************************************/
package com.andexert.calendarlistview.library;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

public class DayPickerView extends RecyclerView
{
    protected Context mContext;
	protected SimpleMonthAdapter mAdapter;
	private DatePickerController mController;
    protected int mCurrentScrollState = 0;
	protected long mPreviousScrollPosition;
	protected int mPreviousScrollState = 0;
    private TypedArray typedArray;
    private OnScrollListener onScrollListener;

    public DayPickerView(Context context)
    {
        this(context, null);
    }

    public DayPickerView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public DayPickerView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        if (!isInEditMode())
        {
            typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView);
            setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            init(context);
        }
    }

    public void setController(DatePickerController mController)
    {
        this.mController = mController;
        setUpAdapter();
        setAdapter(mAdapter);
    }


	public void init(Context paramContext) {
        setLayoutManager(new LinearLayoutManager(paramContext));
		mContext = paramContext;
		setUpListView();

        onScrollListener = new OnScrollListener()
        {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy)
            {
                super.onScrolled(recyclerView, dx, dy);
                final SimpleMonthView child = (SimpleMonthView) recyclerView.getChildAt(0);
                if (child == null) {
                    return;
                }

                mPreviousScrollPosition = dy;
                mPreviousScrollState = mCurrentScrollState;
            }
        };
	}


	protected void setUpAdapter() {
		if (mAdapter == null) {
			mAdapter = new SimpleMonthAdapter(getContext(), mController, typedArray);
        }
		mAdapter.notifyDataSetChanged();
	}

	protected void setUpListView() {
		setVerticalScrollBarEnabled(false);
		setOnScrollListener(onScrollListener);
		setFadingEdgeLength(0);
	}

    public SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> getSelectedDays()
    {
        return mAdapter.getSelectedDays();
    }

    protected DatePickerController getController()
    {
        return mController;
    }

    protected TypedArray getTypedArray()
    {
        return typedArray;
    }
}
@@ -1597,17 +1597,17 @@
 clerView
-%0A
+ 
 %7B%0A    pr
@@ -1632,17 +1632,20 @@
 ontext;%0A
-%09
+    
 protecte
@@ -1675,17 +1675,20 @@
 dapter;%0A
-%09
+    
 private 
@@ -1764,17 +1764,20 @@
 te = 0;%0A
-%09
+    
 protecte
@@ -1808,17 +1808,20 @@
 sition;%0A
-%09
+    
 protecte
@@ -1976,20 +1976,16 @@
 context)
-%0A   
  %7B%0A     
@@ -2076,20 +2076,16 @@
 t attrs)
-%0A   
  %7B%0A     
@@ -2194,20 +2194,16 @@
 efStyle)
-%0A   
  %7B%0A     
@@ -2266,24 +2266,16 @@
 tMode())
-%0A       
  %7B%0A     
@@ -2568,20 +2568,16 @@
 troller)
-%0A   
  %7B%0A     
@@ -2673,17 +2673,20 @@
     %7D%0A%0A%0A
-%09
+    
 public v
@@ -2783,18 +2783,24 @@
 text));%0A
-%09%09
+        
 mContext
@@ -2816,18 +2816,24 @@
 ontext;%0A
-%09%09
+        
 setUpLis
@@ -2891,24 +2891,16 @@
 stener()
-%0A       
  %7B%0A     
@@ -2993,28 +2993,16 @@
  int dy)
-%0A           
  %7B%0A     
@@ -3363,14 +3363,20 @@
  %7D;%0A
-%09%7D%0A%0A%0A%09
+    %7D%0A%0A%0A    
 prot
@@ -3403,18 +3403,24 @@
 ter() %7B%0A
-%09%09
+        
 if (mAda
@@ -3439,11 +3439,20 @@
 ) %7B%0A
-%09%09%09
+            
 mAda
@@ -3531,18 +3531,24 @@
       %7D%0A
-%09%09
+        
 mAdapter
@@ -3576,13 +3576,195 @@
 ();%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    public void setSelectedDay(SimpleMonthAdapter.CalendarDay calendarDay) %7B%0A        if (mAdapter != null) %7B%0A            mAdapter.setSelectedDay(calendarDay);%0A        %7D%0A    %7D%0A%0A    
 prot
@@ -3792,18 +3792,24 @@
 iew() %7B%0A
-%09%09
+        
 setVerti
@@ -3836,18 +3836,24 @@
 false);%0A
-%09%09
+        
 setOnScr
@@ -3887,10 +3887,16 @@
 r);%0A
-%09%09
+        
 setF
@@ -3919,9 +3919,12 @@
 0);%0A
-%09
+    
 %7D%0A%0A 
@@ -4014,20 +4014,16 @@
 edDays()
-%0A   
  %7B%0A     
@@ -4117,20 +4117,16 @@
 roller()
-%0A   
  %7B%0A     
@@ -4195,20 +4195,16 @@
 dArray()
-%0A   
  %7B%0A     

add setSelectedDay() method in DayPickerView