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

Fix and improvements #19

Merged
merged 10 commits into from
Dec 11, 2022
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
1,301 changes: 1,301 additions & 0 deletions assets/therms/cgu.html

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions lib/src/api/assos_utc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:dio/dio.dart';

class AssosUTC {
//dio get https://assos.utc.fr/api/v1/semesters
static Future<List<Semester>> getSemesters() async {
final response = await Dio().get('https://assos.utc.fr/api/v1/semesters');
if (response.statusCode == 200) {
return (response.data as List)
.map<Semester>((e) => Semester.fromJson(e))
.toList();
} else {
throw Exception('Failed to load semesters');
}
}
}

//{
// "id": "052f21d0-6c88-11ec-9f69-2306293b178e",
// "name": "A22",
// "is_spring": false,
// "begin_at": "2022-09-01 00:00:00",
// "end_at": "2023-01-31 23:59:59"
// }
class Semester {
final String id;
final String name;
final bool isSpring;
final DateTime beginAt;
final DateTime endAt;

Semester({
required this.id,
required this.name,
required this.isSpring,
required this.beginAt,
required this.endAt,
});

factory Semester.fromJson(Map<String, dynamic> json) {
return Semester(
id: json['id'],
name: json['name'],
isSpring: json['is_spring'],
beginAt: DateTime.parse(json['begin_at']),
endAt: DateTime.parse(json['end_at']),
);
}
}
8 changes: 6 additions & 2 deletions lib/src/services/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';

import 'package:dio/dio.dart';

import 'package:payutc/src/api/assos_utc.dart';
import 'package:payutc/src/api/cas.dart';
import 'package:payutc/src/api/ginger.dart';
import 'package:payutc/src/api/nemopay.dart';
Expand Down Expand Up @@ -60,14 +61,17 @@ class AppService extends ChangeNotifier {

Owner get user => userWallet!.user;

List<Semester> semesters = [];

Future<bool> initApp() async {
await storageService.init();
if (await isFirstConnect) return false;
UserData d = (await storageService.userData)!;
UserData? d = (await storageService.userData);
if (await isFirstConnect || d == null) return false;
userName = await (d.isCas ? _casConnect() : _classicConnect());
appProperties = await nemoPayApi.getAppProperties();
await walletService.forceLoad();
await historyService.forceLoadHistory();
semesters = await AssosUTC.getSemesters();
return true;
}

Expand Down
26 changes: 19 additions & 7 deletions lib/src/ui/component/payutc_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,19 @@ class PayUtcItemWidget extends StatelessWidget {
s,
style: const TextStyle(color: Colors.white),
),
Text(
t,
style: const TextStyle(color: Colors.white),
const SizedBox(
width: 10,
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text(
t,
style: const TextStyle(color: Colors.white),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
],
);
Expand Down Expand Up @@ -132,16 +142,18 @@ class PayUtcItemWidget extends StatelessWidget {
),
_row("Montant", item.amountParse.toStringAsFixed(2)),
_row("Dénomination", item.nameExtracted(context)),
_row("Service", item.service(context)),
if (!item.isVirement)
_row("Service", item.service(context)),
_row("Date", DateFormat("dd/MM/yyyy").format(item.date)),
_row("Heure", DateFormat("HH:mm").format(item.date)),
const SizedBox(
height: 10,
),
if (item.isVirement) ...[
const Text(
"Message",
style: TextStyle(color: Colors.white, fontSize: 18),
Text(
"${item.userVirName} a écrit :",
style:
const TextStyle(color: Colors.white, fontSize: 18),
),
const SizedBox(
height: 5,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/ui/screen/account_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ class _AccountPageState extends State<AccountPage> {
Translate.of(context).nousContacter,
() {
launchUrlString(
"mailto:payutc@assos.utc.fr?subject=[App]&body=Bonjour,\n");
"mailto:payutc@assos.utc.fr?subject=[App]&body=Bonjour,\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je suis pas fan des mails avec du texte pré-écrit si c'est pas pour une bonne raison en vrai.
A la limite tu pourrais ptet caler des infos utiles comme la version de l'app, le login de la personne etc ?

mode: LaunchMode.externalApplication,
);
},
),
if (showLogConsole)
Expand Down
7 changes: 4 additions & 3 deletions lib/src/ui/screen/home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:skeletons/skeletons.dart';

import 'package:payutc/generated/l10n.dart';
import 'package:payutc/src/services/app.dart';
import 'package:payutc/src/services/history.dart';
Expand All @@ -12,8 +15,6 @@ import 'package:payutc/src/ui/screen/stats.dart';
import 'package:payutc/src/ui/screen/transfert_select_amount.dart';
import 'package:payutc/src/ui/style/color.dart';
import 'package:payutc/src/ui/style/theme.dart';
import 'package:skeletons/skeletons.dart';

import '../component/rounded_icon.dart';
import 'account_screen.dart';
import 'receive.dart';
Expand Down Expand Up @@ -146,7 +147,7 @@ class _HomePageState extends State<HomePage>
children: [
Text(
AppService.instance.translateMoney(
(AppService.instance.userWallet?.credit ??
(historyController.history?.credit ??
00) /
100),
style: const TextStyle(
Expand Down
89 changes: 81 additions & 8 deletions lib/src/ui/screen/reload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:url_launcher/url_launcher_string.dart';
import 'package:webview_flutter/webview_flutter.dart';

import 'package:payutc/generated/l10n.dart';
import 'package:payutc/src/env.dart';
import 'package:payutc/src/services/app.dart';
import 'package:payutc/src/ui/screen/select_amount.dart';
import 'package:payutc/src/ui/style/color.dart';

class PaymentFlowPage extends StatefulWidget {
final double amount;
Expand Down Expand Up @@ -50,6 +52,27 @@ class PaymentFlowPage extends StatefulWidget {
}

class _PaymentFlowPageState extends State<PaymentFlowPage> {
String? _url, _error;

@override
void initState() {
AppService.instance.nemoPayApi
.requestTransfertUrl(widget.amount)
.then((value) => setState(() {
_url = value;
if (mounted) {
setState(() {});
}
}))
.catchError((e) {
_error = "Une erreur est survenue";
if (mounted) {
setState(() {});
}
});
super.initState();
}

@override
Widget build(BuildContext context) {
return WillPopScope(
Expand Down Expand Up @@ -82,11 +105,50 @@ class _PaymentFlowPageState extends State<PaymentFlowPage> {
elevation: 0,
iconTheme: const IconThemeData(color: Colors.white),
systemOverlayStyle: SystemUiOverlayStyle.light,
actions: [
if (_url != null)
IconButton(
icon: const Icon(Icons.open_in_new),
onPressed: () => showDialog(
context: context,
builder: (_) {
return AlertDialog(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
title: const Text("Ouvrir dans le navigateur"),
content: const Text(
"Tu n'arrive pas à accéder à la page ou au "
"paiement ? Tu peux essayer d'ouvrir la page dans "
"un navigateur. (Il faudra ensuite revenir sur l'application)",
style: TextStyle(fontSize: 12),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text("Annuler"),
),
TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.black54),
onPressed: () {
Navigator.pop(context, true);
Navigator.pop(context, true);
launchUrlString(_url!,
mode: LaunchMode.externalApplication);
},
child: const Text("Passer par le navigateur"),
),
],
);
},
),
),
],
),
backgroundColor: Colors.black,
body: FutureBuilder<String>(
future: AppService.instance.nemoPayApi
.requestTransfertUrl(widget.amount),
body: FutureBuilder<String?>(
future: Future.value(_url),
builder: (context, snapshot) {
if (snapshot.data != null) {
return ClipRRect(
Expand All @@ -108,13 +170,24 @@ class _PaymentFlowPageState extends State<PaymentFlowPage> {
)),
);
}
if (!snapshot.hasData &&
snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
if (_error != null) {
return Center(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
),
padding: const EdgeInsets.all(16),
child: Text(
"$_error",
style: const TextStyle(color: AppColors.red),
),
),
);
}
return const SizedBox();
return const Center(
child: CircularProgressIndicator(),
);
}),
),
);
Expand Down
27 changes: 26 additions & 1 deletion lib/src/ui/screen/splash.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand All @@ -11,6 +12,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:payutc/compil.dart';
import 'package:payutc/generated/l10n.dart';
import 'package:payutc/src/services/app.dart';
import 'package:payutc/src/ui/component/ui_utils.dart';
import 'package:payutc/src/ui/screen/home.dart';
import 'package:payutc/src/ui/style/color.dart';

Expand Down Expand Up @@ -54,7 +56,7 @@ class _SplashPageState extends State<SplashPage> {
height: 30,
),
const Text(
"Pay'ut",
"Pay'UTC",
style: TextStyle(color: Colors.white, fontSize: 30),
),
const SizedBox(
Expand Down Expand Up @@ -287,6 +289,21 @@ class _LoginPageState extends State<LoginPage> {
const SizedBox(
height: 5,
),
Text.rich(
TextSpan(
text: Translate.of(context).connect_mention_legs,
children: [
TextSpan(
text:
" ${Translate.of(context).mentionsLgales}",
style: const TextStyle(
color: AppColors.orange,
),
recognizer: TapGestureRecognizer()
..onTap = _mentionsLeg)
],
),
),
],
),
),
Expand All @@ -299,6 +316,14 @@ class _LoginPageState extends State<LoginPage> {
);
}

void _mentionsLeg() {
showWebView(
context,
"assets/therms/cgu.html",
Translate.of(context).mentionsLgales,
);
}

void _connect(BuildContext context) async {
if (!Form.of(context)!.validate()) return;
setState(() {
Expand Down
Loading