Improve Game selection

feature/top10
Aurelien Hubert 7 years ago
parent 53fcd28c78
commit a3b00a0726
  1. 3
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 26
      app/src/main/java/net/pokeranalytics/android/model/Limit.kt
  3. 27
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  4. 31
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListGameFragment.kt
  5. 13
      app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
  6. 5
      app/src/main/res/color/chips_background_states.xml
  7. 62
      app/src/main/res/layout/bottom_sheet_game_list.xml
  8. 4
      app/src/main/res/layout/fragment_session.xml
  9. 9
      app/src/main/res/values/styles.xml

@ -5,6 +5,7 @@ import io.realm.Realm
import io.realm.RealmConfiguration
import io.realm.RealmResults
import io.realm.kotlin.where
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.PokerAnalyticsLogs
@ -52,6 +53,8 @@ class PokerAnalyticsApplication : Application() {
*/
}
Limit.init(this)
if (BuildConfig.DEBUG) {
// Logs
Timber.plant(PokerAnalyticsLogs())

@ -0,0 +1,26 @@
package net.pokeranalytics.android.model
import android.content.Context
import net.pokeranalytics.android.R
class Limit {
companion object {
private val values = ArrayList<String>()
fun init(context: Context) {
values.clear()
values.addAll(context.resources.getStringArray(R.array.limit_short_name))
}
/**
* Get a limit name
*/
fun get(index: Int) : String? {
if (index >= 0 && index < values.size) {
return values[index]
}
return ""
}
}
}

@ -8,6 +8,7 @@ import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.ObjectSavable
import net.pokeranalytics.android.model.extensions.SessionState
@ -21,6 +22,7 @@ import net.pokeranalytics.android.util.getDuration
import net.pokeranalytics.android.util.round
import net.pokeranalytics.android.util.short
import net.pokeranalytics.android.util.toCurrency
import timber.log.Timber
import java.util.*
import kotlin.collections.ArrayList
@ -198,13 +200,13 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
*/
fun getGameTitle(): String {
var gameTitle = ""
if (limit != null) {
gameTitle += limit
limit?.let {
gameTitle += Limit.get(it) + " "
}
if (game != null) {
gameTitle += game?.name
}
return gameTitle
return if (gameTitle.isNotBlank()) gameTitle else "--"
}
companion object {
@ -272,7 +274,7 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
return when (row) {
SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.BLINDS -> if (cgSmallBlind != null && cgBigBlind != null) "$cgSmallBlind / $cgBigBlind" else "--"
SessionRow.GAME -> game?.name ?: "--"
SessionRow.GAME -> getGameTitle()
SessionRow.LOCATION -> location?.name ?: "--"
SessionRow.BANKROLL -> bankroll?.name ?: "--"
SessionRow.TABLE_SIZE -> tableSize?.toString() ?: "--"
@ -370,7 +372,22 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
result = localResult
}
SessionRow.TABLE_SIZE -> tableSize = value as Int?
SessionRow.GAME -> game = value as Game?
SessionRow.GAME -> {
if (value is ArrayList<*>) {
Timber.d("${value[0]}")
Timber.d("${value[1]}")
limit = try {
(value[0] as Int?)
} catch (e: Exception) {
null
}
game = try {
(value[1] as Game?)
} catch (e: Exception) {
null
}
}
}
SessionRow.BANKROLL -> bankroll = value as Bankroll?
SessionRow.LOCATION -> location = value as Location?
SessionRow.COMMENT -> comment = value as String? ?: ""

@ -4,22 +4,24 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.chip.Chip
import io.realm.RealmResults
import kotlinx.android.synthetic.main.bottom_sheet_game_list.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.adapter.LimitTypesAdapter
import net.pokeranalytics.android.ui.adapter.components.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.components.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.components.RowRepresentableDelegate
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import timber.log.Timber
class BottomSheetListGameFragment : BottomSheetFragment(), RowRepresentableDataSource, RowRepresentableDelegate {
private var realmData: RealmResults<*>? = null
private lateinit var dataAdapter: RowRepresentableAdapter
private val values = ArrayList<Any?>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -32,6 +34,9 @@ class BottomSheetListGameFragment : BottomSheetFragment(), RowRepresentableDataS
dataAdapter.notifyDataSetChanged()
}
override fun getValue(): Any? {
return values
}
override fun rowRepresentableForPosition(position: Int): RowRepresentable {
realmData?.let {
@ -62,7 +67,8 @@ class BottomSheetListGameFragment : BottomSheetFragment(), RowRepresentableDataS
realmData?.let {
val selectedData = it[position]
selectedData?.let { data ->
bottomSheetDelegate.setValue(data, row)
values[1] = data
bottomSheetDelegate.setValue(values, row)
dismiss()
}
}
@ -86,18 +92,23 @@ class BottomSheetListGameFragment : BottomSheetFragment(), RowRepresentableDataS
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_game_list, view?.bottomSheetContainer, true)
values.add(0, null)
values.add(1, null)
val limits = ArrayList<String>()
limits.addAll(resources.getStringArray(R.array.limit_short_name))
chipGroup.removeAllViews()
for ((index, limit) in limits.withIndex()) {
val chip = Chip(requireContext())
chip.text = limit
chip.id = index
chipGroup.addView(chip)
}
val viewManager1 = LinearLayoutManager(requireContext())
val gameDataAdapter1 = LimitTypesAdapter(limits)
recyclerView1.apply {
setHasFixedSize(true)
layoutManager = viewManager1
adapter = gameDataAdapter1
isNestedScrollingEnabled = false
chipGroup.setOnCheckedChangeListener { chipGroup, i ->
Timber.d("Chip selected: $i")
values[0] = i
}

@ -10,6 +10,7 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.getDayNumber
import net.pokeranalytics.android.util.getShortDayName
import net.pokeranalytics.android.util.toCurrency
class SessionRowView : FrameLayout {
@ -55,17 +56,9 @@ class SessionRowView : FrameLayout {
rowHistorySession.dateDay.text = session.creationDate.getShortDayName()
rowHistorySession.dateNumber.text = session.creationDate.getDayNumber()
// TODO
var gameTitle = session.getGameTitle()
if (gameTitle.isEmpty()) {
gameTitle = "Game title here"
}
rowHistorySession.gameType.text = gameTitle
rowHistorySession.gameType.text = session.getGameTitle()
rowHistorySession.gameInfo.text = session.getDuration(context)
rowHistorySession.gameResult.text = "$ 0"
rowHistorySession.gameResult.text = session.result?.netResult?.toCurrency() ?: "$0"
}

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_checked="true" />
<item android:color="@android:color/transparent" />
</selector>

@ -2,16 +2,62 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="240dp"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="80dp"
<FrameLayout
android:id="@+id/chips"
android:layout_width="0dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
app:chipSpacingHorizontal="16dp"
app:singleSelection="true">
<!--
<com.google.android.material.chip.Chip
android:id="@+id/chip1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NL" />
<com.google.android.material.chip.Chip
android:id="@+id/chip2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PL" />
<com.google.android.material.chip.Chip
android:id="@+id/chip3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FL" />
<com.google.android.material.chip.Chip
android:id="@+id/chip4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SL" />
<com.google.android.material.chip.Chip
android:id="@+id/chip5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ML" />
-->
</com.google.android.material.chip.ChipGroup>
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView2"
@ -19,7 +65,7 @@
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/recyclerView1"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chips" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -47,7 +47,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:text="2h33"
android:text="-"
android:textSize="24sp"
app:fontFamily="@font/roboto_bold"
app:layout_constraintBottom_toBottomOf="parent"
@ -75,7 +75,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="$ 325"
android:text="-"
android:textColor="@color/green"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"

@ -15,6 +15,7 @@
<item name="editTextStyle">@style/PokerAnalyticsTheme.EditText</item>
<item name="android:textViewStyle">@style/PokerAnalyticsTheme.TextView</item>
<item name="alertDialogTheme">@style/PokerAnalyticsTheme.AlertDialog</item>
<item name="chipStyle">@style/PokerAnalyticsTheme.Chip</item>
</style>
@ -159,5 +160,13 @@
<item name="android:fontFamily">@font/roboto_bold</item>
</style>
<!-- Chip -->
<style name="PokerAnalyticsTheme.Chip" parent="Widget.MaterialComponents.Chip.Choice">
<item name="chipBackgroundColor">@color/chips_background_states</item>
<item name="android:textColor">@color/white</item>
<item name="chipStrokeColor">@color/colorAccent</item>
<item name="chipStrokeWidth">1dp</item>
</style>
</resources>

Loading…
Cancel
Save