OH: fix upload

This commit is contained in:
Milos Kozak 2022-05-27 21:01:24 +02:00
parent e02e55ce32
commit 60f5115ce6

View file

@ -91,7 +91,7 @@ class OpenHumansUploader @Inject internal constructor(
} }
private fun onSharedPreferenceChanged(event: EventPreferenceChange) { private fun onSharedPreferenceChanged(event: EventPreferenceChange) {
if (event.changedKey in arrayOf("key_oh_charging_only", "key_oh_wifi_only") && openHumansState != null) scheduleWorker(true) if (event.changedKey in arrayOf("key_oh_charging_only", "key_oh_wifi_only") && openHumansState != null) scheduleWorker(true)
} }
suspend fun login(bearerToken: String) = withContext(Dispatchers.IO) { suspend fun login(bearerToken: String) = withContext(Dispatchers.IO) {
@ -234,10 +234,7 @@ class OpenHumansUploader @Inject internal constructor(
val displayMetrics = DisplayMetrics() val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(displayMetrics)
context.display?.getRealMetrics(displayMetrics)
else
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(displayMetrics)
val displayInfo = JSONObject() val displayInfo = JSONObject()
displayInfo.put("height", displayMetrics.heightPixels) displayInfo.put("height", displayMetrics.heightPixels)
@ -614,13 +611,14 @@ class OpenHumansUploader @Inject internal constructor(
.setAutoCancel(true) .setAutoCancel(true)
.setContentIntent( .setContentIntent(
PendingIntent.getActivity( PendingIntent.getActivity(
context, context,
0, 0,
Intent(context, OHLoginActivity::class.java).apply { Intent(context, OHLoginActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
}, },
0 0
)) )
)
.build() .build()
NotificationManagerCompat.from(context).notify(SIGNED_OUT_NOTIFICATION_ID, notification) NotificationManagerCompat.from(context).notify(SIGNED_OUT_NOTIFICATION_ID, notification)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
@ -646,7 +644,9 @@ class OpenHumansUploader @Inject internal constructor(
} }
private companion object { private companion object {
val HEX_DIGITS = "0123456789ABCDEF".toCharArray() val HEX_DIGITS = "0123456789ABCDEF".toCharArray()
@Suppress("PrivatePropertyName") @Suppress("PrivatePropertyName")
private val FILE_NAME_DATE_FORMAT = SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") } private val FILE_NAME_DATE_FORMAT = SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") }
const val WORK_NAME_PERIODIC = "Open Humans Periodic" const val WORK_NAME_PERIODIC = "Open Humans Periodic"