mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-10-05 21:39:50 +02:00
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.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user