Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving voice logic to the MessageComposer #4523

Merged
merged 6 commits into from
Nov 22, 2021
Merged

Conversation

ouchadam
Copy link
Contributor

@ouchadam ouchadam commented Nov 19, 2021

Moves all the voice recording logic to the MessageComposer (previously called TextComposer) from the RoomDetailViewModel, this will unlock simplifying the draft saving for voice messages (and potentially push more logic to the SDK)

@ouchadam ouchadam changed the title Feature/adm/voice composer Voice logic in the MessageComposer Nov 19, 2021
@ouchadam ouchadam changed the title Voice logic in the MessageComposer Moving voice logic to the MessageComposer Nov 19, 2021
@ouchadam
Copy link
Contributor Author

git mv seems to have worked, phew 😅

const val PAGINATION_COUNT = 50

@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: RoomDetailViewState): RoomDetailViewModel {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this workaround is needed specifically because of the ActivityScoped voice helpers, have removed from here and added to the MessageComposer where it's needed instead

data class ShowRoomUpgradeDialog(val newVersion: String, val isPublic: Boolean) : TextComposerViewEvents()
data class ShowRoomUpgradeDialog(val newVersion: String, val isPublic: Boolean) : MessageComposerViewEvents()

data class VoicePlaybackOrRecordingFailure(val throwable: Throwable) : MessageComposerViewEvents()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the VoicePlaybackOrRecordingFailure is RoomDetailViewEvents.Failure

Base automatically changed from feature/adm/voice-state to develop November 19, 2021 14:59
@ouchadam ouchadam force-pushed the feature/adm/voice-composer branch from db6e6c6 to cca50ed Compare November 19, 2021 15:05
@ouchadam ouchadam marked this pull request as ready for review November 19, 2021 15:05
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, 2 small questions/remarks

@MavericksViewModelKey(TextComposerViewModel::class)
fun textComposerViewModelFactory(factory: TextComposerViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@MavericksViewModelKey(RoomDetailViewModel::class)
fun roomDetailViewModelFactory(factory: RoomDetailViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not replaced by MessageComposerViewModel ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately not :( when a view model is not in this module it's because it needs a workaround https://github.com/vector-im/element-android/blob/develop/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt#L161

Usually we can do...

companion object : MavericksViewModelFactory<*ViewModel, *ViewState> by hiltMavericksViewModelFactory()

which is where the MavericksViewModelModule comes in and injects for us

buttttt the voice helpers are marked as ActivityScoped which hilt doesn't let us inject into the ViewModels as they're some form of singleton scoped~, now that the voice helpers have moved to the MessageComposerViewModel we can add the RoomDetailViewModel to the normal way of providing the ViewModels

The workaround involves injecting the assisted factory into the fragment and then using that field to provide the ViewModel

@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: *ViewState): *ViewModel {
  val fragment: *Fragment = (viewModelContext as FragmentViewModelContext).fragment()
  return fragment.factory.create(state)
}

}

companion object : MavericksViewModelFactory<TextComposerViewModel, TextComposerViewState> by hiltMavericksViewModelFactory()
/**
* Can't use the hiltMaverick here because some dependencies are injected here and in fragment but they don't share the graph.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hiltMaverick ? :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 I'll update and put a few more specifics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -103,7 +103,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
voiceMessageViews.renderVisibilityChanged(parentChanged, visibility)
}

fun display(recordingState: RecordingUiState) {
fun render(recordingState: RecordingUiState) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ouchadam ouchadam force-pushed the feature/adm/voice-composer branch from 277abe1 to c0f8984 Compare November 19, 2021 16:45
@ouchadam ouchadam mentioned this pull request Nov 19, 2021
@github-actions
Copy link

Unit Test Results

  66 files  ±0    66 suites  ±0   51s ⏱️ -2s
135 tests ±0  135 ✔️ ±0  0 💤 ±0  0 ±0 
418 runs  ±0  418 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit c0f8984. ± Comparison against base commit 28e9d4e.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, let's merge this one

@bmarty bmarty merged commit 97a44a5 into develop Nov 22, 2021
@bmarty bmarty deleted the feature/adm/voice-composer branch November 22, 2021 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants