aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-08-11 09:49:30 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-08-11 09:49:30 +0000
commiteb973138f72b181f79d84bbf16c06f92760118e0 (patch)
treedd9495d830abcac15f81907dc0abd9e755fcfc02 /app/src/main/java/ml
parentc0eaf2d3bb599503d35753c69854d62275775f17 (diff)
downloadinfinity-for-reddit-eb973138f72b181f79d84bbf16c06f92760118e0.tar
infinity-for-reddit-eb973138f72b181f79d84bbf16c06f92760118e0.tar.gz
infinity-for-reddit-eb973138f72b181f79d84bbf16c06f92760118e0.tar.bz2
infinity-for-reddit-eb973138f72b181f79d84bbf16c06f92760118e0.tar.lz
infinity-for-reddit-eb973138f72b181f79d84bbf16c06f92760118e0.tar.xz
infinity-for-reddit-eb973138f72b181f79d84bbf16c06f92760118e0.tar.zst
infinity-for-reddit-eb973138f72b181f79d84bbf16c06f92760118e0.zip
Fixed a bug which causes the app to crash when there is no comment in a post. Add a no comment placeholder which is displayed when there is no comment in a post.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java11
3 files changed, 24 insertions, 2 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
index 5d89497f..3721947e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit;
+import android.net.Uri;
+
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
@@ -25,7 +27,12 @@ class FetchComment {
void queryComment(FetchCommentListener fetchCommentListener) {
mFetchCommentListener = fetchCommentListener;
- StringRequest commentRequest = new StringRequest(Request.Method.GET, RedditUtils.getQueryCommentUri(subredditName, article), new Response.Listener<String>() {
+
+ Uri uri = Uri.parse(RedditUtils.getQueryCommentUri(subredditName, article))
+ .buildUpon().appendQueryParameter(RedditUtils.RAW_JSON_KEY, RedditUtils.RAW_JSON_VALUE)
+ .build();
+
+ StringRequest commentRequest = new StringRequest(Request.Method.GET, uri.toString(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mFetchCommentListener.onFetchCommentSuccess(response);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
index dc40018c..58b435f1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
@@ -53,8 +53,13 @@ class ParseComment {
int actualCommentLength;
JSONArray allComments = jsonResponse.getJSONObject(1).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
+ if(allComments.length() == 0) {
+ return null;
+ }
+
JSONObject more = allComments.getJSONObject(allComments.length() - 1).getJSONObject(JSONUtils.DATA_KEY);
+ //Maybe children contain only comments and no more info
if(more.has(JSONUtils.COUNT_KEY)) {
moreCommentCount = more.getInt(JSONUtils.COUNT_KEY);
actualCommentLength = allComments.length() - 1;
@@ -87,7 +92,6 @@ class ParseComment {
} catch (JSONException e) {
parseFailed = true;
Log.i("parse comment error", e.getMessage());
- mParseCommentListener.onParseCommentFail();
}
return null;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 3245ddf9..36bed4e1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -16,6 +16,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -48,6 +49,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private CardView mCommentCardView;
private RecyclerView mRecyclerView;
+ private LinearLayout mNoCommentWrapperLinearLayout;
+ private ImageView mNoCommentImageView;
+
private RequestQueue mVoteThingQueue;
private RequestQueue mCommentQueue;
@@ -86,6 +90,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mCommentCardView = findViewById(R.id.comment_card_view_view_post_detail);
mRecyclerView = findViewById(R.id.recycler_view_view_post_detail);
+ mNoCommentWrapperLinearLayout = findViewById(R.id.no_comment_wrapper_linear_layout_view_post_detail);
+ mNoCommentImageView = findViewById(R.id.no_comment_image_view_view_post_detail);
+
if(mPostData.getSubredditIconUrl() == null) {
new LoadSubredditIconAsyncTask(this, subredditIconCircleImageView,
SubredditRoomDatabase.getDatabase(this).subredditDao(), mPostData.getSubredditName(),
@@ -279,6 +286,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private void queryComment() {
mCommentProgressbar.setVisibility(View.VISIBLE);
+ mNoCommentWrapperLinearLayout.setVisibility(View.GONE);
new FetchComment(mCommentQueue, mPostData.getSubredditName(), mPostData.getId()).queryComment(new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(String response) {
@@ -291,6 +299,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
CommentRecyclerViewAdapter adapter = new CommentRecyclerViewAdapter(ViewPostDetailActivity.this, commentData, mVoteThingQueue);
mRecyclerView.setAdapter(adapter);
mCommentCardView.setVisibility(View.VISIBLE);
+ } else {
+ mNoCommentWrapperLinearLayout.setVisibility(View.VISIBLE);
+ Glide.with(ViewPostDetailActivity.this).load(R.drawable.no_comment_indicator).into(mNoCommentImageView);
}
}