aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit/post/ImgurMedia.java
blob: e78838f1508c5ea69ee1cf91974afe28aa1c6a54 (plain) (blame)
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
package ml.docilealligator.infinityforreddit.post;

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

public class ImgurMedia implements Parcelable {
    public static final int TYPE_IMAGE = 0;
    public static final int TYPE_VIDEO = 1;
    private String id;
    private final String title;
    private final String description;
    private final String link;
    private int type;

    public ImgurMedia(String id, String title, String description, String type, String link) {
        this.id = id;
        this.title = title;
        this.description = description;
        if (type.contains("mp4")) {
            this.type = TYPE_VIDEO;
        } else {
            this.type = TYPE_IMAGE;
        }
        this.link = link;
    }

    protected ImgurMedia(Parcel in) {
        title = in.readString();
        description = in.readString();
        link = in.readString();
    }

    public static final Creator<ImgurMedia> CREATOR = new Creator<ImgurMedia>() {
        @Override
        public ImgurMedia createFromParcel(Parcel in) {
            return new ImgurMedia(in);
        }

        @Override
        public ImgurMedia[] newArray(int size) {
            return new ImgurMedia[size];
        }
    };

    public String getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public String getDescription() {
        return description;
    }

    public int getType() {
        return type;
    }

    public String getLink() {
        return link;
    }

    public String getFileName() {
        if (type == TYPE_VIDEO) {
            return "Imgur-" + id + ".mp4";
        }

        return "Imgur-" + id + ".jpg";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(title);
        parcel.writeString(description);
        parcel.writeString(link);
    }
}