clean up adapterRows to use lazy companion arrays

feature/top10
Razmig Sarkissian 7 years ago
parent 40ac353039
commit fcd5054bab
  1. 14
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  2. 14
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  3. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentName.kt
  4. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  5. 49
      app/src/main/java/net/pokeranalytics/android/ui/fragment/CurrenciesFragment.kt
  6. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt

@ -20,6 +20,15 @@ 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()
@ -41,10 +50,7 @@ open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, R
}
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 {

@ -16,6 +16,15 @@ 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()
@ -34,10 +43,7 @@ open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentable
}
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,6 +15,14 @@ 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()
@ -37,10 +45,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,6 +15,14 @@ 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()
@ -40,10 +48,7 @@ open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDa
}
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,23 +21,34 @@ import java.util.*
class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
private val mostUsedCurrencyCodes = arrayListOf("EUR", "USD", "CAD", "GBP", "AUD", "CNY")
private val systemCurrencies = Currency.getAvailableCurrencies()
private val mostUsedCurrencies = this.mostUsedCurrencyCodes.map { code ->
CurrencyRow(
this.systemCurrencies.filter {
it.currencyCode == code
}.first()
)
}
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 availableCurrencies = this.systemCurrencies.filter {
!mostUsedCurrencyCodes.contains(it.currencyCode)
}.sortedBy {
it.displayName
}.map {
CurrencyRow(it)
private val mostUsedCurrencies = this.mostUsedCurrencyCodes.map { code ->
CurrencyRow(
this.systemCurrencies.filter {
it.currencyCode == code
}.first()
)
}
private val availableCurrencies = this.systemCurrencies.filter {
!mostUsedCurrencyCodes.contains(it.currencyCode)
}.sortedBy {
it.displayName
}.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
}

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