package com.kfzs.duanduan.utils;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sheep.jiuyan.samllsheep.R;

/**
 * @ Created by Dlg
 * @ <p>TiTle:  DiscountUtils</p>
 * @ <p>Description:</p>
 * @ date:  2018/1/5 14:58
 * @ QQ:    315096953
 */

public class DiscountUtils {

    private static DiscountUtils mDiscountUtils;

    public synchronized static DiscountUtils getInstance() {
        if (mDiscountUtils == null) {
            mDiscountUtils = new DiscountUtils();
        }
        return mDiscountUtils;
    }


    /**
     * @param view     logo的layout组件View
     * @param logo     Logo的URL
     * @param discount 打折的文本
     */
    public void showDiscount(View view, String logo, String discount) {
        Glide.with(view.getContext()).load(logo)
                .into((ImageView) view.findViewById(R.id.img_logo));
        if (TextUtils.isEmpty(discount)
                || discount.startsWith("10")) {
            view.findViewById(R.id.img_discount)
                    .setVisibility(View.GONE);
            ((TextView) view.findViewById(R.id.txt_logo_discount)
            ).setText("");
        } else {
            ((TextView) view.findViewById(R.id.txt_logo_discount)
            ).setText((discount.length() == 4?discount.substring(0, 3):discount) + "折");
            view.findViewById(R.id.img_discount)
                    .setVisibility(View.VISIBLE);
        }
        view.findViewById(R.id.img_discount)
                .setVisibility(View.GONE);
        ((TextView) view.findViewById(R.id.txt_logo_discount)
        ).setText("");
        showDiscountNew(view, logo, discount);
    }
    /**
     * 需求变化了，暂时屏蔽 showDiscount（）方法里面的代码
     * @param view     logo的layout组件View
     * @param logo     Logo的URL
     * @param discount 打折的文本
     */
    public void showDiscountNew(View view, String logo, String discount) {
        if (TextUtils.isEmpty(discount)
                || discount.startsWith("10")) {
            view.findViewById(R.id.discount_tv)
                    .setVisibility(View.GONE);
        } else {
            ((TextView) view.findViewById(R.id.discount_tv)
            ).setText((discount.length() == 4?discount.substring(0, 3):discount) + "折");
        }
    }


}
