From e6109ef36d403763eb92b5676d1f5df96bd657b6 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Sun, 19 Jul 2020 12:33:58 +0200 Subject: [PATCH] Search drafts (#574) Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts Merge branch 'master' into search-drafts # Conflicts: # app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java search drafts Co-authored-by: 6543 <6543@noreply.codeberg.org> Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/574 Reviewed-by: 6543 <6543@noreply.codeberg.org> --- .../mian/gitnex/adapters/DraftsAdapter.java | 7 +++ .../mian/gitnex/fragments/DraftsFragment.java | 54 +++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java index a828f839..dba1788a 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java @@ -125,4 +125,11 @@ public class DraftsAdapter extends RecyclerView.Adapter list) { + + draftsList = list; + notifyDataSetChanged(); + } + + } diff --git a/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java b/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java index d6d2863c..a437df46 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java @@ -6,10 +6,13 @@ import android.os.Handler; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.appcompat.widget.SearchView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; @@ -127,12 +130,53 @@ public class DraftsFragment extends Fragment { } - @Override - public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { + @Override + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { - inflater.inflate(R.menu.generic_nav_dotted_menu, menu); - super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.generic_nav_dotted_menu, menu); + inflater.inflate(R.menu.search_menu, menu); + super.onCreateOptionsMenu(menu, inflater); - } + MenuItem searchItem = menu.findItem(R.id.action_search); + SearchView searchView = (SearchView) searchItem.getActionView(); + searchView.setImeOptions(EditorInfo.IME_ACTION_DONE); + + ((SearchView) searchView).setOnQueryTextListener(new SearchView.OnQueryTextListener() { + + @Override + public boolean onQueryTextSubmit(String query) { + + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + + filter(newText); + return false; + + } + }); + + } + + private void filter(String text) { + + List arr = new ArrayList<>(); + + for(DraftWithRepository d : draftsList_) { + + if(d == null || d.getRepositoryOwner() == null || d.getRepositoryName() == null || d.getDraftText() == null) { + continue; + } + + if(d.getRepositoryOwner().toLowerCase().contains(text) || d.getRepositoryName().toLowerCase().contains(text) + || d.getDraftText().toLowerCase().contains(text) || String.valueOf(d.getIssueId()).contains(text)) { + arr.add(d); + } + } + + adapter.updateList(arr); + } }