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

Feat/connect digital guide #533

Merged
merged 3 commits into from
Jan 17, 2025
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
320 changes: 164 additions & 156 deletions lib/api_base/schema.graphql

Large diffs are not rendered by default.

49 changes: 37 additions & 12 deletions lib/features/buildings_view/building_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import "dart:async";
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../config/ui_config.dart";
import "../../theme/app_theme.dart";
import "../../utils/context_extensions.dart";
import "../../widgets/wide_tile_card.dart";
import "../navigator/utils/navigation_commands.dart";
import "controllers.dart";
import "model/building_model.dart";
import "utils/utils.dart";
Expand All @@ -21,18 +23,41 @@ class BuildingTile extends ConsumerWidget {
final bool isActive;
@override
Widget build(BuildContext context, WidgetRef ref) {
return PhotoTrailingWideTileCard(
activeGradient: context.colorTheme.toPwrGradient,
directusPhotoUrl: building.cover?.filename_disk,
title:
"${building.disableBuildingPrefix ? "" : "${context.localize.building_prefix} "}${building.name}",
subtitle: context.changeNull(building.addressFormatted),
isActive: isActive,
onTap: () {
unawaited(
ref.read(buildingsMapControllerProvider).onMarkerTap(building),
);
},
return Stack(
children: [
PhotoTrailingWideTileCard(
activeGradient: context.colorTheme.toPwrGradient,
directusPhotoUrl: building.cover?.filename_disk,
title:
"${building.disableBuildingPrefix ? "" : "${context.localize.building_prefix} "}${building.name}",
subtitle: context.changeNull(building.addressFormatted),
isActive: isActive,
onTap: () {
unawaited(
ref.read(buildingsMapControllerProvider).onMarkerTap(building),
);
},
),
if (building.externalDigitalGuideMode != null &&
building.externalDigitalGuideIdOrURL != null)
Positioned(
top: 2,
right: WideTileCardConfig.imageSize,
child: IconButton(
iconSize: 18,
visualDensity: VisualDensity.compact,
icon: Icon(
Icons.info,
color: isActive
? context.colorTheme.whiteSoap
: context.colorTheme.greyPigeon,
),
onPressed: () {
unawaited(ref.navigateBuildingDetailAction(building));
},
),
),
],
);
}
}
2 changes: 2 additions & 0 deletions lib/features/buildings_view/model/building_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class BuildingModel extends Building implements GoogleNavigable {
cover: building.cover,
naturalName: building.naturalName,
disableBuildingPrefix: building.disableBuildingPrefix,
externalDigitalGuideMode: building.externalDigitalGuideMode,
externalDigitalGuideIdOrURL: building.externalDigitalGuideIdOrURL,
);

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/features/buildings_view/repository/getBuildings.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ query GetBuildings {
}
naturalName
disableBuildingPrefix
externalDigitalGuideMode
externalDigitalGuideIdOrURL
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

import "../../../buildings_view/repository/buildings_repository.dart";
import "../api/digital_guide_get_and_cache.dart";
import "../models/digital_guide_response.dart";

part "digital_guide_repository.g.dart";

@riverpod
Future<DigitalGuideResponse> digitalGuideRepository(
Future<({DigitalGuideResponse digitalGuideData, String? photoUrl})>
digitalGuideRepository(
Ref ref,
int id,
String ourId,
) async {
return ref.getAndCacheDataFromDigitalGuide(
"buildings/$id",
final buildings = await ref.watch(buildingsRepositoryProvider.future);
final building = buildings.firstWhere(
(building) => building.id == ourId,
orElse: () => throw Exception("No such building: $ourId"),
);
final digitalGuideId = building.externalDigitalGuideIdOrURL;
final digitalGuideData = await ref.getAndCacheDataFromDigitalGuide(
"buildings/$digitalGuideId",
DigitalGuideResponse.fromJson,
onRetry: () => ref.invalidateSelf(),
);
return (
digitalGuideData: digitalGuideData,
photoUrl: building.cover?.filename_disk,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../../api_base/directus_assets_url.dart";
import "../../../config/ui_config.dart";
import "../../../gen/assets.gen.dart";
import "../../../utils/context_extensions.dart";
import "../../../utils/determine_contact_icon.dart";
import "../../../widgets/detail_views/contact_section.dart";
import "../../../widgets/detail_views/detail_view_app_bar.dart";
import "../../../widgets/my_error_widget.dart";
import "../../../widgets/zoomable_images.dart";
import "../data/models/digital_guide_response.dart";
import "../data/repository/digital_guide_repository.dart";
import "widgets/accessibility_button.dart";
import "widgets/digital_guide_data_source_link.dart";
import "widgets/digital_guide_features_section.dart";
import "widgets/digital_guide_image.dart";
import "widgets/headlines_section.dart";
import "widgets/report_change_button.dart";

@RoutePage()
class DigitalGuideView extends ConsumerWidget {
const DigitalGuideView({
@PathParam("id") required this.id,
@PathParam("id") required this.ourId,
});

final int id;
final String ourId;

static String localizedOfflineMessage(BuildContext context) {
return context.localize.my_offline_error_message(
Expand All @@ -35,9 +36,10 @@ class DigitalGuideView extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final asyncDigitalGuideData = ref.watch(digitalGuideRepositoryProvider(id));
final asyncDigitalGuideData =
ref.watch(digitalGuideRepositoryProvider(ourId));
return asyncDigitalGuideData.when(
data: _DigitalGuideView.new,
data: (data) => _DigitalGuideView(data.digitalGuideData, data.photoUrl),
error: (error, stackTrace) => Scaffold(
appBar: DetailViewAppBar(),
body: MyErrorWidget(error),
Expand All @@ -54,17 +56,18 @@ class DigitalGuideView extends ConsumerWidget {
}

class _DigitalGuideView extends ConsumerWidget {
const _DigitalGuideView(this.digitalGuideData);
const _DigitalGuideView(this.digitalGuideData, this.photoUrl);

final DigitalGuideResponse digitalGuideData;
final String? photoUrl;

@override
Widget build(BuildContext context, WidgetRef ref) {
final widgets1 = [
const SizedBox(height: DigitalGuideConfig.heightSmall),
SizedBox(
height: DetailViewsConfig.imageHeight,
child: DigitalGuideImage(id: digitalGuideData.images[0]),
child: ZoomableOptimizedDirectusImage(photoUrl?.directusUrl),
),
HeadlinesSection(
name: digitalGuideData.translations.plTranslation.name,
Expand Down
9 changes: 0 additions & 9 deletions lib/features/home_view/widgets/nav_actions_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ class NavActionsSection extends ConsumerWidget {
),
ref.navigateAboutUs,
),
// _NavActionButton(
// "Digital Guide",
// Icon(
// Icons.accessibility,
// color: context.colorTheme.whiteSoap,
// size: 32,
// ),
// () => unawaited(ref.navigateDigitalGuide(421)),
// ),
],
),
);
Expand Down
19 changes: 17 additions & 2 deletions lib/features/navigator/utils/navigation_commands.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "dart:async";

import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:logger/logger.dart";

import "../../../utils/launch_url_util.dart";
import "../../buildings_view/model/building_model.dart";
import "../../digital_guide_view/tabs/adapted_toilets/data/models/adapted_toilet.dart";
import "../../digital_guide_view/tabs/rooms/data/models/digital_guide_room.dart";
Expand Down Expand Up @@ -79,8 +81,8 @@ extension NavigationX on WidgetRef {
await _router.push(const SksMenuRoute());
}

Future<void> navigateDigitalGuide(int id) async {
await _router.push(DigitalGuideRoute(id: id));
Future<void> navigateDigitalGuide(String ourId) async {
await _router.push(DigitalGuideRoute(ourId: ourId));
}

Future<void> navigateAdaptedToiletDetails(AdaptedToilet adaptedToilet) async {
Expand All @@ -90,4 +92,17 @@ extension NavigationX on WidgetRef {
Future<void> navigateRoomDetails(DigitalGuideRoom room) async {
await _router.push(DigitalGuideRoomDetailRoute(room: room));
}

Future<void> navigateBuildingDetailAction(BuildingModel building) async {
return switch (building.externalDigitalGuideMode) {
"web_url" => launch(building.externalDigitalGuideIdOrURL!),
"digital_guide_building" => navigateDigitalGuide(building.id),
"digital_guide_other_place" => Logger().i(
"Other Digital Guide place, not yet implemented",
),
_ => Logger().w(
"Unknown externalDigitalGuideMode: ${building.externalDigitalGuideMode}",
)
};
}
}
Loading