mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Fix crash when opening license screen.
This commit is contained in:
@@ -5,11 +5,10 @@
|
||||
|
||||
package org.thoughtcrime.securesms.components.settings.app.help
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
@@ -33,40 +32,45 @@ class LicenseFragment : ComposeFragment() {
|
||||
|
||||
@Composable
|
||||
override fun FragmentContent() {
|
||||
val textState: State<String> = Single.fromCallable {
|
||||
requireContext().resources.openRawResource(R.raw.third_party_licenses).bufferedReader().use { it.readText() }
|
||||
}
|
||||
val textState: State<List<String>> = Single
|
||||
.fromCallable {
|
||||
requireContext().resources.openRawResource(R.raw.third_party_licenses).bufferedReader().use {
|
||||
it.readText().split("\n")
|
||||
}
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeAsState(initial = "")
|
||||
.subscribeAsState(initial = emptyList())
|
||||
|
||||
Scaffolds.Settings(
|
||||
title = stringResource(id = R.string.HelpSettingsFragment__licenses),
|
||||
onNavigationClick = findNavController()::popBackStack,
|
||||
navigationIconPainter = painterResource(id = R.drawable.ic_arrow_left_24),
|
||||
navigationContentDescription = stringResource(id = R.string.Material3SearchToolbar__close)
|
||||
) {
|
||||
LicenseScreen(licenseText = textState.value, modifier = Modifier.padding(it))
|
||||
LicenseScreen(licenseTextLines = textState.value, modifier = Modifier.padding(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LicenseScreen(licenseText: String, modifier: Modifier = Modifier) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
Text(
|
||||
text = licenseText,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(vertical = 16.dp)
|
||||
)
|
||||
fun LicenseScreen(licenseTextLines: List<String>, modifier: Modifier = Modifier) {
|
||||
Surface(modifier = modifier) {
|
||||
LazyColumn(modifier = Modifier.padding(horizontal = 4.dp)) {
|
||||
licenseTextLines.forEach { line ->
|
||||
item {
|
||||
Text(
|
||||
text = line,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun LicenseFragmentPreview() {
|
||||
LicenseScreen("Lorem ipsum")
|
||||
LicenseScreen(listOf("Lorem ipsum", "Delor"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user