Scroll to top on filter type changed.
This commit is contained in:
		
							parent
							
								
									42ade670da
								
							
						
					
					
						commit
						b5c6f60ee6
					
				| @ -199,7 +199,11 @@ class VectorSettingsDevicesFragment : | ||||
|         } else { | ||||
|             views.deviceListHeaderOtherSessions.isVisible = true | ||||
|             views.deviceListOtherSessions.isVisible = true | ||||
|             views.deviceListOtherSessions.render(otherDevices.take(NUMBER_OF_OTHER_DEVICES_TO_RENDER), otherDevices.size) | ||||
|             views.deviceListOtherSessions.render( | ||||
|                     devices = otherDevices.take(NUMBER_OF_OTHER_DEVICES_TO_RENDER), | ||||
|                     totalNumberOfDevices = otherDevices.size, | ||||
|                     showViewAll = otherDevices.size > NUMBER_OF_OTHER_DEVICES_TO_RENDER | ||||
|             ) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -19,6 +19,8 @@ package im.vector.app.features.settings.devices.v2.list | ||||
| import android.content.Context | ||||
| import android.util.AttributeSet | ||||
| import androidx.constraintlayout.widget.ConstraintLayout | ||||
| import androidx.core.view.isVisible | ||||
| import androidx.recyclerview.widget.RecyclerView | ||||
| import dagger.hilt.android.AndroidEntryPoint | ||||
| import im.vector.app.R | ||||
| import im.vector.app.core.extensions.cleanup | ||||
| @ -42,8 +44,10 @@ class OtherSessionsView @JvmOverloads constructor( | ||||
|     @Inject lateinit var otherSessionsController: OtherSessionsController | ||||
| 
 | ||||
|     private val views: ViewOtherSessionsBinding | ||||
|     private val recyclerViewDataObserver: RecyclerView.AdapterDataObserver | ||||
|     var callback: Callback? = null | ||||
| 
 | ||||
| 
 | ||||
|     init { | ||||
|         inflate(context, R.layout.view_other_sessions, this) | ||||
|         views = ViewOtherSessionsBinding.bind(this) | ||||
| @ -53,16 +57,30 @@ class OtherSessionsView @JvmOverloads constructor( | ||||
|         views.otherSessionsViewAllButton.setOnClickListener { | ||||
|             callback?.onViewAllOtherSessionsClicked() | ||||
|         } | ||||
| 
 | ||||
|         recyclerViewDataObserver = object : RecyclerView.AdapterDataObserver() { | ||||
|             override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { | ||||
|                 super.onItemRangeInserted(positionStart, itemCount) | ||||
|                 views.otherSessionsRecyclerView.scrollToPosition(0) | ||||
|             } | ||||
|         } | ||||
|         otherSessionsController.adapter.registerAdapterDataObserver(recyclerViewDataObserver) | ||||
|     } | ||||
| 
 | ||||
|     fun render(devices: List<DeviceFullInfo>, totalNumberOfDevices: Int) { | ||||
|     fun render(devices: List<DeviceFullInfo>, totalNumberOfDevices: Int, showViewAll: Boolean) { | ||||
|         views.otherSessionsRecyclerView.configureWith(otherSessionsController, hasFixedSize = true) | ||||
|         views.otherSessionsViewAllButton.text = context.getString(R.string.device_manager_other_sessions_view_all, totalNumberOfDevices) | ||||
|         if (showViewAll) { | ||||
|             views.otherSessionsViewAllButton.isVisible = true | ||||
|             views.otherSessionsViewAllButton.text = context.getString(R.string.device_manager_other_sessions_view_all, totalNumberOfDevices) | ||||
|         } else { | ||||
|             views.otherSessionsViewAllButton.isVisible = false | ||||
|         } | ||||
|         otherSessionsController.setData(devices) | ||||
|     } | ||||
| 
 | ||||
|     override fun onDetachedFromWindow() { | ||||
|         otherSessionsController.callback = null | ||||
|         otherSessionsController.adapter.unregisterAdapterDataObserver(recyclerViewDataObserver) | ||||
|         views.otherSessionsRecyclerView.cleanup() | ||||
|         super.onDetachedFromWindow() | ||||
|     } | ||||
|  | ||||
| @ -147,7 +147,7 @@ class OtherSessionsFragment : | ||||
|         } else { | ||||
|             views.deviceListOtherSessions.isVisible = true | ||||
|             views.otherSessionsNotFoundLayout.isVisible = false | ||||
|             views.deviceListOtherSessions.render(devices, devices.size) | ||||
|             views.deviceListOtherSessions.render(devices = devices, totalNumberOfDevices = devices.size, showViewAll = false) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -25,8 +25,8 @@ | ||||
|                 android:layout_width="wrap_content" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 android:layout_gravity="end" | ||||
|                 android:padding="8dp" | ||||
|                 android:layout_marginEnd="8dp"> | ||||
|                 android:layout_marginEnd="8dp" | ||||
|                 android:padding="8dp"> | ||||
| 
 | ||||
|                 <ImageView | ||||
|                     android:layout_width="wrap_content" | ||||
| @ -109,8 +109,9 @@ | ||||
|     <im.vector.app.features.settings.devices.v2.list.OtherSessionsView | ||||
|         android:id="@+id/deviceListOtherSessions" | ||||
|         android:layout_width="0dp" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_height="0dp" | ||||
|         android:layout_marginTop="32dp" | ||||
|         app:layout_constraintBottom_toBottomOf="parent" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toBottomOf="@id/otherSessionsSecurityRecommendationView" /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user