fix: 修复字体选择主题颜色
This commit is contained in:
1 file changed
+26
-25
@@ -31,11 +31,12 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.help.loadFontFiles
|
import io.legado.app.help.loadFontFiles
|
||||||
import io.legado.app.ui.theme.LegadoTheme
|
import io.legado.app.ui.theme.LegadoTheme
|
||||||
@@ -139,11 +140,25 @@ private fun FontItem(
|
|||||||
isSelected: Boolean,
|
isSelected: Boolean,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val fontFamily = remember(item.uri) {
|
||||||
|
runCatching {
|
||||||
|
val uri = item.uri
|
||||||
|
val typeface: Typeface? = if (uri.scheme == "content") {
|
||||||
|
context.contentResolver.openFileDescriptor(uri, "r")?.use {
|
||||||
|
Typeface.Builder(it.fileDescriptor).build()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uri.path?.let { Typeface.createFromFile(it) }
|
||||||
|
}
|
||||||
|
typeface?.let { FontFamily(it) }
|
||||||
|
}.getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.background(LegadoTheme.colorScheme.surface, RoundedCornerShape(8.dp))
|
||||||
.background(LegadoTheme.colorScheme.surface)
|
|
||||||
.clickable(onClick = onClick)
|
.clickable(onClick = onClick)
|
||||||
.padding(12.dp),
|
.padding(12.dp),
|
||||||
) {
|
) {
|
||||||
@@ -151,27 +166,13 @@ private fun FontItem(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.height(48.dp)
|
modifier = Modifier.height(48.dp)
|
||||||
) {
|
) {
|
||||||
AndroidView(
|
Text(
|
||||||
factory = { ctx ->
|
text = item.name,
|
||||||
android.widget.TextView(ctx).apply {
|
style = LegadoTheme.typography.bodyMedium.copy(fontFamily = fontFamily),
|
||||||
text = item.name
|
color = LegadoTheme.colorScheme.onSurface,
|
||||||
textSize = 14f
|
maxLines = 2,
|
||||||
gravity = android.view.Gravity.CENTER
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 2
|
textAlign = TextAlign.Center,
|
||||||
ellipsize = android.text.TextUtils.TruncateAt.END
|
|
||||||
runCatching {
|
|
||||||
val uri = item.uri
|
|
||||||
val typeface: Typeface? = if (uri.scheme == "content") {
|
|
||||||
ctx.contentResolver.openFileDescriptor(uri, "r")?.use {
|
|
||||||
Typeface.Builder(it.fileDescriptor).build()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
uri.path?.let { Typeface.createFromFile(it) }
|
|
||||||
}
|
|
||||||
this.typeface = typeface
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
|
|||||||
Reference in new issue
Block a user