Adds configurationId to create a HH from a session or a previous HH

hh
Laurent 6 years ago
parent ea6b0a29d5
commit fa69fcb264
  1. 41
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt
  2. 3
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  4. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BaseFragment.kt
  5. 11
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt
  6. 13
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  7. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  8. 6
      app/src/main/res/menu/toolbar_session.xml

@ -1,12 +1,53 @@
package net.pokeranalytics.android.model.handhistory package net.pokeranalytics.android.model.handhistory
import io.realm.Realm
import net.pokeranalytics.android.model.realm.Game import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.util.extensions.findById
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
class HandSetup { class HandSetup {
companion object {
fun from(configurationId: String?, realm: Realm): HandSetup {
return if (configurationId != null) {
val handSetup = HandSetup()
val hh = realm.findById(HandHistory::class.java, configurationId)
if (hh != null) {
handSetup.configure(hh)
}
val session = realm.findById(Session::class.java, configurationId)
if (session != null) {
handSetup.configure(session)
}
handSetup
} else {
HandSetup()
}
}
}
private fun configure(handHistory: HandHistory) {
this.smallBlind = handHistory.smallBlind
this.bigBlind = handHistory.bigBlind
this.bigBlindAnte = handHistory.bigBlindAnte
this.ante = handHistory.ante
this.tableSize = handHistory.numberOfPlayers
}
private fun configure(session: Session) {
this.type = session.sessionType
this.smallBlind = session.cgSmallBlind
this.bigBlind = session.cgBigBlind
this.tableSize = session.tableSize
this.game = session.game
}
var type: Session.Type? = null var type: Session.Type? = null
var smallBlind: Double? = null var smallBlind: Double? = null

@ -131,6 +131,9 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
@Index @Index
var type: Int = Type.CASH_GAME.ordinal var type: Int = Type.CASH_GAME.ordinal
val sessionType: Type
get() { return Type.values()[this.type] }
// The result of the main user // The result of the main user
var result: Result? = null var result: Result? = null

@ -27,6 +27,7 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.RealmFragment import net.pokeranalytics.android.ui.fragment.components.RealmFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.helpers.DateTimePickerManager import net.pokeranalytics.android.ui.helpers.DateTimePickerManager
import net.pokeranalytics.android.ui.modules.handhistory.HandHistoryActivity
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
@ -143,6 +144,7 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item!!.itemId) { when (item!!.itemId) {
R.id.stop -> stopSession() R.id.stop -> stopSession()
R.id.newHandHistory -> addHandHistory()
R.id.newCustomField -> addNewCustomField() R.id.newCustomField -> addNewCustomField()
R.id.restart -> restartTimer() R.id.restart -> restartTimer()
R.id.delete -> deleteSession() R.id.delete -> deleteSession()
@ -355,6 +357,10 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
updateSessionUI() updateSessionUI()
} }
private fun addHandHistory() {
HandHistoryActivity.newInstance(this, this.currentSession)
}
/** /**
* Add new custom field * Add new custom field
*/ */

@ -17,6 +17,7 @@ abstract class BaseFragment : Fragment() {
enum class BundleKey(val value: String) { enum class BundleKey(val value: String) {
STYLE("style"), STYLE("style"),
PRIMARY_KEY("primary_key"), PRIMARY_KEY("primary_key"),
SECONDARY_KEY("secondary_key"),
DATA_TYPE("data_type"), DATA_TYPE("data_type"),
SHOW_MESSAGE("show_message") SHOW_MESSAGE("show_message")
} }

@ -4,17 +4,25 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.activity.components.BaseActivity import net.pokeranalytics.android.ui.activity.components.BaseActivity
import net.pokeranalytics.android.ui.activity.components.RequestCode import net.pokeranalytics.android.ui.activity.components.RequestCode
class HandHistoryActivity : BaseActivity() { class HandHistoryActivity : BaseActivity() {
enum class IntentKey(val keyName: String) { enum class IntentKey(val keyName: String) {
IDENTIFIER("identifier") IDENTIFIER("identifier"),
SESSION_CONFIGURATION("session_id")
} }
companion object { companion object {
fun newInstance(fragment: Fragment, session: Session) {
val intent = Intent(fragment.requireContext(), HandHistoryActivity::class.java)
intent.putExtra(IntentKey.SESSION_CONFIGURATION.keyName, session.id)
fragment.startActivityForResult(intent, RequestCode.NEW_HAND_HISTORY.value)
}
fun newInstance(fragment: Fragment, id: String? = null) { fun newInstance(fragment: Fragment, id: String? = null) {
val intent = Intent(fragment.requireContext(), HandHistoryActivity::class.java) val intent = Intent(fragment.requireContext(), HandHistoryActivity::class.java)
id?.let { intent.putExtra(IntentKey.IDENTIFIER.keyName, it) } id?.let { intent.putExtra(IntentKey.IDENTIFIER.keyName, it) }
@ -38,6 +46,7 @@ class HandHistoryActivity : BaseActivity() {
val fragmentTransaction = supportFragmentManager.beginTransaction() val fragmentTransaction = supportFragmentManager.beginTransaction()
val handHistoryId = intent.getStringExtra(IntentKey.IDENTIFIER.keyName) val handHistoryId = intent.getStringExtra(IntentKey.IDENTIFIER.keyName)
val sessionId = intent.getStringExtra(IntentKey.SESSION_CONFIGURATION.keyName)
val fragment = HandHistoryFragment.newInstance(handHistoryId) val fragment = HandHistoryFragment.newInstance(handHistoryId)
fragmentTransaction.add(R.id.container, fragment) fragmentTransaction.add(R.id.container, fragment)
fragmentTransaction.commit() fragmentTransaction.commit()

@ -14,7 +14,6 @@ import kotlinx.android.synthetic.main.fragment_settings.recyclerView
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.handhistory.HandSetup
import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.Player import net.pokeranalytics.android.model.realm.Player
import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.Action
@ -54,11 +53,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
companion object { companion object {
fun newInstance(id: String? = null): HandHistoryFragment { fun newInstance(id: String? = null, configurationId: String? = null): HandHistoryFragment {
val fragment = val fragment = HandHistoryFragment()
HandHistoryFragment()
val bundle = Bundle() val bundle = Bundle()
bundle.putSerializable(BundleKey.PRIMARY_KEY.value, id) bundle.putSerializable(BundleKey.PRIMARY_KEY.value, id)
bundle.putSerializable(BundleKey.SECONDARY_KEY.value, configurationId)
fragment.arguments = bundle fragment.arguments = bundle
return fragment return fragment
} }
@ -100,8 +99,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.setHandHistory(handHistory) this.model.setHandHistory(handHistory)
this.setEditing(false) this.setEditing(false)
} ?: run { } ?: run {
val configurationId= this.arguments?.getString(BundleKey.SECONDARY_KEY.value)
getRealm().executeTransaction { getRealm().executeTransaction {
this.model.createNewHandHistory(it, HandSetup()) this.model.createNewHandHistory(it, configurationId)
} }
this.setEditing(true) this.setEditing(true)
} }
@ -128,8 +129,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow
// row.performActionForTag(it.tag)
row.keyboardForTag(it.tag)?.let { keyboard -> row.keyboardForTag(it.tag)?.let { keyboard ->
when (keyboard) { when (keyboard) {

@ -151,8 +151,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
/*** /***
* Creates and configures a new HandHistory object using a [handSetup] * Creates and configures a new HandHistory object using a [handSetup]
*/ */
fun createNewHandHistory(realm: Realm, handSetup: HandSetup) { fun createNewHandHistory(realm: Realm, configurationId: String?) {
this.handSetup = handSetup
this.handSetup = HandSetup.from(configurationId, realm)
createHandHistory(realm) createHandHistory(realm)
} }

@ -7,6 +7,12 @@
android:title="@string/stop" android:title="@string/stop"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/newHandHistory"
android:title="@string/new_hand"
android:icon="@drawable/ic_add"
app:showAsAction="never" />
<item <item
android:id="@+id/newCustomField" android:id="@+id/newCustomField"
android:title="@string/new_custom_field" android:title="@string/new_custom_field"

Loading…
Cancel
Save