Mercurial > dwindows
comparison android/DWindows.kt @ 2845:64c528d38fb8
Android: Attempt at fixing the container selection issues after clear.
Some container information persists after a clear() that shouldn't... this
was an attempt at fixing that but, it didn't work... however I want to
switch locations so commiting so I don't lose the work.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 26 Sep 2022 08:35:26 +0000 |
parents | bacac2eb1677 |
children | e6edeb2b63bc |
comparison
equal
deleted
inserted
replaced
2844:1df137a1a4b9 | 2845:64c528d38fb8 |
---|---|
2076 var columns = mutableListOf<String?>() | 2076 var columns = mutableListOf<String?>() |
2077 var types = mutableListOf<Int>() | 2077 var types = mutableListOf<Int>() |
2078 var data = mutableListOf<Any?>() | 2078 var data = mutableListOf<Any?>() |
2079 var rowdata = mutableListOf<Long>() | 2079 var rowdata = mutableListOf<Long>() |
2080 var rowtitle = mutableListOf<String?>() | 2080 var rowtitle = mutableListOf<String?>() |
2081 var selected = mutableListOf<Boolean>() | |
2081 var querypos: Int = -1 | 2082 var querypos: Int = -1 |
2082 | 2083 |
2083 fun numberOfColumns(): Int | 2084 fun numberOfColumns(): Int |
2084 { | 2085 { |
2085 return columns.size | 2086 return columns.size |
2142 return rowdata[row] | 2143 return rowdata[row] |
2143 } | 2144 } |
2144 return 0 | 2145 return 0 |
2145 } | 2146 } |
2146 | 2147 |
2148 fun changeRowSelected(row: Int, rselected: Boolean) | |
2149 { | |
2150 if(row > -1 && row < selected.size) { | |
2151 selected[row] = rselected | |
2152 } | |
2153 } | |
2154 | |
2155 fun getRowSelected(row: Int): Boolean | |
2156 { | |
2157 if(row > -1 && row < selected.size) { | |
2158 return selected[row] | |
2159 } | |
2160 return false | |
2161 } | |
2162 | |
2147 fun changeRowTitle(row: Int, title: String?) | 2163 fun changeRowTitle(row: Int, title: String?) |
2148 { | 2164 { |
2149 if(row > -1 && row < rowtitle.size) { | 2165 if(row > -1 && row < rowtitle.size) { |
2150 rowtitle[row] = title | 2166 rowtitle[row] = title |
2151 } | 2167 } |
2174 for(j in 0 until columns.size) { | 2190 for(j in 0 until columns.size) { |
2175 data.removeAt(0) | 2191 data.removeAt(0) |
2176 } | 2192 } |
2177 rowdata.removeAt(0) | 2193 rowdata.removeAt(0) |
2178 rowtitle.removeAt(0) | 2194 rowtitle.removeAt(0) |
2195 selected.removeAt(0) | |
2179 } | 2196 } |
2180 } else { | 2197 } else { |
2181 data.clear() | 2198 data.clear() |
2182 rowdata.clear() | 2199 rowdata.clear() |
2183 rowtitle.clear() | 2200 rowtitle.clear() |
2201 selected.clear() | |
2184 } | 2202 } |
2185 } | 2203 } |
2186 | 2204 |
2187 fun deleteRowByTitle(title: String?) | 2205 fun deleteRowByTitle(title: String?) |
2188 { | 2206 { |
2191 for(j in 0 until columns.size) { | 2209 for(j in 0 until columns.size) { |
2192 data.removeAt(i * columns.size) | 2210 data.removeAt(i * columns.size) |
2193 } | 2211 } |
2194 rowdata.removeAt(i) | 2212 rowdata.removeAt(i) |
2195 rowtitle.removeAt(i) | 2213 rowtitle.removeAt(i) |
2214 selected.removeAt(i) | |
2196 } | 2215 } |
2197 } | 2216 } |
2198 } | 2217 } |
2199 | 2218 |
2200 fun deleteRowByData(rdata: Long) | 2219 fun deleteRowByData(rdata: Long) |
2204 for(j in 0 until columns.size) { | 2223 for(j in 0 until columns.size) { |
2205 data.removeAt(i * columns.size) | 2224 data.removeAt(i * columns.size) |
2206 } | 2225 } |
2207 rowdata.removeAt(i) | 2226 rowdata.removeAt(i) |
2208 rowtitle.removeAt(i) | 2227 rowtitle.removeAt(i) |
2228 selected.removeAt(i) | |
2209 } | 2229 } |
2210 } | 2230 } |
2211 } | 2231 } |
2212 | 2232 |
2213 fun positionByTitle(title: String?): Int | 2233 fun positionByTitle(title: String?): Int |
2241 // Fill in with nulls to be set later | 2261 // Fill in with nulls to be set later |
2242 data.add(null) | 2262 data.add(null) |
2243 } | 2263 } |
2244 rowdata.add(0) | 2264 rowdata.add(0) |
2245 rowtitle.add(null) | 2265 rowtitle.add(null) |
2266 selected.add(false) | |
2246 } | 2267 } |
2247 return startRow | 2268 return startRow |
2248 } | 2269 } |
2249 | 2270 |
2250 fun clear() | 2271 fun clear() |
2251 { | 2272 { |
2252 data.clear() | 2273 data.clear() |
2253 rowdata.clear() | 2274 rowdata.clear() |
2254 rowtitle.clear() | 2275 rowtitle.clear() |
2276 selected.clear() | |
2255 } | 2277 } |
2256 } | 2278 } |
2257 | 2279 |
2258 class DWContainerRow : RelativeLayout, Checkable { | 2280 class DWContainerRow : RelativeLayout, Checkable { |
2259 private var mChecked = false | 2281 private var mChecked = false |
2260 private var colorSelection = Color.DKGRAY | 2282 private var colorSelection = Color.DKGRAY |
2283 var position: Int = -1 | |
2261 var imageview: ImageView = ImageView(context) | 2284 var imageview: ImageView = ImageView(context) |
2262 var text: TextView = TextView(context) | 2285 var text: TextView = TextView(context) |
2263 var stack: LinearLayout = LinearLayout(context) | 2286 var stack: LinearLayout = LinearLayout(context) |
2264 | 2287 |
2265 fun setup(context: Context?) { | 2288 fun setup(context: Context?) { |
2299 if(mChecked) { | 2322 if(mChecked) { |
2300 this.setBackgroundColor(colorSelection) | 2323 this.setBackgroundColor(colorSelection) |
2301 } else { | 2324 } else { |
2302 this.setBackgroundColor(Color.TRANSPARENT) | 2325 this.setBackgroundColor(Color.TRANSPARENT) |
2303 } | 2326 } |
2327 if(this.parent is ListView && position != -1) { | |
2328 val cont = this.parent as ListView | |
2329 val adapter = cont.adapter as DWContainerAdapter | |
2330 | |
2331 adapter.model.changeRowSelected(position, mChecked) | |
2332 } | |
2304 } | 2333 } |
2305 | 2334 |
2306 override fun setChecked(b: Boolean) { | 2335 override fun setChecked(b: Boolean) { |
2307 mChecked = b | 2336 mChecked = b |
2308 updateBackground() | 2337 updateBackground() |
2364 } | 2393 } |
2365 | 2394 |
2366 // If the view passed in is null we need to create the layout | 2395 // If the view passed in is null we need to create the layout |
2367 if(rowView == null) { | 2396 if(rowView == null) { |
2368 rowView = DWContainerRow(context) | 2397 rowView = DWContainerRow(context) |
2398 | |
2399 // Save the position for later use | |
2400 rowView.position = position | |
2369 | 2401 |
2370 // Handle DW_CONTAINER_MODE_MULTI by setting the orientation vertical | 2402 // Handle DW_CONTAINER_MODE_MULTI by setting the orientation vertical |
2371 if(contMode == 2) { | 2403 if(contMode == 2) { |
2372 rowView.stack.orientation = LinearLayout.VERTICAL | 2404 rowView.stack.orientation = LinearLayout.VERTICAL |
2373 rowView.stack.gravity = Gravity.LEFT | 2405 rowView.stack.gravity = Gravity.LEFT |
2431 } | 2463 } |
2432 rowView.stack.addView(textview) | 2464 rowView.stack.addView(textview) |
2433 } | 2465 } |
2434 } | 2466 } |
2435 } else { | 2467 } else { |
2468 // Need to save the position to set the check state | |
2469 rowView.position = position | |
2470 | |
2471 // Refresh the selected state from the model | |
2472 rowView.isChecked = model.getRowSelected(position) | |
2473 | |
2436 // Otherwise we just need to update the existing layout | 2474 // Otherwise we just need to update the existing layout |
2437 for(i in extraColumns until displayColumns) { | 2475 for(i in extraColumns until displayColumns) { |
2438 var content = model.getRowAndColumn(position, i) | 2476 var content = model.getRowAndColumn(position, i) |
2439 | 2477 |
2440 // Image | 2478 // Image |
2460 } | 2498 } |
2461 } | 2499 } |
2462 } | 2500 } |
2463 } | 2501 } |
2464 | 2502 |
2503 // Check the main column content, image or text | |
2465 var content = model.getRowAndColumn(position, 0) | 2504 var content = model.getRowAndColumn(position, 0) |
2466 | 2505 |
2467 // Setup the built-in Image and Text based on if we are fileystem mode or not | 2506 // Setup the built-in Image and Text based on if we are fileystem mode or not |
2468 if(isFilesystem) { | 2507 if(isFilesystem) { |
2469 if(content is Drawable) { | 2508 if(content is Drawable) { |
2476 rowView.text.text = content.toString() | 2515 rowView.text.text = content.toString() |
2477 } | 2516 } |
2478 } else { | 2517 } else { |
2479 if(content is Drawable) { | 2518 if(content is Drawable) { |
2480 rowView.imageview.setImageDrawable(content) | 2519 rowView.imageview.setImageDrawable(content) |
2520 rowView.text.text = "" | |
2481 } else if (content is String) { | 2521 } else if (content is String) { |
2482 rowView.text.text = content | 2522 rowView.text.text = content |
2523 rowView.imageview.setImageDrawable(null) | |
2483 } else if(content is Long || content is Int) { | 2524 } else if(content is Long || content is Int) { |
2484 rowView.text.text = content.toString() | 2525 rowView.text.text = content.toString() |
2526 rowView.imageview.setImageDrawable(null) | |
2485 } | 2527 } |
2486 } | 2528 } |
2487 | 2529 |
2488 // Handle row stripe | 2530 // Handle row stripe |
2489 if (position % 2 == 0) { | 2531 if (position % 2 == 0) { |
5368 fun containerClear(cont: ListView) | 5410 fun containerClear(cont: ListView) |
5369 { | 5411 { |
5370 waitOnUiThread { | 5412 waitOnUiThread { |
5371 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter | 5413 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter |
5372 | 5414 |
5415 adapter.lastClick = 0L | |
5416 adapter.lastClickRow = -1 | |
5417 adapter.selectedItem = -1 | |
5373 adapter.model.clear() | 5418 adapter.model.clear() |
5374 } | 5419 } |
5375 } | 5420 } |
5376 | 5421 |
5377 fun containerScroll(cont: ListView, direction: Int, rows: Int) | 5422 fun containerScroll(cont: ListView, direction: Int, rows: Int) |