parent
42001c8f0d
commit
df13c43e3d
@ -0,0 +1,164 @@ |
||||
package net.pokeranalytics.android.ui.adapter |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.appcompat.widget.AppCompatTextView |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import io.realm.RealmResults |
||||
import kotlinx.android.synthetic.main.row_hand_history.view.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
||||
import net.pokeranalytics.android.ui.view.BindableHolder |
||||
import net.pokeranalytics.android.ui.view.RowViewType |
||||
import net.pokeranalytics.android.util.NULL_TEXT |
||||
import net.pokeranalytics.android.util.extensions.getMonthAndYear |
||||
import java.util.* |
||||
import kotlin.collections.HashMap |
||||
|
||||
|
||||
/** |
||||
* An adapter capable of displaying a list of RowRepresentables |
||||
* @param dataSource the datasource providing rows |
||||
* @param delegate the delegate, notified of UI actions |
||||
*/ |
||||
class FeedHandHistoryRowRepresentableAdapter( |
||||
var delegate: RowRepresentableDelegate? = null, |
||||
var realmHandHistories: RealmResults<HandHistory>, |
||||
var distinctHandHistoryHeaders: RealmResults<HandHistory> |
||||
) : |
||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||
|
||||
private var headersPositions = HashMap<Int, Date?>() |
||||
private lateinit var sortedHeaders: SortedMap<Int, Date?> |
||||
|
||||
init { |
||||
refreshData() |
||||
} |
||||
|
||||
inner class RowHandHistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), |
||||
BindableHolder { |
||||
|
||||
fun bind(position: Int, row: HandHistory?, adapter: FeedHandHistoryRowRepresentableAdapter) { |
||||
|
||||
itemView.handHistoryRow.setData(row as HandHistory) |
||||
val listener = View.OnClickListener { |
||||
adapter.delegate?.onRowSelected(position, row) |
||||
} |
||||
itemView.handHistoryRow.setOnClickListener(listener) |
||||
} |
||||
|
||||
} |
||||
/** |
||||
* Display a header |
||||
*/ |
||||
inner class HeaderTitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), |
||||
BindableHolder { |
||||
fun bind(title: String) { |
||||
// Title |
||||
itemView.findViewById<AppCompatTextView>(R.id.title)?.let { |
||||
it.text = title |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||
return if (viewType == RowViewType.ROW_TRANSACTION.ordinal) { |
||||
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_transaction, parent, false) |
||||
RowHandHistoryViewHolder(layout) |
||||
} else { |
||||
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_header_title, parent, false) |
||||
HeaderTitleViewHolder(layout) |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
override fun getItemViewType(position: Int): Int { |
||||
return if (sortedHeaders.containsKey(position)) { |
||||
RowViewType.HEADER_TITLE.ordinal |
||||
} else { |
||||
1 |
||||
// RowViewType.ROW_HAND_HISTORY.ordinal |
||||
} |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return realmHandHistories.size + distinctHandHistoryHeaders.size |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||
if (holder is RowHandHistoryViewHolder) { |
||||
holder.bind(position, getHandHistoryForPosition(position), this) |
||||
} else if (holder is HeaderTitleViewHolder) { |
||||
holder.bind(getHeaderForPosition(position)) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Return the header |
||||
*/ |
||||
private fun getHeaderForPosition(position: Int): String { |
||||
if (sortedHeaders.containsKey(position)) { |
||||
val realmHeaderPosition = sortedHeaders.keys.indexOf(position) |
||||
return distinctHandHistoryHeaders[realmHeaderPosition]?.date?.getMonthAndYear() ?: "" |
||||
} |
||||
return NULL_TEXT |
||||
} |
||||
|
||||
/** |
||||
* Get real index |
||||
*/ |
||||
private fun getHandHistoryForPosition(position: Int): HandHistory? { |
||||
|
||||
// Row position |
||||
var headersBefore = 0 |
||||
for (key in sortedHeaders.keys) { |
||||
if (position > key) { |
||||
headersBefore++ |
||||
} else { |
||||
break |
||||
} |
||||
} |
||||
|
||||
return realmHandHistories[position - headersBefore] |
||||
} |
||||
|
||||
/** |
||||
* Refresh headers positions |
||||
*/ |
||||
fun refreshData() { |
||||
|
||||
headersPositions.clear() |
||||
|
||||
var previousYear = Int.MAX_VALUE |
||||
var previousMonth = Int.MAX_VALUE |
||||
|
||||
val calendar = Calendar.getInstance() |
||||
|
||||
// Add headers if the date doesn't exist yet |
||||
for ((index, handHistory) in realmHandHistories.withIndex()) { |
||||
calendar.time = handHistory.date |
||||
if (checkHeaderCondition(calendar, previousYear, previousMonth)) { |
||||
headersPositions[index + headersPositions.size] = handHistory.date |
||||
previousYear = calendar.get(Calendar.YEAR) |
||||
previousMonth = calendar.get(Calendar.MONTH) |
||||
} |
||||
} |
||||
|
||||
sortedHeaders = headersPositions.toSortedMap() |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Check if we need to add a header |
||||
* Can be change to manage different condition |
||||
*/ |
||||
private fun checkHeaderCondition(currentCalendar: Calendar, previousYear: Int, previousMonth: Int): Boolean { |
||||
return currentCalendar.get(Calendar.YEAR) == previousYear && currentCalendar.get(Calendar.MONTH) < previousMonth || (currentCalendar.get( |
||||
Calendar.YEAR) < previousYear) |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,68 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import android.content.Context |
||||
import android.util.AttributeSet |
||||
import android.view.LayoutInflater |
||||
import android.widget.FrameLayout |
||||
import androidx.constraintlayout.widget.ConstraintLayout |
||||
import kotlinx.android.synthetic.main.row_transaction_view.view.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
||||
import net.pokeranalytics.android.util.extensions.getDayNumber |
||||
import net.pokeranalytics.android.util.extensions.getShortDayName |
||||
|
||||
/** |
||||
* Display a transaction row |
||||
*/ |
||||
class HandHistoryRowView : FrameLayout { |
||||
|
||||
private lateinit var rowHandHistory: 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 |
||||
*/ |
||||
private fun init() { |
||||
val layoutInflater = LayoutInflater.from(context) |
||||
rowHandHistory = layoutInflater.inflate(R.layout.row_hand_history_view, this, false) as ConstraintLayout |
||||
val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT) |
||||
addView(rowHandHistory, layoutParams) |
||||
} |
||||
|
||||
/** |
||||
* Set the session data to the view |
||||
*/ |
||||
fun setData(handHistory: HandHistory) { |
||||
|
||||
// Date |
||||
rowHandHistory.transactionDateDay.text = handHistory.date.getShortDayName() |
||||
rowHandHistory.transactionDateNumber.text = handHistory.date.getDayNumber() |
||||
|
||||
// Title / Game type |
||||
// var title = handHistory.type?.name ?: "" + " " + handHistory.comment |
||||
// var subtitle = handHistory.bankroll?.name |
||||
// |
||||
// rowHandHistory.transactionTitle.text = title |
||||
// rowHandHistory.transactionSubtitle.text = subtitle |
||||
// |
||||
// Amount |
||||
// val formattedStat = ComputedStat(Stat.NET_RESULT, handHistory.amount, currency = handHistory.bankroll?.utilCurrency).format() |
||||
// rowHandHistory.transactionAmount.setTextFormat(formattedStat, context) |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
package net.pokeranalytics.android.ui.view.holder |
||||
|
||||
import android.view.View |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import kotlinx.android.synthetic.main.row_hand_history.view.* |
||||
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
||||
import net.pokeranalytics.android.ui.adapter.FeedHandHistoryRowRepresentableAdapter |
||||
import net.pokeranalytics.android.ui.view.BindableHolder |
||||
|
||||
class RowHandHistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), |
||||
BindableHolder { |
||||
|
||||
fun bind(position: Int, row: HandHistory?, adapter: FeedHandHistoryRowRepresentableAdapter) { |
||||
|
||||
itemView.handHistoryRow.setData(row as HandHistory) |
||||
val listener = View.OnClickListener { |
||||
adapter.delegate?.onRowSelected(position, row) |
||||
} |
||||
itemView.handHistoryRow.setOnClickListener(listener) |
||||
} |
||||
|
||||
} |
||||
@ -1,6 +1,42 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:orientation="vertical" android:layout_width="match_parent" |
||||
android:orientation="horizontal" android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<com.google.android.material.button.MaterialButton |
||||
android:id="@+id/playerButton" |
||||
style="@style/PokerAnalyticsTheme.Button" |
||||
android:layout_width="44dp" |
||||
android:layout_height="44dp" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp"/> |
||||
|
||||
<com.google.android.material.button.MaterialButton |
||||
android:id="@+id/positionButton" |
||||
style="@style/PokerAnalyticsTheme.Button" |
||||
android:layout_width="44dp" |
||||
android:layout_height="44dp" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp"/> |
||||
|
||||
<com.google.android.material.button.MaterialButton |
||||
android:id="@+id/actionButton" |
||||
style="@style/PokerAnalyticsTheme.Button" |
||||
android:layout_width="120dp" |
||||
android:layout_height="44dp" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="16dp"/> |
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText |
||||
android:id="@+id/amountEditText" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_marginBottom="16dp" |
||||
android:imeOptions="actionDone" |
||||
android:maxLines="1" /> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,37 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:orientation="horizontal" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText |
||||
android:id="@+id/flopEditText" |
||||
android:layout_width="180dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginBottom="16dp" |
||||
android:imeOptions="actionDone" |
||||
android:maxLines="1" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText |
||||
android:id="@+id/turnEditText" |
||||
android:layout_width="60dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginBottom="16dp" |
||||
android:imeOptions="actionDone" |
||||
android:maxLines="1" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText |
||||
android:id="@+id/riverEditText" |
||||
android:layout_width="60dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginBottom="16dp" |
||||
android:imeOptions="actionDone" |
||||
android:maxLines="1" /> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,12 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
|
||||
<net.pokeranalytics.android.ui.view.HandHistoryRowView |
||||
android:id="@+id/handHistoryRow" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" /> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,108 @@ |
||||
<?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="56dp" |
||||
android:background="?selectableItemBackground"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/transactionDateDay" |
||||
style="@style/PokerAnalyticsTheme.TextView.SessionRow.Date" |
||||
android:layout_width="32dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
android:gravity="center" |
||||
android:textAllCaps="true" |
||||
app:fontFamily="@font/roboto_mono_medium" |
||||
app:layout_constraintBottom_toTopOf="@+id/transactionDateNumber" |
||||
app:layout_constraintStart_toStartOf="@+id/guidelineStart" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:layout_constraintVertical_chainStyle="packed" |
||||
tools:text="THU" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/transactionDateNumber" |
||||
style="@style/PokerAnalyticsTheme.TextView.SessionRow.DateNumber" |
||||
android:layout_width="32dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="8dp" |
||||
android:gravity="center" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="@+id/transactionDateDay" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintStart_toStartOf="@+id/transactionDateDay" |
||||
app:layout_constraintTop_toBottomOf="@+id/transactionDateDay" |
||||
tools:text="21" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/transactionTitle" |
||||
style="@style/PokerAnalyticsTheme.TextView.SessionRow.Title" |
||||
android:layout_width="0dp" |
||||
android:layout_height="24dp" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
app:layout_constraintBottom_toTopOf="@+id/transactionSubtitle" |
||||
app:layout_constraintEnd_toStartOf="@+id/transactionAmount" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintStart_toEndOf="@+id/transactionDateDay" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:layout_constraintVertical_chainStyle="packed" |
||||
tools:text="Deposit: Live" /> |
||||
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/transactionSubtitle" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="8dp" |
||||
android:layout_marginBottom="2dp" |
||||
android:ellipsize="end" |
||||
android:fontFamily="@font/roboto" |
||||
android:maxLines="1" |
||||
android:textColor="@color/kaki_lighter" |
||||
android:textSize="12sp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toStartOf="@+id/transactionAmount" |
||||
app:layout_constraintStart_toStartOf="@+id/transactionTitle" |
||||
app:layout_constraintTop_toBottomOf="@+id/transactionTitle" |
||||
tools:text="Live" |
||||
tools:visibility="visible" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/transactionAmount" |
||||
style="@style/PokerAnalyticsTheme.TextView.SessionRow.Result" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="8dp" |
||||
app:layout_constraintBottom_toBottomOf="@+id/transactionSubtitle" |
||||
app:layout_constraintEnd_toStartOf="@+id/nextArrow" |
||||
app:layout_constraintTop_toTopOf="@+id/transactionTitle" |
||||
tools:text="$ 1000" /> |
||||
|
||||
<ImageView |
||||
android:id="@+id/nextArrow" |
||||
android:layout_width="24dp" |
||||
android:layout_height="24dp" |
||||
android:src="@drawable/ic_arrow_right" |
||||
android:tint="@color/gray_light" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="@+id/guidelineEnd" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
|
||||
<androidx.constraintlayout.widget.Guideline |
||||
android:id="@+id/guidelineStart" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
app:layout_constraintGuide_begin="16dp" /> |
||||
|
||||
<androidx.constraintlayout.widget.Guideline |
||||
android:id="@+id/guidelineEnd" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
app:layout_constraintGuide_end="8dp" /> |
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
@ -1,6 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:orientation="vertical" android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue