Minor bugs fixed. Change logic of parsing post to avoid displaying error view if some of the posts are not parsed successfully.

This commit is contained in:
Alex Ning 2019-08-08 11:59:41 +08:00
parent 1c8ba320bc
commit eb1d243f2c
2 changed files with 29 additions and 25 deletions

View File

@ -185,7 +185,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
mNameTextView.setText(mName); mNameTextView.setText(mName);
mKarmaTextView.setText(mKarma); mKarmaTextView.setText(mKarma);
if (!mProfileImageUrl.equals("")) { if (mProfileImageUrl != null && !mProfileImageUrl.equals("")) {
glide.load(mProfileImageUrl) glide.load(mProfileImageUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
.error(glide.load(R.drawable.subreddit_default_icon) .error(glide.load(R.drawable.subreddit_default_icon)
@ -197,7 +197,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
.into(mProfileImageView); .into(mProfileImageView);
} }
if (!mBannerImageUrl.equals("")) { if (mBannerImageUrl != null && !mBannerImageUrl.equals("")) {
glide.load(mBannerImageUrl).into(mBannerImageView); glide.load(mBannerImageUrl).into(mBannerImageView);
} }
@ -226,7 +226,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
@Override @Override
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) { public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
mNameTextView.setText(name); mNameTextView.setText(name);
if (!profileImageUrl.equals("")) { if (profileImageUrl != null && !profileImageUrl.equals("")) {
glide.load(profileImageUrl) glide.load(profileImageUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0))) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0)))
.error(glide.load(R.drawable.subreddit_default_icon) .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))) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0)))
.into(mProfileImageView); .into(mProfileImageView);
} }
if (!bannerImageUrl.equals("")) { if (bannerImageUrl != null && !bannerImageUrl.equals("")) {
glide.load(bannerImageUrl).into(mBannerImageView); glide.load(bannerImageUrl).into(mBannerImageView);
} }

View File

@ -85,7 +85,6 @@ class ParsePost {
return null; return null;
} }
try {
if (newPosts == null) { if (newPosts == null) {
//Only one post //Only one post
if (allData.length() == 0) { if (allData.length() == 0) {
@ -93,8 +92,13 @@ class ParsePost {
return null; return null;
} }
try {
JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY); JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY);
post = parseBasicData(data, locale, -1); post = parseBasicData(data, locale, -1);
} catch (JSONException e) {
Log.e("parsing post error", "message: " + e.getMessage());
parseFailed = true;
}
} else { } else {
//Posts listing //Posts listing
int size; int size;
@ -105,6 +109,7 @@ class ParsePost {
} }
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
try {
JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
Post post = parseBasicData(data, locale, i); Post post = parseBasicData(data, locale, i);
if (filter == PostFragment.EXTRA_NO_FILTER) { if (filter == PostFragment.EXTRA_NO_FILTER) {
@ -114,11 +119,10 @@ class ParsePost {
} 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); newPosts.add(post);
} }
}
}
} catch (JSONException e) { } catch (JSONException e) {
Log.e("parsing post error", e.getMessage()); Log.e("parsing post error", "message: " + e.getMessage());
parseFailed = true; }
}
} }
return null; return null;
} }