Skip to content

Instantly share code, notes, and snippets.

@mrowl
Created February 28, 2015 16:57
Show Gist options
  • Save mrowl/0ab027b5f84e25f51102 to your computer and use it in GitHub Desktop.
Save mrowl/0ab027b5f84e25f51102 to your computer and use it in GitHub Desktop.
Shim between RecyclerView.Adapter and ParseAdapter
public class ThingsAdapter extends RecyclerView.Adapter<ThingsAdapter.ViewHolder> {
private ParseQueryAdapter<ParseObject> parseAdapter;
private ViewGroup parseParent;
private ThingsAdapter thingsAdapter = this;
public ThingsAdapter(Context context, ViewGroup parentIn) {
parseParent = parentIn;
parseAdapter = new ParseQueryAdapter<ParseObject>(context, "thing") {
@Override
public View getItemView(ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.thing_card, parent, false);
}
super.getItemView(object, v, parent);
ParseImageView imageView = (ParseImageView) v.findViewById(R.id.icon);
imageView.setParseFile(object.getParseFile("thumbnail"));
imageView.loadInBackground();
TextView nameView = (TextView) v.findViewById(R.id.thing_card_name);
nameView.setText(object.getString("name"));
return v;
}
};
parseAdapter.addOnQueryLoadListener(new OnQueryLoadListener());
parseAdapter.loadObjects();
}
@Override
public ThingsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.thing_card, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
parseAdapter.getView(position, holder.cardView, parseParent);
}
@Override
public int getItemCount() {
return parseAdapter.getCount();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public View cardView;
public ViewHolder(View v) {
super(v);
cardView = v;
}
}
public class OnQueryLoadListener implements ParseQueryAdapter.OnQueryLoadListener<ParseObject> {
public void onLoading() {
}
public void onLoaded(List<ParseObject> objects, Exception e) {
thingsAdapter.notifyDataSetChanged();
}
}
}
@akshaysahai19
Copy link

How do i this parse in my main activity?

@marios-codes
Copy link

Hello and thank you very much for this gist. Are you planning to continue development of this by adding other ParseQueryAdapter methods, like loadNextPage etc., because I would really like to use it in my app!!
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment