From 73d85709973157ce222671f5db6b2467227d1e4d Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 9 Sep 2020 19:59:02 +0200 Subject: [PATCH] Implemented collapsing --- .../ui/android/dialogs/EnterTanDialog.kt | 4 +- .../banking/ui/android/home/HomeFragment.kt | 1 + .../ui/android/views/CollapsibleTextView.kt | 46 +++++++++++++++++++ .../drawable/ic_baseline_expand_less_24.xml | 10 ++++ .../drawable/ic_baseline_expand_more_24.xml | 10 ++++ .../src/main/res/layout/dialog_enter_tan.xml | 14 ++---- .../main/res/layout/view_collapsible_text.xml | 40 ++++++++++++++++ .../src/main/res/values/dimens.xml | 3 ++ 8 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/CollapsibleTextView.kt create mode 100644 ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_less_24.xml create mode 100644 ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_more_24.xml create mode 100644 ui/BankingAndroidApp/src/main/res/layout/view_collapsible_text.xml diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt index d6655f93..6c169ee3 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt @@ -15,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.DialogFragment import kotlinx.android.synthetic.main.dialog_enter_tan.* import kotlinx.android.synthetic.main.dialog_enter_tan.view.* +import kotlinx.android.synthetic.main.view_collapsible_text.view.* import net.dankito.banking.ui.android.R import net.dankito.banking.ui.android.adapter.TanMediumAdapter import net.dankito.banking.ui.android.adapter.TanProceduresAdapter @@ -85,8 +86,7 @@ open class EnterTanDialog : DialogFragment() { setupTanView(rootView) - rootView.txtTanDescriptionToShowToUser.text = tanChallenge.messageToShowToUser.getSpannedFromHtml() - rootView.lytTanDescriptionToShowToUser.setMaxHeightInDp(145) + rootView.txtvwCollapsibleText.text = tanChallenge.messageToShowToUser.getSpannedFromHtml() if (tanChallenge.tanProcedure.allowedTanFormat == AllowedTanFormat.Numeric) { rootView.edtxtEnteredTan.inputType = InputType.TYPE_CLASS_NUMBER diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt index 02bff70e..eccaed5a 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt @@ -10,6 +10,7 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.SearchView import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProviders +import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import net.dankito.banking.ui.android.R diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/CollapsibleTextView.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/CollapsibleTextView.kt new file mode 100644 index 00000000..6e11fd6b --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/CollapsibleTextView.kt @@ -0,0 +1,46 @@ +package net.dankito.banking.ui.android.views + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.ScrollView +import kotlinx.android.synthetic.main.view_collapsible_text.view.* +import net.dankito.banking.ui.android.R + + +open class CollapsibleTextView @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : ScrollView(context, attrs, defStyleAttr) { + + protected var isCollapsed = true + + + init { + setupUi(context) + } + + private fun setupUi(context: Context) { + val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + val rootView = inflater.inflate(R.layout.view_collapsible_text, this, true) + + rootView.txtvwCollapsibleText.setOnClickListener { toggleIsCollapsed() } + rootView.btnExpandCollapseTextView.setOnClickListener { toggleIsCollapsed() } + } + + + protected open fun toggleIsCollapsed() { + if (isCollapsed) { + txtvwCollapsibleText.maxLines = Int.MAX_VALUE + btnExpandCollapseTextView.setImageResource(R.drawable.ic_baseline_expand_less_24) + + isCollapsed = false + } + else { + txtvwCollapsibleText.maxLines = 3 + btnExpandCollapseTextView.setImageResource(R.drawable.ic_baseline_expand_more_24) + + isCollapsed = true + } + } + +} \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_less_24.xml b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_less_24.xml new file mode 100644 index 00000000..15501459 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_less_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_more_24.xml b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_more_24.xml new file mode 100644 index 00000000..adc215c4 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/res/drawable/ic_baseline_expand_more_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/ui/BankingAndroidApp/src/main/res/layout/dialog_enter_tan.xml b/ui/BankingAndroidApp/src/main/res/layout/dialog_enter_tan.xml index 22e636a0..71dda9e6 100644 --- a/ui/BankingAndroidApp/src/main/res/layout/dialog_enter_tan.xml +++ b/ui/BankingAndroidApp/src/main/res/layout/dialog_enter_tan.xml @@ -95,19 +95,11 @@ android:text="@string/dialog_enter_tan_tan_description_label" /> - + android:layout_height="wrap_content"> - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/values/dimens.xml b/ui/BankingAndroidApp/src/main/res/values/dimens.xml index 636e5b4c..a789bd17 100644 --- a/ui/BankingAndroidApp/src/main/res/values/dimens.xml +++ b/ui/BankingAndroidApp/src/main/res/values/dimens.xml @@ -121,4 +121,7 @@ 8dp 120dp + 36dp + -8dp + \ No newline at end of file