aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-08 03:59:41 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-08 03:59:41 +0000
commiteb1d243f2c7e9d73a3863bcd21119095d0241acc (patch)
treef7adaa23e766f2d307c8b71b24bc359c64fee47a
parent1c8ba320bc8b1c64dfaff32e4debe740b6820213 (diff)
downloadinfinity-for-reddit-eb1d243f2c7e9d73a3863bcd21119095d0241acc.tar
infinity-for-reddit-eb1d243f2c7e9d73a3863bcd21119095d0241acc.tar.gz
infinity-for-reddit-eb1d243f2c7e9d73a3863bcd21119095d0241acc.tar.bz2
infinity-for-reddit-eb1d243f2c7e9d73a3863bcd21119095d0241acc.tar.lz
infinity-for-reddit-eb1d243f2c7e9d73a3863bcd21119095d0241acc.tar.xz
infinity-for-reddit-eb1d243f2c7e9d73a3863bcd21119095d0241acc.tar.zst
infinity-for-reddit-eb1d243f2c7e9d73a3863bcd21119095d0241acc.zip
Minor bugs fixed. Change logic of parsing post to avoid displaying error view if some of the posts are not parsed successfully.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java46
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;
}