diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-07-12 11:41:52 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-07-12 11:41:52 +0000 |
commit | 67d4d9cc4f887a87450bbdca041a75a41a103d2b (patch) | |
tree | 5a483b4a4a6a6a14b9b1771881024e85f912dd50 /app/src/main | |
parent | 5fc3212f98a8ca8652fc7d370946d10b477a251c (diff) | |
download | infinity-for-reddit-67d4d9cc4f887a87450bbdca041a75a41a103d2b.tar infinity-for-reddit-67d4d9cc4f887a87450bbdca041a75a41a103d2b.tar.gz infinity-for-reddit-67d4d9cc4f887a87450bbdca041a75a41a103d2b.tar.bz2 infinity-for-reddit-67d4d9cc4f887a87450bbdca041a75a41a103d2b.tar.lz infinity-for-reddit-67d4d9cc4f887a87450bbdca041a75a41a103d2b.tar.xz infinity-for-reddit-67d4d9cc4f887a87450bbdca041a75a41a103d2b.tar.zst infinity-for-reddit-67d4d9cc4f887a87450bbdca041a75a41a103d2b.zip |
Searching comments in ViewPostDetailActivity is available.
Diffstat (limited to '')
4 files changed, 95 insertions, 1 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f320cb64..fb659b23 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -406,7 +406,8 @@ <activity android:name=".activities.ViewPostDetailActivity" android:parentActivityName=".activities.MainActivity" - android:theme="@style/AppTheme.Slidable" /> + android:theme="@style/AppTheme.Slidable" + android:windowSoftInputMode="adjustPan" /> <activity android:name=".activities.ViewSubredditDetailActivity" android:parentActivityName=".activities.MainActivity" 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 f093c1f6..a00f4c8d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -300,6 +300,28 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele if (savedInstanceState == null) { viewPager2.setCurrentItem(getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, 0), false); } + nextResultImageView.setOnClickListener(view -> { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + searchComment(fragment, true); + } + }); + + previousResultImageView.setOnClickListener(view -> { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + searchComment(fragment, false); + } + }); + + closeSearchPanelImageView.setOnClickListener(view -> { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + fragment.resetSearchCommentIndex(); + } + + searchPanelMaterialCardView.setVisibility(View.GONE); + }); } public boolean isNsfwSubreddit() { @@ -396,6 +418,10 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } + public void searchComment(ViewPostDetailFragment fragment, boolean searchNextComment) { + fragment.searchComment(searchTextInputEditText.getText().toString(), searchNextComment); + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { if (!getClass().getName().equals(event.excludeActivityClassName)) { 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 f88012b9..7e00a97f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -139,6 +139,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi private Drawable mCommentIcon; + private int mSearchCommentIndex = -1; + public CommentsRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment, CustomThemeWrapper customThemeWrapper, Executor executor, Retrofit retrofit, Retrofit oauthRetrofit, @@ -396,6 +398,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (holder instanceof CommentViewHolder) { Comment comment = getCurrentComment(position); if (comment != null) { + if (position == mSearchCommentIndex) { + holder.itemView.setBackgroundColor(Color.parseColor("#03A9F4")); + } if (mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) { holder.itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor); } else if (comment.getAwards() != null && !comment.getAwards().equals("")) { @@ -1036,6 +1041,18 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } } + public int getSearchCommentIndex() { + return mSearchCommentIndex; + } + + public void highlightSearchResult(int searchCommentIndex) { + mSearchCommentIndex = searchCommentIndex; + } + + public void resetCommentSearchIndex() { + mSearchCommentIndex = -1; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof CommentViewHolder) { 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 509ce597..cf84a2a6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -766,6 +766,56 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } } + public void searchComment(String query, boolean searchNextComment) { + if (mCommentsAdapter != null) { + ArrayList<Comment> visibleComments = mCommentsAdapter.getVisibleComments(); + int currentSearchIndex = mCommentsAdapter.getSearchCommentIndex(); + 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) { + if (mCommentsRecyclerView == null) { + mRecyclerView.smoothScrollToPosition(i + 1); + } else { + mCommentsRecyclerView.smoothScrollToPosition(i); + } + mCommentsAdapter.highlightSearchResult(i); + mCommentsAdapter.notifyItemChanged(i); + } + return; + } + } + + return; + } else { + for (int i = currentSearchIndex - 1; i >= 0; i--) { + if (visibleComments.get(i).getCommentRawText() !=null && visibleComments.get(i).getCommentRawText().contains(query)) { + if (mCommentsAdapter != null) { + if (mCommentsRecyclerView == null) { + mRecyclerView.smoothScrollToPosition(i + 1); + } else { + mCommentsRecyclerView.smoothScrollToPosition(i); + } + mCommentsAdapter.highlightSearchResult(i); + mCommentsAdapter.notifyItemChanged(i); + } + return; + } + } + + return; + } + } + } + } + + public void resetSearchCommentIndex() { + if (mCommentsAdapter != null) { + mCommentsAdapter.resetCommentSearchIndex(); + } + } + @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.view_post_detail_fragment, menu); |