Skip to content

Commit

Permalink
Merge pull request #4455 from rokwire/4454-bug-bug-fixes-on-the-place…
Browse files Browse the repository at this point in the history
…s-bottomsheet

[BUG] Bug fixes on the stories sites bottomsheet
  • Loading branch information
mihail-varbanov authored Nov 4, 2024
2 parents a1a1997 + d5d61b1 commit e5cc3e0
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- Bug fixes on the stories sites bottomsheet [#4454](https://github.com/rokwire/illinois-app/issues/4454)

## [6.0.55] - 2024-10-24
### Fixed
Expand Down
29 changes: 20 additions & 9 deletions lib/ui/explore/ExploreMapPanel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class _ExploreMapPanelState extends State<ExploreMapPanel>
key: _storiedSightsKey,
places: _explores?.whereType<Place>().toList() ?? [],
onPlaceSelected: (places_model.Place place) {
_centerMapOnExplore(place);
_centerMapOnExplore(place, zoom: false);
_selectMapExplore(place);
},
),
Expand Down Expand Up @@ -587,10 +587,7 @@ class _ExploreMapPanelState extends State<ExploreMapPanel>
void _onMapTap(LatLng coordinate) {
debugPrint('ExploreMap tap' );
MTDStop? mtdStop;
if (_selectedMapType == ExploreMapType.StoriedSites) {
_storiedSightsKey.currentState?.resetSelection();
}
else if ((mtdStop = MTD().stops?.findStop(location: Native.LatLng(latitude: coordinate.latitude, longitude: coordinate.longitude), locationThresholdDistance: 25 /*in meters*/)) != null) {
if ((mtdStop = MTD().stops?.findStop(location: Native.LatLng(latitude: coordinate.latitude, longitude: coordinate.longitude), locationThresholdDistance: 25 /*in meters*/)) != null) {
_selectMapExplore(mtdStop);
}
else if (_selectedMapExplore != null) {
Expand Down Expand Up @@ -619,6 +616,7 @@ class _ExploreMapPanelState extends State<ExploreMapPanel>
if (_selectedMapType == ExploreMapType.StoriedSites) {
if (origin is Place) {
_storiedSightsKey.currentState?.selectPlace(origin);
// _centerMapOnExplore(origin);
} else if (origin is List<Explore>) {
List<places_model.Place> places = origin.cast<places_model.Place>();
_storiedSightsKey.currentState?.selectPlaces(places);
Expand All @@ -630,7 +628,7 @@ class _ExploreMapPanelState extends State<ExploreMapPanel>
}


void _centerMapOnExplore(dynamic explore) {
void _centerMapOnExplore(dynamic explore, {bool zoom = true}) async {
LatLng? targetPosition;

if (explore is Explore) {
Expand All @@ -640,13 +638,26 @@ class _ExploreMapPanelState extends State<ExploreMapPanel>
}

if (targetPosition != null && _mapController != null) {
CameraUpdate cameraUpdate = CameraUpdate.newLatLng(targetPosition);
_mapController!.moveCamera(cameraUpdate);
double currentZoom = await _mapController!.getZoomLevel();
double targetZoom = currentZoom;

if (zoom) {
targetZoom += 1;
if (targetZoom > 20) {
targetZoom = 20;
}
}

CameraUpdate cameraUpdate = zoom
? CameraUpdate.newLatLngZoom(targetPosition, targetZoom)
: CameraUpdate.newLatLng(targetPosition); // Center without zoom

await _mapController!.moveCamera(cameraUpdate);

double devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
double offset = 450 / devicePixelRatio;

_mapController!.moveCamera(CameraUpdate.scrollBy(0, offset));
await _mapController!.moveCamera(CameraUpdate.scrollBy(0, offset));
}
}

Expand Down
96 changes: 90 additions & 6 deletions lib/ui/explore/ExploreStoriedSightsBottomSheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:rokwire_plugin/model/places.dart' as places_model;
import 'package:rokwire_plugin/service/localization.dart';
import 'package:rokwire_plugin/service/places.dart';
import 'package:rokwire_plugin/service/styles.dart';
import 'package:rokwire_plugin/service/tracking_services.dart';
import 'package:rokwire_plugin/ui/panels/modal_image_holder.dart';
import 'package:rokwire_plugin/ui/widgets/triangle_header_image.dart';
import 'package:rokwire_plugin/utils/utils.dart';
Expand Down Expand Up @@ -37,7 +38,9 @@ class ExploreStoriedSightsBottomSheetState extends State<ExploreStoriedSightsBot
Map<String, Set<String>> _mainFilters = {};
Set<String> _regularFilters = {};
Set<String> _expandedMainTags = {};
List<places_model.Place>? _customPlaces;

static final String _customSelectionFilterKey = 'CustomSelection';


@override
Expand Down Expand Up @@ -153,6 +156,11 @@ class ExploreStoriedSightsBottomSheetState extends State<ExploreStoriedSightsBot
_buildPlaceListView() :
[ExploreStoriedSightWidget(place: _selectedDestination!, onTapBack: () => setState(() {
_selectedDestination = null;
_controller.animateTo(
0.65,
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
}))];

double _calculateFilterButtonsHeight() {
Expand Down Expand Up @@ -191,15 +199,21 @@ class ExploreStoriedSightsBottomSheetState extends State<ExploreStoriedSightsBot
}

Widget _buildDestinationCard(places_model.Place place) {

List<String> typesToShow = List<String>.from(place.types ?? []);
if (place.userData?.visited != null && place.userData!.visited!.isNotEmpty) {
typesToShow.add('Visited');
}

return InkWell(
onTap: () => _onTapDestinationCard(place),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (place.types != null && place.types!.isNotEmpty)
_buildTypeChips(place.types!),
if (typesToShow.isNotEmpty)
_buildTypeChips(typesToShow),
SizedBox(height: 8.0),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -306,6 +320,13 @@ class ExploreStoriedSightsBottomSheetState extends State<ExploreStoriedSightsBot
Widget _buildFilterButtons() {
List<Widget> filterButtons = [];

// Add Custom Selection Filter Button
if (_customPlaces != null) {
String label = '${_customPlaces!.length} Places';
bool isSelected = _selectedFilters.contains(_customSelectionFilterKey);
filterButtons.add(_buildCustomFilterButton(label, isSelected));
}

filterButtons.addAll(_regularFilters.map((tag) => _buildRegularFilterButton(tag)));

for (String mainTag in _mainFilters.keys) {
Expand Down Expand Up @@ -353,6 +374,46 @@ class ExploreStoriedSightsBottomSheetState extends State<ExploreStoriedSightsBot
);
}

Widget _buildCustomFilterButton(String label, bool isSelected) {
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child: ElevatedButton(
onPressed: () {
setState(() {
if (isSelected) {
// Deselect custom filter
_selectedFilters.remove(_customSelectionFilterKey);
_customPlaces = null;
} else {
// Select custom filter
_selectedFilters.clear();
_selectedFilters.add(_customSelectionFilterKey);
}
_applyFilters();
});
},
style: ElevatedButton.styleFrom(
foregroundColor: isSelected ? Colors.white : Styles().colors.fillColorPrimary,
backgroundColor: isSelected ? Styles().colors.fillColorPrimary : Colors.white,
side: BorderSide(
color: isSelected ? Styles().colors.fillColorPrimary : Styles().colors.surfaceAccent,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24.0),
),
),
child: Text(
label,
style: Styles()
.textStyles
.getTextStyle("widget.button.title.small")
?.apply(color: isSelected ? Colors.white : Styles().colors.fillColorPrimary),
),
),
);
}


Widget _buildMainFilterButton(String mainTag, bool isExpanded) {
return Padding(
padding: const EdgeInsets.only(right: 8.0),
Expand Down Expand Up @@ -470,6 +531,10 @@ class ExploreStoriedSightsBottomSheetState extends State<ExploreStoriedSightsBot
setState(() {
_storiedSights = List.from(_allPlaces);
});
} else if (_selectedFilters.contains(_customSelectionFilterKey)) {
setState(() {
_storiedSights = List.from(_customPlaces!);
});
} else {
setState(() {
_storiedSights = _allPlaces.where((place) {
Expand Down Expand Up @@ -555,8 +620,10 @@ class ExploreStoriedSightsBottomSheetState extends State<ExploreStoriedSightsBot
void selectPlaces(List<places_model.Place> places) {
setState(() {
_storiedSights = places;
_customPlaces = places;
_selectedDestination = null;
_selectedFilters.clear();
_selectedFilters.add(_customSelectionFilterKey);
});
_controller.animateTo(
0.65,
Expand Down Expand Up @@ -589,6 +656,23 @@ class _ExploreStoriedSightWidgetState extends State<ExploreStoriedSightWidget> {

List<DateTime> _placeCheckInDates = [];
bool? _isHistoryExpanded;
TrackingAuthorizationStatus? _status;

@override
void initState() {
super.initState();
_loadTrackingStatus();
}

void _loadTrackingStatus() async {
TrackingAuthorizationStatus? trackingStatus = await TrackingServices.queryAuthorizationStatus();
if (mounted) {
setState(() {
_status = trackingStatus;
});
}
}


@override
Widget build(BuildContext context) =>
Expand All @@ -602,11 +686,11 @@ class _ExploreStoriedSightWidgetState extends State<ExploreStoriedSightWidget> {
child: MarkdownBody(
data: widget.place.description ?? Localization().getStringEx('panel.explore.storied_sites.default.description', 'No description available'),
onTapLink: (text, href, title) {
if (href?.startsWith('https://') == true) {
Navigator.push(context, CupertinoPageRoute(builder: (context) => WebPanel(url: href)));
return;
if (UrlUtils.isWebScheme(href) && (_status == TrackingAuthorizationStatus.allowed)) {
Navigator.push(context, CupertinoPageRoute(builder: (context) => WebPanel(url: href)),);
} else {
UrlUtils.launchExternal(href);
}
UrlUtils.launchExternal(href);
},
styleSheet: MarkdownStyleSheet(
p: Styles().textStyles.getTextStyle("widget.description.regular"),
Expand Down
2 changes: 1 addition & 1 deletion plugin

0 comments on commit e5cc3e0

Please sign in to comment.