-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split settings in sections and check if shared links is enabled
- Loading branch information
Showing
14 changed files
with
637 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/DomainVerifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dev.datlag.aniflow.other | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.verify.domain.DomainVerificationManager | ||
import android.content.pm.verify.domain.DomainVerificationUserState | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.provider.Settings | ||
import androidx.annotation.ChecksSdkIntAtLeast | ||
import androidx.core.content.ContextCompat | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.update | ||
|
||
data object DomainVerifier { | ||
|
||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S) | ||
val supported: Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S | ||
val verified: MutableStateFlow<Boolean> = MutableStateFlow(false) | ||
|
||
@Suppress("NewApi") | ||
fun verify(context: Context) { | ||
if (supported) { | ||
val manager = ContextCompat.getSystemService(context, DomainVerificationManager::class.java) | ||
val userState = manager?.getDomainVerificationUserState(context.packageName) | ||
val unapprovedDomains = userState?.hostToStateMap?.filterValues { it == DomainVerificationUserState.DOMAIN_STATE_NONE } | ||
|
||
unapprovedDomains?.let { count -> | ||
verified.update { count.isEmpty() } | ||
} | ||
} | ||
} | ||
|
||
@Suppress("NewApi") | ||
fun enable(context: Context) { | ||
if (supported) { | ||
val intent = Intent( | ||
Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, | ||
Uri.parse("package:${context.packageName}") | ||
) | ||
ContextCompat.startActivity(context, intent, null) | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...v/datlag/aniflow/ui/navigation/screen/initial/settings/component/DomainSection.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dev.datlag.aniflow.ui.navigation.screen.initial.settings.component | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Check | ||
import androidx.compose.material.icons.filled.Share | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Switch | ||
import androidx.compose.material3.SwitchDefaults | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.SideEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.unit.dp | ||
import dev.datlag.aniflow.other.DomainVerifier | ||
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle | ||
|
||
@Composable | ||
actual fun DomainSection(modifier: Modifier) { | ||
if (DomainVerifier.supported) { | ||
val context = LocalContext.current | ||
val verified by DomainVerifier.verified.collectAsStateWithLifecycle() | ||
|
||
SideEffect { | ||
DomainVerifier.verify(context) | ||
} | ||
|
||
Row( | ||
modifier = modifier, | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
Icon( | ||
imageVector = Icons.Filled.Share, | ||
contentDescription = null, | ||
) | ||
Text( | ||
text = "Open Links" | ||
) | ||
Spacer(modifier = Modifier.weight(1F)) | ||
Switch( | ||
checked = verified, | ||
onCheckedChange = { | ||
DomainVerifier.enable(context) | ||
}, | ||
enabled = !verified, | ||
thumbContent = { | ||
if (verified) { | ||
Icon( | ||
modifier = Modifier.size(SwitchDefaults.IconSize), | ||
imageVector = Icons.Default.Check, | ||
contentDescription = null | ||
) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.