File

src/services/app-header.service.ts

Index

Properties
Methods

Constructor

constructor(menuCtrl: MenuController, statusBar: StatusBar, preferences: SharedPreferences, onboardingConfigurationService: OnboardingConfigurationService)
Parameters :
Name Type Optional
menuCtrl MenuController No
statusBar StatusBar No
preferences SharedPreferences No
onboardingConfigurationService OnboardingConfigurationService No

Methods

getDefaultPageConfig
getDefaultPageConfig()
Returns : { showHeader: boolean; showBurgerMenu: boolean; showKebabMenu: boolean; kebabMenuOptions: {}; pageTitle: string; actionButtons: {}; }
hideHeader
hideHeader()
Returns : void
hideStatusBar
hideStatusBar()
Returns : void
showHeaderWithBackButton
showHeaderWithBackButton(iconList?, pageTitle?)
Parameters :
Name Optional
iconList Yes
pageTitle Yes
Returns : void
showHeaderWithHomeButton
showHeaderWithHomeButton(iconList?, pageTitle?)
Parameters :
Name Optional
iconList Yes
pageTitle Yes
Returns : void
Async showStatusBar
showStatusBar()
Returns : any
sidebarEvent
sidebarEvent(name: any)
Parameters :
Name Type Optional
name any No
Returns : void
sideMenuItemEvents
sideMenuItemEvents($event)
Parameters :
Name Optional
$event No
Returns : void
updatePageConfig
updatePageConfig(config)
Parameters :
Name Optional
config No
Returns : void

Properties

Private headerConfig
Default value : new Subject<any>()
headerConfigEmitted$
Default value : this.headerConfig.asObservable()
Private headerEvent
Default value : new Subject<any>()
headerEventEmitted$
Default value : this.headerEvent.asObservable()
Private sideMenuItemEvent
Default value : new Subject<any>()
sideMenuItemEventEmitted$
Default value : this.sideMenuItemEvent.asObservable()
import {Inject, Injectable} from '@angular/core';
import {Subject} from 'rxjs';
import {MenuController} from '@ionic/angular';
import {StatusBar} from '@ionic-native/status-bar/ngx';
import {SharedPreferences} from 'sunbird-sdk';
import {AppThemes, StatusBarTheme,AppMode} from '@app/app/app.constant';
import { OnboardingConfigurationService } from '.';

@Injectable()
export class AppHeaderService {

    constructor(private menuCtrl: MenuController,
                private statusBar: StatusBar,
                @Inject('SHARED_PREFERENCES') private preferences: SharedPreferences,
                private onboardingConfigurationService: OnboardingConfigurationService
    ) {
    }

    private headerEvent = new Subject<any>();
    headerEventEmitted$ = this.headerEvent.asObservable();

    private headerConfig = new Subject<any>();
    headerConfigEmitted$ = this.headerConfig.asObservable();


    private sideMenuItemEvent = new Subject<any>();
    sideMenuItemEventEmitted$ = this.sideMenuItemEvent.asObservable();

    sidebarEvent(name: any) {
        this.headerEvent.next(name);
    }

    sideMenuItemEvents($event) {
        this.sideMenuItemEvent.next($event);
    }

    getDefaultPageConfig() {
        const defaultConfig = {
            showHeader: true,
            showBurgerMenu: true,
            showKebabMenu: false,
            kebabMenuOptions: [],
            pageTitle: '',
            actionButtons: ['search'],
        };
        return defaultConfig;
    }

    hideHeader() {
        const defaultConfig = this.getDefaultPageConfig();
        defaultConfig.showHeader = false;
        defaultConfig.showBurgerMenu = false;
        this.updatePageConfig(defaultConfig);
        this.menuCtrl.enable(false);
    }

    showHeaderWithBackButton(iconList?, pageTitle?) {
        const defaultConfig = this.getDefaultPageConfig();
        defaultConfig.showHeader = true;
        defaultConfig.showBurgerMenu = false;
        defaultConfig.actionButtons = iconList ? iconList : [];
        defaultConfig.pageTitle = pageTitle;
        this.updatePageConfig(defaultConfig);
        this.menuCtrl.enable(false);
    }

    showHeaderWithHomeButton(iconList?, pageTitle?) {
        const defaultConfig = this.getDefaultPageConfig();
        defaultConfig.showHeader = true;
        defaultConfig.showBurgerMenu = true;
        defaultConfig.actionButtons = iconList ? iconList : [];
        defaultConfig.pageTitle = pageTitle;
        this.updatePageConfig(defaultConfig);
        this.menuCtrl.enable(true);
    }

    updatePageConfig(config) {
        this.headerConfig.next(config);
    }

    async showStatusBar() {
        const theme = await this.preferences.getString('current_selected_theme').toPromise();
        if (theme === 'JOYFUL') {
            document.querySelector('html').setAttribute('data-theme', AppThemes.JOYFUL);
            const customTheme = this.onboardingConfigurationService.getAppConfig().theme
            if(customTheme.name){
                document.querySelector('html').setAttribute('data-color', customTheme.name);
            }
            document.querySelector('html').setAttribute('device-accessable-theme','accessible' );
            const themeColor = getComputedStyle(document.querySelector('html')).getPropertyValue('--app-primary-header');
            this.statusBar.backgroundColorByHexString(themeColor);      
        }
        const mode = await this.preferences.getString('data-mode').toPromise();
        if(mode===AppMode.DARKMODE){
            document.querySelector('html').setAttribute('data-mode',AppMode.DARKMODE);
        }else{
            document.querySelector('html').setAttribute('data-mode',AppMode.DEFAULT);
        }
        
    }

    hideStatusBar() {
        this.statusBar.backgroundColorByHexString(StatusBarTheme.SET_DEFAULT);
    }
}

results matching ""

    No results matching ""