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. 21
      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 { 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() var id = UUID.randomUUID().toString()
@ -41,10 +50,7 @@ open class Game : RealmObject(), Manageable, StaticRowRepresentableDataSource, R
} }
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 {

@ -16,6 +16,15 @@ 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() var id = UUID.randomUUID().toString()
@ -34,10 +43,7 @@ open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentable
} }
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,6 +15,14 @@ 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() var id = UUID.randomUUID().toString()
@ -37,10 +45,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,6 +15,14 @@ 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() var id = UUID.randomUUID().toString()
@ -40,10 +48,7 @@ open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDa
} }
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,8 +21,18 @@ 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>()
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 -> private val mostUsedCurrencies = this.mostUsedCurrencyCodes.map { code ->
CurrencyRow( CurrencyRow(
@ -39,6 +49,7 @@ class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataS
}.map { }.map {
CurrencyRow(it) 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
} }

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