mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
63e1de46ac
commit
4979cc66e1
@ -5,6 +5,8 @@ import android.os.Build
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object Permissions {
|
object Permissions {
|
||||||
|
|
||||||
|
const val POST_NOTIFICATIONS = "android.permission.POST_NOTIFICATIONS"
|
||||||
|
|
||||||
const val READ_CALENDAR = "android.permission.READ_CALENDAR"
|
const val READ_CALENDAR = "android.permission.READ_CALENDAR"
|
||||||
const val WRITE_CALENDAR = "android.permission.WRITE_CALENDAR"
|
const val WRITE_CALENDAR = "android.permission.WRITE_CALENDAR"
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@ import android.os.Environment
|
|||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.utils.startActivity
|
import io.legado.app.utils.startActivity
|
||||||
|
import splitties.init.appCtx
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
internal class Request : OnRequestPermissionsResultCallback {
|
internal class Request : OnRequestPermissionsResultCallback {
|
||||||
@ -118,19 +120,29 @@ internal class Request : OnRequestPermissionsResultCallback {
|
|||||||
if (permissions != null) {
|
if (permissions != null) {
|
||||||
val deniedPermissionList = ArrayList<String>()
|
val deniedPermissionList = ArrayList<String>()
|
||||||
for (permission in permissions) {
|
for (permission in permissions) {
|
||||||
if (permission == Permissions.MANAGE_EXTERNAL_STORAGE) {
|
when (permission) {
|
||||||
|
Permissions.POST_NOTIFICATIONS -> {
|
||||||
|
if (!NotificationManagerCompat.from(appCtx).areNotificationsEnabled()) {
|
||||||
|
deniedPermissionList.add(permission)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Permissions.MANAGE_EXTERNAL_STORAGE -> {
|
||||||
if (Permissions.isManageExternalStorage()) {
|
if (Permissions.isManageExternalStorage()) {
|
||||||
if (!Environment.isExternalStorageManager()) {
|
if (!Environment.isExternalStorageManager()) {
|
||||||
deniedPermissionList.add(permission)
|
deniedPermissionList.add(permission)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (
|
}
|
||||||
|
else -> {
|
||||||
|
if (
|
||||||
ContextCompat.checkSelfPermission(context, permission)
|
ContextCompat.checkSelfPermission(context, permission)
|
||||||
!= PackageManager.PERMISSION_GRANTED
|
!= PackageManager.PERMISSION_GRANTED
|
||||||
) {
|
) {
|
||||||
deniedPermissionList.add(permission)
|
deniedPermissionList.add(permission)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
val size = deniedPermissionList.size
|
val size = deniedPermissionList.size
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
return deniedPermissionList.toTypedArray()
|
return deniedPermissionList.toTypedArray()
|
||||||
|
Loading…
Reference in New Issue
Block a user