summaryrefslogtreecommitdiff
path: root/src/org/fox/ttrss/types/Attachment.java
blob: 9e363dba694045333bf614b7e1c9ee17d097dd3f (plain)
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
package org.fox.ttrss.types;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import android.os.Parcel;
import android.os.Parcelable;

public class Attachment implements Parcelable {
	public int id;
	public String content_url;
	public String content_type;
	public String title;
	public String duration;
	public int post_id;
	
	public Attachment(Parcel in) {
		readFromParcel(in);
	}
	
	public Attachment() {
		
	}
	
	@Override
	public int describeContents() {
		return 0;
	}
	
	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeInt(id);
		out.writeString(content_url);
		out.writeString(content_type);
		out.writeString(title);
		out.writeString(duration);
		out.writeInt(post_id);
	}
	
	public String toString() {
		if (title != null && title.length() > 0) {
			return title;
		} else {		
			try {
				URL url = new URL(content_url.trim());
				return new File(url.getFile()).getName();
			} catch (MalformedURLException e) {
				return content_url;
			}
		}
	}
	
	public void readFromParcel(Parcel in) {
		id = in.readInt();
		content_url = in.readString();
		content_type = in.readString();
		title = in.readString();
		duration = in.readString();
		post_id = in.readInt();
	}
	
	@SuppressWarnings("rawtypes")
	public static final Parcelable.Creator CREATOR =
    	new Parcelable.Creator() {
            public Attachment createFromParcel(Parcel in) {
                return new Attachment(in);
            }
 
            public Attachment[] newArray(int size) {
                return new Attachment[size];
            }
        };

}