Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check associated resource metadatas before restoring previously selected one #509

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ChapterTabGroup : TabGroup() {

// Adding these tabs can change the active resource property so we need to
// change it back to what it was originally
if (activeResourceMetadata != null) {
if (shouldRestoreActiveResourceMetadata(activeResourceMetadata)) {
restoreActiveResourceMetadata(activeResourceMetadata)
}
}
Expand All @@ -28,6 +28,11 @@ class ChapterTabGroup : TabGroup() {
tabMap.clear()
}

private fun shouldRestoreActiveResourceMetadata(metadataToRestore: ResourceMetadata?): Boolean {
return metadataToRestore != null &&
getAssociatedMetadatas().contains(metadataToRestore)
}

private fun getTargetBookResourceMetadata(): ResourceMetadata {
return workbookViewModel.workbook.target.resourceMetadata
}
Expand All @@ -36,9 +41,12 @@ class ChapterTabGroup : TabGroup() {
return workbookViewModel.workbook.source.subtreeResources
}

private fun getAssociatedMetadatas(): Sequence<ResourceMetadata> {
return sequenceOf(getTargetBookResourceMetadata()) + getSourceBookSubtreeResources()
}

private fun createTabs() {
val metadataList = sequenceOf(getTargetBookResourceMetadata()) + getSourceBookSubtreeResources()
metadataList.forEach { metadata ->
getAssociatedMetadatas().forEach { metadata ->
tabMap.putIfAbsent(metadata.identifier, ChapterSelectTab(metadata))
}
}
Expand Down