import { NgZone , ViewChild , ViewContainerRef , OnDestroy , ElementRef , AfterViewInit , OnInit , ChangeDetectionStrategy } from '@angular/core' ; import { Router } from '@angular/router' ; import { Location } from '@angular/common' ; import { ModalDialogService , ModalDialogOptions } from "nativescript-angular" ; import { screen , isIOS } from 'platform' ; import { Animation } from 'ui/animation' ; import { topmost } from 'ui/frame' ; import { AnimationCurve } from 'ui/enums' ; import { Store } from '@ngrx/store' ; import { BehaviorSubject } from "rxjs/BehaviorSubject" ; import { Subscription } from "rxjs/Subscription" ; import 'rxjs/add/operator/take' ; import { BaseComponent , Config , LogService } from '../../shared/core/index' ; import { SearchService , AuthService , IAuthState , PlaylistService , PLAYLIST_ACTIONS , TrackModel , EmptyComponent , CoachmarksService } from '../../shared/shoutoutplay/index' ; import { PlaylistChooserComponent } from '../playlist/playlist-chooser.component' ; import { IntegrationsComponent } from './integrations.component' ; @ BaseComponent ( { selector : 'search' , templateUrl : './components/search/search.component.html' } ) export class SearchComponent implements AfterViewInit , OnInit , OnDestroy { @ ViewChild ( 'searchbar' ) searchBarEl : ElementRef ; private _loadingMore : boolean = false ; private _sub : Subscription ; private _sub2 : Subscription ; constructor ( private store , private logger , public authService , public searchService , public playlistService , private modal , private vcRef , private ngZone , private router , private loc , private coachmarks ) { logger . debug ( `SearchComponent constructor` ) ; } public search ( e ) { if ( e && e . object ) { this . logger . debug ( e . object . text ) ; this . searchService . search ( e . object . text ) ; this . dismissKeyboard ( ) ; } } public loadMore ( e ) { if ( ! this . _loadingMore ) { this . _loadingMore = true ; this . searchService . searchMore ( ) ; setTimeout ( ( ) => { this . _loadingMore = false ; } , 1000 ) ; } } public clear ( ) { this . logger . debug ( 'clear' ) ; } public itemLoading ( e ) { if ( isIOS ) { e . ios . selectionStyle = UITableViewCellSelectionStyle . None ; } } private dismissKeyboard ( ) { if ( ! isIOS ) { setTimeout ( ( ) => { if ( this . searchBarEl . nativeElement ) { if ( this . searchBarEl . nativeElement . android ) { this . searchBarEl . nativeElement . android . clearFocus ( ) ; } else if ( this . searchBarEl . nativeElement . clearFocus ) { this . searchBarEl . nativeElement . clearFocus ( ) ; } } this . searchBarEl . nativeElement . dismissSoftInput ( ) ; } , 400 ) ; } } ngOnInit ( ) { this . logger . debug ( `SearchComponent ngOnInit` ) ; if ( ! Config . SEEN_INTRO ( ) ) { this . router . navigate ( [ '/intro' ] ) ; } else { } this . _sub = this . playlistService . state$ . subscribe ( ( state ) => { if ( state . showPicker ) { this . ngZone . run ( ( ) => { this . logger . debug ( `SearchComponent trying to show modal: PlaylistChooserComponent` ) ; let options = { context : { promptMsg : "This is the prompt message!" } , fullscreen : false , viewContainerRef : this . vcRef } ; this . modal . showModal ( PlaylistChooserComponent , options ) . then ( ( res ) => { this . store . dispatch ( { type : PLAYLIST_ACTIONS . CLOSE_PICKER } ) ; } ) ; } ) ; } } ) ; this . _sub2 = this . playlistService . showRecord$ . subscribe ( ( track ) => { if ( track ) { this . searchService . quickRecordTrack = track ; this . router . navigate ( [ '/record' ] ) ; } } ) ; } public requestIntegration ( ) { let options = { context : { promptMsg : "This is the prompt message!" } , fullscreen : false , viewContainerRef : this . vcRef } ; this . modal . showModal ( IntegrationsComponent , options ) . then ( ( choices ) => { if ( choices ) { this . logger . debug ( choices ) ; for ( let key in choices ) { this . logger . debug ( `key: ${ key }, ${ choices [ key ] }` ) ; } this . authService . sendRequests ( choices ) ; } } ) ; } ngAfterViewInit ( ) { this . logger . debug ( `SearchComponent ngAfterViewInit` ) ; this . logger . debug ( this . searchBarEl ) ; if ( this . searchBarEl ) { this . coachmarks . teachSearch ( this . searchBarEl . nativeElement ) ; this . dismissKeyboard ( ) ; } } ngOnDestroy ( ) { this . logger . debug ( `SearchComponent ngOnDestroy...` ) ; if ( this . _sub ) { this . _sub . unsubscribe ( ) ; } if ( this . _sub2 ) { this . _sub2 . unsubscribe ( ) ; } } }