145 lines
5.3 KiB
Kotlin
145 lines
5.3 KiB
Kotlin
package com.dahe.gldriver.ui
|
|
|
|
import android.app.ActivityManager
|
|
import android.content.Context
|
|
import android.os.Bundle
|
|
import android.os.Process
|
|
import cn.jiguang.api.utils.JCollectionAuth
|
|
import cn.jpush.android.api.JPushInterface
|
|
import com.alct.mdp.MDPLocationCollectionManager
|
|
import com.amap.api.location.AMapLocationClient
|
|
import com.amap.api.maps.MapsInitializer
|
|
import com.dahe.gldriver.BuildConfig
|
|
import com.dahe.gldriver.databinding.ActivityLauncherBinding
|
|
import com.dahe.gldriver.third.JTTProcess
|
|
import com.dahe.gldriver.third.SPUtil
|
|
import com.dahe.gldriver.ui.account.LoginActivity
|
|
import com.dahe.gldriver.utils.CommonPopUtils
|
|
import com.dahe.gldriver.utils.SPUtils
|
|
import com.dahe.mylibrary.base.BaseActivity
|
|
import com.dahe.mylibrary.utils.ActivityUtils
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|
import io.reactivex.rxjava3.core.Observable
|
|
import io.reactivex.rxjava3.disposables.Disposable
|
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
class LauncherActivity : BaseActivity<ActivityLauncherBinding>() {
|
|
|
|
|
|
override fun initView(savedInstanceState: Bundle?) {
|
|
// setStatusBarColorToLight2()
|
|
val extras = intent.extras
|
|
binding.llCount.setOnClickListener {
|
|
mDisposable?.dispose()
|
|
//已登录,直接跳转首页
|
|
//
|
|
if (!SPUtils.instance.getUserToken(mContext).isNullOrEmpty()) {
|
|
ActivityUtils.startActivity(mContext, HomeActivity::class.java, intent.extras)
|
|
} else {
|
|
ActivityUtils.startActivity(this@LauncherActivity, LoginActivity::class.java)
|
|
}
|
|
// ActivityUtils.startActivity(this@LauncherActivity, LoginActivity::class.java)
|
|
finish()
|
|
}
|
|
|
|
}
|
|
|
|
private var mDisposable: Disposable? = null
|
|
|
|
override fun initDate() {
|
|
val isFirstOpenApp = SPUtils.instance.getIsFirstOpenApp(mContext)
|
|
if (isFirstOpenApp) {
|
|
MapsInitializer.updatePrivacyShow(this, true, true)
|
|
CommonPopUtils.getInstance().showCenterAgreement(mContext) {
|
|
SPUtils.instance.setIsFirstOpenApp(mContext, false)
|
|
AMapLocationClient.updatePrivacyShow(mContext, true, true)
|
|
AMapLocationClient.updatePrivacyAgree(mContext, true)
|
|
MapsInitializer.updatePrivacyAgree(this, true)
|
|
initThird()
|
|
initPush()
|
|
goNext()
|
|
}
|
|
} else {
|
|
goNext()
|
|
}
|
|
}
|
|
|
|
private fun initThird() {
|
|
val state: String = SPUtil.getSP(mContext, "state_data", "authorization_state")
|
|
if ("1" != state) {
|
|
try {
|
|
//安联初始化
|
|
if (packageName == getCurrentProcessName(this)) {
|
|
//Log.e("--使用的测试环境--",BuildConfig.OPEN_API_URL);
|
|
MDPLocationCollectionManager.initialize(
|
|
applicationContext,
|
|
BuildConfig.OPEN_AL_URL
|
|
)
|
|
}
|
|
//初始化交通厅
|
|
JTTProcess.init(application)
|
|
SPUtil.insSP(mContext, "state_data", "authorization_state", "1")
|
|
} catch (e: Exception) {
|
|
SPUtil.insSP(mContext, "state_data", "authorization_state", "0")
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun initPush() {
|
|
// if (SPUtils.instance.isShowPrivacy(mContext)) {
|
|
JCollectionAuth.setAuth(mContext, true)
|
|
// 初始化SDK
|
|
JPushInterface.setDebugMode(true)
|
|
JPushInterface.init(this)
|
|
// }
|
|
|
|
}
|
|
|
|
override fun onDestroy() {
|
|
super.onDestroy()
|
|
mDisposable?.dispose()
|
|
}
|
|
|
|
private fun goNext() {
|
|
val count = 3
|
|
mDisposable = Observable.interval(0, 1, TimeUnit.SECONDS)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe { aLong: Long ->
|
|
binding.tvCount.setText((count - aLong).toString())
|
|
if (count - aLong == 0L) {
|
|
mDisposable?.dispose()
|
|
//已登录,直接跳转首页
|
|
//已登录,直接跳转首页
|
|
if (!SPUtils.instance.getUserToken(mContext).isNullOrEmpty()) {
|
|
ActivityUtils.startActivity(
|
|
mContext,
|
|
HomeActivity::class.java
|
|
)
|
|
} else {
|
|
ActivityUtils.startActivity(
|
|
this@LauncherActivity,
|
|
LoginActivity::class.java
|
|
)
|
|
finish()
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private fun getCurrentProcessName(context: Context): String? {
|
|
var currentProcessName = ""
|
|
val pid = Process.myPid()
|
|
val mActivityManager = context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
|
if (mActivityManager.runningAppProcesses != null && mActivityManager.runningAppProcesses.size > 0) {
|
|
for (appProcess in mActivityManager.runningAppProcesses) {
|
|
if (appProcess.pid == pid) {
|
|
currentProcessName = appProcess.processName
|
|
}
|
|
}
|
|
}
|
|
return currentProcessName
|
|
}
|
|
} |