diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt index 5fdf1035..be8504ca 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HandSetup.kt @@ -1,12 +1,53 @@ package net.pokeranalytics.android.model.handhistory +import io.realm.Realm import net.pokeranalytics.android.model.realm.Game 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 java.util.* 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 smallBlind: Double? = null diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt index bbdeed0f..7ec574ea 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt @@ -131,6 +131,9 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat @Index var type: Int = Type.CASH_GAME.ordinal + val sessionType: Type + get() { return Type.values()[this.type] } + // The result of the main user var result: Result? = null diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt index 9ba18594..dc029cff 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt @@ -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.bottomsheet.BottomSheetFragment 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.RowRepresentableDiffCallback import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager @@ -143,6 +144,7 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate { override fun onOptionsItemSelected(item: MenuItem?): Boolean { when (item!!.itemId) { R.id.stop -> stopSession() + R.id.newHandHistory -> addHandHistory() R.id.newCustomField -> addNewCustomField() R.id.restart -> restartTimer() R.id.delete -> deleteSession() @@ -355,6 +357,10 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate { updateSessionUI() } + private fun addHandHistory() { + HandHistoryActivity.newInstance(this, this.currentSession) + } + /** * Add new custom field */ diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BaseFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BaseFragment.kt index bc57f0d1..7dbae9fe 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BaseFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BaseFragment.kt @@ -17,6 +17,7 @@ abstract class BaseFragment : Fragment() { enum class BundleKey(val value: String) { STYLE("style"), PRIMARY_KEY("primary_key"), + SECONDARY_KEY("secondary_key"), DATA_TYPE("data_type"), SHOW_MESSAGE("show_message") } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt index 0c90fd2b..718db973 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt @@ -4,17 +4,25 @@ import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment 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.RequestCode class HandHistoryActivity : BaseActivity() { enum class IntentKey(val keyName: String) { - IDENTIFIER("identifier") + IDENTIFIER("identifier"), + SESSION_CONFIGURATION("session_id") } 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) { val intent = Intent(fragment.requireContext(), HandHistoryActivity::class.java) id?.let { intent.putExtra(IntentKey.IDENTIFIER.keyName, it) } @@ -38,6 +46,7 @@ class HandHistoryActivity : BaseActivity() { val fragmentTransaction = supportFragmentManager.beginTransaction() val handHistoryId = intent.getStringExtra(IntentKey.IDENTIFIER.keyName) + val sessionId = intent.getStringExtra(IntentKey.SESSION_CONFIGURATION.keyName) val fragment = HandHistoryFragment.newInstance(handHistoryId) fragmentTransaction.add(R.id.container, fragment) fragmentTransaction.commit() diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt index d58c782d..27246f10 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt @@ -14,7 +14,6 @@ import kotlinx.android.synthetic.main.fragment_settings.recyclerView import net.pokeranalytics.android.R import net.pokeranalytics.android.exceptions.PAIllegalStateException 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.realm.Player import net.pokeranalytics.android.model.realm.handhistory.Action @@ -54,11 +53,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL companion object { - fun newInstance(id: String? = null): HandHistoryFragment { - val fragment = - HandHistoryFragment() + fun newInstance(id: String? = null, configurationId: String? = null): HandHistoryFragment { + val fragment = HandHistoryFragment() val bundle = Bundle() bundle.putSerializable(BundleKey.PRIMARY_KEY.value, id) + bundle.putSerializable(BundleKey.SECONDARY_KEY.value, configurationId) fragment.arguments = bundle return fragment } @@ -100,8 +99,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.model.setHandHistory(handHistory) this.setEditing(false) } ?: run { + val configurationId= this.arguments?.getString(BundleKey.SECONDARY_KEY.value) + getRealm().executeTransaction { - this.model.createNewHandHistory(it, HandSetup()) + this.model.createNewHandHistory(it, configurationId) } this.setEditing(true) } @@ -128,8 +129,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow -// row.performActionForTag(it.tag) - row.keyboardForTag(it.tag)?.let { keyboard -> when (keyboard) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt index 812019d5..0d1ba5d8 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt @@ -151,8 +151,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra /*** * Creates and configures a new HandHistory object using a [handSetup] */ - fun createNewHandHistory(realm: Realm, handSetup: HandSetup) { - this.handSetup = handSetup + fun createNewHandHistory(realm: Realm, configurationId: String?) { + + this.handSetup = HandSetup.from(configurationId, realm) createHandHistory(realm) } diff --git a/app/src/main/res/menu/toolbar_session.xml b/app/src/main/res/menu/toolbar_session.xml index 80d24410..382cddad 100644 --- a/app/src/main/res/menu/toolbar_session.xml +++ b/app/src/main/res/menu/toolbar_session.xml @@ -7,6 +7,12 @@ android:title="@string/stop" app:showAsAction="always" /> + +