From ecf975c916936c1309fd595ef0cd43d2424cf91c Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 31 May 2019 14:30:20 +0200 Subject: [PATCH] Show result fields depending on what has been used in priority --- .../android/ui/fragment/SessionFragment.kt | 81 ++++++++++--------- .../ui/view/rowrepresentable/SessionRow.kt | 37 ++++----- 2 files changed, 56 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt index 29fb9e8c..cb13262e 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt @@ -55,6 +55,47 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate { } } + + /** + * Set fragment data + */ + fun setData(isTournament: Boolean, sessionId: String) { + + val realm = getRealm() + val sessionRealm = realm.findById(sessionId) + if (sessionRealm != null) { + currentSession = sessionRealm + sessionHasBeenCustomized = true + } else { + realm.beginTransaction() + currentSession = Session.newInstance(realm, isTournament) + FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, null, requireContext()) + realm.commitTransaction() + + // Find the nearest location around the user + parentActivity?.findNearestLocation { + it?.let { location -> + realm.beginTransaction() + val realmLocation = realm.findById(location.id) + FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, realmLocation, requireContext()) + + currentSession.location = realmLocation + realm.commitTransaction() + updateSessionUI(true) + } + } + sessionHasBeenCustomized = false + } + + toolbar.title = if (currentSession.isTournament()) getString(R.string.tournament) else getString(R.string.cash_game) + collapsingToolbar.title = toolbar.title + + sessionAdapter = RowRepresentableAdapter(currentSession, this) + recyclerView.adapter = sessionAdapter + + updateSessionUI(true) + } + override fun onResume() { super.onResume() this.refreshTimer() @@ -308,46 +349,6 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate { activity?.finish() } - /** - * Set fragment data - */ - fun setData(isTournament: Boolean, sessionId: String) { - - val realm = getRealm() - val sessionRealm = realm.findById(sessionId) - if (sessionRealm != null) { - currentSession = sessionRealm - sessionHasBeenCustomized = true - } else { - realm.beginTransaction() - currentSession = Session.newInstance(realm, isTournament) - FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, null, requireContext()) - realm.commitTransaction() - - // Find the nearest location around the user - parentActivity?.findNearestLocation { - it?.let { location -> - realm.beginTransaction() - val realmLocation = realm.findById(location.id) - FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, realmLocation, requireContext()) - - currentSession.location = realmLocation - realm.commitTransaction() - updateSessionUI(true) - } - } - sessionHasBeenCustomized = false - } - - toolbar.title = if (currentSession.isTournament()) getString(R.string.tournament) else getString(R.string.cash_game) - collapsingToolbar.title = toolbar.title - - sessionAdapter = RowRepresentableAdapter(currentSession, this) - recyclerView.adapter = sessionAdapter - - updateSessionUI(true) - } - /** * Called when the user pressed back on the parent activity */ diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt index f41ea396..8ea38dfe 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt @@ -43,7 +43,7 @@ enum class SessionRow : RowRepresentable { /** * Return the rows to display for the current session state */ - fun getRows(session: Session): ArrayList { + fun getRows(session: Session): List { when (session.type) { Session.Type.TOURNAMENT.ordinal -> { return when (session.getState()) { @@ -93,26 +93,19 @@ enum class SessionRow : RowRepresentable { } SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> { val liveBankroll = session.bankroll?.live ?: false - return if (liveBankroll) { - arrayListOf( - CASHED_OUT, - BUY_IN, - TIPS, - SeparatorRow(), - GAME, - BLINDS, - LOCATION, - BANKROLL, - TABLE_SIZE, - START_DATE, - END_DATE, - BREAK_TIME, - COMMENT - ) + + val fields = mutableListOf() + if (session.result?.buyin != null) { // fill with what's used + fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS)) + } else if (session.result?.netResult != null) { + fields.add(NET_RESULT) + } else if (liveBankroll) { + fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS)) } else { - arrayListOf( - NET_RESULT, - SeparatorRow(), + fields.add(NET_RESULT) + } + fields.add(SeparatorRow()) + fields.addAll(listOf( GAME, BLINDS, LOCATION, @@ -123,9 +116,9 @@ enum class SessionRow : RowRepresentable { BREAK_TIME, COMMENT ) - } + ) + return fields } - else -> return arrayListOf() } } }