Skip to content

Commit

Permalink
Merge pull request #689 from hpi-studyu/fix/debugscreen
Browse files Browse the repository at this point in the history
fix: Improve Debug Screen
  • Loading branch information
johannesvedder authored Sep 10, 2024
2 parents aa643cc + 28340f4 commit 44e3bb2
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 110 deletions.
10 changes: 8 additions & 2 deletions app/lib/screens/app_onboarding/loading_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:studyu_app/screens/app_onboarding/preview.dart';
import 'package:studyu_app/screens/study/onboarding/eligibility_screen.dart';
import 'package:studyu_app/screens/study/tasks/task_screen.dart';
import 'package:studyu_app/util/cache.dart';
import 'package:studyu_app/util/schedule_notifications.dart';
import 'package:studyu_core/core.dart';
import 'package:studyu_flutter_common/studyu_flutter_common.dart';

Expand Down Expand Up @@ -39,7 +40,7 @@ class _LoadingScreenState extends State<LoadingScreen> {
if (!mounted) return;

if (selectedSubjectId == null) {
Navigator.pushReplacementNamed(context, Routes.welcome);
await noSubjectFound();
return;
}
StudySubject? subject = await _retrieveSubject(selectedSubjectId);
Expand All @@ -51,10 +52,15 @@ class _LoadingScreenState extends State<LoadingScreen> {
state.init(context);
Navigator.pushReplacementNamed(context, Routes.dashboard);
} else {
Navigator.pushReplacementNamed(context, Routes.welcome);
await noSubjectFound();
}
}

Future<void> noSubjectFound() async {
await cancelNotifications(context);
if (mounted) Navigator.pushReplacementNamed(context, Routes.welcome);
}

Future<StudySubject?> _fetchRemoteSubject(String selectedStudyObjectId) {
return SupabaseQuery.getById<StudySubject>(
selectedStudyObjectId,
Expand Down
13 changes: 9 additions & 4 deletions app/lib/screens/app_onboarding/welcome.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';

import 'package:studyu_app/routes.dart';
import 'package:studyu_app/util/debug_screen.dart';

class WelcomeScreen extends StatelessWidget {
const WelcomeScreen({super.key});
Expand All @@ -16,9 +16,14 @@ class WelcomeScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Spacer(),
const Image(
image: AssetImage('assets/icon/logo.png'),
height: 200,
GestureDetector(
onDoubleTap: () {
DebugScreen.showDebugScreen(context);
},
child: const Image(
image: AssetImage('assets/icon/logo.png'),
height: 200,
),
),
const SizedBox(height: 20),
OutlinedButton.icon(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/screens/study/dashboard/contact_tab/faq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ final data_de = <Entry>[
],
),
Entry(
'das Studium',
'Die Studie',
<Entry>[
Entry(
'Wie lange dauert es, bis die Studie abgeschlossen ist?',
Expand Down
64 changes: 2 additions & 62 deletions app/lib/screens/study/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:studyu_app/models/app_state.dart';
import 'package:studyu_app/routes.dart';
import 'package:studyu_app/screens/study/dashboard/task_overview_tab/task_overview.dart';
import 'package:studyu_app/screens/study/report/report_details.dart';
import 'package:studyu_app/util/notifications.dart';
import 'package:studyu_app/util/schedule_notifications.dart';
import 'package:studyu_app/util/debug_screen.dart';
import 'package:studyu_core/core.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -90,10 +88,6 @@ class _DashboardScreenState extends State<DashboardScreen>
super.dispose();
}

Future<bool> receivePermission() async {
return await Permission.ignoreBatteryOptimizations.request().isGranted;
}

@override
Widget build(BuildContext context) {
if (subject == null) {
Expand Down Expand Up @@ -170,61 +164,7 @@ class _DashboardScreenState extends State<DashboardScreen>
context: context,
applicationIcon: GestureDetector(
onDoubleTap: () {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: const SelectableText(
'Notification Log',
),
content: Column(
children: [
ElevatedButton(
onPressed: () {
final Uri emailLaunchUri = Uri(
scheme: 'mailto',
path: subject!.study.contact.email,
queryParameters: {
'subject':
'[StudyU] Debug Information',
'body': StudyNotifications
.scheduledNotificationsDebug,
},
);
launchUrl(emailLaunchUri);
},
// text color is white, so we need to set the background color to black
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).primaryColor,
),
child: const Text('Send via email'),
),
FutureBuilder<bool>(
future: receivePermission(),
builder: (
context,
AsyncSnapshot<bool> snapshot,
) {
if (snapshot.hasData) {
final String data =
"ignoreBatteryOptimizations: ${snapshot.data}";
return Text(data);
} else {
return const CircularProgressIndicator();
}
},
),
SelectableText(
StudyNotifications
.scheduledNotificationsDebug ??
'No data',
),
],
),
scrollable: true,
),
);
testNotifications(context);
DebugScreen.showDebugScreen(context);
},
child: const Image(
image: AssetImage('assets/icon/icon.png'),
Expand Down
19 changes: 1 addition & 18 deletions app/lib/screens/study/dashboard/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
Expand All @@ -9,6 +8,7 @@ import 'package:studyu_app/models/app_state.dart';
import 'package:studyu_app/routes.dart';
import 'package:studyu_app/util/app_analytics.dart';
import 'package:studyu_app/util/localization.dart';
import 'package:studyu_app/util/schedule_notifications.dart';
import 'package:studyu_core/core.dart';
import 'package:studyu_flutter_common/studyu_flutter_common.dart';

Expand Down Expand Up @@ -237,20 +237,3 @@ class DeleteAlertDialog extends StatelessWidget {
],
);
}

Future<void>? cancelNotifications(BuildContext context) {
if (kIsWeb) return Future.value(); // Notifications not supported on web
final appState = context.read<AppState>();
final studyNotifications = appState.studyNotifications;
final notificationsPlugin =
studyNotifications?.flutterLocalNotificationsPlugin;
notificationsPlugin?.cancelAll();
if (kDebugMode) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('DEBUG: Notifications cancelled'),
),
);
}
return Future.value();
}
Loading

0 comments on commit 44e3bb2

Please sign in to comment.