diff --git a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/CustomTabsLauncher.kt b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/CustomTabsLauncher.kt index ce5af44b..ea0137f3 100644 --- a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/CustomTabsLauncher.kt +++ b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/CustomTabsLauncher.kt @@ -20,7 +20,6 @@ import com.github.droibit.flutter.plugins.customtabs.core.ExternalBrowserLaunche import com.github.droibit.flutter.plugins.customtabs.core.NativeAppLauncher import com.github.droibit.flutter.plugins.customtabs.core.PartialCustomTabsLauncher import com.github.droibit.flutter.plugins.customtabs.core.session.CustomTabsSessionManager -import com.github.droibit.flutter.plugins.customtabs.core.utils.CODE_LAUNCH_ERROR @RestrictTo(RestrictTo.Scope.LIBRARY) internal class CustomTabsLauncher @VisibleForTesting constructor( @@ -153,4 +152,8 @@ internal class CustomTabsLauncher @VisibleForTesting constructor( pm.resolveService(intent, flags) } } + + private companion object { + const val CODE_LAUNCH_ERROR = "LAUNCH_ERROR" + } } diff --git a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/CustomTabsIntentFactory.kt b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/CustomTabsIntentFactory.kt index d2ad39f1..32335fbe 100644 --- a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/CustomTabsIntentFactory.kt +++ b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/CustomTabsIntentFactory.kt @@ -16,7 +16,7 @@ import com.github.droibit.flutter.plugins.customtabs.core.options.CustomTabsColo import com.github.droibit.flutter.plugins.customtabs.core.options.CustomTabsIntentOptions import com.github.droibit.flutter.plugins.customtabs.core.options.PartialCustomTabsConfiguration import com.github.droibit.flutter.plugins.customtabs.core.session.CustomTabsSessionProvider -import com.github.droibit.flutter.plugins.customtabs.core.utils.extractBundle +import com.github.droibit.flutter.plugins.customtabs.core.utils.bundleOf class CustomTabsIntentFactory @VisibleForTesting internal constructor( private val resources: ResourceFactory @@ -130,7 +130,7 @@ class CustomTabsIntentFactory @VisibleForTesting internal constructor( options: BrowserConfiguration ) { val rawIntent = customTabsIntent.intent - options.headers?.let { rawIntent.putExtra(EXTRA_HEADERS, extractBundle(it)) } + options.headers?.let { rawIntent.putExtra(EXTRA_HEADERS, bundleOf(it)) } // Avoid overriding the package if using CustomTabsSession. if (rawIntent.getPackage() != null) { diff --git a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/ExternalBrowserLauncher.kt b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/ExternalBrowserLauncher.kt index cdb22c3f..e887c05b 100644 --- a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/ExternalBrowserLauncher.kt +++ b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/ExternalBrowserLauncher.kt @@ -6,7 +6,7 @@ import android.net.Uri import android.provider.Browser.EXTRA_HEADERS import androidx.annotation.VisibleForTesting import com.github.droibit.flutter.plugins.customtabs.core.options.CustomTabsIntentOptions -import com.github.droibit.flutter.plugins.customtabs.core.utils.extractBundle +import com.github.droibit.flutter.plugins.customtabs.core.utils.bundleOf class ExternalBrowserLauncher { fun launch(context: Context, uri: Uri, options: CustomTabsIntentOptions?): Boolean { @@ -26,7 +26,7 @@ class ExternalBrowserLauncher { val browserOptions = options.browser ?: return null val prefersExternalBrowser = browserOptions.prefersExternalBrowser if (prefersExternalBrowser == true) { - browserOptions.headers?.let { intent.putExtra(EXTRA_HEADERS, extractBundle(it)) } + browserOptions.headers?.let { intent.putExtra(EXTRA_HEADERS, bundleOf(it)) } return intent } return null diff --git a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/PartialCustomTabsLauncher.kt b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/PartialCustomTabsLauncher.kt index db422fc1..34fa655c 100644 --- a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/PartialCustomTabsLauncher.kt +++ b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/PartialCustomTabsLauncher.kt @@ -5,7 +5,6 @@ import android.net.Uri import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent.EXTRA_ACTIVITY_HEIGHT_RESIZE_BEHAVIOR import androidx.browser.customtabs.CustomTabsIntent.EXTRA_INITIAL_ACTIVITY_HEIGHT_PX -import com.github.droibit.flutter.plugins.customtabs.core.utils.REQUEST_CODE_PARTIAL_CUSTOM_TABS class PartialCustomTabsLauncher { fun launch(activity: Activity, uri: Uri, customTabsIntent: CustomTabsIntent): Boolean { @@ -20,4 +19,8 @@ class PartialCustomTabsLauncher { } return false } + + private companion object { + const val REQUEST_CODE_PARTIAL_CUSTOM_TABS = 1001 + } } diff --git a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/utils/Utils.kt b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/utils/Utils.kt index 60bb19f2..2f1f9635 100644 --- a/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/utils/Utils.kt +++ b/flutter_custom_tabs_android/android/src/main/kotlin/com/github/droibit/flutter/plugins/customtabs/core/utils/Utils.kt @@ -4,10 +4,7 @@ import android.os.Bundle internal const val TAG = "CustomTabsAndroid" -internal const val CODE_LAUNCH_ERROR: String = "LAUNCH_ERROR" -internal const val REQUEST_CODE_PARTIAL_CUSTOM_TABS = 1001 - -internal fun extractBundle(headers: Map): Bundle { +internal fun bundleOf(headers: Map): Bundle { return Bundle(headers.size).apply { for ((key, value) in headers) { putString(key, value)