clean up bottom sheet and datetimepicker management

refactoring some name for clarity
dev^2
Razmig Sarkissian 6 years ago
parent 8835a7d4d6
commit e8f83ba08b
  1. 3
      app/src/main/java/net/pokeranalytics/android/exceptions/Exceptions.kt
  2. 9
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  3. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/CustomField.kt
  4. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/CustomFieldEntry.kt
  5. 5
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  6. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  7. 9
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableAdapter.kt
  8. 1
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt
  9. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FiltersListFragment.kt
  10. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetDoubleEditTextFragment.kt
  11. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetEditTextFragment.kt
  12. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetEditTextMultiLinesFragment.kt
  13. 68
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  14. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListFragment.kt
  15. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListGameFragment.kt
  16. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetMultiSelectionFragment.kt
  17. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetNumericTextFragment.kt
  18. 14
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetStaticListFragment.kt
  19. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetSumFragment.kt
  20. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt
  21. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/CustomFieldDataFragment.kt
  22. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionDataFragment.kt
  23. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionTypeDataFragment.kt
  24. 72
      app/src/main/java/net/pokeranalytics/android/ui/helpers/DateTimePickerManager.kt
  25. 93
      app/src/main/java/net/pokeranalytics/android/ui/view/RowEditableDescriptor.kt
  26. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  27. 25
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentableEditDescriptor.kt
  28. 7
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/BankrollRow.kt
  29. 13
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/CustomFieldRow.kt
  30. 18
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  31. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/GameRow.kt
  32. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/LocationRow.kt
  33. 387
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt
  34. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentFeatureRow.kt
  35. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentNameRow.kt
  36. 49
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt
  37. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionTypeRow.kt

@ -21,7 +21,8 @@ sealed class PokerAnalyticsException(message: String) : Exception(message) {
object QueryTypeUnhandled: PokerAnalyticsException(message = "queryWith type not handled")
object QueryValueMapUnexpectedValue: PokerAnalyticsException(message = "valueMap null not expected")
object FilterElementExpectedValueMissing : PokerAnalyticsException(message = "queryWith is empty or null")
object BottomSheetException : PokerAnalyticsException(message = "Issue when creating a bottomsheet")
object BottomSheetException : PokerAnalyticsException(message = "RowEditableDelegate must be a Fragment")
object DateTimePickerException: PokerAnalyticsException(message = "DataSource is not a DateRowEditableDescriptor")
data class FilterElementTypeMissing(val filterElementRow: FilterElementRow) : PokerAnalyticsException(message = "queryWith element '$filterElementRow' type is missing")
data class QueryValueMapMissingKeys(val missingKeys: List<String>) : PokerAnalyticsException(message = "valueMap does not contain $missingKeys")
data class UnknownQueryTypeForRow(val filterElementRow: FilterElementRow) : PokerAnalyticsException(message = "no queryWith type for $filterElementRow")

@ -45,6 +45,15 @@ open class Bankroll : RealmObject(), NameManageable, RowRepresentable {
return this.currency?.rate ?: Currency.DEFAULT_RATE
}
val javaCurrency: java.util.Currency
get() {
return currency?.code?.let {
java.util.Currency.getInstance(it)
} ?: run {
UserDefaults.currency
}
}
override fun getDisplayName(context: Context): String {
return this.name
}

@ -20,8 +20,7 @@ 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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomFieldRow
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
@ -133,13 +132,13 @@ open class CustomField : RealmObject(), NameManageable, StaticRowRepresentableDa
if (dataSource !is Session) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
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)
BottomSheetFragment.create(this, parent, data)
}
override fun updateValue(value: Any?, row: RowRepresentable) {

@ -20,7 +20,7 @@ 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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.toCurrency
@ -97,9 +97,9 @@ open class CustomFieldEntry : RealmObject(), NameManageable, RowRepresentable {
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
data.append(this.value, R.string.value, InputType.TYPE_CLASS_TEXT)
BottomSheetFragment.newCreate(this, parent, data, isDeletable = true)
BottomSheetFragment.create(this, parent, data, isDeletable = true)
}
override val valueCanBeClearedWhenEditing: Boolean

@ -1,7 +1,6 @@
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
@ -215,8 +214,8 @@ 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()
val data = RowEditableDataSource()
data.append(this.name)
BottomSheetFragment.newCreate(this, parent, data, isDeletable = true, valueHasPlaceholder = false)
BottomSheetFragment.create(this, parent, data, isDeletable = true, valueHasPlaceholder = false)
}
}

@ -14,9 +14,7 @@ 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.GameRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.NULL_TEXT
import java.util.*
import kotlin.collections.ArrayList

@ -7,10 +7,13 @@ import net.pokeranalytics.android.ui.view.BindableHolder
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
interface RowRepresentableDelegate {
interface RowRepresentableDelegate: RowEditableDelegate {
fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean = false) {}
fun onRowValueChanged(value: Any?, row: RowRepresentable) {}
fun onRowDeleted(row: RowRepresentable) {}
}
interface RowEditableDelegate {
fun onRowValueChanged(value: Any?, row: RowRepresentable) {}
fun onRowDeleted(row: RowRepresentable) {}
}
/**

@ -3,7 +3,6 @@ package net.pokeranalytics.android.ui.adapter
import android.content.Context
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.util.TextFormat
/**

@ -10,10 +10,8 @@ import net.pokeranalytics.android.model.interfaces.Identifiable
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.activity.FiltersActivity
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.interfaces.FilterHandler.Companion.INTENT_FILTER_UPDATE_FILTER_UI
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.util.Preferences
import timber.log.Timber

@ -52,9 +52,9 @@ class BottomSheetDoubleEditTextFragment(row: RowRepresentable) : BottomSheetFrag
* Init UI
*/
private fun initUI() {
val data = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val data = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (data.size != 2) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
values.add(0, "")

@ -51,9 +51,9 @@ class BottomSheetEditTextFragment(row: RowRepresentable) : BottomSheetFragment(r
*/
private fun initUI() {
val data = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val data = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (data.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_edit_text, view?.bottomSheetContainer, true)

@ -43,9 +43,9 @@ class BottomSheetEditTextMultiLinesFragment(row: RowRepresentable) : BottomSheet
* Init UI
*/
private fun initUI() {
val data = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val data = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (data.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
LayoutInflater.from(requireContext()).inflate(net.pokeranalytics.android.R.layout.bottom_sheet_edit_text_multi_lines, view?.bottomSheetContainer, true)

@ -11,7 +11,6 @@ import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.view.ContextThemeWrapper
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import io.realm.RealmModel
import kotlinx.android.synthetic.main.fragment_bottom_sheet.*
@ -21,10 +20,10 @@ import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.adapter.RowEditableDelegate
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
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.helpers.DateTimePickerManager
import net.pokeranalytics.android.ui.view.*
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
import net.pokeranalytics.android.ui.view.rowrepresentable.TransactionRow
import java.util.*
@ -32,59 +31,38 @@ import java.util.*
open class BottomSheetFragment(val row: RowRepresentable) : BottomSheetDialogFragment() {
// lateinit var row: RowRepresentable
lateinit var delegate: RowRepresentableDelegate
lateinit var delegate: RowEditableDelegate
var currentCurrency: Currency? = null
var valueHasPlaceholder: Boolean = false
private var isClearable: Boolean = true
private var isDeletable: Boolean = false
private var rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>? = null
private var rowEditableDescriptors: ArrayList<RowEditableDescriptor>? = null
companion object {
const val REQUEST_CODE_ADD_NEW_OBJECT = 100
fun create(
fragmentManager: FragmentManager?,
row: RowRepresentable,
delegate: RowRepresentableDelegate,
rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>?,
isClearable: Boolean? = true,
currentCurrency: Currency? = null,
isDeletable: Boolean? = false,
valueHasPlaceholder: Boolean? = null
): BottomSheetFragment {
val bottomSheetFragment = row.bottomSheetType.newInstance(row)
bottomSheetFragment.show(fragmentManager, "bottomSheet")
// bottomSheetFragment.row = row
bottomSheetFragment.delegate = delegate
bottomSheetFragment.rowRepresentableEditDescriptors = rowRepresentableEditDescriptors
bottomSheetFragment.isClearable = isClearable ?: true
bottomSheetFragment.isDeletable = isDeletable ?: true
bottomSheetFragment.valueHasPlaceholder = valueHasPlaceholder ?: true
bottomSheetFragment.currentCurrency = currentCurrency
return bottomSheetFragment
}
fun newCreate(
fun create(
row: RowRepresentable,
delegate: RowRepresentableDelegate,
dataSource: RowRepresentableEditData?,
delegate: RowEditableDelegate,
dataSource: RowEditableDataSource?,
isDeletable: Boolean? = false,
valueHasPlaceholder: Boolean? = null
): BottomSheetFragment {
) {
if (delegate !is Fragment) throw PokerAnalyticsException.BottomSheetException
val bottomSheetFragment = row.bottomSheetType.newInstance(row)
bottomSheetFragment.show(delegate.fragmentManager, "bottomSheet")
bottomSheetFragment.delegate = delegate
bottomSheetFragment.rowRepresentableEditDescriptors = dataSource?.descriptors
bottomSheetFragment.isClearable = row.valueCanBeClearedWhenEditing
bottomSheetFragment.isDeletable = isDeletable ?: true
bottomSheetFragment.valueHasPlaceholder = valueHasPlaceholder ?: true
bottomSheetFragment.currentCurrency = dataSource?.currency
return bottomSheetFragment
if (dataSource?.descriptorType == RowEditableDescriptorType.DATE) {
DateTimePickerManager.create(row, delegate, dataSource.descriptors.first())
} else {
val bottomSheetFragment = row.bottomSheetType.newInstance(row)
bottomSheetFragment.show(delegate.fragmentManager, "bottomSheet")
bottomSheetFragment.delegate = delegate
bottomSheetFragment.rowEditableDescriptors = dataSource?.descriptors
bottomSheetFragment.isClearable = row.valueCanBeClearedWhenEditing
bottomSheetFragment.isDeletable = isDeletable ?: true
bottomSheetFragment.valueHasPlaceholder = valueHasPlaceholder ?: true
bottomSheetFragment.currentCurrency = dataSource?.currency
}
}
}
@ -182,8 +160,8 @@ open class BottomSheetFragment(val row: RowRepresentable) : BottomSheetDialogFra
/**
* Return the data list
*/
fun getData(): ArrayList<RowRepresentableEditDescriptor>? {
return this.rowRepresentableEditDescriptors
fun getData(): ArrayList<RowEditableDescriptor>? {
return this.rowEditableDescriptors
}
open fun getValue(): Any? {

@ -13,6 +13,7 @@ import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorExcep
import net.pokeranalytics.android.ui.adapter.LiveRowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.view.DataRowEditableDescriptor
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
@ -69,14 +70,14 @@ open class BottomSheetListFragment(row: RowRepresentable) : BottomSheetFragment(
* Init data
*/
open fun initData() {
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (bottomSheetData.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
if (bottomSheetData.first().data == null) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
this.realmData = bottomSheetData.first().data as RealmResults<RowRepresentable>
val dataList = bottomSheetData[0]
if (dataList !is DataRowEditableDescriptor) { throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") }
if (dataList.data == null) { throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") }
this.realmData = dataList.data
}
/**

@ -13,6 +13,7 @@ import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorExcep
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.extensions.px
import net.pokeranalytics.android.ui.view.DataRowEditableDescriptor
import net.pokeranalytics.android.ui.view.RowRepresentable
/**
@ -49,15 +50,15 @@ class BottomSheetListGameFragment(row: RowRepresentable) : BottomSheetListFragme
* Init data
*/
override fun initData() {
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (bottomSheetData.size != 2) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
if (bottomSheetData[1].data == null) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
val dataList = bottomSheetData[1]
if (dataList !is DataRowEditableDescriptor) { throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") }
if (dataList.data == null) { throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") }
this.realmData = dataList.data
this.limit = bottomSheetData[0].defaultValue as Int?
this.realmData = bottomSheetData[1].data
}
/**

@ -54,9 +54,9 @@ open class BottomSheetMultiSelectionFragment(row: RowRepresentable) : BottomShee
override fun initData() {
super.initData()
val bottomSheetData =
getData() ?: throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
getData() ?: throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (bottomSheetData.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
bottomSheetData.first().defaultValue?.let {
(it as RealmList<*>).forEach { row ->

@ -43,9 +43,9 @@ class BottomSheetNumericTextFragment(row: RowRepresentable) : BottomSheetFragmen
* Init UI
*/
private fun initUI() {
val data = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val data = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (data.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_edit_text, view?.bottomSheetContainer, true)

@ -11,7 +11,9 @@ import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorExcep
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.view.DataRowEditableDescriptor
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.StaticDataRowEditableDescriptor
class BottomSheetStaticListFragment(row: RowRepresentable) : BottomSheetFragment(row), StaticRowRepresentableDataSource,
RowRepresentableDelegate {
@ -44,14 +46,14 @@ class BottomSheetStaticListFragment(row: RowRepresentable) : BottomSheetFragment
* Init data
*/
private fun initData() {
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (bottomSheetData.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
if (bottomSheetData.first().staticData == null) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
this.staticRows = bottomSheetData.first().staticData as List<RowRepresentable>
val dataList = bottomSheetData[0]
if (dataList !is StaticDataRowEditableDescriptor) { throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") }
if (dataList.staticData == null) { throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency") }
this.staticRows= dataList.staticData as List<RowRepresentable>
}
/**

@ -50,9 +50,9 @@ class BottomSheetSumFragment(row: RowRepresentable) : BottomSheetFragment(row) {
* Init UI
*/
private fun initUI() {
val data = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val data = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (data.size != 5) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_sum, view?.bottomSheetContainer, true)

@ -39,9 +39,9 @@ class BottomSheetTableSizeGridFragment(row: RowRepresentable) : BottomSheetFragm
* Init data
*/
private fun initData() {
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowEditableDescriptor not found")
if (bottomSheetData.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
}
defaultSize = bottomSheetData.first().defaultValue as Int?
}

@ -141,7 +141,7 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
}
/*
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
override fun editDescriptors(row: RowRepresentable): ArrayList<RowEditableDescriptor>? {
return when (row) {
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.customField.name))
is CustomFieldEntry -> row.editingDescriptors(mapOf("defaultValue" to row.value))

@ -7,20 +7,14 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import net.pokeranalytics.android.calculus.bankroll.BankrollReportManager
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.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
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.rowrepresentable.TransactionRow
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.round
import net.pokeranalytics.android.util.extensions.shortDate
import net.pokeranalytics.android.util.extensions.sorted
import java.util.*
/**
* Custom EditableDataFragment to manage the Transaction data

@ -4,7 +4,6 @@ import net.pokeranalytics.android.model.realm.Transaction
import net.pokeranalytics.android.model.realm.TransactionType
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
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

@ -8,9 +8,13 @@ import android.text.format.DateFormat
import android.widget.DatePicker
import android.widget.TimePicker
import android.widget.Toast
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.ui.adapter.RowEditableDelegate
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.view.*
import java.util.*
class DateTimePickerManager : DatePickerDialog.OnDateSetListener,
@ -19,7 +23,7 @@ class DateTimePickerManager : DatePickerDialog.OnDateSetListener,
private var context: Context? = null
private lateinit var row: RowRepresentable
private lateinit var delegate: RowRepresentableDelegate
private lateinit var delegate: RowEditableDelegate
private lateinit var calendar: Calendar
private var minimumDate: Date? = null
private var onlyDate: Boolean = false
@ -27,73 +31,33 @@ class DateTimePickerManager : DatePickerDialog.OnDateSetListener,
private var isClearable: Boolean = true
companion object {
fun create(
context: Context,
row: RowRepresentable,
delegate: RowRepresentableDelegate,
date: Date?,
minimumDate: Date? = null,
onlyDate: Boolean? = false,
onlyTime: Boolean? = false,
isClearable: Boolean? = true
): DateTimePickerManager {
val calendar = Calendar.getInstance()
calendar.time = date ?: Date()
val dateTimePickerManager = DateTimePickerManager()
dateTimePickerManager.context = context
dateTimePickerManager.row = row
dateTimePickerManager.delegate = delegate
dateTimePickerManager.calendar = calendar
dateTimePickerManager.minimumDate = minimumDate
dateTimePickerManager.onlyDate = onlyDate ?: false
dateTimePickerManager.onlyTime = onlyTime ?: false
dateTimePickerManager.isClearable = isClearable ?: true
if (dateTimePickerManager.onlyTime) {
dateTimePickerManager.showTimePicker()
} else {
dateTimePickerManager.showDatePicker()
}
return dateTimePickerManager
}
fun newCreate(
context: Context,
fun create(
row: RowRepresentable,
delegate: RowRepresentableDelegate,
date: Date?,
minimumDate: Date? = null,
onlyDate: Boolean? = false,
onlyTime: Boolean? = false,
isClearable: Boolean? = true
): DateTimePickerManager {
delegate: RowEditableDelegate,
dataSource: RowEditableDescriptor
) {
if (delegate !is Fragment) throw PokerAnalyticsException.BottomSheetException
if (dataSource !is DateRowEditableDescriptor) throw PokerAnalyticsException.DateTimePickerException
val calendar = Calendar.getInstance()
calendar.time = date ?: Date()
calendar.time = dataSource.date ?: Date()
val dateTimePickerManager = DateTimePickerManager()
dateTimePickerManager.context = context
dateTimePickerManager.context = delegate.context
dateTimePickerManager.row = row
dateTimePickerManager.delegate = delegate
dateTimePickerManager.calendar = calendar
dateTimePickerManager.minimumDate = minimumDate
dateTimePickerManager.onlyDate = onlyDate ?: false
dateTimePickerManager.onlyTime = onlyTime ?: false
dateTimePickerManager.isClearable = isClearable ?: true
dateTimePickerManager.minimumDate = dataSource.minimumDate
dateTimePickerManager.onlyDate = dataSource.onlyDate
dateTimePickerManager.onlyTime = dataSource.onlyTime
dateTimePickerManager.isClearable = row.valueCanBeClearedWhenEditing
if (dateTimePickerManager.onlyTime) {
dateTimePickerManager.showTimePicker()
} else {
dateTimePickerManager.showDatePicker()
}
return dateTimePickerManager
}
}
override fun onDateSet(view: DatePicker?, year: Int, month: Int, dayOfMonth: Int) {

@ -0,0 +1,93 @@
package net.pokeranalytics.android.ui.view
import io.realm.RealmResults
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorException
import net.pokeranalytics.android.util.UserDefaults
import java.util.*
import kotlin.collections.ArrayList
/**
* An container class to describe the way an field of an object will be edited
*/
enum class RowEditableDescriptorType {
DATE,
DATA,
STATIC,
DEFAULT
}
open class RowEditableDescriptor(var defaultValue: Any? = null,
var hint: Int? = null,
var inputType: Int? = null)
class DateRowEditableDescriptor(date: Date? = null,
val minimumDate: Date? = null,
var onlyDate: Boolean = false,
var onlyTime: Boolean = false): RowEditableDescriptor(defaultValue = date) {
val date: Date?
get() {
return defaultValue as Date?
}
}
class DataRowEditableDescriptor(
defaultValue: Any? = null,
hint: Int? = null,
inputType: Int? = null,
data: RealmResults<*>? = null): RowEditableDescriptor(defaultValue, hint, inputType) {
var data: RealmResults<RowRepresentable>? = null
init {
if (data != null && data.count() > 0) {
if (data.first() is RowRepresentable) {
this.data = data as RealmResults<RowRepresentable>?
}
}
}
}
class StaticDataRowEditableDescriptor(
defaultValue: Any? = null,
hint: Int? = null,
inputType: Int? = null,
var staticData: List<RowRepresentable>? = null): RowEditableDescriptor(defaultValue, hint, inputType) {
}
class RowEditableDataSource(customCurrency: Currency? = null) {
var currency: Currency = UserDefaults.currency
init {
customCurrency?.let { currency = it }
}
var descriptors = ArrayList<RowEditableDescriptor>()
fun append(defaultValue: Any? = null, hint: Int? = null, inputType: Int? = null, data: RealmResults<*>? = null, staticData: List<RowRepresentable>? = null) {
when {
data != null -> descriptors.add(DataRowEditableDescriptor(defaultValue, hint, inputType, data))
staticData != null -> descriptors.add(StaticDataRowEditableDescriptor(defaultValue, hint, inputType, staticData))
else -> descriptors.add(RowEditableDescriptor(defaultValue, hint, inputType))
}
}
fun appendDateDescriptor(date:Date?= null,
minimumDate: Date? = null,
onlyDate: Boolean = false,
onlyTime: Boolean = false) {
descriptors.add(DateRowEditableDescriptor(date, minimumDate, onlyDate, onlyTime))
}
val descriptorType: RowEditableDescriptorType
get() {
return when (descriptors.firstOrNull()) {
null -> throw RowRepresentableEditDescriptorException("RowEditableDescriptor inconsistency")
is DateRowEditableDescriptor -> RowEditableDescriptorType.DATE
is DataRowEditableDescriptor -> RowEditableDescriptorType.DATA
is StaticDataRowEditableDescriptor -> RowEditableDescriptorType.STATIC
else -> RowEditableDescriptorType.DEFAULT
}
}
}

@ -3,21 +3,20 @@ package net.pokeranalytics.android.ui.view
import android.content.Context
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.util.NULL_TEXT
/**
* An interface extending Displayable to add a way to represent an object as a String
*/
interface RowRepresentable : Displayable, EditDataSource, ImageDecorator {
interface RowRepresentable : Displayable, RowEditable, ImageDecorator {
fun getDisplayName(context: Context): String {
return NULL_TEXT
}
}
interface EditDataSource {
interface RowEditable {
fun startEditing(dataSource:Any?, parent:Fragment?) {}
val valueCanBeClearedWhenEditing: Boolean

@ -1,25 +0,0 @@
package net.pokeranalytics.android.ui.view
import io.realm.RealmResults
import net.pokeranalytics.android.util.UserDefaults
import java.util.*
import kotlin.collections.ArrayList
/**
* An container class to describe the way an field of an object will be edited
*/
class RowRepresentableEditDescriptor(
var defaultValue: Any? = null,
var hint: Int? = null,
var inputType: Int? = null,
var data: RealmResults<RowRepresentable>? = null,
var staticData: List<RowRepresentable>? = null
)
class RowRepresentableEditData(val currency: Currency = UserDefaults.currency) {
var descriptors = ArrayList<RowRepresentableEditDescriptor>()
fun append(defaultValue: Any? = null, hint: Int? = null, inputType: Int? = null, data: RealmResults<RowRepresentable>? = null, staticData: List<RowRepresentable>? = null) {
descriptors.add(RowRepresentableEditDescriptor(defaultValue, hint, inputType, data, staticData))
}
}

@ -9,6 +9,7 @@ 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.*
import java.util.*
enum class BankrollRow : RowRepresentable {
NAME,
@ -59,13 +60,15 @@ enum class BankrollRow : RowRepresentable {
if (dataSource !is Bankroll) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val bankrollCurrency: Currency? = dataSource.currency?.code?.let { Currency.getInstance(it) }
val data = RowEditableDataSource(bankrollCurrency)
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)
BottomSheetFragment.create(this, parent, data)
}
}

@ -4,12 +4,11 @@ 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.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
enum class CustomFieldRow : RowRepresentable {
@ -67,19 +66,19 @@ enum class CustomFieldRow : RowRepresentable {
/*
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowEditableDescriptor>? {
return when (type) {
Type.LIST.uniqueIdentifier -> {
val defaultValue: Any? by map
val data: RealmList<CustomFieldEntry>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, staticData = data)
RowEditableDescriptor(defaultValue, staticData = data)
)
}
else -> {
val defaultValue: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(
RowEditableDescriptor(
defaultValue, inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
@ -94,11 +93,11 @@ enum class CustomFieldRow : RowRepresentable {
if (dataSource !is CustomField) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
when (this) {
NAME -> data.append(dataSource.name)
else -> PokerAnalyticsException.BottomSheetException
}
BottomSheetFragment.newCreate(this, parent, data)
BottomSheetFragment.create(this, parent, data)
}
}

@ -4,28 +4,20 @@ 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.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.RowRepresentableEditData
import net.pokeranalytics.android.ui.view.RowEditableDataSource
interface FilterElementRow : RowRepresentable {
override fun startEditing(dataSource: Any?, parent: Fragment?) {
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
when (this) {
is QueryCondition.DateQuery -> DateTimePickerManager.create(
parent.requireContext(),
this,
parent,
this.singleValue,
onlyDate = !this.showTime,
onlyTime = this.showTime
)
is QueryCondition.DateQuery -> data.appendDateDescriptor(this.singleValue, onlyDate = !this.showTime, onlyTime = this.showTime)
is QueryCondition.Duration -> {
var hours: String? = null
var minutes: String? = null
@ -35,7 +27,6 @@ interface FilterElementRow : RowRepresentable {
}
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<*> -> {
var valueAsString: String? = null
@ -53,9 +44,10 @@ interface FilterElementRow : RowRepresentable {
else -> this.resId
}
data.append(valueAsString, hint, inputType = InputType.TYPE_CLASS_NUMBER)
BottomSheetFragment.newCreate(this, parent, data)
}
}
BottomSheetFragment.create(this, parent, data)
}
var filterSectionRow: FilterSectionRow

@ -7,7 +7,7 @@ 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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
enum class GameRow : RowRepresentable {
@ -43,12 +43,12 @@ enum class GameRow : RowRepresentable {
if (dataSource !is Game) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
when (this) {
NAME -> data.append(dataSource.name)
SHORT_NAME -> data.append(dataSource.shortName)
}
BottomSheetFragment.newCreate(this, parent, data)
BottomSheetFragment.create(this, parent, data)
}
}

@ -8,7 +8,7 @@ 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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
@ -50,11 +50,11 @@ enum class LocationRow : RowRepresentable {
if (dataSource !is Location) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
when (this) {
NAME -> data.append(dataSource.name)
else -> PokerAnalyticsException.BottomSheetException
}
BottomSheetFragment.newCreate(this, parent, data)
BottomSheetFragment.create(this, parent, data)
}
}

@ -3,7 +3,6 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import android.widget.Toast
import androidx.fragment.app.Fragment
import io.realm.RealmResults
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.TournamentType
import net.pokeranalytics.android.model.extensions.SessionState
@ -14,174 +13,173 @@ import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheet
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.helpers.DateTimePickerManager
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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.round
import net.pokeranalytics.android.util.extensions.sorted
import java.util.*
import kotlin.collections.ArrayList
enum class SessionRow : RowRepresentable {
PRIZE,
CASHED_OUT,
NET_RESULT,
INITIAL_BUY_IN,
BUY_IN,
POSITION,
PLAYERS,
TIPS,
PRIZE,
CASHED_OUT,
NET_RESULT,
INITIAL_BUY_IN,
BUY_IN,
POSITION,
PLAYERS,
TIPS,
GAME,
BLINDS,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
START_DATE,
END_DATE,
GAME,
BLINDS,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
START_DATE,
END_DATE,
BREAK_TIME,
COMMENT;
BREAK_TIME,
COMMENT;
companion object {
/**
* Return the rows to display for the current session state
*/
fun getRows(session: Session): List<RowRepresentable> {
when (session.type) {
Session.Type.TOURNAMENT.ordinal -> {
return when (session.getState()) {
SessionState.PENDING, SessionState.PLANNED -> {
arrayListOf(
GAME,
INITIAL_BUY_IN,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
START_DATE,
END_DATE
)
}
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> {
arrayListOf(
PRIZE,
BUY_IN,
POSITION,
PLAYERS,
TIPS,
COMMENT,
SeparatorRow(),
GAME,
INITIAL_BUY_IN,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
SeparatorRow(),
START_DATE,
END_DATE,
BREAK_TIME
)
}
}
}
Session.Type.CASH_GAME.ordinal -> {
when (session.getState()) {
SessionState.PENDING, SessionState.PLANNED -> {
return arrayListOf(GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE)
}
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> {
companion object {
/**
* Return the rows to display for the current session state
*/
fun getRows(session: Session): List<RowRepresentable> {
when (session.type) {
Session.Type.TOURNAMENT.ordinal -> {
return when (session.getState()) {
SessionState.PENDING, SessionState.PLANNED -> {
arrayListOf(
GAME,
INITIAL_BUY_IN,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
START_DATE,
END_DATE
)
}
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> {
arrayListOf(
PRIZE,
BUY_IN,
POSITION,
PLAYERS,
TIPS,
COMMENT,
SeparatorRow(),
GAME,
INITIAL_BUY_IN,
LOCATION,
BANKROLL,
TABLE_SIZE,
TOURNAMENT_TYPE,
TOURNAMENT_NAME,
TOURNAMENT_FEATURE,
SeparatorRow(),
START_DATE,
END_DATE,
BREAK_TIME
)
}
}
}
Session.Type.CASH_GAME.ordinal -> {
when (session.getState()) {
SessionState.PENDING, SessionState.PLANNED -> {
return arrayListOf(GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE)
}
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> {
val fields = mutableListOf<RowRepresentable>()
when {
session.hasBuyin -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS))
session.hasNetResult -> fields.add(NET_RESULT)
session.isLive -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS))
else -> fields.add(NET_RESULT)
}
fields.add(COMMENT)
fields.add(SeparatorRow())
fields.addAll(listOf(
GAME,
BLINDS,
LOCATION,
BANKROLL,
TABLE_SIZE,
START_DATE,
END_DATE,
BREAK_TIME
val fields = mutableListOf<RowRepresentable>()
when {
session.hasBuyin -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS))
session.hasNetResult -> fields.add(NET_RESULT)
session.isLive -> fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS))
else -> fields.add(NET_RESULT)
}
fields.add(COMMENT)
fields.add(SeparatorRow())
fields.addAll(
listOf(
GAME,
BLINDS,
LOCATION,
BANKROLL,
TABLE_SIZE,
START_DATE,
END_DATE,
BREAK_TIME
)
)
return fields
}
}
}
}
return arrayListOf()
}
}
)
)
return fields
}
}
}
}
return arrayListOf()
}
}
override val resId: Int?
get() {
return when (this) {
NET_RESULT -> R.string.net_result
PRIZE -> R.string.prize
POSITION -> R.string.position
PLAYERS -> R.string.players
CASHED_OUT -> R.string.cashed_out
INITIAL_BUY_IN -> R.string.initial_stack
BUY_IN -> R.string.buyin
TIPS -> R.string.tips
GAME -> R.string.game
BLINDS -> R.string.blinds
LOCATION -> R.string.location
BANKROLL -> R.string.bankroll
TABLE_SIZE -> R.string.table_size
TOURNAMENT_TYPE -> R.string.tournament_type
TOURNAMENT_NAME -> R.string.tournament_name
TOURNAMENT_FEATURE -> R.string.tournament_feature
START_DATE -> R.string.start_date
END_DATE -> R.string.end_date
BREAK_TIME -> R.string.break_time
COMMENT -> R.string.comment
}
}
override val resId: Int?
get() {
return when (this) {
NET_RESULT -> R.string.net_result
PRIZE -> R.string.prize
POSITION -> R.string.position
PLAYERS -> R.string.players
CASHED_OUT -> R.string.cashed_out
INITIAL_BUY_IN -> R.string.initial_stack
BUY_IN -> R.string.buyin
TIPS -> R.string.tips
GAME -> R.string.game
BLINDS -> R.string.blinds
LOCATION -> R.string.location
BANKROLL -> R.string.bankroll
TABLE_SIZE -> R.string.table_size
TOURNAMENT_TYPE -> R.string.tournament_type
TOURNAMENT_NAME -> R.string.tournament_name
TOURNAMENT_FEATURE -> R.string.tournament_feature
START_DATE -> R.string.start_date
END_DATE -> R.string.end_date
BREAK_TIME -> R.string.break_time
COMMENT -> R.string.comment
}
}
override val viewType: Int
get() {
return when (this) {
NET_RESULT, PRIZE, POSITION, PLAYERS, CASHED_OUT, INITIAL_BUY_IN, BUY_IN, TIPS,
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, COMMENT,
TOURNAMENT_TYPE, TOURNAMENT_NAME, TOURNAMENT_FEATURE, START_DATE, END_DATE, BREAK_TIME -> RowViewType.TITLE_VALUE.ordinal
}
}
override val viewType: Int
get() {
return when (this) {
NET_RESULT, PRIZE, POSITION, PLAYERS, CASHED_OUT, INITIAL_BUY_IN, BUY_IN, TIPS,
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, COMMENT,
TOURNAMENT_TYPE, TOURNAMENT_NAME, TOURNAMENT_FEATURE, START_DATE, END_DATE, BREAK_TIME -> RowViewType.TITLE_VALUE.ordinal
}
}
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> BottomSheetType.NUMERIC_TEXT
BUY_IN, TIPS -> BottomSheetType.SUM
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.LIST_GAME
TOURNAMENT_TYPE -> BottomSheetType.LIST_STATIC
LOCATION, BANKROLL, TOURNAMENT_NAME -> BottomSheetType.LIST
TOURNAMENT_FEATURE -> BottomSheetType.MULTI_SELECTION
TABLE_SIZE -> BottomSheetType.GRID
COMMENT -> BottomSheetType.EDIT_TEXT_MULTI_LINES
else -> BottomSheetType.NONE
}
}
override val bottomSheetType: BottomSheetType
get() {
return when (this) {
NET_RESULT, CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> BottomSheetType.NUMERIC_TEXT
BUY_IN, TIPS -> BottomSheetType.SUM
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.LIST_GAME
TOURNAMENT_TYPE -> BottomSheetType.LIST_STATIC
LOCATION, BANKROLL, TOURNAMENT_NAME -> BottomSheetType.LIST
TOURNAMENT_FEATURE -> BottomSheetType.MULTI_SELECTION
TABLE_SIZE -> BottomSheetType.GRID
COMMENT -> BottomSheetType.EDIT_TEXT_MULTI_LINES
else -> BottomSheetType.NONE
}
}
override fun startEditing(dataSource: Any?, parent: Fragment?) {
@ -190,39 +188,31 @@ enum class SessionRow : RowRepresentable {
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val session: Session = dataSource
val data = RowEditableDataSource(session.currency)
when (this) {
START_DATE -> DateTimePickerManager.create(parent.requireContext(), this, parent, dataSource.startDate)
START_DATE -> {
data.appendDateDescriptor(session.startDate)
}
END_DATE -> {
if (dataSource.startDate == null) {
if (session.startDate == null) {
Toast.makeText(parent.context, R.string.session_missing_start_date, Toast.LENGTH_SHORT).show()
return
} else {
DateTimePickerManager.create(
parent.requireContext(),
this,
parent,
dataSource.endDate ?: dataSource.startDate ?: Date(),
dataSource.startDate
)
data.appendDateDescriptor(session.endDate ?: session.startDate ?: Date(), session.startDate)
}
}
else -> BottomSheetFragment.newCreate(this, parent, this.editingData(dataSource))
}
}
override val valueCanBeClearedWhenEditing: Boolean
get() {
return when (this) {
BANKROLL -> false
else -> true
}
}
private fun editingData(session:Session): RowRepresentableEditData? {
val data = RowRepresentableEditData(session.currency)
when (this) {
BANKROLL -> data.append(session.bankroll, data = session.realm.sorted<Bankroll>() as RealmResults<RowRepresentable>)
CASHED_OUT, PRIZE -> data.append(session.result?.cashout, inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED)
NET_RESULT -> data.append(session.result?.netResult, inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED)
BANKROLL -> data.append(session.bankroll, data = session.realm.sorted<Bankroll>())
CASHED_OUT, PRIZE -> data.append(
session.result?.cashout,
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED
)
NET_RESULT -> data.append(
session.result?.netResult,
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED
)
INITIAL_BUY_IN -> data.append(session.tournamentEntryFee?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
BUY_IN -> {
val bb: Double? = session.cgBigBlind
@ -243,7 +233,10 @@ enum class SessionRow : RowRepresentable {
data.append(inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL)
}
POSITION -> data.append(session.result?.tournamentFinalPosition, inputType = InputType.TYPE_CLASS_NUMBER)
PLAYERS -> data.append(session.tournamentNumberOfPlayers.toString(), inputType = InputType.TYPE_CLASS_NUMBER)
PLAYERS -> data.append(
session.tournamentNumberOfPlayers.toString(),
inputType = InputType.TYPE_CLASS_NUMBER
)
TIPS -> {
val sb: String? = session.cgSmallBlind?.round()
val bb: String? = session.cgBigBlind?.round()
@ -256,21 +249,39 @@ enum class SessionRow : RowRepresentable {
}
GAME -> {
data.append(session.limit)
data.append(session.game, data = session.realm.sorted<Game>() as RealmResults<RowRepresentable>)
data.append(session.game, data = session.realm.sorted<Game>())
}
BLINDS -> {
data.append(session.cgSmallBlind?.round(), R.string.smallblind, InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL)
data.append(session.cgBigBlind?.round(), R.string.bigblind, InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL)
data.append(
session.cgSmallBlind?.round(),
R.string.smallblind,
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
data.append(
session.cgBigBlind?.round(),
R.string.bigblind,
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
}
LOCATION -> data.append(session.location, data = session.realm.sorted<Location>() as RealmResults<RowRepresentable>)
LOCATION -> data.append(session.location, data = session.realm.sorted<Location>())
TABLE_SIZE -> data.append(session.tableSize)
TOURNAMENT_TYPE -> data.append(session.tournamentType, staticData = TournamentType.values().map { it })
TOURNAMENT_NAME -> data.append(session.tournamentName, data = session.realm.sorted<TournamentName>() as RealmResults<RowRepresentable>)
TOURNAMENT_FEATURE -> data.append(session.tournamentFeatures, data = session.realm.sorted<TournamentFeature>() as RealmResults<RowRepresentable>)
TOURNAMENT_NAME -> data.append(session.tournamentName, data = session.realm.sorted<TournamentName>())
TOURNAMENT_FEATURE -> data.append(
session.tournamentFeatures,
data = session.realm.sorted<TournamentFeature>()
)
BREAK_TIME -> data.append(hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER)
COMMENT -> data.append(session.comment, R.string.comment)
else -> {}
}
return data
BottomSheetFragment.create(this, parent, data)
}
override val valueCanBeClearedWhenEditing: Boolean
get() {
return when (this) {
BANKROLL -> false
else -> true
}
}
}

@ -7,7 +7,7 @@ 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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
enum class TournamentFeatureRow : RowRepresentable {
@ -39,11 +39,11 @@ enum class TournamentFeatureRow : RowRepresentable {
if (dataSource !is TournamentFeature) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
when (this) {
NAME -> data.append(dataSource.name)
}
BottomSheetFragment.newCreate(this, parent, data)
BottomSheetFragment.create(this, parent, data)
}
}

@ -7,7 +7,7 @@ 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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
enum class TournamentNameRow : RowRepresentable {
@ -39,11 +39,11 @@ enum class TournamentNameRow : RowRepresentable {
if (dataSource !is TournamentName) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
when (this) {
NAME -> data.append(dataSource.name)
}
BottomSheetFragment.newCreate(this, parent, data)
BottomSheetFragment.create(this, parent, data)
}
}

@ -3,11 +3,11 @@ package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import androidx.fragment.app.Fragment
import io.realm.Realm
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.RowEditableDelegate
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
@ -69,34 +69,27 @@ enum class TransactionRow : RowRepresentable {
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 = Realm.getDefaultInstance().sorted<Bankroll>() as RealmResults<RowRepresentable>
)
TYPE -> data.append(
dataSource.type,
data = Realm.getDefaultInstance().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)
if (parent !is RowEditableDelegate) return
val data = RowEditableDataSource()
val realm = dataSource.realm?.let { it } ?: run { Realm.getDefaultInstance() }
when (this) {
DATE -> {
data.appendDateDescriptor(dataSource.date, onlyDate = true)
}
BottomSheetFragment.newCreate(this, parent, data)
BANKROLL -> data.append(
dataSource.bankroll,
data = realm.sorted<Bankroll>()
)
TYPE -> data.append(
dataSource.type,
data = realm.sorted<TransactionType>()
)
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.create(this, parent, data)
}
}

@ -8,7 +8,7 @@ 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.RowEditableDataSource
import net.pokeranalytics.android.ui.view.RowViewType
enum class TransactionTypeRow : RowRepresentable {
@ -45,12 +45,12 @@ enum class TransactionTypeRow : RowRepresentable {
if (dataSource !is TransactionType) return
if (parent == null) return
if (parent !is RowRepresentableDelegate) return
val data = RowRepresentableEditData()
val data = RowEditableDataSource()
when (this) {
NAME -> data.append(dataSource.name)
else -> PokerAnalyticsException.BottomSheetException
}
BottomSheetFragment.newCreate(this, parent, data)
BottomSheetFragment.create(this, parent, data)
}

Loading…
Cancel
Save