From 12495533b39f6c38c43efae9d018798c9edb5237 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 14 Feb 2020 15:41:55 +0100 Subject: [PATCH] Fixes cursor placement --- .../modules/handhistory/HandHistoryAdapter.kt | 83 ++++++------------- .../ui/modules/handhistory/model/CardsRow.kt | 8 +- .../handhistory/views/KeyboardAmountView.kt | 17 ++++ .../CustomizableRowRepresentable.kt | 2 +- 4 files changed, 48 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt index 2435920d..a0ebcb14 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt @@ -216,38 +216,6 @@ class HandHistoryAdapter( this.configureEditTexts(index..index, position, row, adapter) } - protected fun setClickListener(editText: EditText) { - - editText.isFocusableInTouchMode = true - -// editText.setOnClickListener { -// -// itemView.context.hideKeyboard(it) -// -// editText.isFocusable = true -// editText.isFocusableInTouchMode = true -// -// editText.requestFocus() -// -// editTextSelected(editText, true, editText.tag as Int) -// } - - editText.setOnTouchListener { _, event -> - - if (event.action == MotionEvent.ACTION_UP) { - // Both are required, otherwise requestFocus() fails - editText.isFocusable = true - editText.isFocusableInTouchMode = true - - editText.requestFocus() - - editTextSelected(editText, true, editText.tag as Int) - } - return@setOnTouchListener true - } - - } - protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { tagRange.forEach { tag -> @@ -270,6 +238,11 @@ class HandHistoryAdapter( editText.isFocusable = adapter.dataSource.isFocusable(position, row, tag) editText.isFocusableInTouchMode = adapter.dataSource.isFocusable(position, row, tag) + // Put cursor at the end + if (focused) { + editText.setSelection(editText.text.length) + } + // Background editText.setBackgroundColor(color(focused)) @@ -277,6 +250,26 @@ class HandHistoryAdapter( } + protected fun setClickListener(editText: EditText) { + + editText.isFocusableInTouchMode = true + + editText.setOnTouchListener { _, event -> + + if (event.action == MotionEvent.ACTION_UP) { + // Both are required, otherwise requestFocus() fails + editText.isFocusable = true + editText.isFocusableInTouchMode = true + + editText.requestFocus() + + editTextSelected(editText, true, editText.tag as Int) + } + return@setOnTouchListener true + } + + } + private fun toggleFocus(editText: EditText, focused: Boolean) { if (focused) { editText.requestFocus() @@ -326,7 +319,6 @@ class HandHistoryAdapter( val chip = Chip(itemView.context) chip.id = View.generateViewId() -// chip.tag = filter.id chip.text = pos.shortValue chip.chipStartPadding = 4f.px chip.chipEndPadding = 4f.px @@ -402,7 +394,6 @@ class HandHistoryAdapter( // Action itemView.findViewById