feature/top10
Laurent 7 years ago
commit 1696ed4269
  1. BIN
      app/src/androidTest/assets/schema_0.realm
  2. 15
      app/src/androidTest/java/net/pokeranalytics/android/unitTests/filter/ExceptionFilterInstrumentedTest.kt
  3. 3
      app/src/androidTest/java/net/pokeranalytics/android/unitTests/filter/RealmFilterInstrumentedUnitTest.kt
  4. 41
      app/src/main/java/net/pokeranalytics/android/exceptions/Exceptions.kt
  5. 31
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryType.kt
  6. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  7. 33
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterElement.kt
  8. 14
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  9. 5
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  10. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  11. 1
      app/src/main/res/layout/fragment_bottom_sheet.xml
  12. 8
      app/src/main/res/layout/fragment_session.xml
  13. 4
      app/src/main/res/values/styles.xml

@ -2,7 +2,7 @@ package net.pokeranalytics.android.unitTests.filter
import androidx.test.ext.junit.runners.AndroidJUnit4
import net.pokeranalytics.android.components.BaseFilterInstrumentedUnitTest
import net.pokeranalytics.android.exceptions.FilterValueMapException
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.filter.QueryType
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.model.realm.FilterElement
@ -13,7 +13,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ExceptionFilterInstrumentedTest: BaseFilterInstrumentedUnitTest() {
@Test(expected = FilterValueMapException::class)
@Test(expected = PokerAnalyticsException.FilterElementExpectedValueMissing::class)
fun testValueKeyFilterException() {
val filter = QueryType.STARTED_FROM_DATE
val filterElement = FilterElement()
@ -27,15 +27,8 @@ class ExceptionFilterInstrumentedTest: BaseFilterInstrumentedUnitTest() {
)
}
@Test(expected = FilterValueMapException::class)
@Test(expected = PokerAnalyticsException.FilterElementUnknownName::class)
fun testFilterException() {
val realm = this.mockRealm
val filter = QueryType.BLINDS
filter.updateValueMap(FilterElement())
Filter.queryOn(
realm,
Session,
arrayListOf(filter)
)
FilterElement().queryType
}
}

@ -2,6 +2,7 @@ package net.pokeranalytics.android.unitTests.filter
import androidx.test.ext.junit.runners.AndroidJUnit4
import net.pokeranalytics.android.components.BaseFilterInstrumentedUnitTest
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.filter.QueryType
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.model.realm.Session
@ -37,7 +38,7 @@ class RealmFilterInstrumentedUnitTest : BaseFilterInstrumentedUnitTest() {
val filterComponent = filter.filterElements.first()
filterComponent?.let {
Assert.assertEquals(QueryType.CASH, QueryType.valueOf(it.filterName))
Assert.assertEquals(QueryType.CASH, QueryType.valueOf(it.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName))
} ?: run {
Assert.fail()
}

@ -1,25 +1,22 @@
package net.pokeranalytics.android.exceptions
class ModelException(message: String) : Exception(message) {
}
class FormattingException(message: String) : Exception(message) {
}
class RowRepresentableEditDescriptorException(message: String) : Exception(message) {
}
class FilterValueMapException(message: String) : Exception(message) {
init {
println("FilterValueMapException(): $message")
}
}
class FilterMissingEntityException(message: String) : Exception(message)
class FilterUnhandledEntityException(message : String) : Exception(message)
class ConfigurationException(message: String) : Exception(message) {
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
class ModelException(message: String) : Exception(message)
class FormattingException(message: String) : Exception(message)
class RowRepresentableEditDescriptorException(message: String) : Exception(message)
class ConfigurationException(message: String) : Exception(message)
sealed class PokerAnalyticsException(message: String) : Exception(message) {
object FilterElementUnknownName : PokerAnalyticsException(message = "No filterElement name was found to identify the queryType")
object FilterElementUnknownSectionName: PokerAnalyticsException(message = "No filterElement section name was found to identify the queryType")
object FilterMissingEntity: PokerAnalyticsException(message = "This filter has no entity initialized")
object FilterUnhandledEntity : PokerAnalyticsException(message = "This entity is not filterable")
object QueryValueMapUnknown: PokerAnalyticsException(message = "fieldName is missing")
object QueryTypeUnhandled: PokerAnalyticsException(message = "filter type not handled")
object QueryValueMapUnexpectedValue: PokerAnalyticsException(message = "valueMap null not expected")
object FilterElementExpectedValueMissing : PokerAnalyticsException(message = "filter is empty or null")
data class QueryValueMapMissingKeys(val missingKeys: List<String>) : PokerAnalyticsException(message = "valueMap does not contain $missingKeys")
data class UnknownQueryTypeForRow(val filterElementRow: FilterElementRow) : PokerAnalyticsException(message = "no filter type for $filterElementRow")
}

@ -2,7 +2,17 @@ package net.pokeranalytics.android.model.filter
import io.realm.RealmList
import io.realm.RealmQuery
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.FilterElement
import net.pokeranalytics.android.model.realm.FilterElementBlind
import java.util.*
<<<<<<< HEAD
import net.pokeranalytics.android.exceptions.FilterValueMapException
=======
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.FilterElementBlind
>>>>>>> 5301b81ebff84f627ba6b22fdbfa19235a65b218
import net.pokeranalytics.android.model.realm.FilterElement
import net.pokeranalytics.android.model.realm.FilterElementBlind
import java.util.*
@ -100,12 +110,12 @@ enum class QueryType(var subType:SubType? = null) {
when {
this == BLINDS -> {
val smallBlindFieldName = FilterHelper.fieldNameForQueryType<T>(queryType = SMALL_BLIND)
val bigBlindFieldName = FilterHelper.fieldNameForQueryType<T>(queryType = BIG_BLIND)
val smallBlindFieldName = FilterHelper.fieldNameForQueryType<T>(SMALL_BLIND)
val bigBlindFieldName = FilterHelper.fieldNameForQueryType<T>(BIG_BLIND)
val currencyCodeFieldName = FilterHelper.fieldNameForQueryType<T>(CURRENCY_CODE)
smallBlindFieldName ?: throw FilterValueMapException("fieldName is missing")
bigBlindFieldName ?: throw FilterValueMapException("fieldName is missing")
currencyCodeFieldName ?: throw FilterValueMapException("fieldName is missing")
smallBlindFieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown
bigBlindFieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown
currencyCodeFieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown
val blinds: RealmList<FilterElementBlind> by valueMap
blinds.forEachIndexed { index, blind ->
@ -137,8 +147,9 @@ enum class QueryType(var subType:SubType? = null) {
return realmQuery
}
else -> {
val fieldName = FilterHelper.fieldNameForQueryType<T>(this)
fieldName ?: throw FilterValueMapException("fieldName is missing")
fieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown
this.subType?.let { subType ->
return when (subType) {
@ -214,7 +225,7 @@ enum class QueryType(var subType:SubType? = null) {
query
}
else -> {
throw FilterValueMapException("filter type not handled")
throw PokerAnalyticsException.QueryTypeUnhandled
}
}
}
@ -265,7 +276,7 @@ enum class QueryType(var subType:SubType? = null) {
valueMap = mapOf("year" to filterElement.year)
}
else -> {
throw FilterValueMapException("filter type not handled")
throw PokerAnalyticsException.QueryValueMapUnexpectedValue
}
}
}
@ -276,10 +287,10 @@ enum class QueryType(var subType:SubType? = null) {
field?.let { map ->
val missingKeys = map.keys.filter { !valueMapExceptedKeys.contains(it) }
if (map.keys.size == valueMapExceptedKeys.size && missingKeys.isNotEmpty()) {
throw FilterValueMapException("valueMap does not contain $missingKeys")
throw PokerAnalyticsException.QueryValueMapMissingKeys(missingKeys)
}
} ?: run {
throw FilterValueMapException("valueMap null not expected")
throw PokerAnalyticsException.QueryValueMapUnexpectedValue
}
}
return field

@ -2,8 +2,9 @@ package net.pokeranalytics.android.model.realm
import io.realm.*
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import io.realm.kotlin.where
import net.pokeranalytics.android.exceptions.FilterUnhandledEntityException
import net.pokeranalytics.android.model.filter.Filterable
import net.pokeranalytics.android.model.filter.QueryType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
@ -38,7 +39,7 @@ open class Filter(entity:Filterable) : RealmObject() {
fun filterableClass(entity: Filterable): FilterableClass {
return when (entity) {
is Session.Companion -> SESSION
else -> throw FilterUnhandledEntityException("this entity is not filterable")
else -> throw PokerAnalyticsException.FilterUnhandledEntity
}
}
}
@ -115,7 +116,7 @@ open class Filter(entity:Filterable) : RealmObject() {
fun countBy(filterCategoryRow: FilterCategoryRow) : Int {
val sections = filterCategoryRow.filterSectionRows
return filterElements.count {
sections.contains(FilterSectionRow.valueOf(it.sectionName))
sections.contains(FilterSectionRow.valueOf(it.sectionName ?: throw PokerAnalyticsException.FilterElementUnknownSectionName))
}
}

@ -2,7 +2,7 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmList
import io.realm.RealmObject
import net.pokeranalytics.android.exceptions.FilterValueMapException
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.filter.QueryType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
@ -17,7 +17,8 @@ open class FilterElement() : RealmObject() {
}
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) {
this.stringValues = when (QueryType.valueOf(this.filterName)) {
val filterName : String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName
this.stringValues = when (QueryType.valueOf(filterName)) {
QueryType.GAME, QueryType.BANKROLL, QueryType.TOURNAMENT_NAME, QueryType.ALL_TOURNAMENT_FEATURES, QueryType.ANY_TOURNAMENT_FEATURES, QueryType.LOCATION -> {
RealmList<String>().apply {
this.addAll(filterElementRows.map {
@ -86,11 +87,11 @@ open class FilterElement() : RealmObject() {
}
}
var filterName : String = ""
var sectionName : String = ""
var filterName : String? = null
var sectionName : String? = null
val queryType : QueryType
get() = QueryType.valueOf(filterName)
get() = QueryType.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName)
.apply {
this.updateValueMap(this@FilterElement)
}
@ -101,7 +102,7 @@ open class FilterElement() : RealmObject() {
private var blindValues : RealmList<FilterElementBlind>? = null
val ids : Array<String>
get() = stringValues?.toTypedArray()?: throw FilterValueMapException("filter type not handled")
get() = stringValues?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val blinds : RealmList<FilterElementBlind>
get() {
@ -109,44 +110,44 @@ open class FilterElement() : RealmObject() {
if (it.isNotEmpty()) {
return it
} else {
throw FilterValueMapException("filter is empty or null")
throw PokerAnalyticsException.FilterElementExpectedValueMissing
}
}
throw FilterValueMapException("filter is empty or null")
throw PokerAnalyticsException.FilterElementExpectedValueMissing
}
val date : Date
get() = dateValue?: throw FilterValueMapException("filter type not handled")
get() = dateValue?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val values : Array<Int>
get() = numericValues?.map {
it.toInt()
}?.toTypedArray()?: throw FilterValueMapException("filter type not handled")
}?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val value : Double
get() = numericValues?.first()?: throw FilterValueMapException("filter type not handled")
get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val leftValue : Double
get() = numericValues?.first()?: throw FilterValueMapException("filter type not handled")
get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val rightValue : Double
get() = numericValues?.last()?: throw FilterValueMapException("filter type not handled")
get() = numericValues?.last()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val dayOfWeek : Int
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled")
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val month : Int
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled")
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val year : Int
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled")
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
}

@ -88,7 +88,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
val data = currentSession.editDescriptors(row)
when (row) {
SessionRow.START_DATE -> DateTimePickerManager.create(requireContext(),row,this,currentSession.startDate)
SessionRow.START_DATE -> DateTimePickerManager.create(requireContext(), row, this, currentSession.startDate)
SessionRow.END_DATE -> DateTimePickerManager.create(
requireContext(),
row,
@ -151,12 +151,14 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
* Update the UI with the session data
* Should be called after the initialization of the session
*/
private fun updateSessionUI() {
private fun updateSessionUI(firstDisplay: Boolean = false) {
this.currentSession.updateRowRepresentation()
handler.removeCallbacksAndMessages(null)
val animationDuration = if (firstDisplay) 0L else 300L
when (currentSession.getState()) {
SessionState.PENDING, SessionState.PLANNED -> {
state.setTextColor(ContextCompat.getColor(requireContext(), R.color.white))
@ -164,6 +166,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
floatingActionButton.setImageResource(R.drawable.ic_outline_play)
sessionMenu?.findItem(R.id.stop)?.isVisible = false
floatingActionButton.animate().scaleX(1f).scaleY(1f).alpha(1f)
.setDuration(animationDuration)
.setInterpolator(OvershootInterpolator()).start()
}
SessionState.STARTED -> {
@ -172,6 +175,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
floatingActionButton.setImageResource(R.drawable.ic_outline_pause)
sessionMenu?.findItem(R.id.stop)?.isVisible = true
floatingActionButton.animate().scaleX(1f).scaleY(1f).alpha(1f)
.setDuration(animationDuration)
.setInterpolator(OvershootInterpolator()).start()
handler.postDelayed(refreshTimer, 30000)
}
@ -181,6 +185,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
floatingActionButton.setImageResource(R.drawable.ic_outline_play)
sessionMenu?.findItem(R.id.stop)?.isVisible = true
floatingActionButton.animate().scaleX(1f).scaleY(1f).alpha(1f)
.setDuration(animationDuration)
.setInterpolator(OvershootInterpolator()).start()
}
SessionState.FINISHED -> {
@ -188,6 +193,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
sessionMenu?.findItem(R.id.restart)?.isVisible = true
sessionMenu?.findItem(R.id.stop)?.isVisible = false
floatingActionButton.animate().scaleX(0f).scaleY(0f).alpha(0f)
.setDuration(animationDuration)
.setInterpolator(FastOutSlowInInterpolator()).start()
}
}
@ -299,7 +305,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
currentSession.location = location
realm.commitTransaction()
updateSessionUI()
updateSessionUI(true)
}
}
sessionHasBeenCustomized = false
@ -312,7 +318,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
sessionAdapter = RowRepresentableAdapter(currentSession, this)
recyclerView.adapter = sessionAdapter
updateSessionUI()
updateSessionUI(true)
}
/**

@ -9,6 +9,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.view.ContextThemeWrapper
import androidx.fragment.app.FragmentManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import io.realm.RealmObject
@ -57,7 +58,9 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_bottom_sheet, container, false)
//TODO: When dependency 'com.google.android.material:material:1.1.0' will be available in stable version, upgrade and remove that
val contextThemeWrapper = ContextThemeWrapper(activity, R.style.PokerAnalyticsTheme)
return inflater.cloneInContext(contextThemeWrapper).inflate(R.layout.fragment_bottom_sheet, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

@ -1,7 +1,7 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.FilterValueMapException
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.filter.QueryType
import net.pokeranalytics.android.model.interfaces.Manageable
import net.pokeranalytics.android.model.realm.FilterElement
@ -88,7 +88,7 @@ sealed class FilterElementRow : RowRepresentable {
is AllTournamentFeature -> QueryType.ALL_TOURNAMENT_FEATURES
is ResultMoreThan -> QueryType.MORE_THAN_NET_RESULT
is ResultLessThan -> QueryType.LESS_THAN_NET_RESULT
else -> throw FilterValueMapException("no filter type for $this") //TODO create exception
else -> throw PokerAnalyticsException.UnknownQueryTypeForRow(this)
}
}

@ -8,7 +8,6 @@
<androidx.appcompat.widget.Toolbar
android:id="@+id/bottomSheetToolbar"
style="@style/PokerAnalyticsTheme.Toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
tools:title="Test" />

@ -145,8 +145,14 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="28dp"
android:alpha="0"
android:elevation="16dp"
android:scaleX="0"
android:scaleY="0"
android:src="@drawable/ic_outline_play"
android:tint="@color/black" />
android:tint="@color/black"
tools:alpha="1"
tools:scaleX="1"
tools:scaleY="1" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

@ -6,9 +6,10 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorControlHighlight">@color/green_transparent</item>
<item name="android:windowBackground">@color/gray_dark</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<item name="colorControlHighlight">@color/green_transparent</item>
<item name="android:actionMenuTextColor">@color/white</item>
<item name="bottomNavigationStyle">@style/PokerAnalyticsTheme.BottomNavigationView</item>
<item name="toolbarStyle">@style/PokerAnalyticsTheme.Toolbar</item>
@ -61,7 +62,6 @@
<item name="android:colorPrimary">@color/white</item>
<item name="android:titleTextColor">@color/white</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="actionMenuTextColor">@color/white</item>
</style>
<!-- TextView -->

Loading…
Cancel
Save