src/app/settings/settings.page.ts
OnInit
selector | app-settings |
styleUrls | ./settings.page.scss |
templateUrl | ./settings.page.html |
Properties |
Methods |
constructor(profileService: ProfileService, preferences: SharedPreferences, authService: AuthService, sdkConfig: SdkConfig, apiService: ApiService, debugginService: DebuggingService, appVersion: AppVersion, socialSharing: SocialSharing, commonUtilService: CommonUtilService, telemetryGeneratorService: TelemetryGeneratorService, utilityService: UtilityService, headerService: AppHeaderService, router: Router, toastCtrl: ToastController, translate: TranslateService, popoverCtrl: PopoverController, formAndFrameworkUtilService: FormAndFrameworkUtilService, platform: Platform, location: Location, events: Events)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in src/app/settings/settings.page.ts:42
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters :
|
aboutUs |
aboutUs()
|
Defined in src/app/settings/settings.page.ts:118
|
Returns :
void
|
dataSync |
dataSync()
|
Defined in src/app/settings/settings.page.ts:113
|
Returns :
void
|
Async debugModeToggle |
debugModeToggle()
|
Defined in src/app/settings/settings.page.ts:306
|
Returns :
any
|
generateInteractTelemetry | ||||||
generateInteractTelemetry(interactionType, interactSubtype)
|
||||||
Defined in src/app/settings/settings.page.ts:134
|
||||||
Parameters :
Returns :
void
|
handleBackButton |
handleBackButton()
|
Defined in src/app/settings/settings.page.ts:298
|
Returns :
void
|
ionViewDidEnter |
ionViewDidEnter()
|
Defined in src/app/settings/settings.page.ts:105
|
Returns :
void
|
ionViewWillEnter |
ionViewWillEnter()
|
Defined in src/app/settings/settings.page.ts:74
|
Returns :
void
|
ionViewWillLeave |
ionViewWillLeave()
|
Defined in src/app/settings/settings.page.ts:86
|
Returns :
void
|
isOptionEnabled |
isOptionEnabled()
|
Defined in src/app/settings/settings.page.ts:387
|
Returns :
boolean
|
Private Async mergeAccount |
mergeAccount()
|
Defined in src/app/settings/settings.page.ts:191
|
Returns :
any
|
ngOnInit |
ngOnInit()
|
Defined in src/app/settings/settings.page.ts:92
|
Returns :
void
|
Async observeDebugging |
observeDebugging()
|
Defined in src/app/settings/settings.page.ts:377
|
Returns :
any
|
Async shareApp |
shareApp()
|
Defined in src/app/settings/settings.page.ts:123
|
Returns :
any
|
Async showMergeAccountConfirmationPopup |
showMergeAccountConfirmationPopup()
|
Defined in src/app/settings/settings.page.ts:147
|
Returns :
any
|
showPermissionPage |
showPermissionPage()
|
Defined in src/app/settings/settings.page.ts:142
|
Returns :
void
|
appName |
Type : any
|
Defined in src/app/settings/settings.page.ts:37
|
backButtonFunc |
Type : Subscription
|
Defined in src/app/settings/settings.page.ts:41
|
chosenLanguageString |
Type : string
|
Defined in src/app/settings/settings.page.ts:31
|
debugmode |
Type : any
|
Defined in src/app/settings/settings.page.ts:42
|
deviceId |
Type : string
|
Defined in src/app/settings/settings.page.ts:34
|
fileUrl |
Type : string
|
Defined in src/app/settings/settings.page.ts:33
|
Public isNotDefaultChannelProfile$ |
Type : Observable<boolean>
|
Defined in src/app/settings/settings.page.ts:40
|
Public isUserLoggedIn$ |
Type : Observable<boolean>
|
Defined in src/app/settings/settings.page.ts:39
|
Public platform |
Type : Platform
|
Defined in src/app/settings/settings.page.ts:61
|
selectedLanguage |
Type : string
|
Defined in src/app/settings/settings.page.ts:32
|
shareAppLabel |
Type : string
|
Defined in src/app/settings/settings.page.ts:36
|
subjectDetails |
Type : string
|
Defined in src/app/settings/settings.page.ts:35
|
import { Location } from '@angular/common';
import { Component, Inject, OnInit } from '@angular/core';
import { NavigationExtras, Router } from '@angular/router';
import { SbAppSharePopupComponent, SbPopoverComponent } from '@app/app/components/popups';
import { AppVersion } from '@ionic-native/app-version/ngx';
import { SocialSharing } from '@ionic-native/social-sharing/ngx';
import { Platform, PopoverController, ToastController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { Observable, Subscription } from 'rxjs';
import { catchError, finalize, map, mergeMap, tap } from 'rxjs/operators';
import { AppHeaderService, CommonUtilService, FormAndFrameworkUtilService, TelemetryGeneratorService, UtilityService } from 'services';
import { Environment, ImpressionType, InteractSubtype, InteractType, PageId } from 'services/telemetry-constants';
import {
ApiService, AuthService,
DebuggingService,
MergeServerProfilesRequest, ProfileService,
SdkConfig, SharedPreferences,
TelemetryImpressionRequest,
WebviewManualMergeSessionProvider,
WebviewSessionProviderConfig
} from 'sunbird-sdk';
import { PreferenceKey, RouterLinks } from '../app.constant';
import { Events } from '@app/util/events';
@Component({
selector: 'app-settings',
templateUrl: './settings.page.html',
styleUrls: ['./settings.page.scss'],
})
export class SettingsPage implements OnInit {
chosenLanguageString: string;
selectedLanguage: string;
fileUrl: string;
deviceId: string;
subjectDetails: string;
shareAppLabel: string;
appName: any;
public isUserLoggedIn$: Observable<boolean>;
public isNotDefaultChannelProfile$: Observable<boolean>;
backButtonFunc: Subscription;
debugmode: any;
constructor(
@Inject('PROFILE_SERVICE') private profileService: ProfileService,
@Inject('SHARED_PREFERENCES') private preferences: SharedPreferences,
@Inject('AUTH_SERVICE') private authService: AuthService,
@Inject('SDK_CONFIG') private sdkConfig: SdkConfig,
@Inject('API_SERVICE') private apiService: ApiService,
@Inject('DEBUGGING_SERVICE') private debugginService: DebuggingService,
private appVersion: AppVersion,
private socialSharing: SocialSharing,
private commonUtilService: CommonUtilService,
private telemetryGeneratorService: TelemetryGeneratorService,
private utilityService: UtilityService,
private headerService: AppHeaderService,
private router: Router,
private toastCtrl: ToastController,
private translate: TranslateService,
private popoverCtrl: PopoverController,
private formAndFrameworkUtilService: FormAndFrameworkUtilService,
public platform: Platform,
private location: Location,
private events: Events
) {
this.isUserLoggedIn$ = this.authService.getSession().pipe(
map((session) => !!session)
);
this.isNotDefaultChannelProfile$ = this.profileService.isDefaultChannelProfile().pipe(
map((isDefaultChannelProfile) => !isDefaultChannelProfile)
);
}
ionViewWillEnter() {
this.headerService.showHeaderWithBackButton(['font-accessibility']);
this.appVersion.getAppName()
.then((appName) => {
this.appName = appName;
this.shareAppLabel = this.commonUtilService.translateMessage('SHARE_APP', appName);
});
this.handleBackButton();
this.debugmode = this.debugginService.isDebugOn();
this.events.subscribe('debug_mode', (debugMode) => this.debugmode = debugMode);
}
ionViewWillLeave() {
if (this.backButtonFunc) {
this.backButtonFunc.unsubscribe();
}
}
ngOnInit() {
const telemetryImpressionRequest = new TelemetryImpressionRequest();
telemetryImpressionRequest.type = ImpressionType.VIEW;
telemetryImpressionRequest.pageId = PageId.SETTINGS;
telemetryImpressionRequest.env = Environment.SETTINGS;
this.telemetryGeneratorService.generateImpressionTelemetry(
ImpressionType.VIEW, '',
PageId.SETTINGS,
Environment.SETTINGS, '', '', '',
undefined
);
}
ionViewDidEnter() {
this.chosenLanguageString = this.commonUtilService.translateMessage('CURRENT_LANGUAGE');
this.preferences.getString(PreferenceKey.SELECTED_LANGUAGE).toPromise()
.then(value => {
this.selectedLanguage = `${this.chosenLanguageString} : ${value}`;
});
}
dataSync() {
this.generateInteractTelemetry(InteractType.TOUCH, InteractSubtype.DATA_SYNC_CLICKED);
this.router.navigate(['settings/data-sync']);
}
aboutUs() {
this.generateInteractTelemetry(InteractType.TOUCH, InteractSubtype.ABOUT_APP_CLICKED);
this.router.navigate([`/${RouterLinks.SETTINGS}/about-us`]);
}
async shareApp() {
const popover = await this.popoverCtrl.create({
component: SbAppSharePopupComponent,
componentProps: {
pageId: PageId.SETTINGS
},
cssClass: 'sb-popover',
});
await popover.present();
}
generateInteractTelemetry(interactionType, interactSubtype) {
this.telemetryGeneratorService.generateInteractTelemetry(
interactionType, interactSubtype,
PageId.SETTINGS,
Environment.SETTINGS, null
);
}
showPermissionPage() {
const navigationExtras: NavigationExtras = { state: { changePermissionAccess: true } };
this.router.navigate([`/${RouterLinks.SETTINGS}/permission`], navigationExtras);
}
async showMergeAccountConfirmationPopup() {
const confirm = await this.popoverCtrl.create({
component: SbPopoverComponent,
componentProps: {
isNotShowCloseIcon: false,
sbPopoverHeading: this.commonUtilService.translateMessage('MERGE_ACCOUNT'),
sbPopoverHtmlContent: '<div class="text-left font-weight-normal padding-left-10 padding-right-10">'
+ this.commonUtilService.translateMessage('ACCOUNT_MERGE_CONFIRMATION_CONTENT', await this.appVersion.getAppName()) + '</div>',
actionsButtons: [
{
btntext: this.commonUtilService.translateMessage('CANCEL'),
btnClass: 'popover-color popover-button-cancel',
},
{
btntext: this.commonUtilService.translateMessage('ACCOUNT_MERGE_CONFIRMATION_BTN_MERGE'),
btnClass: 'popover-color popover-button-allow',
}
],
handler: (selectedButton: string) => {
if (selectedButton === this.commonUtilService.translateMessage('CANCEL')) {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.CANCEL_CLICKED,
Environment.SETTINGS,
PageId.MERGE_ACCOUNT_POPUP
);
confirm.dismiss();
} else if (selectedButton === this.commonUtilService.translateMessage('ACCOUNT_MERGE_CONFIRMATION_BTN_MERGE')) {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.MERGE_CLICKED,
Environment.SETTINGS,
PageId.MERGE_ACCOUNT_POPUP
);
confirm.dismiss();
this.mergeAccount();
}
},
},
cssClass: 'sb-popover primary',
});
await confirm.present();
}
private async mergeAccount() {
let loader: any | undefined;
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.MERGE_ACCOUNT_INITIATED,
Environment.SETTINGS,
PageId.SETTINGS
);
const webviewSessionProviderConfigloader = await this.commonUtilService.getLoader();
let webviewMergeSessionProviderConfig: WebviewSessionProviderConfig;
await webviewSessionProviderConfigloader.present();
try {
webviewMergeSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('merge');
await webviewSessionProviderConfigloader.dismiss();
} catch (e) {
await webviewSessionProviderConfigloader.dismiss();
this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
return;
}
this.authService.getSession().pipe(
map((session) => session!),
mergeMap(async (mergeToProfileSession) => {
const mergeFromProfileSessionProvider = new WebviewManualMergeSessionProvider(
webviewMergeSessionProviderConfig
);
const mergeFromProfileSession = await mergeFromProfileSessionProvider.provide();
return {
from: {
userId: mergeFromProfileSession.userToken,
accessToken: mergeFromProfileSession.access_token
},
to: {
userId: mergeToProfileSession.userToken,
accessToken: mergeToProfileSession.access_token
}
} as MergeServerProfilesRequest;
}),
tap(async () => {
loader = await this.commonUtilService.getLoader();
await loader.present();
}),
mergeMap((mergeServerProfilesRequest) => {
return this.profileService.mergeServerProfiles(mergeServerProfilesRequest);
}),
catchError(async (e) => {
console.error(e);
if (e instanceof Error && e['code'] === 'INTERRUPT_ERROR') {
throw e;
}
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.OTHER,
InteractSubtype.MERGE_ACCOUNT_FAILED,
Environment.SETTINGS,
PageId.SETTINGS
);
const toast = await this.toastCtrl.create({
message: await this.translate.get('ACCOUNT_MERGE_FAILED').toPromise(),
duration: 2000,
position: 'bottom'
});
await toast.present();
throw e;
}),
tap(async () => {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.OTHER,
InteractSubtype.MERGE_ACCOUNT_SUCCESS,
Environment.SETTINGS,
PageId.SETTINGS
);
const successPopover = await this.popoverCtrl.create({
component: SbPopoverComponent,
componentProps: {
sbPopoverHeading: this.commonUtilService.translateMessage('MERGE_ACCOUNT'),
icon: null,
actionsButtons: [
{
btntext: this.commonUtilService.translateMessage('OKAY'),
btnClass: 'sb-btn sb-btn-sm sb-btn-outline-info'
},
],
sbPopoverContent: this.commonUtilService.translateMessage('ACCOUNT_MERGE_SUCCESS_POPOVER_CONTENT'),
},
cssClass: 'sb-popover'
});
await successPopover.present();
}),
finalize(() => {
if (loader) {
loader.dismiss();
}
})
).subscribe();
}
handleBackButton() {
this.backButtonFunc = this.platform.backButton.subscribeWithPriority(10, () => {
this.telemetryGeneratorService.generateBackClickedTelemetry(PageId.SETTINGS, Environment.SETTINGS, false);
this.location.back();
this.backButtonFunc.unsubscribe();
});
}
async debugModeToggle() {
if (this.debugmode) {
const confirm = await this.popoverCtrl.create({
component: SbPopoverComponent,
componentProps: {
sbPopoverHeading: this.commonUtilService.translateMessage('DEBUG_MODE'),
sbPopoverMainTitle: this.commonUtilService.translateMessage('DEBUG_ENABLE', { '%appName': this.appName }),
actionsButtons: [
{
btntext: this.commonUtilService.translateMessage('DISMISS'),
btnClass: 'popover-color popover-button-cancel'
},
{
btntext: this.commonUtilService.translateMessage('DEBUG_ON'),
btnClass: 'popover-color popover-button-allow'
},
],
icon: null,
handler: (selectedButton: string) => {
console.log(selectedButton);
if (selectedButton === this.commonUtilService.translateMessage('DISMISS')) {
this.debugmode = false;
} else if (selectedButton === this.commonUtilService.translateMessage('DEBUG_ON')) {
this.preferences.putString('debug_started_at', new Date().getTime().toString()).toPromise();
this.observeDebugging();
this.commonUtilService.showToast('DEBUG_ON_MESSAGE');
}
}
// metaInfo: this.content.contentData.name,
},
cssClass: 'sb-popover dw-active-downloads-popover',
});
await confirm.present();
} else {
const confirm = await this.popoverCtrl.create({
component: SbPopoverComponent,
componentProps: {
sbPopoverHeading: this.commonUtilService.translateMessage('DEBUG_MODE'),
sbPopoverMainTitle: this.commonUtilService.translateMessage('DEBUG_DISABLE'),
actionsButtons: [
{
btntext: this.commonUtilService.translateMessage('DISMISS'),
btnClass: 'popover-color popover-button-cancel'
},
{
btntext: this.commonUtilService.translateMessage('DEBUG_OFF'),
btnClass: 'popover-color popover-button-allow'
},
],
icon: null,
handler: (selectedButton: string) => {
console.log(selectedButton);
if (selectedButton === this.commonUtilService.translateMessage('DISMISS')) {
this.debugmode = true;
} else if (selectedButton === this.commonUtilService.translateMessage('DEBUG_OFF')) {
this.debugginService.disableDebugging().subscribe((response) => {
if (response) {
this.commonUtilService.showToast('DEBUG_OFF_MESSAGE');
this.debugmode = false;
}
});
}
}
},
cssClass: 'sb-popover dw-active-downloads-popover',
});
await confirm.present();
}
}
async observeDebugging() {
this.debugginService.enableDebugging().subscribe((isDebugMode) => {
console.log('Debug Mode', isDebugMode);
if (isDebugMode) {
this.debugmode = true;
} else if (!isDebugMode) {
this.debugmode = false;
}
});
}
isOptionEnabled() {
if(this.platform.is('ios')) {
return false;
}
return true;
}
}
<ion-content>
<ion-list mode="ios">
<ion-item class="PT2 PB2" (click)="dataSync()" role="button" detail>
<ion-label>
<p class="setting-label">{{ 'DATA_SYNC' | translate }}</p>
<p class="settings-item-style">{{ 'DATA_SYNC_SUB' | translate }}</p>
</ion-label>
</ion-item>
<ion-item class="PT2 PB2" (click)="showPermissionPage()" role="button" detail *ngIf="!platform.is('ios')">
<ion-label>
<p class="setting-label">{{'PERMISSION' | translate}}</p>
</ion-label>
</ion-item>
<ion-item class="PT2 PB2" (click)="shareApp()" role="button" detail *ngIf="!platform.is('ios')">
<ion-label>
<p class="setting-label">{{ shareAppLabel }}</p>
</ion-label>
</ion-item>
<ion-item class="PT2 PB2" *ngIf="(isUserLoggedIn$ | async) && (isNotDefaultChannelProfile$ | async)"
(click)="showMergeAccountConfirmationPopup()" role="button" detail>
<ion-label>
<p class="setting-label">{{ 'MERGE_ACCOUNT' | translate }}</p>
</ion-label>
</ion-item>
<ion-item class="PT2 PB2" (click)="aboutUs()" role="button" detail>
<ion-label>
<p class="setting-label">{{ 'ABOUT_US' | translate }}</p>
</ion-label>
</ion-item>
<ion-item class="PT2 PB2" (click)="debugModeToggle()" role="button">
<ion-label>
<p class="setting-label">Debug Mode</p>
</ion-label>
<ion-toggle [(ngModel)]="debugmode"></ion-toggle>
</ion-item>
</ion-list>
</ion-content>
./settings.page.scss
.settings-item-style {
padding-top:5px;
}
ion-icon{
font-size: 1.375rem !important;
font-weight: 550 !important;
}
.item-ios h2 {
line-height: 1.7;
}
.setting-label {
font-size: 1.125rem;
color: var(--app-light-gray) !important;
}