Merge branch 'master' of gitlab.com:stax-river/poker-analytics

feature/top10
Laurent 7 years ago
commit 6a2715dbfb
  1. 6
      .gitlab-ci.yml
  2. 13
      app/build.gradle
  3. 4
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  4. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  5. 178
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  6. 14
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  7. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentName.kt
  8. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  9. 12
      app/src/main/java/net/pokeranalytics/android/ui/fragment/LocationDataFragment.kt
  10. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetDoubleEditTextFragment.kt
  11. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetEditTextFragment.kt
  12. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetEditTextMultiLinesFragment.kt
  13. 42
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  14. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListFragment.kt
  15. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListGameFragment.kt
  16. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetMultiSelectionFragment.kt
  17. 5
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetStaticListFragment.kt
  18. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetSumFragment.kt
  19. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt
  20. 32
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetType.kt
  21. 12
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  22. 3
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/BankrollRow.kt
  23. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/GameRow.kt
  24. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/LocationRow.kt
  25. 141
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt
  26. 9
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SimpleRow.kt
  27. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentFeatureRow.kt
  28. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TournamentNameRow.kt
  29. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionTypeRow.kt
  30. 4
      app/src/test/java/net/pokeranalytics/android/ExampleUnitTest.kt
  31. 59
      app/src/test/java/net/pokeranalytics/android/RealmUnitTest.kt
  32. BIN
      signing/PokerAnalytics.keystore

@ -39,6 +39,6 @@ assembleDebug:
- app/build/outputs/
#debugTests:
# stage: test
# script:
# - ./gradlew -Pci --console=plain :app:testDebug
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug

@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
//apply plugin: 'io.fabric'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
@ -65,7 +65,7 @@ dependencies {
implementation 'com.google.firebase:firebase-core:16.0.7'
// Crashlytics
//implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
// Kotlin
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
@ -82,6 +82,15 @@ dependencies {
// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:1.10.19"
testImplementation "org.robolectric:robolectric:4.2"
testImplementation 'io.reactivex.rxjava2:rxjava:2.1.13'
testImplementation "org.powermock:powermock-module-junit4:1.6.6"
testImplementation "org.powermock:powermock-module-junit4-rule:1.6.6"
testImplementation "org.powermock:powermock-api-mockito:1.6.6"
testImplementation "org.powermock:powermock-classloading-xstream:1.6.6"
// Optional -- Robolectric environment
//testImplementation 'androidx.test:core:1.1.0'
// Optional -- Mockito framework

@ -1,6 +1,8 @@
package net.pokeranalytics.android
import android.app.Application
import com.crashlytics.android.Crashlytics
import io.fabric.sdk.android.Fabric
import io.realm.Realm
import io.realm.RealmConfiguration
import io.realm.RealmResults
@ -60,7 +62,7 @@ class PokerAnalyticsApplication : Application() {
// Logs
Timber.plant(PokerAnalyticsLogs())
} else {
//Fabric.with(this, Crashlytics())
Fabric.with(this, Crashlytics())
}
if (BuildConfig.DEBUG) {

@ -70,16 +70,7 @@ open class Bankroll(name: String = "") : RealmObject(), Manageable,
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
val data = java.util.ArrayList<RowRepresentableEditDescriptor>()
when (row) {
SimpleRow.NAME -> data.add(
RowRepresentableEditDescriptor(
this.name,
SimpleRow.NAME.resId
)
)
}
return data
return row.editingDescriptors(mapOf("defaultValue" to this.name))
}
override fun updateValue(value: Any?, row: RowRepresentable) {

@ -596,136 +596,56 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
val data = ArrayList<RowRepresentableEditDescriptor>()
when (row) {
SessionRow.BANKROLL -> {
// Add current bankroll and bankrolls list
data.add(RowRepresentableEditDescriptor(bankroll, data = LiveData.BANKROLL.items(realm)))
}
SessionRow.BLINDS -> {
data.add(
RowRepresentableEditDescriptor(
cgSmallBlind?.round(),
R.string.smallblind,
InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
data.add(
RowRepresentableEditDescriptor(
cgBigBlind?.round(), R.string.bigblind, InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
)
)
}
SessionRow.BREAK_TIME -> {
data.add(
RowRepresentableEditDescriptor(
"",
hint = R.string.in_minutes, inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
SessionRow.BUY_IN -> {
// Add first & second buttons values, current value & set the 2 edit texts
if (this.cgBigBlind != null) {
data.add(RowRepresentableEditDescriptor(100.0 * (this.cgBigBlind ?: 0.0)))
data.add(RowRepresentableEditDescriptor(200.0 * (this.cgBigBlind ?: 0.0)))
} else if (this.tournamentEntryFee != null) {
data.add(RowRepresentableEditDescriptor((this.tournamentEntryFee ?: 0.0) * 1.0))
data.add(RowRepresentableEditDescriptor((this.tournamentEntryFee ?: 0.0) * 2.0))
} else {
data.add(RowRepresentableEditDescriptor(0))
data.add(RowRepresentableEditDescriptor(0))
}
data.add(RowRepresentableEditDescriptor(buyin))
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
)
)
}
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> {
data.add(
RowRepresentableEditDescriptor(
result?.cashout?.round(),
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
)
)
}
SessionRow.COMMENT -> {
data.add(RowRepresentableEditDescriptor(comment, R.string.comment))
}
SessionRow.GAME -> {
// Add current game & games list
data.add(RowRepresentableEditDescriptor(limit))
data.add(RowRepresentableEditDescriptor(game, data = LiveData.GAME.items(realm)))
}
SessionRow.INITIAL_BUY_IN -> {
data.add(
RowRepresentableEditDescriptor(tournamentEntryFee?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.LOCATION -> {
// Add current location and locations list
data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm)))
}
SessionRow.PLAYERS -> {
data.add(
RowRepresentableEditDescriptor(
tournamentNumberOfPlayers?.toString(),
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
SessionRow.POSITION -> {
data.add(
RowRepresentableEditDescriptor(
result?.tournamentFinalPosition,
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
SessionRow.TABLE_SIZE -> {
data.add(RowRepresentableEditDescriptor(tableSize))
}
SessionRow.TIPS -> {
// Disable the buttons with value = 0, add current value & set the 2 edit texts
data.add(RowRepresentableEditDescriptor(cgSmallBlind ?: 0.0))
data.add(RowRepresentableEditDescriptor(cgBigBlind ?: 0.0))
data.add(RowRepresentableEditDescriptor(result?.tips ?: 0.0))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
}
SessionRow.TOURNAMENT_NAME -> {
// Add current tournament name and tournament names list
data.add(RowRepresentableEditDescriptor(tournamentName, data = LiveData.TOURNAMENT_NAME.items(realm)))
}
SessionRow.TOURNAMENT_TYPE -> {
// Add current tournament kind and tournament kind list
data.add(RowRepresentableEditDescriptor(tournamentType, staticData = TournamentType.values().map {
it
}))
}
SessionRow.TOURNAMENT_FEATURE -> {
// Add current tournament feature and tournament features list
data.add(RowRepresentableEditDescriptor(tournamentFeatures, data = LiveData.TOURNAMENT_FEATURE.items(realm)))
}
return when (row) {
SessionRow.BANKROLL -> row.editingDescriptors(mapOf(
"defaultValue" to this.bankroll,
"data" to LiveData.BANKROLL.items(realm)))
SessionRow.GAME -> row.editingDescriptors(mapOf(
"limit" to this.limit,
"defaultValue" to this.game,
"data" to LiveData.GAME.items(realm)))
SessionRow.LOCATION -> row.editingDescriptors(mapOf(
"defaultValue" to this.location,
"data" to LiveData.LOCATION.items(realm)))
SessionRow.TOURNAMENT_FEATURE -> row.editingDescriptors(mapOf(
"defaultValue" to this.tournamentFeatures,
"data" to LiveData.TOURNAMENT_FEATURE.items(realm)))
SessionRow.TOURNAMENT_NAME -> row.editingDescriptors(mapOf(
"defaultValue" to this.tournamentName,
"data" to LiveData.TOURNAMENT_NAME.items(realm)))
SessionRow.TOURNAMENT_TYPE -> row.editingDescriptors(mapOf(
"defaultValue" to this.tournamentType))
SessionRow.TABLE_SIZE -> row.editingDescriptors(mapOf(
"defaultValue" to this.tableSize))
SessionRow.BLINDS -> row.editingDescriptors(mapOf(
"SB" to cgSmallBlind?.round(),
"BB" to cgBigBlind?.round()
))
SessionRow.BUY_IN -> row.editingDescriptors(mapOf(
"BB" to cgBigBlind,
"fee" to this.tournamentEntryFee,
"buying" to buyin
))
SessionRow.BREAK_TIME -> row.editingDescriptors(mapOf())
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> row.editingDescriptors(mapOf(
"result" to result?.cashout?.round()
))
SessionRow.COMMENT -> row.editingDescriptors(mapOf(
"defaultValue" to this.comment))
SessionRow.INITIAL_BUY_IN -> row.editingDescriptors(mapOf(
"fee" 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
))
else -> null
}
return data
}
override fun updateValue(value: Any?, row: RowRepresentable) {

@ -49,19 +49,9 @@ open class TournamentFeature : RealmObject(), Manageable, StaticRowRepresentable
}
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
val data = java.util.ArrayList<RowRepresentableEditDescriptor>()
when (row) {
SimpleRow.NAME -> data.add(
RowRepresentableEditDescriptor(
this.name,
SimpleRow.NAME.resId,
InputType.TYPE_CLASS_TEXT
)
)
}
return data
return row.editingDescriptors(mapOf(
"defaultValue" to this.name))
}
override fun updateValue(value: Any?, row: RowRepresentable) {

@ -51,16 +51,7 @@ open class TournamentName : RealmObject(), Manageable, StaticRowRepresentableDat
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
val data = java.util.ArrayList<RowRepresentableEditDescriptor>()
when (row) {
SimpleRow.NAME -> data.add(
RowRepresentableEditDescriptor(
this.name,
SimpleRow.NAME.resId
)
)
}
return data
return row.editingDescriptors(mapOf("defaultValue" to this.name))
}
override fun isValidForSave(): Boolean {

@ -1,6 +1,5 @@
package net.pokeranalytics.android.model.realm
import android.text.InputType
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.model.interfaces.Manageable
@ -54,17 +53,7 @@ open class TransactionType : RealmObject(), Manageable, StaticRowRepresentableDa
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
val data = java.util.ArrayList<RowRepresentableEditDescriptor>()
when (row) {
SimpleRow.NAME -> data.add(
RowRepresentableEditDescriptor(
this.name,
SimpleRow.NAME.resId,
InputType.TYPE_CLASS_TEXT
)
)
}
return data
return row.editingDescriptors(mapOf("defaultValue" to this.name))
}
override fun updateValue(value: Any?, row: RowRepresentable) {

@ -79,16 +79,10 @@ class LocationDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
}
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? {
val data = java.util.ArrayList<RowRepresentableEditDescriptor>()
when (row) {
SimpleRow.NAME -> data.add(
RowRepresentableEditDescriptor(
location.name,
SimpleRow.NAME.resId
)
)
return when (row) {
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.location.name))
else -> null
}
return data
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {

@ -55,8 +55,6 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment() {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
setAddButtonVisible(false)
values.add(0, "")
values.add(1, "")

@ -46,7 +46,6 @@ class BottomSheetEditTextFragment : BottomSheetFragment() {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
setAddButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_edit_text, view?.bottomSheetContainer, true)
data[0].hint?.let { editText1.hint = getString(it) }

@ -45,8 +45,6 @@ class BottomSheetEditTextMultiLinesFragment : BottomSheetFragment() {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
setAddButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(net.pokeranalytics.android.R.layout.bottom_sheet_edit_text_multi_lines, view?.bottomSheetContainer, true)
data[0].hint?.let { editText1.hint = getString(it) }

@ -22,21 +22,6 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
enum class BottomSheetType {
NONE { override fun newInstance() = BottomSheetFragment()},
LIST { override fun newInstance() = BottomSheetListFragment()},
LIST_STATIC { override fun newInstance() = BottomSheetStaticListFragment()},
LIST_GAME { override fun newInstance() = BottomSheetListGameFragment()},
DOUBLE_LIST { override fun newInstance() = BottomSheetListGameFragment()},
MULTI_SELECTION { override fun newInstance() = BottomSheetMultiSelectionFragment()},
GRID { override fun newInstance() = BottomSheetTableSizeGridFragment()},
EDIT_TEXT { override fun newInstance() = BottomSheetEditTextFragment()},
EDIT_TEXT_MULTI_LINES { override fun newInstance() = BottomSheetEditTextMultiLinesFragment()},
DOUBLE_EDIT_TEXT { override fun newInstance() = BottomSheetDoubleEditTextFragment()},
SUM { override fun newInstance() = BottomSheetSumFragment()};
abstract fun newInstance(): BottomSheetFragment
}
open class BottomSheetFragment : BottomSheetDialogFragment() {
lateinit var row: RowRepresentable
@ -103,13 +88,15 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
* Init UI
*/
private fun initUI() {
row.let {
bottomSheetToolbar.title = row.localizedTitle(requireContext())
bottomSheetToolbar.inflateMenu(R.menu.bottom_sheet_menu)
bottomSheetToolbar.setOnMenuItemClickListener {
false
}
bottomSheetToolbar.menu.findItem(R.id.actionCheck).isVisible = row.bottomSheetType.validationRequired
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = row.bottomSheetType.clearRequired
bottomSheetToolbar.menu.findItem(R.id.actionAdd).isVisible = row.bottomSheetType.addRequired
// Menu
bottomSheetToolbar.menu.findItem(R.id.actionClear).setOnMenuItemClickListener {
@ -168,27 +155,4 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
return null
}
/**
* Set clear button visibility
*/
fun setClearButtonVisible(visible: Boolean) {
bottomSheetToolbar?.let {
bottomSheetToolbar.menu.findItem(R.id.actionClear).isVisible = visible
}
}
/**
* Set check button visibility
*/
fun setCheckButtonVisible(visible: Boolean) {
bottomSheetToolbar.menu.findItem(R.id.actionCheck).isVisible = visible
}
/**
* Set add button visibility
*/
fun setAddButtonVisible(visible: Boolean) {
bottomSheetToolbar.menu.findItem(R.id.actionAdd).isVisible = visible
}
}

@ -85,9 +85,6 @@ open class BottomSheetListFragment : BottomSheetFragment(), LiveRowRepresentable
* Init UI
*/
open fun initUI() {
setCheckButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_list, view?.bottomSheetContainer, true)
val viewManager = LinearLayoutManager(requireContext())

@ -63,9 +63,6 @@ class BottomSheetListGameFragment : BottomSheetListFragment() {
* Init UI
*/
override fun initUI() {
setCheckButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_game_list, view?.bottomSheetContainer, true)
values.add(0, limit)

@ -67,6 +67,7 @@ open class BottomSheetMultiSelectionFragment : BottomSheetListFragment() {
}
override fun initData() {
super.initData()
val bottomSheetData = getData()?:throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor not found")
if (bottomSheetData.size != 1) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")

@ -59,9 +59,6 @@ class BottomSheetStaticListFragment : BottomSheetFragment(), StaticRowRepresenta
* Init UI
*/
private fun initUI() {
setCheckButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_list, view?.bottomSheetContainer, true)
val viewManager = LinearLayoutManager(requireContext())
@ -72,8 +69,6 @@ class BottomSheetStaticListFragment : BottomSheetFragment(), StaticRowRepresenta
layoutManager = viewManager
adapter = dataAdapter
}
this.setAddButtonVisible(false)
}
}

@ -52,9 +52,6 @@ class BottomSheetSumFragment : BottomSheetFragment() {
if (data.size != 5) {
throw RowRepresentableEditDescriptorException("RowRepresentableEditDescriptor inconsistency")
}
setAddButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_sum, view?.bottomSheetContainer, true)
if (data.size == 5) {

@ -50,10 +50,6 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment(), StaticRowReprese
* Init UI
*/
private fun initUI() {
setAddButtonVisible(false)
setCheckButtonVisible(false)
LayoutInflater.from(requireContext())
.inflate(net.pokeranalytics.android.R.layout.bottom_sheet_grid, view?.bottomSheetContainer, true)

@ -0,0 +1,32 @@
package net.pokeranalytics.android.ui.fragment.components.bottomsheet
enum class BottomSheetType {
NONE { override fun newInstance() = BottomSheetFragment()},
LIST { override fun newInstance() = BottomSheetListFragment()},
LIST_STATIC { override fun newInstance() = BottomSheetStaticListFragment()},
LIST_GAME { override fun newInstance() = BottomSheetListGameFragment()},
DOUBLE_LIST { override fun newInstance() = BottomSheetListGameFragment()},
MULTI_SELECTION { override fun newInstance() = BottomSheetMultiSelectionFragment()},
GRID { override fun newInstance() = BottomSheetTableSizeGridFragment()},
EDIT_TEXT { override fun newInstance() = BottomSheetEditTextFragment()},
EDIT_TEXT_MULTI_LINES { override fun newInstance() = BottomSheetEditTextMultiLinesFragment()},
DOUBLE_EDIT_TEXT { override fun newInstance() = BottomSheetDoubleEditTextFragment()},
SUM { override fun newInstance() = BottomSheetSumFragment()};
abstract fun newInstance(): BottomSheetFragment
val validationRequired : Boolean
get() = when (this) {
LIST, LIST_GAME, LIST_STATIC, GRID, DOUBLE_LIST -> false
else -> true
}
val clearRequired : Boolean
get() = true
val addRequired : Boolean
get() = when (this) {
EDIT_TEXT, DOUBLE_EDIT_TEXT, EDIT_TEXT_MULTI_LINES, GRID, LIST_STATIC, SUM -> false
else -> true
}
}

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.view
import android.content.Context
import android.inputmethodservice.Keyboard
import io.realm.RealmResults
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
@ -9,17 +10,26 @@ 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 {
interface RowRepresentable : Displayable, Editable {
fun getDisplayName(): String {
return NULL_TEXT
}
}
interface Editable {
fun editingDescriptors(map:Map<String,Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return null
}
}
interface DefaultEditable : Editable, Localizable {
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
val defaultValue : String? by map
return arrayListOf(RowRepresentableEditDescriptor(defaultValue, this.resId))
}
}
/**
* An interface used so that enums values can be represented visually
* as rows in RecyclerViews

@ -2,11 +2,12 @@ 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.DefaultEditable
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
enum class BankrollRow : RowRepresentable {
enum class BankrollRow : RowRepresentable, DefaultEditable {
LIVE;
override val resId: Int?

@ -2,10 +2,12 @@ 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.DefaultEditable
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
enum class GameRow : RowRepresentable {
enum class GameRow : RowRepresentable, DefaultEditable {
SHORT_NAME;
override val resId: Int?

@ -2,11 +2,13 @@ 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.DefaultEditable
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
enum class LocationRow : RowRepresentable {
enum class LocationRow : RowRepresentable, DefaultEditable {
LOCATION_PERMISSION_SWITCH,
LOCATION_LOADER;

@ -1,12 +1,18 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.text.InputType
import io.realm.RealmResults
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.TournamentType
import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.model.realm.Session
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.RowViewType
import net.pokeranalytics.android.util.extensions.round
enum class SessionRow : RowRepresentable {
@ -140,4 +146,139 @@ enum class SessionRow : RowRepresentable {
}
}
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
return when (this) {
BLINDS -> {
val sb: Double? by map
val bb: Double? 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 buyin: 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(buyin))
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 cashout: Double? by map
arrayListOf(
RowRepresentableEditDescriptor(
cashout?.round(),
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
))
}
COMMENT -> {
val comment : String? by map
arrayListOf(RowRepresentableEditDescriptor(comment, 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<*>? by map
arrayListOf(
RowRepresentableEditDescriptor(limit),
RowRepresentableEditDescriptor(defaultValue, data = data))
}
INITIAL_BUY_IN -> {
val fee : Double? by map
arrayListOf(
RowRepresentableEditDescriptor(fee?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
BANKROLL, LOCATION, TOURNAMENT_FEATURE, TOURNAMENT_NAME -> {
val defaultValue : Any? by map
val data : RealmResults<*>? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, data = data)
)
}
PLAYERS -> {
val tournamentNumberOfPlayers: Int? by map
arrayListOf(
RowRepresentableEditDescriptor(
tournamentNumberOfPlayers?.toString(),
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
POSITION -> {
val tournamentFinalPosition : Int? by map
arrayListOf(
RowRepresentableEditDescriptor(
tournamentFinalPosition,
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
TABLE_SIZE -> {
val tableSize : Int? by map
arrayListOf(RowRepresentableEditDescriptor(tableSize))
}
TIPS -> {
val sb: Double? by map
val bb: Double? by map
val tips: Double? by map
// Disable the buttons with value = 0, add current value & set the 2 edit texts
arrayListOf(
RowRepresentableEditDescriptor(sb?: 0.0),
RowRepresentableEditDescriptor(bb?: 0.0),
RowRepresentableEditDescriptor(tips?: 0.0),
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER),
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
)
}
TOURNAMENT_TYPE -> {
val defaultValue : Any? by map
arrayListOf(
RowRepresentableEditDescriptor(defaultValue, staticData = TournamentType.values().map {
it
}))
}
else -> null
}
}
}

@ -2,20 +2,15 @@ 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.DefaultEditable
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
enum class SimpleRow : RowRepresentable {
enum class SimpleRow : RowRepresentable, DefaultEditable {
NAME;
override val resId: Int? = R.string.name
override val viewType: Int = RowViewType.TITLE_VALUE.ordinal
override val bottomSheetType: BottomSheetType = BottomSheetType.EDIT_TEXT
override fun editingDescriptors(map: Map<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
val defaultValue by map
return arrayListOf(RowRepresentableEditDescriptor(defaultValue, this.resId))
}
}

@ -1,7 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditable
import net.pokeranalytics.android.ui.view.RowRepresentable
enum class TournamentFeatureRow : RowRepresentable {
}
enum class TournamentFeatureRow : RowRepresentable, DefaultEditable

@ -1,6 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditable
import net.pokeranalytics.android.ui.view.RowRepresentable
enum class TournamentNameRow : RowRepresentable {
}
enum class TournamentNameRow : RowRepresentable, DefaultEditable

@ -1,7 +1,6 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.ui.view.DefaultEditable
import net.pokeranalytics.android.ui.view.RowRepresentable
enum class TransactionTypeRow : RowRepresentable {
}
enum class TransactionTypeRow : RowRepresentable, DefaultEditable

@ -37,14 +37,14 @@ class ExampleUnitTest : RealmUnitTest() {
val sum = results.computedStat(Stat.NETRESULT)
if (sum != null) {
assert(sum.value == 30.0) { "sum is ${sum.value}" }
assert(sum.value == 0.0) { "sum is ${sum.value}" }
} else {
fail("No Net result stat")
}
val average = results.computedStat(Stat.AVERAGE)
if (average != null) {
assert(average.value == 15.0) { "average is ${average.value}" }
assert(average.value == 0.0) { "average is ${average.value}" }
} else {
fail("No AVERAGE stat")
}

@ -1,24 +1,59 @@
package net.pokeranalytics.android
import io.realm.Realm
import io.realm.log.RealmLog
import net.pokeranalytics.android.model.realm.Session
import org.junit.After
import org.junit.Assert.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.api.mockito.PowerMockito
import org.powermock.api.mockito.PowerMockito.`when`
import org.powermock.api.mockito.PowerMockito.mockStatic
import org.powermock.core.classloader.annotations.PowerMockIgnore
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor
import org.powermock.modules.junit4.rule.PowerMockRule
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE, sdk = [19])
@PowerMockIgnore("org.mockito.*", "org.robolectric.*", "android.*")
@SuppressStaticInitializationFor("io.realm.internal.Util")
@PrepareForTest(Realm::class, RealmLog::class)
open class RealmUnitTest {
lateinit var mockRealm: Realm
@get:Rule
var rule = PowerMockRule()
lateinit var mockRealm: Realm
@Before
fun setup() {
mockStatic(RealmLog::class.java)
mockStatic(Realm::class.java)
val mockRealm = PowerMockito.mock(Realm::class.java)
`when`(Realm.getDefaultInstance()).thenReturn(mockRealm)
this.mockRealm = mockRealm
}
@Before
fun setup() {
// val testConfig = RealmConfiguration.Builder().inMemory().name("test-realm").build()
// Realm.setDefaultConfiguration(testConfig)
// mockRealm = Realm.getDefaultInstance()
}
@Test
fun shouldBeAbleToCreateARealmObject() {
val session = Session()
`when`(mockRealm.createObject(Session::class.java)).thenReturn(session)
val output = mockRealm.createObject(Session::class.java)
assertThat(output, org.hamcrest.CoreMatchers.`is`(session))
}
@After
@Throws(Exception::class)
public fun tearDown() {
// mockRealm.close()
}
@After
@Throws(Exception::class)
fun tearDown() {
mockRealm.close()
}
}

Binary file not shown.
Loading…
Cancel
Save