aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
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
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 '')
-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
-rw-r--r--app/src/main/res/drawable/no_comment_indicator.pngbin0 -> 60561 bytes
-rw-r--r--app/src/main/res/layout/activity_view_post_detail.xml24
-rw-r--r--app/src/main/res/values/strings.xml1
6 files changed, 49 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);
}
}
diff --git a/app/src/main/res/drawable/no_comment_indicator.png b/app/src/main/res/drawable/no_comment_indicator.png
new file mode 100644
index 00000000..62a3668f
--- /dev/null
+++ b/app/src/main/res/drawable/no_comment_indicator.png
Binary files differ
diff --git a/app/src/main/res/layout/activity_view_post_detail.xml b/app/src/main/res/layout/activity_view_post_detail.xml
index 8f6627a7..e696acf3 100644
--- a/app/src/main/res/layout/activity_view_post_detail.xml
+++ b/app/src/main/res/layout/activity_view_post_detail.xml
@@ -250,6 +250,30 @@
</android.support.v7.widget.CardView>
+ <LinearLayout
+ android:id="@+id/no_comment_wrapper_linear_layout_view_post_detail"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="48dp"
+ android:layout_marginBottom="48dp"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <ImageView
+ android:id="@+id/no_comment_image_view_view_post_detail"
+ android:layout_width="150dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:layout_gravity="center_horizontal"
+ android:text="@string/no_comments_yet"/>
+
+ </LinearLayout>
+
</LinearLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 09e9c511..c7505627 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -12,6 +12,7 @@
<string name="load_comment_failed">Error loading comments</string>
<string name="retry">Retry</string>
<string name="comments">Comments</string>
+ <string name="no_comments_yet">No comments yet. Write a comment?</string>
<string name="nsfw">NSFW</string>
<string name="karma_info">Karma: %1$d</string>