6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 8f00a33c

AuthorMikkel Thygesen<mth@dwarf.dk>
Date2025-02-04 11:22:57 +0100
455: Implemented refresh keys in booking_details_page

Changed files

.../booking_details/bloc/booking_details_bloc.dart    | 19 ++++++++++++++++++-
 .../booking_details/bloc/booking_details_state.dart   |  1 +
 .../lib/booking_details/booking_details_page.dart     |  1 +
 comwell_key_app/lib/check_in/check_in_repository.dart |  2 +-
 comwell_key_app/lib/database/daos/bookings_dao.dart   |  2 +-
 comwell_key_app/lib/utils/seos_repository.dart        |  2 +-
 6 files changed, 23 insertions(+), 4 deletions(-)

Diff

diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
index 96e1fb33..26439c2f 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
@@ -1,5 +1,6 @@
import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/database/comwell_db.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
@@ -17,6 +18,7 @@ class BookingDetailsBloc
final Booking booking;
final BookingDetailsRepository bookingDetailsRepository;
+ final SeosRepository seosRepository = locator<SeosRepository>();
final ComwellDatabase database = locator<ComwellDatabase>();
BookingDetailsBloc(
@@ -26,6 +28,7 @@ class BookingDetailsBloc
on<InitialEvent>((event, emit) async {
try {
await checkIfHouseKeepingOrdered(emit);
+ await checkMobileKeys(emit);
} catch (e, st) {
if (kDebugMode) print("err=$e, $st");
emit(state.setupError());
@@ -37,9 +40,23 @@ class BookingDetailsBloc
});
}
+ Future<void> checkMobileKeys(Emitter<BookingDetailsState> emit) async {
+ try {
+ final isEndPointSetup = await seosRepository.startMobilePlugin();
+ print("qqq isEndPointSetup=$isEndPointSetup");
+ if (isEndPointSetup) {
+ final keys = await seosRepository.refreshKeys();
+ emit(state.updateKeys(keys));
+ }
+ } catch (e) {
+ emit(state.setupError());
+ }
+ }
+
Future<void> checkIfHouseKeepingOrdered(
Emitter<BookingDetailsState> emit) async {
- final isHouseKeepingOrdered = await bookingDetailsRepository.isHousesKeepingOrdered();
+ final isHouseKeepingOrdered =
+ await bookingDetailsRepository.isHousesKeepingOrdered();
if (isHouseKeepingOrdered) {
emit(state.houseKeepingOrdered());
}
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
index e28e474f..1e1eb7e9 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
@@ -11,6 +11,7 @@ class BookingDetailsState extends Equatable {
BookingDetailsState.initial() : this._(status: BookingDetailsStatus.initial, key: null, keys: [], isHouseKeepingOrdered: false);
BookingDetailsState setupError() => copyWith(status: BookingDetailsStatus.setupError);
+ BookingDetailsState updateKeys(List<MobileKeysKey> keys) => copyWith(keys: keys);
BookingDetailsState houseKeepingOrdered() => copyWith(status: BookingDetailsStatus.houseKeepingOrdered, isHouseKeepingOrdered: true);
BookingDetailsState main() => copyWith(status: BookingDetailsStatus.main);
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 53e84a67..cbb46823 100644
--- a/comwell_key_app/lib/booking_details/booking_details_page.dart
+++ b/comwell_key_app/lib/booking_details/booking_details_page.dart
@@ -61,6 +61,7 @@ class _BookingDetailsPage extends State<BookingDetailsPage> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
+ if (state.keys.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: SliderButton(
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 aa8d3663..72c17676 100644
--- a/comwell_key_app/lib/check_in/check_in_repository.dart
+++ b/comwell_key_app/lib/check_in/check_in_repository.dart
@@ -17,7 +17,7 @@ class CheckInRepository {
Future<Booking> getBooking(String bookingId) async {
//return mockBooking;
- final entity = await db.bookingsDao.getBooking(bookingId);
+ final entity = await db.bookingsDao.getBookingDetails(bookingId);
final Json json = jsonDecode(entity.json) as Json;
return Booking.fromJson(json);
}
diff --git a/comwell_key_app/lib/database/daos/bookings_dao.dart b/comwell_key_app/lib/database/daos/bookings_dao.dart
index ed370c77..9b8fc7c7 100644
--- a/comwell_key_app/lib/database/daos/bookings_dao.dart
+++ b/comwell_key_app/lib/database/daos/bookings_dao.dart
@@ -19,7 +19,7 @@ class BookingsDao extends DatabaseAccessor<ComwellDatabase>
return bookingEntity.all().get();
}
- Future<BookingDb> getBooking(String bookingId) {
+ Future<BookingDb> getBookingDetails(String bookingId) {
return (select(bookingEntity)
..where((entity) => entity.id.equals(bookingId)))
.getSingle();
diff --git a/comwell_key_app/lib/utils/seos_repository.dart b/comwell_key_app/lib/utils/seos_repository.dart
index dcfb7972..cb247b61 100644
--- a/comwell_key_app/lib/utils/seos_repository.dart
+++ b/comwell_key_app/lib/utils/seos_repository.dart
@@ -84,7 +84,7 @@ class SeosRepository {
Future<List<MobileKeysKey>> refreshKeys() async {
try {
final List<MobileKeysKey> listOfKeys = await seosMobileKeysPlugin.listMobileKeys();
- await secureStorage.write(constants.hasKey, DateTime.now().toString());
+ //await secureStorage.write(constants.hasKey, DateTime.now().toString());
return listOfKeys;
} catch (e) {
throw Exception('Failed to list keys - ${e.toString()}');