WIP refactoring editDescriptor

dev^2
Razmig Sarkissian 6 years ago
parent 63d6c9b5b9
commit 5882fd8cd6
  1. 3
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  2. 56
      app/src/main/java/net/pokeranalytics/android/model/realm/CustomField.kt
  3. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/CustomFieldEntry.kt
  4. 22
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  5. 16
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  6. 105
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  7. 14
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  8. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentName.kt
  9. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  10. 14
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt
  11. 30
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  12. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FiltersListFragment.kt
  13. 28
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  14. 20
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/BankrollDataFragment.kt
  15. 11
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/CustomFieldDataFragment.kt
  16. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/EditableDataFragment.kt
  17. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/LocationDataFragment.kt
  18. 34
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionDataFragment.kt
  19. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionTypeDataFragment.kt
  20. 11
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  21. 54
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/BankrollRow.kt
  22. 52
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/CustomFieldRow.kt
  23. 53
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  24. 25
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/GameRow.kt
  25. 26
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/LocationRow.kt
  26. 125
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt
  27. 3
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SimpleRow.kt
  28. 47
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentFeatureRow.kt
  29. 47
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentNameRow.kt
  30. 91
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt
  31. 26
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionTypeRow.kt

@ -15,7 +15,6 @@ import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.BankrollRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.UserDefaults
import java.util.*
@ -52,7 +51,7 @@ open class Bankroll : RealmObject(), NameManageable, RowRepresentable {
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""
BankrollRow.NAME -> this.name = value as String? ?: ""
BankrollRow.LIVE -> {
this.live = if (value is Boolean) !value else false
}

@ -2,6 +2,7 @@ package net.pokeranalytics.android.model.realm
import android.content.Context
import android.text.InputType
import androidx.fragment.app.Fragment
import io.realm.Realm
import io.realm.RealmList
import io.realm.RealmObject
@ -14,14 +15,16 @@ import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus
import net.pokeranalytics.android.model.interfaces.Identifiable
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomFieldRow
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.enumerations.IntIdentifiable
import java.util.*
import kotlin.collections.ArrayList
@ -125,9 +128,23 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa
return rowRepresentation
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is Session) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (type) {
Type.LIST.uniqueIdentifier -> data.append(dataSource.customFieldEntries.find { it.customField?.id == id }?.value, staticData = entries)
else -> data.append(dataSource.customFieldEntries.find { it.customField?.id == dataSource.id }?.numericValue, inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED)
}
BottomSheetFragment.newCreate(this, parent, data)
}
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""
CustomFieldRow.NAME -> this.name = value as String? ?: ""
CustomFieldRow.TYPE -> this.type = (value as Type?)?.uniqueIdentifier ?: Type.LIST.uniqueIdentifier
CustomFieldRow.COPY_ON_DUPLICATE -> this.duplicateValue = value as Boolean? ?: false
}
@ -176,45 +193,12 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
is CustomFieldEntry -> row.editingDescriptors(
mapOf(
"defaultValue" to row.value
)
)
else -> null
}
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (type) {
Type.LIST.uniqueIdentifier -> {
val defaultValue: Any? by map
val data: RealmList<CustomFieldEntry>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, staticData = data)
)
}
else -> {
val defaultValue: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue, inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
)
)
}
}
}
/**
* Update the row representation
*/
private fun updatedRowRepresentationForCurrentState(): List<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.add(CustomFieldRow.NAME)
rows.add(CustomFieldRow.TYPE)
if (type == Type.LIST.uniqueIdentifier && entries.size >= 0) {

@ -2,6 +2,7 @@ package net.pokeranalytics.android.model.realm
import android.content.Context
import android.text.InputType
import androidx.fragment.app.Fragment
import io.realm.Realm
import io.realm.RealmObject
import io.realm.RealmResults
@ -15,9 +16,11 @@ import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus
import net.pokeranalytics.android.model.interfaces.Identifiable
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.toCurrency
@ -91,12 +94,16 @@ open class CustomFieldEntry : RealmObject(), NameManageable, RowRepresentable {
return if (value.isNotEmpty()) value else NULL_TEXT
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
val defaultValue: Any? by map
return arrayListOf(
RowRepresentableEditDescriptor(defaultValue, R.string.value, InputType.TYPE_CLASS_TEXT)
)
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
data.append(this.value, R.string.value, InputType.TYPE_CLASS_TEXT)
BottomSheetFragment.newCreate(this, parent, data, isDeletable = true)
}
override val valueCanBeClearedWhenEditing: Boolean
get() = false
override fun isValidForSave(): Boolean {
return true

@ -1,6 +1,8 @@
package net.pokeranalytics.android.model.realm
import android.content.Context
import android.text.InputType
import androidx.fragment.app.Fragment
import io.realm.*
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
@ -10,12 +12,11 @@ import net.pokeranalytics.android.model.filter.Filterable
import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.interfaces.*
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.interfaces.FilterableType
import net.pokeranalytics.android.ui.view.ImageDecorator
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.*
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import timber.log.Timber
import java.util.*
@ -202,11 +203,6 @@ open class Filter : RealmObject(), RowRepresentable, Editable, Deletable, Counta
return context.getString(R.string.name)
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
val defaultValue: String? by map
return arrayListOf(RowRepresentableEditDescriptor(defaultValue, R.string.name))
}
override fun updateValue(value: Any?, row: RowRepresentable) {
realm.executeTransaction {
val newName = value as String? ?: ""
@ -215,4 +211,12 @@ open class Filter : RealmObject(), RowRepresentable, Editable, Deletable, Counta
}
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
data.append(this.name)
BottomSheetFragment.newCreate(this, parent, data, isDeletable = true, valueHasPlaceholder = false)
}
}

@ -29,7 +29,7 @@ open class Game : RealmObject(), NameManageable, StaticRowRepresentableDataSourc
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.add(GameRow.NAME)
// rows.addAll(GameRow.values())
rows
}
@ -62,28 +62,20 @@ open class Game : RealmObject(), NameManageable, StaticRowRepresentableDataSourc
}
override fun adapterRows(): List<RowRepresentable>? {
return Game.rowRepresentation
return rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
GameRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
GameRow.SHORT_NAME -> this.shortName ?: NULL_TEXT
else -> return super.stringForRow(row)
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.name))
GameRow.SHORT_NAME -> row.editingDescriptors(mapOf("defaultValue" to this.shortName))
else -> null
}
}
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""
GameRow.NAME -> this.name = value as String? ?: ""
GameRow.SHORT_NAME -> this.shortName = value as String? ?: ""
}
}

@ -834,111 +834,6 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
SessionRow.BANKROLL -> row.editingDescriptors(
mapOf(
"defaultValue" to this.bankroll,
"data" to realm.sorted<Bankroll>() // LiveData.Bankroll.items(realm)
)
)
SessionRow.GAME -> row.editingDescriptors(
mapOf(
"limit" to this.limit,
"defaultValue" to this.game,
"data" to realm.sorted<Game>() //LiveData.Game.items(realm)
)
)
SessionRow.LOCATION -> row.editingDescriptors(
mapOf(
"defaultValue" to this.location,
"data" to realm.sorted<Location>() // LiveData.Location.items(realm)
)
)
SessionRow.TOURNAMENT_FEATURE -> row.editingDescriptors(
mapOf(
"defaultValue" to this.tournamentFeatures,
"data" to realm.sorted<TournamentFeature>() //LiveData.TournamentFeature.items(realm)
)
)
SessionRow.TOURNAMENT_NAME -> row.editingDescriptors(
mapOf(
"defaultValue" to this.tournamentName,
"data" to realm.sorted<TournamentName>() //LiveData.TournamentName.items(realm)
)
)
SessionRow.TOURNAMENT_TYPE -> row.editingDescriptors(
mapOf(
"defaultValue" to this.tournamentType
)
)
SessionRow.TABLE_SIZE -> row.editingDescriptors(
mapOf(
"defaultValue" to this.tableSize
)
)
SessionRow.BUY_IN -> row.editingDescriptors(
mapOf(
"bb" to cgBigBlind,
"fee" to this.tournamentEntryFee,
"ratedBuyin" to result?.buyin
)
)
SessionRow.BREAK_TIME -> row.editingDescriptors(mapOf())
SessionRow.CASHED_OUT, SessionRow.PRIZE -> row.editingDescriptors(
mapOf(
"defaultValue" to result?.cashout
)
)
SessionRow.NET_RESULT -> row.editingDescriptors(
mapOf(
"defaultValue" to result?.netResult
)
)
SessionRow.COMMENT -> row.editingDescriptors(
mapOf(
"defaultValue" to this.comment
)
)
SessionRow.INITIAL_BUY_IN -> row.editingDescriptors(
mapOf(
"defaultValue" to this.tournamentEntryFee
)
)
SessionRow.PLAYERS -> row.editingDescriptors(
mapOf(
"defaultValue" to this.tournamentNumberOfPlayers
)
)
SessionRow.POSITION -> row.editingDescriptors(
mapOf(
"defaultValue" to this.result?.tournamentFinalPosition
)
)
SessionRow.TIPS -> row.editingDescriptors(
mapOf(
"sb" to cgSmallBlind?.round(),
"bb" to cgBigBlind?.round(),
"tips" to result?.tips
)
)
is CustomField -> {
row.editingDescriptors(
when (row.type) {
CustomField.Type.LIST.uniqueIdentifier -> mapOf(
"defaultValue" to customFieldEntries.find { it.customField?.id == row.id }?.value,
"data" to row.entries
)
else -> mapOf(
"defaultValue" to customFieldEntries.find { it.customField?.id == row.id }?.numericValue
)
}
)
}
else -> null
}
}
override fun updateValue(value: Any?, row: RowRepresentable) {
realm.executeTransaction {

@ -14,8 +14,6 @@ import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.ui.view.rowrepresentable.TournamentFeatureRow
import net.pokeranalytics.android.util.NULL_TEXT
import java.util.*
@ -27,7 +25,6 @@ open class TournamentFeature : RealmObject(), NameManageable, StaticRowRepresent
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentFeatureRow.values())
rows
}
@ -53,24 +50,19 @@ open class TournamentFeature : RealmObject(), NameManageable, StaticRowRepresent
}
override fun adapterRows(): List<RowRepresentable>? {
return TournamentFeature.rowRepresentation
return rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
TournamentFeatureRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
else -> return super.stringForRow(row)
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return row.editingDescriptors(mapOf(
"defaultValue" to this.name))
}
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""
TournamentFeatureRow.NAME -> this.name = value as String? ?: ""
}
}

@ -12,8 +12,6 @@ import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.ui.view.rowrepresentable.TournamentNameRow
import net.pokeranalytics.android.util.NULL_TEXT
import java.util.*
@ -24,7 +22,6 @@ open class TournamentName : RealmObject(), NameManageable, StaticRowRepresentabl
companion object {
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentNameRow.values())
rows
}
@ -45,25 +42,21 @@ open class TournamentName : RealmObject(), NameManageable, StaticRowRepresentabl
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""
TournamentNameRow.NAME -> this.name = value as String? ?: ""
}
}
override fun adapterRows(): List<RowRepresentable>? {
return TournamentName.rowRepresentation
return rowRepresentation
}
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
SimpleRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
TournamentNameRow.NAME -> if (this.name.isNotEmpty()) this.name else NULL_TEXT
else -> return super.stringForRow(row)
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return row.editingDescriptors(mapOf("defaultValue" to this.name))
}
override fun getFailedSaveMessage(status: SaveValidityStatus): Int {
return when (status) {
SaveValidityStatus.DATA_INVALID -> R.string.tournament_name_empty_field_error

@ -12,8 +12,6 @@ import net.pokeranalytics.android.model.interfaces.*
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.view.Localizable
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.ui.view.rowrepresentable.TransactionTypeRow
import net.pokeranalytics.android.util.enumerations.IntIdentifiable
import net.pokeranalytics.android.util.enumerations.IntSearchable
@ -55,7 +53,6 @@ open class TransactionType : RealmObject(), NameManageable, StaticRowRepresentab
companion object {
val rowRepresentation: List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TransactionTypeRow.values())
rows
}
@ -108,7 +105,7 @@ open class TransactionType : RealmObject(), NameManageable, StaticRowRepresentab
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
SimpleRow.NAME -> this.name
TransactionTypeRow.NAME -> this.name
else -> return super.stringForRow(row)
}
}
@ -120,13 +117,9 @@ open class TransactionType : RealmObject(), NameManageable, StaticRowRepresentab
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return row.editingDescriptors(mapOf("defaultValue" to this.name))
}
override fun updateValue(value: Any?, row: RowRepresentable) {
when (row) {
SimpleRow.NAME -> this.name = value as String? ?: ""
TransactionTypeRow.NAME -> this.name = value as String? ?: ""
TransactionTypeRow.TRANSACTION_ADDITIVE -> this.additive = value as Boolean? ?: false
}
}

@ -9,7 +9,7 @@ import net.pokeranalytics.android.util.TextFormat
/**
* Base Interface to provide the RowRepresentable to the adapter
*/
interface RowRepresentableDataSource: EditableDataSource, DisplayableDataSource, SelectableDataSource {
interface RowRepresentableDataSource: DisplayableDataSource, SelectableDataSource {
/**
* Returns a prebuild list of rows
@ -161,18 +161,6 @@ interface DisplayableDataSource {
}
}
/**
* An interface providing a way to describe how the edition of a [RowRepresentable] will be displayed
*/
interface EditableDataSource {
/**
* A list of [RowRepresentableEditDescriptor] object specifying the way the edition will be handled
*/
fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return null
}
}
/**
* An interface providing a way to select a row

@ -65,35 +65,7 @@ open class FilterDetailsFragment : RealmFragment(), StaticRowRepresentableDataSo
updateRowsSelection(row)
return
}
when (row) {
is QueryCondition.DateQuery -> DateTimePickerManager.create(
requireContext(),
row,
this,
row.singleValue,
onlyDate = !row.showTime,
onlyTime = row.showTime
)
is QueryCondition.Duration -> {
var hours: String? = null
var minutes: String? = null
row.minutes?.let {
hours = if (it / 60 > 0) (it / 60).toString() else null
minutes = if (it % 60 > 0) (it % 60).toString() else null
}
val data = row.editingDescriptors(mapOf("hours" to hours, "minutes" to minutes))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
is QueryCondition.ListOfValues<*> -> {
var valueAsString: String? = null
row.listOfValues.firstOrNull()?.let {
valueAsString = row.listOfValues.firstOrNull()?.toString()
}
val data = row.editingDescriptors(mapOf("valueAsString" to valueAsString))
BottomSheetFragment.create(fragmentManager, row, this, data, true)
}
}
row.startEditing(null, this)
}
override fun stringForRow(row: RowRepresentable, context: Context): String {

@ -55,13 +55,6 @@ open class FiltersListFragment : DataListFragment() {
return if (viewType != -1) viewType else RowViewType.DATA.ordinal
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
is Filter -> row.editingDescriptors(mapOf("defaultValue" to row.name))
else -> super.editDescriptors(row)
}
}
override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
when (row) {
is Filter -> {
@ -91,8 +84,7 @@ open class FiltersListFragment : DataListFragment() {
when (row) {
is Filter -> {
if (fromAction) {
val data = row.editingDescriptors(mapOf("defaultValue" to row.name))
BottomSheetFragment.create(fragmentManager, row, this, data, false, isDeletable = true, valueHasPlaceholder = false)
row.startEditing(null, this)
} else {
val intent = Intent()
intent.putExtra(FiltersActivity.IntentKey.FILTER_ID.keyName, row.id)

@ -23,8 +23,6 @@ import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.RealmFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.helpers.DateTimePickerManager
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
@ -158,31 +156,7 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
Toast.makeText(requireContext(), "Action for row: $row", Toast.LENGTH_SHORT).show()
return
}
//row.startEditing(currentSession, this)
val data = currentSession.editDescriptors(row)
when (row) {
SessionRow.START_DATE -> DateTimePickerManager.create(requireContext(), row, this, currentSession.startDate)
SessionRow.END_DATE -> {
if (this.currentSession.startDate == null) {
Toast.makeText(context, R.string.session_missing_start_date, Toast.LENGTH_SHORT).show()
} else {
DateTimePickerManager.create(
requireContext(),
row,
this,
currentSession.endDate ?: currentSession.startDate ?: Date(),
currentSession.startDate
)
}
}
SessionRow.BANKROLL -> {
BottomSheetFragment.create(fragmentManager, row, this, data, false, currentSession.currency)
}
else -> BottomSheetFragment.create(fragmentManager, row, this, data, currentCurrency = currentSession.currency)
}
row.startEditing(currentSession, this)
}
override fun onRowValueChanged(value: Any?, row: RowRepresentable) {

@ -14,11 +14,9 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.fragment.CurrenciesFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.BankrollRow
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.UserDefaults
import net.pokeranalytics.android.util.extensions.toCurrency
@ -85,7 +83,7 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
SimpleRow.NAME -> if (bankroll.name.isNotEmpty()) bankroll.name else NULL_TEXT
BankrollRow.NAME -> if (bankroll.name.isNotEmpty()) bankroll.name else NULL_TEXT
BankrollRow.CURRENCY -> {
bankroll.currency?.code?.let { code ->
Currency.getInstance(code).currencyCode
@ -116,20 +114,6 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.bankroll.name))
BankrollRow.INITIAL_VALUE -> {
row.editingDescriptors(mapOf("defaultValue" to this.bankroll.initialValue))
}
BankrollRow.RATE -> {
val rate = this.bankroll.currency?.rate
row.editingDescriptors(mapOf("defaultValue" to rate))
}
else -> null
}
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
when (row) {
BankrollRow.CURRENCY -> CurrenciesActivity.newInstanceForResult(this@BankrollDataFragment,
@ -174,7 +158,7 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
private fun refreshRows() {
rows.clear()
rows.add(SimpleRow.NAME)
rows.add(BankrollRow.NAME)
rows.add(BankrollRow.LIVE)
rows.add(BankrollRow.INITIAL_VALUE)
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.currency))

@ -19,9 +19,7 @@ import net.pokeranalytics.android.ui.extensions.px
import net.pokeranalytics.android.ui.extensions.showAlertDialog
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomFieldRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.NULL_TEXT
import java.util.*
@ -122,7 +120,7 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
SimpleRow.NAME -> if (customField.name.isNotEmpty()) customField.name else NULL_TEXT
CustomFieldRow.NAME -> if (customField.name.isNotEmpty()) customField.name else NULL_TEXT
else -> super.stringForRow(row)
}
}
@ -142,6 +140,7 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
}
}
/*
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.customField.name))
@ -149,13 +148,11 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
else -> null
}
}
*/
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
when (row) {
is CustomFieldEntry -> {
val data = customField.editDescriptors(row)
BottomSheetFragment.create(fragmentManager, row, this, data, isClearable = false, isDeletable = true)
}
is CustomFieldEntry -> row.startEditing(null, this)
else -> super.onRowSelected(position, row, fromAction)
}
}

@ -14,7 +14,6 @@ import net.pokeranalytics.android.model.interfaces.Editable
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
@ -62,7 +61,7 @@ open class EditableDataFragment : DataManagerFragment(), RowRepresentableDelegat
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
BottomSheetFragment.create(fragmentManager, row, this, getDataSource().editDescriptors(row))
row.startEditing(this.item, this)
}
override fun onRowValueChanged(value: Any?, row: RowRepresentable) {

@ -8,11 +8,9 @@ import net.pokeranalytics.android.model.realm.Location
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.LocationRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.NULL_TEXT
/**
@ -66,7 +64,7 @@ class LocationDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
override fun stringForRow(row: RowRepresentable): String {
return when (row) {
SimpleRow.NAME -> if (location.name.isNotEmpty())location.name else NULL_TEXT
LocationRow.NAME -> if (location.name.isNotEmpty())location.name else NULL_TEXT
else -> return super.stringForRow(row)
}
}
@ -78,13 +76,6 @@ class LocationDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.location.name))
else -> null
}
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
// If we click on a location row, save the location (and finish activity)
placesForRows[row]?.place?.let { place ->
@ -128,7 +119,7 @@ class LocationDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
*/
private fun refreshRows() {
rows.clear()
rows.add(SimpleRow.NAME)
rows.add(LocationRow.NAME)
rows.add(LocationRow.LOCATION_PERMISSION_SWITCH)
// Add info row to explain why we need the location permission
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.INFO, resId = R.string.location_when_in_use_usage_description))

@ -57,40 +57,6 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return when (row) {
TransactionRow.BANKROLL -> row.editingDescriptors(
mapOf(
"defaultValue" to this.transaction.bankroll,
"data" to getRealm().sorted<Bankroll>()
)
)
TransactionRow.TYPE -> row.editingDescriptors(
mapOf(
"defaultValue" to this.transaction.type,
"data" to getRealm().sorted<TransactionType>()
)
)
TransactionRow.AMOUNT -> row.editingDescriptors(mapOf("defaultValue" to (if (this.transaction.amount != 0.0) this.transaction.amount.round() else "")))
TransactionRow.COMMENT -> row.editingDescriptors(mapOf("defaultValue" to this.transaction.comment))
else -> super.editDescriptors(row)
}
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
when (row) {
TransactionRow.DATE -> DateTimePickerManager.create(
requireContext(),
row,
this,
this.transaction.date,
onlyDate = true,
isClearable = false
)
else -> super.onRowSelected(position, row, fromAction)
}
}
override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
super.onRowValueChanged(value, row)
rowRepresentableAdapter.refreshRow(row)

@ -47,10 +47,6 @@ class TransactionTypeDataFragment : EditableDataFragment(), RowRepresentableData
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
return row.editingDescriptors(mapOf("defaultValue" to this.transactionType.name))
}
override fun isEnabled(row: RowRepresentable): Boolean {
return when (row) {
TransactionTypeRow.TRANSACTION_ADDITIVE -> {

@ -18,23 +18,12 @@ interface RowRepresentable : Displayable, EditDataSource, ImageDecorator {
}
interface EditDataSource {
fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return null
}
fun startEditing(dataSource:Any?, parent:Fragment?) {}
val valueCanBeClearedWhenEditing: Boolean
get() { return true }
}
interface DefaultEditDataSource : EditDataSource, Localizable {
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
val defaultValue: String? by map
return arrayListOf(RowRepresentableEditDescriptor(defaultValue, this.resId))
}
}
/**
* An interface to add an image to a row
*/

@ -1,16 +1,17 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import io.realm.RealmObject
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.Bankroll
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.*
enum class BankrollRow : RowRepresentable, DefaultEditDataSource {
enum class BankrollRow : RowRepresentable {
NAME,
LIVE,
INITIAL_VALUE,
CURRENCY,
@ -20,6 +21,7 @@ enum class BankrollRow : RowRepresentable, DefaultEditDataSource {
override val resId: Int?
get() {
return when (this) {
NAME -> R.string.name
LIVE -> R.string.online
INITIAL_VALUE -> R.string.initial_value
CURRENCY -> R.string.currency
@ -31,6 +33,7 @@ enum class BankrollRow : RowRepresentable, DefaultEditDataSource {
override val viewType: Int
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
LIVE -> RowViewType.TITLE_SWITCH.ordinal
INITIAL_VALUE -> RowViewType.TITLE_VALUE.ordinal
CURRENCY -> RowViewType.TITLE_VALUE_ARROW.ordinal
@ -42,6 +45,7 @@ enum class BankrollRow : RowRepresentable, DefaultEditDataSource {
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
LIVE -> BottomSheetType.NONE
INITIAL_VALUE -> BottomSheetType.NUMERIC_TEXT
CURRENCY -> BottomSheetType.NONE
@ -50,28 +54,18 @@ enum class BankrollRow : RowRepresentable, DefaultEditDataSource {
}
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (this) {
INITIAL_VALUE -> {
val defaultValue : Any? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, R.string.initial_value, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL)
)
}
RATE -> {
val defaultValue : Any? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, R.string.rate, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL)
)
}
else -> super<RowRepresentable>.editingDescriptors(map)
}
}
fun editDefaultValue(entity:RealmObject): Any? {
return null
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is Bankroll) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
NAME -> data.append(dataSource.name)
INITIAL_VALUE -> data.append(dataSource.initialValue, R.string.initial_value, InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL)
RATE -> data.append(dataSource.currency?.rate, R.string.rate, InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL)
else -> PokerAnalyticsException.BottomSheetException
}
BottomSheetFragment.newCreate(this, parent, data)
}
}

@ -1,19 +1,26 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.CustomField
import net.pokeranalytics.android.model.realm.CustomFieldEntry
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowViewType
enum class CustomFieldRow : RowRepresentable, DefaultEditDataSource {
enum class CustomFieldRow : RowRepresentable {
NAME,
TYPE,
COPY_ON_DUPLICATE;
override val resId: Int?
get() {
return when (this) {
NAME -> R.string.name
COPY_ON_DUPLICATE -> R.string.copy_on_duplicate
else -> null
}
@ -22,6 +29,7 @@ enum class CustomFieldRow : RowRepresentable, DefaultEditDataSource {
override val viewType: Int
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
TYPE -> RowViewType.LIST.ordinal
COPY_ON_DUPLICATE -> RowViewType.TITLE_SWITCH.ordinal
}
@ -30,7 +38,8 @@ enum class CustomFieldRow : RowRepresentable, DefaultEditDataSource {
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
TYPE -> BottomSheetType.NONE
NAME -> BottomSheetType.EDIT_TEXT
TYPE -> BottomSheetType.NONE
COPY_ON_DUPLICATE -> BottomSheetType.NONE
}
}
@ -55,4 +64,41 @@ enum class CustomFieldRow : RowRepresentable, DefaultEditDataSource {
}
return list
}
/*
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (type) {
Type.LIST.uniqueIdentifier -> {
val defaultValue: Any? by map
val data: RealmList<CustomFieldEntry>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, staticData = data)
)
}
else -> {
val defaultValue: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue, inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
)
)
}
}
}
*/
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is CustomField) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
NAME -> data.append(dataSource.name)
else -> PokerAnalyticsException.BottomSheetException
}
BottomSheetFragment.newCreate(this, parent, data)
}
}

@ -1,27 +1,47 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.model.realm.Bankroll
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.helpers.DateTimePickerManager
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import java.util.*
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
interface FilterElementRow : RowRepresentable {
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (this) {
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
is QueryCondition.DateQuery -> DateTimePickerManager.create(
parent.requireContext(),
this,
parent,
this.singleValue,
onlyDate = !this.showTime,
onlyTime = this.showTime
)
is QueryCondition.Duration -> {
val hours: String? by map
val minutes: String? by map
arrayListOf(
RowRepresentableEditDescriptor(hours, R.string.hour, inputType = InputType.TYPE_CLASS_NUMBER),
RowRepresentableEditDescriptor(minutes, R.string.minute, inputType = InputType.TYPE_CLASS_NUMBER)
)
var hours: String? = null
var minutes: String? = null
this.minutes?.let {
hours = if (it / 60 > 0) (it / 60).toString() else null
minutes = if (it % 60 > 0) (it % 60).toString() else null
}
data.append(hours, R.string.hour, inputType = InputType.TYPE_CLASS_NUMBER)
data.append(minutes, R.string.minute, inputType = InputType.TYPE_CLASS_NUMBER)
BottomSheetFragment.newCreate(this, parent, data)
}
is QueryCondition.ListOfValues<*> -> {
val valueAsString: String? by map
var valueAsString: String? = null
this.listOfValues.firstOrNull()?.let {
valueAsString = this.listOfValues.firstOrNull()?.toString()
}
val hint = when (this.operator) {
QueryCondition.Operator.MORE, QueryCondition.Operator.LESS -> {
when (this) {
@ -32,12 +52,9 @@ interface FilterElementRow : RowRepresentable {
}
else -> this.resId
}
arrayListOf(
RowRepresentableEditDescriptor(valueAsString, hint, inputType = InputType.TYPE_CLASS_NUMBER)
)
data.append(valueAsString, hint, inputType = InputType.TYPE_CLASS_NUMBER)
BottomSheetFragment.newCreate(this, parent, data)
}
else -> super.editingDescriptors(map)
}
}

@ -1,17 +1,23 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowViewType
enum class GameRow : RowRepresentable, DefaultEditDataSource {
enum class GameRow : RowRepresentable {
NAME,
SHORT_NAME;
override val resId: Int?
get() {
return when (this) {
NAME -> R.string.name
SHORT_NAME -> R.string.short_name
}
}
@ -19,6 +25,7 @@ enum class GameRow : RowRepresentable, DefaultEditDataSource {
override val viewType: Int
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
SHORT_NAME -> RowViewType.TITLE_VALUE.ordinal
}
}
@ -26,8 +33,22 @@ enum class GameRow : RowRepresentable, DefaultEditDataSource {
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
SHORT_NAME -> BottomSheetType.EDIT_TEXT
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is Game) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
NAME -> data.append(dataSource.name)
SHORT_NAME -> data.append(dataSource.shortName)
}
BottomSheetFragment.newCreate(this, parent, data)
}
}

@ -1,19 +1,26 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.Location
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowViewType
enum class LocationRow : RowRepresentable, DefaultEditDataSource {
enum class LocationRow : RowRepresentable {
NAME,
LOCATION_PERMISSION_SWITCH,
LOCATION_LOADER;
override val resId: Int?
get() {
return when (this) {
NAME -> R.string.name
LOCATION_PERMISSION_SWITCH -> R.string.geo_locate
LOCATION_LOADER -> null
}
@ -22,6 +29,7 @@ enum class LocationRow : RowRepresentable, DefaultEditDataSource {
override val viewType: Int
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
LOCATION_PERMISSION_SWITCH -> RowViewType.TITLE_SWITCH.ordinal
LOCATION_LOADER -> RowViewType.LOADER.ordinal
}
@ -30,9 +38,23 @@ enum class LocationRow : RowRepresentable, DefaultEditDataSource {
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
LOCATION_PERMISSION_SWITCH -> BottomSheetType.NONE
LOCATION_LOADER -> BottomSheetType.NONE
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is Location) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
NAME -> data.append(dataSource.name)
else -> PokerAnalyticsException.BottomSheetException
}
BottomSheetFragment.newCreate(this, parent, data)
}
}

@ -273,129 +273,4 @@ enum class SessionRow : RowRepresentable {
}
return data
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (this) {
BLINDS -> {
val sb: String? by map
val bb: String? by map
arrayListOf(
RowRepresentableEditDescriptor(
sb, R.string.smallblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
),
RowRepresentableEditDescriptor(
bb, R.string.bigblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
}
BUY_IN -> {
val bb: Double? by map
val fee: Double? by map
val ratedBuyin: Double? by map
val data = arrayListOf<RowRepresentableEditDescriptor>()
if (bb != null) {
data.add(RowRepresentableEditDescriptor(100.0 * (bb ?: 0.0)))
data.add(RowRepresentableEditDescriptor(200.0 * (bb ?: 0.0)))
} else if (fee != null) {
data.add(RowRepresentableEditDescriptor((fee ?: 0.0) * 1.0))
data.add(RowRepresentableEditDescriptor((fee ?: 0.0) * 2.0))
} else {
data.add(RowRepresentableEditDescriptor(0))
data.add(RowRepresentableEditDescriptor(0))
}
data.add(RowRepresentableEditDescriptor(ratedBuyin))
data.add(
RowRepresentableEditDescriptor(
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
data.add(
RowRepresentableEditDescriptor(
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
data
}
CASHED_OUT, PRIZE, NET_RESULT -> {
val defaultValue: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue,
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
)
)
}
COMMENT -> {
val defaultValue: String? by map
arrayListOf(RowRepresentableEditDescriptor(defaultValue, R.string.comment))
}
BREAK_TIME -> {
arrayListOf(
RowRepresentableEditDescriptor(
hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
GAME -> {
val limit: Int? by map
val defaultValue: Any? by map
val data: RealmResults<RowRepresentable>? by map
arrayListOf(
RowRepresentableEditDescriptor(limit),
RowRepresentableEditDescriptor(defaultValue, data = data)
)
}
INITIAL_BUY_IN -> {
val defaultValue: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
BANKROLL, LOCATION, TOURNAMENT_FEATURE, TOURNAMENT_NAME -> {
val defaultValue: Any? by map
val data: RealmResults<RowRepresentable>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, data = data)
)
}
PLAYERS -> {
val defaultValue: Int? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue?.toString(),
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
POSITION -> {
val defaultValue: Int? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue,
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
TABLE_SIZE -> {
val defaultValue: Int? by map
arrayListOf(RowRepresentableEditDescriptor(defaultValue))
}
TOURNAMENT_TYPE -> {
val defaultValue: Any? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, staticData = TournamentType.values().map {
it
})
)
}
else -> null
}
}
}

@ -2,12 +2,11 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
enum class SimpleRow : RowRepresentable, DefaultEditDataSource {
enum class SimpleRow : RowRepresentable {
NAME;
override val resId: Int? = R.string.name

@ -1,6 +1,49 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.TournamentFeature
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowViewType
enum class TournamentFeatureRow : RowRepresentable, DefaultEditDataSource
enum class TournamentFeatureRow : RowRepresentable {
NAME;
override val resId: Int?
get() {
return when (this) {
NAME -> R.string.name
}
}
override val viewType: Int
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
}
}
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is TournamentFeature) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
NAME -> data.append(dataSource.name)
}
BottomSheetFragment.newCreate(this, parent, data)
}
}

@ -1,6 +1,49 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.TournamentName
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowViewType
enum class TournamentNameRow : RowRepresentable, DefaultEditDataSource
enum class TournamentNameRow : RowRepresentable {
NAME;
override val resId: Int?
get() {
return when (this) {
NAME -> R.string.name
}
}
override val viewType: Int
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
}
}
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is TournamentName) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
NAME -> data.append(dataSource.name)
}
BottomSheetFragment.newCreate(this, parent, data)
}
}

@ -1,16 +1,22 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import androidx.fragment.app.Fragment
import io.realm.RealmResults
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Bankroll
import net.pokeranalytics.android.model.realm.Transaction
import net.pokeranalytics.android.model.realm.TransactionType
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.helpers.DateTimePickerManager
import net.pokeranalytics.android.ui.view.*
import net.pokeranalytics.android.util.extensions.round
import net.pokeranalytics.android.util.extensions.sorted
enum class TransactionRow : RowRepresentable, DefaultEditDataSource {
enum class TransactionRow : RowRepresentable {
BANKROLL,
TYPE,
AMOUNT,
@ -50,37 +56,46 @@ enum class TransactionRow : RowRepresentable, DefaultEditDataSource {
}
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (this) {
BANKROLL -> {
val defaultValue : Any? by map
val data : RealmResults<RowRepresentable>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, data = data)
)
}
TYPE -> {
val defaultValue : Any? by map
val data : RealmResults<RowRepresentable>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, data = data)
)
}
AMOUNT -> {
val defaultValue: String? by map
arrayListOf(
RowRepresentableEditDescriptor(
defaultValue,
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
))
}
COMMENT -> {
val defaultValue : String? by map
arrayListOf(RowRepresentableEditDescriptor(defaultValue, R.string.comment))
}
else -> super<RowRepresentable>.editingDescriptors(map)
}
}
override val valueCanBeClearedWhenEditing: Boolean
get() {
return when (this) {
DATE -> false
else -> true
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is Transaction) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
if (this == DATE) {
DateTimePickerManager.create(
parent.requireContext(),
this,
parent,
dataSource.date,
onlyDate = true,
isClearable = false)
} else {
when (this) {
BANKROLL -> data.append(
dataSource.bankroll,
data = dataSource.realm.sorted<Bankroll>() as RealmResults<RowRepresentable>
)
TYPE -> data.append(
dataSource.type,
data = dataSource.realm.sorted<TransactionType>() as RealmResults<RowRepresentable>
)
AMOUNT -> data.append(
(if (dataSource.amount != 0.0) dataSource.amount.round() else ""),
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED
)
COMMENT -> data.append(dataSource.comment, R.string.comment)
}
BottomSheetFragment.newCreate(this, parent, data)
}
}
}

@ -1,17 +1,24 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.TransactionType
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.view.DefaultEditDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowViewType
enum class TransactionTypeRow : RowRepresentable, DefaultEditDataSource {
enum class TransactionTypeRow : RowRepresentable {
NAME,
TRANSACTION_ADDITIVE;
override val resId: Int?
get() {
return when (this) {
NAME -> R.string.name
TRANSACTION_ADDITIVE -> R.string.additive
}
}
@ -19,6 +26,7 @@ enum class TransactionTypeRow : RowRepresentable, DefaultEditDataSource {
override val viewType: Int
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
TRANSACTION_ADDITIVE -> RowViewType.TITLE_SWITCH.ordinal
}
}
@ -26,10 +34,24 @@ enum class TransactionTypeRow : RowRepresentable, DefaultEditDataSource {
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
TRANSACTION_ADDITIVE -> BottomSheetType.NONE
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (dataSource == null) return
if (dataSource !is TransactionType) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
when (this) {
NAME -> data.append(dataSource.name)
else -> PokerAnalyticsException.BottomSheetException
}
BottomSheetFragment.newCreate(this, parent, data)
}
}

Loading…
Cancel
Save