From 70ec8a79a121471a004e7e4c23157d10157e136f Mon Sep 17 00:00:00 2001 From: Lisandro Pérez Meyer Date: Tue, 14 Nov 2023 17:20:58 -0300 Subject: Initial cleanup push. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on agldemo2024 on commit 2a5dc04d801134338150c3f6afc67eaa65599763 Disable device preview. Disable Lottie animation. The original commit was b3c493c340fcb4bb0a937692838fc830bec3e9ea but I am just keeping this change, because the json did not really needed to change. I think. Signed-off-by: Lisandro Pérez Meyer --- lib/data/models/audio.dart | 84 +++++++++++ lib/data/models/connections_signals.dart | 92 ++++++++++++ lib/data/models/date_time.dart | 59 ++++++++ lib/data/models/hybrid.dart | 98 +++++++++++++ lib/data/models/units.dart | 45 ++++++ lib/data/models/user.dart | 54 +++++++ lib/data/models/users.dart | 64 +++++++++ lib/data/models/vehicle.dart | 233 +++++++++++++++++++++++++++++++ 8 files changed, 729 insertions(+) create mode 100644 lib/data/models/audio.dart create mode 100644 lib/data/models/connections_signals.dart create mode 100644 lib/data/models/date_time.dart create mode 100644 lib/data/models/hybrid.dart create mode 100644 lib/data/models/units.dart create mode 100644 lib/data/models/user.dart create mode 100644 lib/data/models/users.dart create mode 100644 lib/data/models/vehicle.dart (limited to 'lib/data/models') diff --git a/lib/data/models/audio.dart b/lib/data/models/audio.dart new file mode 100644 index 0000000..69df18b --- /dev/null +++ b/lib/data/models/audio.dart @@ -0,0 +1,84 @@ +import 'dart:convert'; + +import 'package:flutter_ics_homescreen/export.dart'; + +@immutable +class Audio { + final double volume; + final double treble; + final double bass; + final double rearFront; + const Audio({ + required this.volume, + required this.treble, + required this.bass, + required this.rearFront, + }); + + const Audio.initial() + : volume = 5.0, + treble = 5.0, + bass = 5.0, + rearFront = 5.0; + + + Audio copyWith({ + double? volume, + double? treble, + double? bass, + double? rearFront, + }) { + return Audio( + volume: volume ?? this.volume, + treble: treble ?? this.treble, + bass: bass ?? this.bass, + rearFront: rearFront ?? this.rearFront, + ); + } + + Map toMap() { + return { + 'volume': volume, + 'treble': treble, + 'bass': bass, + 'rearFront': rearFront, + }; + } + + factory Audio.fromMap(Map map) { + return Audio( + volume: map['volume']?.toDouble() ?? 0.0, + treble: map['treble']?.toDouble() ?? 0.0, + bass: map['bass']?.toDouble() ?? 0.0, + rearFront: map['rearFront']?.toDouble() ?? 0.0, + ); + } + + String toJson() => json.encode(toMap()); + + factory Audio.fromJson(String source) => Audio.fromMap(json.decode(source)); + + @override + String toString() { + return 'Audio(volume: $volume, treble: $treble, bass: $bass, rearFront: $rearFront)'; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Audio && + other.volume == volume && + other.treble == treble && + other.bass == bass && + other.rearFront == rearFront; + } + + @override + int get hashCode { + return volume.hashCode ^ + treble.hashCode ^ + bass.hashCode ^ + rearFront.hashCode; + } +} diff --git a/lib/data/models/connections_signals.dart b/lib/data/models/connections_signals.dart new file mode 100644 index 0000000..cd6d695 --- /dev/null +++ b/lib/data/models/connections_signals.dart @@ -0,0 +1,92 @@ +import 'dart:convert'; + +import 'package:flutter_ics_homescreen/export.dart'; + +@immutable +class Signals { + final bool isBluetoothConnected; + final bool isDataConnected; + final bool isWifiConnected; + final int dataSignalStrenght; + final int wifiSignalStrenght; + const Signals({ + required this.isBluetoothConnected, + required this.isDataConnected, + required this.isWifiConnected, + required this.dataSignalStrenght, + required this.wifiSignalStrenght, + }); + const Signals.initial() + : isBluetoothConnected = false, + isDataConnected = false, + isWifiConnected = false, + dataSignalStrenght = 0, + wifiSignalStrenght = 0; + + Signals copyWith({ + bool? isBluetoothConnected, + bool? isDataConnected, + bool? isWifiConnected, + int? dataSignalStrenght, + int? wifiSignalStrenght, + }) { + return Signals( + isBluetoothConnected: isBluetoothConnected ?? this.isBluetoothConnected, + isDataConnected: isDataConnected ?? this.isDataConnected, + isWifiConnected: isWifiConnected ?? this.isWifiConnected, + dataSignalStrenght: dataSignalStrenght ?? this.dataSignalStrenght, + wifiSignalStrenght: wifiSignalStrenght ?? this.wifiSignalStrenght, + ); + } + + Map toMap() { + return { + 'isBluetoothConnected': isBluetoothConnected, + 'isDataConnected': isDataConnected, + 'isWifiConnected': isWifiConnected, + 'dataSignalStrenght': dataSignalStrenght, + 'wifiSignalStrenght': wifiSignalStrenght, + }; + } + + factory Signals.fromMap(Map map) { + return Signals( + isBluetoothConnected: map['isBluetoothConnected'] ?? false, + isDataConnected: map['isDataConnected'] ?? false, + isWifiConnected: map['isWifiConnected'] ?? false, + dataSignalStrenght: map['dataSignalStrenght']?.toInt() ?? 0, + wifiSignalStrenght: map['wifiSignalStrenght']?.toInt() ?? 0, + ); + } + + String toJson() => json.encode(toMap()); + + factory Signals.fromJson(String source) => + Signals.fromMap(json.decode(source)); + + @override + String toString() { + return 'Signals(isBluetoothConnected: $isBluetoothConnected, isDataConnected: $isDataConnected, isWifiConnected: $isWifiConnected, dataSignalStrenght: $dataSignalStrenght, wifiSignalStrenght: $wifiSignalStrenght)'; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Signals && + other.isBluetoothConnected == isBluetoothConnected && + other.isDataConnected == isDataConnected && + other.isWifiConnected == isWifiConnected && + other.dataSignalStrenght == dataSignalStrenght && + other.wifiSignalStrenght == wifiSignalStrenght; + } + + @override + int get hashCode { + return isBluetoothConnected.hashCode ^ + isDataConnected.hashCode ^ + isWifiConnected.hashCode ^ + dataSignalStrenght.hashCode ^ + wifiSignalStrenght.hashCode; + } +} diff --git a/lib/data/models/date_time.dart b/lib/data/models/date_time.dart new file mode 100644 index 0000000..62d7743 --- /dev/null +++ b/lib/data/models/date_time.dart @@ -0,0 +1,59 @@ +import 'dart:convert'; + +import 'package:flutter_ics_homescreen/export.dart'; +import 'package:intl/intl.dart'; + +@immutable +class DateAndTime { + final String date; + final String time; + const DateAndTime({ + required this.date, + required this.time, + }); + + DateAndTime.initial() + : date = DateFormat().add_yMMMMd().format(DateTime.now()), + time = DateFormat('hh:mm a').format(DateTime.now()); + DateAndTime copyWith({ + String? date, + String? time, + }) { + return DateAndTime( + date: date ?? this.date, + time: time ?? this.time, + ); + } + + Map toMap() { + return { + 'date': date, + 'time': time, + }; + } + + factory DateAndTime.fromMap(Map map) { + return DateAndTime( + date: map['date'], + time: map['time'], + ); + } + + String toJson() => json.encode(toMap()); + + factory DateAndTime.fromJson(String source) => + DateAndTime.fromMap(json.decode(source)); + + @override + String toString() => 'DateAndTime(date: $date, time: $time)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is DateAndTime && other.date == date && other.time == time; + } + + @override + int get hashCode => date.hashCode ^ time.hashCode; +} diff --git a/lib/data/models/hybrid.dart b/lib/data/models/hybrid.dart new file mode 100644 index 0000000..d567f14 --- /dev/null +++ b/lib/data/models/hybrid.dart @@ -0,0 +1,98 @@ +enum HybridState { + idle, + engineOutput, + regenerativeBreaking, + baterryOutput, +} + +enum ArrowState { blue, red, green, yellow } + +enum BatteryState { white, red, green, yellow, orange } + +class Hybrid { + final HybridState hybridState; + final ArrowState topArrowState; + final ArrowState leftArrowState; + final ArrowState rightArrowState; + final BatteryState batteryState; + Hybrid({ + required this.hybridState, + required this.topArrowState, + required this.leftArrowState, + required this.rightArrowState, + required this.batteryState, + }); + + const Hybrid.initial() + : hybridState = HybridState.idle, + topArrowState = ArrowState.blue, + leftArrowState = ArrowState.blue, + rightArrowState = ArrowState.blue, + batteryState = BatteryState.white; + + Hybrid copyWith({ + HybridState? hybridState, + ArrowState? topArrowState, + ArrowState? leftArrowState, + ArrowState? rightArrowState, + BatteryState? batteryState, + }) { + return Hybrid( + hybridState: hybridState ?? this.hybridState, + topArrowState: topArrowState ?? this.topArrowState, + leftArrowState: leftArrowState ?? this.leftArrowState, + rightArrowState: rightArrowState ?? this.rightArrowState, + batteryState: batteryState ?? this.batteryState, + ); + } + + // Map toMap() { + // return { + // 'hybridState': hybridState.toMap(), + // 'topArrowState': topArrowState.toMap(), + // 'leftArrowState': leftArrowState.toMap(), + // 'rightArrowState': rightArrowState.toMap(), + // 'batteryState': batteryState.toMap(), + // }; + // } + + // factory Hybrid.fromMap(Map map) { + // return Hybrid( + // hybridState: HybridState.fromMap(map['hybridState']), + // topArrowState: ArrowState.fromMap(map['topArrowState']), + // leftArrowState: ArrowState.fromMap(map['leftArrowState']), + // rightArrowState: ArrowState.fromMap(map['rightArrowState']), + // batteryState: BatteryState.fromMap(map['batteryState']), + // ); + // } + + // String toJson() => json.encode(toMap()); + + // factory Hybrid.fromJson(String source) => Hybrid.fromMap(json.decode(source)); + + @override + String toString() { + return 'Hybrid(hybridState: $hybridState, topArrowState: $topArrowState, leftArrowState: $leftArrowState, rightArrowState: $rightArrowState, batteryState: $batteryState)'; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Hybrid && + other.hybridState == hybridState && + other.topArrowState == topArrowState && + other.leftArrowState == leftArrowState && + other.rightArrowState == rightArrowState && + other.batteryState == batteryState; + } + + @override + int get hashCode { + return hybridState.hashCode ^ + topArrowState.hashCode ^ + leftArrowState.hashCode ^ + rightArrowState.hashCode ^ + batteryState.hashCode; + } +} diff --git a/lib/data/models/units.dart b/lib/data/models/units.dart new file mode 100644 index 0000000..9e71213 --- /dev/null +++ b/lib/data/models/units.dart @@ -0,0 +1,45 @@ +import '../../export.dart'; + +enum DistanceUnit { kilometers, miles } + +enum TemperatureUnit { celsius, fahrenheit } + +@immutable +class Units { + final DistanceUnit distanceUnit; + final TemperatureUnit temperatureUnit; + + const Units( + this.distanceUnit, + this.temperatureUnit, + ); + const Units.initial() + : distanceUnit = DistanceUnit.kilometers, + temperatureUnit = TemperatureUnit.celsius; + + Units copyWith({ + DistanceUnit? distanceUnit, + TemperatureUnit? temperatureUnit, + }) { + return Units( + distanceUnit ?? this.distanceUnit, + temperatureUnit ?? this.temperatureUnit, + ); + } + + @override + String toString() => + 'Units(distanceUnit: $distanceUnit, temperatureUnit: $temperatureUnit)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Units && + other.distanceUnit == distanceUnit && + other.temperatureUnit == temperatureUnit; + } + + @override + int get hashCode => distanceUnit.hashCode ^ temperatureUnit.hashCode; +} diff --git a/lib/data/models/user.dart b/lib/data/models/user.dart new file mode 100644 index 0000000..b163c5e --- /dev/null +++ b/lib/data/models/user.dart @@ -0,0 +1,54 @@ +import 'dart:convert'; + +import 'package:flutter_ics_homescreen/export.dart'; + +@immutable +class User { + final String id; + final String name; + const User({ + required this.id, + required this.name, + }); + + User copyWith({ + String? id, + String? name, + }) { + return User( + id: id ?? this.id, + name: name ?? this.name, + ); + } + + Map toMap() { + return { + 'id': id, + 'name': name, + }; + } + + factory User.fromMap(Map map) { + return User( + id: map['id'] ?? '', + name: map['name'] ?? '', + ); + } + + String toJson() => json.encode(toMap()); + + factory User.fromJson(String source) => User.fromMap(json.decode(source)); + + @override + String toString() => 'User(id: $id, name: $name)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is User && other.id == id && other.name == name; + } + + @override + int get hashCode => id.hashCode ^ name.hashCode; +} diff --git a/lib/data/models/users.dart b/lib/data/models/users.dart new file mode 100644 index 0000000..9b4d027 --- /dev/null +++ b/lib/data/models/users.dart @@ -0,0 +1,64 @@ +import 'dart:convert'; + +import 'package:flutter_ics_homescreen/data/models/user.dart'; +import 'package:flutter_ics_homescreen/export.dart'; +// ignore: depend_on_referenced_packages +import 'package:collection/collection.dart'; + +@immutable +class Users { + final List users; + final User selectedUser; + const Users({ + required this.users, + required this.selectedUser, + }); + Users.initial() + //: users = [], + : users = [], + selectedUser = const User(id: '', name: ''); + + Users copyWith({ + List? users, + User? selectedUser, + }) { + return Users( + users: users ?? this.users, + selectedUser: selectedUser ?? this.selectedUser, + ); + } + + Map toMap() { + return { + 'users': users.map((x) => x.toMap()).toList(), + 'selectedUser': selectedUser.toMap(), + }; + } + + factory Users.fromMap(Map map) { + return Users( + users: List.from(map['users']?.map((x) => User.fromMap(x))), + selectedUser: User.fromMap(map['selectedUser']), + ); + } + + String toJson() => json.encode(toMap()); + + factory Users.fromJson(String source) => Users.fromMap(json.decode(source)); + + @override + String toString() => 'Users(users: $users, selectedUser: $selectedUser)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + final listEquals = const DeepCollectionEquality().equals; + + return other is Users && + listEquals(other.users, users) && + other.selectedUser == selectedUser; + } + + @override + int get hashCode => users.hashCode ^ selectedUser.hashCode; +} diff --git a/lib/data/models/vehicle.dart b/lib/data/models/vehicle.dart new file mode 100644 index 0000000..f27b750 --- /dev/null +++ b/lib/data/models/vehicle.dart @@ -0,0 +1,233 @@ +import 'dart:convert'; + +import '../../export.dart'; + +@immutable +class Vehicle { + final double speed; + final double insideTemperature; + final double outsideTemperature; + final int range; + final double fuelLevel; + final int mediaVolume; + final bool isChildLockActiveLeft; + final bool isChildLockActiveRight; + final int engineSpeed; + final int frontLeftTire; + final int frontRightTire; + final int rearLeftTire; + final int rearRightTire; + final bool isAirConditioningActive; + final bool isFrontDefrosterActive; + final bool isRearDefrosterActive; + final bool isRecirculationActive; + final int fanSpeed; + + const Vehicle( + this.speed, + this.insideTemperature, + this.outsideTemperature, + this.range, + this.fuelLevel, + this.mediaVolume, + this.isChildLockActiveLeft, + this.isChildLockActiveRight, + this.engineSpeed, + this.frontLeftTire, + this.frontRightTire, + this.rearLeftTire, + this.rearRightTire, + this.isAirConditioningActive, + this.isFrontDefrosterActive, + this.isRearDefrosterActive, + this.isRecirculationActive, + this.fanSpeed); + + const Vehicle.initial() + : speed = 0, + insideTemperature = 0, + outsideTemperature = 0, + range = 0, + fuelLevel = 0, + mediaVolume = 50, + isChildLockActiveLeft = false, + isChildLockActiveRight = true, + engineSpeed = 0, + frontLeftTire = 33, + frontRightTire = 31, + rearLeftTire = 31, + rearRightTire = 32, + isAirConditioningActive = false, + isFrontDefrosterActive = false, + isRearDefrosterActive = false, + isRecirculationActive = false, + fanSpeed = 0; + + const Vehicle.initialForDebug() + : speed = 60, + insideTemperature = 25, + outsideTemperature = 32.0, + range = 21, + fuelLevel = 49.5, + mediaVolume = 50, + isChildLockActiveLeft = false, + isChildLockActiveRight = true, + engineSpeed = 6500, + frontLeftTire = 33, + frontRightTire = 31, + rearLeftTire = 31, + rearRightTire = 32, + isAirConditioningActive = false, + isFrontDefrosterActive = false, + isRearDefrosterActive = false, + isRecirculationActive = false, + fanSpeed = 0; + + Vehicle copyWith( + {double? speed, + double? insideTemperature, + double? outsideTemperature, + int? range, + double? fuelLevel, + int? mediaVolume, + bool? isChildLockActiveLeft, + bool? isChildLockActiveRight, + int? engineSpeed, + int? frontLeftTire, + int? frontRightTire, + int? rearLeftTire, + int? rearRightTire, + bool? isAirConditioningActive, + bool? isFrontDefrosterActive, + bool? isRearDefrosterActive, + bool? isRecirculationActive, + int? fanSpeed}) { + return Vehicle( + speed ?? this.speed, + insideTemperature ?? this.insideTemperature, + outsideTemperature ?? this.outsideTemperature, + range ?? this.range, + fuelLevel ?? this.fuelLevel, + mediaVolume ?? this.mediaVolume, + isChildLockActiveLeft ?? this.isChildLockActiveLeft, + isChildLockActiveRight ?? this.isChildLockActiveRight, + engineSpeed ?? this.engineSpeed, + frontLeftTire ?? this.frontLeftTire, + frontRightTire ?? this.frontRightTire, + rearLeftTire ?? this.rearLeftTire, + rearRightTire ?? this.rearRightTire, + isAirConditioningActive ?? this.isAirConditioningActive, + isFrontDefrosterActive ?? this.isFrontDefrosterActive, + isRearDefrosterActive ?? this.isRearDefrosterActive, + isRecirculationActive ?? this.isRecirculationActive, + fanSpeed ?? this.fanSpeed); + } + + Map toMap() { + return { + 'speed': speed, + 'insideTemperature': insideTemperature, + 'outsideTemperature': outsideTemperature, + 'range': range, + 'fuelLevel': fuelLevel, + 'mediaVolume': mediaVolume, + 'isChildLockActiveLeft': isChildLockActiveLeft, + 'isChildLockActiveRight': isChildLockActiveRight, + 'engineSpeed': engineSpeed, + 'frontLeftTire': frontLeftTire, + 'frontRightTire': frontRightTire, + 'rearLeftTire': rearLeftTire, + 'rearRightTire': rearRightTire, + 'isAirConditioningActive': isAirConditioningActive, + 'isFrontDefrosterActive': isFrontDefrosterActive, + 'isRearDefrosterActive': isRearDefrosterActive, + 'isRecirculationActive': isRecirculationActive, + 'fanSpeed': fanSpeed + }; + } + + factory Vehicle.fromMap(Map map) { + return Vehicle( + map['speed']?.toDouble() ?? 0.0, + map['insideTemperature']?.toDouble() ?? 0.0, + map['outsideTemperature']?.toDouble() ?? 0.0, + map['range']?.toInt() ?? 0, + map['fuelLevel']?.toDouble() ?? 0.0, + map['mediaVolume']?.toInt() ?? 0, + map['isChildLockActiveLeft'] ?? false, + map['isChildLockActiveRight'] ?? false, + map['engineSpeed']?.toInt() ?? 0, + map['frontLeftTire']?.toInt() ?? 0, + map['frontRightTire']?.toInt() ?? 0, + map['rearLeftTire']?.toInt() ?? 0, + map['rearRightTire']?.toInt() ?? 0, + map['isAirConditioningActive'] ?? false, + map['isFrontDefrosterActive'] ?? false, + map['isRearDefrosterActive'] ?? false, + map['isRecirculationActive'] ?? false, + map['fanSpeed'] ?? 0, + ); + } + + String toJson() => json.encode(toMap()); + + factory Vehicle.fromJson(String source) => + Vehicle.fromMap(json.decode(source)); + + @override + String toString() { + return 'Vehicle(speed: $speed, insideTemperature: $insideTemperature, outsideTemperature: $outsideTemperature, range: $range, fuelLevel: $fuelLevel, mediaVolume: $mediaVolume, isChildLockActiveLeft: $isChildLockActiveLeft, isChildLockActiveRight: $isChildLockActiveRight, engineSpeed: $engineSpeed, frontLeftTire: $frontLeftTire, frontRightTire: $frontRightTire, rearLeftTire: $rearLeftTire, rearRightTire: $rearRightTire, isAirConditioningActive: $isAirConditioningActive, isFrontDefrosterActive: $isFrontDefrosterActive, isRearDefrosterActive: $isRearDefrosterActive, isRecirculationActive: $isRecirculationActive,fanSpeed:$fanSpeed)'; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Vehicle && + other.speed == speed && + other.insideTemperature == insideTemperature && + other.outsideTemperature == outsideTemperature && + other.range == range && + other.fuelLevel == fuelLevel && + other.mediaVolume == mediaVolume && + other.isChildLockActiveLeft == isChildLockActiveLeft && + other.isChildLockActiveRight == isChildLockActiveRight && + other.engineSpeed == engineSpeed && + other.frontLeftTire == frontLeftTire && + other.frontRightTire == frontRightTire && + other.rearLeftTire == rearLeftTire && + other.rearRightTire == rearRightTire && + other.isAirConditioningActive == isAirConditioningActive && + other.isFrontDefrosterActive == isFrontDefrosterActive && + other.isRearDefrosterActive == isRearDefrosterActive && + other.isRecirculationActive == isRecirculationActive && + other.fanSpeed == fanSpeed; + } + + @override + int get hashCode { + return speed.hashCode ^ + insideTemperature.hashCode ^ + outsideTemperature.hashCode ^ + range.hashCode ^ + fuelLevel.hashCode ^ + mediaVolume.hashCode ^ + isChildLockActiveLeft.hashCode ^ + isChildLockActiveRight.hashCode ^ + engineSpeed.hashCode ^ + frontLeftTire.hashCode ^ + frontRightTire.hashCode ^ + rearLeftTire.hashCode ^ + rearRightTire.hashCode ^ + isAirConditioningActive.hashCode ^ + isFrontDefrosterActive.hashCode ^ + isRearDefrosterActive.hashCode ^ + isRecirculationActive.hashCode ^ + fanSpeed.hashCode; + } +// } +// / class VehicleNotifier extends StateNotifier { +// // VehicleNotifier() : super(Vehicle()); + +// // } +} -- cgit 1.2.3-korg