Created
September 18, 2017 20:47
-
-
Save galek/c35e3ea5840087fe7c3f923408a9b304 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.mastermmo.rhumester; | |
import android.graphics.Bitmap; | |
import android.nfc.Tag; | |
import android.support.annotation.Nullable; | |
import android.util.Log; | |
import com.google.gson.annotations.Expose; | |
import com.google.gson.annotations.SerializedName; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.lang.*; | |
class ServerTails | |
{ | |
@SerializedName("user_id") | |
public int user_id; | |
@SerializedName("body") | |
public String body; | |
@SerializedName("likes") | |
public int likes; | |
@SerializedName("dislikes") | |
public int dislikes; | |
} | |
class ServerPost | |
{ | |
@SerializedName("caption") | |
public String caption; | |
@SerializedName("user_id") | |
public int user_id; | |
@SerializedName("body") | |
public String body; | |
@Nullable | |
@SerializedName("contest_id") | |
public Integer contest_id=null; | |
@SerializedName("tails") | |
public List<ServerTails> tails=new ArrayList<>(); | |
public ServerPost(Post _postRaw) { | |
this.caption=_postRaw.getCaption(); | |
//this.user_id=_postRaw.; | |
this.body=_postRaw.getPoemHead(); | |
//this.contest_id = _postRaw.g | |
} | |
} | |
public class Post | |
{ | |
//@SerializedName("postId") | |
private int postId; | |
//@SerializedName("likes") | |
private int likes; | |
//@SerializedName("dislikes") | |
private int dislikes; | |
// @SerializedName("timestamp") | |
private long timestamp; | |
//@SerializedName("avatars") | |
private Bitmap[] avatars; | |
//@SerializedName("caption") | |
private String caption; | |
//@SerializedName("poemHead") | |
private String poemHead; | |
//@SerializedName("poemTails") | |
private String[] poemTails; | |
// @SerializedName("currentTail") | |
private int currentTail; | |
public Post(int postId, int likes, int dislikes, long timestamp, Bitmap[] avatars, String caption, String poemHead, String[] poemTails, int currentTail) { | |
this.setPostId(postId); | |
this.setLikes(likes); | |
this.setDislikes(dislikes); | |
this.setTimestamp(timestamp); | |
this.setAvatars(avatars); | |
this.setCaption(caption); | |
this.setPoemHead(poemHead); | |
this.setPoemTails(poemTails); | |
this.setCurrentTail(currentTail); | |
} | |
public Post(ServerPost _post, int _ID) { | |
this.setPostId(_ID); // TODO: придумать как заменить. | |
this.setLikes(0); | |
this.setDislikes(20); | |
this.setTimestamp(0); | |
this.setAvatars(null); | |
this.setCaption(_post.caption); | |
this.setPoemHead(_post.body); | |
this.setCurrentTail(0); | |
if (_post.tails.size() == 0) { | |
// TODO: Replace on empty string constant | |
this.setPoemTails(new String[]{"EMPTY BODY"}); | |
} | |
else | |
{ | |
List<String> list = new ArrayList<String>(); | |
for(ServerTails str:_post.tails) | |
list.add(str.body); | |
this.setPoemTails(list.toArray(new String[0])); | |
} | |
} | |
public int getPostId() { | |
return postId; | |
} | |
public void setPostId(int postId) { | |
this.postId = postId; | |
} | |
public int getLikes() { | |
return likes; | |
} | |
public void setLikes(int likes) { | |
this.likes = likes; | |
} | |
public int getDislikes() { | |
return dislikes; | |
} | |
public void setDislikes(int dislikes) { | |
this.dislikes = dislikes; | |
} | |
public long getTimestamp() { | |
return timestamp; | |
} | |
public void setTimestamp(long timestamp) { | |
this.timestamp = timestamp; | |
} | |
public Bitmap CurrentAvatar() { | |
return avatars[currentTail]; | |
} | |
public String getCaption() { | |
return caption; | |
} | |
public void setCaption(String caption) { | |
this.caption = caption; | |
} | |
public String getPoemHead() { | |
return poemHead; | |
} | |
public void setPoemHead(String poemHead) { | |
this.poemHead = poemHead; | |
} | |
public int getCurrentTail() { | |
return currentTail; | |
} | |
public String getCurrentText() { | |
return getPoemHead() + "\n" + poemTails[getCurrentTail()]; | |
} | |
public int getTailsCount() { | |
return poemTails.length; | |
} | |
public void setAvatars(Bitmap[] avatars) { | |
this.avatars = avatars; | |
} | |
public void setPoemTails(String[] poemTails) { | |
this.poemTails = poemTails; | |
} | |
public void setCurrentTail(int currentTail) { | |
this.currentTail = currentTail; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment