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 {
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_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
)
)
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG -> {
HeaderViewHolder(layout)
}
// 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")
}

@ -1,15 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground">
<androidx.appcompat.widget.AppCompatTextView
@ -53,26 +47,4 @@
android:orientation="vertical"
app:layout_constraintGuide_end="16dp" />
</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>
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save