package com.gh.gamecenter.vpn.view

import android.os.Bundle
import android.os.ParcelFileDescriptor
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.launcher.ARouter
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.IVpnProvider
import com.gh.gamecenter.vpn.R
import com.lightgame.utils.Utils

class VpnActivity : AppCompatActivity() {

    private var mPfd: ParcelFileDescriptor? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val vpnImpl = ARouter.getInstance().build(RouteConsts.provider.vpn).navigation() as? IVpnProvider

        setContentView(R.layout.activity_vpn)

        findViewById<View>(R.id.btn).setOnClickListener {
            if (mPfd == null) {
                vpnImpl?.startVpn(this, hashSetOf("com.gh.gamecenter"), {
                    Utils.log("vpn started result is $it")
                }, {
                    mPfd = it
                })
            } else {
                vpnImpl?.stopVpn(this, mPfd)
                mPfd = null
            }
        }
    }

}