import { ActionType } from '@ulangi/ulangi-action' ; import { ScreenName } from '@ulangi/ulangi-common/enums' ; import { EventBus , group , on } from '@ulangi/ulangi-event' ; import { ObservableCategoryDetailScreen , ObservableVocabulary , } from '@ulangi/ulangi-observable' ; import { boundClass } from 'autobind-decorator' ; import { CategoryActionMenuDelegate } from '../category/CategoryActionMenuDelegate' ; import { FeatureSettingsDelegate } from '../learn/FeatureSettingsDelegate' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; import { VocabularyActionMenuDelegate } from '../vocabulary/VocabularyActionMenuDelegate' ; import { VocabularyBulkActionMenuDelegate } from '../vocabulary/VocabularyBulkActionMenuDelegate' ; import { VocabularyFilterMenuDelegate } from '../vocabulary/VocabularyFilterMenuDelegate' ; import { VocabularyListDelegate } from '../vocabulary/VocabularyListDelegate' ; import { VocabularyLiveUpdateDelegate } from '../vocabulary/VocabularyLiveUpdateDelegate' ; import { VocabularySelectionDelegate } from '../vocabulary/VocabularySelectionDelegate' ; import { VocabularySortMenuDelegate } from '../vocabulary/VocabularySortMenuDelegate' ; @ boundClass export class CategoryDetailScreenDelegate { private eventBus : EventBus ; private observableScreen : ObservableCategoryDetailScreen ; private categoryActionMenuDelegate : CategoryActionMenuDelegate ; private vocabularyListDelegate : VocabularyListDelegate ; private vocabularyFilterMenuDelegate : VocabularyFilterMenuDelegate ; private vocabularySortMenuDelegate : VocabularySortMenuDelegate ; private vocabularyActionMenuDelegate : VocabularyActionMenuDelegate ; private vocabularyBulkActionMenuDelegate : VocabularyBulkActionMenuDelegate ; private vocabularyLiveUpdateDelegate : VocabularyLiveUpdateDelegate ; private vocabularySelectionDelegate : VocabularySelectionDelegate ; private featureSettingsDelegate : FeatureSettingsDelegate ; private navigatorDelegate : NavigatorDelegate ; public constructor ( eventBus , observableScreen , categoryActionMenuDelegate , vocabularyListDelegate , vocabularyFilterMenuDelegate , vocabularySortMenuDelegate , vocabularyActionMenuDelegate , vocabularyBulkActionMenuDelegate , vocabularyLiveUpdateDelegate , vocabularySelectionDelegate , featureSettingsDelegate , navigatorDelegate ) { this . eventBus = eventBus ; this . observableScreen = observableScreen ; this . categoryActionMenuDelegate = categoryActionMenuDelegate ; this . vocabularyListDelegate = vocabularyListDelegate ; this . vocabularyFilterMenuDelegate = vocabularyFilterMenuDelegate ; this . vocabularySortMenuDelegate = vocabularySortMenuDelegate ; this . vocabularyActionMenuDelegate = vocabularyActionMenuDelegate ; this . vocabularyBulkActionMenuDelegate = vocabularyBulkActionMenuDelegate ; this . vocabularyLiveUpdateDelegate = vocabularyLiveUpdateDelegate ; this . vocabularySelectionDelegate = vocabularySelectionDelegate ; this . featureSettingsDelegate = featureSettingsDelegate ; this . navigatorDelegate = navigatorDelegate ; } public prepareAndFetch ( ) { this . vocabularyListDelegate . prepareAndFetch ( this . observableScreen . selectedVocabularyStatus . get ( ) , this . observableScreen . selectedSortType . get ( ) , [ this . observableScreen . category . categoryName ] ) ; } public fetch ( ) { this . vocabularyListDelegate . fetch ( ) ; } public clearFetch ( ) { this . vocabularyListDelegate . clearFetch ( ) ; } public refresh ( ) { this . vocabularyListDelegate . refresh ( this . observableScreen . selectedVocabularyStatus . get ( ) , this . observableScreen . selectedSortType . get ( ) , [ this . observableScreen . category . categoryName ] ) ; } public autoUpdateEditedVocabulary ( ) { this . vocabularyLiveUpdateDelegate . autoUpdateEditedVocabulary ( true , true ) ; } public autoRefreshOnMultipleEdit ( ) { this . eventBus . subscribe ( on ( [ ActionType . VOCABULARY__ADD_MULTIPLE_SUCCEEDED , ActionType . VOCABULARY__BULK_EDIT_SUCCEEDED , ActionType . VOCABULARY__EDIT_MULTIPLE_SUCCEEDED , ] , ( ) : void => { this . refresh ( ) ; } ) ) ; } public autoShowRefreshNotice ( ) { this . eventBus . subscribe ( on ( [ ActionType . VOCABULARY__ADD_SUCCEEDED , ActionType . VOCABULARY__EDIT_SUCCEEDED , ActionType . VOCABULARY__DOWNLOAD_VOCABULARY_SUCCEEDED , ActionType . VOCABULARY__DOWNLOAD_INCOMPATIBLE_VOCABULARY_SUCCEEDED , ] , ( ) : void => { this . observableScreen . vocabularyListState . shouldShowRefreshNotice . set ( true ) ; } ) ) ; } public autoShowSyncingInProgress ( ) { this . eventBus . subscribe ( group ( on ( [ ActionType . SYNC__STOP , ActionType . SYNC__SYNC_COMPLETED ] , ( ) : void => { this . observableScreen . vocabularyListState . shouldShowSyncingNotice . set ( false ) ; } ) , on ( ActionType . SYNC__SYNCING , ( ) : void => { this . observableScreen . vocabularyListState . shouldShowSyncingNotice . set ( true ) ; } ) ) ) ; } public showVocabularyDetail ( vocabulary ) { this . navigatorDelegate . showModal ( ScreenName . VOCABULARY_DETAIL_SCREEN , { vocabulary , } ) ; } public toggleSelection ( vocabularyId ) { this . vocabularySelectionDelegate . toggleSelection ( vocabularyId ) ; } public clearSelections ( ) { this . vocabularySelectionDelegate . clearSelections ( ) ; } public showCategoryActionMenu ( ) { const featureSettings = this . featureSettingsDelegate . getCurrentSettings ( ) ; this . categoryActionMenuDelegate . show ( this . observableScreen . category , this . observableScreen . selectedVocabularyStatus . get ( ) , { hideCategorizeButton : true , hideMoveButton : true , hideRestoreButton : true , hideArchiveButton : true , hideDeleteButton : true , hideViewDetailButton : true , hideReviewBySpacedRepetitionButton : ! featureSettings . spacedRepetitionEnabled , hideReviewByWritingButton : ! featureSettings . writingEnabled , hideQuizButton : ! featureSettings . quizEnabled , hidePlayReflexButton : ! featureSettings . reflexEnabled , hidePlayAtomButton : ! featureSettings . atomEnabled , } ) ; } public showVocabularyFilterMenu ( ) { this . vocabularyFilterMenuDelegate . show ( this . observableScreen . selectedVocabularyStatus . get ( ) , ( vocabularyStatus ) : void => { this . observableScreen . selectedVocabularyStatus . set ( vocabularyStatus ) ; this . refresh ( ) ; } ) ; } public showVocabularySortMenu ( ) { this . vocabularySortMenuDelegate . show ( this . observableScreen . selectedSortType . get ( ) , ( sortType ) : void => { this . observableScreen . selectedSortType . set ( sortType ) ; this . refresh ( ) ; } ) ; } public showVocabularyActionMenu ( vocabulary ) { this . vocabularyActionMenuDelegate . show ( vocabulary ) ; } public showVocabularyBulkActionMenu ( ) { this . vocabularyBulkActionMenuDelegate . show ( ) ; } }