package com.mytatvarnsdk.myView.progress;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.mytatvarnsdk.R;

import cgmblelib.utils.Tool;

/**
 * 等待进度弹框
 * @author minyuchun
 */
public class WaitProgress extends BaseCustomProgress{
    /**搜索是才用得到*/
    private RelativeLayout mLayout;
    /**等待的动画图片*/
    private ImageView mImageView;

    private ImageView mImageViewCenter;
    /**等待的显示文字*/
    private TextView mTextView;

    protected WaitProgress(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public WaitProgress(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    public WaitProgress(@NonNull Context context) {
        super(context,  R.style.WarnDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_progress_wait);
        initView();
    }

    private void initView(){
        mLayout = findViewById(R.id.progress_wait_scan);
        mImageView = findViewById(R.id.progress_wait_other);
        mImageViewCenter = findViewById(R.id.progress_wait_center);
        mTextView = findViewById(R.id.progress_wait_message);
    }

    private void refreshView(){
        if (TextUtils.isEmpty(message)){
            mTextView.setVisibility(View.GONE);
        } else {
            mTextView.setVisibility(View.VISIBLE);
            mTextView.setText(message);
        }
        if (mCancelListener != null){
            setCancelable(true);
            setOnCancelListener(mCancelListener);
        } else {
            setCancelable(false);
        }
        float fromDegrees = 0f;
        float toDegrees = 360f;
        switch (type){
            case ProgressType.PROGRESSDIALOG_SCAN:
                mLayout.setVisibility(View.VISIBLE);
                mImageView = findViewById(R.id.progress_wait_image);
                break;
            default:
                mImageView = findViewById(R.id.progress_wait_other);
                mImageView.setVisibility(View.VISIBLE);
                break;
        }
        mImageView.setAnimation(Tool.getRotate());
    }

    @Override
    public void show() {
        super.show();
        refreshView();
    }
}
