Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make changes to Coin description #6710

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
package io.horizontalsystems.bankwallet.modules.coin.overview.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.CellData2
import io.horizontalsystems.bankwallet.ui.compose.components.CellSingleLineClear
import io.horizontalsystems.bankwallet.ui.compose.components.DescriptionMarkdown
import io.horizontalsystems.bankwallet.ui.compose.components.VSpacer
import io.horizontalsystems.bankwallet.ui.compose.components.body_leah
import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_jacob

Expand All @@ -44,9 +37,6 @@ fun About(text: String) {
body_leah(text = stringResource(id = R.string.CoinPage_Overview))
}

var showReadMoreToggle by remember { mutableStateOf(false)}
var expanded by remember { mutableStateOf(false)}

Column(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -55,32 +45,19 @@ fun About(text: String) {
.background(ComposeAppTheme.colors.lawrence)
) {
DescriptionMarkdown(
textMaxLines = 8,
toggleLines = 2,
text = text,
expanded = expanded
) { overflow ->
showReadMoreToggle = overflow
}

if (showReadMoreToggle) {
CellData2 {
Row(
modifier = Modifier.fillMaxSize(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
val stringId = if (expanded) R.string.CoinPage_ReadLess else R.string.CoinPage_ReadMore
subhead2_jacob(
modifier = Modifier
.clickable { expanded = !expanded }
.padding(horizontal = 16.dp),
text = stringResource(id = stringId),
textAlign = TextAlign.End,
)
}
}
)
Row(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically
) {
subhead2_jacob(
modifier = Modifier
.padding(horizontal = 16.dp),
text = stringResource(id = R.string.CoinPage_AiGeneratedText),
)
}
VSpacer(12.dp)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.view.doOnPreDraw
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.ui.helpers.LayoutHelper
import io.noties.markwon.AbstractMarkwonPlugin
import io.noties.markwon.Markwon
import io.noties.markwon.MarkwonSpansFactory
import io.noties.markwon.RenderProps
import io.noties.markwon.core.CoreProps
import io.noties.markwon.core.spans.LastLineSpacingSpan
import org.commonmark.node.Heading
import org.commonmark.node.Paragraph

@Composable
fun DescriptionMarkdown(
textMaxLines: Int,
toggleLines: Int,
text: String,
expanded: Boolean,
f: (Boolean) -> Unit,
) {
val context = LocalContext.current
val markdownRender = remember { buildMarkwon(context) }
Expand All @@ -41,19 +38,11 @@ fun DescriptionMarkdown(
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 12.dp),
factory = {
TextView(it).also { aboutText ->
aboutText.doOnPreDraw {
val overflow = aboutText.lineCount > textMaxLines + toggleLines

aboutText.maxLines = if (overflow) textMaxLines else Integer.MAX_VALUE
f.invoke(overflow)
}
}
TextView(it)
},
update = { aboutText ->
val aboutTextSpanned = markdownRender.toMarkdown(text)
aboutText.text = removeLinkSpans(aboutTextSpanned)
aboutText.maxLines = if (expanded) Integer.MAX_VALUE else textMaxLines
}
)
}
Expand All @@ -63,11 +52,19 @@ private fun buildMarkwon(context: Context): Markwon {
.usePlugin(object : AbstractMarkwonPlugin() {

override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
builder.setFactory(Heading::class.java) { _, _ ->
arrayOf(
TextAppearanceSpan(context, R.style.Headline2),
ForegroundColorSpan(context.getColor(R.color.bran))
)
builder.setFactory(Heading::class.java) { _, props: RenderProps ->
val level = CoreProps.HEADING_LEVEL.require(props)
if (level == 1) {
arrayOf(
TextAppearanceSpan(context, R.style.Title3NoColor),
ForegroundColorSpan(context.getColor(R.color.leah))
)
} else {
arrayOf(
TextAppearanceSpan(context, R.style.Headline2),
ForegroundColorSpan(context.getColor(R.color.leah))
)
}
}
builder.setFactory(Paragraph::class.java) { _, _ ->
arrayOf(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@
<string name="CoinPage_SlowLength">Slow Length</string>
<string name="CoinPage_SignalSmoothing">Signal Smoothing</string>
<string name="CoinPage_IndicatorsAlertText">Indicators available only for Unstoppable Wallet premium users.</string>
<string name="CoinPage_AiGeneratedText">This is an AI generated description based on the provided reference material for the given cryptocurrency. It may contain errors.</string>

// Coin Page -> Analytics
<string name="CoinAnalytics_CexVolume_Info1">Total trading volume for the token on leading centralized exchanges over 30-day period.</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<item name="android:textColor">?TitleColor</item>
</style>

<style name="Title3NoColor">
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24sp</item>
</style>

<style name="Headline1">
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">20sp</item>
Expand Down