diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 3dd98593..e8b6fa85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -424,11 +424,13 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } - public void toggleSearchPanelVisibility() { + public boolean toggleSearchPanelVisibility() { if (searchPanelMaterialCardView.getVisibility() == View.GONE) { searchPanelMaterialCardView.setVisibility(View.VISIBLE); + return false; } else { searchPanelMaterialCardView.setVisibility(View.GONE); + return true; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 7e00a97f..6aa38fd3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -13,6 +13,7 @@ import android.text.Spanned; import android.text.TextPaint; import android.text.style.ClickableSpan; import android.text.util.Linkify; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -314,14 +315,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter visibleComments = mCommentsAdapter.getVisibleComments(); int currentSearchIndex = mCommentsAdapter.getSearchCommentIndex(); + if (currentSearchIndex >= 0) { + mCommentsAdapter.notifyItemChanged(currentSearchIndex); + } if (visibleComments != null) { if (searchNextComment) { for (int i = currentSearchIndex + 1; i < visibleComments.size(); i++) { if (visibleComments.get(i).getCommentRawText() != null && visibleComments.get(i).getCommentRawText().contains(query)) { if (mCommentsAdapter != null) { + mCommentsAdapter.highlightSearchResult(i); + mCommentsAdapter.notifyItemChanged(i); if (mCommentsRecyclerView == null) { mRecyclerView.smoothScrollToPosition(i + 1); } else { mCommentsRecyclerView.smoothScrollToPosition(i); } - mCommentsAdapter.highlightSearchResult(i); - mCommentsAdapter.notifyItemChanged(i); } return; } @@ -792,13 +796,13 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic for (int i = currentSearchIndex - 1; i >= 0; i--) { if (visibleComments.get(i).getCommentRawText() !=null && visibleComments.get(i).getCommentRawText().contains(query)) { if (mCommentsAdapter != null) { + mCommentsAdapter.highlightSearchResult(i); + mCommentsAdapter.notifyItemChanged(i); if (mCommentsRecyclerView == null) { mRecyclerView.smoothScrollToPosition(i + 1); } else { mCommentsRecyclerView.smoothScrollToPosition(i); } - mCommentsAdapter.highlightSearchResult(i); - mCommentsAdapter.notifyItemChanged(i); } return; } @@ -830,7 +834,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic public boolean onOptionsItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); if (itemId == R.id.action_search_view_post_detail_fragment) { - activity.toggleSearchPanelVisibility(); + if (activity.toggleSearchPanelVisibility() && mCommentsAdapter != null) { + mCommentsAdapter.resetCommentSearchIndex(); + } } else if (itemId == R.id.action_refresh_view_post_detail_fragment) { refresh(true, true); return true; 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 3a7cbf3c..eeaf034d 100644 --- a/app/src/main/res/layout/activity_view_post_detail.xml +++ b/app/src/main/res/layout/activity_view_post_detail.xml @@ -52,13 +52,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:backgroundTint="#FFFFFF" android:visibility="gone" app:cardElevation="16dp"> + android:layout_height="wrap_content" + android:paddingStart="0dp" + android:paddingEnd="8dp">