Skip to content

Commit

Permalink
fix bug in chapters relay
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonymousWalker committed Jan 13, 2025
1 parent 7a3be41 commit 8560f90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class HomePageViewModel2 : ViewModel() {
find<ImportAudioViewModel>()
.generateBook(workbookDescriptor)
.doOnComplete {
println("Finished generating for ${workbookDescriptor.slug}")
workbook.projectFilesAccessor.writeSelectedTakesFile(workbook, true)
workbookRepo.closeWorkbook(workbook)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,38 @@ class ImportAudioViewModel : ViewModel() {
val targetChapters = collectionRepository.getChildren(workbookDescriptor.targetCollection)
.blockingGet()


return workbook.target.chapters
// .firstOrError() // DEBUG first chapter
.subscribeOn(Schedulers.io())
.toList() // force emit from deferred observable
.flattenAsObservable { it }
.map { ch ->
val srcChapter = sourceChapters.first { it.sort == ch.sort}
val srcChapter = sourceChapters.first { it.sort == ch.sort }
val targetChapter = targetChapters.first { it.sort == ch.sort }
val chapterVerseContents = contentRepository.getByCollection(srcChapter).blockingGet()
val verseText = chapterVerseContents.filter { it.labelKey == "verse" }.map{ it.text!! }
val verseText = chapterVerseContents.filter { it.labelKey == "verse" }.map { it.text!! }

val chapterMetaContent = contentRepository.getCollectionMetaContent(targetChapter).blockingGet()
generateForChapter(workbook, ch, chapterMetaContent, verseText)
}
.subscribeOn(Schedulers.io())
.ignoreElements()
}

private fun generateForChapter(workbook: Workbook, chapter: Chapter, chapterContent: Content, chunkTextList: List<String>) {
private fun generateForChapter(
workbook: Workbook,
chapter: Chapter,
chapterContent: Content,
chunkTextList: List<String>
) {
println("Generate chapter ${chapter.sort}")
val generatedAudio = audioGenerator.convertTextToAudio(chunkTextList)

// delete/restart chapter
workbook.projectFilesAccessor.getChapterAudioDir(
workbook,
chapter
).deleteRecursively()
// workbook.projectFilesAccessor.getChapterAudioDir(
// workbook,
// chapter
// )
// ?.listFiles()
// ?.forEach { it.deleteRecursively() }

// import to chapter content
val namer = getFileNamer(workbook, chapter)
Expand Down

0 comments on commit 8560f90

Please sign in to comment.