From 2fc5ed53ebc4b07101f22adfb8c5a840ad8efe09 Mon Sep 17 00:00:00 2001 From: egeysn Date: Fri, 9 Jun 2023 16:52:16 +0300 Subject: [PATCH 1/2] Add optional less more action. --- app/src/main/res/layout/activity_main.xml | 19 ++++++++++++++ .../expandable_textview/ExpandableTextView.kt | 26 +++++++++++++++++-- .../src/main/res/values/attrs.xml | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 246a3fd..593229f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -46,6 +46,25 @@ app:expandActionColor="@color/blue_500" app:originalText="@string/long_text" /> + + + this@addLessMoreSpan + else -> return SpannableStringBuilder(this) + .append(lessMoreActionSpannable) + } + } + } diff --git a/expandable_textview/src/main/res/values/attrs.xml b/expandable_textview/src/main/res/values/attrs.xml index 0573ac7..623630e 100644 --- a/expandable_textview/src/main/res/values/attrs.xml +++ b/expandable_textview/src/main/res/values/attrs.xml @@ -5,6 +5,7 @@ + From 3882e7bd95598e7ca773492ba25e100fc9941d97 Mon Sep 17 00:00:00 2001 From: egeysn Date: Sun, 6 Aug 2023 23:44:45 +0300 Subject: [PATCH 2/2] Change collapse action params name. --- README.md | 8 +++---- .../io/github/giangpham96/app/MainActivity.kt | 4 ++-- app/src/main/res/layout/activity_main.xml | 10 ++++---- .../expandable_text_compose/ExpandableText.kt | 20 ++++++++-------- .../expandable_textview/ExpandableTextView.kt | 24 +++++++++---------- .../src/main/res/values/attrs.xml | 4 ++-- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 4aeb5b2..e93d3a2 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ dependencies { android:maxLines="10" app:expandAction="More" app:limitedMaxLines="2" - app:expandActionColor="@color/blue_500" + app:actionColor="@color/blue_500" app:originalText="@string/long_text" /> ``` @@ -72,7 +72,7 @@ dependencies { |:---------------------:|:------:|:-----------------------------------------------------------:|:-------------------------------------------------------:| | app:limitedMaxLines | Int | The maximum line counts when the text is collapsed | 3 | | app:expandAction | String | The action at the end of truncated text such as "View more" | "" (Nothing will be shown at the end of truncated text) | -| app:expandActionColor | Color | The color of expand action | #ffaa66cc | +| app:actionColor | Color | The color of expand/collapse action | #ffaa66cc | | app:originalText | String | The text to be displayed on this text view | "" | #### Public functions @@ -80,7 +80,7 @@ dependencies { - `limitedMaxLines` public getter & setter for the maximum line counts when the text is collapsed. - `expandAction` public getter & setter for the action at the end of truncated text such as "View more". -- `expandActionColor` public getter & setter for the color of expand action. +- `actionColor` public getter & setter for the color of expand/collapse action. - `originalText` public getter & setter for the text to be displayed on this text view. - `collapsed` public getter to determine if the text is being collapsed - `expanded` public getter to determine if the text is being expanded @@ -108,7 +108,7 @@ ExpandableText( originalText = "a very long text that will be truncated at some points", expandAction = "See more", expand = expand, - expandActionColor = Color.Blue, + actionColor = Color.Blue, limitedMaxLines = 2, animationSpec = spring(), modifier = Modifier diff --git a/app/src/main/java/io/github/giangpham96/app/MainActivity.kt b/app/src/main/java/io/github/giangpham96/app/MainActivity.kt index c5a30c3..35152bc 100644 --- a/app/src/main/java/io/github/giangpham96/app/MainActivity.kt +++ b/app/src/main/java/io/github/giangpham96/app/MainActivity.kt @@ -61,7 +61,7 @@ class MainActivity : AppCompatActivity() { btnExpandCtaColor.setOnClickListener { val ctaColorSet = setOf(Color.WHITE, Color.BLACK, Color.BLUE, Color.CYAN, Color.MAGENTA, Color.RED, Color.DKGRAY) - tvDynamic.expandActionColor = ctaColorSet.random() + tvDynamic.actionColor = ctaColorSet.random() } btnMaxLines.setOnClickListener { tvDynamic.maxLines = Random.nextInt(7, 20) @@ -120,7 +120,7 @@ class MainActivity : AppCompatActivity() { originalText = stringResource(id = R.string.long_text), expandAction = "See more", expand = expand, - expandActionColor = androidx.compose.ui.graphics.Color.Blue, + actionColor = androidx.compose.ui.graphics.Color.Blue, ) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 593229f..c1a51cb 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -43,7 +43,7 @@ android:background="@color/purple_100" android:padding="16dp" app:expandAction="More" - app:expandActionColor="@color/blue_500" + app:actionColor="@color/blue_500" app:originalText="@string/long_text" /> this@addLessMoreSpan else -> return SpannableStringBuilder(this) - .append(lessMoreActionSpannable) + .append(collapseActionSpannable) } } diff --git a/expandable_textview/src/main/res/values/attrs.xml b/expandable_textview/src/main/res/values/attrs.xml index 623630e..208effa 100644 --- a/expandable_textview/src/main/res/values/attrs.xml +++ b/expandable_textview/src/main/res/values/attrs.xml @@ -4,8 +4,8 @@ - - + +