Skip to content

Commit

Permalink
Export chunk's take in Blind Draft (#1177)
Browse files Browse the repository at this point in the history
* export chunk take

* bring back old duration
  • Loading branch information
AnonymousWalker authored Aug 8, 2024
1 parent db6fd28 commit 8390d25
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ package org.wycliffeassociates.otter.jvm.controls.event
import org.wycliffeassociates.otter.common.data.workbook.Take
import org.wycliffeassociates.otter.jvm.controls.model.ChunkingStep
import tornadofx.FXEvent
import java.io.File

class ChunkingStepSelectedEvent(val step: ChunkingStep) : FXEvent()
class ChunkSelectedEvent(val chunkNumber: Int): FXEvent()
class ChunkExportedEvent(val chunkTake: Take, val outputFile: File): FXEvent()
class ChunkTakeEvent(val take: Take, val action: TakeAction): FXEvent()
enum class TakeAction {
SELECT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SimpleAudioPlayer(
nodeOrientation = NodeOrientation.LEFT_TO_RIGHT

button {
addClass("btn", "btn--secondary")
addClass("btn", "btn--tertiary")
textProperty().bind(playPauseTextBinding())
tooltip {
textProperty().bind(playPauseTextBinding(true))
Expand Down
2 changes: 1 addition & 1 deletion jvm/controls/src/main/resources/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
}

.jfx-snackbar-content .label {
-fx-text-fill: -wa-white;
-fx-text-fill: -wa-regular-text;
-fx-font-size: 14pt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import javafx.animation.FadeTransition
import javafx.beans.property.SimpleObjectProperty
import javafx.scene.layout.HBox
import javafx.scene.layout.Priority
import javafx.stage.FileChooser
import javafx.util.Duration
import org.kordamp.ikonli.javafx.FontIcon
import org.kordamp.ikonli.materialdesign.MaterialDesign
import org.wycliffeassociates.otter.common.audio.AudioFileFormat
import org.wycliffeassociates.otter.jvm.controls.TakeSelectionAnimationMediator
import org.wycliffeassociates.otter.jvm.controls.event.ChunkExportedEvent
import org.wycliffeassociates.otter.jvm.controls.media.simpleaudioplayer
import org.wycliffeassociates.otter.jvm.controls.event.ChunkTakeEvent
import org.wycliffeassociates.otter.jvm.controls.event.TakeAction
Expand All @@ -52,7 +55,28 @@ class ChunkTakeCard(take: TakeCardModel) : HBox() {
sideTextProperty.bind(remainingTimeProperty)
}
button {
addClass("btn", "btn--secondary")
addClass("btn", "btn--tertiary")
tooltip(messages["export"])
graphic = FontIcon(MaterialDesign.MDI_EXPORT)

action {
chooseFile(
FX.messages["export"],
arrayOf(
FileChooser.ExtensionFilter(
messages["audioFileTypes"],
"*.${AudioFileFormat.MP3.extension}"
)
),
mode = FileChooserMode.Save,
initialFileName = take.take.name
).firstOrNull()?.let {
FX.eventbus.fire(ChunkExportedEvent(take.take, it))
}
}
}
button {
addClass("btn", "btn--tertiary")
tooltip(messages["delete"])
graphic = FontIcon(MaterialDesign.MDI_DELETE)

Expand All @@ -68,7 +92,7 @@ class ChunkTakeCard(take: TakeCardModel) : HBox() {
}
}
button {
addClass("btn", "btn--secondary")
addClass("btn", "btn--tertiary")
tooltip(messages["select"])
togglePseudoClass("active", take.selected)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/
package org.wycliffeassociates.otter.jvm.workbookapp.ui.screens

import com.github.thomasnield.rxkotlinfx.observeOnFx
import javafx.beans.binding.Bindings
import javafx.scene.layout.Priority
import org.kordamp.ikonli.materialdesign.MaterialDesign
import org.wycliffeassociates.otter.jvm.controls.event.ChunkExportedEvent
import org.wycliffeassociates.otter.jvm.controls.styles.tryImportStylesheet
import org.wycliffeassociates.otter.jvm.workbookapp.ui.components.drawer.SourceTextDrawer
import org.wycliffeassociates.otter.jvm.controls.event.ChunkSelectedEvent
Expand All @@ -29,6 +32,9 @@ import org.wycliffeassociates.otter.jvm.controls.event.GoToPreviousChapterEvent
import org.wycliffeassociates.otter.jvm.controls.event.NavigateChapterEvent
import org.wycliffeassociates.otter.jvm.controls.event.ReturnFromPluginEvent
import org.wycliffeassociates.otter.jvm.controls.model.ChunkingStep
import org.wycliffeassociates.otter.jvm.controls.model.NotificationStatusType
import org.wycliffeassociates.otter.jvm.controls.model.NotificationViewData
import org.wycliffeassociates.otter.jvm.workbookapp.SnackbarHandler
import org.wycliffeassociates.otter.jvm.workbookapp.ui.screens.translation.BlindDraft
import org.wycliffeassociates.otter.jvm.workbookapp.ui.screens.translation.Chunking
import org.wycliffeassociates.otter.jvm.workbookapp.ui.screens.translation.ChunkingStepsDrawer
Expand All @@ -41,6 +47,8 @@ import org.wycliffeassociates.otter.jvm.workbookapp.ui.screens.translation.trans
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.TranslationViewModel2
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.WorkbookDataStore
import tornadofx.*
import java.lang.Exception
import java.text.MessageFormat

class ChunkingTranslationPage : View() {

Expand Down Expand Up @@ -137,6 +145,9 @@ class ChunkingTranslationPage : View() {
subscribe<ChunkSelectedEvent> {
viewModel.selectChunk(it.chunkNumber)
}
subscribe<ChunkExportedEvent> {
handleExportChunk(it)
}
subscribe<GoToNextChapterEvent> {
viewModel.nextChapter()
}
Expand Down Expand Up @@ -173,4 +184,29 @@ class ChunkingTranslationPage : View() {
}
}
}

private fun handleExportChunk(event: ChunkExportedEvent) {
viewModel.exportChunk(event.chunkTake, event.outputFile)
.observeOnFx()
.doOnComplete {
val notification = NotificationViewData(
title = messages["exportSuccessful"],
message = MessageFormat.format(messages["export_take_successful"], event.chunkTake.number),
statusType = NotificationStatusType.SUCCESSFUL,
actionText = messages["showLocation"],
actionIcon = MaterialDesign.MDI_OPEN_IN_NEW
) {
val f = event.outputFile
if (f.exists()) {
try {
viewModel.openInFilesManager(f.path)
} catch (_: Exception) {
// no-op
}
}
}
SnackbarHandler.showNotification(notification, root)
}
.subscribe()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel
import com.github.thomasnield.rxkotlinfx.observeOnFx
import io.reactivex.Completable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
Expand All @@ -35,21 +34,25 @@ import org.wycliffeassociates.otter.common.data.primitives.ContentType
import org.wycliffeassociates.otter.common.data.primitives.ProjectMode
import org.wycliffeassociates.otter.common.data.workbook.Chapter
import org.wycliffeassociates.otter.common.data.workbook.Chunk
import org.wycliffeassociates.otter.common.data.workbook.Take
import org.wycliffeassociates.otter.common.domain.collections.CreateProject
import org.wycliffeassociates.otter.common.persistence.IDirectoryProvider
import org.wycliffeassociates.otter.jvm.controls.event.TranslationNavigationEvent
import org.wycliffeassociates.otter.jvm.controls.model.ChapterGridItemData
import org.wycliffeassociates.otter.jvm.workbookapp.ui.model.ChunkViewData
import org.wycliffeassociates.otter.jvm.controls.model.ChunkingStep
import org.wycliffeassociates.otter.jvm.workbookapp.di.IDependencyGraphProvider
import org.wycliffeassociates.otter.jvm.workbookapp.ui.NavigationMediator
import tornadofx.*
import java.util.concurrent.TimeUnit
import java.io.File
import javax.inject.Inject

class TranslationViewModel2 : ViewModel() {

@Inject
lateinit var creationUseCase: CreateProject
@Inject
lateinit var directoryProvider: IDirectoryProvider

val workbookDataStore: WorkbookDataStore by inject()
val audioDataStore: AudioDataStore by inject()
Expand Down Expand Up @@ -158,6 +161,14 @@ class TranslationViewModel2 : ViewModel() {
.subscribe()
}

fun exportChunk(take: Take, outputFile: File): Completable {
return Completable
.fromAction {
take.file.copyTo(outputFile, overwrite = true)
}
.subscribeOn(Schedulers.io())
}

fun loadChunks(chunks: List<Chunk>) {
val chunkViewData = chunks.map { chunk ->
val completed = when(selectedStepProperty.value) {
Expand Down Expand Up @@ -236,6 +247,8 @@ class TranslationViewModel2 : ViewModel() {
}
}

fun openInFilesManager(path: String) = directoryProvider.openInFileManager(path)

private fun loadChapter(chapter: Chapter) {
workbookDataStore.activeChapterProperty.set(chapter)
resetUndoRedo()
Expand Down
1 change: 1 addition & 0 deletions jvm/workbookapp/src/main/resources/Messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ importResourceFromZip = Import Content from Orature File
exportSuccessful = Export Successful
# {0} - Book name, {1} - Language name. Example: John (English) was exported successfully
exportSuccessfulMessage = {0} ({1}) was exported successfully.
export_take_successful = Take {0} was exported successfully.
exportFailed = Export Failed
exportFailedMessage = {0} ({1}) was not exported because of an error.
importing = Importing
Expand Down

0 comments on commit 8390d25

Please sign in to comment.