Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
2753:2ac361d3a837 | 2754:e256bd8628ba |
---|---|
1661 | 1661 |
1662 constructor(context: Context?) : super(context) {} | 1662 constructor(context: Context?) : super(context) {} |
1663 constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} | 1663 constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} |
1664 constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {} | 1664 constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {} |
1665 | 1665 |
1666 fun updateBackground() { | |
1667 if(mChecked) { | |
1668 this.setBackgroundColor(Color.DKGRAY) | |
1669 } else { | |
1670 this.setBackgroundColor(Color.TRANSPARENT) | |
1671 } | |
1672 } | |
1673 | |
1666 override fun setChecked(b: Boolean) { | 1674 override fun setChecked(b: Boolean) { |
1667 mChecked = b | 1675 mChecked = b |
1668 refreshDrawableState() | 1676 updateBackground() |
1669 } | 1677 } |
1670 | 1678 |
1671 override fun isChecked(): Boolean { | 1679 override fun isChecked(): Boolean { |
1672 return mChecked | 1680 return mChecked |
1673 } | 1681 } |
1674 | 1682 |
1675 override fun toggle() { | 1683 override fun toggle() { |
1676 mChecked = !mChecked | 1684 mChecked = !mChecked |
1677 refreshDrawableState() | 1685 updateBackground() |
1678 } | |
1679 | |
1680 override fun onCreateDrawableState(extraSpace: Int): IntArray { | |
1681 val states = super.onCreateDrawableState(extraSpace + 1) | |
1682 if (mChecked) { | |
1683 mergeDrawableStates(states, CHECKED_STATE) | |
1684 } | |
1685 return states | |
1686 } | |
1687 | |
1688 companion object { | |
1689 val CHECKED_STATE = intArrayOf(R.attr.state_checked) | |
1690 } | 1686 } |
1691 } | 1687 } |
1692 | 1688 |
1693 class DWContainerAdapter(c: Context) : BaseAdapter() | 1689 class DWContainerAdapter(c: Context) : BaseAdapter() |
1694 { | 1690 { |
4007 val data = adapter.model.getRowData(position) | 4003 val data = adapter.model.getRowData(position) |
4008 val now = System.currentTimeMillis() | 4004 val now = System.currentTimeMillis() |
4009 val rowView: DWContainerRow = view as DWContainerRow | 4005 val rowView: DWContainerRow = view as DWContainerRow |
4010 | 4006 |
4011 view.isSelected = !view.isSelected | 4007 view.isSelected = !view.isSelected |
4012 rowView.isChecked = !rowView.isChecked | 4008 rowView.toggle() |
4013 adapter.selectedItem = position | 4009 adapter.selectedItem = position |
4014 lastClickView = cont!! | 4010 lastClickView = cont!! |
4015 // If we are single select or we got a double tap... | 4011 // If we are single select or we got a double tap... |
4016 // Generate an ENTER event | 4012 // Generate an ENTER event |
4017 if(cont!!.choiceMode != ListView.CHOICE_MODE_MULTIPLE || | 4013 if(cont!!.choiceMode != ListView.CHOICE_MODE_MULTIPLE || |
4069 adapter.evenColor = colorFromDW(evencolor) | 4065 adapter.evenColor = colorFromDW(evencolor) |
4070 } | 4066 } |
4071 } | 4067 } |
4072 } | 4068 } |
4073 | 4069 |
4070 // Create a new SparseBooleanArray with only the true or false contents | |
4071 private fun onlyBooleanArray(array: SparseBooleanArray, bool: Boolean): SparseBooleanArray | |
4072 { | |
4073 val newArray = SparseBooleanArray() | |
4074 | |
4075 for (i in 0 until array.size()) { | |
4076 if (array.valueAt(i) == bool) { | |
4077 newArray.put(array.keyAt(i), bool) | |
4078 } | |
4079 } | |
4080 return newArray | |
4081 } | |
4082 | |
4074 fun containerGetTitleStart(cont: ListView, flags: Int): String? | 4083 fun containerGetTitleStart(cont: ListView, flags: Int): String? |
4075 { | 4084 { |
4076 var retval: String? = null | 4085 var retval: String? = null |
4077 | 4086 |
4078 waitOnUiThread { | 4087 waitOnUiThread { |
4079 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter | 4088 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter |
4080 | 4089 |
4081 // Handle DW_CRA_SELECTED | 4090 // Handle DW_CRA_SELECTED |
4082 if((flags and 1) != 0) { | 4091 if((flags and 1) != 0) { |
4083 val checked: SparseBooleanArray = cont.getCheckedItemPositions() | 4092 val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) |
4084 val position = checked.keyAt(0) | 4093 val position = checked.keyAt(0) |
4085 | 4094 |
4086 adapter.model.querypos = position | 4095 adapter.model.querypos = position |
4087 retval = adapter.model.getRowTitle(position) | 4096 retval = adapter.model.getRowTitle(position) |
4088 } else { | 4097 } else { |
4105 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter | 4114 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter |
4106 | 4115 |
4107 if(adapter.model.querypos != -1) { | 4116 if(adapter.model.querypos != -1) { |
4108 // Handle DW_CRA_SELECTED | 4117 // Handle DW_CRA_SELECTED |
4109 if ((flags and 1) != 0) { | 4118 if ((flags and 1) != 0) { |
4110 val checked: SparseBooleanArray = cont.getCheckedItemPositions() | 4119 val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) |
4111 | 4120 |
4112 // Otherwise loop until we find our current place | 4121 // Otherwise loop until we find our current place |
4113 for (i in 0 until checked.size()) { | 4122 for (i in 0 until checked.size()) { |
4114 // Item position in adapter | 4123 // Item position in adapter |
4115 val position: Int = checked.keyAt(i) | 4124 val position: Int = checked.keyAt(i) |
4141 waitOnUiThread { | 4150 waitOnUiThread { |
4142 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter | 4151 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter |
4143 | 4152 |
4144 // Handle DW_CRA_SELECTED | 4153 // Handle DW_CRA_SELECTED |
4145 if((flags and 1) != 0) { | 4154 if((flags and 1) != 0) { |
4146 val checked: SparseBooleanArray = cont.getCheckedItemPositions() | 4155 val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) |
4147 val position = checked.keyAt(0) | 4156 val position = checked.keyAt(0) |
4148 | 4157 |
4149 adapter.model.querypos = position | 4158 adapter.model.querypos = position |
4150 retval = adapter.model.getRowData(position) | 4159 retval = adapter.model.getRowData(position) |
4151 } else { | 4160 } else { |
4168 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter | 4177 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter |
4169 | 4178 |
4170 if(adapter.model.querypos != -1) { | 4179 if(adapter.model.querypos != -1) { |
4171 // Handle DW_CRA_SELECTED | 4180 // Handle DW_CRA_SELECTED |
4172 if ((flags and 1) != 0) { | 4181 if ((flags and 1) != 0) { |
4173 val checked: SparseBooleanArray = cont.getCheckedItemPositions() | 4182 val checked: SparseBooleanArray = onlyBooleanArray(cont.checkedItemPositions, true) |
4174 | 4183 |
4175 // Otherwise loop until we find our current place | 4184 // Otherwise loop until we find our current place |
4176 for (i in 0 until checked.size()) { | 4185 for (i in 0 until checked.size()) { |
4177 // Item position in adapter | 4186 // Item position in adapter |
4178 val position: Int = checked.keyAt(i) | 4187 val position: Int = checked.keyAt(i) |