Mercurial > dwindows
diff android/DWindows.kt @ 2754:e256bd8628ba
Andrdoi: Attempt to fix a number of issues querying containers.
Always returning nullptr from the query functions made it always fail.
Varaibles were incorrectly named and I had incorrectly assumed the
SparseBooleanArray only returned checked items. This is not the case, it
only returns items that were changed. So we now take this array and create a
copy but only including the items that are checked so the code works as
intended.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 02 Jan 2022 19:06:04 +0000 |
parents | 2ac361d3a837 |
children | 9477910393ac |
line wrap: on
line diff
--- a/android/DWindows.kt Sat Jan 01 18:47:38 2022 +0000 +++ b/android/DWindows.kt Sun Jan 02 19:06:04 2022 +0000 @@ -1663,9 +1663,17 @@ constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {} + fun updateBackground() { + if(mChecked) { + this.setBackgroundColor(Color.DKGRAY) + } else { + this.setBackgroundColor(Color.TRANSPARENT) + } + } + override fun setChecked(b: Boolean) { mChecked = b - refreshDrawableState() + updateBackground() } override fun isChecked(): Boolean { @@ -1674,19 +1682,7 @@ override fun toggle() { mChecked = !mChecked - refreshDrawableState() - } - - override fun onCreateDrawableState(extraSpace: Int): IntArray { - val states = super.onCreateDrawableState(extraSpace + 1) - if (mChecked) { - mergeDrawableStates(states, CHECKED_STATE) - } - return states - } - - companion object { - val CHECKED_STATE = intArrayOf(R.attr.state_checked) + updateBackground() } } @@ -4009,7 +4005,7 @@ val rowView: DWContainerRow = view as DWContainerRow view.isSelected = !view.isSelected - rowView.isChecked = !rowView.isChecked + rowView.toggle() adapter.selectedItem = position lastClickView = cont!! // If we are single select or we got a double tap... @@ -4071,6 +4067,19 @@ } } + // Create a new SparseBooleanArray with only the true or false contents + private fun onlyBooleanArray(array: SparseBooleanArray, bool: Boolean): SparseBooleanArray + { + val newArray = SparseBooleanArray() + + for (i in 0 until array.size()) { + if (array.valueAt(i) == bool) { + newArray.put(array.keyAt(i), bool) + } + } + return newArray + } + fun containerGetTitleStart(cont: ListView, flags: Int): String? { var retval: String? = null @@ -4080,7 +4089,7 @@ // Handle DW_CRA_SELECTED if((flags and 1) != 0) { - val checked: SparseBooleanArray = cont.getCheckedItemPositions() + val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) val position = checked.keyAt(0) adapter.model.querypos = position @@ -4107,7 +4116,7 @@ if(adapter.model.querypos != -1) { // Handle DW_CRA_SELECTED if ((flags and 1) != 0) { - val checked: SparseBooleanArray = cont.getCheckedItemPositions() + val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) // Otherwise loop until we find our current place for (i in 0 until checked.size()) { @@ -4143,7 +4152,7 @@ // Handle DW_CRA_SELECTED if((flags and 1) != 0) { - val checked: SparseBooleanArray = cont.getCheckedItemPositions() + val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) val position = checked.keyAt(0) adapter.model.querypos = position @@ -4170,7 +4179,7 @@ if(adapter.model.querypos != -1) { // Handle DW_CRA_SELECTED if ((flags and 1) != 0) { - val checked: SparseBooleanArray = cont.getCheckedItemPositions() + val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) // Otherwise loop until we find our current place for (i in 0 until checked.size()) {