Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #39 from Myzel394/remove-gms
Browse files Browse the repository at this point in the history
Remove gms
  • Loading branch information
Myzel394 authored Jun 5, 2023
2 parents 14991f7 + 3d05878 commit 9a1d336
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 255 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ dependencies {

// Remove this for FLOSS version
//f configurations.all {
//f exclude group: 'com.google.android.gms', module: 'play-services-base'
//f exclude group: 'com.google.android.gms'
//f }
2 changes: 2 additions & 0 deletions lib/constants/values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ const LOCATION_INTERVAL = Duration(minutes: 2);

const TRANSFER_DATA_USERNAME = "locus_transfer";
final TRANSFER_SUCCESS_MESSAGE = Uint8List.fromList([1, 2, 3, 4]);

const CURRENT_APP_VERSION = "0.7.0";
16 changes: 5 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'dart:io';
import 'package:disable_battery_optimization/disable_battery_optimization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:geolocator/geolocator.dart';
import 'package:locus/App.dart';
import 'package:locus/services/app_update_service.dart';
import 'package:locus/services/log_service.dart';
Expand All @@ -13,7 +13,6 @@ import 'package:locus/services/settings_service.dart';
import 'package:locus/services/task_service.dart';
import 'package:locus/services/view_service.dart';
import 'package:locus/utils/permission.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';

const storage = FlutterSecureStorage();
Expand All @@ -27,19 +26,16 @@ void main() async {
]);

final futures = await Future.wait<dynamic>([
Permission.locationAlways.isGranted,
Geolocator.checkPermission(),
TaskService.restore(),
ViewService.restore(),
Platform.isAndroid
? DisableBatteryOptimization.isBatteryOptimizationDisabled
: Future.value(true),
Platform.isAndroid ? DisableBatteryOptimization.isBatteryOptimizationDisabled : Future.value(true),
SettingsService.restore(),
hasGrantedNotificationPermission(),
LogService.restore(),
AppUpdateService.restore(),
FlutterMapTileCaching.initialise(),
]);
final bool hasLocationAlwaysGranted = futures[0];
final bool hasLocationAlwaysGranted = futures[0] == LocationPermission.always;
final TaskService taskService = futures[1];
final ViewService viewService = futures[2];
final bool isIgnoringBatteryOptimizations = futures[3];
Expand All @@ -49,7 +45,6 @@ void main() async {
final AppUpdateService appUpdateService = futures[7];

await logService.deleteOldLogs();
await FMTC.instance('mapStore').manage.createAsync();

appUpdateService.checkForUpdates(force: true);

Expand All @@ -60,8 +55,7 @@ void main() async {
ChangeNotifierProvider<ViewService>(create: (_) => viewService),
ChangeNotifierProvider<SettingsService>(create: (_) => settingsService),
ChangeNotifierProvider<LogService>(create: (_) => logService),
ChangeNotifierProvider<AppUpdateService>(
create: (_) => appUpdateService),
ChangeNotifierProvider<AppUpdateService>(create: (_) => appUpdateService),
],
child: App(
hasLocationAlwaysGranted: hasLocationAlwaysGranted,
Expand Down
17 changes: 9 additions & 8 deletions lib/screens/LocationPointsDetailsScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ class LocationPointsDetailsScreen extends StatelessWidget {
if (isPreview) {
return Column(
children: <Widget>[
Text(
l10n.taskDetails_summary(
locations.length,
locations.first.createdAt,
locations.last.createdAt,
if (locations.isNotEmpty)
Text(
l10n.taskDetails_summary(
locations.length,
locations.first.createdAt,
locations.last.createdAt,
),
style: getCaptionTextStyle(context),
textAlign: TextAlign.center,
),
style: getCaptionTextStyle(context),
textAlign: TextAlign.center,
),
const SizedBox(
height: SMALL_SPACE,
),
Expand Down
171 changes: 52 additions & 119 deletions lib/screens/SettingsScreen.dart

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions lib/screens/welcome_screen_widgets/LocationPermissionScreen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:geolocator/geolocator.dart';
import 'package:locus/screens/welcome_screen_widgets/SimpleContinuePage.dart';
import 'package:locus/utils/theme.dart';
import 'package:lottie/lottie.dart';
Expand All @@ -13,30 +14,25 @@ class LocationPermissionScreen extends StatelessWidget {
Key? key,
}) : super(key: key);

Future<PermissionStatus> _checkPermission(
{bool withoutRequest = false}) async {
var alwaysPermission = await Permission.locationAlways.status;
Future<bool> _checkPermission() async {
final alwaysPermission = await Geolocator.checkPermission();

// We first need to request locationWhenInUse, because it is required to request locationAlways
if (alwaysPermission.isGranted == false) {
var whenInUsePermission = await Permission.locationWhenInUse.status;
if (whenInUsePermission.isGranted == false && !withoutRequest) {
whenInUsePermission = await Permission.locationWhenInUse.request();
if (whenInUsePermission.isGranted == false) {
return whenInUsePermission;
}
if (alwaysPermission != LocationPermission.always) {
final whenInUse = await Geolocator.requestPermission();

if (whenInUse != LocationPermission.whileInUse) {
return false;
}
}

if (alwaysPermission.isGranted == false && !withoutRequest) {
alwaysPermission = await Permission.locationAlways.request();
final always = await Geolocator.requestPermission();

if (alwaysPermission.isGranted == false) {
return alwaysPermission;
if (always != LocationPermission.always) {
return false;
}
}

return alwaysPermission;
return true;
}

@override
Expand Down Expand Up @@ -72,7 +68,7 @@ class LocationPermissionScreen extends StatelessWidget {
),
onContinue: () async {
final permission = await _checkPermission();
if (permission.isGranted) {
if (permission) {
onGranted();
} else {
await openAppSettings();
Expand Down
7 changes: 1 addition & 6 deletions lib/services/app_update_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:locus/constants/values.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:version/version.dart';

Expand Down Expand Up @@ -54,11 +53,7 @@ class AppUpdateService extends ChangeNotifier {

bool get isUpdateAvailable => _isUpdateAvailable;

Future<Version> getCurrentVersion() async {
final packageInfo = await PackageInfo.fromPlatform();

return Version.parse(packageInfo.version);
}
Future<Version> getCurrentVersion() async => Version.parse(CURRENT_APP_VERSION);

Future<void> checkForUpdates({final bool force = false}) async {
if (_outDateDate != null && !force) {
Expand Down
6 changes: 2 additions & 4 deletions lib/utils/import_export_handler.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:locus/constants/values.dart';
import 'package:locus/services/settings_service.dart';
import 'package:locus/services/task_service.dart';
import 'package:locus/services/view_service.dart';
import 'package:package_info_plus/package_info_plus.dart';

Future<Map<String, dynamic>> exportToJSON(
final TaskService taskService,
Expand All @@ -19,7 +19,5 @@ Future<Map<String, dynamic>> exportToJSON(

Future<String> getBluetoothServiceID() async {
// We use a different service id for each version of the app, so that the user has the same version on both devices
final packageInfo = await PackageInfo.fromPlatform();

return "locus-import-export-transfer-${packageInfo.version}";
return "locus-import-export-transfer-$CURRENT_APP_VERSION";
}
6 changes: 6 additions & 0 deletions lib/utils/permission.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:locus/constants/app.dart';
import 'package:permission_handler/permission_handler.dart';

Future<bool> hasOSNotificationPermission() async {
if (!Platform.isAndroid) {
return false;
}

if (isFLOSSFlavor) {
// GMS not available
return false;
}

final androidInfo = await DeviceInfoPlugin().androidInfo;

return androidInfo.version.sdkInt >= 33;
Expand Down
29 changes: 9 additions & 20 deletions lib/widgets/LocationsMap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:apple_maps_flutter/apple_maps_flutter.dart' as AppleMaps;
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';

// Provided by the flutter_map package
import 'package:latlong2/latlong.dart';
import 'package:locus/services/settings_service.dart';
Expand All @@ -25,8 +25,7 @@ class LocationsMapController extends ChangeNotifier {

// To inform our wrappers to update the map, we use a stream.
// This emits event to which our wrappers listen to.
final StreamController<Map<String, dynamic>> _eventEmitter =
StreamController.broadcast();
final StreamController<Map<String, dynamic>> _eventEmitter = StreamController.broadcast();

LocationsMapController({
List<LocationPointService>? locations,
Expand All @@ -43,8 +42,7 @@ class LocationsMapController extends ChangeNotifier {

bool get useAppleMaps => Platform.isIOS;

UnmodifiableListView<LocationPointService> get locations =>
UnmodifiableListView(_locations);
UnmodifiableListView<LocationPointService> get locations => UnmodifiableListView(_locations);

@override
void dispose() {
Expand Down Expand Up @@ -80,8 +78,7 @@ class LocationsMapController extends ChangeNotifier {
}

// Groups the locations by hour and returns a map of the hour and the number of locations in that hour.
Map<DateTime, List<LocationPointService>> getLocationsPerHour() =>
locations.fold(
Map<DateTime, List<LocationPointService>> getLocationsPerHour() => locations.fold(
{},
(final Map<DateTime, List<LocationPointService>> value, element) {
final date = normalizeDateTime(element.createdAt);
Expand Down Expand Up @@ -126,8 +123,7 @@ class _LocationsMapState extends State<LocationsMap> {
AppleMaps.AppleMapController? appleMapsController;
MapController? flutterMapController;

static toAppleCoordinate(final LatLng latLng) =>
AppleMaps.LatLng(latLng.latitude, latLng.longitude);
static toAppleCoordinate(final LatLng latLng) => AppleMaps.LatLng(latLng.latitude, latLng.longitude);

bool get shouldUseAppleMaps {
final settings = context.watch<SettingsService>();
Expand All @@ -138,14 +134,9 @@ class _LocationsMapState extends State<LocationsMap> {
String get snippetText {
final location = widget.controller.locations.last;

final batteryInfo = location.batteryLevel == null
? ""
: "Battery at ${(location.batteryLevel! * 100).ceil()}%";
final dateInfo =
"Date: ${DateFormat.yMd().add_jm().format(location.createdAt)}";
final speedInfo = location.speed == null
? ""
: "Moving at ${(location.speed!.abs() * 3.6).ceil()} km/h";
final batteryInfo = location.batteryLevel == null ? "" : "Battery at ${(location.batteryLevel! * 100).ceil()}%";
final dateInfo = "Date: ${DateFormat.yMd().add_jm().format(location.createdAt)}";
final speedInfo = location.speed == null ? "" : "Moving at ${(location.speed!.abs() * 3.6).ceil()} km/h";

return [
batteryInfo,
Expand All @@ -158,8 +149,7 @@ class _LocationsMapState extends State<LocationsMap> {
void initState() {
super.initState();

_controllerSubscription =
widget.controller.eventListener.listen(eventEmitterListener);
_controllerSubscription = widget.controller.eventListener.listen(eventEmitterListener);

if (widget.initWithUserPosition) {
fetchUserPosition();
Expand Down Expand Up @@ -292,7 +282,6 @@ class _LocationsMapState extends State<LocationsMap> {
urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: const ['a', 'b', 'c'],
userAgentPackageName: "app.myzel394.locus",
tileProvider: FMTC.instance('mapStore').getTileProvider(),
),
CircleLayer(
circles: widget.controller.locations
Expand Down
Loading

0 comments on commit 9a1d336

Please sign in to comment.