aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/SubredditDatabase/SubredditDao.java4
-rw-r--r--app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java2
-rw-r--r--app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java2
-rw-r--r--app/src/main/java/User/UserDao.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java288
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java3
8 files changed, 200 insertions, 156 deletions
diff --git a/app/src/main/java/SubredditDatabase/SubredditDao.java b/app/src/main/java/SubredditDatabase/SubredditDao.java
index df763c93..657da989 100644
--- a/app/src/main/java/SubredditDatabase/SubredditDao.java
+++ b/app/src/main/java/SubredditDatabase/SubredditDao.java
@@ -14,9 +14,9 @@ public interface SubredditDao {
@Query("DELETE FROM subreddits")
void deleteAllSubreddits();
- @Query("SELECT * from subreddits WHERE name = :namePrefixed LIMIT 1")
+ @Query("SELECT * from subreddits WHERE name = :namePrefixed COLLATE NOCASE LIMIT 1")
LiveData<SubredditData> getSubredditLiveDataByName(String namePrefixed);
- @Query("SELECT * from subreddits WHERE name = :namePrefixed LIMIT 1")
+ @Query("SELECT * from subreddits WHERE name = :namePrefixed COLLATE NOCASE LIMIT 1")
SubredditData getSubredditData(String namePrefixed);
}
diff --git a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java
index ed77c65c..35ceac47 100644
--- a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java
+++ b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java
@@ -19,7 +19,7 @@ public interface SubscribedSubredditDao {
@Query("SELECT * from subscribed_subreddits ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits();
- @Query("SELECT * from subscribed_subreddits WHERE name = :subredditName LIMIT 1")
+ @Query("SELECT * from subscribed_subreddits WHERE name = :subredditName COLLATE NOCASE LIMIT 1")
SubscribedSubredditData getSubscribedSubreddit(String subredditName);
@Query("DELETE FROM subscribed_subreddits WHERE name = :subredditName")
diff --git a/app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java b/app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java
index 83bdf6fe..e1810eec 100644
--- a/app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java
+++ b/app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java
@@ -19,7 +19,7 @@ public interface SubscribedUserDao {
@Query("SELECT * FROM subscribed_users ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedUserData>> getAllSubscribedUsers();
- @Query("SELECT * FROM subscribed_users WHERE name = :userName LIMIT 1")
+ @Query("SELECT * FROM subscribed_users WHERE name = :userName COLLATE NOCASE LIMIT 1")
SubscribedUserData getSubscribedUser(String userName);
@Query("DELETE FROM subscribed_users WHERE name = :userName")
diff --git a/app/src/main/java/User/UserDao.java b/app/src/main/java/User/UserDao.java
index 7aba086d..4ce2536b 100644
--- a/app/src/main/java/User/UserDao.java
+++ b/app/src/main/java/User/UserDao.java
@@ -14,9 +14,9 @@ public interface UserDao {
@Query("DELETE FROM users")
void deleteAllUsers();
- @Query("SELECT * FROM users WHERE name = :userName LIMIT 1")
+ @Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1")
LiveData<UserData> getUserLiveData(String userName);
- @Query("SELECT * FROM users WHERE name = :userName LIMIT 1")
+ @Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1")
UserData getUserData(String userName);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java
index 3e3c655c..89ecf3bf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java
@@ -1,9 +1,12 @@
package ml.docilealligator.infinityforreddit;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.ColorFilter;
+import android.net.Uri;
import android.support.annotation.NonNull;
+import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@@ -25,6 +28,7 @@ import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Retrofit;
+import ru.noties.markwon.SpannableConfiguration;
import ru.noties.markwon.view.MarkwonView;
class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
@@ -66,7 +70,26 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
((CommentViewHolder) holder).authorTextView.setText(commentItem.getAuthor());
((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime());
- ((CommentViewHolder) holder).commentMarkdownView.setMarkdown(commentItem.getCommentContent());
+ SpannableConfiguration spannableConfiguration = SpannableConfiguration.builder(mContext).linkResolver((view, link) -> {
+ if(link.startsWith("/u/")) {
+ Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3));
+ mContext.startActivity(intent);
+ } else if(link.startsWith("/r/")) {
+ Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3));
+ mContext.startActivity(intent);
+ } else {
+ CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
+ // add share action to menu list
+ builder.addDefaultShareMenuItem();
+ builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary));
+ CustomTabsIntent customTabsIntent = builder.build();
+ customTabsIntent.launchUrl(mContext, Uri.parse(link));
+ }
+ }).build();
+
+ ((CommentViewHolder) holder).commentMarkdownView.setMarkdown(spannableConfiguration, commentItem.getCommentContent());
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16;
@@ -74,44 +97,41 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
}
- ((CommentViewHolder) holder).expandButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if(commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
- mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
- setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
- } else {
- ((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.VISIBLE);
- FetchComment.fetchComment(mRetrofit, subredditNamePrefixed, article, commentItem.getId(),
- new FetchComment.FetchCommentListener() {
- @Override
- public void onFetchCommentSuccess(String response) {
- ParseComment.parseComment(response, new ArrayList<CommentData>(),
- locale, false, commentItem.getDepth(), new ParseComment.ParseCommentListener() {
- @Override
- public void onParseCommentSuccess(List<?> commentData, int moreCommentCount) {
- commentItem.addChildren((List<RecyclerViewItem>) commentData);
- ((CommentViewHolder) holder).loadMoreCommentsProgressBar
- .setVisibility(View.GONE);
- mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
- ((CommentViewHolder) holder).expandButton
- .setImageResource(R.drawable.ic_expand_less_black_20dp);
- }
-
- @Override
- public void onParseCommentFail() {
- ((CommentViewHolder) holder).loadMoreCommentsProgressBar
- .setVisibility(View.GONE);
- }
- });
- }
-
- @Override
- public void onFetchCommentFail() {
-
- }
- });
- }
+ ((CommentViewHolder) holder).expandButton.setOnClickListener(view -> {
+ if(commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
+ mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
+ setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
+ } else {
+ ((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.VISIBLE);
+ FetchComment.fetchComment(mRetrofit, subredditNamePrefixed, article, commentItem.getId(),
+ new FetchComment.FetchCommentListener() {
+ @Override
+ public void onFetchCommentSuccess(String response) {
+ ParseComment.parseComment(response, new ArrayList<CommentData>(),
+ locale, false, commentItem.getDepth(), new ParseComment.ParseCommentListener() {
+ @Override
+ public void onParseCommentSuccess(List<?> commentData, int moreCommentCount) {
+ commentItem.addChildren((List<RecyclerViewItem>) commentData);
+ ((CommentViewHolder) holder).loadMoreCommentsProgressBar
+ .setVisibility(View.GONE);
+ mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
+ ((CommentViewHolder) holder).expandButton
+ .setImageResource(R.drawable.ic_expand_less_black_20dp);
+ }
+
+ @Override
+ public void onParseCommentFail() {
+ ((CommentViewHolder) holder).loadMoreCommentsProgressBar
+ .setVisibility(View.GONE);
+ }
+ });
+ }
+
+ @Override
+ public void onFetchCommentFail() {
+
+ }
+ });
}
});
@@ -126,120 +146,114 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
break;
}
- ((CommentViewHolder) holder).upvoteButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- final boolean isDownvotedBefore = ((CommentViewHolder) holder).downvoteButton.getColorFilter() != null;
- final ColorFilter minusButtonColorFilter = ((CommentViewHolder) holder).downvoteButton.getColorFilter();
- ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).upvoteButton.setOnClickListener(view -> {
+ final boolean isDownvotedBefore = ((CommentViewHolder) holder).downvoteButton.getColorFilter() != null;
+ final ColorFilter minusButtonColorFilter = ((CommentViewHolder) holder).downvoteButton.getColorFilter();
+ ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
- if (((CommentViewHolder) holder).upvoteButton.getColorFilter() == null) {
- ((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
- if(isDownvotedBefore) {
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 2));
- } else {
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
- }
+ if (((CommentViewHolder) holder).upvoteButton.getColorFilter() == null) {
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ if(isDownvotedBefore) {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 2));
+ } else {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
+ }
- VoteThing.voteThing(mOauthRetrofit,mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position) {
- commentItem.setVoteType(1);
- if(isDownvotedBefore) {
- commentItem.setScore(commentItem.getScore() + 2);
- } else {
- commentItem.setScore(commentItem.getScore() + 1);
- }
+ VoteThing.voteThing(mOauthRetrofit,mSharedPreferences, new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position1) {
+ commentItem.setVoteType(1);
+ if(isDownvotedBefore) {
+ commentItem.setScore(commentItem.getScore() + 2);
+ } else {
+ commentItem.setScore(commentItem.getScore() + 1);
}
+ }
- @Override
- public void onVoteThingFail(int position) {
- Toast.makeText(mContext, "Cannot upvote this comment", Toast.LENGTH_SHORT).show();
- ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
- ((CommentViewHolder) holder).downvoteButton.setColorFilter(minusButtonColorFilter);
- }
- }, commentItem.getFullName(), RedditUtils.DIR_UPVOTE, ((CommentViewHolder) holder).getAdapterPosition());
- } else {
- //Upvoted before
- ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 1));
+ @Override
+ public void onVoteThingFail(int position1) {
+ Toast.makeText(mContext, "Cannot upvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(minusButtonColorFilter);
+ }
+ }, commentItem.getFullName(), RedditUtils.DIR_UPVOTE, ((CommentViewHolder) holder).getAdapterPosition());
+ } else {
+ //Upvoted before
+ ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 1));
- VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position) {
- commentItem.setVoteType(0);
- commentItem.setScore(commentItem.getScore() - 1);
- }
+ VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position1) {
+ commentItem.setVoteType(0);
+ commentItem.setScore(commentItem.getScore() - 1);
+ }
- @Override
- public void onVoteThingFail(int position) {
- Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
- ((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
- commentItem.setScore(commentItem.getScore() + 1);
- }
- }, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, ((CommentViewHolder) holder).getAdapterPosition());
- }
+ @Override
+ public void onVoteThingFail(int position1) {
+ Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ commentItem.setScore(commentItem.getScore() + 1);
+ }
+ }, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, ((CommentViewHolder) holder).getAdapterPosition());
}
});
- ((CommentViewHolder) holder).downvoteButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- final boolean isUpvotedBefore = ((CommentViewHolder) holder).upvoteButton.getColorFilter() != null;
+ ((CommentViewHolder) holder).downvoteButton.setOnClickListener(view -> {
+ final boolean isUpvotedBefore = ((CommentViewHolder) holder).upvoteButton.getColorFilter() != null;
- final ColorFilter upvoteButtonColorFilter = ((CommentViewHolder) holder).upvoteButton.getColorFilter();
- ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
+ final ColorFilter upvoteButtonColorFilter = ((CommentViewHolder) holder).upvoteButton.getColorFilter();
+ ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
- if (((CommentViewHolder) holder).downvoteButton.getColorFilter() == null) {
- ((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
- if (isUpvotedBefore) {
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 2));
- } else {
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 1));
- }
+ if (((CommentViewHolder) holder).downvoteButton.getColorFilter() == null) {
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ if (isUpvotedBefore) {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 2));
+ } else {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 1));
+ }
- VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position) {
- commentItem.setVoteType(-1);
- if(isUpvotedBefore) {
- commentItem.setScore(commentItem.getScore() - 2);
- } else {
- commentItem.setScore(commentItem.getScore() - 1);
- }
+ VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position12) {
+ commentItem.setVoteType(-1);
+ if(isUpvotedBefore) {
+ commentItem.setScore(commentItem.getScore() - 2);
+ } else {
+ commentItem.setScore(commentItem.getScore() - 1);
}
+ }
- @Override
- public void onVoteThingFail(int position) {
- Toast.makeText(mContext, "Cannot downvote this comment", Toast.LENGTH_SHORT).show();
- ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
- ((CommentViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
- }
- }, commentItem.getFullName(), RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition());
- } else {
- //Down voted before
- ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
+ @Override
+ public void onVoteThingFail(int position12) {
+ Toast.makeText(mContext, "Cannot downvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
+ }
+ }, commentItem.getFullName(), RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition());
+ } else {
+ //Down voted before
+ ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
- VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position) {
- commentItem.setVoteType(0);
- commentItem.setScore(commentItem.getScore());
- }
+ VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position12) {
+ commentItem.setVoteType(0);
+ commentItem.setScore(commentItem.getScore());
+ }
- @Override
- public void onVoteThingFail(int position) {
- Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
- ((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
- ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
- commentItem.setScore(commentItem.getScore());
- }
- }, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, holder.getAdapterPosition());
- }
+ @Override
+ public void onVoteThingFail(int position12) {
+ Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
+ commentItem.setScore(commentItem.getScore());
+ }
+ }, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, holder.getAdapterPosition());
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
index ab42d660..cc7a0326 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
@@ -43,20 +43,27 @@ class ParseSubredditData {
String id = data.getString(JSONUtils.NAME_KEY);
String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME);
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
- String bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY);
- if(bannerImageUrl.equals("") || bannerImageUrl.equals("null")) {
+
+ String bannerImageUrl;
+ if(data.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
+ bannerImageUrl = "";
+ } else {
+ bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY);
+ }
+ if(bannerImageUrl.equals("") && !data.isNull(JSONUtils.BANNER_IMG_KEY)) {
bannerImageUrl= data.getString(JSONUtils.BANNER_IMG_KEY);
- if(bannerImageUrl.equals("null")) {
- bannerImageUrl = "";
- }
}
- String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
- if(iconUrl.equals("") || iconUrl.equals("null")) {
+
+ String iconUrl;
+ if(data.isNull(JSONUtils.COMMUNITY_ICON_KEY)) {
+ iconUrl = "";
+ } else {
+ iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
+ }
+ if(iconUrl.equals("") && !data.isNull(JSONUtils.ICON_IMG_KEY)) {
iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
- if(iconUrl.equals("null")) {
- iconUrl = "";
- }
}
+
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
int nCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY);
subredditData = new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 1b3a9f90..6b0c9e49 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -49,6 +49,7 @@ import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import jp.wasabeef.glide.transformations.BlurTransformation;
import retrofit2.Retrofit;
+import ru.noties.markwon.SpannableConfiguration;
import ru.noties.markwon.view.MarkwonView;
public class ViewPostDetailActivity extends AppCompatActivity {
@@ -269,7 +270,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mTypeChip.setText("LINK");
if(!mPost.getSelfText().equals("")) {
mContentMarkdownView.setVisibility(View.VISIBLE);
- mContentMarkdownView.setMarkdown(mPost.getSelfText());
+ mContentMarkdownView.setMarkdown(getCustomSpannableConfiguration(), mPost.getSelfText());
}
mNoPreviewLinkImageView.setVisibility(View.VISIBLE);
mNoPreviewLinkImageView.setOnClickListener(view -> {
@@ -285,7 +286,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mTypeChip.setVisibility(View.GONE);
if(!mPost.getSelfText().equals("")) {
mContentMarkdownView.setVisibility(View.VISIBLE);
- mContentMarkdownView.setMarkdown(mPost.getSelfText());
+ mContentMarkdownView.setMarkdown(getCustomSpannableConfiguration(), mPost.getSelfText());
}
break;
}
@@ -482,6 +483,27 @@ public class ViewPostDetailActivity extends AppCompatActivity {
}
}
+ private SpannableConfiguration getCustomSpannableConfiguration() {
+ return SpannableConfiguration.builder(this).linkResolver((view, link) -> {
+ if(link.startsWith("/u/")) {
+ Intent intent = new Intent(ViewPostDetailActivity.this, ViewUserDetailActivity.class);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3));
+ startActivity(intent);
+ } else if(link.startsWith("/r/")) {
+ Intent intent = new Intent(ViewPostDetailActivity.this, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3));
+ startActivity(intent);
+ } else {
+ CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
+ // add share action to menu list
+ builder.addDefaultShareMenuItem();
+ builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
+ CustomTabsIntent customTabsIntent = builder.build();
+ customTabsIntent.launchUrl(ViewPostDetailActivity.this, Uri.parse(link));
+ }
+ }).build();
+ }
+
private void showRetrySnackbar() {
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, R.string.load_comment_failed, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.retry, new View.OnClickListener() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
index 67042e55..18b26349 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
@@ -104,8 +104,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
params.topMargin = statusBarHeight;
String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
-
String title = "r/" + subredditName;
+ subredditNameTextView.setText(title);
+
CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsing_toolbar_layout_view_subreddit_detail_activity);
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout_view_subreddit_detail_activity);