package com.tenlionsoft.baselib.core.widget.views;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.view.TimePickerView;
import com.tenlionsoft.baselib.R;

import java.text.SimpleDateFormat;

/**
 * 作者: Adam
 * 日期: 2019/4/22 - 15:37
 * 邮箱: itgaojian@163.com
 * 描述:
 */
public class ConditionDialog extends Dialog {
    private Context mContext;
    private Activity mActivity;
    private View mContentView;
    private TextView mTvStartTime;
    private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd");

    public ConditionDialog(Context context, Activity activity) {
        super(context);
        this.mContext = context;
        this.mActivity = activity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.dialog_condititon_view, null);
        setContentView(mContentView);
        Button mBtnConfirm = mContentView.findViewById(R.id.btn_confirm);
        mTvStartTime = mContentView.findViewById(R.id.tv_start_time);
        mBtnConfirm.setOnClickListener(v -> showPickerView());
        Window window = this.getWindow();
        window.setGravity(Gravity.RIGHT);
        window.setWindowAnimations(R.style.dialog_condition);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = 800;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(params);
        window.setBackgroundDrawable(new ColorDrawable());
    }

    private void showPickerView() {
        TimePickerView pvTime = new TimePickerBuilder(mContext, (date, v) -> {
            mTvStartTime.setText(mDateFormat.format(date));
        }).setTitleText("请选择时间")
                .setType(new boolean[]{true, true, true, true, true, true})
                .setLabel("年", "月", "日", "时", "分", "秒")
                .build();
        pvTime.show();
    }

    @Override
    public void show() {
        super.show();
//        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mContentView
//                .getLayoutParams();
//        layoutParams.width = 500;
//        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
//        mContentView.setLayoutParams(layoutParams);
    }
}
