package com.ccwangluo.accelerator.ui.login

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.ccwangluo.accelerator.databinding.FragmentSplashBinding
import com.ccwangluo.accelerator.ui.BottomNavigationFragment
import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.tencent.map.geolocation.TencentLocationManager
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xpage.utils.TitleBar
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext


@Page(name = "splash")
class SplashFragment : XPageFragment() {

    override fun initTitleBar(): TitleBar? {
        return null
    }
    override fun inflateView(inflater: LayoutInflater?, container: ViewGroup?): View {
        val inflate = FragmentSplashBinding.inflate(inflater!!, container, false)
        return inflate.root
    }

    override fun initViews() {
        AcceleratorUtils.getGameList(this) {
            if (it) {
                lifecycleScope.launch(Dispatchers.IO) {
                    delay(1000)
                    withContext(Dispatchers.Main) {
                        openPage(BottomNavigationFragment::class.java, false)
                    }
                }
            }
        }
        TencentLocationManager.getInstance(context)
    }

    override fun initListeners() {

    }
}