-
Notifications
You must be signed in to change notification settings - Fork 1
/
ItemModel.java
137 lines (102 loc) · 3.62 KB
/
ItemModel.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.cajor.dk.dlna;
import android.content.res.Resources;
import android.net.Uri;
import org.fourthline.cling.model.meta.Service;
import org.fourthline.cling.support.model.DIDLObject;
import org.fourthline.cling.support.model.Res;
import org.fourthline.cling.support.model.container.Container;
import org.fourthline.cling.support.model.item.Item;
import java.util.List;
public class ItemModel extends CustomListItem {
private final Resources res;
private final Service service;
private final DIDLObject item;
private Boolean showExtension = false;
public ItemModel(Resources res, int icon, Service service, DIDLObject item) {
super(icon);
this.res = res;
this.service = service;
this.item = item;
}
public String getUrl() {
if (item == null)
return "N/A";
Res resource = item.getFirstResource();
if (resource == null || resource.getValue() == null)
return "N/A";
return resource.getValue();
}
public void setShowExtension(Boolean show) {
this.showExtension = show;
}
public Item getItem() {
if (isContainer())
return null;
return (Item)item;
}
public Container getContainer() {
if (!isContainer())
return null;
return (Container)item;
}
public Service getService() {
return this.service;
}
public boolean isContainer() {
return item instanceof Container;
}
@Override
public String getId() {
return item.getId();
}
@Override
public String getTitle() {
if (showExtension)
return item.getTitle() + "." + MimeTypeMap.getFileExtensionFromUrl(getUrl());
return item.getTitle();
}
@Override
public String getDescription() {
if (isContainer()) {
Integer children = getContainer().getChildCount();
if (children != null)
return getContainer().getChildCount() + " " + res.getString(R.string.info_items);
return res.getString(R.string.info_folder);
}
List<DIDLObject.Property> properties = item.getProperties();
if (properties != null && properties.size() != 0) {
for(DIDLObject.Property property : properties) {
if (property.getDescriptorName().equalsIgnoreCase("date"))
return property.getValue().toString();
}
}
List<Res> resources = item.getResources();
if (resources != null && resources.size() != 0) {
Res resource = item.getResources().get(0);
String resolution = resource.getResolution();
if (resolution != null)
return resolution;
String creator = item.getCreator();
if (creator == null)
return res.getString(R.string.info_file);
if (creator.startsWith("Unknown"))
return null;
return creator;
}
return "N/A";
}
@Override
public String getDescription2() {
if (!isContainer()) {
Uri uri = Uri.parse(getUrl());
MimeTypeMap mime = MimeTypeMap.getSingleton();
return mime.getMimeTypeFromUrl(uri.toString());
}
String genre = item.getFirstPropertyValue(DIDLObject.Property.UPNP.GENRE.class);
if (genre == null)
return null;
if (genre.startsWith("Unknown"))
return null;
return genre;
}
}