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.bindTo(getViewLifecycleOwner());
|
||||||
lifecycleDisposable.add(mainNavigationViewModel.getTabClickEvents().filter(tab -> tab == MainNavigationListLocation.CHATS)
|
lifecycleDisposable.add(mainNavigationViewModel.getTabClickEvents().filter(tab -> tab == MainNavigationListLocation.CHATS)
|
||||||
.subscribe(unused -> {
|
.subscribe(unused -> {
|
||||||
|
Log.d(TAG, "Scroll to top please");
|
||||||
LinearLayoutManager layoutManager = (LinearLayoutManager) list.getLayoutManager();
|
LinearLayoutManager layoutManager = (LinearLayoutManager) list.getLayoutManager();
|
||||||
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
|
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
|
||||||
if (firstVisibleItemPosition <= LIST_SMOOTH_SCROLL_TO_TOP_THRESHOLD) {
|
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.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.reactive.asFlow
|
import kotlinx.coroutines.reactive.asFlow
|
||||||
@@ -66,7 +65,7 @@ class MainNavigationViewModel(
|
|||||||
* This is Rx because these are still accessed from Java.
|
* This is Rx because these are still accessed from Java.
|
||||||
*/
|
*/
|
||||||
private val internalTabClickEvents: MutableSharedFlow<MainNavigationListLocation> = MutableSharedFlow()
|
private val internalTabClickEvents: MutableSharedFlow<MainNavigationListLocation> = MutableSharedFlow()
|
||||||
val tabClickEvents: Observable<MainNavigationListLocation> = internalTabClickEvents.filter { Stories.isFeatureEnabled() }.asObservable()
|
val tabClickEvents: Observable<MainNavigationListLocation> = internalTabClickEvents.asObservable()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
performStoreUpdate(MainNavigationRepository.getNumberOfUnreadMessages()) { unreadChats, state ->
|
performStoreUpdate(MainNavigationRepository.getNumberOfUnreadMessages()) { unreadChats, state ->
|
||||||
@@ -177,30 +176,31 @@ class MainNavigationViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onChatsSelected() {
|
fun onChatsSelected() {
|
||||||
internalTabClickEvents.tryEmit(MainNavigationListLocation.CHATS)
|
onTabSelected(MainNavigationListLocation.CHATS)
|
||||||
internalMainNavigationState.update {
|
|
||||||
it.copy(selectedDestination = MainNavigationListLocation.CHATS)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onArchiveSelected() {
|
fun onArchiveSelected() {
|
||||||
internalTabClickEvents.tryEmit(MainNavigationListLocation.ARCHIVE)
|
onTabSelected(MainNavigationListLocation.ARCHIVE)
|
||||||
internalMainNavigationState.update {
|
|
||||||
it.copy(selectedDestination = MainNavigationListLocation.ARCHIVE)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCallsSelected() {
|
fun onCallsSelected() {
|
||||||
internalTabClickEvents.tryEmit(MainNavigationListLocation.CALLS)
|
onTabSelected(MainNavigationListLocation.CALLS)
|
||||||
internalMainNavigationState.update {
|
|
||||||
it.copy(selectedDestination = MainNavigationListLocation.CALLS)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onStoriesSelected() {
|
fun onStoriesSelected() {
|
||||||
internalTabClickEvents.tryEmit(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 {
|
internalMainNavigationState.update {
|
||||||
it.copy(selectedDestination = MainNavigationListLocation.STORIES)
|
it.copy(selectedDestination = destination)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user