package com.yidianling.course.courseNew;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.widget.TextView;

import com.yidianling.course.R;
import com.yidianling.ydlcommon.app.YdlCommonApp;

/**
 * Created by Jim on 2018/7/17 0017.
 */
public class PriceUtil {

    public static void formatPrice(String price, TextView textView) {
        if (TextUtils.isEmpty(price) || "0.00".equals(price) || "null".equals(price)) {
            textView.setTextSize(12);
            textView.setTextColor(YdlCommonApp.INSTANCE.getApp().getResources().getColor(R.color.google_green));
            String money = "0.00";
            SpannableString sStr = new SpannableString("¥" + money);
            int index = money.indexOf(".") + 1;
            if (index != -1) {
                sStr.setSpan(new AbsoluteSizeSpan(18, true), 1, index, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            textView.setText(sStr);
        } else {
            textView.setTextSize(12);
            textView.setTextColor(YdlCommonApp.INSTANCE.getApp().getResources().getColor(R.color.cube_holo_orange_dark));
            SpannableString sStr = new SpannableString("¥" + price);
            int index = price.indexOf(".") + 1;
            if (index != -1 && index > 1) {
                sStr.setSpan(new AbsoluteSizeSpan(18, true), 1, index, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            textView.setText(sStr);
        }
    }
}
