mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 20:17:02 +05:30
app: rewrite UrlLauncherImpl to use Chrome Custom Tabs
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
b30ab6a537
commit
1ba1701574
3 changed files with 22 additions and 6 deletions
|
@ -67,6 +67,7 @@ dependencies {
|
|||
implementation 'androidx.core:core-ktx:1.5.0-alpha03'
|
||||
implementation 'androidx.activity:activity-ktx:1.2.0-alpha08'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
|
||||
implementation "androidx.browser:browser:1.2.0"
|
||||
implementation "androidx.compose.foundation:foundation:$compose_version"
|
||||
implementation "androidx.compose.foundation:foundation-layout:$compose_version"
|
||||
implementation "androidx.compose.foundation:foundation-text:$compose_version"
|
||||
|
@ -84,6 +85,7 @@ dependencies {
|
|||
implementation 'com.google.android.material:material:1.3.0-alpha02'
|
||||
implementation "com.google.dagger:hilt-android:$hilt_dagger_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
|
||||
implementation "saschpe.android:customtabs:3.0.2"
|
||||
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_dagger_version"
|
||||
testImplementation 'junit:junit:4.13'
|
||||
androidTestImplementation "androidx.ui:ui-test:$compose_version"
|
||||
|
|
|
@ -2,6 +2,12 @@ package dev.msfjarvis.lobsters
|
|||
|
||||
import android.app.Application
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import saschpe.android.customtabs.CustomTabsActivityLifecycleCallbacks
|
||||
|
||||
@HiltAndroidApp
|
||||
class Application : Application()
|
||||
class Application : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
registerActivityLifecycleCallbacks(CustomTabsActivityLifecycleCallbacks())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
package dev.msfjarvis.lobsters.urllauncher
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.ACTION_VIEW
|
||||
import android.net.Uri
|
||||
import android.util.Patterns
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import saschpe.android.customtabs.CustomTabsHelper
|
||||
import saschpe.android.customtabs.WebViewFallback
|
||||
|
||||
class UrlLauncherImpl(private val context: Context) : UrlLauncher {
|
||||
override fun launch(url: String) {
|
||||
if (!Patterns.WEB_URL.matcher(url).matches()) return
|
||||
context.startActivity(Intent(ACTION_VIEW).apply { data = Uri.parse(url) })
|
||||
val customTabsIntent = CustomTabsIntent.Builder()
|
||||
.addDefaultShareMenuItem()
|
||||
.setShowTitle(true)
|
||||
.build()
|
||||
CustomTabsHelper.addKeepAliveExtra(context, customTabsIntent.intent)
|
||||
CustomTabsHelper.openCustomTab(
|
||||
context, customTabsIntent,
|
||||
Uri.parse(url),
|
||||
WebViewFallback()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue