feat: allow user to hide exit app alert

This commit is contained in:
Tom Fong 2022-11-24 11:01:07 +08:00
parent c1c8a2171e
commit 04949d2bf9
5 changed files with 65 additions and 40 deletions

View file

@ -1,5 +1,6 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { Preferences } from '@capacitor/preferences';
import { AlertController, IonRouterOutlet, Platform } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { EnvService } from 'src/app/services/env.service';
@ -50,10 +51,26 @@ export class LandingPage {
}
async confirmExitApp(): Promise<void> {
if (this.env.showExitAppAlert == "on") {
const alert = await this.alertController.create({
header: this.translate.instant('EXIT_APP'),
message: this.translate.instant('MSG.EXIT_APP'),
cssClass: ['alert-bg'],
inputs: [
{
type: "checkbox",
label: this.translate.instant("MSG.TUTORIAL_NOT_SHOW_AGAIN"),
checked: false,
handler: async (result) => {
if (result.checked) {
this.env.showExitAppAlert = "off";
} else {
this.env.showExitAppAlert = "on";
}
await Preferences.set({ key: this.env.KEY_SHOW_EXIT_APP_ALERT, value: this.env.showExitAppAlert });
}
}
],
cssClass: ['alert-bg', 'alert-input-no-border'],
buttons: [
{
text: this.translate.instant('EXIT'),
@ -70,6 +87,9 @@ export class LandingPage {
]
});
await alert.present();
} else {
navigator['app'].exitApp();
}
}
}

View file

@ -134,7 +134,7 @@
</ion-label>
</ion-item>
<ion-item *ngIf="isAndroid" class="ion-no-padding ripple-parent" detail="false" lines="none"
(click)="confirmExitApp()">
(click)="exitApp()">
<ion-icon class="ion-margin-start ion-padding-horizontal" color="danger" name="exit"></ion-icon>
<ion-label>
<p class="ion-padding pre-line">

View file

@ -127,28 +127,9 @@ export class SettingPage {
alert.present();
}
async confirmExitApp(): Promise<void> {
const alert = await this.alertController.create({
header: this.translate.instant('EXIT_APP'),
message: this.translate.instant('MSG.EXIT_APP'),
cssClass: ['alert-bg'],
buttons: [
{
text: this.translate.instant('EXIT'),
handler: () => {
exitApp() {
navigator['app'].exitApp();
}
},
{
text: this.translate.instant('RATE_THE_APP'),
handler: () => {
this.openGooglePlay();
}
}
]
});
await alert.present();
}
openGooglePlay(): void {
window.open(this.env.GOOGLE_PLAY_URL, '_system');

View file

@ -75,6 +75,7 @@ export class EnvService {
public showSendMessageButton: OnOffType = 'on';
public showSendEmailButton: OnOffType = 'on';
public showOpenFoodFactsButton: OnOffType = 'on';
public showExitAppAlert: OnOffType = "on";
public debugMode: OnOffType = 'off';
public autoExitAppMin: 1 | 3 | 5 | -1 = -1;
@ -86,6 +87,7 @@ export class EnvService {
public readonly KEY_LANGUAGE = "language";
public readonly KEY_COLOR = "color";
public readonly KEY_DEBUG_MODE = "debug-mode-on";
public readonly KEY_SHOW_EXIT_APP_ALERT = "showExitAppAlert";
public readonly KEY_ORIENTATION = "orientation";
public readonly KEY_SCAN_RECORD_LOGGING = "scan-record-logging";
public readonly KEY_RECORDS_LIMIT = "recordsLimit";
@ -852,6 +854,15 @@ export class EnvService {
await this.toggleColorTheme();
}
);
await Preferences.get({ key: this.KEY_SHOW_EXIT_APP_ALERT }).then(
async result => {
if (result.value != null) {
this.showExitAppAlert = result.value as OnOffType;
} else {
this.showExitAppAlert = 'on';
}
}
);
await Preferences.get({ key: this.KEY_DEBUG_MODE }).then(
async result => {
if (result.value != null) {
@ -1216,6 +1227,7 @@ export class EnvService {
this.showOpenFoodFactsButton = 'on';
this.scanRecords = [];
this.bookmarks = [];
this.showExitAppAlert = 'on';
this.debugMode = 'off';
this.autoExitAppMin = -1;
}
@ -1349,6 +1361,9 @@ export class EnvService {
this.showOpenFoodFactsButton = 'on';
await Preferences.set({ key: this.KEY_SHOW_OPEN_FOOD_FACTS_BUTTON, value: this.showOpenFoodFactsButton });
this.showExitAppAlert = 'on';
await Preferences.set({ key: this.KEY_SHOW_EXIT_APP_ALERT, value: this.showExitAppAlert });
this.debugMode = 'off';
await Preferences.set({ key: this.KEY_DEBUG_MODE, value: this.debugMode });

View file

@ -109,6 +109,15 @@ ion-tab-button:not(.tab-selected)::part(native):hover {
opacity: 0.5;
}
.alert-input-no-border .alert-checkbox-group {
border: 0px !important;
}
.alert-input-no-border .alert-checkbox-label {
overflow: auto !important;
white-space: pre-line !important;
}
.alert-can-copy {
user-select: text !important;
}