diff --git a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/custom/share.android.kt b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/custom/share.android.kt index 7c30034..b368a82 100644 --- a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/custom/share.android.kt +++ b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/custom/share.android.kt @@ -7,6 +7,8 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalContext import androidx.core.content.ContextCompat +import dev.datlag.aniflow.other.DomainVerifier +import kotlinx.coroutines.flow.StateFlow @Composable actual fun shareHandler(): ShareHandler { @@ -19,6 +21,9 @@ actual fun shareHandler(): ShareHandler { actual class ShareHandler( private val context: Context ) { + actual val domainVerifier: StateFlow = DomainVerifier.verified + actual val domainVerifierSupported: Boolean = DomainVerifier.supported + actual fun share(url: String?) { if (!url.isNullOrBlank()) { val intent = Intent(Intent.ACTION_SEND) @@ -32,4 +37,12 @@ actual class ShareHandler( ) } } + + actual fun checkDomain() { + DomainVerifier.verify(context) + } + + actual fun enableDomain() { + DomainVerifier.enable(context) + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/share.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/share.kt index 25643e9..3ce201b 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/share.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/share.kt @@ -1,10 +1,17 @@ package dev.datlag.aniflow.ui.custom import androidx.compose.runtime.Composable +import kotlinx.coroutines.flow.StateFlow @Composable expect fun shareHandler(): ShareHandler expect class ShareHandler { + + val domainVerifier: StateFlow + val domainVerifierSupported: Boolean + fun share(url: String?) + fun checkDomain() + fun enableDomain() } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt index d41d2ce..01df7e1 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt @@ -25,6 +25,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shadow import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import coil3.compose.AsyncImage @@ -33,6 +34,7 @@ import dev.chrisbanes.haze.hazeChild import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi import dev.chrisbanes.haze.materials.HazeMaterials import dev.datlag.aniflow.LocalHaze +import dev.datlag.aniflow.SharedRes import dev.datlag.aniflow.anilist.MediumRepository import dev.datlag.aniflow.anilist.model.Medium import dev.datlag.aniflow.common.notPreferred @@ -44,6 +46,7 @@ import dev.datlag.aniflow.ui.navigation.screen.medium.MediumComponent import dev.datlag.tooling.compose.ifFalse import dev.datlag.tooling.compose.ifTrue import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle +import dev.icerock.moko.resources.compose.stringResource import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow import kotlin.math.max @@ -167,6 +170,54 @@ fun CollapsingToolbar( val siteUrl by component.siteUrl.collectAsStateWithLifecycle(component.initialMedium.siteUrl) val shareHandler = shareHandler() val instantAppHelper = rememberInstantAppHelper() + var showDomainDialog by remember { mutableStateOf(false) } + + SideEffect { + shareHandler.checkDomain() + } + + if (showDomainDialog) { + AlertDialog( + onDismissRequest = { + showDomainDialog = false + }, + icon = { + Icon( + imageVector = Icons.Rounded.Share, + contentDescription = null + ) + }, + title = { + Text(text = stringResource(SharedRes.strings.share_domain_title)) + }, + text = { + Text( + text = stringResource(SharedRes.strings.share_domain_text), + textAlign = TextAlign.Center + ) + }, + confirmButton = { + TextButton( + onClick = { + showDomainDialog = false + shareHandler.enableDomain() + } + ) { + Text(text = stringResource(SharedRes.strings.enable)) + } + }, + dismissButton = { + TextButton( + onClick = { + showDomainDialog = false + shareHandler.share(siteUrl) + } + ) { + Text(text = stringResource(SharedRes.strings.ignore)) + } + } + ) + } AnimatedVisibility( visible = mediumState is MediumRepository.State.Success && !instantAppHelper.isInstantApp, @@ -205,9 +256,21 @@ fun CollapsingToolbar( enter = fadeIn(), exit = fadeOut() ) { + val domainVerified by shareHandler.domainVerifier.collectAsStateWithLifecycle() + IconButton( onClick = { - shareHandler.share(siteUrl) + shareHandler.checkDomain() + + if (shareHandler.domainVerifierSupported) { + if (domainVerified) { + shareHandler.share(siteUrl) + } else { + showDomainDialog = true + } + } else { + shareHandler.share(siteUrl) + } } ) { Icon( diff --git a/composeApp/src/commonMain/moko-resources/base/strings.xml b/composeApp/src/commonMain/moko-resources/base/strings.xml index b30c6d2..7fc2921 100644 --- a/composeApp/src/commonMain/moko-resources/base/strings.xml +++ b/composeApp/src/commonMain/moko-resources/base/strings.xml @@ -119,4 +119,8 @@ Recommendation This feature will be supported with Burning-Series version 6.0.0 and upwards. You have nothing on your list, either change the filter or add any Anime/Manga. + Enable + Ignore + Enable In-App View + When enabling this option you can view future shared links directly in this app. diff --git a/composeApp/src/commonMain/moko-resources/de-DE/strings.xml b/composeApp/src/commonMain/moko-resources/de-DE/strings.xml index 074eb0b..733a65b 100644 --- a/composeApp/src/commonMain/moko-resources/de-DE/strings.xml +++ b/composeApp/src/commonMain/moko-resources/de-DE/strings.xml @@ -119,4 +119,8 @@ Empfehlung Diese Option wird mit Burning-Series Version 6.0.0 und höher unterstützt. Du hast nichts auf deiner Liste, ändere den Filter oder füge einen Anime/Manga hinzu. + Aktivieren + Ignorieren + In-App Ansicht aktivieren + Wenn du diese Option einschaltest kannst du in Zukunft Links direkt in der App öffnen.