parent
8b3e1d7bd0
commit
79d02078c6
@ -0,0 +1,61 @@ |
||||
package net.pokeranalytics.android.ui.adapter |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import io.realm.RealmResults |
||||
import kotlinx.android.synthetic.main.row_history_session.view.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.Session |
||||
import net.pokeranalytics.android.ui.view.SessionRowView |
||||
import timber.log.Timber |
||||
|
||||
class SettingsAdapter(private var sessions: RealmResults<Session>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||
|
||||
companion object { |
||||
const val ROW_SESSION: Int = 100 |
||||
const val ROW_TOURNAMENT: Int = 101 |
||||
const val ROW_HAND: Int = 102 |
||||
const val ROW_TRANSACTION: Int = 103 |
||||
} |
||||
|
||||
var onClickOnSession: ((position: Int, session: Session) -> Unit)? = null |
||||
|
||||
inner class RowSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||
|
||||
fun bind(session: Session?) { |
||||
Timber.d("Bind session") |
||||
|
||||
session?.let { |
||||
itemView.sessionRow.setData(session) |
||||
itemView.sessionRow.setOnClickListener { |
||||
onClickOnSession?.invoke(adapterPosition, session) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||
when (viewType) { |
||||
ROW_SESSION -> return RowSessionViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_history_session, parent, false)) |
||||
else -> throw IllegalStateException("Need to implement type $viewType in HistoryAdapter") |
||||
} |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||
when (getItemViewType(position)) { |
||||
ROW_SESSION -> (holder as SettingsAdapter.RowSessionViewHolder).bind(sessions.get(position)) |
||||
} |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return sessions.size |
||||
} |
||||
|
||||
override fun getItemViewType(position: Int): Int { |
||||
return ROW_SESSION |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,58 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import android.widget.FrameLayout |
||||
import android.content.Context |
||||
import android.graphics.Color |
||||
import android.util.AttributeSet |
||||
import android.view.LayoutInflater |
||||
import androidx.constraintlayout.widget.ConstraintLayout |
||||
import kotlinx.android.synthetic.main.row_session.view.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.Session |
||||
import timber.log.Timber |
||||
|
||||
|
||||
class DataRowView : FrameLayout { |
||||
|
||||
private lateinit var rowHistorySession: ConstraintLayout |
||||
|
||||
/** |
||||
* Constructors |
||||
*/ |
||||
constructor(context: Context) : super(context) { |
||||
init() |
||||
} |
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { |
||||
init() |
||||
} |
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
||||
init() |
||||
} |
||||
|
||||
/** |
||||
* Init |
||||
* |
||||
* @param attrs |
||||
*/ |
||||
private fun init() { |
||||
val layoutInflater = LayoutInflater.from(context) |
||||
rowHistorySession = layoutInflater.inflate(R.layout.row_session, this, false) as ConstraintLayout |
||||
val layoutParams = FrameLayout.LayoutParams( |
||||
FrameLayout.LayoutParams.MATCH_PARENT, |
||||
FrameLayout.LayoutParams.WRAP_CONTENT |
||||
) |
||||
|
||||
addView(rowHistorySession, layoutParams) |
||||
} |
||||
|
||||
/** |
||||
* Set the session data to the view |
||||
*/ |
||||
fun setData(session: Session) { |
||||
Timber.d("Set data: ${session.creationDate}") |
||||
rowHistorySession.date.text = session.creationDate.toString() |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,12 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"> |
||||
|
||||
<net.pokeranalytics.android.ui.view.SessionRowView |
||||
android:id="@+id/sessionRow" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" /> |
||||
|
||||
</FrameLayout> |
||||
@ -0,0 +1,25 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<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:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:padding="16dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/title" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
android:layout_marginEnd="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:textSize="20sp" |
||||
tools:text="Data Type Title" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginBottom="8dp" |
||||
app:layout_constraintBottom_toBottomOf="parent"/> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
Loading…
Reference in new issue