Refactor RowViewType

feature/top10
Aurelien Hubert 7 years ago
parent 0aaa398229
commit 15bf9452a4
  1. 164
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  2. 32
      app/src/main/res/layout/row_title_value.xml

@ -25,153 +25,61 @@ interface BindableHolder {
} }
enum class RowViewType { enum class RowViewType(var layoutRes: Int) {
HEADER_TITLE, HEADER_TITLE(R.layout.row_header_title),
HEADER_TITLE_VALUE, HEADER_TITLE_VALUE(R.layout.row_header_title_value),
HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT(R.layout.row_header_title_amount),
HEADER_TITLE_AMOUNT_BIG, HEADER_TITLE_AMOUNT_BIG(R.layout.row_header_title_amount_big),
EDIT_TEXT, EDIT_TEXT(R.layout.row_header_title_value),
TITLE,
TITLE_ARROW, TITLE(R.layout.row_title),
TITLE_VALUE, TITLE_VALUE(R.layout.row_title_value),
TITLE_VALUE_ACTION, TITLE_ARROW(R.layout.row_title_arrow),
TITLE_SWITCH, TITLE_SWITCH(R.layout.row_title_switch),
DATA, TITLE_GRID(R.layout.row_bottom_sheet_grid_title),
BOTTOM_SHEET_DATA, DATA(R.layout.row_title),
TITLE_GRID, BOTTOM_SHEET_DATA(R.layout.row_bottom_sheet_title),
ROW_SESSION,
ROW_BUTTON, ROW_SESSION(R.layout.row_history_session),
ROW_FOLLOW_US, ROW_BUTTON(R.layout.row_button),
STAT, ROW_FOLLOW_US(R.layout.row_follow_us),
STAT(R.layout.row_stats_title_value),
SEPARATOR;
SEPARATOR(R.layout.row_separator), ;
/** /**
* View holder * View holder
*/ */
fun viewHolder(parent: ViewGroup): RecyclerView.ViewHolder { fun viewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
val layout = LayoutInflater.from(parent.context).inflate(layoutRes, parent, false)
return when (this) { return when (this) {
// Header Row View Holder // Header Row View Holder
HEADER_TITLE -> { HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG -> {
HeaderViewHolder( HeaderViewHolder(layout)
LayoutInflater.from(parent.context).inflate( }
R.layout.row_header_title, parent, false
)
)
}
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 // Row View Holder
TITLE -> RowViewHolder( TITLE, TITLE_VALUE, TITLE_ARROW, TITLE_GRID, TITLE_SWITCH, DATA, BOTTOM_SHEET_DATA -> RowViewHolder(layout)
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
)
)
// Row Session // Row Session
ROW_SESSION -> RowSessionViewHolder( ROW_SESSION -> RowSessionViewHolder(layout)
LayoutInflater.from(parent.context).inflate(
R.layout.row_history_session,
parent,
false
)
)
// Row Button // Row Button
ROW_BUTTON -> { ROW_BUTTON -> RowButtonViewHolder(layout)
RowButtonViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.row_button,
parent,
false
)
)
}
// Row Follow Us // Row Follow Us
ROW_FOLLOW_US -> { ROW_FOLLOW_US -> RowFollowUsViewHolder(layout)
RowFollowUsViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.row_follow_us,
parent,
false
)
)
}
// Row Stat // Row Stat
STAT -> StatsTitleValueViewHolder( STAT -> StatsTitleValueViewHolder(layout)
LayoutInflater.from(parent.context).inflate(
R.layout.row_stats_title_value,
parent,
false
)
)
// Separator // Separator
SEPARATOR -> SeparatorViewHolder( SEPARATOR -> SeparatorViewHolder(layout)
LayoutInflater.from(parent.context).inflate(
R.layout.row_separator,
parent,
false
)
)
else -> throw Exception("Undefined rowViewType's holder") else -> throw Exception("Undefined rowViewType's holder")
} }

@ -1,15 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container" android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"> android:background="?selectableItemBackground">
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
@ -53,26 +47,4 @@
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintGuide_end="16dp" /> app:layout_constraintGuide_end="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
android:id="@+id/rowTitleValue.separator"
android:layout_width="match_parent"
android:layout_height="16dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="gone">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/kaki" />
</FrameLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

Loading…
Cancel
Save