Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
small fixes and close #107
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre committed Nov 24, 2021
1 parent 5771d4a commit d91f565
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
2 changes: 2 additions & 0 deletions lib/core/utils/file_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:ynotes/core/logic/models_exporter.dart';
import 'package:ynotes/core/utils/logging_utils/logging_utils.dart';
import 'package:ynotes/core/utils/ui.dart';

///Every action related to files
class FileAppUtil {
Expand Down Expand Up @@ -94,6 +95,7 @@ class FileAppUtil {
List<FileInfo> listFiles = [];
return listFiles;
}
UIUtils.setSystemUIOverlayStyle();
return [];
}

Expand Down
89 changes: 46 additions & 43 deletions lib/ui/screens/intro/sub_pages/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:ynotes/core/apis/model.dart';
import 'package:ynotes/core/logic/app_config/controller.dart';
import 'package:ynotes/core/utils/controller_consumer.dart';
import 'package:ynotes/core/utils/kvs.dart';
import 'package:ynotes/core/utils/ui.dart';
import 'package:ynotes/globals.dart';
import 'package:ynotes/ui/components/dialogs.dart';
import 'package:ynotes_packages/components.dart';
Expand All @@ -22,6 +23,28 @@ class IntroConfigPage extends StatefulWidget {
}

class _IntroConfigPageState extends State<IntroConfigPage> {
Future<void> notificationSetting({required ApplicationSystem controller, required Function fn}) async {
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
final notificationPermission = await Permission.notification.request();
final batteryPermission = await Permission.ignoreBatteryOptimizations.request();
UIUtils.setSystemUIOverlayStyle();
if (notificationPermission.isGranted && batteryPermission.isGranted) {
fn();
appSys.saveSettings();
} else {
YDialogs.showInfo(
context,
YInfoDialog(
title: "Oups !",
body: Text("Tu n'as pas accordé à yNotes toutes les permissions nécessaires.",
style: theme.texts.body1)));
}
} else {
fn();
appSys.saveSettings();
}
}

@override
Widget build(BuildContext context) {
return YPage(
Expand All @@ -33,51 +56,31 @@ class _IntroConfigPageState extends State<IntroConfigPage> {
YSettingsSections(
sections: [
if (Platform.isAndroid || Platform.isIOS)
YSettingsSection(title: "Notifications", tiles: [
YSettingsSection(tiles: [
YSettingsTile.switchTile(
title: "Nouvelle note",
switchValue: controller.settings.user.global.notificationNewGrade,
onSwitchValueChanged: (bool value) async {
if (value == false ||
(!kIsWeb &&
(Platform.isIOS && await Permission.notification.request().isGranted) ||
(await Permission.ignoreBatteryOptimizations.isGranted))) {
controller.settings.user.global.notificationNewGrade = value;
} else {
if (await (CustomDialogs.showAuthorizationsDialog(
context,
"la configuration d'optimisation de batterie",
"Pouvoir s'exécuter en arrière plan sans être automatiquement arrêté par Android.")) ??
false) {
if (await Permission.ignoreBatteryOptimizations.request().isGranted) {
controller.settings.user.global.notificationNewGrade = value;
}
}
}
controller.saveSettings();
}),
title: "Nouvel email",
switchValue: controller.settings.user.global.notificationNewMail,
onSwitchValueChanged: (bool value) async => await notificationSetting(
controller: controller,
fn: () => controller.settings.user.global.notificationNewMail = value),
disabledOnTap: () => YSnackbars.info(context,
title: "Paramètre désactivé",
message:
"Tu as activé l'économiseur de batterie, qui désactive l'envoi de notifications."),
enabled: !controller.settings.user.global.batterySaver,
),
YSettingsTile.switchTile(
title: "Nouveau mail",
switchValue: controller.settings.user.global.notificationNewMail,
onSwitchValueChanged: (bool value) async {
if (value == false ||
(!kIsWeb &&
(Platform.isIOS && await Permission.notification.request().isGranted) ||
(await Permission.ignoreBatteryOptimizations.isGranted))) {
controller.settings.user.global.notificationNewMail = value;
} else {
if (await (CustomDialogs.showAuthorizationsDialog(
context,
"la configuration d'optimisation de batterie",
"Pouvoir s'exécuter en arrière plan sans être automatiquement arrêté par Android.")) ??
false) {
if (await Permission.ignoreBatteryOptimizations.request().isGranted) {
controller.settings.user.global.notificationNewMail = value;
}
}
}
controller.saveSettings();
})
title: "Nouvelle note",
switchValue: controller.settings.user.global.notificationNewGrade,
onSwitchValueChanged: (bool value) async => await notificationSetting(
controller: controller,
fn: () => controller.settings.user.global.notificationNewGrade = value),
disabledOnTap: () => YSnackbars.info(context,
title: "Paramètre désactivé",
message:
"Tu as activé l'économiseur de batterie, qui désactive l'envoi de notifications."),
enabled: !controller.settings.user.global.batterySaver,
)
]),
YSettingsSection(title: "Divers", tiles: [
if (controller.account!.isParentMainAccount)
Expand Down
1 change: 0 additions & 1 deletion lib/ui/screens/terms/terms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class TermsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return YPage(
showScrollbar: !Platform.isWindows,
appBar: const YAppBar(title: "Termes et conditions", removeLeading: true),
body: Padding(
padding: EdgeInsets.fromLTRB(YScale.s2, YScale.s2, Platform.isWindows ? YScale.s4 : YScale.s2, YScale.s2),
Expand Down

0 comments on commit d91f565

Please sign in to comment.