Skip to content

Commit

Permalink
Apply map style at timeline and detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushik committed Dec 11, 2024
1 parent 4a5b6f3 commit 3f680e8
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 251 deletions.
3 changes: 3 additions & 0 deletions app/lib/ui/flow/journey/components/journey_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class JourneyMap extends StatefulWidget {
final List<Marker> markers;
final bool isTimeLine;
final bool gestureEnable;
final MapType mapType;

const JourneyMap({
super.key,
required this.journey,
required this.markers,
required this.isTimeLine,
required this.gestureEnable,
this.mapType = MapType.normal,
});

@override
Expand Down Expand Up @@ -66,6 +68,7 @@ class _JourneyMapState extends State<JourneyMap> {
zoomGesturesEnabled: widget.gestureEnable,
scrollGesturesEnabled: widget.gestureEnable,
rotateGesturesEnabled: widget.gestureEnable,
mapType: widget.mapType,
markers: widget.markers.toSet(),
polylines:ployLines.toSet(),
),
Expand Down
15 changes: 13 additions & 2 deletions app/lib/ui/flow/journey/detail/user_journey_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class _UserJourneyDetailScreenState
markers: _markers,
isTimeLine: false,
gestureEnable: true,
mapType: getMapTypeInfo(state.mapType),
),
),
_journeyInfo(state)
Expand Down Expand Up @@ -256,8 +257,8 @@ class _UserJourneyDetailScreenState
}

Future<List<Marker>> _buildMarkers(LatLng fromLatLng, LatLng toLatLng) async {
final fromIcon = await notifier.createCustomIcon(
'assets/images/ic_timeline_start_location_icon.png');
final fromIcon = await notifier
.createCustomIcon('assets/images/ic_timeline_start_location_icon.png');
final toIcon = await notifier.createCustomIcon(
'assets/images/ic_timeline_end_location_flag_icon.png');

Expand All @@ -280,4 +281,14 @@ class _UserJourneyDetailScreenState

return markers;
}

MapType getMapTypeInfo(String mapType) {
if (mapType == 'Terrain') {
return MapType.terrain;
} else if (mapType == 'Satellite') {
return MapType.satellite;
} else {
return MapType.normal;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui' as ui;
import 'package:data/api/location/journey/api_journey_service.dart';
import 'package:data/api/location/journey/journey.dart';
import 'package:data/log/logger.dart';
import 'package:data/storage/app_preferences.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
Expand All @@ -17,13 +18,15 @@ final userJourneyDetailStateProvider = StateNotifierProvider.autoDispose<
UserJourneyDetailViewModel, UserJourneyDetailState>(
(ref) => UserJourneyDetailViewModel(
ref.read(journeyServiceProvider),
ref.read(googleMapType.notifier),
));

class UserJourneyDetailViewModel extends StateNotifier<UserJourneyDetailState> {
final ApiJourneyService journeyService;
final StateController<String> mapTypeController;

UserJourneyDetailViewModel(this.journeyService)
: super(const UserJourneyDetailState());
UserJourneyDetailViewModel(this.journeyService, this.mapTypeController)
: super(UserJourneyDetailState(mapType: mapTypeController.state));

void loadData(ApiLocationJourney journey) async {
final isNetworkOff = await _checkUserInternet();
Expand Down Expand Up @@ -122,6 +125,7 @@ class UserJourneyDetailState with _$UserJourneyDetailState {
@Default(false) bool isNetworkOff,
ApiLocationJourney? journey,
String? journeyId,
@Default("Normal") String mapType,
@Default([]) List<Placemark> addressFrom,
@Default([]) List<Placemark> addressTo,
Object? error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mixin _$UserJourneyDetailState {
bool get isNetworkOff => throw _privateConstructorUsedError;
ApiLocationJourney? get journey => throw _privateConstructorUsedError;
String? get journeyId => throw _privateConstructorUsedError;
String get mapType => throw _privateConstructorUsedError;
List<Placemark> get addressFrom => throw _privateConstructorUsedError;
List<Placemark> get addressTo => throw _privateConstructorUsedError;
Object? get error => throw _privateConstructorUsedError;
Expand All @@ -40,6 +41,7 @@ abstract class $UserJourneyDetailStateCopyWith<$Res> {
bool isNetworkOff,
ApiLocationJourney? journey,
String? journeyId,
String mapType,
List<Placemark> addressFrom,
List<Placemark> addressTo,
Object? error});
Expand All @@ -65,6 +67,7 @@ class _$UserJourneyDetailStateCopyWithImpl<$Res,
Object? isNetworkOff = null,
Object? journey = freezed,
Object? journeyId = freezed,
Object? mapType = null,
Object? addressFrom = null,
Object? addressTo = null,
Object? error = freezed,
Expand All @@ -86,6 +89,10 @@ class _$UserJourneyDetailStateCopyWithImpl<$Res,
? _value.journeyId
: journeyId // ignore: cast_nullable_to_non_nullable
as String?,
mapType: null == mapType
? _value.mapType
: mapType // ignore: cast_nullable_to_non_nullable
as String,
addressFrom: null == addressFrom
? _value.addressFrom
: addressFrom // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -125,6 +132,7 @@ abstract class _$$UserJourneyDetailStateImplCopyWith<$Res>
bool isNetworkOff,
ApiLocationJourney? journey,
String? journeyId,
String mapType,
List<Placemark> addressFrom,
List<Placemark> addressTo,
Object? error});
Expand All @@ -150,6 +158,7 @@ class __$$UserJourneyDetailStateImplCopyWithImpl<$Res>
Object? isNetworkOff = null,
Object? journey = freezed,
Object? journeyId = freezed,
Object? mapType = null,
Object? addressFrom = null,
Object? addressTo = null,
Object? error = freezed,
Expand All @@ -171,6 +180,10 @@ class __$$UserJourneyDetailStateImplCopyWithImpl<$Res>
? _value.journeyId
: journeyId // ignore: cast_nullable_to_non_nullable
as String?,
mapType: null == mapType
? _value.mapType
: mapType // ignore: cast_nullable_to_non_nullable
as String,
addressFrom: null == addressFrom
? _value._addressFrom
: addressFrom // ignore: cast_nullable_to_non_nullable
Expand All @@ -192,6 +205,7 @@ class _$UserJourneyDetailStateImpl implements _UserJourneyDetailState {
this.isNetworkOff = false,
this.journey,
this.journeyId,
this.mapType = "Normal",
final List<Placemark> addressFrom = const [],
final List<Placemark> addressTo = const [],
this.error})
Expand All @@ -208,6 +222,9 @@ class _$UserJourneyDetailStateImpl implements _UserJourneyDetailState {
final ApiLocationJourney? journey;
@override
final String? journeyId;
@override
@JsonKey()
final String mapType;
final List<Placemark> _addressFrom;
@override
@JsonKey()
Expand All @@ -231,7 +248,7 @@ class _$UserJourneyDetailStateImpl implements _UserJourneyDetailState {

@override
String toString() {
return 'UserJourneyDetailState(loading: $loading, isNetworkOff: $isNetworkOff, journey: $journey, journeyId: $journeyId, addressFrom: $addressFrom, addressTo: $addressTo, error: $error)';
return 'UserJourneyDetailState(loading: $loading, isNetworkOff: $isNetworkOff, journey: $journey, journeyId: $journeyId, mapType: $mapType, addressFrom: $addressFrom, addressTo: $addressTo, error: $error)';
}

@override
Expand All @@ -245,6 +262,7 @@ class _$UserJourneyDetailStateImpl implements _UserJourneyDetailState {
(identical(other.journey, journey) || other.journey == journey) &&
(identical(other.journeyId, journeyId) ||
other.journeyId == journeyId) &&
(identical(other.mapType, mapType) || other.mapType == mapType) &&
const DeepCollectionEquality()
.equals(other._addressFrom, _addressFrom) &&
const DeepCollectionEquality()
Expand All @@ -259,6 +277,7 @@ class _$UserJourneyDetailStateImpl implements _UserJourneyDetailState {
isNetworkOff,
journey,
journeyId,
mapType,
const DeepCollectionEquality().hash(_addressFrom),
const DeepCollectionEquality().hash(_addressTo),
const DeepCollectionEquality().hash(error));
Expand All @@ -277,6 +296,7 @@ abstract class _UserJourneyDetailState implements UserJourneyDetailState {
final bool isNetworkOff,
final ApiLocationJourney? journey,
final String? journeyId,
final String mapType,
final List<Placemark> addressFrom,
final List<Placemark> addressTo,
final Object? error}) = _$UserJourneyDetailStateImpl;
Expand All @@ -290,6 +310,8 @@ abstract class _UserJourneyDetailState implements UserJourneyDetailState {
@override
String? get journeyId;
@override
String get mapType;
@override
List<Placemark> get addressFrom;
@override
List<Placemark> get addressTo;
Expand Down
18 changes: 17 additions & 1 deletion app/lib/ui/flow/journey/timeline/journey_timeline_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
journey,
state.sortedJourney.first.id == journey.id,
state.sortedJourney.last.id == journey.id,
state.mapType,
),
],
);
Expand Down Expand Up @@ -224,6 +225,7 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
ApiLocationJourney journey,
bool isFirstItem,
bool isLastItem,
String mapType,
) {
final time = _getFormattedJourneyTime(
journey.created_at ?? 0, journey.update_at ?? 0);
Expand Down Expand Up @@ -262,13 +264,15 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
markers: markers,
isTimeLine: true,
gestureEnable: false,
mapType: getMapTypeInfo(mapType),
);
} else {
return JourneyMap(
journey: journey,
markers: const [],
isTimeLine: true,
gestureEnable: false,
mapType: getMapTypeInfo(mapType),
);
}
},
Expand Down Expand Up @@ -369,7 +373,9 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
address.isEmpty ? context.l10n.journey_timeline_unknown_address_text : address,
address.isEmpty
? context.l10n.journey_timeline_unknown_address_text
: address,
style: AppTextStyle.body2
.copyWith(color: context.colorScheme.textPrimary),
maxLines: 2,
Expand Down Expand Up @@ -542,4 +548,14 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
return date.toString();
}
}

MapType getMapTypeInfo(String mapType) {
if (mapType == 'Terrain') {
return MapType.terrain;
} else if (mapType == 'Satellite') {
return MapType.satellite;
} else {
return MapType.normal;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ final journeyTimelineStateProvider = StateNotifierProvider.autoDispose<
ref.read(currentUserPod),
ref.read(journeyServiceProvider),
ref.read(currentSpaceId.notifier),
ref.read(googleMapType.notifier),
));

class JourneyTimelineViewModel extends StateNotifier<JourneyTimelineState> {
final ApiUser? currentUser;
final ApiJourneyService journeyService;
final StateController<String?> _currentSpaceId;
final StateController<String> mapTypeController;

JourneyTimelineViewModel(
this.currentUser,
this.journeyService,
this._currentSpaceId,
) : super(const JourneyTimelineState());
this.mapTypeController,
) : super(JourneyTimelineState(mapType: mapTypeController.state));

void loadData(ApiUser selectedUser) async {
final isNetworkOff = await _checkUserInternet();
Expand Down Expand Up @@ -249,6 +252,7 @@ class JourneyTimelineState with _$JourneyTimelineState {
int? selectedTimeFrom,
int? selectedTimeTo,
String? spaceId,
@Default("Normal") String mapType,
Object? error,
}) = _JourneyTimelineState;
}
Loading

0 comments on commit 3f680e8

Please sign in to comment.