-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeviceModel.java
122 lines (94 loc) · 3.38 KB
/
DeviceModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.cajor.dk.dlna;
import org.fourthline.cling.model.meta.Device;
import org.fourthline.cling.model.meta.DeviceDetails;
import org.fourthline.cling.model.meta.Icon;
import org.fourthline.cling.model.meta.ManufacturerDetails;
import org.fourthline.cling.model.meta.RemoteDevice;
import org.fourthline.cling.model.meta.Service;
import org.seamless.util.MimeType;
import java.net.URI;
public class DeviceModel extends CustomListItem {
private final Device device;
public DeviceModel(int icon, Device device) {
super(icon);
this.device = device;
setIconUrl(getIconUrl());
}
public String getIconUrl() {
for (Object o : device.getIcons()) {
Icon icon = (Icon)o;
if (icon == null)
continue;
if (icon.getWidth() >= 64 && icon.getHeight() >= 64
&& isUsableImageType(icon.getMimeType()))
return ((RemoteDevice)device).normalizeURI(icon.getUri()).toString();
}
return null;
}
private boolean isUsableImageType(MimeType mt) {
return mt.getType().equals("image") &&
(mt.getSubtype().equals("png") || mt.getSubtype().equals("jpg") ||
mt.getSubtype().equals("jpeg") || mt.getSubtype().equals("gif"));
}
public Device getDevice() {
return device;
}
public Service getContentDirectory() {
for (Service current : this.device.getServices())
if (current.getServiceType().getType().equals("ContentDirectory"))
return current;
return null;
}
@Override
public String getTitle() {
return toString();
}
@Override
public String getDescription() {
DeviceDetails details = device.getDetails();
if (details == null)
return "N/A";
ManufacturerDetails manDetails = details.getManufacturerDetails();
if (manDetails == null)
return "N/A";
String manufacturer = manDetails.getManufacturer();
if (manufacturer == null)
return "N/A";
return manufacturer;
}
@Override
public String getDescription2() {
DeviceDetails details = device.getDetails();
if (details == null)
return "N/A";
ManufacturerDetails manDetails = details.getManufacturerDetails();
if (manDetails == null)
return "N/A";
URI uri = manDetails.getManufacturerURI();
if (uri == null)
return "N/A";
return uri.toString();
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
DeviceModel that = (DeviceModel)o;
return device.equals(that.device);
}
@Override
public int hashCode() {
return device.hashCode();
}
@Override
public String toString() {
String name =
getDevice().getDetails() != null
&& getDevice().getDetails().getFriendlyName() != null
? getDevice().getDetails().getFriendlyName()
: getDevice().getDisplayString();
return device.isFullyHydrated() ? name : name + " *";
}
}