package com.itant.shiwushu.ui.menu.me;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.itant.shiwushu.R;
import com.itant.shiwushu.base.BaseSkinActivity;
import com.itant.shiwushu.bean.User;
import com.itant.shiwushu.manager.ToastManager;
import com.itant.shiwushu.manager.UserManager;
import com.itant.shiwushu.net.GlobalPresenter;
import com.itant.shiwushu.tool.ColorTool;
import com.itant.shiwushu.tool.DonateTool;
import com.itant.shiwushu.tool.SocialTool;
import com.itant.shiwushu.tool.StringTool;


/**
 * Created by Jason on 2018/10/3.
 */

public class AboutActivity extends BaseSkinActivity implements View.OnClickListener {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        TextView tv_desc = findViewById(R.id.tv_desc);
        String desc = getResources().getString(R.string.about_desc);
        tv_desc.setText(desc);
        tv_desc.setOnClickListener(this);

        findViewById(R.id.aciv_back).setOnClickListener(this);
        findViewById(R.id.ll_contact).setOnClickListener(this);
        findViewById(R.id.ll_donate).setOnClickListener(this);
        findViewById(R.id.ll_vip).setOnClickListener(this);
        findViewById(R.id.ll_share).setOnClickListener(this);
        findViewById(R.id.ll_rate).setOnClickListener(this);

        TextView tv_app_name = findViewById(R.id.tv_app_name);
        PackageManager manager = getPackageManager();
        if (manager != null) {
            try {
                // 0标识获取基本信息
                PackageInfo packageInfo = manager.getPackageInfo(getPackageName(), 0);
                tv_app_name.setText("失物树 v" + packageInfo.versionName);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }

        ImageView iv_head = findViewById(R.id.iv_head);
        int color = ColorTool.getColorPrimary(this);
        iv_head.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_share:
                // 分享
                SocialTool.shareApp(this, "失物树", "失物树是一个专注于失物招领的平台，酷安市场搜索[失物树]即可下载");
                break;
            case R.id.ll_rate:
                // 评分
                SocialTool.jumpMarket(this);
                break;

            case R.id.aciv_back:
                finish();
                break;

            case R.id.tv_desc:
                // 复制
                StringTool.copyText(this, "964161472@qq.com");
                break;

            case R.id.ll_contact:
                // 联系我
                SocialTool.openQQ(this, "964161472");
                break;

            case R.id.ll_donate:
                // 捐助，支付宝自定义输入
                DonateTool.openAlipayPayPage(this, "HTTPS://QR.ALIPAY.COM/FKX05955OEVVEN0DMQXO49");
                break;

            case R.id.ll_vip:
                // 购买会员
                if (UserManager.getInstance().getUser().getUserType() == User.USER_TYPE_VIP) {
                    ToastManager.getInstance().toastShort("您已经是VIP会员");
                } else {
                    GlobalPresenter.becomeVIP();
                    // 支付宝转账1.99元
                    DonateTool.openAlipayPayPage(this, "https://qr.alipay.com/fkx05937kvc49ayh1mko112");
                }
                break;
        }
    }
}
