summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/config/defaults.dart2
-rw-r--r--lib/main.dart4
-rw-r--r--lib/pages/delivery_login_page.dart79
-rw-r--r--lib/pages/developer_page.dart6
-rw-r--r--lib/pages/home_page.dart9
-rw-r--r--lib/services/authentication_service.dart10
-rw-r--r--lib/services/local_shift_provider_service.dart21
-rw-r--r--lib/widgets/agenda_week_item.dart6
8 files changed, 120 insertions, 17 deletions
diff --git a/lib/config/defaults.dart b/lib/config/defaults.dart
index cee6ed2..9c3855f 100644
--- a/lib/config/defaults.dart
+++ b/lib/config/defaults.dart
@@ -1,4 +1,4 @@
-String program_version = '0.3.0';
+String program_version = '0.4';
bool debug_output = false;
class ShiftType {
diff --git a/lib/main.dart b/lib/main.dart
index a944760..5282c68 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -5,6 +5,7 @@ import 'package:event_bus/event_bus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
+import 'package:training_planner/services/authentication_service.dart';
import 'package:training_planner/services/iroute_provider_service.dart';
import 'package:training_planner/services/ishift_provider_service.dart';
import 'package:training_planner/services/log_service.dart';
@@ -52,7 +53,8 @@ void _initializeHERESDK() async {
final IRouteProviderService routeProvider = MockRouteProviderService();
final IProgramProviderService shiftProvider = LocalShiftProviderService();
-final LocalAuthentication auth = LocalAuthentication();
+final LocalAuthentication localAuthService = LocalAuthentication();
+final AuthenticationService remoteAuthService = AuthenticationService();
final MessagingService messageService = MessagingService();
final SettingsService settingsService = SettingsService();
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
diff --git a/lib/pages/delivery_login_page.dart b/lib/pages/delivery_login_page.dart
new file mode 100644
index 0000000..1724ba2
--- /dev/null
+++ b/lib/pages/delivery_login_page.dart
@@ -0,0 +1,79 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:training_planner/pages/agenda_page.dart';
+import 'package:training_planner/pages/developer_page.dart';
+import 'package:training_planner/pages/logbook_page.dart';
+import 'package:training_planner/pages/navigation_page.dart';
+import 'package:training_planner/pages/settings_page.dart';
+import 'package:training_planner/shift.dart';
+import 'package:training_planner/main.dart';
+import 'package:training_planner/style/style.dart';
+
+class DeliveryLoginPage extends StatefulWidget {
+ @override
+ _DeliveryLoginPageState createState() => _DeliveryLoginPageState();
+
+ const DeliveryLoginPage({Key? key}) : super(key: key);
+}
+
+class _DeliveryLoginPageState extends State<DeliveryLoginPage> {
+ final pnumberController = TextEditingController();
+ final daycodeController = TextEditingController();
+
+ @override
+ initState() {
+ super.initState();
+ }
+
+ _attemptLogin() async {
+ bool success = await remoteAuthService.authenticate(
+ pnumberController.text, daycodeController.text);
+ if (success) {
+ Navigator.push(
+ context,
+ MaterialPageRoute(builder: (context) => NavigationPage()),
+ );
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ children: [
+ Container(
+ width: 50,
+ ),
+ Expanded(
+ child: Column(
+ children: [
+ Padding(padding: EdgeInsets.all(50)),
+ TextField(
+ decoration: InputDecoration(labelText: "pnummer"),
+ keyboardType: TextInputType.number,
+ controller: pnumberController,
+ inputFormatters: <TextInputFormatter>[
+ FilteringTextInputFormatter.digitsOnly
+ ],
+ ),
+ Padding(padding: EdgeInsets.all(10)),
+ TextField(
+ decoration: InputDecoration(labelText: "dagcode"),
+ keyboardType: TextInputType.number,
+ controller: daycodeController,
+ inputFormatters: <TextInputFormatter>[
+ FilteringTextInputFormatter.digitsOnly
+ ],
+ ),
+ Padding(padding: EdgeInsets.all(10)),
+ OutlinedButton(
+ onPressed: () => _attemptLogin(), child: Text('Inloggen'))
+ ],
+ ),
+ ),
+ Container(
+ width: 50,
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/pages/developer_page.dart b/lib/pages/developer_page.dart
index 13d3c5d..b724f8c 100644
--- a/lib/pages/developer_page.dart
+++ b/lib/pages/developer_page.dart
@@ -22,8 +22,8 @@ class _DeveloperPageState extends State<DeveloperPage> {
initState() {
super.initState();
- auth.canCheckBiometrics.then((bio) => {
- auth
+ localAuthService.canCheckBiometrics.then((bio) => {
+ localAuthService
.isDeviceSupported()
.then((supported) => {canUseLocalAuth = bio && supported})
});
@@ -60,7 +60,7 @@ class _DeveloperPageState extends State<DeveloperPage> {
TextButton(
onPressed: () {
if (canUseLocalAuth) {
- auth
+ localAuthService
.authenticate(
localizedReason:
'Weet je zeker dat je alle locale bestanden wilt verwijderen?')
diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart
index 404f6cc..07fc1a8 100644
--- a/lib/pages/home_page.dart
+++ b/lib/pages/home_page.dart
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:training_planner/pages/agenda_page.dart';
+import 'package:training_planner/pages/delivery_login_page.dart';
import 'package:training_planner/pages/developer_page.dart';
import 'package:training_planner/pages/logbook_page.dart';
import 'package:training_planner/pages/navigation_page.dart';
@@ -26,7 +27,7 @@ class _HomePageState extends State<HomePage> {
_widgetOptions = <Widget>[
new AgendaPage(agendaWeekNr: widget.agendaWeekNr),
new LogbookPage(),
- new NavigationPage(),
+ new DeliveryLoginPage(),
];
super.initState();
@@ -38,7 +39,7 @@ class _HomePageState extends State<HomePage> {
_widgetOptions = <Widget>[
new AgendaPage(agendaWeekNr: widget.agendaWeekNr),
new LogbookPage(),
- new NavigationPage(),
+ new DeliveryLoginPage(),
];
_selectedIndex = index;
});
@@ -110,11 +111,11 @@ class _HomePageState extends State<HomePage> {
),
BottomNavigationBarItem(
icon: Icon(Icons.book),
- label: 'Logboek',
+ label: 'Registratie',
),
BottomNavigationBarItem(
icon: Icon(Icons.pin_drop),
- label: 'Delivery',
+ label: 'Bezorging',
),
],
currentIndex: _selectedIndex,
diff --git a/lib/services/authentication_service.dart b/lib/services/authentication_service.dart
new file mode 100644
index 0000000..a1fd370
--- /dev/null
+++ b/lib/services/authentication_service.dart
@@ -0,0 +1,10 @@
+class AuthenticationService {
+ bool isAuthenticated = false;
+ String apiKey = '';
+
+ Future<bool> authenticate(String username, String password) async {
+ isAuthenticated = true;
+ apiKey = 'test';
+ return true;
+ }
+}
diff --git a/lib/services/local_shift_provider_service.dart b/lib/services/local_shift_provider_service.dart
index fe4d466..d49f6ec 100644
--- a/lib/services/local_shift_provider_service.dart
+++ b/lib/services/local_shift_provider_service.dart
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
+import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';
import 'package:training_planner/config/defaults.dart';
import 'package:training_planner/config/old_data.dart';
@@ -84,11 +85,13 @@ class LocalShiftProviderService extends IProgramProviderService {
Future<void> writeShiftsToFile(List<Shift> shifts) async {
try {
- for (var shift in shifts) {
+ if (shifts.isNotEmpty) {
final file = await _localFile(
- DateUtilities.DateUtils.firstDayOfWeek(shift.start).toString());
+ DateUtilities.DateUtils.firstDayOfWeek(shifts.first.start)
+ .toString());
LogService.log(
- DateUtilities.DateUtils.firstDayOfWeek(shift.start).toString());
+ DateUtilities.DateUtils.firstDayOfWeek(shifts.first.start)
+ .toString());
String content = jsonEncode(shifts);
LogService.log('writing content to ' + file.path + ' -- ' + content);
await file.writeAsString(content);
@@ -184,14 +187,22 @@ class LocalShiftProviderService extends IProgramProviderService {
@override
Future<void> deleteShift(Shift shift) async {
- List<Shift> savedShifts = await readShiftsFromFile(
- DateUtilities.DateUtils.firstDayOfWeek(shift.start));
+ DateTime firstDayOfWeek =
+ DateUtilities.DateUtils.firstDayOfWeek(shift.start);
+
+ List<Shift> savedShifts = await readShiftsFromFile(firstDayOfWeek);
for (var item in savedShifts) {
if (DateUtilities.DateUtils.isSameDay(shift.start, item.start)) {
savedShifts.remove(item);
break;
}
}
+
+ if (savedShifts.isEmpty) {
+ final file = await _localFile(firstDayOfWeek.toString());
+ await file.delete();
+ }
+
await writeShiftsToFile(savedShifts);
}
}
diff --git a/lib/widgets/agenda_week_item.dart b/lib/widgets/agenda_week_item.dart
index a121084..f9f503f 100644
--- a/lib/widgets/agenda_week_item.dart
+++ b/lib/widgets/agenda_week_item.dart
@@ -49,8 +49,8 @@ class _ExerciseEntryState extends State<AgendaWeekItem> {
void initState() {
super.initState();
- auth.canCheckBiometrics.then((bio) => {
- auth
+ localAuthService.canCheckBiometrics.then((bio) => {
+ localAuthService
.isDeviceSupported()
.then((supported) => {canUseLocalAuth = bio && supported})
});
@@ -103,7 +103,7 @@ class _ExerciseEntryState extends State<AgendaWeekItem> {
return TextButton(
onPressed: () {
if (canUseLocalAuth) {
- auth
+ localAuthService
.authenticate(
localizedReason: 'Weet je zeker dat je wilt eindigen?')
.then((value) => {