Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide incomplete functions by feature flags #40

Merged
merged 4 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CHANGELOG
=========

➕ New function
🛠 Enhancement changes
🐞 Bug fixing

## Upcoming version ##

**TODO**

## 1.2.0 (2022-xx-xx) ##

**TODO**

## 1.1.0 (2022-xx-xx) ##

**TODO**

## 1.0.0 (2022-xx-xx) ##

**TODO**
4 changes: 4 additions & 0 deletions lib/app/cubit/app_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class AppCubit extends Cubit<AppState> {
emit(AppState.loading());

getThemeUseCase.invoke().listen((theme) {
if (isClosed) {
return;
}

emit(AppState.success(theme));
}).onError((error) => emit(AppState.failure(error)));
}
Expand Down
19 changes: 17 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:geolocator/geolocator.dart';
import 'package:map/generic/generic_map.dart';
import 'package:settings/developer/model/developer_settings_model.dart';
import 'package:settings/developer/repository/developer_settings_repository.dart';
import 'package:settings/settings/settings_page.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:station/repository/station_repository.dart';
Expand Down Expand Up @@ -79,6 +81,8 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
final CameraPosition initialCameraPosition =
CameraPosition(latLng: LatLng(51.2147194, 10.3634281), zoom: 6.0);
final DeveloperSettingsRepository developerSettingsRepository =
LocalDeveloperSettingsRepository();
Set<Marker> _markers = {};
List<StationModel> _stations = [];
Filter _filter = Filter("e5");
Expand All @@ -87,6 +91,7 @@ class _MyHomePageState extends State<MyHomePage> {
bool _showMarkers = true;
CameraPosition? _lastRequestPosition;
CameraPosition? _position;
CameraPosition? _ownPosition;
MapController? _mapController;
bool _isLoading = true;
Exception? _error;
Expand Down Expand Up @@ -448,7 +453,8 @@ class _MyHomePageState extends State<MyHomePage> {
});

GetStationsUseCase getStationsUseCase = GetStationsUseCaseImpl(
TankerkoenigStationRepository(FileConfigRepository()));
TankerkoenigStationRepository(FileConfigRepository()),
LocalDeveloperSettingsRepository());
return getStationsUseCase.invoke(_filter.gas,
CoordinateModel(location.latLng.latitude, location.latLng.longitude));
}
Expand All @@ -467,6 +473,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
_handleCameraPositionUpdate(cameraPosition);
_mapController?.moveCameraToPosition(cameraPosition);
_ownPosition = cameraPosition;
return locationData;
}

Expand Down Expand Up @@ -537,6 +544,14 @@ class _MyHomePageState extends State<MyHomePage> {
return;
}

// Allow fetching without location only with enabled flag
DeveloperSettingsModel developerSettings =
await developerSettingsRepository.get().first;
CameraPosition position = _ownPosition!;
if (developerSettings.isFetchingWithoutLocationEnabled) {
position = _position!;
}

// Fetch new stations only if we move camera by 8 kilometers
if (!force && _lastRequestPosition != null) {
double movementDistance = Geolocator.distanceBetween(
Expand All @@ -549,7 +564,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

_requestStations(_position!)
_requestStations(position)
.then((stations) {
_lastRequestPosition = _position;
_stations = stations;
Expand Down
4 changes: 4 additions & 0 deletions map/lib/cubit/map_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class MapCubit extends Cubit<MapState> {
emit(MapState.loading());

getMapProviderUseCase.invoke().listen((mapProvider) {
if (isClosed) {
return;
}

emit(MapState.success(mapProvider));
}).onError((error) => emit(MapState.failure(error)));
}
Expand Down
4 changes: 4 additions & 0 deletions settings/lib/developer/ui/cubit/developer_card_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class DeveloperCardCubit extends Cubit<DeveloperCardState> {
emit(DeveloperCardState.loading());

getDeveloperSettingsUseCase.invoke().listen((developerSettings) {
if (isClosed) {
return;
}

emit(DeveloperCardState.success(developerSettings.isDeveloperModeEnabled,
developerSettings.mapProvider));
}).onError((error) => emit(DeveloperCardState.failure(error)));
Expand Down
4 changes: 4 additions & 0 deletions settings/lib/feature/cubit/feature_settings_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class FeatureSettingsCubit extends Cubit<FeatureSettingsState> {
emit(FeatureSettingsState.loading());

getDeveloperSettingsUseCase.invoke().listen((developerSettings) {
if (isClosed) {
return;
}

emit(FeatureSettingsState.success(
developerSettings.isFetchingWithoutLocationEnabled,
developerSettings.isPercentagePriceRangesEnabled));
Expand Down
4 changes: 4 additions & 0 deletions settings/lib/theme/ui/cubit/theme_item_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ThemeItemCubit extends Cubit<ThemeItemState> {
emit(ThemeItemState.loading());

getThemeUseCase.invoke().listen((theme) {
if (isClosed) {
return;
}

String label;
if (theme == ThemeMode.light) {
label = "Hell";
Expand Down
76 changes: 53 additions & 23 deletions station/lib/usecase/get_stations_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:navigation/coordinate_model.dart';
import 'package:settings/developer/repository/developer_settings_repository.dart';
import 'package:station/repository/station_repository.dart';
import 'package:station/station_model.dart';

Expand All @@ -10,37 +11,41 @@ abstract class GetStationsUseCase {

class GetStationsUseCaseImpl extends GetStationsUseCase {
final StationRepository _stationRepository;
final DeveloperSettingsRepository _developerSettingsRepository;

GetStationsUseCaseImpl(this._stationRepository);
GetStationsUseCaseImpl(
this._stationRepository, this._developerSettingsRepository);

@override
Future<List<StationModel>> invoke(
String type, CoordinateModel position) async {
List<StationPricesModel> minMaxPrices = await _fetchMinMaxPrices(type, position);
List<StationPricesModel> minMaxPrices =
await _fetchMinMaxPrices(type, position);
StationPricesModel minPrices = minMaxPrices[0];
StationPricesModel maxPrices = minMaxPrices[1];

return _stationRepository.list(type, position, 15).then((stations) {
return stations
.map((station) => StationModel(
station.id,
station.name,
station.company,
station.address,
StationPricesModel(
station.prices.e5,
_getPriceRange(minPrices.e5, maxPrices.e5, station.prices.e5),
station.prices.e10,
_getPriceRange(
minPrices.e10, maxPrices.e10, station.prices.e10),
station.prices.diesel,
_getPriceRange(
minPrices.diesel, maxPrices.diesel, station.prices.diesel),
),
station.coordinate,
station.openTimes,
station.isOpen))
.toList();
return Future.wait(stations.map((station) async {
return StationModel(
station.id,
station.name,
station.company,
station.address,
StationPricesModel(
station.prices.e5,
await _getPriceRange(
minPrices.e5, maxPrices.e5, station.prices.e5),
station.prices.e10,
await _getPriceRange(
minPrices.e10, maxPrices.e10, station.prices.e10),
station.prices.diesel,
await _getPriceRange(
minPrices.diesel, maxPrices.diesel, station.prices.diesel),
),
station.coordinate,
station.openTimes,
station.isOpen);
}).toList());
});
}

Expand Down Expand Up @@ -75,7 +80,32 @@ class GetStationsUseCaseImpl extends GetStationsUseCase {
});
}

StationPriceRange _getPriceRange(
Future<StationPriceRange> _getPriceRange(
double minPrice, double maxPrice, double price) {
return _developerSettingsRepository.get().first.then((developerSettings) {
if (developerSettings.isPercentagePriceRangesEnabled) {
return _getPriceRangePercentage(minPrice, maxPrice, price);
} else {
return _getPriceRangeRelative(minPrice, price);
}
});
}

StationPriceRange _getPriceRangeRelative(double minPrice, double price) {
if (price == 0.0) {
return StationPriceRange.unknown;
}

if (minPrice + 0.04 >= price) {
return StationPriceRange.cheap;
} else if (minPrice + 0.10 >= price) {
return StationPriceRange.normal;
} else {
return StationPriceRange.expensive;
}
}

StationPriceRange _getPriceRangePercentage(
double minPrice, double maxPrice, double price) {
if (price == 0.0) {
return StationPriceRange.unknown;
Expand Down
3 changes: 3 additions & 0 deletions station/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ dependencies:
navigation:
path: '../navigation'

settings:
path: '../settings'

# BLoC - https://pub.dev/packages/flutter_bloc
flutter_bloc: ^8.0.1

Expand Down