diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java | 8 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java | 46 |
2 files changed, 29 insertions, 25 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 6c3831f2..e467035b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -185,7 +185,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe mNameTextView.setText(mName); mKarmaTextView.setText(mKarma); - if (!mProfileImageUrl.equals("")) { + if (mProfileImageUrl != null && !mProfileImageUrl.equals("")) { glide.load(mProfileImageUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))) .error(glide.load(R.drawable.subreddit_default_icon) @@ -197,7 +197,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe .into(mProfileImageView); } - if (!mBannerImageUrl.equals("")) { + if (mBannerImageUrl != null && !mBannerImageUrl.equals("")) { glide.load(mBannerImageUrl).into(mBannerImageView); } @@ -226,7 +226,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe @Override public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) { mNameTextView.setText(name); - if (!profileImageUrl.equals("")) { + if (profileImageUrl != null && !profileImageUrl.equals("")) { glide.load(profileImageUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0))) .error(glide.load(R.drawable.subreddit_default_icon) @@ -237,7 +237,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0))) .into(mProfileImageView); } - if (!bannerImageUrl.equals("")) { + if (bannerImageUrl != null && !bannerImageUrl.equals("")) { glide.load(bannerImageUrl).into(mBannerImageView); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index 05890b9b..d4b13be8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -85,40 +85,44 @@ class ParsePost { return null; } - try { - if(newPosts == null) { - //Only one post - if(allData.length() == 0) { - parseFailed = true; - return null; - } + if (newPosts == null) { + //Only one post + if (allData.length() == 0) { + parseFailed = true; + return null; + } + try { JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY); post = parseBasicData(data, locale, -1); + } catch (JSONException e) { + Log.e("parsing post error", "message: " + e.getMessage()); + parseFailed = true; + } + } else { + //Posts listing + int size; + if (nPosts < 0 || nPosts > allData.length()) { + size = allData.length(); } else { - //Posts listing - int size; - if(nPosts < 0 || nPosts > allData.length()) { - size = allData.length(); - } else { - size = nPosts; - } + size = nPosts; + } - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { + try { JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); Post post = parseBasicData(data, locale, i); - if(filter == PostFragment.EXTRA_NO_FILTER) { + if (filter == PostFragment.EXTRA_NO_FILTER) { newPosts.add(post); - } else if(filter == post.getPostType()) { + } else if (filter == post.getPostType()) { newPosts.add(post); - } else if(filter == Post.LINK_TYPE && post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { + } else if (filter == Post.LINK_TYPE && post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { newPosts.add(post); } + } catch (JSONException e) { + Log.e("parsing post error", "message: " + e.getMessage()); } } - } catch (JSONException e) { - Log.e("parsing post error", e.getMessage()); - parseFailed = true; } return null; } |