package ai.pai.lensman.upgrade;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import ai.pai.lensman.R;
import ai.pai.lensman.base.BaseActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chengzhenyu on 2017/4/22.
 */

public class BoxUpgradeActivity extends BaseActivity implements BoxUpgradeInteractor.BoxUpgradeListener{

    @BindView(R.id.layout_choose_update) View chooseUpdateView;

    BoxUpgradeInteractor upgradeInteractor;

    private String bpversion_str;

    public static void startBoxUpgradeActivity(Context context,String bpversion_str){
        Intent intent = new Intent(context, BoxUpgradeActivity.class);
        intent.putExtra("bpversion_str",bpversion_str);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_box_upgrade);
        unbinder = ButterKnife.bind(this);
        bpversion_str = getIntent().getStringExtra("bpversion_str");
        if(TextUtils.isEmpty(bpversion_str)){
            finish();
        }
    }

    @OnClick(R.id.btn_update_now)
    public void updateNow(){
        chooseUpdateView.setVisibility(View.GONE);
        upgradeInteractor = new BoxUpgradeInteractor(bpversion_str,this);
        upgradeInteractor.startJob();
    }

    @OnClick(R.id.btn_update_later)
    public void UpdateLater(){
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getKeyCode()==KeyEvent.KEYCODE_BACK){
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBoxUpgrade(boolean result) {
        if(result){

        }else{

        }
    }
}
