Skip to content

Commit

Permalink
replace location with non-google dependent geolocator
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed May 29, 2024
1 parent 7ebab0a commit d9e8d67
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
68 changes: 37 additions & 31 deletions lib/ui/locations/check_in/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:geolocator/geolocator.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:location/location.dart';

import '../../../data/models/contact_location.dart';
import '../../../data/repositories/contacts.dart';
Expand All @@ -29,47 +28,54 @@ class CheckInCubit extends Cubit<CheckInState> {
required DateTime end}) async {
emit(state.copyWith(checkingIn: true));

// TODO: Add timeout?
final location = await Location().getLocation();
if (location.longitude == null || location.latitude == null) {
final profileContact = contactsRepository.getProfileContact();
if (profileContact == null) {
if (!isClosed) {
//TODO: Emit failure state
emit(state.copyWith(checkingIn: false));
}
return;
}

final profileContact = contactsRepository.getProfileContact();
if (profileContact == null) {
try {
final location =
await Geolocator.getCurrentPosition(timeLimit: Duration(seconds: 30));

// TODO: Switch to unawaited because it'll be synced eventually?
await contactsRepository
.updateContact(profileContact.copyWith(temporaryLocations: [
...profileContact.temporaryLocations
.map((l) => l.copyWith(checkedIn: false)),
ContactTemporaryLocation(
coagContactId: contactsRepository.profileContactId!,
longitude: location.longitude,
latitude: location.latitude,
start: DateTime.now(),
name: name,
details: details,
end: end,
circles: circles,
checkedIn: true)
]))
// Make sure to regenerate the sharing profiles and update DHT sharing records
.then((_) => contactsRepository
.updateProfileContact(profileContact.coagContactId));

if (!isClosed) {
emit(state.copyWith(checkingIn: false));
}
} on TimeoutException {
if (!isClosed) {
//TODO: Emit failure state
emit(state.copyWith(checkingIn: false));
}
return;
} on LocationServiceDisabledException {
if (!isClosed) {
//TODO: Emit failure state
emit(state.copyWith(checkingIn: false));
}
return;
}

// TODO: Switch to unawaited because it'll be synced eventually?
await contactsRepository
.updateContact(profileContact.copyWith(temporaryLocations: [
...profileContact.temporaryLocations
.map((l) => l.copyWith(checkedIn: false)),
ContactTemporaryLocation(
coagContactId: contactsRepository.profileContactId!,
longitude: location.longitude!,
latitude: location.latitude!,
start: DateTime.now(),
name: name,
details: details,
end: end,
circles: circles,
checkedIn: true)
]))
// Make sure to regenerate the sharing profiles and update DHT sharing records
.then((_) => contactsRepository
.updateProfileContact(profileContact.coagContactId));

if (!isClosed) {
emit(state.copyWith(checkingIn: false));
}
}
}
1 change: 0 additions & 1 deletion lib/ui/locations/schedule/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:latlong2/latlong.dart';
import 'package:location/location.dart';

import '../../../data/models/contact_location.dart';
import '../../../data/repositories/contacts.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/map/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension MapStatusX on MapStatus {
bool get isDenied => this == MapStatus.denied;
}

enum MarkerType { address, temporary }
enum MarkerType { address, temporary, checkedIn }

// TODO: Add color or indicator whether it's a contact or profile location
@JsonSerializable()
Expand Down

0 comments on commit d9e8d67

Please sign in to comment.