Implement last heard and info
This commit is contained in:
127
lib/models/last_heard_item.dart
Normal file
127
lib/models/last_heard_item.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
class LastHeardItem {
|
||||
final String linkName;
|
||||
final String sessionID;
|
||||
final int linkType;
|
||||
final int contextID;
|
||||
final int sessionType;
|
||||
final int slot;
|
||||
final int sourceID;
|
||||
final int destinationID;
|
||||
final String route;
|
||||
final String linkCall;
|
||||
final String sourceCall;
|
||||
final String? sourceName;
|
||||
final String destinationCall;
|
||||
final String? destinationName;
|
||||
final int start;
|
||||
final int stop;
|
||||
final int? rssi;
|
||||
final int? ber;
|
||||
final int reflectorID;
|
||||
final String linkTypeName;
|
||||
final List<String> callTypes;
|
||||
final int lossCount;
|
||||
final int totalCount;
|
||||
final String master;
|
||||
final String? talkerAlias;
|
||||
final int flagSet;
|
||||
final String event;
|
||||
|
||||
LastHeardItem({
|
||||
required this.linkName,
|
||||
required this.sessionID,
|
||||
required this.linkType,
|
||||
required this.contextID,
|
||||
required this.sessionType,
|
||||
required this.slot,
|
||||
required this.sourceID,
|
||||
required this.destinationID,
|
||||
required this.route,
|
||||
required this.linkCall,
|
||||
required this.sourceCall,
|
||||
this.sourceName,
|
||||
required this.destinationCall,
|
||||
this.destinationName,
|
||||
required this.start,
|
||||
required this.stop,
|
||||
this.rssi,
|
||||
this.ber,
|
||||
required this.reflectorID,
|
||||
required this.linkTypeName,
|
||||
required this.callTypes,
|
||||
required this.lossCount,
|
||||
required this.totalCount,
|
||||
required this.master,
|
||||
this.talkerAlias,
|
||||
required this.flagSet,
|
||||
required this.event,
|
||||
});
|
||||
|
||||
factory LastHeardItem.fromJson(Map<String, dynamic> json) {
|
||||
return LastHeardItem(
|
||||
linkName: json['LinkName'] as String? ?? '',
|
||||
sessionID: json['SessionID'] as String? ?? '',
|
||||
linkType: json['LinkType'] as int? ?? 0,
|
||||
contextID: json['ContextID'] as int? ?? 0,
|
||||
sessionType: json['SessionType'] as int? ?? 0,
|
||||
slot: json['Slot'] as int? ?? 0,
|
||||
sourceID: json['SourceID'] as int? ?? 0,
|
||||
destinationID: json['DestinationID'] as int? ?? 0,
|
||||
route: json['Route'] as String? ?? '',
|
||||
linkCall: json['LinkCall'] as String? ?? '',
|
||||
sourceCall: json['SourceCall'] as String? ?? '',
|
||||
sourceName: json['SourceName'] as String?,
|
||||
destinationCall: json['DestinationCall'] as String? ?? '',
|
||||
destinationName: json['DestinationName'] as String?,
|
||||
start: json['Start'] as int? ?? 0,
|
||||
stop: json['Stop'] as int? ?? 0,
|
||||
rssi: json['RSSI'] as int?,
|
||||
ber: json['BER'] as int?,
|
||||
reflectorID: json['ReflectorID'] as int? ?? 0,
|
||||
linkTypeName: json['LinkTypeName'] as String? ?? '',
|
||||
callTypes: (json['CallTypes'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
[],
|
||||
lossCount: json['LossCount'] as int? ?? 0,
|
||||
totalCount: json['TotalCount'] as int? ?? 0,
|
||||
master: json['Master'] as String? ?? '',
|
||||
talkerAlias: json['TalkerAlias'] as String?,
|
||||
flagSet: json['FlagSet'] as int? ?? 0,
|
||||
event: json['Event'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
String get displayName {
|
||||
if (sourceName != null && sourceName!.isNotEmpty) {
|
||||
return '$sourceCall ($sourceName)';
|
||||
}
|
||||
return sourceCall;
|
||||
}
|
||||
|
||||
String get destinationDisplayName {
|
||||
if (destinationName != null && destinationName!.isNotEmpty) {
|
||||
return '$destinationCall ($destinationName)';
|
||||
}
|
||||
return destinationCall;
|
||||
}
|
||||
|
||||
DateTime get timestamp {
|
||||
return DateTime.fromMillisecondsSinceEpoch(start * 1000);
|
||||
}
|
||||
|
||||
String get timeAgo {
|
||||
final now = DateTime.now();
|
||||
final difference = now.difference(timestamp);
|
||||
|
||||
if (difference.inSeconds < 60) {
|
||||
return '${difference.inSeconds}s ago';
|
||||
} else if (difference.inMinutes < 60) {
|
||||
return '${difference.inMinutes}m ago';
|
||||
} else if (difference.inHours < 24) {
|
||||
return '${difference.inHours}h ago';
|
||||
} else {
|
||||
return '${difference.inDays}d ago';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user