package com.yyrh.ui.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.yyrh.utils.ResourceUtil;

import cn.yyxx.support.ResUtils;

/**
 * @author #Suyghur.
 * Created on 2021/10/19
 */
public class TipsToast {

    private Toast mToast;

    public TipsToast(Context context, String message, boolean error) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View view = inflater.inflate(ResourceUtil.getLayoutId(context, "hnyy_tips_toast"), null);

        TextView mTextView = view.findViewById(ResUtils.getResId(context, "hnyy_tv_desc", "id"));
        mTextView.setText(message);

        ImageView mImageView = view.findViewById(ResUtils.getResId(context, "hnyy_iv_desc", "id"));
        if (error) {
            mImageView.setImageResource(ResUtils.getResId(context, "hnyy_error_img", "drawable"));
        } else {
            mImageView.setImageResource(ResUtils.getResId(context, "hnyy_success_img", "drawable"));
        }

        if (mToast == null) {
            mToast = new Toast(context);
        }

        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setView(view);
        mToast.setGravity(Gravity.CENTER, 0, 0);
    }

    public void show() {
        if (mToast != null) {
            mToast.show();
        }
    }

    public static void showSuccessMsg(Context context, String message) {
        new TipsToast(context, message, false).show();
    }

    public static void showErrorMsg(Context context, String message) {
        new TipsToast(context, message, true).show();
    }
}
