diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ecb20be2..979807ba 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -58,6 +58,7 @@ dependencies { implementation(libs.workmanager) implementation(libs.encrypted.preferences) implementation(libs.datastore) + implementation(libs.browser) implementation(libs.jsoup) implementation(libs.jodatime) diff --git a/app/src/main/java/com/readrops/app/ComposeAppModule.kt b/app/src/main/java/com/readrops/app/ComposeAppModule.kt index 08b8ea2b..9bfb65bb 100644 --- a/app/src/main/java/com/readrops/app/ComposeAppModule.kt +++ b/app/src/main/java/com/readrops/app/ComposeAppModule.kt @@ -44,7 +44,7 @@ val composeAppModule = module { factory { AccountScreenModel(get()) } - factory { (itemId: Int) -> ItemScreenModel(get(), itemId) } + factory { (itemId: Int) -> ItemScreenModel(get(), itemId, get()) } factory { (accountType: Account, mode: AccountCredentialsScreenMode) -> AccountCredentialsScreenModel(accountType, mode, get()) diff --git a/app/src/main/java/com/readrops/app/item/ItemScreen.kt b/app/src/main/java/com/readrops/app/item/ItemScreen.kt index 3d56ac98..fbaa039e 100644 --- a/app/src/main/java/com/readrops/app/item/ItemScreen.kt +++ b/app/src/main/java/com/readrops/app/item/ItemScreen.kt @@ -3,6 +3,8 @@ package com.readrops.app.item import android.content.Intent import android.net.Uri import android.widget.RelativeLayout +import androidx.browser.customtabs.CustomTabColorSchemeParams +import androidx.browser.customtabs.CustomTabsIntent import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.IntrinsicSize @@ -32,6 +34,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.NestedScrollSource import androidx.compose.ui.input.nestedscroll.nestedScroll @@ -43,6 +46,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView +import androidx.core.net.toUri import androidx.core.view.children import androidx.lifecycle.compose.collectAsStateWithLifecycle import cafe.adriel.voyager.koin.getScreenModel @@ -132,8 +136,22 @@ class ItemScreen( } fun openUrl(url: String) { - val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) - context.startActivity(intent) + if (state.openInExternalBrowser) { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + context.startActivity(intent) + } else { + CustomTabsIntent.Builder() + .setDefaultColorSchemeParams( + CustomTabColorSchemeParams + .Builder() + .setToolbarColor(accentColor.toArgb()) + .build() + ) + .setShareState(CustomTabsIntent.SHARE_STATE_ON) + .setUrlBarHidingEnabled(true) + .build() + .launchUrl(context, url.toUri()) + } } Scaffold( diff --git a/app/src/main/java/com/readrops/app/item/ItemScreenModel.kt b/app/src/main/java/com/readrops/app/item/ItemScreenModel.kt index eddd585c..239f4db7 100644 --- a/app/src/main/java/com/readrops/app/item/ItemScreenModel.kt +++ b/app/src/main/java/com/readrops/app/item/ItemScreenModel.kt @@ -13,6 +13,7 @@ import cafe.adriel.voyager.core.model.screenModelScope import coil.imageLoader import coil.request.ImageRequest import com.readrops.app.repositories.BaseRepository +import com.readrops.app.util.Preferences import com.readrops.db.Database import com.readrops.db.entities.Item import com.readrops.db.entities.account.Account @@ -31,6 +32,7 @@ import java.io.FileOutputStream class ItemScreenModel( private val database: Database, private val itemId: Int, + private val preferences: Preferences, private val dispatcher: CoroutineDispatcher = Dispatchers.IO ) : StateScreenModel(ItemState()), KoinComponent { @@ -64,6 +66,20 @@ class ItemScreenModel( } } } + + screenModelScope.launch(dispatcher) { + preferences.openLinksWith.flow + .collect { value -> + mutableState.update { + it.copy( + openInExternalBrowser = when (value) { + "external_navigator" -> true + else -> false + } + ) + } + } + } } fun shareItem(item: Item, context: Context) { @@ -158,5 +174,6 @@ data class ItemState( val itemWithFeed: ItemWithFeed? = null, val bottomBarState: BottomBarState = BottomBarState(), val imageDialogUrl: String? = null, - val fileDownloadedEvent: Boolean = false + val fileDownloadedEvent: Boolean = false, + val openInExternalBrowser: Boolean = false ) \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index df5bb3d9..eaa0393b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -95,6 +95,7 @@ palette = "androidx.palette:palette-ktx:1.0.0" workmanager = "androidx.work:work-runtime-ktx:2.9.0" encrypted-preferences = "androidx.security:security-crypto:1.1.0-alpha06" datastore = "androidx.datastore:datastore-preferences:1.1.1" +browser = "androidx.browser:browser:1.8.0" # test junit4 = "junit:junit:4.13.2"