package com.duben.microtribe.ui.widgets;

import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.duben.microtribe.R;

/**
 * 描述：加载中dialog
 * 作者：孟崔广
 * 时间：2017/10/10 17:51
 * 邮箱：mengcuiguang@cashbang.cn
 */
public class LoadingDialog extends BaseDialog {

    private Context mContext;
    private LayoutInflater inflater;
    private LayoutParams lp;
    private TextView loadtext;
    private LinearLayout loading_ll;

    public LoadingDialog(Context context) {
        super(context, R.style.dialog);
        this.mContext = context;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.loadingdialog, null);
        if (android.os.Build.VERSION.SDK_INT > 22) {//android 6.0替换clip的加载动画
            final Drawable drawable = ContextCompat.getDrawable(mContext, R.drawable.ufo_loading_refresh);
            ProgressBar loading_bar = (ProgressBar) layout.findViewById(R.id.loading_bar);
            loading_bar.setIndeterminateDrawable(drawable);
        }
        loadtext = (TextView) layout.findViewById(R.id.loading_text);
        loading_ll = (LinearLayout) layout.findViewById(R.id.loading_ll);
        setContentView(layout);
        // 设置window属性
        lp = getWindow().getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.dimAmount = 0; // 去背景遮盖
        // lp.alpha = 1.0f;//透明效果
        getWindow().setAttributes(lp);
    }

    /**
     * 设置显示文字
     *
     * @param content 文字内容
     */
    public void setLoadText(String content) {
        if (TextUtils.isEmpty(content)) {
            loading_ll.setVisibility(View.GONE);
        } else {
            loading_ll.setVisibility(View.VISIBLE);
            loadtext.setText(content);
        }
    }

}