Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wearos #168

Merged
merged 8 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="ep2.vypal.me" />
<data android:scheme="https" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
11 changes: 10 additions & 1 deletion lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@
try {
Response resp = await data.dio.get(
"${data.baseUrl}/validate-token",
options: Options(headers: {"Authorization": "Bearer $token"}),
options: Options(
headers: {"Authorization": "Bearer $token"},
validateStatus: (status) {
return status == 200 || status == 401;

Check warning on line 268 in lib/api.dart

View check run for this annotation

Codecov / codecov/patch

lib/api.dart#L265-L268

Added lines #L265 - L268 were not covered by tests
},
),
);

if (resp.data['success'] != true) {
Expand Down Expand Up @@ -401,6 +406,10 @@
return timetables[dateOnly]!;
}

if (data.user.token == "") {
return TimeTableData(date, [], []);
}

Response response = await data.dio.get(
"${data.baseUrl}/api/timetable?to=${DateFormat('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'en_US').format(DateTime(date.year, date.month, date.day))}&from=${DateFormat('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'en_US').format(DateTime(date.year, date.month, date.day))}",
options: Options(
Expand Down
4 changes: 2 additions & 2 deletions lib/create_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@
leading: const Icon(Icons.drag_handle_rounded),
trailing: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<
backgroundColor: WidgetStateProperty.all<

Check warning on line 256 in lib/create_message.dart

View check run for this annotation

Codecov / codecov/patch

lib/create_message.dart#L256

Added line #L256 was not covered by tests
Color>(
const Color.fromARGB(255, 152, 1, 29)),
foregroundColor:
MaterialStateProperty.all<Color>(
WidgetStateProperty.all<Color>(

Check warning on line 260 in lib/create_message.dart

View check run for this annotation

Codecov / codecov/patch

lib/create_message.dart#L260

Added line #L260 was not covered by tests
Colors.white),
),
child: const Icon(Icons.delete_rounded),
Expand Down
2 changes: 1 addition & 1 deletion lib/grades.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
children: <Widget>[messages],
)
: Text(AppLocalizations.of(context)!.loading),
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,

Check warning on line 50 in lib/grades.dart

View check run for this annotation

Codecov / codecov/patch

lib/grades.dart#L50

Added line #L50 was not covered by tests
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ class HomePageState extends BaseState<HomePage> {
height: 50,
margin: const EdgeInsets.only(left: 20, right: 20, top: 10),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceVariant,
color: theme.colorScheme.surfaceContainerHighest,
border: Border.all(
color: theme.colorScheme.background,
color: theme.colorScheme.surface,
),
borderRadius: BorderRadiusDirectional.circular(25),
),
Expand Down Expand Up @@ -617,7 +617,7 @@ class HomePageState extends BaseState<HomePage> {
),
],
),
backgroundColor: theme.colorScheme.background,
backgroundColor: theme.colorScheme.surface,
drawer: Drawer(
child: ListView(
children: [
Expand Down
2 changes: 1 addition & 1 deletion lib/homework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HomeworkPageState extends BaseState<HomeworkPage> {
children: <Widget>[messages],
)
: Text(AppLocalizations.of(context)!.loading),
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_cs.arb
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,7 @@
"createMessageNewPollOptionPlaceholder": "Nová možnost",
"createMessageErrorSelectRecipient": "Vyberte prosím příjemce",
"createMessageErrorNoMessage": "Napište prosím zprávu",
"createMessageSend": "Odeslat"
"createMessageSend": "Odeslat",
"qrLoginPleaseLogin": "EduPage2 QR Přihlášení",
"qrLoginUseExistingCredentials": "Chystáte se přihlásit pomocí QR kódu"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@
"createMessageNewPollOptionPlaceholder": "New option",
"createMessageErrorSelectRecipient": "Please select a recipient",
"createMessageErrorNoMessage": "Please write a message",
"createMessageSend": "Send"
"createMessageSend": "Send",
"qrLoginPleaseLogin": "EduPage2 QR Login",
"qrLoginUseExistingCredentials": "You are about to login to EduPage2 using a QR code"
}
2 changes: 1 addition & 1 deletion lib/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class LoinPageState extends BaseState<LoginPage> {
Navigator.pop(context),
},
style: ButtonStyle(
elevation: MaterialStateProperty.all(3),
elevation: WidgetStateProperty.all(3),
),
child: Text(local!.loginLogin),
),
Expand Down
32 changes: 32 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'dart:async';

import 'package:app_links/app_links.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:eduapge2/api.dart';
import 'package:eduapge2/homework.dart';
import 'package:eduapge2/icanteen.dart';
import 'package:eduapge2/load.dart';
import 'package:eduapge2/messages.dart';
import 'package:eduapge2/qrlogin.dart';
import 'package:eduapge2/timetable.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
Expand Down Expand Up @@ -53,6 +57,8 @@
}
}

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

Check warning on line 60 in lib/main.dart

View check run for this annotation

Codecov / codecov/patch

lib/main.dart#L60

Added line #L60 was not covered by tests

class MyApp extends StatelessWidget {
const MyApp({super.key});

Expand All @@ -78,6 +84,7 @@
return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) {
return MaterialApp(
title: 'EduPage2',
navigatorKey: navigatorKey,

Check warning on line 87 in lib/main.dart

View check run for this annotation

Codecov / codecov/patch

lib/main.dart#L87

Added line #L87 was not covered by tests
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
navigatorObservers: [SentryNavigatorObserver(), observer],
Expand Down Expand Up @@ -107,6 +114,9 @@
int _selectedIndex = 0;
String baseUrl = FirebaseRemoteConfig.instance.getString("testUrl");

late AppLinks _appLinks;
StreamSubscription<Uri>? _linkSubscription;

bool loaded = false;

bool error = false; //for error status
Expand All @@ -125,6 +135,28 @@
setOptimalDisplayMode();
if (!_isCheckingForUpdate) _checkForUpdate(); // ik that it's not necessary
super.initState();
initDeepLinks();
}

@override
void dispose() {
_linkSubscription?.cancel();
super.dispose();
}

Future<void> initDeepLinks() async {
_appLinks = AppLinks();

_linkSubscription = _appLinks.uriLinkStream.listen((uri) {
if (uri.path.startsWith('/l/')) {
final code = uri.pathSegments[1];
navigatorKey.currentState?.push(MaterialPageRoute(
builder: (context) => QRLoginPage(

Check warning on line 154 in lib/main.dart

View check run for this annotation

Codecov / codecov/patch

lib/main.dart#L151-L154

Added lines #L151 - L154 were not covered by tests
code: code,
),
));
}
});
}

Future<void> setOptimalDisplayMode() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class MessagePageState extends BaseState<MessagePage> {
children: <Widget>[messages],
)
: Text(AppLocalizations.of(context)!.loading),
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class TimeTablePageState extends BaseState<MessagesPage> {
children: <Widget>[messages],
)
: Text(AppLocalizations.of(context)!.loading),
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
Expand Down
178 changes: 178 additions & 0 deletions lib/qrlogin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import 'package:dio/dio.dart';
import 'package:eduapge2/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class QRLoginPage extends StatefulWidget {
final String code;
const QRLoginPage({super.key, required this.code});

Check warning on line 10 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L10

Added line #L10 was not covered by tests

@override
BaseState<StatefulWidget> createState() => QRLoinPageState();

Check warning on line 13 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L12-L13

Added lines #L12 - L13 were not covered by tests
}

class QRLoinPageState extends BaseState<QRLoginPage> {
AppLocalizations? local;
late SharedPreferences sharedPreferences;
bool _useCustomEndpoint = false;
bool showPassword = false;

TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController serverController = TextEditingController();
TextEditingController customEndpointController = TextEditingController();

@override

Check warning on line 27 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L27

Added line #L27 was not covered by tests
void initState() {
getPrefs();
super.initState();

Check warning on line 30 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L29-L30

Added lines #L29 - L30 were not covered by tests
}

@override

Check warning on line 33 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L33

Added line #L33 was not covered by tests
void setState(VoidCallback fn) {
if (!mounted) return;
super.setState(fn);

Check warning on line 36 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L35-L36

Added lines #L35 - L36 were not covered by tests
}

Future<void> getPrefs() async {
sharedPreferences = await SharedPreferences.getInstance();
String? sEmail = sharedPreferences.getString("email");
String? sPassword = sharedPreferences.getString("password");
String? sServer = sharedPreferences.getString("server");
String? sEndpoint = sharedPreferences.getString("customEndpoint");

Check warning on line 44 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L39-L44

Added lines #L39 - L44 were not covered by tests

if (sEmail != null) {
emailController.text = sEmail;

Check warning on line 47 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L47

Added line #L47 was not covered by tests
}
if (sPassword != null) {
passwordController.text = sPassword;

Check warning on line 50 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L50

Added line #L50 was not covered by tests
}
if (sServer != null) {
serverController.text = sServer;

Check warning on line 53 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L53

Added line #L53 was not covered by tests
}
if (sEndpoint != null && sEndpoint != "") {
customEndpointController.text = sEndpoint;
_useCustomEndpoint = true;

Check warning on line 57 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L55-L57

Added lines #L55 - L57 were not covered by tests
}
setState(() {});

Check warning on line 59 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L59

Added line #L59 was not covered by tests
}

@override

Check warning on line 62 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L62

Added line #L62 was not covered by tests
Widget build(BuildContext context) {
local ??= AppLocalizations.of(context);
return Center(
child: Column(

Check warning on line 66 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L64-L66

Added lines #L64 - L66 were not covered by tests
mainAxisSize: MainAxisSize.min,
children: [
Card(
child: Padding(

Check warning on line 70 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L68-L70

Added lines #L68 - L70 were not covered by tests
padding: const EdgeInsets.all(15),
child: Column(

Check warning on line 72 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L72

Added line #L72 was not covered by tests
mainAxisSize: MainAxisSize.min,
children: [
Text(
local!.qrLoginPleaseLogin,

Check warning on line 76 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L74-L76

Added lines #L74 - L76 were not covered by tests
style: const TextStyle(
fontSize: 18,
),
),
Text(local!.qrLoginUseExistingCredentials),
TextField(
controller: emailController,
decoration: InputDecoration(

Check warning on line 84 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L81-L84

Added lines #L81 - L84 were not covered by tests
icon: const Icon(Icons.email),
hintText: local!.loginUsername,

Check warning on line 86 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L86

Added line #L86 was not covered by tests
),
keyboardType: TextInputType.emailAddress,
),
TextField(
controller: passwordController,
decoration: InputDecoration(

Check warning on line 92 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L90-L92

Added lines #L90 - L92 were not covered by tests
icon: const Icon(Icons.key),
hintText: local!.loginPassword,
suffixIcon: IconButton(
icon: Icon(showPassword

Check warning on line 96 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L94-L96

Added lines #L94 - L96 were not covered by tests
? Icons.visibility
: Icons.visibility_off),
onPressed: () {
setState(() {
showPassword = !showPassword;

Check warning on line 101 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L99-L101

Added lines #L99 - L101 were not covered by tests
});
},
),
),
obscureText: !showPassword,

Check warning on line 106 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L106

Added line #L106 was not covered by tests
keyboardType: TextInputType.visiblePassword,
),
Row(
children: [
Checkbox(
value: _useCustomEndpoint,
onChanged: (value) {
setState(() {
_useCustomEndpoint = value!;

Check warning on line 115 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L109-L115

Added lines #L109 - L115 were not covered by tests
});
},
),
Text(local!.loginCustomEndpointCheckbox),

Check warning on line 119 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L119

Added line #L119 was not covered by tests
],
),
if (_useCustomEndpoint)
TextField(
controller: customEndpointController,
decoration: InputDecoration(

Check warning on line 125 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L122-L125

Added lines #L122 - L125 were not covered by tests
icon: const Icon(Icons.language),
hintText: local!.loginCustomEndpoint,

Check warning on line 127 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L127

Added line #L127 was not covered by tests
),
),
TextField(
controller: serverController,
decoration: InputDecoration(

Check warning on line 132 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L130-L132

Added lines #L130 - L132 were not covered by tests
icon: const Icon(Icons.cloud_queue),
hintText: local!.loginServer,

Check warning on line 134 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L134

Added line #L134 was not covered by tests
),
keyboardType: TextInputType.url,
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () async {
Dio dio = Dio();

Check warning on line 141 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L138-L141

Added lines #L138 - L141 were not covered by tests

var response = await dio.post(
'https://ep2.vypal.me/qrlogin/${widget.code}',
options: Options(
headers: {

Check warning on line 146 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L143-L146

Added lines #L143 - L146 were not covered by tests
Headers.contentTypeHeader:
Headers.formUrlEncodedContentType,
},
),
data: {
'username': emailController.text,
'password': passwordController.text,
'server': serverController.text,
'endpoint': customEndpointController.text,

Check warning on line 155 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L151-L155

Added lines #L151 - L155 were not covered by tests
},
);

if (response.statusCode == 200) {
SystemNavigator.pop();

Check warning on line 160 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L159-L160

Added lines #L159 - L160 were not covered by tests
} else {
throw Exception('Failed to load data');

Check warning on line 162 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L162

Added line #L162 was not covered by tests
}
},
style: ButtonStyle(
elevation: WidgetStateProperty.all(3),

Check warning on line 166 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L165-L166

Added lines #L165 - L166 were not covered by tests
),
child: Text(local!.loginLogin),

Check warning on line 168 in lib/qrlogin.dart

View check run for this annotation

Codecov / codecov/patch

lib/qrlogin.dart#L168

Added line #L168 was not covered by tests
),
],
),
),
),
],
),
);
}
}
2 changes: 1 addition & 1 deletion lib/timetable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TimeTablePageState extends BaseState<TimeTablePage> {
context);
},
),
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
);
}
}
Expand Down
Loading
Loading