Skip to content

Commit

Permalink
add type of journey
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Dec 12, 2024
1 parent 325a4e8 commit 3606062
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 30 deletions.
4 changes: 0 additions & 4 deletions app/ios/Runner/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ class LocationsHandler: NSObject, ObservableObject, CLLocationManagerDelegate {

func startLocationUpdates() {
if self.manager.authorizationStatus == .notDetermined {
print("startLocationUpdates: permission notDetermined")
return
}
updatesStarted = true
print("startLocationUpdates: startUpdatingLocation......")
manager.startUpdatingLocation()
}

Expand Down Expand Up @@ -65,8 +63,6 @@ class LocationsHandler: NSObject, ObservableObject, CLLocationManagerDelegate {
return
}

print("Got location update: \(currentLocation.coordinate.latitude):\(currentLocation.coordinate.longitude)")

lastLocation = currentLocation
}

Expand Down
4 changes: 2 additions & 2 deletions app/lib/ui/flow/journey/timeline/journey_timeline_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
journey.isSteadyLocation()
journey.type == JOURNEY_TYPE_STEADY
? _steadyLocationItem(
journey,
state.sortedJourney.first.id == journey.id,
Expand Down Expand Up @@ -199,7 +199,7 @@ class _JourneyTimelineScreenState extends ConsumerState<JourneyTimelineScreen> {
_buildPlaceInfo(
location,
formattedTime,
journey.isSteadyLocation(),
journey.type == JOURNEY_TYPE_STEADY,
steadyDuration,
isFirstItem),
const SizedBox(height: 16),
Expand Down
2 changes: 2 additions & 0 deletions data/lib/api/location/journey/api_journey_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ApiJourneyService {
int? routeDuration,
int? created_at,
int? updated_at,
String? type,
}) async {
final fromLatLng = LatLng(fromLatitude, fromLongitude);
final toLatLng = (toLatitude != null && toLongitude != null)
Expand All @@ -58,6 +59,7 @@ class ApiJourneyService {
route_duration: routeDuration,
created_at: created_at ?? DateTime.now().millisecondsSinceEpoch,
update_at: updated_at ?? DateTime.now().millisecondsSinceEpoch,
type: type ?? (toLatLng == null ? JOURNEY_TYPE_STEADY : JOURNEY_TYPE_MOVING)
);
await docRef.set(journey.toJson());
return docRef.id;
Expand Down
11 changes: 6 additions & 5 deletions data/lib/api/location/journey/journey.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: constant_identifier_names
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:data/api/location/location.dart';
import 'package:data/domain/journey_lat_lng_entension.dart';
Expand All @@ -7,6 +8,9 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
part 'journey.freezed.dart';
part 'journey.g.dart';

const JOURNEY_TYPE_STEADY = 'steady';
const JOURNEY_TYPE_MOVING = 'moving';

@freezed
class ApiLocationJourney with _$ApiLocationJourney {
const ApiLocationJourney._();
Expand All @@ -23,6 +27,7 @@ class ApiLocationJourney with _$ApiLocationJourney {
int? route_duration,
int? created_at,
int? update_at,
String? type,
}) = _LocationJourney;

factory ApiLocationJourney.fromJson(Map<String, dynamic> json) =>
Expand All @@ -36,7 +41,7 @@ class ApiLocationJourney with _$ApiLocationJourney {
}

List<LatLng> toRoute() {
if (isSteadyLocation()) {
if (type == JOURNEY_TYPE_STEADY) {
return [];
} else {
List<LatLng> result = [LatLng(from_latitude, from_longitude)];
Expand All @@ -48,10 +53,6 @@ class ApiLocationJourney with _$ApiLocationJourney {
}
}

bool isSteadyLocation() {
return to_latitude == null && to_longitude == null;
}

LocationData toLocationFromSteadyJourney() {
return LocationData(latitude: from_latitude, longitude: from_longitude, timestamp: DateTime.now());
}
Expand Down
77 changes: 62 additions & 15 deletions data/lib/api/location/journey/journey.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ mixin _$ApiLocationJourney {
int? get route_duration => throw _privateConstructorUsedError;
int? get created_at => throw _privateConstructorUsedError;
int? get update_at => throw _privateConstructorUsedError;
String? get type => throw _privateConstructorUsedError;

/// Serializes this ApiLocationJourney to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)

/// Create a copy of ApiLocationJourney
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ApiLocationJourneyCopyWith<ApiLocationJourney> get copyWith =>
throw _privateConstructorUsedError;
}
Expand All @@ -55,7 +60,8 @@ abstract class $ApiLocationJourneyCopyWith<$Res> {
double? route_distance,
int? route_duration,
int? created_at,
int? update_at});
int? update_at,
String? type});
}

/// @nodoc
Expand All @@ -68,6 +74,8 @@ class _$ApiLocationJourneyCopyWithImpl<$Res, $Val extends ApiLocationJourney>
// ignore: unused_field
final $Res Function($Val) _then;

/// Create a copy of ApiLocationJourney
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Expand All @@ -82,6 +90,7 @@ class _$ApiLocationJourneyCopyWithImpl<$Res, $Val extends ApiLocationJourney>
Object? route_duration = freezed,
Object? created_at = freezed,
Object? update_at = freezed,
Object? type = freezed,
}) {
return _then(_value.copyWith(
id: freezed == id
Expand Down Expand Up @@ -128,6 +137,10 @@ class _$ApiLocationJourneyCopyWithImpl<$Res, $Val extends ApiLocationJourney>
? _value.update_at
: update_at // ignore: cast_nullable_to_non_nullable
as int?,
type: freezed == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}
}
Expand All @@ -151,7 +164,8 @@ abstract class _$$LocationJourneyImplCopyWith<$Res>
double? route_distance,
int? route_duration,
int? created_at,
int? update_at});
int? update_at,
String? type});
}

/// @nodoc
Expand All @@ -162,6 +176,8 @@ class __$$LocationJourneyImplCopyWithImpl<$Res>
_$LocationJourneyImpl _value, $Res Function(_$LocationJourneyImpl) _then)
: super(_value, _then);

/// Create a copy of ApiLocationJourney
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Expand All @@ -176,6 +192,7 @@ class __$$LocationJourneyImplCopyWithImpl<$Res>
Object? route_duration = freezed,
Object? created_at = freezed,
Object? update_at = freezed,
Object? type = freezed,
}) {
return _then(_$LocationJourneyImpl(
id: freezed == id
Expand Down Expand Up @@ -222,6 +239,10 @@ class __$$LocationJourneyImplCopyWithImpl<$Res>
? _value.update_at
: update_at // ignore: cast_nullable_to_non_nullable
as int?,
type: freezed == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
Expand All @@ -240,7 +261,8 @@ class _$LocationJourneyImpl extends _LocationJourney {
this.route_distance,
this.route_duration,
this.created_at,
this.update_at})
this.update_at,
this.type})
: _routes = routes,
super._();

Expand Down Expand Up @@ -276,10 +298,12 @@ class _$LocationJourneyImpl extends _LocationJourney {
final int? created_at;
@override
final int? update_at;
@override
final String? type;

@override
String toString() {
return 'ApiLocationJourney(id: $id, user_id: $user_id, from_latitude: $from_latitude, from_longitude: $from_longitude, to_latitude: $to_latitude, to_longitude: $to_longitude, routes: $routes, route_distance: $route_distance, route_duration: $route_duration, created_at: $created_at, update_at: $update_at)';
return 'ApiLocationJourney(id: $id, user_id: $user_id, from_latitude: $from_latitude, from_longitude: $from_longitude, to_latitude: $to_latitude, to_longitude: $to_longitude, routes: $routes, route_distance: $route_distance, route_duration: $route_duration, created_at: $created_at, update_at: $update_at, type: $type)';
}

@override
Expand All @@ -305,10 +329,11 @@ class _$LocationJourneyImpl extends _LocationJourney {
(identical(other.created_at, created_at) ||
other.created_at == created_at) &&
(identical(other.update_at, update_at) ||
other.update_at == update_at));
other.update_at == update_at) &&
(identical(other.type, type) || other.type == type));
}

@JsonKey(ignore: true)
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
Expand All @@ -322,9 +347,12 @@ class _$LocationJourneyImpl extends _LocationJourney {
route_distance,
route_duration,
created_at,
update_at);
update_at,
type);

@JsonKey(ignore: true)
/// Create a copy of ApiLocationJourney
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LocationJourneyImplCopyWith<_$LocationJourneyImpl> get copyWith =>
Expand All @@ -351,7 +379,8 @@ abstract class _LocationJourney extends ApiLocationJourney {
final double? route_distance,
final int? route_duration,
final int? created_at,
final int? update_at}) = _$LocationJourneyImpl;
final int? update_at,
final String? type}) = _$LocationJourneyImpl;
const _LocationJourney._() : super._();

factory _LocationJourney.fromJson(Map<String, dynamic> json) =
Expand Down Expand Up @@ -380,7 +409,12 @@ abstract class _LocationJourney extends ApiLocationJourney {
@override
int? get update_at;
@override
@JsonKey(ignore: true)
String? get type;

/// Create a copy of ApiLocationJourney
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LocationJourneyImplCopyWith<_$LocationJourneyImpl> get copyWith =>
throw _privateConstructorUsedError;
}
Expand All @@ -394,8 +428,12 @@ mixin _$JourneyRoute {
double get latitude => throw _privateConstructorUsedError;
double get longitude => throw _privateConstructorUsedError;

/// Serializes this JourneyRoute to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)

/// Create a copy of JourneyRoute
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$JourneyRouteCopyWith<JourneyRoute> get copyWith =>
throw _privateConstructorUsedError;
}
Expand All @@ -419,6 +457,8 @@ class _$JourneyRouteCopyWithImpl<$Res, $Val extends JourneyRoute>
// ignore: unused_field
final $Res Function($Val) _then;

/// Create a copy of JourneyRoute
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Expand Down Expand Up @@ -457,6 +497,8 @@ class __$$JourneyRouteImplCopyWithImpl<$Res>
_$JourneyRouteImpl _value, $Res Function(_$JourneyRouteImpl) _then)
: super(_value, _then);

/// Create a copy of JourneyRoute
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Expand Down Expand Up @@ -505,11 +547,13 @@ class _$JourneyRouteImpl implements _JourneyRoute {
other.longitude == longitude));
}

@JsonKey(ignore: true)
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, latitude, longitude);

@JsonKey(ignore: true)
/// Create a copy of JourneyRoute
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$JourneyRouteImplCopyWith<_$JourneyRouteImpl> get copyWith =>
Expand All @@ -535,8 +579,11 @@ abstract class _JourneyRoute implements JourneyRoute {
double get latitude;
@override
double get longitude;

/// Create a copy of JourneyRoute
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(ignore: true)
@JsonKey(includeFromJson: false, includeToJson: false)
_$$JourneyRouteImplCopyWith<_$JourneyRouteImpl> get copyWith =>
throw _privateConstructorUsedError;
}
2 changes: 2 additions & 0 deletions data/lib/api/location/journey/journey.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3606062

Please sign in to comment.