package com.zswc.creativity.utils.func

import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.net.Uri
import com.zswc.creativity.config.ConfigFuncType

object QrUtils {
    private var WHICH_QR = ConfigFuncType.QR_WX
    fun scanQr(context: Context) {
        val intent = qrIntent
        context.startActivity(intent)
    }

    fun scanQr(context: Context, WHICH_QR: Int) {
        val intent = getQrIntent(WHICH_QR)
        context.startActivity(intent)
    }
    //https://qr.alipay.com/FKX004164D6OSCOVF5XM2E

    //                String url = "alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=https://qr.alipay.com/FKX038104O53PB4IKOM9F4?_s=web-other&_t=1472443966571";
//                String url = "alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=https://qr.alipay.com/FKX004164D6OSCOVF5XM2E?_s=web-other&_t=1472443966571";
    val qrIntent: Intent
        get() {
            var intent = Intent()
            when (WHICH_QR) {
                ConfigFuncType.QR_APP -> intent.setClassName("com.xiaomi.scanner", "com.xiaomi.scanner.app.ScanActivity")
                ConfigFuncType.QR_WX -> {
                    intent.component = ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI")
                    intent.putExtra("LauncherUI.From.Scaner.Shortcut", true)
                    intent.flags = 335544320
                    intent.action = "android.intent.action.VIEW"
                }
                ConfigFuncType.QR_MIUI -> intent.setClassName("com.xiaomi.scanner", "com.xiaomi.scanner.app.ScanActivity")
                ConfigFuncType.QR_ALIPAY -> {
                    //https://qr.alipay.com/FKX004164D6OSCOVF5XM2E

//                String url = "alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=https://qr.alipay.com/FKX038104O53PB4IKOM9F4?_s=web-other&_t=1472443966571";
//                String url = "alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=https://qr.alipay.com/FKX004164D6OSCOVF5XM2E?_s=web-other&_t=1472443966571";
                    val url = "alipayqr://platformapi/startapp?saId=10000007"
                    val uri = Uri.parse(url)
                    intent = Intent(Intent.ACTION_VIEW, uri)
                    intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
                }
            }
            return intent
        }

    fun getQrIntent(WHICH_QR: Int): Intent {
        QrUtils.WHICH_QR = WHICH_QR
        return qrIntent
    }
}
