Skip to content

Commit

Permalink
added domain verification when sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 26, 2024
1 parent 9e60f2d commit 07ee778
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,6 +21,9 @@ actual fun shareHandler(): ShareHandler {
actual class ShareHandler(
private val context: Context
) {
actual val domainVerifier: StateFlow<Boolean> = DomainVerifier.verified
actual val domainVerifierSupported: Boolean = DomainVerifier.supported

actual fun share(url: String?) {
if (!url.isNullOrBlank()) {
val intent = Intent(Intent.ACTION_SEND)
Expand All @@ -32,4 +37,12 @@ actual class ShareHandler(
)
}
}

actual fun checkDomain() {
DomainVerifier.verify(context)
}

actual fun enableDomain() {
DomainVerifier.enable(context)
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean>
val domainVerifierSupported: Boolean

fun share(url: String?)
fun checkDomain()
fun enableDomain()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,8 @@
<string name="recommendation">Recommendation</string>
<string name="bs_version_requirement">This feature will be supported with Burning-Series version 6.0.0 and upwards.</string>
<string name="nothing_on_list">You have nothing on your list, either change the filter or add any Anime/Manga.</string>
<string name="enable">Enable</string>
<string name="ignore">Ignore</string>
<string name="share_domain_title">Enable In-App View</string>
<string name="share_domain_text">When enabling this option you can view future shared links directly in this app.</string>
</resources>
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/moko-resources/de-DE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,8 @@
<string name="recommendation">Empfehlung</string>
<string name="bs_version_requirement">Diese Option wird mit Burning-Series Version 6.0.0 und höher unterstützt.</string>
<string name="nothing_on_list">Du hast nichts auf deiner Liste, ändere den Filter oder füge einen Anime/Manga hinzu.</string>
<string name="enable">Aktivieren</string>
<string name="ignore">Ignorieren</string>
<string name="share_domain_title">In-App Ansicht aktivieren</string>
<string name="share_domain_text">Wenn du diese Option einschaltest kannst du in Zukunft Links direkt in der App öffnen.</string>
</resources>

0 comments on commit 07ee778

Please sign in to comment.