From 15bf9452a43aa8801c22e472ba5ce2b0e66d7226 Mon Sep 17 00:00:00 2001 From: Aurelien Hubert Date: Wed, 6 Mar 2019 08:55:50 +0100 Subject: [PATCH] Refactor RowViewType --- .../android/ui/view/RowViewType.kt | 162 ++++-------------- app/src/main/res/layout/row_title_value.xml | 108 +++++------- 2 files changed, 75 insertions(+), 195 deletions(-) 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 b177327f..ce44adc0 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 @@ -25,153 +25,61 @@ interface BindableHolder { } -enum class RowViewType { - - HEADER_TITLE, - HEADER_TITLE_VALUE, - HEADER_TITLE_AMOUNT, - HEADER_TITLE_AMOUNT_BIG, - - EDIT_TEXT, - TITLE, - TITLE_ARROW, - TITLE_VALUE, - TITLE_VALUE_ACTION, - TITLE_SWITCH, - DATA, - BOTTOM_SHEET_DATA, - TITLE_GRID, - ROW_SESSION, - ROW_BUTTON, - ROW_FOLLOW_US, - STAT, - - SEPARATOR; +enum class RowViewType(var layoutRes: Int) { + + HEADER_TITLE(R.layout.row_header_title), + HEADER_TITLE_VALUE(R.layout.row_header_title_value), + HEADER_TITLE_AMOUNT(R.layout.row_header_title_amount), + HEADER_TITLE_AMOUNT_BIG(R.layout.row_header_title_amount_big), + + EDIT_TEXT(R.layout.row_header_title_value), + + TITLE(R.layout.row_title), + TITLE_VALUE(R.layout.row_title_value), + TITLE_ARROW(R.layout.row_title_arrow), + TITLE_SWITCH(R.layout.row_title_switch), + TITLE_GRID(R.layout.row_bottom_sheet_grid_title), + DATA(R.layout.row_title), + BOTTOM_SHEET_DATA(R.layout.row_bottom_sheet_title), + + ROW_SESSION(R.layout.row_history_session), + ROW_BUTTON(R.layout.row_button), + ROW_FOLLOW_US(R.layout.row_follow_us), + STAT(R.layout.row_stats_title_value), + + SEPARATOR(R.layout.row_separator), ; /** * View holder */ fun viewHolder(parent: ViewGroup): RecyclerView.ViewHolder { + + val layout = LayoutInflater.from(parent.context).inflate(layoutRes, parent, false) + return when (this) { // Header Row View Holder - HEADER_TITLE -> { - HeaderViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_header_title, parent, false - ) - ) + HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG -> { + HeaderViewHolder(layout) } - HEADER_TITLE_VALUE -> HeaderViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_header_title_value, parent, false - ) - ) - HEADER_TITLE_AMOUNT -> HeaderViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_header_title_amount, parent, false - ) - ) - HEADER_TITLE_AMOUNT_BIG -> HeaderViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_header_title_amount_big, parent, false - ) - ) // Row View Holder - TITLE -> RowViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_title, parent, false - ) - ) - TITLE_ARROW -> RowViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_title_arrow, parent, false - ) - ) - TITLE_GRID -> RowViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_bottom_sheet_grid_title, parent, false - ) - ) - DATA -> RowViewHolder( - LayoutInflater.from(parent.context).inflate(R.layout.row_title, parent, false) - ) - BOTTOM_SHEET_DATA -> RowViewHolder( - LayoutInflater.from(parent.context).inflate(R.layout.row_bottom_sheet_title, parent, false) - ) - //TODO: Manage action - TITLE_VALUE_ACTION -> RowViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_title_value_action, - parent, - false - ) - ) - //TODO: Manage switch - TITLE_SWITCH -> RowViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_title_switch, - parent, - false - ) - ) - //TODO: Update layout container to ConstraintLayout and remove separator - TITLE_VALUE -> RowViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_title_value, - parent, - false - ) - ) + TITLE, TITLE_VALUE, TITLE_ARROW, TITLE_GRID, TITLE_SWITCH, DATA, BOTTOM_SHEET_DATA -> RowViewHolder(layout) // Row Session - ROW_SESSION -> RowSessionViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_history_session, - parent, - false - ) - ) + ROW_SESSION -> RowSessionViewHolder(layout) // Row Button - ROW_BUTTON -> { - RowButtonViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_button, - parent, - false - ) - ) - } + ROW_BUTTON -> RowButtonViewHolder(layout) + // Row Follow Us - ROW_FOLLOW_US -> { - RowFollowUsViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_follow_us, - parent, - false - ) - ) - } + ROW_FOLLOW_US -> RowFollowUsViewHolder(layout) // Row Stat - STAT -> StatsTitleValueViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_stats_title_value, - parent, - false - ) - ) + STAT -> StatsTitleValueViewHolder(layout) // Separator - SEPARATOR -> SeparatorViewHolder( - LayoutInflater.from(parent.context).inflate( - R.layout.row_separator, - parent, - false - ) - ) + SEPARATOR -> SeparatorViewHolder(layout) else -> throw Exception("Undefined rowViewType's holder") } diff --git a/app/src/main/res/layout/row_title_value.xml b/app/src/main/res/layout/row_title_value.xml index 98877dda..5dbfedde 100644 --- a/app/src/main/res/layout/row_title_value.xml +++ b/app/src/main/res/layout/row_title_value.xml @@ -1,78 +1,50 @@ - - + android:background="?selectableItemBackground"> - - - - - - - - - - - - - - - + app:layout_constraintStart_toStartOf="@+id/guidelineStart" + app:layout_constraintTop_toTopOf="parent" + tools:text="Title" /> + + + + - + - \ No newline at end of file +