@ -18,7 +18,6 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.Player
import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.model.realm.handhistory.Card
@ -26,6 +25,7 @@ import net.pokeranalytics.android.model.realm.handhistory.HandHistory
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.extensions.toByteArray
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
@ -39,6 +39,7 @@ import net.pokeranalytics.android.ui.modules.handhistory.views.KeyboardListener
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
import net.pokeranalytics.android.util.extensions.findById
import net.pokeranalytics.android.util.video.MMediaMuxer
import timber.log.Timber
@ -72,7 +73,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
companion object {
fun newInstance ( id : String ? = null , configurationId : String ? = null , attached : Boolean = false ) : HandHistoryFragment {
fun newInstance (
id : String ? = null ,
configurationId : String ? = null ,
attached : Boolean = false
) : HandHistoryFragment {
val fragment = HandHistoryFragment ( )
val bundle = Bundle ( )
bundle . putSerializable ( BundleKey . HAND _HISTORY _ID . value , id )
@ -93,7 +98,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
override fun onCreateView ( inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ) : View ? {
override fun onCreateView (
inflater : LayoutInflater ,
container : ViewGroup ? ,
savedInstanceState : Bundle ?
) : View ? {
super . onCreateView ( inflater , container , savedInstanceState )
return inflater . inflate ( R . layout . fragment _hand _history , container , false )
}
@ -115,8 +124,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this . model . setHandHistory ( hhCopy )
this . setEditing ( false )
} ?: run {
val configurationId = this . arguments ?. getString ( BundleKey . CONFIGURATION _ID . value )
val attached = this . arguments ?. getBoolean ( BundleKey . ATTACHED . value ) ?: false
val configurationId = this . arguments ?. getString ( BundleKey . CONFIGURATION _ID . value )
val attached = this . arguments ?. getBoolean ( BundleKey . ATTACHED . value ) ?: false
this . model . createNewHandHistory ( getRealm ( ) , configurationId , attached )
this . setEditing ( true )
@ -130,7 +139,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
setDisplayHomeAsUpEnabled ( true )
this . handHistoryAdapter = HandHistoryAdapter ( this . model , this )
this . handHistoryAdapter = HandHistoryAdapter ( this . model , this )
// val swipeToDelete = SwipeToDeleteCallback { position ->
// this.model.deleteIfPossible(position)
@ -162,7 +171,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val selection = this . model . currentSelection
retrieveEditTextInputConnection ( selection )
}
else -> { }
else -> {
}
}
}
@ -185,7 +195,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
RequestCode . PLAYER _SELECTION . ordinal -> {
if ( resultCode == Activity . RESULT _OK ) {
val playerId = data ?. getStringExtra ( BaseFragment . 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 " )
@ -238,7 +249,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
HHKeyboard . AMOUNT -> {
retrieveEditTextInputConnection ( selection )
}
else -> { }
else -> {
}
}
this . showKeyboard ( kb ) {
@ -270,10 +282,14 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val handRow = this . model . rowRepresentableForPosition ( selection . index ) as ? HandHistoryRow
val holder = recyclerView . findViewHolderForAdapterPosition ( selection . index ) as ? HandHistoryAdapter . RowHandHolder
val holder =
recyclerView . findViewHolderForAdapterPosition ( selection . index ) as ? HandHistoryAdapter . RowHandHolder
holder ?. let {
val amountEditText = it . editTextForTag ( selection . tag )
this . keyboard . setAmountEditText ( amountEditText , handRow ?. amountForTag ( this . model . handHistory , selection . tag ) )
this . keyboard . setAmountEditText (
amountEditText ,
handRow ?. amountForTag ( this . model . handHistory , selection . tag )
)
} ?: run {
Timber . d ( " no holder, or not RowHandAction " )
}
@ -337,17 +353,31 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
when ( row . bottomSheetType ) { // Comment, number of players...
BottomSheetType . NONE -> { }
BottomSheetType . NONE -> {
}
else -> {
val editDescriptors = this . model . editDescriptors ( row )
when ( row ) {
HandRowType . PLAYER _NUMBER -> {
BottomSheetFragment . create ( requireFragmentManager ( ) , row , this , editDescriptors , isClearable = false , alternativeLabels = true )
BottomSheetFragment . create (
requireFragmentManager ( ) ,
row ,
this ,
editDescriptors ,
isClearable = false ,
alternativeLabels = true
)
}
else -> {
BottomSheetFragment . create ( requireFragmentManager ( ) , row , this , editDescriptors , alternativeLabels = true )
BottomSheetFragment . create (
requireFragmentManager ( ) ,
row ,
this ,
editDescriptors ,
alternativeLabels = true
)
}
}
@ -527,7 +557,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
onRowSelected ( rowRepresentableIndex , it , ComputedAction . Tag . ACTION . ordinal )
this . handHistoryAdapter . notifyItemChanged ( rowRepresentableIndex )
this . scrollToPosition ( rowRepresentableIndex )
} ?: throw PAIllegalStateException ( " Rowrepresentable not fouind at index $rowRepresentableIndex " )
}
?: throw PAIllegalStateException ( " Rowrepresentable not fouind at index $rowRepresentableIndex " )
}
// Table
@ -642,9 +673,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val builder : AlertDialog . Builder = AlertDialog . Builder ( context )
builder . setTitle ( R . string . position )
builder . setItems ( arrayOf < CharSequence > (
builder . setItems (
arrayOf < CharSequence > (
getString ( R . string . remove )
) ) { _ , index ->
)
) { _ , index ->
// The 'which' argument contains the index position
// of the selected item
when ( index ) {
@ -666,11 +699,13 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val builder : AlertDialog . Builder = AlertDialog . Builder ( context )
builder . setTitle ( R . string . export )
builder . setItems ( arrayOf < CharSequence > (
builder . setItems (
arrayOf < CharSequence > (
getString ( R . string . text )
// getString(R.string.video),
// "GIF"
) ) { _ , index ->
)
) { _ , index ->
// The 'which' argument contains the index position
// of the selected item
when ( index ) {
@ -687,17 +722,33 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val config = ReplayerConfiguration ( this . model . handHistory )
val bitmap = Bitmap . createBitmap ( 480 , 480 , Bitmap . Config . ARGB _8888 )
val width = 480
val height = 480
val bitmap = Bitmap . createBitmap ( width , height , Bitmap . Config . ARGB _8888 )
val tc = TableCanvas ( bitmap )
// draw initial table
TableCanvas . initializeTable ( config , tc , requireContext ( ) )
HandStep . build ( this . model . handHistory ) . forEach {
it . draw ( config , tc , requireContext ( ) )
val muxer = MMediaMuxer ( )
muxer . Init ( requireActivity ( ) , bitmap . width , bitmap . height , " hhVideo " , " YES! " )
HandStep . createSteps ( this . model . handHistory ) . forEach { step ->
step . frames ( config , tc , requireContext ( ) ) {
try {
val byteArray = bitmap . toByteArray ( )
muxer . AddFrame ( byteArray )
} catch ( e : Exception ) {
Timber . e ( " error = ${e.message} " )
}
}
}
muxer . CreateVideo ( )
val path = muxer . GetPath ( )
Timber . d ( " **** Video path = $path " )
// Timber.d("**** Start video test")
//