@@ -10,7 +10,9 @@ import android.os.Build
10
10
import android.os.Bundle
11
11
import android.view.View
12
12
import androidx.appcompat.app.AppCompatActivity
13
- import com.tbruyelle.rxpermissions2.RxPermissions
13
+ import com.hjq.permissions.OnPermissionCallback
14
+ import com.hjq.permissions.Permission
15
+ import com.hjq.permissions.XXPermissions
14
16
import kotlinx.coroutines.CoroutineScope
15
17
import kotlinx.coroutines.MainScope
16
18
import remix.myplayer.BuildConfig
@@ -24,7 +26,12 @@ import remix.myplayer.theme.ThemeStore.sColoredNavigation
24
26
import remix.myplayer.theme.ThemeStore.statusBarColor
25
27
import remix.myplayer.theme.ThemeStore.themeRes
26
28
import remix.myplayer.ui.misc.AudioTag
27
- import remix.myplayer.util.*
29
+ import remix.myplayer.util.ColorUtil
30
+ import remix.myplayer.util.MediaStoreUtil
31
+ import remix.myplayer.util.PermissionUtil
32
+ import remix.myplayer.util.StatusBarUtil
33
+ import remix.myplayer.util.ToastUtil
34
+ import remix.myplayer.util.Util
28
35
import timber.log.Timber
29
36
30
37
/* *
@@ -43,7 +50,7 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {
43
50
var toDeleteSongs: ArrayList <Song >? = null
44
51
45
52
private var dialog: Dialog ? = null
46
-
53
+
47
54
private val loadingDialog by lazy {
48
55
Theme .getBaseDialog(this )
49
56
.title(R .string.loading)
@@ -86,6 +93,25 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {
86
93
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
87
94
// }
88
95
setNavigationBarColor()
96
+
97
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU && ! XXPermissions .isGranted(
98
+ this ,
99
+ Manifest .permission.POST_NOTIFICATIONS
100
+ )
101
+ ) {
102
+ XXPermissions .with (this )
103
+ .permission(Permission .POST_NOTIFICATIONS )
104
+ .request(object : OnPermissionCallback {
105
+ override fun onGranted (permissions : MutableList <String >, allGranted : Boolean ) {
106
+ Timber .v(" request notification permission onGranted" )
107
+ }
108
+
109
+ override fun onDenied (permissions : MutableList <String >, doNotAskAgain : Boolean ) {
110
+ Timber .v(" request notification permission onDenied: $doNotAskAgain " )
111
+ }
112
+ })
113
+ }
114
+
89
115
}
90
116
91
117
override fun setContentView (layoutResID : Int ) {
@@ -137,23 +163,19 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {
137
163
override fun onResume () {
138
164
super .onResume()
139
165
isForeground = true
140
- RxPermissions (this )
141
- .request(* NECESSARY_PERMISSIONS )
142
- .subscribe { has: Boolean ->
143
- if (has != hasPermission) {
144
- val intent = Intent (MusicService .PERMISSION_CHANGE )
145
- intent.putExtra(BaseMusicActivity .EXTRA_PERMISSION , has)
146
- Util .sendLocalBroadcast(intent)
147
- }
148
- }
149
-
150
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
151
- RxPermissions (this )
152
- .request(Manifest .permission.POST_NOTIFICATIONS )
153
- .subscribe { has ->
154
- Timber .v(" has: $has " )
166
+ if (! hasPermission) {
167
+ XXPermissions .with (this )
168
+ .permission(* NECESSARY_PERMISSIONS )
169
+ .request { _, allGranted ->
170
+ Timber .v(" request necessary permission: $allGranted " )
171
+ if (allGranted != hasPermission) {
172
+ val intent = Intent (MusicService .PERMISSION_CHANGE )
173
+ intent.putExtra(BaseMusicActivity .EXTRA_PERMISSION , allGranted)
174
+ Util .sendLocalBroadcast(intent)
175
+ }
155
176
}
156
177
}
178
+
157
179
}
158
180
159
181
override fun onPause () {
@@ -204,27 +226,26 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {
204
226
loadingDialog.dismiss()
205
227
}
206
228
}
207
-
229
+
208
230
protected fun showDialog (newDialog : Dialog ) {
209
231
dialog?.dismiss()
210
232
if (! isFinishing && ! isDestroyed && hasWindowFocus()) {
211
233
dialog = newDialog
212
234
newDialog.show()
213
235
}
214
236
}
215
-
216
237
217
238
companion object {
218
239
val NECESSARY_PERMISSIONS =
219
240
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
220
- arrayOf(Manifest .permission. READ_MEDIA_AUDIO , Manifest .permission .READ_MEDIA_IMAGES )
241
+ arrayOf(Permission . READ_MEDIA_AUDIO , Permission .READ_MEDIA_IMAGES )
221
242
} else if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .Q ) {
222
243
arrayOf(
223
- Manifest .permission .READ_EXTERNAL_STORAGE ,
224
- Manifest .permission .WRITE_EXTERNAL_STORAGE
244
+ Permission .READ_EXTERNAL_STORAGE ,
245
+ Permission .WRITE_EXTERNAL_STORAGE
225
246
)
226
247
} else {
227
- arrayOf(Manifest .permission .READ_EXTERNAL_STORAGE )
248
+ arrayOf(Permission .READ_EXTERNAL_STORAGE )
228
249
}
229
250
}
230
251
}
0 commit comments