package com.phlx.anchorcollect.ui.labelchange;

import android.os.Bundle;
import android.view.KeyEvent;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.ViewModelProviders;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.bigkoo.pickerview.view.TimePickerView;
import com.phlx.anchorcollect.BR;
import com.phlx.anchorcollect.R;
import com.phlx.anchorcollect.data.VMFactory;
import com.phlx.anchorcollect.databinding.ActivityLabelChangeBinding;
import com.phlx.anchorcollect.entity.CattleResumeEntity;
import com.phlx.anchorcollect.entity.InspectEntity;
import com.phlx.anchorcollect.ui.base.BaseActivity;
import com.phlx.anchorcollect.util.ImagePicker;

public class LabelChangeActivity extends BaseActivity<ActivityLabelChangeBinding, LabelChangeVM> {

    private TimePickerView pvTime;

    private ImagePicker markImagePicker;

    private String epc, noticeNo;

    private CattleResumeEntity entity;
    private InspectEntity inspectEntity;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_label_change;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {
        super.initParam();

        Bundle _bundle = getIntent().getExtras();
        if (_bundle != null) {
            epc = _bundle.getString("epc");
            noticeNo = _bundle.getString("noticeNo");
            entity = _bundle.getParcelable("entity");
            inspectEntity = _bundle.getParcelable("inspectEntity");
        }
    }

    @Override
    public LabelChangeVM initViewModel() {
        VMFactory factory = VMFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(LabelChangeVM.class);
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.initToolbar(epc, noticeNo, entity, inspectEntity);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

    }

    /**
     * 监听Back键按下事件
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            new MaterialDialog.Builder(this).title("系统提示").content("数据尚未保存，是否退出?").positiveText("确定").negativeText("取消").onAny(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    if (which == DialogAction.POSITIVE) {
                        finish();
                    }
                }
            }).show();
            return true;
        } else if (keyCode == 782) {
//            viewModel.photoOnClick.call();
        }
        return super.onKeyDown(keyCode, event);
    }

}
