|
|
|
@ -4,6 +4,9 @@ import android.os.Bundle |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import android.view.inputmethod.EditorInfo |
|
|
|
|
|
|
|
import android.view.inputmethod.InputConnection |
|
|
|
|
|
|
|
import android.widget.EditText |
|
|
|
import androidx.lifecycle.ViewModelProviders |
|
|
|
import androidx.lifecycle.ViewModelProviders |
|
|
|
import kotlinx.android.synthetic.main.fragment_hand_history.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_hand_history.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_settings.recyclerView |
|
|
|
import kotlinx.android.synthetic.main.fragment_settings.recyclerView |
|
|
|
@ -34,6 +37,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
|
|
|
|
|
|
|
|
private var rows: List<RowRepresentable> = listOf() |
|
|
|
private var rows: List<RowRepresentable> = listOf() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var inputConnection: InputConnection? = null |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
|
|
fun newInstance(id: String? = null): HandHistoryFragment { |
|
|
|
fun newInstance(id: String? = null): HandHistoryFragment { |
|
|
|
@ -64,6 +69,13 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
initUI() |
|
|
|
initUI() |
|
|
|
|
|
|
|
this.edit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.model.currentSelection.value?.index?.let { |
|
|
|
|
|
|
|
Timber.d(">>>> attempt to retrieveEditTextInputConnection") |
|
|
|
|
|
|
|
this.retrieveEditTextInputConnection(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
@ -77,6 +89,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
} |
|
|
|
} |
|
|
|
this.model.setBuilder(builder) |
|
|
|
this.model.setBuilder(builder) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.rows = this.model.builder.value?.rowRepresentables() ?: listOf() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initUI() { |
|
|
|
private fun initUI() { |
|
|
|
@ -87,7 +101,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
|
|
|
|
|
|
|
|
// SmoothScrollLinearLayoutManager(requireContext()) |
|
|
|
// SmoothScrollLinearLayoutManager(requireContext()) |
|
|
|
// val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
// val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
handHistoryAdapter = HandHistoryAdapter(this, this) |
|
|
|
this.handHistoryAdapter = HandHistoryAdapter(this, this) |
|
|
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
recyclerView.apply { |
|
|
|
setHasFixedSize(true) |
|
|
|
setHasFixedSize(true) |
|
|
|
@ -95,11 +109,25 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
adapter = handHistoryAdapter |
|
|
|
adapter = handHistoryAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.rows = this.model.builder.value?.rowRepresentables() ?: listOf() |
|
|
|
this.model.currentSelection.observeForever { selection -> |
|
|
|
|
|
|
|
Timber.d("Current selection is ${selection.index} / ${selection.keyboard}") |
|
|
|
|
|
|
|
retrieveEditTextInputConnection(selection.index) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.keyboard.keyboardListener = this |
|
|
|
this.keyboard.keyboardListener = this |
|
|
|
|
|
|
|
|
|
|
|
this.edit() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun retrieveEditTextInputConnection(position: Int) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val holder = recyclerView.findViewHolderForAdapterPosition(position) as? HandHistoryAdapter.RowHandAction |
|
|
|
|
|
|
|
holder?.let { |
|
|
|
|
|
|
|
this.inputConnection = it.itemView.findViewById<EditText>(R.id.amountEditText) |
|
|
|
|
|
|
|
.onCreateInputConnection(EditorInfo()) |
|
|
|
|
|
|
|
} ?: run { |
|
|
|
|
|
|
|
Timber.d("no holder, or not RowHandAction") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun edit() { |
|
|
|
private fun edit() { |
|
|
|
@ -112,7 +140,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun findNextActionToEdit() { |
|
|
|
private fun findNextActionToEdit() { |
|
|
|
val selection = this.model.currentSelection |
|
|
|
val selection = this.model.currentSelection.value |
|
|
|
val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection") |
|
|
|
val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection") |
|
|
|
this.findNextActionToEdit(index, selection.keyboard) |
|
|
|
this.findNextActionToEdit(index, selection.keyboard) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -152,12 +180,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// if (tag == HHKeyboard.ACTION.ordinal) { |
|
|
|
// if (tag == HHKeyboard.ACTION.ordinal) { |
|
|
|
this.model.currentSelection?.index?.let { oldIndex -> |
|
|
|
this.model.currentSelection.value?.index?.let { oldIndex -> |
|
|
|
refreshCells(oldIndex) |
|
|
|
refreshCells(oldIndex) |
|
|
|
} |
|
|
|
} |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
this.model.currentSelection = HHSelection(position, HHKeyboard.values()[tag]) |
|
|
|
this.model.currentSelection.value = HHSelection(position, HHKeyboard.values()[tag]) |
|
|
|
|
|
|
|
|
|
|
|
// scrolls to selected position |
|
|
|
// scrolls to selected position |
|
|
|
// this.recyclerView.scrollToPosition(position) |
|
|
|
// this.recyclerView.scrollToPosition(position) |
|
|
|
@ -182,7 +210,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onRowDeselected(position: Int, row: RowRepresentable) { |
|
|
|
override fun onRowDeselected(position: Int, row: RowRepresentable) { |
|
|
|
this.model.currentSelection = null |
|
|
|
this.model.currentSelection.value = null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { |
|
|
|
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { |
|
|
|
@ -191,8 +219,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
|
|
|
|
|
|
|
|
override fun isSelected(position: Int, row: RowRepresentable, tag: Int): Boolean { |
|
|
|
override fun isSelected(position: Int, row: RowRepresentable, tag: Int): Boolean { |
|
|
|
val currentSelection = this.model.currentSelection |
|
|
|
val currentSelection = this.model.currentSelection |
|
|
|
val isSelectedIndex = (position == currentSelection?.index) |
|
|
|
val isSelectedIndex = (position == currentSelection.value?.index) |
|
|
|
val isSelectedAction = (tag == currentSelection?.keyboard?.ordinal) |
|
|
|
val isSelectedAction = (tag == currentSelection.value?.keyboard?.ordinal) |
|
|
|
// Timber.d("position = $position, tag = $tag, current index = ${currentSelection?.index}, kb = ${currentSelection?.keyboard}") |
|
|
|
// Timber.d("position = $position, tag = $tag, current index = ${currentSelection?.index}, kb = ${currentSelection?.keyboard}") |
|
|
|
return isSelectedIndex && isSelectedAction |
|
|
|
return isSelectedIndex && isSelectedAction |
|
|
|
} |
|
|
|
} |
|
|
|
@ -240,6 +268,22 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
|
|
|
|
|
|
|
|
override fun amountKeyTyped(key: NumericKey) { |
|
|
|
override fun amountKeyTyped(key: NumericKey) { |
|
|
|
this.model.amountKeyTyped(key) |
|
|
|
this.model.amountKeyTyped(key) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.inputConnection?.let { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when { |
|
|
|
|
|
|
|
key.isBackSpace -> { it.deleteSurroundingText(1, 0) } |
|
|
|
|
|
|
|
key.isDecimalSeparator -> { |
|
|
|
|
|
|
|
val text = it.getSelectedText(0) |
|
|
|
|
|
|
|
if (text != null && !text.contains(key.value)) { |
|
|
|
|
|
|
|
it.commitText(key.value, 1) |
|
|
|
|
|
|
|
} else { false } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { it.commitText(key.value, 1) } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Table refresh |
|
|
|
// Table refresh |
|
|
|
@ -250,7 +294,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun refreshCurrentRow() { |
|
|
|
private fun refreshCurrentRow() { |
|
|
|
this.model.currentSelection?.index?.let { |
|
|
|
this.model.currentSelection.value?.index?.let { |
|
|
|
Timber.d("refreshes row at index = $it") |
|
|
|
Timber.d("refreshes row at index = $it") |
|
|
|
this.handHistoryAdapter.notifyItemChanged(it) |
|
|
|
this.handHistoryAdapter.notifyItemChanged(it) |
|
|
|
} |
|
|
|
} |
|
|
|
|