Merge branch 'master' of gitlab.com:stax-river/poker-analytics

feature/top10
Aurelien Hubert 7 years ago
commit 6d7f66fefd
  1. 18
      app/src/main/java/net/pokeranalytics/android/model/LiveData.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/model/interfaces/CountableUsage.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/model/interfaces/Manageable.kt
  4. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  5. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  6. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/Location.kt
  7. 32
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  8. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  9. 19
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentName.kt
  10. 19
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  11. 21
      app/src/main/java/net/pokeranalytics/android/ui/fragment/CurrenciesFragment.kt
  12. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/DataListFragment.kt
  13. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt
  14. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/HistoryFragment.kt
  15. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  16. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt

@ -40,12 +40,24 @@ enum class LiveData : Localizable {
fun setUseCount(realm: Realm, realmResults: RealmResults<*>) {
realm.executeTransaction {
realmResults.forEach { countableUsage ->
when (this) {
TOURNAMENT_FEATURE -> {
(countableUsage as CountableUsage).useCount = it.where<Session>().contains(
"tournamentFeatures.id",
countableUsage.id
).count().toInt()
}
else -> {
(countableUsage as CountableUsage).useCount = it.where<Session>().equalTo(
"${relatedEntity.simpleName.toLowerCase()}.id",
countableUsage.uniqueIdentifier()
"${relatedEntity.simpleName.decapitalize()}.id",
countableUsage.id
).count().toInt()
}
}
}
}
}
/**
@ -81,7 +93,7 @@ enum class LiveData : Localizable {
}
fun deleteData(realm: Realm, data: Manageable) {
realm.where(this.relatedEntity).equalTo("id", data.uniqueIdentifier()).findAll().deleteAllFromRealm()
realm.where(this.relatedEntity).equalTo("id", data.id).findAll().deleteAllFromRealm()
}
fun updateOrCreate(realm: Realm, primaryKey: String?): RealmObject {

@ -6,5 +6,5 @@ package net.pokeranalytics.android.model.interfaces
interface CountableUsage : Identifiable {
var useCount: Int
get() { return 0 }
set(newValue) {}
set(_) {}
}

@ -16,7 +16,7 @@ interface Identifiable {
/**
* A unique identifier getter
*/
fun uniqueIdentifier(): String
var id: String
}
/**

@ -11,6 +11,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.BankrollRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import timber.log.Timber
import java.util.*
import kotlin.collections.ArrayList
@ -22,10 +23,17 @@ open class Bankroll(name: String = "") : RealmObject(), Manageable,
var bankroll: Bankroll = Bankroll()
return bankroll
}
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(BankrollRow.values())
rows
}
}
@PrimaryKey
var id = UUID.randomUUID().toString()
override var id = UUID.randomUUID().toString()
// the name of the bankroll
var name: String = name
@ -43,17 +51,9 @@ open class Bankroll(name: String = "") : RealmObject(), Manageable,
return this.name
}
override fun uniqueIdentifier(): String {
return this.id
}
// Row Representable Datasource
override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(BankrollRow.values())
return rows
return Bankroll.rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {

@ -20,8 +20,17 @@ import kotlin.collections.ArrayList
open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable, CountableUsage {
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(GameRow.values())
rows
}
}
@PrimaryKey
var id = UUID.randomUUID().toString()
override var id = UUID.randomUUID().toString()
// The name of the game
var name: String = ""
@ -36,15 +45,8 @@ open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, R
return this.name
}
override fun uniqueIdentifier(): String {
return this.id
}
override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(GameRow.values())
return rows
return Game.rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {

@ -13,7 +13,7 @@ import java.util.*
open class Location : RealmObject(), Manageable, RowRepresentable {
@PrimaryKey
var id = UUID.randomUUID().toString()
override var id = UUID.randomUUID().toString()
// The name of the location
var name: String = ""
@ -31,11 +31,6 @@ open class Location : RealmObject(), Manageable, RowRepresentable {
return this.name
}
override fun uniqueIdentifier(): String {
return this.id
}
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""

@ -35,6 +35,8 @@ import net.pokeranalytics.android.util.*
import java.util.*
import java.util.Currency
import kotlin.collections.ArrayList
import kotlin.properties.Delegates
import kotlin.reflect.KProperty
open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepresentableDataSource, RowRepresentable,
Timed {
@ -55,7 +57,7 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
}
@PrimaryKey
var id = UUID.randomUUID().toString()
override var id = UUID.randomUUID().toString()
/**
* Indicates the type of session, cash game or tournament
@ -109,6 +111,11 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
* The start date of the break
*/
override var pauseDate: Date? = null
set(value) {
field = value
this.updateRowRepresentation()
}
// The time frame of the Session, i.e. the start & end date
// var timeFrame: TimeFrame? = null
@ -185,6 +192,7 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
} else if (this.sessionSet != null) {
SessionSetManager.removeFromTimeline(this)
}
this.updateRowRepresentation()
}
/**
@ -460,15 +468,14 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
@Ignore
override val viewType: Int = RowViewType.ROW_SESSION.ordinal
override fun uniqueIdentifier(): String {
return this.id
}
override fun getDisplayName(): String {
return "Session ${this.creationDate}"
}
override fun adapterRows(): List<RowRepresentable>? {
@Ignore
private var rowRepresentationForCurrentState : List<RowRepresentable> = this.updatedRowRepresentationForCurrentState()
private fun updatedRowRepresentationForCurrentState(): List<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
// Headers
@ -509,8 +516,6 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
)
)
//TODO V2: Add Bankroll variation
/*
if (!isTournament()) {
rows.add(
CustomizableRowRepresentable(
@ -520,8 +525,6 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
)
)
}
*/
rows.add(SeparatorRowRepresentable())
}
else -> {
@ -533,6 +536,15 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
return rows
}
private fun updateRowRepresentation() {
this.rowRepresentationForCurrentState = this.updatedRowRepresentationForCurrentState()
}
override fun adapterRows(): List<RowRepresentable>? {
return this.rowRepresentationForCurrentState
}
override fun boolForRow(row: RowRepresentable): Boolean {
return false
}

@ -16,8 +16,17 @@ import kotlin.collections.ArrayList
open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable,
CountableUsage {
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentFeatureRow.values())
rows
}
}
@PrimaryKey
var id = UUID.randomUUID().toString()
override var id = UUID.randomUUID().toString()
// The name of the feature
var name: String = ""
@ -29,15 +38,8 @@ open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentable
return this.name
}
override fun uniqueIdentifier(): String {
return this.id
}
override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentFeatureRow.values())
return rows
return TournamentFeature.rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {

@ -15,9 +15,17 @@ import kotlin.collections.ArrayList
open class TournamentName : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable {
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentNameRow.values())
rows
}
}
@PrimaryKey
var id = UUID.randomUUID().toString()
override var id = UUID.randomUUID().toString()
// The name of the tournament
var name: String = ""
@ -26,10 +34,6 @@ open class TournamentName : RealmObject(), Manageable, StaticRowRepresentableDat
return this.name
}
override fun uniqueIdentifier(): String {
return this.id
}
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""
@ -37,10 +41,7 @@ open class TournamentName : RealmObject(), Manageable, StaticRowRepresentableDat
}
override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentNameRow.values())
return rows
return TournamentName.rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {

@ -15,9 +15,17 @@ import kotlin.collections.ArrayList
open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable {
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TransactionTypeRow.values())
rows
}
}
@PrimaryKey
var id = UUID.randomUUID().toString()
override var id = UUID.randomUUID().toString()
// The name of the transaction type
var name: String = ""
@ -35,15 +43,8 @@ open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDa
return this.name
}
override fun uniqueIdentifier(): String {
return this.id
}
override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TransactionTypeRow.values())
return rows
return TransactionType.rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {

@ -21,8 +21,18 @@ import java.util.*
class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
private val mostUsedCurrencyCodes = arrayListOf("EUR", "USD", "CAD", "GBP", "AUD", "CNY")
private val systemCurrencies = Currency.getAvailableCurrencies()
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.addAll(mostUsedCurrencies)
rows.add(SeparatorRowRepresentable())
rows.addAll(availableCurrencies)
rows
}
val mostUsedCurrencyCodes = arrayListOf("EUR", "USD", "CAD", "GBP", "AUD", "CNY")
val systemCurrencies = Currency.getAvailableCurrencies()
private val mostUsedCurrencies = this.mostUsedCurrencyCodes.map { code ->
CurrencyRow(
@ -39,6 +49,7 @@ class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataS
}.map {
CurrencyRow(it)
}
}
private class CurrencyRow(var currency:Currency) : RowRepresentable {
@ -68,11 +79,7 @@ class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataS
// StaticRowRepresentableDataSource
override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>()
rows.addAll(mostUsedCurrencies)
rows.add(SeparatorRowRepresentable())
rows.addAll(availableCurrencies)
return rows
return CurrenciesFragment.rowRepresentation
}

@ -70,7 +70,7 @@ class DataListFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSourc
EditableDataActivity.newInstance(
requireContext(),
it.ordinal,
(row as Manageable).uniqueIdentifier()
(row as Manageable).id
)
}
}

@ -146,7 +146,7 @@ open class EditableDataFragment : PokerAnalyticsFragment(), RowRepresentableDele
val item = it.copyToRealmOrUpdate(this.item)
val uniqueIdentifier = if (item is Identifiable) {
item.uniqueIdentifier()
item.id
} else ""
finishActivityWithResult(uniqueIdentifier)

@ -175,6 +175,6 @@ class HistoryFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSource
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
SessionActivity.newInstance(requireContext(), sessionId = (row as Manageable).uniqueIdentifier())
SessionActivity.newInstance(requireContext(), sessionId = (row as Manageable).id)
}
}

@ -215,7 +215,6 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
* Update adapter UI
*/
private fun updateAdapterUI(scrollToTop: Boolean) {
currentSession.adapterRows()?.let {
val diffResult = DiffUtil.calculateDiff(RowRepresentableDiffCallback(it, oldRows))
sessionAdapter.updateRows(diffResult)

@ -40,6 +40,12 @@ class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Sta
return fragment
}
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.addAll(SettingRow.getRows())
rows
}
val REQUEST_CODE_CURRENCY : Int = 0
}
@ -71,9 +77,7 @@ class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Sta
}
override fun adapterRows(): List<RowRepresentable>? {
val rows = ArrayList<RowRepresentable>()
rows.addAll(SettingRow.getRows())
return rows
return SettingsFragment.rowRepresentation
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {

Loading…
Cancel
Save