package com.kdanmobile.kdan_others_library_for_android.card;

import android.content.Context;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import android.util.AttributeSet;

import com.kdanmobile.kdan_others_library_for_android.R;

/**
 * Created by Wei on 2017/11/20.
 */

public class QubiiXCreativeStoreCard extends BaseCard {

    private OnClickListener onClickViewNowListener;
    private OnClickListener onClickImageListener;

    public QubiiXCreativeStoreCard(@NonNull Context context) {
        super(context);
        initView();
    }

    public QubiiXCreativeStoreCard(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public QubiiXCreativeStoreCard(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    public void setButtonColor(int color) {
        getAction1Button().setTextColor(color);
    }

    public void setOnClickViewNowListener(OnClickListener onClickViewNowListener) {
        this.onClickViewNowListener = onClickViewNowListener;
    }

    public void setOnClickImageListener(OnClickListener onClickImageListener) {
        this.onClickImageListener = onClickImageListener;
    }

    private void initView() {
        getMediaImageView().setImageResource(R.mipmap.creative_store_card_qubii);
        getMediaImageView().setOnClickListener(v -> {
            if (onClickImageListener != null) onClickImageListener.onClick(v);
        });
        getPrimaryTextTextView().setVisibility(VISIBLE);
        getPrimaryTextTextView().setText(R.string.qubii_card_title);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            getPrimaryTextTextView().setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_gradient_white));
        }else{
            getPrimaryTextTextView().setBackgroundDrawable(ContextCompat.getDrawable(getContext(),R.drawable.shape_gradient_white));
        }

        getSupportingTextTextView().setVisibility(VISIBLE);
        getSupportingTextTextView().setText(R.string.qubii_card_description);
        int c = getContext().getResources().getColor(R.color.card_view_supporting_text_color);
        getSupportingTextTextView().setTextColor(c);
        getAction1Button().setVisibility(VISIBLE);
        getAction1Button().setText(R.string.creative_store_card_view);
        getAction1Button().setOnClickListener(v -> {
            if (onClickViewNowListener != null) onClickViewNowListener.onClick(v);
        });
    }
}
