From 8b97a4a3f1dc799d327dbb7ac631d266a7a986a4 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 27 Mar 2023 17:45:35 +0530 Subject: refactor: migrate to androidx.core APIs for `Bundle`/`Intent` API changes --- .../autofillparser/AutofillScenario.kt | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'autofill-parser/src') diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt index 4f14907c..08eab3ff 100644 --- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt +++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt @@ -7,12 +7,12 @@ package com.github.androidpasswordstore.autofillparser import android.app.assist.AssistStructure import android.os.Build import android.os.Bundle -import android.os.Parcelable import android.service.autofill.Dataset import android.service.autofill.Field import android.view.autofill.AutofillId import android.view.autofill.AutofillValue import androidx.annotation.RequiresApi +import androidx.core.os.BundleCompat import logcat.LogPriority.ERROR import logcat.asLog import logcat.logcat @@ -57,18 +57,36 @@ public sealed class AutofillScenario { return try { Builder() .apply { - username = clientState.getParcelableCompat(BUNDLE_KEY_USERNAME_ID) + username = + BundleCompat.getParcelable( + clientState, + BUNDLE_KEY_USERNAME_ID, + AutofillId::class.java + ) fillUsername = clientState.getBoolean(BUNDLE_KEY_FILL_USERNAME) - otp = clientState.getParcelableCompat(BUNDLE_KEY_OTP_ID) + otp = BundleCompat.getParcelable(clientState, BUNDLE_KEY_OTP_ID, AutofillId::class.java) currentPassword.addAll( - clientState.getParcelableArrayListCompat(BUNDLE_KEY_CURRENT_PASSWORD_IDS) + BundleCompat.getParcelableArrayList( + clientState, + BUNDLE_KEY_CURRENT_PASSWORD_IDS, + AutofillId::class.java + ) ?: emptyList() ) newPassword.addAll( - clientState.getParcelableArrayListCompat(BUNDLE_KEY_NEW_PASSWORD_IDS) ?: emptyList() + BundleCompat.getParcelableArrayList( + clientState, + BUNDLE_KEY_NEW_PASSWORD_IDS, + AutofillId::class.java + ) + ?: emptyList() ) genericPassword.addAll( - clientState.getParcelableArrayListCompat(BUNDLE_KEY_GENERIC_PASSWORD_IDS) + BundleCompat.getParcelableArrayList( + clientState, + BUNDLE_KEY_GENERIC_PASSWORD_IDS, + AutofillId::class.java + ) ?: emptyList() ) } @@ -78,24 +96,6 @@ public sealed class AutofillScenario { null } } - - private inline fun Bundle.getParcelableCompat(key: String): T? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - getParcelable(key, T::class.java) - } else { - @Suppress("DEPRECATION") getParcelable(key) - } - } - - private inline fun Bundle.getParcelableArrayListCompat( - key: String - ): ArrayList? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - getParcelableArrayList(key, T::class.java) - } else { - @Suppress("DEPRECATION") getParcelableArrayList(key) - } - } } internal class Builder { -- cgit v1.2.3