Fixing issue with favorite sessions

feature/top10
Laurent 7 years ago
parent 9da9bea414
commit ec90222e43
  1. 12
      app/src/main/java/net/pokeranalytics/android/model/utils/FavoriteSessionFinder.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt

@ -6,6 +6,7 @@ import io.realm.Sort
import net.pokeranalytics.android.model.realm.Location import net.pokeranalytics.android.model.realm.Location
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
import timber.log.Timber
/** /**
* Returns all significant parameters concatenated in a String * Returns all significant parameters concatenated in a String
@ -75,7 +76,14 @@ class FavoriteSessionFinder {
*/ */
fun copyParametersFromFavoriteSession(newSession: Session, location: Location?, context: Context) { fun copyParametersFromFavoriteSession(newSession: Session, location: Location?, context: Context) {
val favoriteSession = FavoriteSessionFinder.favoriteSession(newSession.type, location, newSession.realm, context) val favoriteSession =
FavoriteSessionFinder.favoriteSession(newSession.type, location, newSession.realm, context)
Timber.d(">>> fav null? = ${favoriteSession == null}")
Timber.d(">>> game = ${favoriteSession?.game?.name}")
Timber.d(">>> bb = ${favoriteSession?.cgBigBlind?.toString()}")
Timber.d(">>> duration = ${favoriteSession?.netDuration}")
favoriteSession?.let { fav -> favoriteSession?.let { fav ->
@ -101,7 +109,7 @@ class FavoriteSessionFinder {
*/ */
fun favoriteSession(sessionType: Int, location: Location?, realm: Realm, context: Context): Session? { fun favoriteSession(sessionType: Int, location: Location?, realm: Realm, context: Context): Session? {
val lastSessionsQuery = realm.where(Session::class.java).equalTo("type", sessionType) val lastSessionsQuery = realm.where(Session::class.java).isNotNull("endDate").equalTo("type", sessionType)
if (location != null) { if (location != null) {
lastSessionsQuery.equalTo("location.id", location.id) lastSessionsQuery.equalTo("location.id", location.id)
} }

@ -285,10 +285,10 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
parentActivity.findNearestLocation { location -> parentActivity.findNearestLocation { location ->
location?.let { location?.let {
realm.beginTransaction() realm.beginTransaction()
val realmLocation = realm.where<Location>().equalTo("id", it.id).findFirst() val location = realm.where<Location>().equalTo("id", it.id).findFirst()
FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, realmLocation, requireContext()) FavoriteSessionFinder.copyParametersFromFavoriteSession(currentSession, location, requireContext())
currentSession.location = realmLocation currentSession.location = location
realm.commitTransaction() realm.commitTransaction()
updateSessionUI() updateSessionUI()
} }

Loading…
Cancel
Save