This file contains 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
public class PostViewModel extends BaseObservable { | |
private Context context; | |
private Post post; | |
private Boolean isUserPosts; | |
public PostViewModel(Context context, Post post, boolean isUserPosts) { | |
this.context = context; | |
this.post = post; | |
this.isUserPosts = isUserPosts; | |
} | |
public String getPostScore() { | |
return String.valueOf(post.score) + context.getString(R.string.story_points); | |
} | |
public String getPostTitle() { | |
return post.title; | |
} | |
public Spannable getPostAuthor() { | |
String author = context.getString(R.string.text_post_author, post.by); | |
SpannableString content = new SpannableString(author); | |
int index = author.indexOf(post.by); | |
if (!isUserPosts) content.setSpan(new UnderlineSpan(), index, post.by.length() + index, 0); | |
return content; | |
} | |
public int getCommentsVisibility() { | |
return post.postType == Post.PostType.STORY && post.kids == null ? View.GONE : View.VISIBLE; | |
} | |
public View.OnClickListener onClickPost() { | |
return new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Post.PostType postType = post.postType; | |
if (postType == Post.PostType.JOB || postType == Post.PostType.STORY) { | |
launchStoryActivity(); | |
} else if (postType == Post.PostType.ASK) { | |
launchCommentsActivity(); | |
} | |
} | |
}; | |
} | |
public View.OnClickListener onClickAuthor() { | |
return new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
context.startActivity(UserActivity.getStartIntent(context, post.by)); | |
} | |
}; | |
} | |
public View.OnClickListener onClickComments() { | |
return new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
launchCommentsActivity(); | |
} | |
}; | |
} | |
private void launchStoryActivity() { | |
context.startActivity(ViewStoryActivity.getStartIntent(context, post)); | |
} | |
private void launchCommentsActivity() { | |
context.startActivity(CommentsActivity.getStartIntent(context, post)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment