@ -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 . B undleKey . 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 " )