Skip to content

Commit

Permalink
Fix undo chapter edit (#1174)
Browse files Browse the repository at this point in the history
* apply new plugin event to chapter review and reload audio

* fix auto-select chunk in Checking steps
  • Loading branch information
AnonymousWalker authored Aug 6, 2024
1 parent c9ccf6b commit b9d7e09
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.wycliffeassociates.otter.jvm.controls.event.MarkerDeletedEvent
import org.wycliffeassociates.otter.jvm.controls.event.MarkerMovedEvent
import org.wycliffeassociates.otter.jvm.controls.event.OpenInPluginEvent
import org.wycliffeassociates.otter.jvm.controls.event.RedoChunkingPageEvent
import org.wycliffeassociates.otter.jvm.controls.event.ReturnFromPluginEvent
import org.wycliffeassociates.otter.jvm.controls.event.UndoChunkingPageEvent
import org.wycliffeassociates.otter.jvm.controls.marker.MARKER_WIDTH_APPROX
import org.wycliffeassociates.otter.jvm.controls.media.simpleaudioplayer
Expand Down Expand Up @@ -280,6 +281,12 @@ class ChapterReview : View() {
}
}.let { eventSubscriptions.add(it) }

subscribe<ReturnFromPluginEvent> {
viewModel.pluginOpenedProperty.set(false)
translationViewModel.loadingStepProperty.set(false)
viewModel.reloadAudio().subscribe()
}.let { eventSubscriptions.add(it) }

subscribe<SnackBarEvent> {
viewModel.snackBarMessage(it.message)
}.let { eventSubscriptions.add(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ class ChapterReviewViewModel : ViewModel(), IMarkerViewModel {
}
}

/* set pluginOpenedProperty to false to allow invoking dock()
which refreshes the chapter audio. */
pluginOpenedProperty.set(false)
FX.eventbus.fire(PluginClosedEvent(pluginType))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class PeerEditViewModel : ViewModel(), IWaveformViewModel {
override var totalFrames: Int by totalFramesProperty // beware of divided by 0

private val newTakeProperty = SimpleObjectProperty<Take>(null)
private val currentStep: ChunkingStep by translationViewModel.selectedStepProperty
private val builder = ObservableWaveformBuilder()
private val height = Integer.min(Screen.getMainScreen().platformHeight, WAVEFORM_MAX_HEIGHT.toInt())
private val width = Screen.getMainScreen().platformWidth
Expand All @@ -115,7 +116,6 @@ class PeerEditViewModel : ViewModel(), IWaveformViewModel {
currentChunkProperty.onChangeAndDoNowWithDisposer {
it?.let { chunk ->
subscribeToSelectedTake(chunk)
val currentStep = translationViewModel.selectedStepProperty.value
val isConfirmed = chunk.checkingStatus().ordinal >= checkingStatusFromStep(currentStep).ordinal
chunkConfirmed.set(isConfirmed)
}
Expand Down Expand Up @@ -180,9 +180,7 @@ class PeerEditViewModel : ViewModel(), IWaveformViewModel {
fun confirmChunk() {
currentChunkProperty.value?.let { chunk ->
chunkConfirmed.set(true)
val checkingStatus = checkingStatusFromStep(
translationViewModel.selectedStepProperty.value
)
val checkingStatus = checkingStatusFromStep(currentStep)
val take = chunk.audio.getSelectedTake()!!
take.checkingState
.take(1)
Expand Down Expand Up @@ -265,10 +263,13 @@ class PeerEditViewModel : ViewModel(), IWaveformViewModel {
.observeOnFx()
.subscribe { chunks ->
translationViewModel.loadChunks(chunks)
(chunks.firstOrNull { it.checkingStatus() == CheckingStatus.UNCHECKED } ?: chunks.firstOrNull())
?.let { chunk ->
translationViewModel.selectChunk(chunk.sort)
}

val chunkToSelect = chunks.firstOrNull { c ->
c.checkingStatus().ordinal < checkingStatusFromStep(currentStep).ordinal
} ?: chunks.firstOrNull()
chunkToSelect?.let { chunk ->
translationViewModel.selectChunk(chunk.sort)
}
}.addTo(disposable)
}

Expand Down

0 comments on commit b9d7e09

Please sign in to comment.