package ai.pai.lensman.activities;

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

import com.android.common.utils.DeviceUtils;

import ai.pai.lensman.R;
import ai.pai.lensman.base.BaseActivity;
import ai.pai.lensman.db.Preferences;
import ai.pai.lensman.qrcode.QRCreateUtils;
import ai.pai.lensman.utils.SystemUtils;
import butterknife.BindView;
import butterknife.ButterKnife;


public class SessionQRCodeActivity extends BaseActivity {

    private String qrcode;
    @BindView(R.id.iv_qrcode)   ImageView qrCodeImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_session_qrcode);
        unbinder = ButterKnife.bind(this);
        SystemUtils.setImmerseLayout(this, findViewById(R.id.title_layout));
        TextView title = (TextView) findViewById(R.id.title_bar_middle_txt);
        title.setText(R.string.scan_qr);
        findViewById(R.id.title_bar_back_layout).setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.title_bar_option_layout).setVisibility(View.INVISIBLE);
        qrcode = getIntent().getStringExtra("qrcode");
        if(TextUtils.isEmpty(qrcode)){
            finish();
            return;
        }

        try{
            qrCodeImg.setImageBitmap(QRCreateUtils.Create2DCode("http://pai.ai/s/"+qrcode+"?lensman_id="+ Preferences.getInstance().getLensManId(),
                    DeviceUtils.dip2px(this,280)));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
