aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-12 15:09:15 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-12 15:09:15 +0000
commit67416fa3e47ecac67db667906e86bf8a58b31f45 (patch)
treef8be4c013e14df6506c4566b8523dc5d4e1e8d40
parent8c89603f198c0912d926018c26f8856c3b59c1cd (diff)
downloadinfinity-for-reddit-67416fa3e47ecac67db667906e86bf8a58b31f45.tar
infinity-for-reddit-67416fa3e47ecac67db667906e86bf8a58b31f45.tar.gz
infinity-for-reddit-67416fa3e47ecac67db667906e86bf8a58b31f45.tar.bz2
infinity-for-reddit-67416fa3e47ecac67db667906e86bf8a58b31f45.tar.lz
infinity-for-reddit-67416fa3e47ecac67db667906e86bf8a58b31f45.tar.xz
infinity-for-reddit-67416fa3e47ecac67db667906e86bf8a58b31f45.tar.zst
infinity-for-reddit-67416fa3e47ecac67db667906e86bf8a58b31f45.zip
Improve the experience of searching in comments.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java16
-rw-r--r--app/src/main/res/layout/activity_view_post_detail.xml5
4 files changed, 31 insertions, 19 deletions
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<RecyclerVi
@Override
public int getItemViewType(int position) {
if (mVisibleComments.size() == 0) {
- if (position == 0) {
- if (isInitiallyLoading) {
- return VIEW_TYPE_FIRST_LOADING;
- } else if (isInitiallyLoadingFailed) {
- return VIEW_TYPE_FIRST_LOADING_FAILED;
- } else {
- return VIEW_TYPE_NO_COMMENT_PLACEHOLDER;
- }
+ if (isInitiallyLoading) {
+ return VIEW_TYPE_FIRST_LOADING;
+ } else if (isInitiallyLoadingFailed) {
+ return VIEW_TYPE_FIRST_LOADING_FAILED;
+ } else {
+ return VIEW_TYPE_NO_COMMENT_PLACEHOLDER;
}
}
@@ -400,6 +399,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (comment != null) {
if (position == mSearchCommentIndex) {
holder.itemView.setBackgroundColor(Color.parseColor("#03A9F4"));
+ } else {
+ holder.itemView.setBackgroundColor(mCommentBackgroundColor);
}
if (mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) {
holder.itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor);
@@ -900,13 +901,14 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
public void initiallyLoading() {
+ resetCommentSearchIndex();
if (mVisibleComments.size() != 0) {
int previousSize = mVisibleComments.size();
mVisibleComments.clear();
if (mIsSingleCommentThreadMode) {
- notifyItemRangeRemoved(0, previousSize + 1);
+ notifyItemRangeRemoved(0, previousSize + ((mHasMoreComments || loadMoreCommentsFailed) ? 1 : 0) + 1);
} else {
- notifyItemRangeRemoved(0, previousSize);
+ notifyItemRangeRemoved(0, previousSize + ((mHasMoreComments || loadMoreCommentsFailed) ? 1 : 0));
}
}
@@ -1056,6 +1058,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentViewHolder) {
+ holder.itemView.setBackgroundColor(mCommentBackgroundColor);
((CommentViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
@@ -1067,13 +1070,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((CommentViewHolder) holder).itemView.setBackgroundColor(mCommentBackgroundColor);
}
}
@Override
public int getItemCount() {
if (isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) {
+ Log.i("adfasdf", "sds");
return 1;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index cf84a2a6..13d19083 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -12,6 +12,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -770,18 +771,21 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (mCommentsAdapter != null) {
ArrayList<Comment> 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">
<LinearLayout
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:paddingStart="0dp"
+ android:paddingEnd="8dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/search_text_input_layout_view_post_detail_activity"