Refactors stringForRow into charSequenceForRow

hh
Laurent 6 years ago
parent 524520acd1
commit 4092fdedef
  1. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/Player.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  4. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  5. 8
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentName.kt
  6. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  7. 2
      app/src/main/java/net/pokeranalytics/android/model/utils/FavoriteSessionFinder.kt
  8. 24
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt
  9. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/CurrenciesFragment.kt
  10. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  11. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FiltersFragment.kt
  12. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
  13. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt
  14. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/BankrollDataFragment.kt
  15. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/CustomFieldDataFragment.kt
  16. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/LocationDataFragment.kt
  17. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/PlayerDataFragment.kt
  18. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionDataFragment.kt
  19. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionTypeDataFragment.kt
  20. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  21. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  22. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardActionView.kt
  23. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt

@ -64,15 +64,15 @@ open class Game : RealmObject(), NameManageable, StaticRowRepresentableDataSourc
return rowRepresentation return rowRepresentation
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
GameRow.SHORT_NAME -> this.shortName ?: NULL_TEXT GameRow.SHORT_NAME -> this.shortName ?: NULL_TEXT
else -> return super.stringForRow(row, context, 0) else -> return super.charSequenceForRow(row, context, 0)
} }
} }

@ -75,14 +75,14 @@ open class Player : RealmObject(), NameManageable, Deletable, StaticRowRepresent
return this.name return this.name
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
PlayerRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT PlayerRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
else -> return super.stringForRow(row, context, 0) else -> return super.charSequenceForRow(row, context, 0)
} }
} }
@ -94,7 +94,6 @@ open class Player : RealmObject(), NameManageable, Deletable, StaticRowRepresent
} }
} }
/** /**
* Update the row representation * Update the row representation
*/ */

@ -778,7 +778,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
return false return false
} }
override fun stringForRow(row: RowRepresentable, context: Context): String { override fun charSequenceForRow(row: RowRepresentable, context: Context): String {
return when (row) { return when (row) {
SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT
SessionRow.BLINDS -> getFormattedBlinds() SessionRow.BLINDS -> getFormattedBlinds()

@ -56,14 +56,14 @@ open class TournamentFeature : RealmObject(), NameManageable, StaticRowRepresent
return TournamentFeature.rowRepresentation return TournamentFeature.rowRepresentation
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
else -> return super.stringForRow(row, context, 0) else -> return super.charSequenceForRow(row, context, 0)
} }
} }

@ -50,17 +50,17 @@ open class TournamentName : RealmObject(), NameManageable, StaticRowRepresentabl
} }
override fun adapterRows(): List<RowRepresentable>? { override fun adapterRows(): List<RowRepresentable>? {
return TournamentName.rowRepresentation return rowRepresentation
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
else -> return super.stringForRow(row, context, 0) else -> return super.charSequenceForRow(row, context,0)
} }
} }

@ -106,14 +106,14 @@ open class TransactionType : RealmObject(), NameManageable, StaticRowRepresentab
return rowRepresentation return rowRepresentation
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> this.name SimpleRow.NAME -> this.name
else -> return super.stringForRow(row, context, 0) else -> return super.charSequenceForRow(row, context, 0)
} }
} }

@ -15,7 +15,7 @@ private fun Session.parameterRepresentation(context: Context): String {
var representation = "" var representation = ""
this.significantFields().forEach { this.significantFields().forEach {
representation += this.stringForRow(it, context) representation += this.charSequenceForRow(it, context)
} }
return representation return representation

@ -122,14 +122,22 @@ interface DisplayableDataSource {
/** /**
* Returns a localized string for a specific row * Returns a localized string for a specific row
*/ */
fun stringForRow(row: RowRepresentable, context: Context): String { // fun charSequenceForRow(row: RowRepresentable, context: Context): String {
return stringForRow(row, context, 0) // return charSequenceForRow(row, context, 0)
} // }
//
/** // /**
* Returns a string for a specific row // * Returns a string for a specific row
*/ // */
fun stringForRow(row: RowRepresentable, context: Context, tag: Int = 0): String { // fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int = 0): String {
// return ""
// }
fun charSequenceForRow(row: RowRepresentable, context: Context): CharSequence {
return charSequenceForRow(row, context, 0)
}
fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int = 0): CharSequence {
return "" return ""
} }

@ -90,11 +90,11 @@ class CurrenciesFragment : BaseFragment(), StaticRowRepresentableDataSource, Row
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return (row as CurrencyRow).currencyCodeAndSymbol return (row as CurrencyRow).currencyCodeAndSymbol
} }

@ -96,10 +96,10 @@ open class FilterDetailsFragment : RealmFragment(), StaticRowRepresentableDataSo
} }
} }
override fun stringForRow(row: RowRepresentable, context: Context): String { override fun charSequenceForRow(row: RowRepresentable, context: Context): CharSequence {
return when (row) { return when (row) {
is QueryCondition.ListOfValues<*> -> row.firstValue(context) is QueryCondition.ListOfValues<*> -> row.firstValue(context)
else -> super.stringForRow(row, context, 0) else -> super.charSequenceForRow(row, context, 0)
} ?: NULL_TEXT } ?: NULL_TEXT
} }

@ -132,11 +132,11 @@ open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource,
return rows return rows
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
// Return the number of selected filters for this category // Return the number of selected filters for this category
var selectedFilters = "" var selectedFilters = ""
if (row is FilterCategoryRow) { if (row is FilterCategoryRow) {

@ -104,11 +104,11 @@ class SettingsFragment : BaseFragment(), RowRepresentableDelegate, StaticRowRepr
return rowRepresentation return rowRepresentation
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SettingRow.SUBSCRIPTION -> AppGuard.subscriptionStatus(requireContext()) SettingRow.SUBSCRIPTION -> AppGuard.subscriptionStatus(requireContext())
SettingRow.VERSION -> BuildConfig.VERSION_NAME + if (BuildConfig.DEBUG) " (${BuildConfig.VERSION_CODE}) DEBUG" else "" SettingRow.VERSION -> BuildConfig.VERSION_NAME + if (BuildConfig.DEBUG) " (${BuildConfig.VERSION_CODE}) DEBUG" else ""

@ -63,7 +63,7 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment(), StaticRowReprese
dismiss() dismiss()
} }
// override fun stringForRow(row: RowRepresentable, context: Context, tag: Int): String { // override fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int): String {
// //
// if (this.viewModel.alternativeLabels) { // if (this.viewModel.alternativeLabels) {
// return (row as TableSize).numberOfPlayer.toString() // return (row as TableSize).numberOfPlayer.toString()

@ -84,11 +84,11 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
return rows return rows
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> if (bankroll.name.isNotEmpty()) bankroll.name else NULL_TEXT SimpleRow.NAME -> if (bankroll.name.isNotEmpty()) bankroll.name else NULL_TEXT
BankrollRow.CURRENCY -> { BankrollRow.CURRENCY -> {
@ -109,7 +109,7 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
val rate = this.bankroll.currency?.rate ?: 1.0 val rate = this.bankroll.currency?.rate ?: 1.0
rate.toRate() rate.toRate()
} }
else -> super.stringForRow(row, context, 0) else -> super.charSequenceForRow(row, context, 0)
} }
} }

@ -121,14 +121,14 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
return customField.adapterRows() return customField.adapterRows()
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> if (customField.name.isNotEmpty()) customField.name else NULL_TEXT SimpleRow.NAME -> if (customField.name.isNotEmpty()) customField.name else NULL_TEXT
else -> super.stringForRow(row, context, 0) else -> super.charSequenceForRow(row, context, 0)
} }
} }

@ -65,14 +65,14 @@ class LocationDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
return rows return rows
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> if (location.name.isNotEmpty())location.name else NULL_TEXT SimpleRow.NAME -> if (location.name.isNotEmpty())location.name else NULL_TEXT
else -> return super.stringForRow(row, context, 0) else -> return super.charSequenceForRow(row, context, 0)
} }
} }

@ -117,15 +117,15 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou
} }
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
PlayerRow.NAME -> if (player.name.isNotEmpty()) player.name else NULL_TEXT PlayerRow.NAME -> if (player.name.isNotEmpty()) player.name else NULL_TEXT
PlayerRow.SUMMARY -> if (player.summary.isNotEmpty()) player.summary else NULL_TEXT PlayerRow.SUMMARY -> if (player.summary.isNotEmpty()) player.summary else NULL_TEXT
else -> super.stringForRow(row, context, 0) else -> super.charSequenceForRow(row, context, 0)
} }
} }

@ -47,18 +47,18 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa
return transaction.adapterRows() return transaction.adapterRows()
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
TransactionRow.BANKROLL -> this.transaction.bankroll?.name ?: NULL_TEXT TransactionRow.BANKROLL -> this.transaction.bankroll?.name ?: NULL_TEXT
TransactionRow.TYPE -> this.transaction.type?.name ?: NULL_TEXT TransactionRow.TYPE -> this.transaction.type?.name ?: NULL_TEXT
TransactionRow.AMOUNT -> if (this.transaction.amount != 0.0) this.transaction.amount.round() else NULL_TEXT TransactionRow.AMOUNT -> if (this.transaction.amount != 0.0) this.transaction.amount.round() else NULL_TEXT
TransactionRow.COMMENT -> if (this.transaction.comment.isNotEmpty()) this.transaction.comment else NULL_TEXT TransactionRow.COMMENT -> if (this.transaction.comment.isNotEmpty()) this.transaction.comment else NULL_TEXT
TransactionRow.DATE -> this.transaction.date.shortDate() TransactionRow.DATE -> this.transaction.date.shortDate()
else -> super.stringForRow(row, context, 0) else -> super.charSequenceForRow(row, context, 0)
} }
} }

@ -34,14 +34,14 @@ class TransactionTypeDataFragment : EditableDataFragment(), RowRepresentableData
return this.transactionType.viewTypeForPosition(position) return this.transactionType.viewTypeForPosition(position)
} }
override fun stringForRow( override fun charSequenceForRow(
row: RowRepresentable, row: RowRepresentable,
context: Context, context: Context,
tag: Int tag: Int
): String { ): CharSequence {
return when (row) { return when (row) {
SimpleRow.NAME -> this.transactionType.name SimpleRow.NAME -> this.transactionType.name
else -> return super.stringForRow(row, context, 0) else -> return super.charSequenceForRow(row, context, 0)
} }
} }

@ -197,7 +197,7 @@ class HandHistoryAdapter(
protected fun configureEditTexts(range: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { protected fun configureEditTexts(range: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
range.forEach { tag -> range.forEach { tag ->
val string = adapter.dataSource.stringForRow(row, itemView.context, tag) val string = adapter.dataSource.charSequenceForRow(row, itemView.context, tag)
// Text // Text
val editText = itemView.findViewWithTag<EditText>(tag) ?: throw PAIllegalStateException("Edit Text not found for tag: $tag, class: $this") val editText = itemView.findViewWithTag<EditText>(tag) ?: throw PAIllegalStateException("Edit Text not found for tag: $tag, class: $this")
@ -243,9 +243,9 @@ class HandHistoryAdapter(
configureEditTexts(0..2, position, row, adapter) configureEditTexts(0..2, position, row, adapter)
// itemView.smallBlindEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0)) // itemView.smallBlindEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 0))
// itemView.bigBlindEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1)) // itemView.bigBlindEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 1))
// itemView.anteEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 2)) // itemView.anteEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 2))
// itemView.bbAnteSwitch.isChecked = adapter.dataSource.isSelected(position, row, 0) // itemView.bbAnteSwitch.isChecked = adapter.dataSource.isSelected(position, row, 0)
// //
// val sbSelected = adapter.dataSource.isSelected(position, row, 0) // val sbSelected = adapter.dataSource.isSelected(position, row, 0)
@ -640,8 +640,8 @@ class HandHistoryAdapter(
// toggleFocus(itemView.stackEditText, stackSelected) // toggleFocus(itemView.stackEditText, stackSelected)
// itemView.handEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0)) // itemView.handEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 0))
// itemView.stackEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1)) // itemView.stackEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 1))
} }

@ -542,7 +542,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
this.cardSelectionEnded(this.currentSelection.index) this.cardSelectionEnded(this.currentSelection.index)
} }
override fun stringForRow(row: RowRepresentable, context: Context, tag: Int): String { override fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int): CharSequence {
val string = when (row) { val string = when (row) {
HandRowType.PLAYER_NUMBER -> this.handHistory.numberOfPlayers.toString() HandRowType.PLAYER_NUMBER -> this.handHistory.numberOfPlayers.toString()
@ -568,7 +568,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag") else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag")
} }
return string?.let { it.toString() } ?: "" // we don't want "null" so we keep the let return string?.let { it } ?: "" // we don't want "null" so we keep the let
} }
override fun <T : Any> contentForRow(row: RowRepresentable, context: Context, clazz: KClass<T>) : List<T> { override fun <T : Any> contentForRow(row: RowRepresentable, context: Context, clazz: KClass<T>) : List<T> {

@ -91,7 +91,7 @@ class KeyboardActionView(context: Context) : AbstractKeyboardView(context),
this.dataAdapter.notifyDataSetChanged() this.dataAdapter.notifyDataSetChanged()
} }
// override fun stringForRow(row: RowRepresentable): String { // override fun charSequenceForRow(row: RowRepresentable): String {
// this.context?.let { // this.context?.let {
// return row.localizedTitle(it) // return row.localizedTitle(it)
// } // }

@ -122,7 +122,7 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
// Value // Value
itemView.findViewById<AppCompatTextView?>(R.id.value)?.let { itemView.findViewById<AppCompatTextView?>(R.id.value)?.let {
it.text = adapter.dataSource.stringForRow(row, itemView.context) it.text = adapter.dataSource.charSequenceForRow(row, itemView.context)
} }
// Icon // Icon

Loading…
Cancel
Save