mirror of
https://github.com/bitfireAT/davx5-ose
synced 2024-07-23 19:50:18 +00:00
Add UiUtils method to render Spannables (from HtmlCompat) with Compose (bitfireAT/davx5#430)
* Add Spanned.toAnnotatedString, minor changes --------- Co-authored-by: Ricki Hirner <hirner@bitfire.at>
This commit is contained in:
parent
ca26155eed
commit
fbe0c4451b
|
@ -9,13 +9,22 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.Icon
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.text.Spanned
|
||||
import android.text.style.StyleSpan
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.browser.customtabs.CustomTabsClient
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.text.getSpans
|
||||
import at.bitfire.davdroid.R
|
||||
import at.bitfire.davdroid.log.Logger
|
||||
import at.bitfire.davdroid.settings.Settings
|
||||
|
@ -88,4 +97,28 @@ object UiUtils {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun Spanned.toAnnotatedString() = buildAnnotatedString {
|
||||
val spanned = this@toAnnotatedString
|
||||
append(spanned.toString())
|
||||
for (span in getSpans<Any>(0, spanned.length)) {
|
||||
val start = getSpanStart(span)
|
||||
val end = getSpanEnd(span)
|
||||
when (span) {
|
||||
is StyleSpan ->
|
||||
when (span.style) {
|
||||
Typeface.BOLD -> addStyle(
|
||||
SpanStyle(fontWeight = FontWeight.Bold),
|
||||
start = start, end = end
|
||||
)
|
||||
Typeface.ITALIC -> addStyle(
|
||||
SpanStyle(fontStyle = FontStyle.Italic),
|
||||
start = start, end = end
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ buildscript {
|
|||
ext.versions = [
|
||||
aboutLibraries: '10.9.1',
|
||||
appIntro: '7.0.0-beta02',
|
||||
composeBom: '2023.10.00',
|
||||
composeBom: '2023.10.01',
|
||||
hilt: '2.48.1',
|
||||
kotlin: '1.9.10', // keep in sync with * app/build.gradle composeOptions.kotlinCompilerExtensionVersion
|
||||
// * com.google.devtools.ksp at the end of this file
|
||||
|
|
Loading…
Reference in a new issue