Adds hands configuration initial commit

blinds
Laurent 5 years ago
parent 8139c9d8b3
commit 6b7eb38fc9
  1. 2
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 13
      app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt
  3. 23
      app/src/main/java/net/pokeranalytics/android/model/realm/Configuration.kt
  4. 25
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  5. 5
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatisticsFragment.kt
  6. 60
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/RealmFragment.kt
  7. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/calendar/CalendarFragment.kt
  8. 11
      app/src/main/java/net/pokeranalytics/android/ui/modules/settings/DealtHandsPerHourFragment.kt
  9. 14
      app/src/main/java/net/pokeranalytics/android/ui/view/rows/SessionPropertiesRow.kt
  10. 76
      app/src/main/res/layout/fragment_dealt_hands_config.xml
  11. 2
      app/src/main/res/values/strings.xml

@ -47,7 +47,7 @@ class PokerAnalyticsApplication : Application() {
Realm.init(this)
val realmConfiguration = RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.schemaVersion(9)
.schemaVersion(10)
.migration(PokerAnalyticsMigration())
.initialData(Seed(this))
.build()

@ -227,6 +227,18 @@ class PokerAnalyticsMigration : RealmMigration {
currentVersion++
}
// Migrate to version 10
if (currentVersion == 9) {
schema.get("Session")?.addField("handsCount", Int::class.java)
val configSchema = schema.create("Configuration")
configSchema.addField("liveDealtHandsPerHour", Int::class.java)
configSchema.addField("onlineDealtHandsPerHour", Int::class.java)
currentVersion++
}
}
override fun equals(other: Any?): Boolean {
@ -236,4 +248,5 @@ class PokerAnalyticsMigration : RealmMigration {
override fun hashCode(): Int {
return RealmMigration::javaClass.hashCode()
}
}

@ -0,0 +1,23 @@
package net.pokeranalytics.android.model.realm
import io.realm.Realm
import io.realm.RealmObject
class Configuration : RealmObject() {
companion object {
fun getConfiguration(realm: Realm): Configuration {
realm.where(Configuration::class.java).findFirst()?.let {
return it
}
return Configuration()
}
}
var liveDealtHandsPerHour: Int = 250
var onlineDealtHandsPerHour: Int = 500
}

@ -333,6 +333,13 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
// The custom fields values
var customFieldEntries: RealmList<CustomFieldEntry> = RealmList()
// The number of hands played during the sessions
var handsCount: Int? = null
set(value) {
field = value
this.computeStats()
}
fun bankrollHasBeenUpdated() {
formatBlinds()
}
@ -380,11 +387,6 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
// Stats
@Ignore
val ONLINE_PLAYER_HANDS_PER_HOUR = 500.0
@Ignore
val LIVE_PLAYER_HANDS_PER_HOUR = 250.0
/**
* The net result in big blinds
*/
@ -405,12 +407,14 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
@Ignore
var estimatedHands: Double = 0.0
get() {
this.handsCount?.let {
return it.toDouble()
}
val noh = this.numberOfHandsPerHour
val hd = this.hourlyDuration
return noh * hd
}
// DatedValue
@Ignore
@ -455,7 +459,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
val numberOfHandsPerHour: Double
get() {
val tableSize = this.tableSize ?: 9 // 9 is the default table size if null
val playerHandsPerHour = if (this.isLive) LIVE_PLAYER_HANDS_PER_HOUR else ONLINE_PLAYER_HANDS_PER_HOUR
val config = Configuration.getConfiguration(this.realm)
val playerHandsPerHour = if (this.isLive) config.liveDealtHandsPerHour else config.onlineDealtHandsPerHour
return playerHandsPerHour / tableSize.toDouble()
}
@ -982,6 +987,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
}
SessionPropertiesRow.TOURNAMENT_NAME -> tournamentName?.name ?: NULL_TEXT
SessionPropertiesRow.HANDS -> this.handHistories?.size.toString()
SessionPropertiesRow.HANDS_COUNT -> this.handsCountFormatted(context)
is CustomField -> {
customFieldEntries.find { it.customField?.id == row.id }?.let { customFieldEntry ->
return customFieldEntry.getFormattedValue(currency)
@ -992,6 +998,11 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
}
}
private fun handsCountFormatted(context: Context): String {
return this.handsCount?.toString() ?:
"${estimatedHands.toInt()} (${context.getString(R.string.estimated)})"
}
fun clearBuyinCashedOut() {
this.result?.buyin = null
this.result?.cashout = null

@ -20,6 +20,7 @@ import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.realm.ComputableResult
import net.pokeranalytics.android.model.realm.Configuration
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.ui.fragment.components.FilterableFragment
import net.pokeranalytics.android.ui.fragment.components.RealmAsyncListener
@ -68,7 +69,9 @@ class StatisticsFragment : FilterableFragment(), RealmAsyncListener {
initUI()
this.currentFilterable = FilterableType.SESSION
applyFilter()
listenRealmChanges(this, ComputableResult::class.java)
addRealmChangeListener(this, Configuration::class.java)
addRealmChangeListener(this, ComputableResult::class.java)
}
private fun initUI() {

@ -8,6 +8,7 @@ import io.realm.Realm
import io.realm.RealmModel
import io.realm.RealmResults
import kotlinx.coroutines.Dispatchers
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import timber.log.Timber
import kotlin.coroutines.CoroutineContext
@ -40,31 +41,53 @@ open class RealmFragment : BaseFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
realm = Realm.getDefaultInstance()
this.observedEntities.forEach {
val realmResults = realm.where(it).findAll()
realmResults.addChangeListener { t, _ ->
this.entitiesChanged(it, t)
}
this.observedRealmResults.add(realmResults)
}
// this.observedEntities.forEach {
// val realmResults = realm.where(it).findAll()
//
// realmResults.addChangeListener { t, _ ->
// this.entitiesChanged(it, t)
// }
//
// this.observedRealmResults.add(realmResults)
// }
return super.onCreateView(inflater, container, savedInstanceState)
}
fun listenRealmChanges(listener: RealmAsyncListener, clazz: Class<out RealmModel>) {
/**
* Get the realm instance
*/
fun getRealm(): Realm {
return this.realm
}
this.changeListener = listener
fun addRealmChangeListener(listener: RealmAsyncListener, clazz: Class<out RealmModel>) {
if (this.changeListener != null && this.changeListener != listener) {
throw PAIllegalStateException("You cannot use a different listener")
}
this.realmResults = this.realm.where(clazz).findAllAsync()
this.realmResults?.addChangeListener { t, _ ->
this.changeListener = listener
val results = this.realm.where(clazz).findAllAsync()
results.addChangeListener { t, _ ->
Timber.d("Realm changes: ${realmResults?.size}, $this")
this.changeListener?.asyncListenedEntityChange(t.realm)
}
this.observedRealmResults.add(results)
}
// fun listenRealmChanges(listener: RealmAsyncListener, clazz: Class<out RealmModel>) {
//
// this.changeListener = listener
//
// this.realmResults = this.realm.where(clazz).findAllAsync()
// this.realmResults?.addChangeListener { t, _ ->
// Timber.d("Realm changes: ${realmResults?.size}, $this")
// this.changeListener?.asyncListenedEntityChange(t.realm)
// }
//
// }
override fun onDestroyView() {
super.onDestroyView()
@ -76,17 +99,10 @@ open class RealmFragment : BaseFragment() {
this.realmResults?.removeAllChangeListeners()
}
/**
* Get the realm instance
*/
fun getRealm(): Realm {
return this.realm
}
/**
* A list of RealmModel classes to observe
*/
open val observedEntities: List<Class<out RealmModel>> = listOf()
// open val observedEntities: List<Class<out RealmModel>> = listOf()
/**
* The method called when a change happened in any RealmResults

@ -19,6 +19,7 @@ import net.pokeranalytics.android.model.Criteria
import net.pokeranalytics.android.model.combined
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.realm.ComputableResult
import net.pokeranalytics.android.model.realm.Configuration
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
@ -86,7 +87,9 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
listenRealmChanges(this, ComputableResult::class.java)
addRealmChangeListener(this, Configuration::class.java)
addRealmChangeListener(this, ComputableResult::class.java)
}
override fun onDestroyView() {

@ -0,0 +1,11 @@
package net.pokeranalytics.android.ui.modules.settings
import net.pokeranalytics.android.ui.fragment.components.BaseFragment
class DealtHandsPerHourFragment : BaseFragment() {
}

@ -40,7 +40,8 @@ enum class SessionPropertiesRow : RowRepresentable {
BREAK_TIME,
COMMENT,
HANDS;
HANDS,
HANDS_COUNT;
companion object {
/**
@ -172,6 +173,7 @@ enum class SessionPropertiesRow : RowRepresentable {
BREAK_TIME -> R.string.break_time
COMMENT -> R.string.comment
HANDS -> R.string.hands
HANDS_COUNT -> R.string.hands_count
}
}
@ -181,14 +183,15 @@ enum class SessionPropertiesRow : RowRepresentable {
NET_RESULT, PRIZE, POSITION, PLAYERS, CASHED_OUT, INITIAL_BUY_IN, BUY_IN, TIPS,
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, COMMENT,
TOURNAMENT_TYPE, TOURNAMENT_NAME, TOURNAMENT_FEATURE, HANDS,
START_DATE, END_DATE, BREAK_TIME -> RowViewType.TITLE_VALUE.ordinal
START_DATE, END_DATE, BREAK_TIME, HANDS_COUNT -> RowViewType.TITLE_VALUE.ordinal
}
}
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> BottomSheetType.NUMERIC_TEXT
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS,
PRIZE, HANDS_COUNT -> BottomSheetType.NUMERIC_TEXT
BUY_IN, TIPS -> BottomSheetType.SUM
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.LIST_GAME
@ -269,6 +272,11 @@ enum class SessionPropertiesRow : RowRepresentable {
)
)
}
HANDS_COUNT -> {
arrayListOf(
RowRepresentableEditDescriptor(inputType = InputType.TYPE_CLASS_NUMBER)
)
}
GAME -> {
val limit: Int? by map
val defaultValue: Any? by map

@ -0,0 +1,76 @@
<?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="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/liveTitle"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/liveValue"
style="@style/PokerAnalyticsTheme.TextView.RowValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ellipsize="end"
android:gravity="end"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Value" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/onlineTitle"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/liveTitle"
tools:text="Title" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/onlineValue"
style="@style/PokerAnalyticsTheme.TextView.RowValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ellipsize="end"
android:gravity="end"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/liveValue"
tools:text="Value" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/explanation"
style="@style/PokerAnalyticsTheme.TextView.RowValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ellipsize="end"
android:gravity="end"
android:maxLines="10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/onlineValue"
tools:text="Value" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -812,5 +812,7 @@
<string name="show_blog_tips">Show tips on front page</string>
<string name="blog_tips">App tips</string>
<string name="itm_ratio">ITM ratio</string>
<string name="hands_count">Hands count</string>
<string name="estimated">estimated</string>
</resources>

Loading…
Cancel
Save