Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor native codes in flutter_custom_tabs_android #228

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -153,4 +152,8 @@ internal class CustomTabsLauncher @VisibleForTesting constructor(
pm.resolveService(intent, flags)
}
}

private companion object {
const val CODE_LAUNCH_ERROR = "LAUNCH_ERROR"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,4 +19,8 @@ class PartialCustomTabsLauncher {
}
return false
}

private companion object {
const val REQUEST_CODE_PARTIAL_CUSTOM_TABS = 1001
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>): Bundle {
internal fun bundleOf(headers: Map<String, String>): Bundle {
return Bundle(headers.size).apply {
for ((key, value) in headers) {
putString(key, value)
Expand Down
Loading