6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 3411eeec
Changed files
.../lib/booking_details/booking_details_page.dart | 5 ++- .../lib/check_in/bloc/check_in_cubit.dart | 4 ++ comwell_key_app/lib/check_in/check_in_page.dart | 4 +- .../lib/check_in/check_in_repository.dart | 17 ++++--- comwell_key_app/lib/key/bloc/key_bloc.dart | 33 +++++++++++--- comwell_key_app/lib/key/bloc/key_state.dart | 52 +++++++++++++--------- .../lib/key/repository/key_repository.dart | 34 ++++++++------ .../lib/services/mappers/booking_mapper.dart | 19 ++++++++ 8 files changed, 120 insertions(+), 48 deletions(-)
Diff
diff --git a/comwell_key_app/lib/booking_details/booking_details_page.dart b/comwell_key_app/lib/booking_details/booking_details_page.dart
index bab7212b..6138eb50 100644
--- a/comwell_key_app/lib/booking_details/booking_details_page.dart
+++ b/comwell_key_app/lib/booking_details/booking_details_page.dart
@@ -6,6 +6,7 @@ import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
import 'package:comwell_key_app/booking_details/components/housekeeping_button.dart';
import 'package:comwell_key_app/booking_details/components/practical_information_button.dart';
import 'package:comwell_key_app/routing/app_routes.dart';
+import 'package:comwell_key_app/services/mappers/booking_mapper.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/tracking/comwell_tracking.dart';
import 'package:comwell_key_app/utils/locator.dart';
@@ -28,6 +29,8 @@ class BookingDetailsPage extends StatelessWidget {
builder: (context, state) {
final cubit = context.read<BookingDetailsBloc>();
final theme = Theme.of(context);
+
+ print("key: ${cubit.state.keys}");
print("Booking: ${cubit.booking}");
if (state.status == BookingDetailsStatus.initial) {
@@ -224,7 +227,7 @@ class BookingDetailsPage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
- cubit.booking.roomType,
+ cubit.booking.toRoomType(),
style: theme.textTheme.bodyMedium?.copyWith(
color: Colors.white,
),
diff --git a/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart b/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
index 83561cd4..91286b61 100644
--- a/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
+++ b/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
@@ -18,11 +18,15 @@ class CheckInCubit extends Cubit<CheckInState> {
await Future<void>.delayed(const Duration(milliseconds: 500));
emit(state.checkInStatusLoading());
await _checkInRepository.checkIn(booking.confirmationId);
+ final bookingDetails = await _checkInRepository.getBookingDetails(booking.id);
+ booking = bookingDetails.copyWith(roomNumber: bookingDetails.roomNumber);
emit(state.checkInStatusRoomFound(roomNumber: booking.roomNumber));
await _checkInRepository.checkIfSetup();
await tryGetKeys();
await Future<void>.delayed(const Duration(milliseconds: 1000));
+ print("qqq cubit.state.checkInStatus: ${state.checkInStatus}");
+ print("qqq cubit.booking.roomNumber: ${booking.roomNumber}");
emit(state.checkInStatusYourDigitalCard(roomNumber: booking.roomNumber));
} catch (err, st) {
if (kDebugMode) print("qqq err=$err, $st");
diff --git a/comwell_key_app/lib/check_in/check_in_page.dart b/comwell_key_app/lib/check_in/check_in_page.dart
index dc04832e..fca15e3c 100644
--- a/comwell_key_app/lib/check_in/check_in_page.dart
+++ b/comwell_key_app/lib/check_in/check_in_page.dart
@@ -85,6 +85,8 @@ class _CheckInPageState extends State<CheckInPage>
Widget getCardContent(BuildContext context) {
final cubit = context.read<CheckInCubit>();
+ print("qqq cubit.state.checkInStatus: ${cubit.state.checkInStatus}");
+ print("qqq cubit.booking.roomNumber: ${cubit.booking.roomNumber}");
if (cubit.state.checkInStatus is CheckInStatusYourDigitalCard) {
return Container(
decoration: BoxDecoration(
@@ -93,7 +95,7 @@ class _CheckInPageState extends State<CheckInPage>
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
- "${"check_in_your_digital_card_room_prefix".tr()} ${(cubit.state.checkInStatus as CheckInStatusYourDigitalCard).roomNumber}",
+ "${"check_in_your_digital_card_room_prefix".tr()} ${(cubit.booking.roomNumber)}",
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: Colors.white,
),
diff --git a/comwell_key_app/lib/check_in/check_in_repository.dart b/comwell_key_app/lib/check_in/check_in_repository.dart
index 8ba00e8e..3276cf3d 100644
--- a/comwell_key_app/lib/check_in/check_in_repository.dart
+++ b/comwell_key_app/lib/check_in/check_in_repository.dart
@@ -37,11 +37,18 @@ class CheckInRepository {
}
Future<Booking> getBookingDetails(String bookingId) async {
- final user = await profileRepository.fetchProfileSettings();
- final entity = await db.bookingsDao.getBookingDetails(bookingId);
- final Json json = jsonDecode(entity.json) as Json;
- return BookingDTO.fromJson(json)
- .toBooking(user.id, BookingStatus.fromString(entity.status));
+ try {
+ final user = await profileRepository.fetchProfileSettings();
+ final entity = await db.bookingsDao.getBookingDetails(bookingId);
+ print("entity in getBookingDetails: ${entity}");
+ print("entity.json in getBookingDetails: ${entity.json}");
+ final Json json = jsonDecode(entity.json) as Json;
+ return BookingDTO.fromJson(json)
+ .toBooking(user.id, BookingStatus.fromString(entity.status));
+ } catch (err, st) {
+ print("error in getBookingDetails: $err, $st");
+ throw Exception("An unexpected error occurred during getBookingDetails");
+ }
}
Future<void> checkIfSetup() async {
diff --git a/comwell_key_app/lib/key/bloc/key_bloc.dart b/comwell_key_app/lib/key/bloc/key_bloc.dart
index efc3b696..5427cb7f 100644
--- a/comwell_key_app/lib/key/bloc/key_bloc.dart
+++ b/comwell_key_app/lib/key/bloc/key_bloc.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'dart:core';
import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/key/repository/key_repository.dart';
@@ -16,15 +17,20 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
final BookingDetailsRepository bookingDetailsRepository;
final SeosRepository seosRepository;
- KeyBloc({required this.seosRepository, required this.keyRepository, required this.bookingDetailsRepository})
+ KeyBloc(
+ {required this.seosRepository,
+ required this.keyRepository,
+ required this.bookingDetailsRepository})
: super(KeyState.unknown()) {
+ print("qqq refreshKeys");
on<SearchForKeys>((event, emit) async {
emit(KeyState.searchForKeys());
try {
final keys = await seosRepository.refreshKeys();
+ print("qqq keys=$keys");
emit(KeyState.validKeys(keys));
add(const StartScanning());
- } catch (e) {
+ } catch (e) {
emit(KeyState.searchForKeysError(e.toString()));
}
});
@@ -34,12 +40,23 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
await keyRepository.checkDeviceInfo();
emit(KeyState.scanning());
- //Timer.periodic(const Duration(seconds: 1), (timer) async {
- // await keyRepository.openClosestReader();
- //keyRepository.stopScanning();
- //emit(KeyState.openClosestReaderSuccess());
- // });
+ // for (var i = 0; i < 10; i++) {
+ // try {
+ // print("qqq start scanning=$i");
+ // await Future.delayed(const Duration(seconds: 1));
+ // await keyRepository.openClosestReader();
+ // print("qqq openClosestReader=$i");
+ // keyRepository.stopScanning();
+ // emit(KeyState.openClosestReaderSuccess());
+ // break;
+ // } catch (e) {
+ // print("qqq failed, rescanning");
+ // continue;
+ // emit(KeyState.openClosestReaderError(e.toString()));
+ // }
+ // }
} catch (e) {
+ print("qqq e=$e");
emit(KeyState.scanningError(e.toString()));
}
});
@@ -59,5 +76,7 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
emit(KeyState.removeRootOpeningTriggerError(e.toString()));
}
});
+
+ add(SearchForKeys());
}
}
diff --git a/comwell_key_app/lib/key/bloc/key_state.dart b/comwell_key_app/lib/key/bloc/key_state.dart
index 261657c8..f6743ce7 100644
--- a/comwell_key_app/lib/key/bloc/key_state.dart
+++ b/comwell_key_app/lib/key/bloc/key_state.dart
@@ -2,47 +2,59 @@
part of 'key_bloc.dart';
-
-enum KeyStatus { unknown,searchforKeys, scanning, openClosestReader, openClosestReaderSuccess, openClosestReaderError, scanningError,validKeys, searchForKeysError, setRootOpeningTriggerError, removeRootOpeningTriggerError }
+enum KeyStatus {
+ unknown,
+ searchforKeys,
+ scanning,
+ openClosestReader,
+ openClosestReaderSuccess,
+ openClosestReaderError,
+ scanningError,
+ validKeys,
+ searchForKeysError,
+ setRootOpeningTriggerError,
+ removeRootOpeningTriggerError
+}
class KeyState extends Equatable {
-
- KeyState._({
+ KeyState._({
this.status = KeyStatus.unknown,
key,
error,
});
-
KeyState.unknown() : this._(status: KeyStatus.unknown);
KeyState.searchForKeys() : this._(status: KeyStatus.searchforKeys);
- KeyState.validKeys(List<MobileKeysKey?> keys) : this._(status: KeyStatus.validKeys, key: keys);
-
+ KeyState.validKeys(List<MobileKeysKey?> keys)
+ : this._(status: KeyStatus.validKeys, key: keys);
+
KeyState.scanning() : this._(status: KeyStatus.scanning);
KeyState.openClosestReader() : this._(status: KeyStatus.openClosestReader);
- KeyState.openClosestReaderSuccess() : this._(status: KeyStatus.openClosestReaderSuccess);
-
- KeyState.openClosestReaderError(String error) : this._(status: KeyStatus.openClosestReaderError, error: error);
+ KeyState.openClosestReaderSuccess()
+ : this._(status: KeyStatus.openClosestReaderSuccess);
- KeyState.searchForKeysError(String error) : this._(status: KeyStatus.searchForKeysError, error: error);
+ KeyState.openClosestReaderError(String error)
+ : this._(status: KeyStatus.openClosestReaderError, error: error);
- KeyState.scanningError(String error) : this._(status: KeyStatus.scanningError, error: error);
+ KeyState.searchForKeysError(String error)
+ : this._(status: KeyStatus.searchForKeysError, error: error);
- KeyState.setRootOpeningTriggerError(String error) : this._(status: KeyStatus.setRootOpeningTriggerError, error: error);
+ KeyState.scanningError(String error)
+ : this._(status: KeyStatus.scanningError, error: error);
- KeyState.removeRootOpeningTriggerError(String error) : this._(status: KeyStatus.removeRootOpeningTriggerError, error: error);
+ KeyState.setRootOpeningTriggerError(String error)
+ : this._(status: KeyStatus.setRootOpeningTriggerError, error: error);
+ KeyState.removeRootOpeningTriggerError(String error)
+ : this._(status: KeyStatus.removeRootOpeningTriggerError, error: error);
- KeyStatus status;
- MobileKeysKey? key;
- String? error;
+ KeyStatus status;
+ MobileKeysKey? key;
+ String? error;
@override
List<Object?> get props => [status, key, error];
-
}
-
-
diff --git a/comwell_key_app/lib/key/repository/key_repository.dart b/comwell_key_app/lib/key/repository/key_repository.dart
index fd9a6fb2..0ed4cf30 100644
--- a/comwell_key_app/lib/key/repository/key_repository.dart
+++ b/comwell_key_app/lib/key/repository/key_repository.dart
@@ -22,35 +22,38 @@ class KeyRepository {
final androidInfo = await deviceInfo.androidInfo;
if (androidInfo.version.sdkInt >= 33) {
await Permission.bluetoothScan.request();
- await Permission.bluetoothConnect.onGrantedCallback(() {
- _checkAndStartScan();
+ await Permission.bluetoothConnect.onGrantedCallback(() async {
+ await _checkAndStartScan();
}).request();
await Permission.bluetoothAdvertise.request();
await Permission.notification.request();
} else if (androidInfo.version.sdkInt >= 31) {
await Permission.bluetoothScan.request();
await Permission.bluetoothConnect
- .onGrantedCallback(() => () {
- _checkAndStartScan();
- })
+ .onGrantedCallback(() async {
+ await _checkAndStartScan();
+ })
.request();
await Permission.bluetoothAdvertise.request();
} else {
- await Permission.location.onGrantedCallback(() {
- _checkAndStartScan();
+ await Permission.location.onGrantedCallback(() async {
+ await _checkAndStartScan();
}).request();
}
} else {
- _checkAndStartScan();
+ await _checkAndStartScan();
}
} catch (e) {
throw Exception('Failed to refresh keys - ${e.toString()}');
}
}
- void _checkAndStartScan() {
+ Future<void> _checkAndStartScan() async {
+ print("qqq _checkAndStartScan ${_isScanning}");
+
if (!_isScanning) {
- startScanning();
+ print("qqq start scanning");
+ await startScanning();
_isScanning = true;
}
}
@@ -58,6 +61,7 @@ class KeyRepository {
Future<void> stopScanning() async {
try {
await seosMobileKeysPlugin.stopReaderScan();
+ _isScanning = false;
} catch (e) {
throw Exception('Failed to stop scanning - ${e.toString()}');
}
@@ -65,6 +69,7 @@ class KeyRepository {
Future<void> startScanning() async {
try {
+ print("qqq start scanning second");
await seosMobileKeysPlugin
.startReaderScan(MobileKeysScanMode.optimizePerformance, [
MobileKeysOpeningType(openingType: OpeningType.proximity),
@@ -79,6 +84,7 @@ class KeyRepository {
print('startScanning: "scanned');
}
});
+ print("qqq start scanning third");
} catch (e) {
throw Exception('Failed to start scanning - ${e.toString()}');
@@ -86,11 +92,11 @@ class KeyRepository {
}
Future<void> openClosestReader() async {
- try {
+ // try {
await seosMobileKeysPlugin.openClosestReader();
- } catch (e) {
- //throw Exception('Failed to open closest reader - ${e.toString()}');
- }
+ // } catch (e) {
+ // throw Exception('Failed to open closest reader - ${e.toString()}');
+ // }
}
Future<void> setRootOpeningTrigger() async {
diff --git a/comwell_key_app/lib/services/mappers/booking_mapper.dart b/comwell_key_app/lib/services/mappers/booking_mapper.dart
index 509fd5eb..a696c511 100644
--- a/comwell_key_app/lib/services/mappers/booking_mapper.dart
+++ b/comwell_key_app/lib/services/mappers/booking_mapper.dart
@@ -53,3 +53,22 @@ extension ListBookingMapper on Iterable<BookingDTO> {
Iterable<Booking> toBookings(int userId, BookingStatus status) =>
map((dto) => dto.toBooking(userId, status));
}
+
+extension RoomTypeMapper on Booking {
+ String toRoomType() {
+ switch (roomType) {
+ case "SDPBO":
+ return "Standard Double Plus Room";
+ case "SDBO":
+ return "Standard Double Room";
+ case "STPBO":
+ return "Standard Twin Plus Room";
+ case "STPO":
+ return "Standard Twin Room";
+ case "SUBO":
+ return "Suite";
+ default:
+ return "Room";
+ }
+ }
+}