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

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

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

@ -43,4 +43,4 @@ fun Session.getState(): SessionState {
} }
} }
} }

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

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

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

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

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

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

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

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

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

@ -70,7 +70,7 @@ class DataListFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSourc
EditableDataActivity.newInstance( EditableDataActivity.newInstance(
requireContext(), requireContext(),
it.ordinal, 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 item = it.copyToRealmOrUpdate(this.item)
val uniqueIdentifier = if (item is Identifiable) { val uniqueIdentifier = if (item is Identifiable) {
item.uniqueIdentifier() item.id
} else "" } else ""
finishActivityWithResult(uniqueIdentifier) finishActivityWithResult(uniqueIdentifier)

@ -175,6 +175,6 @@ class HistoryFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSource
} }
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { 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 * Update adapter UI
*/ */
private fun updateAdapterUI(scrollToTop: Boolean) { private fun updateAdapterUI(scrollToTop: Boolean) {
currentSession.adapterRows()?.let { currentSession.adapterRows()?.let {
val diffResult = DiffUtil.calculateDiff(RowRepresentableDiffCallback(it, oldRows)) val diffResult = DiffUtil.calculateDiff(RowRepresentableDiffCallback(it, oldRows))
sessionAdapter.updateRows(diffResult) sessionAdapter.updateRows(diffResult)

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

Loading…
Cancel
Save