From 3d45e9e10c6b71f5e1ede304fcd11db2c012b7db Mon Sep 17 00:00:00 2001 From: Aurelien Hubert Date: Thu, 21 Feb 2019 19:05:37 +0100 Subject: [PATCH] Add separator management --- .../android/model/realm/Session.kt | 2 + .../android/ui/view/RowRepresentable.kt | 17 +++++- .../android/ui/view/RowViewType.kt | 47 ++++++++++---- .../res/layout/row_header_title_value.xml | 61 +++++++++++++++++++ app/src/main/res/layout/row_separator.xml | 9 +++ app/src/main/res/layout/row_session.xml | 44 ------------- app/src/main/res/layout/row_session_view.xml | 35 ++++++++--- app/src/main/res/layout/row_title.xml | 33 ++++++---- app/src/main/res/layout/row_title_value.xml | 58 ++++++++++++++---- .../res/layout/row_title_value_action.xml | 39 ++++++++---- app/src/main/res/values/colors.xml | 1 + 11 files changed, 242 insertions(+), 104 deletions(-) create mode 100644 app/src/main/res/layout/row_header_title_value.xml create mode 100644 app/src/main/res/layout/row_separator.xml delete mode 100644 app/src/main/res/layout/row_session.xml diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt index bb582c6d..bab4effd 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt @@ -269,6 +269,8 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource override var title: String = "Change that: $creationDate" override val primaryKey: String get() = this.id + + override fun getBottomSheetData(row: RowRepresentable): ArrayList { val data = ArrayList() diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt index e8f11af6..257248b3 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt @@ -54,6 +54,11 @@ interface RowRepresentable : Localizable { get() { return null } + + val needSeparator: Boolean + get() { + return false + } } enum class SessionRow : RowRepresentable { @@ -110,6 +115,14 @@ enum class SessionRow : RowRepresentable { } } + override val needSeparator: Boolean + get() { + return when (this) { + TIPS -> true + else -> false + } + } + override val resId: Int? get() { return when (this) { @@ -137,7 +150,7 @@ enum class SessionRow : RowRepresentable { override val viewType: Int get() { return when (this) { - DURATION, NET_HOURLY_RATE, BANKROLL_VARIATION, + DURATION, NET_HOURLY_RATE, BANKROLL_VARIATION -> RowViewType.HEADER_TITLE_VALUE.ordinal CASHED_OUT, BUY_IN, TIPS, GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, COMMENT, START_DATE, END_DATE, BREAK_TIME -> RowViewType.TITLE_VALUE.ordinal } @@ -259,7 +272,7 @@ enum class SettingRow : RowRepresentable { override val resId: Int? get() { - this.relatedResultsRepresentable?. let { + this.relatedResultsRepresentable?.let { return it.resId } ?: run { return super.resId diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt index b5f8e226..73bf2d22 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt @@ -4,6 +4,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView +import kotlinx.android.synthetic.main.row_header_title_value.view.* +import kotlinx.android.synthetic.main.row_title.view.* +import kotlinx.android.synthetic.main.row_title_value.view.* import kotlinx.android.synthetic.main.row_title_value_action.view.* import net.pokeranalytics.android.R import net.pokeranalytics.android.ui.adapter.components.RowRepresentableDataSource @@ -19,6 +22,7 @@ interface BindableHolder { enum class RowViewType { HEADER, + HEADER_TITLE_VALUE, EDIT_TEXT, TITLE, TITLE_VALUE, @@ -33,38 +37,50 @@ enum class RowViewType { inner class TitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) { - itemView.title.text = row.localizedTitle(itemView.context) - itemView.container.setOnClickListener(listener) + itemView.rowTitle_title.text = row.localizedTitle(itemView.context) + itemView.rowTitle_container.setOnClickListener(listener) } } - inner class TitleValueViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), + inner class HeaderTitleValueViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) { - itemView.title.text = row.localizedTitle(itemView.context) + itemView.rowHeaderTitleValue_title.text = row.localizedTitle(itemView.context) + rowRepresentableDataSource?.let { + itemView.rowHeaderTitleValue_value.text = it.stringForRow(row) + } + itemView.rowHeaderTitleValue_container.setOnClickListener(listener) + itemView.rowHeaderTitleValue_separator.visibility = if (row.needSeparator) View.VISIBLE else View.GONE + } + } + inner class TitleValueViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), + BindableHolder { + override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) { + itemView.rowTitleValue_title.text = row.localizedTitle(itemView.context) rowRepresentableDataSource?.let { - itemView.value.text = it.stringForRow(row) + itemView.rowTitleValue_value.text = it.stringForRow(row) } - itemView.container.setOnClickListener(listener) + itemView.rowTitleValue_container.setOnClickListener(listener) + itemView.rowTitleValue_separator.visibility = if (row.needSeparator) View.VISIBLE else View.GONE } } inner class TitleValueActionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) { - itemView.title.text = row.localizedTitle(itemView.context) + itemView.rowTitleValueAction_title.text = row.localizedTitle(itemView.context) rowRepresentableDataSource?.let { rowDelegate -> val value = rowDelegate.stringForRow(row) - itemView.value.text = value - itemView.action.visibility = if (value == "--") View.GONE else View.VISIBLE + itemView.rowTitleValueAction_value.text = value + itemView.rowTitleValueAction_action.visibility = if (value == "--") View.GONE else View.VISIBLE rowDelegate.actionIconForRow(row)?.let {icon -> - itemView.action.setImageResource(icon) + itemView.rowTitleValueAction_action.setImageResource(icon) } } - itemView.container.setOnClickListener(listener) - itemView.action.setOnClickListener(actionListener) + itemView.rowTitleValueAction_container.setOnClickListener(listener) + itemView.rowTitleValueAction_action.setOnClickListener(actionListener) } } @@ -78,6 +94,13 @@ enum class RowViewType { false ) ) + HEADER_TITLE_VALUE -> HeaderTitleValueViewHolder( + LayoutInflater.from(parent.context).inflate( + R.layout.row_header_title_value, + parent, + false + ) + ) TITLE_VALUE -> TitleValueViewHolder( LayoutInflater.from(parent.context).inflate( R.layout.row_title_value, diff --git a/app/src/main/res/layout/row_header_title_value.xml b/app/src/main/res/layout/row_header_title_value.xml new file mode 100644 index 00000000..9bfe9193 --- /dev/null +++ b/app/src/main/res/layout/row_header_title_value.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_separator.xml b/app/src/main/res/layout/row_separator.xml new file mode 100644 index 00000000..3f053c35 --- /dev/null +++ b/app/src/main/res/layout/row_separator.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_session.xml b/app/src/main/res/layout/row_session.xml deleted file mode 100644 index 079f9c7f..00000000 --- a/app/src/main/res/layout/row_session.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/row_session_view.xml b/app/src/main/res/layout/row_session_view.xml index e7bfb5b1..9abbfcf9 100644 --- a/app/src/main/res/layout/row_session_view.xml +++ b/app/src/main/res/layout/row_session_view.xml @@ -4,19 +4,19 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?selectableItemBackground" - android:padding="16dp"> + android:background="?selectableItemBackground"> @@ -65,9 +68,9 @@ android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:orientation="vertical" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toBottomOf="@+id/gameInfo" app:layout_constraintEnd_toStartOf="@+id/nextArrow" - app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toTopOf="@+id/gameType"> + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_title.xml b/app/src/main/res/layout/row_title.xml index 0f648782..a4d6a82d 100644 --- a/app/src/main/res/layout/row_title.xml +++ b/app/src/main/res/layout/row_title.xml @@ -2,25 +2,36 @@ + android:background="?selectableItemBackground"> + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_title_value.xml b/app/src/main/res/layout/row_title_value.xml index 80517a70..4fafdc53 100644 --- a/app/src/main/res/layout/row_title_value.xml +++ b/app/src/main/res/layout/row_title_value.xml @@ -2,39 +2,71 @@ + android:background="?selectableItemBackground"> + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_title_value_action.xml b/app/src/main/res/layout/row_title_value_action.xml index b27e805d..36e793aa 100644 --- a/app/src/main/res/layout/row_title_value_action.xml +++ b/app/src/main/res/layout/row_title_value_action.xml @@ -2,15 +2,13 @@ + android:background="?selectableItemBackground"> + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 59fdae84..f5d08d56 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -23,6 +23,7 @@ #101911 #151c15 #1b1f1b + #141714 #3b4a39 #57815a