wip adapterrows update, fix issue with tournamentFeature and useCount

feature/top10
Razmig Sarkissian 7 years ago
parent 51e1a1f0e4
commit 7d4565fc54
  1. 2
      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. 14
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  5. 42
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  6. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt

@ -41,7 +41,7 @@ enum class LiveData : Localizable {
realm.executeTransaction {
realmResults.forEach { countableUsage ->
(countableUsage as CountableUsage).useCount = it.where<Session>().equalTo(
"${relatedEntity.simpleName.toLowerCase()}.id",
"${relatedEntity.simpleName.decapitalize()}.id",
countableUsage.uniqueIdentifier()
).count().toInt()
}

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

@ -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,6 +23,13 @@ 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
@ -48,12 +56,8 @@ open class Bankroll(name: String = "") : RealmObject(), Manageable,
}
// 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 {

@ -36,6 +36,8 @@ import timber.log.Timber
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 {
@ -110,6 +112,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
@ -186,6 +193,7 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
} else if (this.sessionSet != null) {
SessionSetManager.removeFromTimeline(this)
}
this.updateRowRepresentation()
}
/**
@ -469,7 +477,10 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
return "Session ${this.creationDate}"
}
override fun adapterRows(): List<RowRepresentable>? {
@Ignore
private var rowRepresentationForCurrentState : List<RowRepresentable> = this.updatedRowRepresentationForCurrentState()
fun updatedRowRepresentationForCurrentState(): List<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
// Headers
@ -512,16 +523,16 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
//TODO V2: Add Bankroll variation
/*
if (!isTournament()) {
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation,
computedStat = ComputedStat(Stat.HOURLY_RATE, 0.0)
)
)
}
*/
if (!isTournament()) {
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation,
computedStat = ComputedStat(Stat.HOURLY_RATE, 0.0)
)
)
}
*/
rows.add(SeparatorRowRepresentable())
}
@ -534,6 +545,15 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
return rows
}
fun updateRowRepresentation() {
this.rowRepresentationForCurrentState = this.updatedRowRepresentationForCurrentState()
}
override fun adapterRows(): List<RowRepresentable>? {
return this.rowRepresentationForCurrentState
}
override fun boolForRow(row: RowRepresentable): Boolean {
return false
}

@ -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)

Loading…
Cancel
Save