fix: link color

This commit is contained in:
FunkyMuse 2023-09-20 10:37:15 +02:00
parent 3cd957d1bf
commit 8c7f434438
2 changed files with 17 additions and 4 deletions

View File

@ -4,12 +4,12 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
import com.simplemobiletools.commons.compose.extensions.onEventValue
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.extensions.appLaunched
import com.simplemobiletools.commons.extensions.hideKeyboard
import com.simplemobiletools.commons.extensions.launchMoreAppsFromUsIntent
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.thankyou.BuildConfig
@ -24,8 +24,10 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdgeSimple()
setContent {
AppThemeSurface {
val linkColor = rememberLinkColor()
val showMoreApps = onEventValue { !resources.getBoolean(R.bool.hide_google_relations) }
MainScreen(
linkColor = linkColor,
showMoreApps = showMoreApps,
openSettings = ::launchSettings,
openAbout = ::launchAbout,
@ -37,6 +39,14 @@ class MainActivity : ComponentActivity() {
checkWhatsNewDialog()
}
@Composable
private fun rememberLinkColor() = remember {
when {
isWhiteTheme() || isBlackAndWhiteTheme() -> baseConfig.accentColor
else -> getProperPrimaryColor()
}
}
private fun launchSettings() {
hideKeyboard()
startActivity(Intent(this, SettingsActivity::class.java))

View File

@ -33,6 +33,7 @@ internal fun MainScreen(
openSettings: () -> Unit,
openAbout: () -> Unit,
moreAppsFromUs: () -> Unit,
linkColor: Int,
) {
SettingsLazyScaffold(customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color ->
TopAppBar(
@ -60,6 +61,7 @@ internal fun MainScreen(
)
}) { paddingValues ->
val textColor = MaterialTheme.colorScheme.onSurface.toArgb()
AndroidView(
factory = { context ->
TextView(context).apply {
@ -67,6 +69,7 @@ internal fun MainScreen(
textSize = 16.sp.value
setLineSpacing(3.dp.value, 1f)
gravity = Gravity.CENTER_HORIZONTAL
setLinkTextColor(linkColor)
Linkify.addLinks(this, Linkify.WEB_URLS)
Linkify.addLinks(this, Linkify.EMAIL_ADDRESSES)
}
@ -85,6 +88,6 @@ internal fun MainScreen(
@MyDevices
private fun MainScreenPreview() {
AppThemeSurface {
MainScreen(showMoreApps = true, openSettings = {}, openAbout = {}, moreAppsFromUs = {})
MainScreen(showMoreApps = true, openSettings = {}, openAbout = {}, moreAppsFromUs = {}, linkColor = MaterialTheme.colorScheme.onSurface.toArgb())
}
}