[状态栏][GPS]修正应用首次启动后,授权后,GPS状态未高亮显示

This commit is contained in:
renwj
2022-10-19 19:41:35 +08:00
parent 9588c00e6f
commit 6eb097a033

View File

@@ -49,9 +49,19 @@ internal class GpsImpl(ctx: Context): IFlow<GpsStatus>(ctx) {
false
}
private val onStateListener = object : IAppStateListener {
override fun onAppStateChanged(isForeground: Boolean) {
if (isForeground) {
send(isLocationEnabled(), isGrandFineLocation())
}
}
}
override fun onCreate() {
val isGranted = isGrandFineLocation()
AppStateManager.registerAppStateListener(onStateListener)
send(isLocationEnabled(), isGranted)
if (!isGranted) {
PermissionUtils.requestAccessFineLocation(object : SimpleCallback {
@@ -88,6 +98,7 @@ internal class GpsImpl(ctx: Context): IFlow<GpsStatus>(ctx) {
} catch (t: Throwable) {
t.printStackTrace()
}
AppStateManager.unRegisterAppStateListener(onStateListener)
}
}