import { ActionType } from '@ulangi/ulangi-action' ; import { ScreenName , VocabularyStatus } from '@ulangi/ulangi-common/enums' ; import { Category } from '@ulangi/ulangi-common/interfaces' ; import { EventBus , group , on } from '@ulangi/ulangi-event' ; import { ObservableCategory , ObservableManageScreen , } from '@ulangi/ulangi-observable' ; import { boundClass } from 'autobind-decorator' ; import { CategoryActionMenuDelegate } from '../category/CategoryActionMenuDelegate' ; import { CategoryBulkActionMenuDelegate } from '../category/CategoryBulkActionMenuDelegate' ; import { CategoryListDelegate } from '../category/CategoryListDelegate' ; import { CategorySelectionDelegate } from '../category/CategorySelectionDelegate' ; import { CategorySortMenuDelegate } from '../category/CategorySortMenuDelegate' ; import { FeatureSettingsDelegate } from '../learn/FeatureSettingsDelegate' ; import { LevelBreakdownDelegate } from '../level/LevelBreakdownDelegate' ; import { AutorunDelegate } from '../manage/AutorunDelegate' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; import { InAppRatingDelegate } from '../rating/InAppRatingDelegate' ; import { VocabularyFilterMenuDelegate } from '../vocabulary/VocabularyFilterMenuDelegate' ; @ boundClass export class ManageScreenDelegate { private eventBus : EventBus ; private observableScreen : ObservableManageScreen ; private categoryListDelegate : CategoryListDelegate ; private categoryActionMenuDelegate : CategoryActionMenuDelegate ; private categoryBulkActionMenuDelegate : CategoryBulkActionMenuDelegate ; private categorySelectionDelegate : CategorySelectionDelegate ; private categorySortMenuDelegate : CategorySortMenuDelegate ; private levelBreakdownDelegate : LevelBreakdownDelegate ; private vocabularyFilterMenuDelegate : VocabularyFilterMenuDelegate ; private featureSettingsDelegate : FeatureSettingsDelegate ; private autorunDelegate : AutorunDelegate ; private inAppRatingDelegate : InAppRatingDelegate ; private navigatorDelegate : NavigatorDelegate ; public constructor ( eventBus , observableScreen , categoryListDelegate , categoryActionMenuDelegate , categoryBulkActionMenuDelegate , categorySelectionDelegate , categorySortMenuDelegate , levelBreakdownDelegate , vocabularyFilterMenuDelegate , featureSettingsDelegate , autorunDelegate , inAppRatingDelegate , navigatorDelegate ) { this . eventBus = eventBus ; this . observableScreen = observableScreen ; this . categoryListDelegate = categoryListDelegate ; this . categoryActionMenuDelegate = categoryActionMenuDelegate ; this . categoryBulkActionMenuDelegate = categoryBulkActionMenuDelegate ; this . categorySelectionDelegate = categorySelectionDelegate ; this . categorySortMenuDelegate = categorySortMenuDelegate ; this . levelBreakdownDelegate = levelBreakdownDelegate ; this . vocabularyFilterMenuDelegate = vocabularyFilterMenuDelegate ; this . featureSettingsDelegate = featureSettingsDelegate ; this . autorunDelegate = autorunDelegate ; this . inAppRatingDelegate = inAppRatingDelegate ; this . navigatorDelegate = navigatorDelegate ; } public prepareAndFetch ( ) { this . categoryListDelegate . prepareAndFetch ( this . observableScreen . selectedVocabularyStatus . get ( ) , this . observableScreen . selectedSortType . get ( ) ) ; } public fetch ( ) { this . categoryListDelegate . fetch ( this . observableScreen . selectedVocabularyStatus . get ( ) === VocabularyStatus . ACTIVE ) ; } public clearFetch ( ) { this . categoryListDelegate . clearFetch ( ) ; } public refresh ( ) { this . categoryListDelegate . refresh ( this . observableScreen . selectedVocabularyStatus . get ( ) , this . observableScreen . selectedSortType . get ( ) ) ; } public refreshIfEmpty ( ) { this . categoryListDelegate . refreshIfEmpty ( this . observableScreen . selectedVocabularyStatus . get ( ) , this . observableScreen . selectedSortType . get ( ) ) ; } public showCategoryDetail ( category ) { this . navigatorDelegate . push ( ScreenName . CATEGORY_DETAIL_SCREEN , { selectedVocabularyStatus : this . observableScreen . selectedVocabularyStatus . get ( ) , category , } ) ; } public showCategoryActionMenu ( category , vocabularyStatus ) { const featureSettings = this . featureSettingsDelegate . getCurrentSettings ( ) ; this . categoryActionMenuDelegate . show ( category , vocabularyStatus , { hideViewDetailButton : false , hideCategorizeButton : false , hideMoveButton : false , hideRestoreButton : false , hideArchiveButton : false , hideDeleteButton : false , hideReviewBySpacedRepetitionButton : ! featureSettings . spacedRepetitionEnabled , hideReviewByWritingButton : ! featureSettings . writingEnabled , hideQuizButton : ! featureSettings . quizEnabled , hidePlayReflexButton : ! featureSettings . reflexEnabled , hidePlayAtomButton : ! featureSettings . atomEnabled , } ) ; } public showCategoryBulkActionMenu ( ) { const featureSettings = this . featureSettingsDelegate . getCurrentSettings ( ) ; this . categoryBulkActionMenuDelegate . show ( this . observableScreen . selectedVocabularyStatus . get ( ) , this . observableScreen . categoryListState . categoryList , this . observableScreen . categoryListState . selectedCategoryNames , { hideReviewBySpacedRepetitionButton : ! featureSettings . spacedRepetitionEnabled , hideReviewByWritingButton : ! featureSettings . writingEnabled , hideQuizButton : ! featureSettings . quizEnabled , hidePlayReflexButton : ! featureSettings . reflexEnabled , hidePlayAtomButton : ! featureSettings . atomEnabled , } ) ; } public showCategorySortMenu ( ) { this . categorySortMenuDelegate . show ( this . observableScreen . selectedSortType . get ( ) , ( sortType ) : void => { this . observableScreen . selectedSortType . set ( sortType ) ; this . refresh ( ) ; } ) ; } public showVocabularyFilterMenu ( ) { this . vocabularyFilterMenuDelegate . show ( this . observableScreen . selectedVocabularyStatus . get ( ) , ( vocabularyStatus ) : void => { this . observableScreen . selectedVocabularyStatus . set ( vocabularyStatus ) ; this . refresh ( ) ; } ) ; } public autoRefreshOnMultipleEdit ( ) { this . eventBus . subscribe ( on ( [ ActionType . VOCABULARY__ADD_MULTIPLE_SUCCEEDED , ActionType . VOCABULARY__EDIT_MULTIPLE_SUCCEEDED , ActionType . VOCABULARY__BULK_EDIT_SUCCEEDED , ] , ( ) : void => { this . refresh ( ) ; } ) ) ; } public autoShowRefreshNotice ( ) { this . eventBus . subscribe ( on ( [ ActionType . SET__ADD_SUCCEEDED , ActionType . SET__EDIT_SUCCEEDED , ActionType . SET__DOWNLOAD_SETS_SUCCEEDED , ActionType . SET__DOWNLOAD_INCOMPATIBLE_SETS_FAILED , ActionType . VOCABULARY__ADD_SUCCEEDED , ActionType . VOCABULARY__ADD_MULTIPLE_SUCCEEDED , ActionType . VOCABULARY__EDIT_SUCCEEDED , ActionType . VOCABULARY__DOWNLOAD_VOCABULARY_SUCCEEDED , ActionType . VOCABULARY__DOWNLOAD_INCOMPATIBLE_VOCABULARY_SUCCEEDED , ActionType . SPACED_REPETITION__SAVE_RESULT , ActionType . WRITING__SAVE_RESULT , ] , ( ) : void => { this . observableScreen . categoryListState . shouldShowRefreshNotice . set ( true ) ; } ) ) ; } public autoShowSyncingInProgress ( ) { this . eventBus . subscribe ( group ( on ( [ ActionType . SYNC__STOP , ActionType . SYNC__SYNC_COMPLETED ] , ( ) : void => { this . observableScreen . categoryListState . shouldShowSyncingNotice . set ( false ) ; } ) , on ( ActionType . SYNC__SYNCING , ( ) : void => { this . observableScreen . categoryListState . shouldShowSyncingNotice . set ( true ) ; } ) ) ) ; } public autoRefreshOnSetChange ( ) { this . eventBus . subscribe ( on ( ActionType . SET__SELECT , ( ) : void => { this . refresh ( ) ; } ) ) ; } public autoUpdateDueAndNewCounts ( ) { this . categoryListDelegate . autoUpdateSpacedRepetitionDueAndNewCounts ( ) ; this . categoryListDelegate . autoUpdateWritingDueAndNewCounts ( ) ; } public toggleSelection ( id ) { this . categorySelectionDelegate . toggleSelection ( id ) ; } public clearSelections ( ) { this . categorySelectionDelegate . clearSelections ( ) ; } public showQuickTutorial ( ) { this . navigatorDelegate . push ( ScreenName . QUICK_TUTORIAL_SCREEN , { } ) ; } public goToGoogleSheetsAddOnScreen ( ) { this . navigatorDelegate . push ( ScreenName . GOOGLE_SHEETS_ADD_ON_SCREEN , { } ) ; } public goToAddVocabulary ( ) { this . navigatorDelegate . push ( ScreenName . ADD_VOCABULARY_SCREEN , { closeOnSaveSucceeded : false , } ) ; } public goToSearchVocabulary ( ) { this . navigatorDelegate . push ( ScreenName . SEARCH_SCREEN , { } ) ; } public goToSpacedRepetition ( selectedCategoryNames ) { this . navigatorDelegate . push ( ScreenName . SPACED_REPETITION_SCREEN , { selectedCategoryNames , onClose : ( ) : void => { this . inAppRatingDelegate . autoShowInAppRating ( ) ; } , } ) ; } public goToWriting ( selectedCategoryNames ) { this . navigatorDelegate . push ( ScreenName . WRITING_SCREEN , { selectedCategoryNames , } ) ; } public autorun ( ) { this . autorunDelegate . autorun ( ) ; } public showLevelBreakdownForSR ( category ) { this . levelBreakdownDelegate . show ( { totalCount : category . totalCount , level0Count : category . srLevel0Count , level1To3Count : category . srLevel1To3Count , level4To6Count : category . srLevel4To6Count , level7To8Count : category . srLevel7To8Count , level9To10Count : category . srLevel9To10Count , } ) ; } public showLevelBreakdownForWR ( category ) { this . levelBreakdownDelegate . show ( { totalCount : category . totalCount , level0Count : category . wrLevel0Count , level1To3Count : category . wrLevel1To3Count , level4To6Count : category . wrLevel4To6Count , level7To8Count : category . wrLevel7To8Count , level9To10Count : category . wrLevel9To10Count , } ) ; } public shouldShowLevelProgressForSR ( ) { const featureSettings = this . featureSettingsDelegate . getCurrentSettings ( ) ; return featureSettings . spacedRepetitionEnabled ; } public shouldShowLevelProgressForWR ( ) { const featureSettings = this . featureSettingsDelegate . getCurrentSettings ( ) ; return featureSettings . writingEnabled ; } }