Twidere-App-Android-Twitter.../twidere/src/main/java/edu/tsinghua/hotmobi/model/MediaEvent.java

158 lines
4.6 KiB
Java
Raw Normal View History

2015-08-13 14:59:03 +02:00
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package edu.tsinghua.hotmobi.model;
import android.content.Context;
2015-11-30 06:32:05 +01:00
import android.os.Parcel;
import android.os.Parcelable;
2016-01-29 15:46:22 +01:00
import android.support.annotation.NonNull;
2015-08-13 14:59:03 +02:00
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
2015-10-05 12:00:07 +02:00
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
2016-01-29 15:46:22 +01:00
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
2015-08-13 14:59:03 +02:00
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableStatus;
2016-01-29 15:46:22 +01:00
import edu.tsinghua.hotmobi.util.TwidereDataUtils;
2015-08-13 14:59:03 +02:00
/**
* Created by mariotaku on 15/8/7.
*/
2015-10-05 12:00:07 +02:00
@ParcelablePlease
2015-08-13 14:59:03 +02:00
@JsonObject
2015-11-30 06:32:05 +01:00
public class MediaEvent extends BaseEvent implements Parcelable {
2015-08-13 14:59:03 +02:00
@JsonField(name = "id")
2016-01-29 15:46:22 +01:00
@ParcelableThisPlease
2016-03-09 17:12:09 +01:00
String id;
2015-11-30 06:32:05 +01:00
2015-08-13 14:59:03 +02:00
@JsonField(name = "user_id")
2016-01-29 15:46:22 +01:00
@ParcelableThisPlease
2016-03-09 17:12:09 +01:00
String userId;
2015-11-30 06:32:05 +01:00
@JsonField(name = "tweet_type")
@TweetType
2016-01-29 15:46:22 +01:00
@ParcelableThisPlease
String tweetType;
2015-11-30 06:32:05 +01:00
@JsonField(name = "timeline_type")
@TimelineType
2016-01-29 15:46:22 +01:00
@ParcelableThisPlease
String timelineType;
2015-11-30 06:32:05 +01:00
2015-08-13 14:59:03 +02:00
@JsonField(name = "preview_url")
2016-01-29 15:46:22 +01:00
@ParcelableThisPlease
2015-08-13 14:59:03 +02:00
String previewUrl;
2015-11-30 06:32:05 +01:00
2015-08-13 14:59:03 +02:00
@JsonField(name = "media_url")
2016-01-29 15:46:22 +01:00
@ParcelableThisPlease
2015-08-13 14:59:03 +02:00
String mediaUrl;
2015-11-30 06:32:05 +01:00
2015-08-13 14:59:03 +02:00
@JsonField(name = "preview_enabled")
2016-01-29 15:46:22 +01:00
@ParcelableThisPlease
2015-08-13 14:59:03 +02:00
boolean previewEnabled;
2016-05-18 02:58:36 +02:00
public static MediaEvent create(@NonNull Context context, ParcelableStatus status,
@NonNull ParcelableMedia media,
@TimelineType String timelineType, boolean previewEnabled) {
2015-08-13 14:59:03 +02:00
final MediaEvent event = new MediaEvent();
event.markStart(context);
event.setId(status.id);
2016-03-07 18:25:18 +01:00
event.setUserId(status.user_key.getId());
2015-08-13 14:59:03 +02:00
event.setMediaUrl(media.media_url);
event.setPreviewUrl(media.preview_url);
event.setPreviewEnabled(previewEnabled);
event.setTimelineType(timelineType);
2016-01-29 15:46:22 +01:00
event.setTweetType(TwidereDataUtils.getTweetType(status));
2015-08-13 14:59:03 +02:00
return event;
}
public void setPreviewEnabled(boolean previewEnabled) {
this.previewEnabled = previewEnabled;
}
public void setMediaUrl(String mediaUrl) {
this.mediaUrl = mediaUrl;
}
public void setPreviewUrl(String previewUrl) {
this.previewUrl = previewUrl;
}
2016-03-09 17:12:09 +01:00
public void setId(String id) {
2015-08-13 14:59:03 +02:00
this.id = id;
}
2016-03-09 17:12:09 +01:00
public void setUserId(String userId) {
2015-08-13 14:59:03 +02:00
this.userId = userId;
}
public void setTweetType(@TweetType String tweetType) {
2015-08-13 14:59:03 +02:00
this.tweetType = tweetType;
}
public void setTimelineType(@TimelineType String timelineType) {
2015-08-13 14:59:03 +02:00
this.timelineType = timelineType;
}
2015-10-05 13:09:54 +02:00
@Override
public String toString() {
return "MediaEvent{" +
"id=" + id +
", userId=" + userId +
", tweetType=" + tweetType +
", timelineType=" + timelineType +
", previewUrl='" + previewUrl + '\'' +
", mediaUrl='" + mediaUrl + '\'' +
", previewEnabled=" + previewEnabled +
"} " + super.toString();
}
2015-11-30 06:32:05 +01:00
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
MediaEventParcelablePlease.writeToParcel(this, dest, flags);
}
public static final Creator<MediaEvent> CREATOR = new Creator<MediaEvent>() {
public MediaEvent createFromParcel(Parcel source) {
MediaEvent target = new MediaEvent();
MediaEventParcelablePlease.readFromParcel(target, source);
return target;
}
public MediaEvent[] newArray(int size) {
return new MediaEvent[size];
}
};
2016-01-29 15:46:22 +01:00
@NonNull
@Override
public String getLogFileName() {
return "media";
}
2015-08-13 14:59:03 +02:00
}