HH configuration from Feed or Session

hh
Laurent 6 years ago
parent fa69fcb264
commit ad6828e333
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/TableSize.kt
  2. 19
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/ui/adapter/FeedSessionRowRepresentableAdapter.kt
  5. 14
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FeedFragment.kt
  6. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BaseFragment.kt
  7. 8
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt
  8. 23
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  9. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -9,7 +9,7 @@ import net.pokeranalytics.android.util.Parser
class TableSize( class TableSize(
var numberOfPlayer: Int, var numberOfPlayer: Int,
var rowViewType: Int = RowViewType.TITLE_GRID.ordinal, var rowViewType: Int = RowViewType.TITLE_GRID.ordinal,
var alternativeLabels: Boolean = true var alternativeLabels: Boolean = false
) : RowRepresentable { ) : RowRepresentable {
companion object { companion object {

@ -12,7 +12,11 @@ class HandSetup {
companion object { companion object {
fun from(configurationId: String?, realm: Realm): HandSetup { /***
* Returns a HandSetup instance using a [configurationId], the id of a Realm object,
* Session or HandHistory, used to later configure the HandHistory
*/
fun from(configurationId: String?, attached: Boolean, realm: Realm): HandSetup {
return if (configurationId != null) { return if (configurationId != null) {
val handSetup = HandSetup() val handSetup = HandSetup()
@ -22,7 +26,7 @@ class HandSetup {
} }
val session = realm.findById(Session::class.java, configurationId) val session = realm.findById(Session::class.java, configurationId)
if (session != null) { if (session != null) {
handSetup.configure(session) handSetup.configure(session, attached)
} }
handSetup handSetup
} else { } else {
@ -40,7 +44,14 @@ class HandSetup {
this.tableSize = handHistory.numberOfPlayers this.tableSize = handHistory.numberOfPlayers
} }
private fun configure(session: Session) { /***
* Configures the Hand Setup with a [session]
* [attached] denotes if the HandHistory must be directly linked to the session
*/
private fun configure(session: Session, attached: Boolean) {
if (attached) {
this.session = session
}
this.type = session.sessionType this.type = session.sessionType
this.smallBlind = session.cgSmallBlind this.smallBlind = session.cgSmallBlind
this.bigBlind = session.cgBigBlind this.bigBlind = session.cgBigBlind
@ -62,6 +73,8 @@ class HandSetup {
var game: Game? = null var game: Game? = null
var session: Session? = null
var straddlePositions: MutableList<Position> = mutableListOf() var straddlePositions: MutableList<Position> = mutableListOf()
private set private set

@ -125,6 +125,8 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
handSetup.smallBlind?.let { this.smallBlind = it } handSetup.smallBlind?.let { this.smallBlind = it }
handSetup.bigBlind?.let { this.bigBlind = it } handSetup.bigBlind?.let { this.bigBlind = it }
this.session = handSetup.session
this.createActions(handSetup.straddlePositions) this.createActions(handSetup.straddlePositions)
} }

@ -147,8 +147,8 @@ class FeedSessionRowRepresentableAdapter(
throw PAIllegalStateException("Any position should always have a header, position = $position") throw PAIllegalStateException("Any position should always have a header, position = $position")
} }
fun sessionIdForPosition(position: Int): String? { fun sessionForPosition(position: Int): Session? {
return this.getSessionForPosition(position)?.id return this.getSessionForPosition(position)
} }
/** /**

@ -137,9 +137,9 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
when (item?.itemId) { when (item?.itemId) {
R.id.duplicate -> { R.id.duplicate -> {
val sessionId = this.sessionAdapter.sessionIdForPosition(menuPosition) val session = this.sessionAdapter.sessionForPosition(menuPosition)
if (sessionId != null) { if (session != null) {
createNewSession(true, sessionId = sessionId, duplicate = true) createNewSession(true, sessionId = session.id, duplicate = true)
} else { } else {
throw PAIllegalStateException("Session not found for duplicate at position: $menuPosition") throw PAIllegalStateException("Session not found for duplicate at position: $menuPosition")
} }
@ -465,9 +465,11 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
* Create a new hand history * Create a new hand history
*/ */
private fun createNewHandHistory() { private fun createNewHandHistory() {
this.sessionAdapter.sessionForPosition(0)?.let { session ->
HandHistoryActivity.newInstance(this) HandHistoryActivity.newInstance(this, session, false)
} ?: run {
HandHistoryActivity.newInstance(this)
}
} }
/** /**

@ -19,7 +19,8 @@ abstract class BaseFragment : Fragment() {
PRIMARY_KEY("primary_key"), PRIMARY_KEY("primary_key"),
SECONDARY_KEY("secondary_key"), SECONDARY_KEY("secondary_key"),
DATA_TYPE("data_type"), DATA_TYPE("data_type"),
SHOW_MESSAGE("show_message") SHOW_MESSAGE("show_message"),
ATTACHED("attached")
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

@ -12,14 +12,16 @@ class HandHistoryActivity : BaseActivity() {
enum class IntentKey(val keyName: String) { enum class IntentKey(val keyName: String) {
IDENTIFIER("identifier"), IDENTIFIER("identifier"),
SESSION_CONFIGURATION("session_id") SESSION_CONFIGURATION("session_id"),
ATTACHED("attached")
} }
companion object { companion object {
fun newInstance(fragment: Fragment, session: Session) { fun newInstance(fragment: Fragment, session: Session, attached: Boolean) {
val intent = Intent(fragment.requireContext(), HandHistoryActivity::class.java) val intent = Intent(fragment.requireContext(), HandHistoryActivity::class.java)
intent.putExtra(IntentKey.SESSION_CONFIGURATION.keyName, session.id) intent.putExtra(IntentKey.SESSION_CONFIGURATION.keyName, session.id)
intent.putExtra(IntentKey.ATTACHED.keyName, attached)
fragment.startActivityForResult(intent, RequestCode.NEW_HAND_HISTORY.value) fragment.startActivityForResult(intent, RequestCode.NEW_HAND_HISTORY.value)
} }
@ -47,7 +49,7 @@ class HandHistoryActivity : BaseActivity() {
val handHistoryId = intent.getStringExtra(IntentKey.IDENTIFIER.keyName) val handHistoryId = intent.getStringExtra(IntentKey.IDENTIFIER.keyName)
val sessionId = intent.getStringExtra(IntentKey.SESSION_CONFIGURATION.keyName) val sessionId = intent.getStringExtra(IntentKey.SESSION_CONFIGURATION.keyName)
val fragment = HandHistoryFragment.newInstance(handHistoryId) val fragment = HandHistoryFragment.newInstance(handHistoryId, sessionId)
fragmentTransaction.add(R.id.container, fragment) fragmentTransaction.add(R.id.container, fragment)
fragmentTransaction.commit() fragmentTransaction.commit()

@ -23,6 +23,7 @@ import net.pokeranalytics.android.ui.activity.DataListActivity
import net.pokeranalytics.android.ui.activity.components.RequestCode import net.pokeranalytics.android.ui.activity.components.RequestCode
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.extensions.px import net.pokeranalytics.android.ui.extensions.px
import net.pokeranalytics.android.ui.fragment.components.BaseFragment
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.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
@ -36,6 +37,12 @@ import timber.log.Timber
class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListener { class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListener {
private enum class BundleKey(var value: String) {
HAND_HISTORY_ID("hand_history_id"),
CONFIGURATION_ID("configuration_id"),
ATTACHED("attached"),
}
/*** /***
* The fragment's ViewModel * The fragment's ViewModel
*/ */
@ -53,11 +60,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
companion object { companion object {
fun newInstance(id: String? = null, configurationId: String? = null): HandHistoryFragment { fun newInstance(id: String? = null, configurationId: String? = null, attached: Boolean = false): HandHistoryFragment {
val fragment = HandHistoryFragment() val fragment = HandHistoryFragment()
val bundle = Bundle() val bundle = Bundle()
bundle.putSerializable(BundleKey.PRIMARY_KEY.value, id) bundle.putSerializable(BundleKey.HAND_HISTORY_ID.value, id)
bundle.putSerializable(BundleKey.SECONDARY_KEY.value, configurationId) bundle.putSerializable(BundleKey.CONFIGURATION_ID.value, configurationId)
bundle.putSerializable(BundleKey.ATTACHED.value, attached)
fragment.arguments = bundle fragment.arguments = bundle
return fragment return fragment
} }
@ -91,7 +99,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
private fun initData() { private fun initData() {
val handHistoryId = this.arguments?.getString(BundleKey.PRIMARY_KEY.value) val handHistoryId = this.arguments?.getString(BundleKey.HAND_HISTORY_ID.value)
handHistoryId?.let { handHistoryId?.let {
val handHistory = getRealm().findById<HandHistory>(it) val handHistory = getRealm().findById<HandHistory>(it)
@ -99,10 +107,11 @@ 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) val configurationId= this.arguments?.getString(BundleKey.CONFIGURATION_ID.value)
val attached= this.arguments?.getBoolean(BundleKey.ATTACHED.value) ?: false
getRealm().executeTransaction { getRealm().executeTransaction {
this.model.createNewHandHistory(it, configurationId) this.model.createNewHandHistory(it, configurationId, attached)
} }
this.setEditing(true) this.setEditing(true)
} }
@ -190,7 +199,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
when (requestCode) { when (requestCode) {
RequestCode.PLAYER_SELECTION.ordinal -> { RequestCode.PLAYER_SELECTION.ordinal -> {
val playerId = data?.getStringExtra(BundleKey.PRIMARY_KEY.value) ?: throw PAIllegalStateException("Primary key not set where as activity has finished") val playerId = data?.getStringExtra(BaseFragment.BundleKey.PRIMARY_KEY.value) ?: throw PAIllegalStateException("Primary key not set where as activity has finished")
getRealm().findById<Player>(playerId)?.let { player -> getRealm().findById<Player>(playerId)?.let { player ->
this.model.playerSelected(player) this.model.playerSelected(player)
} ?: throw PAIllegalStateException("Player (id=$playerId) not found") } ?: throw PAIllegalStateException("Player (id=$playerId) not found")

@ -151,9 +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, configurationId: String?) { fun createNewHandHistory(realm: Realm, configurationId: String?, attached: Boolean) {
this.handSetup = HandSetup.from(configurationId, realm) this.handSetup = HandSetup.from(configurationId, attached, realm)
createHandHistory(realm) createHandHistory(realm)
} }

Loading…
Cancel
Save