Skip to content

Commit

Permalink
Fix part of #494: Audio Content highlighting (#514)
Browse files Browse the repository at this point in the history
* Audio Content Highlighting

* Bug fix
  • Loading branch information
rt4914 authored and BenHenning committed Dec 5, 2019
1 parent 2116427 commit 10263a0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion app/src/main/java/org/oppia/app/player/audio/AudioViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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?) {}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -418,6 +418,7 @@ class StatePlayerRecyclerViewAssembler private constructor(
bindView = { view, viewModel ->
val binding = DataBindingUtil.findBinding<ContentItemBinding>(view)!!
val contentViewModel = viewModel as ContentViewModel
binding.viewModel = contentViewModel
binding.htmlContent =
htmlParserFactory.create(
resourceBucketName, entityType, contentViewModel.gcsEntityId, /* imageCenterAlign= */ true, customOppiaTagActionListener = fragment as HtmlParser.CustomOppiaTagActionListener
Expand All @@ -440,6 +441,7 @@ class StatePlayerRecyclerViewAssembler private constructor(
bindView = { view, viewModel ->
val binding = DataBindingUtil.findBinding<FeedbackItemBinding>(view)!!
val feedbackViewModel = viewModel as FeedbackViewModel
binding.viewModel = feedbackViewModel
binding.htmlContent =
htmlParserFactory.create(
resourceBucketName, entityType, feedbackViewModel.gcsEntityId, /* imageCenterAlign= */ true, customOppiaTagActionListener = fragment as HtmlParser.CustomOppiaTagActionListener
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
15 changes: 10 additions & 5 deletions app/src/main/res/layout/feedback_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

<data>

<import type="android.view.View" />

<variable
name="viewModel"
type="org.oppia.app.player.state.itemviewmodel.FeedbackViewModel" />

<variable
name="htmlContent"
type="CharSequence" />
Expand All @@ -10,24 +16,23 @@
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/content_blue_background"
android:layout_marginStart="20dp"
android:layout_marginEnd="28dp"
android:layout_marginTop="@dimen/divider_margin_top"
android:layout_marginBottom="@dimen/divider_margin_bottom">
android:layout_marginEnd="28dp"
android:layout_marginBottom="@dimen/divider_margin_bottom"
android:background="@{viewModel.isAudioPlaying ? @drawable/content_yellow_background : @drawable/content_blue_background}">

<TextView
android:id="@+id/feedback_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="12dp"
android:paddingTop="16dp"
android:paddingEnd="12dp"
android:paddingBottom="16dp"
android:fontFamily="sans-serif"
android:text="@{htmlContent}"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp" />
</FrameLayout>

</layout>

0 comments on commit 10263a0

Please sign in to comment.