diff --git a/app/src/main/java/com/mobilecomputing/sahayak/Activities/MenteeOptionsActivity.java b/app/src/main/java/com/mobilecomputing/sahayak/Activities/MenteeOptionsActivity.java index b4df48d..1fb7642 100644 --- a/app/src/main/java/com/mobilecomputing/sahayak/Activities/MenteeOptionsActivity.java +++ b/app/src/main/java/com/mobilecomputing/sahayak/Activities/MenteeOptionsActivity.java @@ -2,7 +2,9 @@ import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; +import android.widget.SearchView; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; @@ -15,9 +17,11 @@ import java.util.List; -public class MenteeOptionsActivity extends AppCompatActivity { +public class MenteeOptionsActivity extends AppCompatActivity implements SearchView.OnQueryTextListener { ProposalAdapter mAdapter; + SearchView searchView; + public static List proposals; @Override protected void onCreate(Bundle savedInstanceState) { @@ -28,7 +32,7 @@ protected void onCreate(Bundle savedInstanceState) { recyclerView.setLayoutManager(new LinearLayoutManager(this)); ProposalLab proposalLab = ProposalLab.get(getApplicationContext()); - List proposals = proposalLab.getProposals(); + proposals = proposalLab.getProposals(); mAdapter = new ProposalAdapter(this, proposals); mAdapter.setClickListener(new ProposalAdapter.ItemClickListener() { @@ -41,5 +45,21 @@ public void onItemClick(View view, int position) { } }); recyclerView.setAdapter(mAdapter); + + searchView = findViewById(R.id.search); + searchView.setOnQueryTextListener(this); + } + + @Override + public boolean onQueryTextSubmit(String query) { + + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + Log.d("Filter","OK:"+newText); + mAdapter.filter(newText); + return false; } } diff --git a/app/src/main/java/com/mobilecomputing/sahayak/Adapters/ProposalAdapter.java b/app/src/main/java/com/mobilecomputing/sahayak/Adapters/ProposalAdapter.java index 3d1222f..91afcb3 100644 --- a/app/src/main/java/com/mobilecomputing/sahayak/Adapters/ProposalAdapter.java +++ b/app/src/main/java/com/mobilecomputing/sahayak/Adapters/ProposalAdapter.java @@ -9,20 +9,26 @@ import androidx.recyclerview.widget.RecyclerView; +import com.mobilecomputing.sahayak.Activities.MenteeOptionsActivity; import com.mobilecomputing.sahayak.JavaClasses.Proposal; import com.mobilecomputing.sahayak.R; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; public class ProposalAdapter extends RecyclerView.Adapter { private List mProposals; + private List store; private LayoutInflater mInflater; private ItemClickListener mClickListener; public ProposalAdapter(Context context, List proposals) { this.mInflater = LayoutInflater.from(context); this.mProposals = proposals; + store=new ArrayList(); + store.addAll(this.mProposals); } @Override @@ -85,4 +91,24 @@ public void onClick(View view) { if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition()); } } + + public void filter(String charText) { + charText = charText.toLowerCase(Locale.getDefault()); + mProposals.clear(); + if (charText.length() == 0) { + mProposals.addAll(store); + } else { + for (Proposal wp : store) { + if (wp.getSkill().toLowerCase(Locale.getDefault()).contains(charText) + || wp.getCategory().toLowerCase(Locale.getDefault()).contains(charText)) { + mProposals.add(wp); + Log.d("Filter","Filtered:"+wp.getSkill()); + } + } +// MenteeOptionsActivity.proposals=tmp; +// mProposals = MenteeOptionsActivity.proposals; + } + notifyDataSetChanged(); + Log.d("Filter",store.size()+" "+mProposals.size()); + } }