|
@@ -1,32 +1,43 @@
|
|
|
package com.luojigou.product.intro
|
|
|
|
|
|
+import android.content.Intent
|
|
|
+import android.net.Uri
|
|
|
+import android.provider.Settings
|
|
|
import android.util.Log
|
|
|
-import android.view.View
|
|
|
import androidx.activity.result.ActivityResultLauncher
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
|
import com.luojigou.product.R
|
|
|
import com.luojigou.product.base.BaseActivity
|
|
|
import com.luojigou.product.utils.PermissionUtils
|
|
|
|
|
|
-abstract class AbsIntroduceActivity : BaseActivity(), View.OnClickListener,
|
|
|
- IntroducePermissionFragment.Host {
|
|
|
+
|
|
|
+abstract class AbsIntroduceActivity : BaseActivity(), IntroducePermissionFragment.Host,
|
|
|
+ IntroducePermissionManualFragment.Host {
|
|
|
|
|
|
private lateinit var permissionUtils: PermissionUtils
|
|
|
|
|
|
private lateinit var requestPermission: ActivityResultLauncher<Array<String>>
|
|
|
|
|
|
+
|
|
|
+ private var requesting = false
|
|
|
override fun onCreate(savedInstanceState: android.os.Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setTitle("连接引导")
|
|
|
- requestPermission =
|
|
|
- registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
|
|
|
- if (it.all { permission -> permission.value }) {
|
|
|
- setFragment(IntroduceNormalFragment())
|
|
|
- } else {
|
|
|
- Log.e("XDScanWifiActivity", "requestPermission: 权限被拒绝")
|
|
|
- }
|
|
|
+ requestPermission = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
|
|
|
+ if (it.all { permission -> permission.value }) {
|
|
|
+ setFragment(IntroduceNormalFragment())
|
|
|
+ } else {
|
|
|
+ setFragment(IntroducePermissionManualFragment(this))
|
|
|
+ Log.e("XDScanWifiActivity", "requestPermission: 权限被拒绝")
|
|
|
}
|
|
|
+
|
|
|
+ requesting = false
|
|
|
+ }
|
|
|
permissionUtils = PermissionUtils(this)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onResume() {
|
|
|
+ super.onResume()
|
|
|
checkAndSetFragment()
|
|
|
}
|
|
|
|
|
@@ -34,21 +45,39 @@ abstract class AbsIntroduceActivity : BaseActivity(), View.OnClickListener,
|
|
|
if (permissionUtils.checkAllPermissions()) {
|
|
|
setFragment(IntroduceNormalFragment())
|
|
|
} else {
|
|
|
- setFragment(IntroducePermissionFragment(this))
|
|
|
+ if (permissionUtils.shouldShowRequestPermissionRationale()) {
|
|
|
+ setFragment(IntroducePermissionManualFragment(this))
|
|
|
+ } else {
|
|
|
+ setFragment(IntroducePermissionFragment(this))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun getLayoutId(): Int = R.layout.activity_introduce
|
|
|
|
|
|
- override fun onClick(v: View?) {
|
|
|
- when (v?.id) {
|
|
|
- R.id.btn_intro_start -> startActivity()
|
|
|
+ override fun requestPermission() {
|
|
|
+ if (requesting) {
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- override fun requestPermission() {
|
|
|
+ requesting = true
|
|
|
requestPermission.launch(permissionUtils.requestAllPermissions())
|
|
|
}
|
|
|
|
|
|
+ override fun manualRequestPermission() {
|
|
|
+ try {
|
|
|
+ val settingsIntent = Intent()
|
|
|
+ settingsIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
|
|
+ settingsIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
|
|
+ settingsIntent.setData(Uri.parse("package:" + this.packageName))
|
|
|
+ settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
+ settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
|
|
|
+ settingsIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
|
|
+ this.startActivity(settingsIntent)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
abstract fun startActivity()
|
|
|
}
|