-
-
Notifications
You must be signed in to change notification settings - Fork 302
/
engine_dev_permission.kt
109 lines (96 loc) · 3.11 KB
/
engine_dev_permission.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package dev.engine.permission
import android.app.Activity
import android.content.Context
import dev.utils.app.permission.PermissionUtils
/**
* detail: DevUtils Permission Engine 实现
* @author Ttt
*/
open class DevPermissionEngineImpl : IPermissionEngine {
// =============
// = 对外公开方法 =
// =============
override fun isGranted(
context: Context?,
vararg permissions: String?
): Boolean {
return PermissionUtils.isGranted(*permissions)
}
override fun shouldShowRequestPermissionRationale(
activity: Activity?,
vararg permissions: String?
): Boolean {
return PermissionUtils.shouldShowRequestPermissionRationale(
activity, *permissions
)
}
override fun getDeniedPermissionStatus(
activity: Activity?,
shouldShow: Boolean,
vararg permissions: String?
): MutableList<String> {
return PermissionUtils.getDeniedPermissionStatus(
activity, shouldShow, *permissions
)
}
override fun againRequest(
activity: Activity?,
callback: IPermissionEngine.Callback?,
deniedList: List<String>?
): Int {
return PermissionUtils.againRequest(activity, object : PermissionUtils.PermissionCallback {
override fun onGranted() {
callback?.onGranted()
}
override fun onDenied(
grantedList: List<String>,
deniedList: List<String>,
notFoundList: List<String>
) {
callback?.onDenied(grantedList, deniedList, notFoundList)
}
}, deniedList)
}
// =============
// = 权限请求方法 =
// =============
override fun request(
activity: Activity?,
permissions: Array<out String>?
) {
request(activity, permissions, null, false)
}
override fun request(
activity: Activity?,
permissions: Array<out String>?,
callback: IPermissionEngine.Callback?
) {
request(activity, permissions, callback, false)
}
override fun request(
activity: Activity?,
permissions: Array<out String>?,
callback: IPermissionEngine.Callback?,
againRequest: Boolean
) {
permissions?.let {
PermissionUtils.permission(*it)
.callback(object : PermissionUtils.PermissionCallback {
override fun onGranted() {
callback?.onGranted()
}
override fun onDenied(
grantedList: List<String>,
deniedList: List<String>,
notFoundList: List<String>
) {
callback?.onDenied(grantedList, deniedList, notFoundList)
// 再次请求处理操作
if (againRequest && deniedList.isNotEmpty()) {
againRequest(activity, callback, deniedList)
}
}
}).request(activity)
}
}
}