Skip to content

Commit

Permalink
Merge pull request #21 from virresh/matching-ui
Browse files Browse the repository at this point in the history
Matching ui
  • Loading branch information
virresh authored Oct 28, 2019
2 parents dc94699 + 756429a commit b420ef6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Proposal> proposals;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -28,7 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));

ProposalLab proposalLab = ProposalLab.get(getApplicationContext());
List<Proposal> proposals = proposalLab.getProposals();
proposals = proposalLab.getProposals();

mAdapter = new ProposalAdapter(this, proposals);
mAdapter.setClickListener(new ProposalAdapter.ItemClickListener() {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProposalAdapter.ProposalHolder> {

private List<Proposal> mProposals;
private List<Proposal> store;
private LayoutInflater mInflater;
private ItemClickListener mClickListener;

public ProposalAdapter(Context context, List<Proposal> proposals) {
this.mInflater = LayoutInflater.from(context);
this.mProposals = proposals;
store=new ArrayList<Proposal>();
store.addAll(this.mProposals);
}

@Override
Expand Down Expand Up @@ -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());
}
}

0 comments on commit b420ef6

Please sign in to comment.