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 1ba7a4c2..403ff443 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 @@ -1,7 +1,10 @@ package net.pokeranalytics.android.ui.modules.handhistory +import android.animation.ValueAnimator import android.os.Bundle import android.view.* +import android.view.animation.AccelerateDecelerateInterpolator +import androidx.constraintlayout.widget.ConstraintLayout import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import kotlinx.android.synthetic.main.fragment_hand_history.* @@ -14,6 +17,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.Card import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate +import net.pokeranalytics.android.ui.extensions.px 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 @@ -125,13 +129,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } keyboard?.let { - this.keyboard.show(it) +// this.animateKeyboard(true) + this.showKeyboard(it) +// this.keyboard.show(it) } ?: run { - this.keyboard.hide() + this.animateKeyboard(false) } } ?: run { - this.keyboard.hide() + this.animateKeyboard(false) } } @@ -152,6 +158,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } } + initKeyboard() this.keyboard.keyboardListener = this this.keyboard.setCardCentralizer(this.model) } @@ -206,30 +213,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.findNextActionToEdit(0) } - private fun closeEdition() { - this.model.isEdited = false - } - private fun findNextActionToEdit(index: Int? = null, userInitiated: Boolean = false) { val startIndex = index ?: this.model.currentSelection.index val minTag = if (index != null) null else this.model.currentSelection.tag this.model.findSelectionForEdition(startIndex, minTag, userInitiated)?.let { selection -> - this.scrollToPosition(selection.index) - -// this.model.currentKeyboard?.let { keyboard -> -// when (keyboard) { -// HHKeyboard.ACTION -> { -// configureActionKeyboard() -// } else -> {} -// } -// this.keyboard.show(keyboard) -// } - } ?: run { - this.keyboard.hide() + this.animateKeyboard(false) } // The whole data set is refreshed because of a weird EditText bug where @@ -249,7 +241,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL return } - when (row.bottomSheetType) { + when (row.bottomSheetType) { // Comment, number of players BottomSheetType.NONE -> {} else -> { val editDescriptors = listOf(RowRepresentableEditDescriptor(this.model.handHistory.comment, R.string.comment)) @@ -404,7 +396,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL val currentIndex = this.model.currentSelection.index this.model.selectionLiveData.value = null this.handHistoryAdapter.notifyItemChanged(currentIndex) - this.keyboard?.hide() + this.animateKeyboard(false) +// this.hideKeyboard() } override fun positionSelected(position: Position) { @@ -443,4 +436,42 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } } + + private fun showKeyboard(keyboard: HHKeyboard) { + + val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams + if (lp.guideEnd == 0) { + this.animateKeyboard(true) + } + this.keyboard.show(keyboard) + } + + private fun animateKeyboard(show: Boolean) { + + val height = 300.0f.px + val start = if (show) 0.0f else height + val end = if (show) height else 0.0f + +// val end = (this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams).guideEnd + val valueAnimator = ValueAnimator.ofFloat(start, end) + valueAnimator.duration = 150L + // set duration + valueAnimator.interpolator = AccelerateDecelerateInterpolator() + // set interpolator and updateListener to get the animated value + valueAnimator.addUpdateListener { + val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams + // get the float value + lp.guideEnd = (it.animatedValue as Float).toInt() + // update layout params + this.kbTopGuideline.layoutParams = lp + } + valueAnimator.start() + } + + + private fun initKeyboard() { + val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams + lp.guideEnd = 0 + } + } \ No newline at end of file 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 a998b660..25b885e9 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 @@ -56,6 +56,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra set(value) { field = value createRowRepresentation() + if (!value) { + this.selectionLiveData.value = null + } } /*** diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt index 7e55fd01..c26d3476 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt @@ -5,7 +5,6 @@ import android.util.AttributeSet import android.view.View import android.widget.EditText import android.widget.FrameLayout -import androidx.core.view.isVisible import net.pokeranalytics.android.R import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.model.handhistory.Position @@ -31,7 +30,13 @@ interface PositionSelectionListener { fun positionSelected(position: Position) } -class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { +class KeyboardContainer : FrameLayout { + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) + + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) private val keyboards = HashMap() @@ -67,24 +72,10 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co } } - private fun show() { - if (!this.isVisible) { - val height = this.height.toFloat() - this.translationY = height - this.visibility = View.VISIBLE - this.animate().translationY(0.0f).setDuration(250).start() - } - } - - fun hide() { - // animate - this.visibility = View.GONE - } - fun show(type: HHKeyboard) { // Timber.d("show keyboard : $type") - show() +// showAnimated() this.keyboards[type]?.let { show(it) @@ -119,15 +110,4 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co cardKeyboard.setCardCentralizer(centralizer) } -// private fun loadView(layoutId: Int) { -// val layoutInflater = LayoutInflater.from(context) -// constraintLayout = layoutInflater.inflate(layoutId, this, false) as ConstraintLayout -// val layoutParams = LayoutParams( -// LayoutParams.MATCH_PARENT, -// LayoutParams.MATCH_PARENT -// ) -// addView(constraintLayout, layoutParams) -// -// } - } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_hand_history.xml b/app/src/main/res/layout/fragment_hand_history.xml index 13ec2eba..52255345 100644 --- a/app/src/main/res/layout/fragment_hand_history.xml +++ b/app/src/main/res/layout/fragment_hand_history.xml @@ -29,18 +29,27 @@ android:id="@+id/recyclerView" android:layout_width="0dp" android:layout_height="0dp" - app:layout_constraintBottom_toTopOf="@id/keyboard" + app:layout_constraintBottom_toTopOf="@id/kbTopGuideline" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/appBar" /> + + + app:layout_constraintStart_toStartOf="parent" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/view_hand_keyboard_action.xml b/app/src/main/res/layout/view_hand_keyboard_action.xml index 45162313..b880bd35 100644 --- a/app/src/main/res/layout/view_hand_keyboard_action.xml +++ b/app/src/main/res/layout/view_hand_keyboard_action.xml @@ -2,7 +2,7 @@ diff --git a/app/src/main/res/layout/view_hand_keyboard_amount.xml b/app/src/main/res/layout/view_hand_keyboard_amount.xml index a0d4198c..69a4af42 100644 --- a/app/src/main/res/layout/view_hand_keyboard_amount.xml +++ b/app/src/main/res/layout/view_hand_keyboard_amount.xml @@ -1,7 +1,7 @@