package com.sobot.widget.ui.calenderview;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.widget.TextView;

import com.sobot.widget.R;


/**
 * 自定义英文栏
 */

public class CustomWeekBar extends WeekBar {

    private int mPreSelectedIndex;

    public CustomWeekBar(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.sobot_custom_week_bar, this, true);
        setBackgroundColor(Color.WHITE);
    }

    @Override
    protected void onDateSelected(Calendar calendar, int weekStart, boolean isClick) {
        getChildAt(mPreSelectedIndex).setSelected(false);
        int viewIndex = getViewIndexByCalendar(calendar, weekStart);
        getChildAt(viewIndex).setSelected(true);
        mPreSelectedIndex = viewIndex;
    }

    /**
     * 当周起始发生变化，使用自定义布局需要重写这个方法，避免出问题
     *
     * @param weekStart 周起始
     */
    @Override
    protected void onWeekStartChange(int weekStart) {
        for (int i = 0; i < getChildCount(); i++) {
            int receId =0;
            if (weekStart == 1) {
                //周日开始
                if(i==0){
                    receId= R.string.calendar_day;
                }else if(i==1) {
                    receId = R.string.calendar_one;
                }else if(i==2) {
                    receId = R.string.calendar_two;
                }else if(i==3) {
                    receId = R.string.calendar_three;
                }else if(i==4) {
                    receId = R.string.calendar_four;
                }else if(i==5) {
                    receId = R.string.calendar_five;
                }else if(i==6) {
                    receId = R.string.calendar_six;
                }
            }else if (weekStart == 2) {
                //周一开始
                if(i==0) {
                    receId = R.string.calendar_one;
                }else if(i==1) {
                    receId = R.string.calendar_two;
                }else if(i==2) {
                    receId = R.string.calendar_three;
                }else if(i==3) {
                    receId = R.string.calendar_four;
                }else if(i==4) {
                    receId = R.string.calendar_five;
                }else if(i==5) {
                    receId = R.string.calendar_six;
                }else if(i==6) {
                    receId = R.string.calendar_day;
                }
            }
            if(receId != 0) {
                ((TextView) getChildAt(i)).setText(receId);
            }
        }
    }

}
