From 10263a0e9d1a014db69835ee42af8a52a9b8a2a6 Mon Sep 17 00:00:00 2001 From: Rajat Talesra Date: Thu, 5 Dec 2019 05:36:57 +0530 Subject: [PATCH] Fix part of #494: Audio Content highlighting (#514) * Audio Content Highlighting * Bug fix --- .idea/misc.xml | 2 +- .../oppia/app/player/audio/AudioViewModel.kt | 11 ++++++- .../player/state/StateFragmentPresenter.kt | 31 +++++++++++++++++-- .../state/StatePlayerRecyclerViewAssembler.kt | 4 ++- .../state/itemviewmodel/FeedbackViewModel.kt | 10 +++++- app/src/main/res/layout/feedback_item.xml | 15 ++++++--- 6 files changed, 61 insertions(+), 12 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index b6ea2b11ac6..7bfef59df1c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/app/src/main/java/org/oppia/app/player/audio/AudioViewModel.kt b/app/src/main/java/org/oppia/app/player/audio/AudioViewModel.kt index f6813ca7123..f35c2f37e1d 100644 --- a/app/src/main/java/org/oppia/app/player/audio/AudioViewModel.kt +++ b/app/src/main/java/org/oppia/app/player/audio/AudioViewModel.kt @@ -133,12 +133,21 @@ class AudioViewModel @Inject constructor( // Do not auto play audio if the LanguageDialogFragment was shown if (!languageSelectionShown) { audioPlayerController.play() + if (audioContentIdListener != null) { + audioContentIdListener!!.contentIdForCurrentAudio(contentId, isPlaying = true) + } } else { languageSelectionShown = false } } - fun pauseAudio() = audioPlayerController.pause() + fun pauseAudio(){ + audioPlayerController.pause() + if (audioContentIdListener != null) { + audioContentIdListener!!.contentIdForCurrentAudio(contentId, isPlaying = false) + } + } + fun handleSeekTo(position: Int) = audioPlayerController.seekTo(position) fun handleRelease() = audioPlayerController.releaseMediaPlayer() diff --git a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt index c6d174d9a6e..44ca9db1144 100755 --- a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt @@ -29,6 +29,9 @@ import org.oppia.app.player.audio.AudioFragment import org.oppia.app.player.audio.AudioFragmentInterface import org.oppia.app.player.audio.AudioViewModel import org.oppia.app.player.audio.CellularAudioDialogFragment +import org.oppia.app.player.state.itemviewmodel.ContentViewModel +import org.oppia.app.player.state.itemviewmodel.FeedbackViewModel +import org.oppia.app.player.state.itemviewmodel.StateItemViewModel import org.oppia.app.player.state.listener.AudioContentIdListener import org.oppia.app.player.stopplaying.StopStatePlayingSessionListener import org.oppia.app.topic.conceptcard.ConceptCardFragment @@ -71,6 +74,7 @@ class StateFragmentPresenter @Inject constructor( private lateinit var explorationId: String private lateinit var currentStateName: String private lateinit var binding: StateFragmentBinding + private lateinit var currentHighlightedContentItem: StateItemViewModel private lateinit var recyclerViewAdapter: RecyclerView.Adapter<*> private val viewModel: StateViewModel by lazy { getStateViewModel() @@ -174,11 +178,31 @@ class StateFragmentPresenter @Inject constructor( } fun handleContentCardHighlighting(contentId: String, playing: Boolean) { - recyclerViewAssembler.contentViewModel?.let { contentViewModel -> - if (contentViewModel.contentId == contentId){ - contentViewModel.updateIsAudioPlaying(playing) + if (::currentHighlightedContentItem.isInitialized) { + if (currentHighlightedContentItem is ContentViewModel && (currentHighlightedContentItem as ContentViewModel).contentId != contentId) { + (currentHighlightedContentItem as ContentViewModel).updateIsAudioPlaying(false) + } else if (currentHighlightedContentItem is FeedbackViewModel && (currentHighlightedContentItem as FeedbackViewModel).contentId != contentId) { + (currentHighlightedContentItem as FeedbackViewModel).updateIsAudioPlaying(false) } } + val itemList = viewModel.itemList + for (item in itemList) { + if (item is ContentViewModel) { + if (item.contentId == contentId) { + currentHighlightedContentItem = item + } + } else if (item is FeedbackViewModel) { + if (item.contentId == contentId) { + currentHighlightedContentItem = item + } + } + } + if (::currentHighlightedContentItem.isInitialized && currentHighlightedContentItem is ContentViewModel) { + (currentHighlightedContentItem as ContentViewModel).updateIsAudioPlaying(playing) + } + if (::currentHighlightedContentItem.isInitialized && currentHighlightedContentItem is FeedbackViewModel) { + (currentHighlightedContentItem as FeedbackViewModel).updateIsAudioPlaying(playing) + } } fun dismissConceptCard() { @@ -286,6 +310,7 @@ class StateFragmentPresenter @Inject constructor( override fun onAnimationEnd(p0: Animation?) { getStateViewModel().setAudioBarVisibility(false) } + override fun onAnimationStart(p0: Animation?) {} override fun onAnimationRepeat(p0: Animation?) {} }) diff --git a/app/src/main/java/org/oppia/app/player/state/StatePlayerRecyclerViewAssembler.kt b/app/src/main/java/org/oppia/app/player/state/StatePlayerRecyclerViewAssembler.kt index 7a4f68420ca..1602c664abf 100644 --- a/app/src/main/java/org/oppia/app/player/state/StatePlayerRecyclerViewAssembler.kt +++ b/app/src/main/java/org/oppia/app/player/state/StatePlayerRecyclerViewAssembler.kt @@ -308,7 +308,7 @@ class StatePlayerRecyclerViewAssembler private constructor( private fun createFeedbackItem(feedback: SubtitledHtml, gcsEntityId: String): FeedbackViewModel? { // Only show feedback if there's some to show. if (feedback.html.isNotEmpty()) { - return FeedbackViewModel(feedback.html, gcsEntityId) + return FeedbackViewModel(feedback.contentId, feedback.html, gcsEntityId) } return null } @@ -418,6 +418,7 @@ class StatePlayerRecyclerViewAssembler private constructor( bindView = { view, viewModel -> val binding = DataBindingUtil.findBinding(view)!! val contentViewModel = viewModel as ContentViewModel + binding.viewModel = contentViewModel binding.htmlContent = htmlParserFactory.create( resourceBucketName, entityType, contentViewModel.gcsEntityId, /* imageCenterAlign= */ true, customOppiaTagActionListener = fragment as HtmlParser.CustomOppiaTagActionListener @@ -440,6 +441,7 @@ class StatePlayerRecyclerViewAssembler private constructor( bindView = { view, viewModel -> val binding = DataBindingUtil.findBinding(view)!! val feedbackViewModel = viewModel as FeedbackViewModel + binding.viewModel = feedbackViewModel binding.htmlContent = htmlParserFactory.create( resourceBucketName, entityType, feedbackViewModel.gcsEntityId, /* imageCenterAlign= */ true, customOppiaTagActionListener = fragment as HtmlParser.CustomOppiaTagActionListener diff --git a/app/src/main/java/org/oppia/app/player/state/itemviewmodel/FeedbackViewModel.kt b/app/src/main/java/org/oppia/app/player/state/itemviewmodel/FeedbackViewModel.kt index cbf83d0dfd0..af992446693 100644 --- a/app/src/main/java/org/oppia/app/player/state/itemviewmodel/FeedbackViewModel.kt +++ b/app/src/main/java/org/oppia/app/player/state/itemviewmodel/FeedbackViewModel.kt @@ -1,4 +1,12 @@ package org.oppia.app.player.state.itemviewmodel +import androidx.databinding.ObservableBoolean + /** [StateItemViewModel] for feedback blurbs. */ -class FeedbackViewModel(val htmlContent: CharSequence, val gcsEntityId: String) : StateItemViewModel(ViewType.FEEDBACK) +class FeedbackViewModel(val contentId: String, val htmlContent: CharSequence, val gcsEntityId: String) : StateItemViewModel(ViewType.FEEDBACK){ + val isAudioPlaying = ObservableBoolean(false) + + fun updateIsAudioPlaying(isPlaying: Boolean){ + isAudioPlaying.set(isPlaying) + } +} diff --git a/app/src/main/res/layout/feedback_item.xml b/app/src/main/res/layout/feedback_item.xml index c64566f7b0a..6b7c5e0f46c 100644 --- a/app/src/main/res/layout/feedback_item.xml +++ b/app/src/main/res/layout/feedback_item.xml @@ -2,6 +2,12 @@ + + + + @@ -10,24 +16,23 @@ + android:layout_marginEnd="28dp" + android:layout_marginBottom="@dimen/divider_margin_bottom" + android:background="@{viewModel.isAudioPlaying ? @drawable/content_yellow_background : @drawable/content_blue_background}"> -