package com.revoapp.calendar.components;


import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.TextView;

import com.revoapp.calendarapp.R;
import com.revoapp.calendar.helper.ThemeHelper;

public class RevoTextView extends TextView {
    private int colorIndex = 0;
    private boolean secondaryFont = false;
    private boolean calendarStyle = false;


    public RevoTextView(Context context) {
        super(context);
        setAttributes(context);
    }

    public RevoTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        obrainAttributes(context, attrs);
        setAttributes(context);
    }

    public RevoTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        obrainAttributes(context, attrs);
        setAttributes(context);
    }

    private void obrainAttributes(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.RevoTextView);

        final int N = a.getIndexCount();
        for (int i = 0; i < N; ++i) {
            int attr = a.getIndex(i);
            switch (attr) {
                case R.styleable.RevoTextView_colorIndex:
                    colorIndex = a.getInt(attr, 0);
                    break;
                case R.styleable.RevoTextView_secondaryFont:
                    secondaryFont = a.getBoolean(attr, false);
                    break;
                case R.styleable.RevoTextView_calendarStyle:
                    calendarStyle = a.getBoolean(attr, false);
                    break;
            }
        }
        a.recycle();
    }

    private void setAttributes(Context context) {
        if (!isInEditMode()) {
            if (!secondaryFont)
                setTypeface(ThemeHelper.get_primary_font());
            else
                setTypeface(ThemeHelper.get_secondary_font());
 //           setTextSize(35);
            setTextSize((int) getResources().getDimension(R.dimen.revo_text_view_monthly_cell));

            if (colorIndex == 0)
                setTextColor(context.getResources().getColor(
                        ThemeHelper.get_primary_color()));
            else if (colorIndex == 1)
                setTextColor(context.getResources().getColor(
                        ThemeHelper.get_secondary_color()));
            else if (colorIndex == 2)
                setTextColor(context.getResources().getColor(
                        ThemeHelper.get_highlight_color()));

			/*if(getId() != R.id.dialogTitle && getId() != R.id.medicine_name && getId() != R.id.alarm_clock_info && getId() != R.id.plii_name &&
			   getId() != R.id.alarm_clock_time && getId() != R.id.dots && getId() != R.id.event_title && getId() != R.id.event_time &&
			   getId() != R.id.event_message && getId() != R.id.contactName && getId() != R.id.text && getId() != R.id.alarm_title)
				setBackgroundResource(R.color.light_yellow);*/
            if (getId() == R.id.dialogTitle)
                setTextColor(context.getResources().getColor(ThemeHelper.get_background_color()));
            if (getId() == R.id.month_info)
                setTextSize((int) getResources().getDimension(R.dimen.calendar_header_text));
            if (getId() == R.id.month_day_name)
                setTextSize((int) getResources().getDimension(R.dimen.revo_text_view_day_name));
            if (getId() == R.id.day_hour) {
                setTextSize((int) getResources().getDimension(R.dimen.revo_text_view_day_hour_col));
            }
			
			/*if(getId() == R.id.plii_name){
				setTextSize(25);
			}*/
            if (getId() == R.id.dots) {
                setTextSize((int) getResources().getDimension(R.dimen.hours_minutes));
            }
            if (getId() == R.id.event_time) {
  //              setTextSize(30);
            }
            if (getId() == R.id.text) {
                setTextSize((int) getResources().getDimension(R.dimen.dialog_toast_event));
            }


        }

    }
}