Implemented FormLabelledValue

This commit is contained in:
dankito 2020-09-28 16:54:44 +02:00
parent 1d09789d38
commit 25089558c1
5 changed files with 113 additions and 1 deletions

View File

@ -0,0 +1,65 @@
package net.dankito.banking.ui.android.views
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.view_form_labelled_value.view.*
import net.dankito.banking.ui.android.R
open class FormLabelledValue @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
init {
setupUi(context, attrs)
}
private fun setupUi(context: Context, attrs: AttributeSet?) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val rootView = inflater.inflate(R.layout.view_form_labelled_value, this, true)
rootView.apply {
context.theme.obtainStyledAttributes(
attrs,
R.styleable.FormLabelledValue,
0, 0).apply {
try {
txtLabel.text = getString(R.styleable.FormLabelledValue_android_label)
txtValue.text = getString(R.styleable.FormLabelledValue_android_value)
} finally {
recycle()
}
}
}
}
open var label: CharSequence
get() = txtLabel.text
set(value) {
txtLabel.text = value
}
open var value: CharSequence
get() = txtValue.text
set(value) {
txtValue.text = value
}
open fun setValueAndVisibilityIfValueIsSet(value: CharSequence?) {
if (value != null) {
this.value = value
this.visibility = View.VISIBLE
}
else {
this.visibility = View.GONE
}
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/txtLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/form_labelled_value_label_margin_top"
android:layout_marginBottom="@dimen/form_labelled_value_label_margin_bottom"
android:maxLines="1"
android:textSize="@dimen/form_labelled_value_label_text_size"
android:textColor="@color/formLabelledValueLabelTextColor"
/>
<TextView
android:id="@+id/txtValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/form_labelled_value_value_margin_bottom"
android:textIsSelectable="true"
android:textSize="@dimen/form_labelled_value_value_text_size"
android:textColor="@color/formLabelledValueValueTextColor"
/>
</LinearLayout>

View File

@ -26,4 +26,12 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="FormLabelledValue">
<attr name="android:label" />
<attr name="android:value" />
</declare-styleable>
</resources> </resources>

View File

@ -17,6 +17,9 @@
<color name="materialDesignTextColorPrimary">#737373</color> <color name="materialDesignTextColorPrimary">#737373</color>
<color name="formLabelledValueLabelTextColor">#494949</color>
<color name="formLabelledValueValueTextColor">#999999</color>
<color name="drawerMenuItemPrimaryColor">@color/primaryTextColor_Dark</color> <color name="drawerMenuItemPrimaryColor">@color/primaryTextColor_Dark</color>
<color name="positiveAmount">#43A047</color> <color name="positiveAmount">#43A047</color>

View File

@ -22,7 +22,13 @@
<dimen name="form_section_margin_bottom">6dp</dimen> <dimen name="form_section_margin_bottom">6dp</dimen>
<dimen name="form_section_title_text_size">15sp</dimen> <dimen name="form_section_title_text_size">15sp</dimen>
<dimen name="form_section_title_margin_top">18dp</dimen> <dimen name="form_section_title_margin_top">18dp</dimen>
<dimen name="form_section_title_margin_bottom">8dp</dimen> <dimen name="form_section_title_margin_bottom_for_subsequent_edit_text">8dp</dimen>
<dimen name="form_labelled_value_label_text_size">15sp</dimen>
<dimen name="form_labelled_value_label_margin_top">12dp</dimen>
<dimen name="form_labelled_value_label_margin_bottom">2dp</dimen>
<dimen name="form_labelled_value_value_text_size">15sp</dimen>
<dimen name="form_labelled_value_value_margin_bottom">4dp</dimen>
<dimen name="fragment_account_transaction_margin_start_and_end">4dp</dimen> <dimen name="fragment_account_transaction_margin_start_and_end">4dp</dimen>
<dimen name="fragment_account_transaction_transactions_summary_height">24dp</dimen> <dimen name="fragment_account_transaction_transactions_summary_height">24dp</dimen>