From b9a5fc5ba698fc6139236f2e7bfbf5c377843540 Mon Sep 17 00:00:00 2001 From: Aurelien Hubert Date: Thu, 14 Mar 2019 18:01:40 +0100 Subject: [PATCH] Add TransactionRow class --- .../view/rowrepresentable/TransactionRow.kt | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt new file mode 100644 index 00000000..d0170214 --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt @@ -0,0 +1,88 @@ +package net.pokeranalytics.android.ui.view.rowrepresentable + +import android.text.InputType +import io.realm.RealmResults +import net.pokeranalytics.android.R +import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType +import net.pokeranalytics.android.ui.view.DefaultEditable +import net.pokeranalytics.android.ui.view.RowRepresentable +import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor +import net.pokeranalytics.android.ui.view.RowViewType +import timber.log.Timber + + +enum class TransactionRow : RowRepresentable, DefaultEditable { + BANKROLL, + TYPE, + AMOUNT, + COMMENT, + DATE; + + override val resId: Int? + get() { + return when (this) { + BANKROLL -> R.string.bankroll + TYPE -> R.string.type + AMOUNT -> R.string.amount + COMMENT -> R.string.comment + DATE -> R.string.date + } + } + + override val viewType: Int + get() { + return when (this) { + BANKROLL -> RowViewType.TITLE_VALUE.ordinal + TYPE -> RowViewType.TITLE_VALUE.ordinal + AMOUNT -> RowViewType.TITLE_VALUE.ordinal + COMMENT -> RowViewType.TITLE_VALUE.ordinal + DATE -> RowViewType.TITLE_VALUE.ordinal + } + } + + override val bottomSheetType: BottomSheetType + get() { + return when (this) { + BANKROLL -> BottomSheetType.LIST + TYPE -> BottomSheetType.LIST + AMOUNT -> BottomSheetType.EDIT_TEXT + COMMENT -> BottomSheetType.EDIT_TEXT_MULTI_LINES + DATE -> BottomSheetType.NONE + } + } + + override fun editingDescriptors(map: Map): ArrayList? { + Timber.d("editingDescriptors") + return when (this) { + BANKROLL -> { + val defaultValue : Any? by map + val data : RealmResults<*>? by map + arrayListOf( + RowRepresentableEditDescriptor(defaultValue, data = data) + ) + } + TYPE -> { + val defaultValue : Any? by map + val data : RealmResults<*>? by map + arrayListOf( + RowRepresentableEditDescriptor(defaultValue, data = data) + ) + } + AMOUNT -> { + val defaultValue: String? by map + arrayListOf( + RowRepresentableEditDescriptor( + defaultValue, + inputType = InputType.TYPE_CLASS_NUMBER + or InputType.TYPE_NUMBER_FLAG_DECIMAL + or InputType.TYPE_NUMBER_FLAG_SIGNED + )) + } + COMMENT -> { + val defaultValue : String? by map + arrayListOf(RowRepresentableEditDescriptor(defaultValue, R.string.comment)) + } + else -> super.editingDescriptors(map) + } + } +} \ No newline at end of file