Mavericks 2: replace selectSubscribe by onEach

This commit is contained in:
ganfra 2021-10-01 18:04:06 +02:00
parent 606cddc826
commit 2ef4cd276b
20 changed files with 38 additions and 38 deletions

View file

@ -152,7 +152,7 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
}
.disposeOnDestroy()
callViewModel.selectSubscribe(VectorCallViewState::callId, VectorCallViewState::isVideoCall) { _, isVideoCall ->
callViewModel.onEach(VectorCallViewState::callId, VectorCallViewState::isVideoCall) { _, isVideoCall ->
if (isVideoCall) {
if (checkPermissions(PERMISSIONS_FOR_VIDEO_IP_CALL, this, permissionCameraLauncher, R.string.permissions_rationale_msg_camera_and_audio)) {
setupRenderersIfNeeded()

View file

@ -66,7 +66,7 @@ class ContactsBookViewModel @AssistedInject constructor(@Assisted
init {
loadContacts()
selectSubscribe(ContactsBookViewState::searchTerm, ContactsBookViewState::onlyBoundContacts) { _, _ ->
onEach(ContactsBookViewState::searchTerm, ContactsBookViewState::onlyBoundContacts) { _, _ ->
updateFilteredMappedContacts()
}
}

View file

@ -102,7 +102,7 @@ class CreateDirectRoomActivity : SimpleFragmentActivity(), UserListViewModel.Fac
)
)
}
viewModel.selectSubscribe(CreateDirectRoomViewState::createAndInviteState) {
viewModel.onEach(CreateDirectRoomViewState::createAndInviteState) {
renderCreateAndInviteState(it)
}
}

View file

@ -55,7 +55,7 @@ class KeysBackupManageActivity : SimpleFragmentActivity() {
}
// Observe the deletion of keys backup
viewModel.selectSubscribe(KeysBackupSettingViewState::deleteBackupRequest) { asyncDelete ->
viewModel.onEach(KeysBackupSettingViewState::deleteBackupRequest) { asyncDelete ->
when (asyncDelete) {
is Fail -> {
updateWaitingView(null)

View file

@ -134,7 +134,7 @@ class HomeDetailFragment @Inject constructor(
views.bottomNavigationView.selectedItemId = it.currentTab.toMenuId()
}
viewModel.selectSubscribe(HomeDetailViewState::roomGroupingMethod) { roomGroupingMethod ->
viewModel.onEach(HomeDetailViewState::roomGroupingMethod) { roomGroupingMethod ->
when (roomGroupingMethod) {
is RoomGroupingMethod.ByLegacyGroup -> {
onGroupChange(roomGroupingMethod.groupSummary)
@ -145,11 +145,11 @@ class HomeDetailFragment @Inject constructor(
}
}
viewModel.selectSubscribe(HomeDetailViewState::currentTab) { currentTab ->
viewModel.onEach(HomeDetailViewState::currentTab) { currentTab ->
updateUIForTab(currentTab)
}
viewModel.selectSubscribe(HomeDetailViewState::showDialPadTab) { showDialPadTab ->
viewModel.onEach(HomeDetailViewState::showDialPadTab) { showDialPadTab ->
updateTabVisibilitySafely(R.id.bottom_action_dial_pad, showDialPadTab)
}

View file

@ -61,7 +61,7 @@ class JoinReplacementRoomBottomSheet :
}
}
viewModel.selectSubscribe(RoomDetailViewState::joinUpgradedRoomAsync) { joinState ->
viewModel.onEach(RoomDetailViewState::joinUpgradedRoomAsync) { joinState ->
when (joinState) {
// it should never be Uninitialized
Uninitialized,

View file

@ -375,13 +375,13 @@ class RoomDetailFragment @Inject constructor(
invalidateOptionsMenu()
}
roomDetailViewModel.selectSubscribe(RoomDetailViewState::canShowJumpToReadMarker, RoomDetailViewState::unreadState) { _, _ ->
roomDetailViewModel.onEach(RoomDetailViewState::canShowJumpToReadMarker, RoomDetailViewState::unreadState) { _, _ ->
updateJumpToReadMarkerViewVisibility()
}
roomDetailViewModel.selectSubscribe(RoomDetailViewState::sendMode, RoomDetailViewState::canSendMessage) { mode, canSend ->
roomDetailViewModel.onEach(RoomDetailViewState::sendMode, RoomDetailViewState::canSendMessage) { mode, canSend ->
if (!canSend) {
return@selectSubscribe
return@onEach
}
when (mode) {
is SendMode.REGULAR -> renderRegularMode(mode.text)
@ -391,7 +391,7 @@ class RoomDetailFragment @Inject constructor(
}
}
roomDetailViewModel.selectSubscribe(
roomDetailViewModel.onEach(
RoomDetailViewState::syncState,
RoomDetailViewState::incrementalSyncStatus,
RoomDetailViewState::pushCounter

View file

@ -1576,7 +1576,7 @@ class RoomDetailViewModel @AssistedInject constructor(
}
private fun observeUnreadState() {
selectSubscribe(RoomDetailViewState::unreadState) {
onEach(RoomDetailViewState::unreadState) {
Timber.v("Unread state: $it")
if (it is UnreadState.HasNoUnread) {
startTrackingUnreadMessages()

View file

@ -42,7 +42,7 @@ sealed class SendMode(open val text: String) {
data class REGULAR(
override val text: String,
val fromSharing: Boolean,
// This is necessary for forcing refresh on selectSubscribe
// This is necessary for forcing refresh on onEach
private val ts: Long = System.currentTimeMillis()
) : SendMode(text)

View file

@ -163,8 +163,8 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
}
private fun observeTimelineEventState() {
selectSubscribe(MessageActionState::timelineEvent, MessageActionState::actionPermissions) { timelineEvent, permissions ->
val nonNullTimelineEvent = timelineEvent() ?: return@selectSubscribe
onEach(MessageActionState::timelineEvent, MessageActionState::actionPermissions) { timelineEvent, permissions ->
val nonNullTimelineEvent = timelineEvent() ?: return@onEach
eventIdFlow.tryEmit(nonNullTimelineEvent.eventId)
setState {
copy(

View file

@ -123,7 +123,7 @@ class RoomListFragment @Inject constructor(
.subscribe { handleQuickActions(it) }
.disposeOnDestroyView()
roomListViewModel.selectSubscribe(RoomListViewState::roomMembershipChanges) { ms ->
roomListViewModel.onEach(RoomListViewState::roomMembershipChanges) { ms ->
// it's for invites local echo
adapterInfosList.filter { it.section.notifyOfLocalEcho }
.onEach {

View file

@ -66,7 +66,7 @@ class RoomDirectoryPickerViewModel @AssistedInject constructor(
}
private fun observeAndCompute() {
selectSubscribe(
onEach(
RoomDirectoryPickerViewState::asyncThirdPartyRequest,
RoomDirectoryPickerViewState::customHomeservers
) { async, custom ->

View file

@ -101,7 +101,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
}
private fun observeState() {
selectSubscribe(
onEach(
RoomSettingsViewState::avatarAction,
RoomSettingsViewState::newName,
RoomSettingsViewState::newTopic,

View file

@ -78,7 +78,7 @@ class RoomJoinRuleActivity : VectorBaseActivity<ActivitySimpleBinding>(),
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel.selectSubscribe(RoomJoinRuleChooseRestrictedState::updatingStatus) {
viewModel.onEach(RoomJoinRuleChooseRestrictedState::updatingStatus) {
when (it) {
Uninitialized -> {
// nop

View file

@ -110,7 +110,7 @@ class SpaceDirectoryFragment @Inject constructor(
views.spaceDirectoryList.configureWith(epoxyController)
epoxyVisibilityTracker.attach(views.spaceDirectoryList)
viewModel.selectSubscribe(SpaceDirectoryState::canAddRooms) {
viewModel.onEach(SpaceDirectoryState::canAddRooms) {
invalidateOptionsMenu()
}

View file

@ -91,35 +91,35 @@ class SpaceAddRoomFragment @Inject constructor(
invalidateOptionsMenu()
}
viewModel.selectSubscribe(SpaceAddRoomsState::spaceName) {
viewModel.onEach(SpaceAddRoomsState::spaceName) {
views.appBarSpaceInfo.text = it
}.disposeOnDestroyView()
}
viewModel.selectSubscribe(SpaceAddRoomsState::ignoreRooms) {
viewModel.onEach(SpaceAddRoomsState::ignoreRooms) {
spaceEpoxyController.ignoreRooms = it
roomEpoxyController.ignoreRooms = it
dmEpoxyController.ignoreRooms = it
}.disposeOnDestroyView()
}
viewModel.selectSubscribe(SpaceAddRoomsState::isSaving) {
viewModel.onEach(SpaceAddRoomsState::isSaving) {
if (it is Loading) {
sharedViewModel.handle(SpaceManagedSharedAction.ShowLoading)
} else {
sharedViewModel.handle(SpaceManagedSharedAction.HideLoading)
}
}.disposeOnDestroyView()
}
viewModel.selectSubscribe(SpaceAddRoomsState::shouldShowDMs) {
viewModel.onEach(SpaceAddRoomsState::shouldShowDMs) {
dmEpoxyController.disabled = !it
}.disposeOnDestroyView()
}
viewModel.selectSubscribe(SpaceAddRoomsState::onlyShowSpaces) {
viewModel.onEach(SpaceAddRoomsState::onlyShowSpaces) {
spaceEpoxyController.disabled = !it
roomEpoxyController.disabled = it
views.createNewRoom.text = if (it) getString(R.string.create_space) else getString(R.string.create_new_room)
val title = if (it) getString(R.string.space_add_existing_spaces) else getString(R.string.space_add_existing_rooms_only)
views.appBarTitle.text = title
}.disposeOnDestroyView()
}
views.createNewRoom.debouncedClicks {
withState(viewModel) { state ->

View file

@ -80,7 +80,7 @@ class SpaceManageRoomsFragment @Inject constructor(
}
.disposeOnDestroyView()
viewModel.selectSubscribe(SpaceManageRoomViewState::actionState) { actionState ->
viewModel.onEach(SpaceManageRoomViewState::actionState) { actionState ->
when (actionState) {
is Loading -> {
sharedViewModel.handle(SpaceManagedSharedAction.ShowLoading)

View file

@ -68,7 +68,7 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
showFragment(ShowUserCodeFragment::class, Bundle.EMPTY)
}
sharedViewModel.selectSubscribe(UserCodeState::mode) { mode ->
sharedViewModel.onEach(UserCodeState::mode) { mode ->
when (mode) {
UserCodeState.Mode.SHOW -> showFragment(ShowUserCodeFragment::class, Bundle.EMPTY)
UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY)

View file

@ -85,7 +85,7 @@ class UserListFragment @Inject constructor(
views.userListE2EbyDefaultDisabled.isVisible = !it.isE2EByDefault
}
viewModel.selectSubscribe(UserListViewState::pendingSelections) {
viewModel.onEach(UserListViewState::pendingSelections) {
renderSelectedUsers(it)
}

View file

@ -102,14 +102,14 @@ class WidgetActivity : VectorBaseActivity<ActivityWidgetBinding>(),
}
}
viewModel.selectSubscribe(WidgetViewState::status) { ws ->
viewModel.onEach(WidgetViewState::status) { ws ->
when (ws) {
WidgetStatus.UNKNOWN -> {
}
WidgetStatus.WIDGET_NOT_ALLOWED -> {
val dFrag = supportFragmentManager.findFragmentByTag(WIDGET_PERMISSION_FRAGMENT_TAG) as? RoomWidgetPermissionBottomSheet
if (dFrag != null && dFrag.dialog?.isShowing == true && !dFrag.isRemoving) {
return@selectSubscribe
return@onEach
} else {
RoomWidgetPermissionBottomSheet
.newInstance(widgetArgs)
@ -124,11 +124,11 @@ class WidgetActivity : VectorBaseActivity<ActivityWidgetBinding>(),
}
}
viewModel.selectSubscribe(WidgetViewState::widgetName) { name ->
viewModel.onEach(WidgetViewState::widgetName) { name ->
supportActionBar?.title = name
}
viewModel.selectSubscribe(WidgetViewState::canManageWidgets) {
viewModel.onEach(WidgetViewState::canManageWidgets) {
invalidateOptionsMenu()
}
}