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(
var numberOfPlayer: Int,
var rowViewType: Int = RowViewType.TITLE_GRID.ordinal,
var alternativeLabels: Boolean = true
var alternativeLabels: Boolean = false
) : RowRepresentable {
companion object {

@ -12,7 +12,11 @@ class HandSetup {
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) {
val handSetup = HandSetup()
@ -22,7 +26,7 @@ class HandSetup {
}
val session = realm.findById(Session::class.java, configurationId)
if (session != null) {
handSetup.configure(session)
handSetup.configure(session, attached)
}
handSetup
} else {
@ -40,7 +44,14 @@ class HandSetup {
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.smallBlind = session.cgSmallBlind
this.bigBlind = session.cgBigBlind
@ -62,6 +73,8 @@ class HandSetup {
var game: Game? = null
var session: Session? = null
var straddlePositions: MutableList<Position> = mutableListOf()
private set

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

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

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

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

@ -12,14 +12,16 @@ class HandHistoryActivity : BaseActivity() {
enum class IntentKey(val keyName: String) {
IDENTIFIER("identifier"),
SESSION_CONFIGURATION("session_id")
SESSION_CONFIGURATION("session_id"),
ATTACHED("attached")
}
companion object {
fun newInstance(fragment: Fragment, session: Session) {
fun newInstance(fragment: Fragment, session: Session, attached: Boolean) {
val intent = Intent(fragment.requireContext(), HandHistoryActivity::class.java)
intent.putExtra(IntentKey.SESSION_CONFIGURATION.keyName, session.id)
intent.putExtra(IntentKey.ATTACHED.keyName, attached)
fragment.startActivityForResult(intent, RequestCode.NEW_HAND_HISTORY.value)
}
@ -47,7 +49,7 @@ class HandHistoryActivity : BaseActivity() {
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, sessionId)
fragmentTransaction.add(R.id.container, fragment)
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.adapter.RowRepresentableDelegate
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.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
@ -36,6 +37,12 @@ import timber.log.Timber
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
*/
@ -53,11 +60,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
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 bundle = Bundle()
bundle.putSerializable(BundleKey.PRIMARY_KEY.value, id)
bundle.putSerializable(BundleKey.SECONDARY_KEY.value, configurationId)
bundle.putSerializable(BundleKey.HAND_HISTORY_ID.value, id)
bundle.putSerializable(BundleKey.CONFIGURATION_ID.value, configurationId)
bundle.putSerializable(BundleKey.ATTACHED.value, attached)
fragment.arguments = bundle
return fragment
}
@ -91,7 +99,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
private fun initData() {
val handHistoryId = this.arguments?.getString(BundleKey.PRIMARY_KEY.value)
val handHistoryId = this.arguments?.getString(BundleKey.HAND_HISTORY_ID.value)
handHistoryId?.let {
val handHistory = getRealm().findById<HandHistory>(it)
@ -99,10 +107,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.setHandHistory(handHistory)
this.setEditing(false)
} ?: 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 {
this.model.createNewHandHistory(it, configurationId)
this.model.createNewHandHistory(it, configurationId, attached)
}
this.setEditing(true)
}
@ -190,7 +199,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
when (requestCode) {
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 ->
this.model.playerSelected(player)
} ?: 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]
*/
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)
}

Loading…
Cancel
Save