package jp.cordea.switter.realm;

import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.Required;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Created by Yoshihiro Tanaka on 16/04/05.
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class LocalTweet extends RealmObject {

    @PrimaryKey
    private long id;

    private long tweetId;

    private long epoch;

    @Required
    private String text;

    private String profileImageUrl;

    private long userId;

    private String userName;

    private String userScreenName;

    private boolean isReply;

    private boolean isFavorite;

    private boolean isRetweet;

    private long replyTweetId;

    private int favoriteCount;

    private int retweetCount;

    private RealmList<LocalEntity> entities;

    public String getProfileBiggerImageUrl() {
        return profileImageUrl.replace("normal.png", "bigger.png");
    }
}

@@ -27,16 +27,521 @@
 realm;%0A%0A
+import com.twitter.sdk.android.core.models.MediaEntity;%0Aimport com.twitter.sdk.android.core.models.Tweet;%0Aimport com.twitter.sdk.android.core.models.TweetEntities;%0Aimport com.twitter.sdk.android.core.models.UrlEntity;%0Aimport com.twitter.sdk.android.core.models.User;%0A%0Aimport org.joda.time.DateTime;%0Aimport org.joda.time.format.DateTimeFormat;%0A%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.ArrayList;%0Aimport java.util.Date;%0Aimport java.util.List;%0Aimport java.util.Locale;%0Aimport java.util.Objects;%0A%0A
 import i
@@ -555,24 +555,24 @@
 .RealmList;%0A
-
 import io.re
@@ -944,18 +944,24 @@
 ate 
-long epoch
+String createdAt
 ;%0A%0A 
@@ -1411,16 +1411,16 @@
 Url() %7B%0A
-
         
@@ -1484,11 +1484,2409 @@
 );%0A    %7D
+%0A%0A    public static Tweet toTweet(LocalTweet localTweet) %7B%0A        RealmList%3CLocalEntity%3E entities = localTweet.getEntities();%0A        List%3CUrlEntity%3E urlEntities = new ArrayList%3C%3E();%0A        List%3CMediaEntity%3E mediaEntities = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C entities.size(); i++) %7B%0A            LocalEntity entity = entities.get(i);%0A            if (entity.getType().equals(%22url%22)) %7B%0A                urlEntities.add(new UrlEntity(entity.getMediaUrl(), null, entity.getDisplayUrl(), 0, 0));%0A            %7D else %7B%0A                mediaEntities.add(%0A                        new MediaEntity(null, null, entity.getDisplayUrl(), 0, 0, 0, null, entity.getMediaUrl(), null, null, 0, null, null, null));%0A            %7D%0A        %7D%0A%0A        return new Tweet(%0A                null,%0A                localTweet.getCreatedAt(),%0A                null,%0A                new TweetEntities(urlEntities, null, mediaEntities, null),%0A                null,%0A                localTweet.getFavoriteCount(),%0A                localTweet.isFavorite(),%0A                null,%0A                localTweet.getTweetId(),%0A                null,%0A                null,%0A                0,%0A                null,%0A                0,%0A                null,%0A                null,%0A                null,%0A                false,%0A                null,%0A                localTweet.getRetweetCount(),%0A                localTweet.isRetweet(),%0A                null,%0A                null,%0A                localTweet.getText(),%0A                false,%0A                new User(false, null, false, false, null, null, null, 0, false, 0, 0, false, localTweet.getUserId(), null, false, null, 0, null, localTweet.getUserName(),%0A                        null, null, null, false, null, localTweet.getProfileImageUrl(), null, null, null, null, null, false,%0A                        false, localTweet.getUserScreenName(), false, null, 0, null, null, 0 , false, null, null),%0A                false,%0A                null,%0A                null);%0A    %7D%0A%0A    public static String epochToString(long epoch) %7B%0A        SimpleDateFormat format = new SimpleDateFormat(%22EEE MMM dd HH:mm:ss Z yyyy%22, Locale.US);%0A        return format.format(new Date(epoch));%0A    %7D%0A%0A    public static long twitterDateToEpoch(String twitterDate) %7B%0A        return DateTime.parse(twitterDate, DateTimeFormat.forPattern(%22EEE MMM dd HH:mm:ss Z yyyy%22).withLocale(Locale.ENGLISH)).getMillis();%0A    %7D
 %0A%7D%0A

fix local tweet model, add util methods