diff --git a/feature/chrome-custom-tabs/build.gradle b/feature/chrome-custom-tabs/build.gradle index 2b1013ed..7da26cab 100644 --- a/feature/chrome-custom-tabs/build.gradle +++ b/feature/chrome-custom-tabs/build.gradle @@ -19,7 +19,6 @@ dependencies { kapt daggerAnnotationProcessor implementation 'androidx.browser:browser:1.6.0' implementation 'androidx.core:core:1.12.0' - implementation 'com.jakewharton.timber:timber:5.0.1' testImplementation 'junit:junit:4.13.2' } diff --git a/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsLauncher.kt b/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsLauncher.kt index b8d5ca52..2cd99798 100644 --- a/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsLauncher.kt +++ b/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsLauncher.kt @@ -1,45 +1,19 @@ package com.jraska.github.client.chrome -import android.content.pm.PackageManager import android.net.Uri import androidx.browser.customtabs.CustomTabsIntent import com.jraska.github.client.WebLinkLauncher import com.jraska.github.client.core.android.TopActivityProvider import okhttp3.HttpUrl -import timber.log.Timber +import javax.inject.Inject -private const val CHROME_BROWSER_PACKAGE = "com.android.chrome" - -internal class ChromeCustomTabsLauncher( - private val provider: TopActivityProvider, private val packageManager: PackageManager +internal class ChromeCustomTabsLauncher @Inject constructor( + private val provider: TopActivityProvider, ) : WebLinkLauncher { override fun launchOnWeb(url: HttpUrl) { val uri = Uri.parse(url.toString()) - - val customTabsIntent = prepareIntent(uri) - provider.onTopActivity { customTabsIntent.launchUrl(it, uri) } - } - - private fun prepareIntent(uri: Uri): CustomTabsIntent { val customTabsIntent = CustomTabsIntent.Builder().build() - customTabsIntent.intent.data = uri - - val browsersToHandler = packageManager.queryIntentActivities(customTabsIntent.intent, 0) - return when (browsersToHandler.size) { - 0 -> { - Timber.e("No apps found for uri: %s", uri) - customTabsIntent - } - 1 -> customTabsIntent - else -> { - val chromeAvailable = - null != browsersToHandler.find { it.activityInfo?.packageName == CHROME_BROWSER_PACKAGE } - if (chromeAvailable) { - customTabsIntent.intent.`package` = CHROME_BROWSER_PACKAGE - } - customTabsIntent - } - } + provider.onTopActivity { customTabsIntent.launchUrl(it, uri) } } } diff --git a/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsModule.kt b/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsModule.kt index 2fe7488c..b96d5018 100644 --- a/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsModule.kt +++ b/feature/chrome-custom-tabs/src/main/java/com/jraska/github/client/chrome/ChromeCustomTabsModule.kt @@ -1,16 +1,12 @@ package com.jraska.github.client.chrome -import android.content.Context import com.jraska.github.client.WebLinkLauncher -import com.jraska.github.client.core.android.TopActivityProvider +import dagger.Binds import dagger.Module -import dagger.Provides @Module -object ChromeCustomTabsModule { +abstract class ChromeCustomTabsModule { - @Provides - fun webLinkLauncher(provider: TopActivityProvider, context: Context): WebLinkLauncher { - return ChromeCustomTabsLauncher(provider, context.packageManager) - } + @Binds + internal abstract fun webLinkLauncher(launcher: ChromeCustomTabsLauncher): WebLinkLauncher }