Show result fields depending on what has been used in priority

dev
Laurent 7 years ago
parent 8ffa72d0f4
commit ecf975c916
  1. 81
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  2. 37
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.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<Session>(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>(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() { override fun onResume() {
super.onResume() super.onResume()
this.refreshTimer() this.refreshTimer()
@ -308,46 +349,6 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
activity?.finish() activity?.finish()
} }
/**
* Set fragment data
*/
fun setData(isTournament: Boolean, sessionId: String) {
val realm = getRealm()
val sessionRealm = realm.findById<Session>(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>(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 * Called when the user pressed back on the parent activity
*/ */

@ -43,7 +43,7 @@ enum class SessionRow : RowRepresentable {
/** /**
* Return the rows to display for the current session state * Return the rows to display for the current session state
*/ */
fun getRows(session: Session): ArrayList<RowRepresentable> { fun getRows(session: Session): List<RowRepresentable> {
when (session.type) { when (session.type) {
Session.Type.TOURNAMENT.ordinal -> { Session.Type.TOURNAMENT.ordinal -> {
return when (session.getState()) { return when (session.getState()) {
@ -93,26 +93,19 @@ enum class SessionRow : RowRepresentable {
} }
SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> { SessionState.STARTED, SessionState.PAUSED, SessionState.FINISHED -> {
val liveBankroll = session.bankroll?.live ?: false val liveBankroll = session.bankroll?.live ?: false
return if (liveBankroll) {
arrayListOf( val fields = mutableListOf<RowRepresentable>()
CASHED_OUT, if (session.result?.buyin != null) { // fill with what's used
BUY_IN, fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS))
TIPS, } else if (session.result?.netResult != null) {
SeparatorRow(), fields.add(NET_RESULT)
GAME, } else if (liveBankroll) {
BLINDS, fields.addAll(listOf(CASHED_OUT, BUY_IN, TIPS))
LOCATION,
BANKROLL,
TABLE_SIZE,
START_DATE,
END_DATE,
BREAK_TIME,
COMMENT
)
} else { } else {
arrayListOf( fields.add(NET_RESULT)
NET_RESULT, }
SeparatorRow(), fields.add(SeparatorRow())
fields.addAll(listOf(
GAME, GAME,
BLINDS, BLINDS,
LOCATION, LOCATION,
@ -123,10 +116,10 @@ enum class SessionRow : RowRepresentable {
BREAK_TIME, BREAK_TIME,
COMMENT COMMENT
) )
)
return fields
} }
} }
else -> return arrayListOf()
}
} }
} }
return arrayListOf() return arrayListOf()

Loading…
Cancel
Save