mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Fix tab scroll-to-top on click.
This commit is contained in:
@@ -407,6 +407,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
||||
lifecycleDisposable.bindTo(getViewLifecycleOwner());
|
||||
lifecycleDisposable.add(mainNavigationViewModel.getTabClickEvents().filter(tab -> tab == MainNavigationListLocation.CHATS)
|
||||
.subscribe(unused -> {
|
||||
Log.d(TAG, "Scroll to top please");
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) list.getLayoutManager();
|
||||
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
if (firstVisibleItemPosition <= LIST_SMOOTH_SCROLL_TO_TOP_THRESHOLD) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.reactive.asFlow
|
||||
@@ -66,7 +65,7 @@ class MainNavigationViewModel(
|
||||
* This is Rx because these are still accessed from Java.
|
||||
*/
|
||||
private val internalTabClickEvents: MutableSharedFlow<MainNavigationListLocation> = MutableSharedFlow()
|
||||
val tabClickEvents: Observable<MainNavigationListLocation> = internalTabClickEvents.filter { Stories.isFeatureEnabled() }.asObservable()
|
||||
val tabClickEvents: Observable<MainNavigationListLocation> = internalTabClickEvents.asObservable()
|
||||
|
||||
init {
|
||||
performStoreUpdate(MainNavigationRepository.getNumberOfUnreadMessages()) { unreadChats, state ->
|
||||
@@ -177,30 +176,31 @@ class MainNavigationViewModel(
|
||||
}
|
||||
|
||||
fun onChatsSelected() {
|
||||
internalTabClickEvents.tryEmit(MainNavigationListLocation.CHATS)
|
||||
internalMainNavigationState.update {
|
||||
it.copy(selectedDestination = MainNavigationListLocation.CHATS)
|
||||
}
|
||||
onTabSelected(MainNavigationListLocation.CHATS)
|
||||
}
|
||||
|
||||
fun onArchiveSelected() {
|
||||
internalTabClickEvents.tryEmit(MainNavigationListLocation.ARCHIVE)
|
||||
internalMainNavigationState.update {
|
||||
it.copy(selectedDestination = MainNavigationListLocation.ARCHIVE)
|
||||
}
|
||||
onTabSelected(MainNavigationListLocation.ARCHIVE)
|
||||
}
|
||||
|
||||
fun onCallsSelected() {
|
||||
internalTabClickEvents.tryEmit(MainNavigationListLocation.CALLS)
|
||||
internalMainNavigationState.update {
|
||||
it.copy(selectedDestination = MainNavigationListLocation.CALLS)
|
||||
}
|
||||
onTabSelected(MainNavigationListLocation.CALLS)
|
||||
}
|
||||
|
||||
fun onStoriesSelected() {
|
||||
internalTabClickEvents.tryEmit(MainNavigationListLocation.STORIES)
|
||||
internalMainNavigationState.update {
|
||||
it.copy(selectedDestination = MainNavigationListLocation.STORIES)
|
||||
onTabSelected(MainNavigationListLocation.STORIES)
|
||||
}
|
||||
|
||||
private fun onTabSelected(destination: MainNavigationListLocation) {
|
||||
viewModelScope.launch {
|
||||
val currentTab = internalMainNavigationState.value.selectedDestination
|
||||
if (currentTab == destination) {
|
||||
internalTabClickEvents.emit(destination)
|
||||
} else {
|
||||
internalMainNavigationState.update {
|
||||
it.copy(selectedDestination = destination)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user