2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-02-20 10:28:04 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2021-07-12 13:49:12 +02:00
|
|
|
IconData _getIconFromName(String displayname) {
|
|
|
|
final name = displayname.toLowerCase();
|
|
|
|
if ({'android'}.any((s) => name.contains(s))) {
|
|
|
|
return Icons.phone_android_outlined;
|
|
|
|
}
|
|
|
|
if ({'ios', 'ipad', 'iphone', 'ipod'}.any((s) => name.contains(s))) {
|
|
|
|
return Icons.phone_iphone_outlined;
|
|
|
|
}
|
|
|
|
if ({
|
|
|
|
'web',
|
|
|
|
'http://',
|
|
|
|
'https://',
|
|
|
|
'firefox',
|
|
|
|
'chrome',
|
|
|
|
'/_matrix',
|
|
|
|
'safari',
|
|
|
|
'opera',
|
|
|
|
}.any((s) => name.contains(s))) {
|
|
|
|
return Icons.web_outlined;
|
|
|
|
}
|
|
|
|
if ({'desktop', 'windows', 'macos', 'linux', 'ubuntu'}
|
|
|
|
.any((s) => name.contains(s))) {
|
|
|
|
return Icons.desktop_mac_outlined;
|
|
|
|
}
|
|
|
|
return Icons.device_unknown_outlined;
|
|
|
|
}
|
|
|
|
|
2021-02-20 10:28:04 +01:00
|
|
|
extension DeviceExtension on Device {
|
|
|
|
String get displayname =>
|
|
|
|
(displayName?.isNotEmpty ?? false) ? displayName : 'Unknown device';
|
|
|
|
|
2021-07-12 13:49:12 +02:00
|
|
|
IconData get icon => _getIconFromName(displayname);
|
2021-02-20 10:28:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension DeviceKeysExtension on DeviceKeys {
|
|
|
|
String get displayname => (deviceDisplayName?.isNotEmpty ?? false)
|
|
|
|
? deviceDisplayName
|
|
|
|
: 'Unknown device';
|
|
|
|
|
2021-07-12 13:49:12 +02:00
|
|
|
IconData get icon => _getIconFromName(displayname);
|
2021-02-20 10:28:04 +01:00
|
|
|
}
|