|
@@ -7,9 +7,9 @@ import android.net.Uri
|
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
import android.os.Handler
|
|
|
-import android.util.Log
|
|
|
import android.view.LayoutInflater
|
|
|
import androidx.core.content.FileProvider
|
|
|
+import com.blankj.utilcode.util.LogUtils
|
|
|
import com.example.chemical.BuildConfig
|
|
|
import com.example.chemical.ChemicalApp
|
|
|
import com.example.chemical.comm.Constants
|
|
@@ -17,7 +17,10 @@ import com.example.chemical.databinding.ActivitySplashBinding
|
|
|
import com.example.chemical.utils.NetworkUtils
|
|
|
import com.example.chemical.utils.SharedPreferencesHelper
|
|
|
import com.example.chemical.utils.UiManager
|
|
|
-import com.google.gson.Gson
|
|
|
+import com.hjq.permissions.OnPermissionCallback
|
|
|
+import com.hjq.permissions.Permission
|
|
|
+import com.hjq.permissions.XXPermissions
|
|
|
+import com.kongzue.dialogx.dialogs.MessageDialog
|
|
|
import com.lztek.toolkit.Lztek
|
|
|
import com.rc.core.log.RcLog
|
|
|
import com.rc.core.ui.activity.RcBaseActivity
|
|
@@ -33,10 +36,15 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
|
|
|
private var mLztek: Lztek? = null
|
|
|
private var mDeviceNum: String? = null //设备唯一标识
|
|
|
private var isOk = false
|
|
|
+ private var test: String = ""
|
|
|
override fun createViewBinding() = ActivitySplashBinding.inflate(LayoutInflater.from(this))
|
|
|
|
|
|
override fun initViews(savedInstanceState: Bundle?) {
|
|
|
super.initViews(savedInstanceState)
|
|
|
+ requestPermission()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun initView() {
|
|
|
viewBinding.versionName.text = "版本号:${DeviceUtils.getVersionName(this)}"
|
|
|
mLztek = Lztek.create(this)
|
|
|
val toUpperCase = mLztek!!.ethMac.toUpperCase()
|
|
@@ -55,43 +63,65 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
|
|
|
Constants.FACE_TAG = urlBase.d.toInt()
|
|
|
}
|
|
|
}
|
|
|
- requestPermission()
|
|
|
+
|
|
|
+ val isNetworkAvailable = NetworkUtils.isNetworkAvailable(this)
|
|
|
+ if (isNetworkAvailable) {
|
|
|
+ // 当前网络可用
|
|
|
+ queryAppVersion()
|
|
|
+ } else {
|
|
|
+ if (!isOk) {
|
|
|
+ // 启动定时任务
|
|
|
+ myHandler.start()
|
|
|
+ isOk = true
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
private fun requestPermission() {
|
|
|
- val disposable = RxPermissions(this)
|
|
|
- .request(
|
|
|
- Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
- Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
|
- Manifest.permission.CAMERA,
|
|
|
- Manifest.permission.READ_PHONE_STATE,
|
|
|
- Manifest.permission.RECORD_AUDIO,
|
|
|
- )
|
|
|
- .subscribe { granted ->
|
|
|
- if (granted) {
|
|
|
- val isNetworkAvailable = NetworkUtils.isNetworkAvailable(this)
|
|
|
- if (isNetworkAvailable) {
|
|
|
- // 当前网络可用
|
|
|
- queryAppVersion()
|
|
|
- } else {
|
|
|
- if (!isOk) {
|
|
|
- // 启动定时任务
|
|
|
- myHandler.start()
|
|
|
- isOk = true
|
|
|
+
|
|
|
+ XXPermissions.with(this)
|
|
|
+ .permission(
|
|
|
+ Permission.CAMERA,
|
|
|
+ Permission.READ_EXTERNAL_STORAGE,
|
|
|
+ Permission.WRITE_EXTERNAL_STORAGE,
|
|
|
+ Permission.READ_PHONE_STATE,
|
|
|
+ Permission.RECORD_AUDIO
|
|
|
+ )
|
|
|
+ .request(object : OnPermissionCallback {
|
|
|
+ override fun onGranted(permissions: MutableList<String>, allGranted: Boolean) {
|
|
|
+ if (allGranted) {
|
|
|
+ initView()
|
|
|
+ } else {
|
|
|
+ MessageDialog.show("提示", "您必须同意所有权限才可以继续使用", "确定")
|
|
|
+ .setCancelable(false).setOkButtonClickListener { dialog, v ->
|
|
|
+ requestPermission()
|
|
|
+ false
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ override fun onDenied(permissions: MutableList<String>, doNotAskAgain: Boolean) {
|
|
|
+ super.onDenied(permissions, doNotAskAgain)
|
|
|
+ if (doNotAskAgain) {
|
|
|
+ MessageDialog.show("提示", "您必须同意所有权限才可以继续使用", "确定")
|
|
|
+ .setCancelable(false).setOkButtonClickListener { dialog, v ->
|
|
|
+ XXPermissions.startPermissionActivity(
|
|
|
+ this@SplashActivity,
|
|
|
+ permissions
|
|
|
+ )
|
|
|
+ false
|
|
|
+ }
|
|
|
} else {
|
|
|
- AlertDialog.Builder(this)
|
|
|
- .setTitle("提示")
|
|
|
- .setMessage("您必须同意所有权限才可以继续使用")
|
|
|
- .setNegativeButton("确定") { _, _ ->
|
|
|
- requestPermission()
|
|
|
- }.show()
|
|
|
+ MessageDialog.show("提示", "您必须同意所有权限才可以继续使用", "确定")
|
|
|
+ .setCancelable(false).setOkButtonClickListener { dialog, v ->
|
|
|
+ requestPermission()
|
|
|
+ false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- addDisposable(disposable)
|
|
|
+ })
|
|
|
|
|
|
}
|
|
|
|
|
@@ -152,55 +182,55 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
|
|
|
// AIO_INFOBORD("aio_infobord","电子信息牌"),
|
|
|
// AIO_EXAM("aio_exam","学习考试一体机");
|
|
|
val disposable =
|
|
|
- ApiRepository.getCheck(mDeviceNum!!, "aio_chemical", toDouble.toDouble())
|
|
|
- .subscribe({ data ->
|
|
|
- dismissLoading()
|
|
|
- if (!data.needUpgrade) {
|
|
|
- ChemicalApp.labInfo = data.labInfo
|
|
|
- ChemicalApp.subjectId = data.labInfo.subjectId
|
|
|
- ChemicalApp.subjectName = data.labInfo.subjectName
|
|
|
- ChemicalApp.subRoom = data.labInfo.room
|
|
|
- UiManager.switcher(this@SplashActivity, MainActivity::class.java)
|
|
|
- finish()
|
|
|
- } else {
|
|
|
- //需要更新
|
|
|
- if (data.appInfo != null) {
|
|
|
- when {
|
|
|
- data.appInfo!!.remark != null -> {
|
|
|
- //同步进行更新
|
|
|
- upDownloadManager(data!!.appInfo!!.remark)
|
|
|
- }
|
|
|
-
|
|
|
- data!!.appInfo!!.url != null -> {
|
|
|
- upDownloadManager(data.appInfo!!.url)
|
|
|
- }
|
|
|
-
|
|
|
- else -> {
|
|
|
- // 启动定时任务
|
|
|
- try {
|
|
|
- myHandler.stop()
|
|
|
- } catch (e: Exception) {
|
|
|
-
|
|
|
- } finally {
|
|
|
- myHandler.start()
|
|
|
- }
|
|
|
- showToast("版本信息不不存在")
|
|
|
- }
|
|
|
+ ApiRepository.getCheck(mDeviceNum!!, "aio_chemical", toDouble.toDouble())
|
|
|
+ .subscribe({ data ->
|
|
|
+ dismissLoading()
|
|
|
+ if (!data.needUpgrade) {
|
|
|
+ ChemicalApp.labInfo = data.labInfo
|
|
|
+ ChemicalApp.subjectId = data.labInfo.subjectId
|
|
|
+ ChemicalApp.subjectName = data.labInfo.subjectName
|
|
|
+ ChemicalApp.subRoom = data.labInfo.room
|
|
|
+ UiManager.switcher(this@SplashActivity, MainActivity::class.java)
|
|
|
+ finish()
|
|
|
+ } else {
|
|
|
+ //需要更新
|
|
|
+ if (data.appInfo != null) {
|
|
|
+ when {
|
|
|
+ data.appInfo!!.remark != null -> {
|
|
|
+ //同步进行更新
|
|
|
+ upDownloadManager(data!!.appInfo!!.remark)
|
|
|
+ }
|
|
|
+
|
|
|
+ data!!.appInfo!!.url != null -> {
|
|
|
+ upDownloadManager(data.appInfo!!.url)
|
|
|
+ }
|
|
|
+
|
|
|
+ else -> {
|
|
|
+ // 启动定时任务
|
|
|
+ try {
|
|
|
+ myHandler.stop()
|
|
|
+ } catch (e: Exception) {
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ myHandler.start()
|
|
|
}
|
|
|
- } else {
|
|
|
- UiManager.switcher(this@SplashActivity, MainActivity::class.java)
|
|
|
- finish()
|
|
|
+ showToast("版本信息不不存在")
|
|
|
}
|
|
|
}
|
|
|
- }, { throwable ->
|
|
|
- dismissLoading()
|
|
|
- showNetError(throwable)
|
|
|
- if (!isOk) {
|
|
|
- // 启动定时任务
|
|
|
- myHandler.start()
|
|
|
- isOk = true
|
|
|
- }
|
|
|
- })
|
|
|
+ } else {
|
|
|
+ UiManager.switcher(this@SplashActivity, MainActivity::class.java)
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, { throwable ->
|
|
|
+ dismissLoading()
|
|
|
+ showNetError(throwable)
|
|
|
+ if (!isOk) {
|
|
|
+ // 启动定时任务
|
|
|
+ myHandler.start()
|
|
|
+ isOk = true
|
|
|
+ }
|
|
|
+ })
|
|
|
addDisposable(disposable)
|
|
|
|
|
|
}
|
|
@@ -208,7 +238,7 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
|
|
|
|
|
|
private fun upDownloadManager(downloadUrl: String) {
|
|
|
ApkUpdater(this, BuildConfig.APPLICATION_ID, callback = object :
|
|
|
- ApkUpdater.DownloadCallback {
|
|
|
+ ApkUpdater.DownloadCallback {
|
|
|
override fun onProgress(progress: Int) {
|
|
|
myHandler.stop()
|
|
|
showLoading("检测到新版本,开始更新(${progress}%)")
|
|
@@ -290,7 +320,7 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
// 与AndroidManifest.xml中的authorities配置一致
|
|
|
val authority =
|
|
|
- BuildConfig.APPLICATION_ID + ".fileprovider"
|
|
|
+ BuildConfig.APPLICATION_ID + ".fileprovider"
|
|
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
val uri = FileProvider.getUriForFile(this@SplashActivity, authority, apkFile)
|
|
|
intent.setDataAndType(uri, "application/vnd.android.package-archive")
|