Mercurial > dwindows
comparison android/DWindows.kt @ 2667:2ae70678c845
Android: Use a RecyclerView method to change the ViewPager2 page since the ViewPager2
method is not functioning. Also create a private function to switch windows.
Next step is to implement functionality to switch between windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 15 Oct 2021 23:22:23 +0000 |
parents | 4f2d433747e2 |
children | 917f2d1f9cae |
comparison
equal
deleted
inserted
replaced
2666:4f2d433747e2 | 2667:2ae70678c845 |
---|---|
89 | 89 |
90 class DWTabViewPagerAdapter : RecyclerView.Adapter<DWTabViewPagerAdapter.DWEventViewHolder>() { | 90 class DWTabViewPagerAdapter : RecyclerView.Adapter<DWTabViewPagerAdapter.DWEventViewHolder>() { |
91 val viewList = mutableListOf<LinearLayout>() | 91 val viewList = mutableListOf<LinearLayout>() |
92 val pageList = mutableListOf<Long>() | 92 val pageList = mutableListOf<Long>() |
93 var currentPageID = 0L | 93 var currentPageID = 0L |
94 var recyclerView: RecyclerView? = null | |
94 | 95 |
95 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = | 96 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = |
96 DWEventViewHolder(viewList.get(viewType)) | 97 DWEventViewHolder(viewList.get(viewType)) |
97 | 98 |
98 override fun getItemCount() = viewList.count() | 99 override fun getItemCount() = viewList.count() |
99 override fun getItemViewType(position: Int): Int { | 100 override fun getItemViewType(position: Int): Int { |
100 return position | 101 return position |
102 } | |
103 override fun onAttachedToRecyclerView(rv: RecyclerView) { | |
104 recyclerView = rv | |
101 } | 105 } |
102 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) { | 106 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) { |
103 holder.setIsRecyclable(false) | 107 holder.setIsRecyclable(false) |
104 } | 108 } |
105 | 109 |
1388 } | 1392 } |
1389 } | 1393 } |
1390 return text | 1394 return text |
1391 } | 1395 } |
1392 | 1396 |
1397 private fun windowSwitchWindow(index: Int) | |
1398 { | |
1399 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter | |
1400 | |
1401 if (index != -1) { | |
1402 val window = adapter.viewList[index] as View | |
1403 | |
1404 // Only allow a window to become active if it is shown | |
1405 if(window.visibility == View.VISIBLE) { | |
1406 // Update the action bar title | |
1407 this.title = windowTitles[index] | |
1408 // Switch the visible view in the pager | |
1409 if(adapter.recyclerView != null) { | |
1410 adapter.recyclerView!!.scrollToPosition(index) | |
1411 } | |
1412 // This is how I prefered to do it, but it doesn't work... | |
1413 // So using he RecyclerView.scrollToPosition() instead | |
1414 //windowLayout!!.setCurrentItem(index, true) | |
1415 | |
1416 // If the new view has a default item, focus it | |
1417 if(windowDefault[index] != null) { | |
1418 windowDefault[index]?.requestFocus() | |
1419 } | |
1420 // Invalidate the menu, so it gets updated for the new window | |
1421 invalidateOptionsMenu() | |
1422 } | |
1423 } | |
1424 } | |
1425 | |
1393 fun windowHideShow(window: View, state: Int) | 1426 fun windowHideShow(window: View, state: Int) |
1394 { | 1427 { |
1395 if(windowLayout != null) { | 1428 if(windowLayout != null) { |
1396 waitOnUiThread { | 1429 waitOnUiThread { |
1397 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter | 1430 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter |
1398 val index = adapter.viewList.indexOf(window) | 1431 val index = adapter.viewList.indexOf(window) |
1399 var defaultItem: View? = null | |
1400 | 1432 |
1401 if(state == 0) { | 1433 if(state == 0) { |
1402 window.visibility = View.GONE | 1434 window.visibility = View.GONE |
1403 } else { | 1435 } else { |
1404 window.visibility = View.VISIBLE | 1436 window.visibility = View.VISIBLE |
1405 } | 1437 } |
1406 if (index != -1) { | 1438 windowSwitchWindow(index) |
1407 defaultItem = windowDefault[index] | |
1408 if(state != 0) { | |
1409 windowLayout!!.setCurrentItem(index, true) | |
1410 } | |
1411 invalidateOptionsMenu() | |
1412 } | |
1413 if(state != 0 && defaultItem != null) { | |
1414 defaultItem.requestFocus() | |
1415 } | |
1416 } | 1439 } |
1417 } | 1440 } |
1418 } | 1441 } |
1419 | 1442 |
1420 fun clipboardGetText(): String { | 1443 fun clipboardGetText(): String { |