Skip to content

Commit

Permalink
rename eco range to device range (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: alexandre_poichet <[email protected]>
  • Loading branch information
apoichet and alexandre_poichet authored Oct 18, 2024
1 parent 32d7bac commit a837552
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ also to offer a less energy-consuming app.
| Free Memory | Yes | Yes | X | |
| Total Storage | Yes | Yes | X | |
| Free Storage | Yes | Yes | X | |
| <span style="color: #3CB371">**Eco Range**</span> | <span style="color: #3CB371">Yes</span> | <span style="color: #3CB371">Yes</span> | <span style="color: #3CB371">X</span> | <span style="color: #3CB371">X</span> |
| <span style="color: #3CB371">**Device Range**</span> | <span style="color: #3CB371">Yes</span> | <span style="color: #3CB371">Yes</span> | <span style="color: #3CB371">X</span> | <span style="color: #3CB371">X</span> |
| Battery Thermal State | Yes | Yes | X | |
| Battery State | Yes | Yes | X | X |
| Battery Level | Yes | Yes | X | X |
Expand All @@ -42,7 +42,7 @@ also to offer a less energy-consuming app.

## Eco Mode

### Eco Range
### Device Range
This feature gives the possibility to calculate a score for the device.
The score does NOT represent an ecological performance.
It's just a score to determine the device's capacities.
Expand Down
2 changes: 1 addition & 1 deletion example/lib/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension FlutterEcoModeExtension on FlutterEcoMode {
.map((value) => value > 0 ? "${value.toInt()} %" : "not reachable");
}

extension FutureEcoRangeExtension on Future<EcoRange?> {
extension FutureEcoRangeExtension on Future<DeviceRange?> {
Future<String?> getScore() => then((value) =>
value?.score != null ? "${(value!.score * 100).toInt()}/100" : null);

Expand Down
14 changes: 7 additions & 7 deletions example/lib/low_end_device/low_end_device_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class LowEndDevicePage extends StatefulWidget {
}

class _LowEndDevicePageState extends State<LowEndDevicePage> {
late Future<EcoRange?> ecoRange;
late Future<DeviceRange?> deviceRange;

@override
void initState() {
super.initState();
ecoRange = widget.ecoMode.getEcoRange();
deviceRange = widget.ecoMode.getDeviceRange();
}

@override
Expand Down Expand Up @@ -51,22 +51,22 @@ class _LowEndDevicePageState extends State<LowEndDevicePage> {
future: widget.ecoMode.getFreeStorage,
),
ResultLine(
label: 'Eco range score',
label: 'Device range score',
labelColor: Colors.blue,
valueColor: Colors.blue,
future: ecoRange.getScore,
future: deviceRange.getScore,
),
ResultLine(
label: 'Device eco range',
label: 'Device range',
labelColor: Colors.blue,
valueColor: Colors.blue,
future: ecoRange.getRange,
future: deviceRange.getRange,
),
ResultLine(
label: 'Is low end device',
labelColor: Colors.purple,
valueColor: Colors.purple,
future: ecoRange.isLowEndDevice,
future: deviceRange.isLowEndDevice,
),
],
);
Expand Down
6 changes: 3 additions & 3 deletions lib/flutter_eco_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ class FlutterEcoMode extends FlutterEcoModePlatform {
}

@override
Future<EcoRange?> getEcoRange() async {
return _api.getEcoScore().then<EcoRange?>((value) {
Future<DeviceRange?> getDeviceRange() async {
return _api.getEcoScore().then<DeviceRange?>((value) {
if (value == null) {
throw Exception('Error while getting eco score');
}
final range = _buildRange(value);
return EcoRange(
return DeviceRange(
score: value,
range: range,
isLowEndDevice: range == DeviceEcoRange.lowEnd);
Expand Down
6 changes: 3 additions & 3 deletions lib/flutter_eco_mode_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ abstract class FlutterEcoModePlatform extends PlatformInterface {
Stream<bool?> get isBatteryEcoModeStream;

/// Return the eco range.
Future<EcoRange?> getEcoRange();
Future<DeviceRange?> getDeviceRange();
}

class EcoRange {
class DeviceRange {
double score;
DeviceEcoRange range;
bool isLowEndDevice;

EcoRange({
DeviceRange({
required this.score,
required this.range,
this.isLowEndDevice = false,
Expand Down
30 changes: 15 additions & 15 deletions test/flutter_eco_mode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,45 +174,45 @@ void main() {
});

group(
'getEcoRange',
'getDeviceRange',
() {
test('should return null when get eco score error', () async {
when(() => ecoModeApi.getEcoScore())
.thenAnswer((_) => Future.error('error eco score'));
expect(await buildEcoMode().getEcoRange(), null);
expect(await buildEcoMode().getDeviceRange(), null);
});

test('should return null when get eco score null', () async {
when(() => ecoModeApi.getEcoScore())
.thenAnswer((_) => Future.value(null));
expect(await buildEcoMode().getEcoRange(), null);
expect(await buildEcoMode().getDeviceRange(), null);
});

test('should return low end device', () async {
when(() => ecoModeApi.getEcoScore())
.thenAnswer((_) => Future.value(minScoreLowEndDevice));
final ecoRange = await buildEcoMode().getEcoRange();
expect(ecoRange!.score, minScoreLowEndDevice);
expect(ecoRange.range, DeviceEcoRange.lowEnd);
expect(ecoRange.isLowEndDevice, true);
final deviceRange = await buildEcoMode().getDeviceRange();
expect(deviceRange!.score, minScoreLowEndDevice);
expect(deviceRange.range, DeviceEcoRange.lowEnd);
expect(deviceRange.isLowEndDevice, true);
});

test('should return mid range device', () async {
when(() => ecoModeApi.getEcoScore())
.thenAnswer((_) => Future.value(minScoreMidRangeDevice));
final ecoRange = await buildEcoMode().getEcoRange();
expect(ecoRange!.score, minScoreMidRangeDevice);
expect(ecoRange.range, DeviceEcoRange.midRange);
expect(ecoRange.isLowEndDevice, false);
final deviceRange = await buildEcoMode().getDeviceRange();
expect(deviceRange!.score, minScoreMidRangeDevice);
expect(deviceRange.range, DeviceEcoRange.midRange);
expect(deviceRange.isLowEndDevice, false);
});

test('should return high end device', () async {
when(() => ecoModeApi.getEcoScore())
.thenAnswer((_) => Future.value(minScoreMidRangeDevice + 0.1));
final ecoRange = await buildEcoMode().getEcoRange();
expect(ecoRange!.score, minScoreMidRangeDevice + 0.1);
expect(ecoRange.range, DeviceEcoRange.highEnd);
expect(ecoRange.isLowEndDevice, false);
final deviceRange = await buildEcoMode().getDeviceRange();
expect(deviceRange!.score, minScoreMidRangeDevice + 0.1);
expect(deviceRange.range, DeviceEcoRange.highEnd);
expect(deviceRange.isLowEndDevice, false);
});
},
);
Expand Down

0 comments on commit a837552

Please sign in to comment.