package com.itant.shiwushu.tool;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import com.itant.shiwushu.manager.ToastManager;

import java.net.URLEncoder;

/**
 * Created by Jason on 2018/9/9.
 */

public class DonateTool {
    public static boolean openAlipayPayPage(Activity context, String qrcode) {
        try {
            qrcode = URLEncoder.encode(qrcode, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            final String alipayqr = "alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=" + qrcode;
            openUri(context, alipayqr + "%3F_s%3Dweb-other&_t=" + System.currentTimeMillis());
            return true;
        } catch (Exception e) {
            ToastManager.getInstance().toastShort("找不到浏览器");
        }
        return false;
    }

    public static void obtainRedPacket(Activity context, String url) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        Uri content_url = Uri.parse(url);
        intent.setData(content_url);
        try {
            ActivityTool.startActivity(context, intent);
        } catch (Exception e) {
            ToastManager.getInstance().toastShort("找不到浏览器");
        }
    }

    /**
     * 发送一个intent
     *
     * @param context
     * @param s
     */
    private static void openUri(Activity context, String s) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
        try {
            ActivityTool.startActivity(context, intent);
        } catch (Exception e) {
            ToastManager.getInstance().toastShort("找不到浏览器");
        }
    }
}
