package com.rv.share;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.base.utils.ui.image.round.RoundImageView;
import com.ruiwenliu.wrapper.SPConstance;
import com.ruiwenliu.wrapper.base.BaseBean;
import com.ruiwenliu.wrapper.util.UtilsManager;
import com.ruiwenliu.wrapper.util.glide.GlideManager;
import com.ruiwenliu.wrapper.weight.TitleView;
import com.rv.component.utils.DisplayUtil;
import com.rv.component.utils.ZxingUtils;
import com.rv.home.rv.module.basic.BaseStatusActivity;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.yuyife.okgo.OkGoUtil;

import butterknife.BindView;

public class ReativeBillActivity extends BaseStatusActivity<CommonPresenter> {
    private String url;
    @BindView(R2.id.ring_header)
    RoundImageView roundImageView;
    @BindView(R2.id.tv_phone)
    TextView tvPhone;
    @BindView(R2.id.img_qrcode)
    ImageView imgQrcode;
    @BindView(R2.id.btn_save_bill)
    Button btnSaveBill;
    @BindView(R2.id.btn_share)
    Button btnShare;

    public static Intent getIntent(Context context, String url) {
        Intent intent = new Intent(context, ReativeBillActivity.class);
        intent.putExtra("url", url);
        return intent;
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_reative_bill;
    }

    @Override
    protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
        titleView.setTitle("邀请码");
        url = intent.getStringExtra("url");
        if (!TextUtils.isEmpty(url)) {
            Bitmap bitmap = ZxingUtils.createQRImage(url, DisplayUtil.dip2px(this, 150), DisplayUtil.dip2px(this, 150), BitmapFactory.decodeResource(getResources(), com.rv.home.R.mipmap.ic_launcher));
            imgQrcode.setImageBitmap(bitmap);
        }

        String name = UtilsManager.getInstance(OkGoUtil.application).getSPInstance(SPConstance.USER_JSON).getString(SPConstance.USER_JSON_NAME, "");
        String url = UtilsManager.getInstance(OkGoUtil.application).getSPInstance(SPConstance.USER_JSON).getString(SPConstance.USER_JSON_HEADERURL, "");
        if (!TextUtils.isEmpty(url)) {
            GlideManager.getInstance(getApplicationContext()).loadImage(url, roundImageView);
        }
        if (!TextUtils.isEmpty(name)) {
            tvPhone.setText(name + " 邀请你一起参与");
        }
    }

    @Override
    public void onShowResult(int requestType, BaseBean result) {


    }
}
