File

src/app/language-settings/language-settings.ts

Metadata

Index

Properties
Methods

Constructor

constructor(preferences: SharedPreferences, translateService: TranslateService, events: Events, zone: NgZone, telemetryGeneratorService: TelemetryGeneratorService, platform: Platform, commonUtilService: CommonUtilService, headerService: AppHeaderService, notification: NotificationService, router: Router, location: Location, activatedRoute: ActivatedRoute, nativePageTransitions: NativePageTransitions, onboardingConfigurationService: OnboardingConfigurationService)
Parameters :
Name Type Optional
preferences SharedPreferences No
translateService TranslateService No
events Events No
zone NgZone No
telemetryGeneratorService TelemetryGeneratorService No
platform Platform No
commonUtilService CommonUtilService No
headerService AppHeaderService No
notification NotificationService No
router Router No
location Location No
activatedRoute ActivatedRoute No
nativePageTransitions NativePageTransitions No
onboardingConfigurationService OnboardingConfigurationService No

Methods

continue
continue()
Returns : void
generateClickInteractEvent
generateClickInteractEvent(selectedLanguage: string, interactSubType)
Parameters :
Name Type Optional
selectedLanguage string No
interactSubType No
Returns : void
generateLanguageFailedInteractEvent
generateLanguageFailedInteractEvent()
Returns : void
generateLanguageSuccessInteractEvent
generateLanguageSuccessInteractEvent(previousLanguage: string, currentLanguage: string)
Parameters :
Name Type Optional
previousLanguage string No
currentLanguage string No
Returns : void
handleBackButton
handleBackButton()
Returns : void
handleHeaderEvents
handleHeaderEvents($event)
Parameters :
Name Optional
$event No
Returns : void
init
init()
Returns : void
ionViewDidEnter
ionViewDidEnter()
Returns : void
Async ionViewWillEnter
ionViewWillEnter()
Returns : any
ionViewWillLeave
ionViewWillLeave()
Returns : void
onLanguageSelected
onLanguageSelected()

It will set app language

Returns : void

Properties

appName
Type : string
Default value : ''
btnColor
Type : string
Default value : '#8FC4FF'
headerConfig
Type : any
headerObservable
Type : any
isFromSettings
Default value : false
isLanguageSelected
Default value : false
language
Type : string
languages
Type : Array<ILanguages>
Default value : []
Public platform
Type : Platform
previousLanguage
Type : any
selectedLanguage
Type : any
Default value : {}
tappedLanguage
Type : string
Public translateService
Type : TranslateService
unregisterBackButton
Type : Subscription
import { Location } from '@angular/common';
import { Component, Inject, NgZone } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { PreferenceKey, RouterLinks } from '@app/app/app.constant';
import { Map } from '@app/app/telemetryutil';
import { AppHeaderService } from '@app/services/app-header.service';
import { CommonUtilService } from '@app/services/common-util.service';
import { NotificationService } from '@app/services/notification.service';
import {
  AuditProps, AuditType, CorReleationDataType, Environment, ID, ImpressionType, InteractSubtype,
  InteractType, PageId
} from '@app/services/telemetry-constants';
import { TelemetryGeneratorService } from '@app/services/telemetry-generator.service';
import { NativePageTransitions, NativeTransitionOptions } from '@ionic-native/native-page-transitions/ngx';
import { Platform } from '@ionic/angular';
import { Events } from '@app/util/events';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { AuditState, CorrelationData, SharedPreferences } from 'sunbird-sdk';
import { TagPrefixConstants } from '@app/services/segmentation-tag/segmentation-tag.service';
import { OnboardingConfigurationService } from '@app/services';

export interface ILanguages {
  label: string;
  code: string;
  isApplied: boolean;
  name: string;
}
@Component({
  selector: 'page-language-settings',
  templateUrl: 'language-settings.html',
  styleUrls: ['./language-settings.scss']
})
export class LanguageSettingsPage {

  languages: Array<ILanguages> = [];
  language: string;
  isLanguageSelected = false;
  isFromSettings = false;
  previousLanguage: any;
  selectedLanguage: any = {};
  tappedLanguage: string;
  btnColor = '#8FC4FF';
  unregisterBackButton: Subscription;
  headerConfig: any;
  headerObservable: any;
  appName = '';

  constructor(
    @Inject('SHARED_PREFERENCES') private preferences: SharedPreferences,
    public translateService: TranslateService,
    private events: Events,
    private zone: NgZone,
    private telemetryGeneratorService: TelemetryGeneratorService,
    public platform: Platform,
    private commonUtilService: CommonUtilService,
    private headerService: AppHeaderService,
    private notification: NotificationService,
    private router: Router,
    private location: Location,
    private activatedRoute: ActivatedRoute,
    private nativePageTransitions: NativePageTransitions,
    private onboardingConfigurationService: OnboardingConfigurationService
  ) { }

  ionViewDidEnter() {
    this.activatedRoute.params.subscribe(async params => {
      this.isFromSettings = Boolean(params['isFromSettings']);
      if (!this.isFromSettings) {
        this.headerService.hideHeader();
      } else {
        this.headerService.showHeaderWithBackButton();
      }
    });
  }

  handleBackButton() {
    this.unregisterBackButton = this.platform.backButton.subscribeWithPriority(10, () => {
      this.telemetryGeneratorService.generateInteractTelemetry(
        InteractType.TOUCH, InteractSubtype.DEVICE_BACK_CLICKED,
        this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
        this.isFromSettings ? PageId.SETTINGS_LANGUAGE : PageId.ONBOARDING_LANGUAGE_SETTING,
      );
      if (this.isFromSettings) {
        this.location.back();
      } else {
        if (this.platform.is('ios')) {
          this.headerService.showHeaderWithHomeButton();
        } else {
          this.commonUtilService.showExitPopUp(PageId.ONBOARDING_LANGUAGE_SETTING, Environment.ONBOARDING, false);
        }
      }
    });
  }

  async ionViewWillEnter() {
    const params = this.activatedRoute.snapshot.params;

    this.isFromSettings = Boolean(params['isFromSettings']);

    if (!this.isFromSettings) {
      this.headerService.hideHeader();
    } else {
      this.headerService.showHeaderWithBackButton();
    }

    this.appName = await this.commonUtilService.getAppName();

    if (this.router.url === '/' + RouterLinks.LANGUAGE_SETTING || this.router.url === '/' + RouterLinks.LANGUAGE_SETTING + '/' + 'true') {
      setTimeout(() => {
        /* New Telemetry */
        this.telemetryGeneratorService.generatePageLoadedTelemetry(
          this.isFromSettings ? PageId.SETTINGS_LANGUAGE : PageId.LANGUAGE,
          this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING
        );

        this.telemetryGeneratorService.generateImpressionTelemetry(
          ImpressionType.VIEW, '',
          this.isFromSettings ? PageId.SETTINGS_LANGUAGE : PageId.ONBOARDING_LANGUAGE_SETTING,
          this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
        );
      }, 350);
    }

    this.selectedLanguage = {};
    this.init();
    this.headerObservable = this.headerService.headerEventEmitted$.subscribe(eventName => {
      this.handleHeaderEvents(eventName);
    });
    this.handleBackButton();
  }

  ionViewWillLeave() {
    if (this.isLanguageSelected) {
      if (!this.selectedLanguage.code) {
        if (this.previousLanguage) {
          this.translateService.use(this.previousLanguage);
        } else {
          this.translateService.use('en');
        }
      }
    }
    if (this.headerObservable) {
      this.headerObservable.unsubscribe();
    }
    if (this.unregisterBackButton) {
      this.unregisterBackButton.unsubscribe();
    }
  }

  init(): void {
    this.languages = this.onboardingConfigurationService.getOnboardingConfig('language-setting').data;

    this.zone.run(() => {
      this.preferences.getString(PreferenceKey.SELECTED_LANGUAGE_CODE).toPromise()
        .then(val => {
          if (Boolean(val)) {
            this.previousLanguage = val;
            this.language = val;
          } else {
            this.previousLanguage = undefined;
          }
        });
    });

  }

  /**
   * It will set app language
   */
  onLanguageSelected() {
    /* New Telemetry */
    const cData: CorrelationData[] = [{
      id: this.language,
      type: CorReleationDataType.NEW_VALUE
    }];
    if (this.tappedLanguage) {
      cData.push({ id: this.tappedLanguage, type: CorReleationDataType.OLD_VALUE });
    }
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.SELECT_LANGUAGE, '',
      this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
      PageId.LANGUAGE,
      undefined,
      undefined,
      undefined,
      cData
    );
    this.tappedLanguage = this.language;
    if (this.language) {
      this.zone.run(() => {
        this.translateService.use(this.language);
        this.btnColor = '#006DE5';
        this.isLanguageSelected = true;
      });
    } else {
      this.btnColor = '#8FC4FF';
    }
  }

  generateLanguageFailedInteractEvent() {
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.DISABLED,
      '',
      Environment.ONBOARDING,
      PageId.ONBOARDING_LANGUAGE_SETTING,
      undefined,
      undefined,
      undefined,
      undefined,
      ID.CONTINUE_CLICKED
    );
    /* New Telemetry */
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.SELECT_CONTINUE,
      InteractSubtype.FAIL,
      Environment.ONBOARDING,
      PageId.LANGUAGE
    );
  }


  generateLanguageSuccessInteractEvent(previousLanguage: string, currentLanguage: string) {
    const valuesMap = new Map();
    valuesMap['previousLanguage'] = previousLanguage ? previousLanguage : '';
    valuesMap['currentLanguage'] = currentLanguage;
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.TOUCH,
      InteractSubtype.LANGUAGE_SETTINGS_SUCCESS,
      this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
      this.isFromSettings ? PageId.SETTINGS_LANGUAGE : PageId.ONBOARDING_LANGUAGE_SETTING,
      undefined,
      valuesMap
    );
    /* New Telemetry */
    const cData: CorrelationData[] = [{
      id: currentLanguage,
      type: CorReleationDataType.NEW_VALUE
    }];
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.SELECT_CONTINUE,
      InteractSubtype.SUCCESS,
      this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
      this.isFromSettings ? PageId.SETTINGS_LANGUAGE : PageId.LANGUAGE,
      undefined,
      undefined,
      undefined,
      cData
    );
  }

  generateClickInteractEvent(selectedLanguage: string, interactSubType) {
    const valuesMap = new Map();
    valuesMap['selectedLanguage'] = selectedLanguage;
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.TOUCH,
      interactSubType,
      this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
      this.isFromSettings ? PageId.SETTINGS_LANGUAGE : PageId.ONBOARDING_LANGUAGE_SETTING,
      undefined,
      valuesMap
    );
  }

  continue() {
    // if language is not null, then select the checked language,
    // else set default language as english
    if (this.isLanguageSelected) {
      this.generateClickInteractEvent(this.language, InteractSubtype.CONTINUE_CLICKED);
      this.generateLanguageSuccessInteractEvent(this.previousLanguage, this.language);

      if (this.language) {
        this.selectedLanguage = this.languages.find(i => i.code === this.language);
        window['segmentation'].SBTagService.pushTag([this.selectedLanguage.code], TagPrefixConstants.USER_LANG, true);
        this.preferences.putString(PreferenceKey.SELECTED_LANGUAGE_CODE, this.selectedLanguage.code).toPromise();
        this.preferences.putString(PreferenceKey.SELECTED_LANGUAGE, this.selectedLanguage.label).toPromise();
        this.translateService.use(this.language);
      }
      this.events.publish('onAfterLanguageChange:update', {
        selectedLanguage: this.language
      });
      this.notification.setupLocalNotification(this.language);
      const corRelationList: Array<CorrelationData> = [
        { id: PageId.LANGUAGE, type: CorReleationDataType.FROM_PAGE }
      ];
      corRelationList.push({ id: this.language || '', type: CorReleationDataType.LANGUAGE });
      this.telemetryGeneratorService.generateAuditTelemetry(
        this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
        AuditState.AUDIT_UPDATED,
        [AuditProps.LANGUAGE],
        AuditType.SET_LANGUAGE,
        undefined,
        undefined,
        undefined,
        corRelationList
      );
      if (this.isFromSettings) {
        this.location.back();
      } else {
        const options: NativeTransitionOptions = {
          direction: 'up',
          duration: 500,
          androiddelay: 500,
          iosdelay: 500,
          fixedPixelsTop: 0,
          fixedPixelsBottom: 0
        };
        this.nativePageTransitions.slide(options);
        this.router.navigate([RouterLinks.USER_TYPE_SELECTION]);
        this.preferences.putBoolean(PreferenceKey.IS_NEW_USER, true).toPromise();
      }
    } else {
      this.generateLanguageFailedInteractEvent();

      this.btnColor = '#8FC4FF';

      const parser = new DOMParser();
      const translatedString = this.commonUtilService.translateMessage('PLEASE_SELECT_A_LANGUAGE');
      const dom = parser.parseFromString(`<!doctype html><body>&#9432; ${translatedString}`, 'text/html');

      this.commonUtilService.showToast(dom.body.textContent, false, 'redErrorToast');
    }
  }

  handleHeaderEvents($event) {
    if ($event.name === 'back') {
      this.telemetryGeneratorService.generateBackClickedTelemetry(
        this.isFromSettings ? PageId.SETTINGS_LANGUAGE : PageId.ONBOARDING_LANGUAGE_SETTING,
        this.isFromSettings ? Environment.SETTINGS : Environment.ONBOARDING,
        true);
      this.location.back();
    }
  }
}
<ion-content [ngClass]="{ 'ui-container': !platform.is('ios') }">
  <div class="ui-container" *ngIf="platform.is('ios')"></div>
  <div class="ui-content">
    <div *ngIf="!isFromSettings" tabindex="0" class="app-title ion-text-center" role="heading" aria-level="1">{{'APP_TITLE' | translate:{'%s': appName } }}</div>
    <div class="font-size-17" role="heading" tabindex="0" aria-level="2" class="ion-text-center ion-padding ion-text-wrap" style="padding: 0">
      <strong>{{ 'CHOOSE_LANGUAGE' | translate }}</strong>
    </div>

    <div class="language-container">
      <div class="language-card" (click)="language = lang.code; onLanguageSelected()" *ngFor="let lang of languages" [ngClass]="{'selected-lang': lang.code === language}"
      tabindex="0" [attr.aria-label]="lang.code === language ? lang?.name + ', selected' : lang?.name" role="button">
        <label class="language-selection" [for]="'language-selection' + lang.code">
          <span class="label-text">
            {{lang?.label | translate}}
          </span>
          <img src='assets/imgs/ic_check_white.svg' alt="check" class="icon-check">
        </label>
      </div>
      <div class="bottom-section"></div>
    </div>

    <button class="sb-btn sb-btn-md sb-btn-primary PR35 W100 ellipsis text-uppercase btn-block continue"
            [style.background-color]="btnColor" [attr.aria-label]="'Continue'" role="button" tabindex="0" [hidden]="!isLanguageSelected" (click)="continue()">
      <span>{{ 'CONTINUE' | translate }}</span>
      <img class="arrow-icon" src="assets/imgs/ic_back.svg" [class.animate]="isLanguageSelected" alt="">
    </button>
  </div>
</ion-content>

./language-settings.scss

@import "src/assets/styles/_variables";
@import "src/assets/styles/_custom-mixins";
@import "src/assets/styles/fonts";
@import "src/assets/styles/_variables.scss";

:host {
  /* This should be item-ios only as we are targeting mode as iOS for radio-button */

  img.arrow-icon {
    display: inline-block;
    width: 1.375rem;
    margin-top: -3px;
    float: right;

    &.animate {
      position: relative;
      animation: dropDown 5s linear infinite;
      animation-duration: 0.9s;
    }

    @include rtl {
      transform: rotate(180deg);
      float: left !important;
    }
  }

  .md button span {
    width: 100%;
    display: inline-block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .ios button span {
    display: inline-block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  @keyframes dropDown {
    0% {
      right: 0;
    }
    50% {
      right: 0.625rem;
    }
    100% {
      right: 0;
    }
  }
  .gray-color {
    color: #{map-get($colors, secondary_black)};
    font-size: 1rem;
    font-weight: 500;
  }

  .font-size-17 {
    font-size: 1.063rem !important;
  }
}

.language-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.language-card {
  box-sizing: border-box;
  width: 50%;
  height: 9rem;
  padding: 1rem;
  outline: none;
  border-radius: 1rem;
}

.selected-lang {
  .language-selection {
    background-color: var(--app-primary) !important;
  }
  .label-text {
    color: var(--app-white) !important;
  }
}

.language-card label {
  position: relative;
  box-shadow: 0 20px 40px -10px map-get($colors, light_silver);
  background-color: map-get($colors, white);
  display: inline-block;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  text-align: center;
}

.language-card span {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 1.25rem;
  transform: translate(-50%, -50%);
}

.language-card input {
  display: none;
}
.continue {
  position: fixed;
  z-index: 2;
  bottom: 2rem;
  width: 90vw;
  left: 5vw;
}

.app-title {
  font-size: 1.5rem;
  font-weight: bold;
  color: $blue;
  margin-top: 5vh;
}

.icon-check {
  visibility: visible;
  width: auto;
  height: auto;
  float: right;
  margin-top: 7px;
  margin-right: 11px;
}

.bottom-section {
  width: 4.688rem;
  height: 4.688rem;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""