Created
February 28, 2015 16:57
-
-
Save mrowl/0ab027b5f84e25f51102 to your computer and use it in GitHub Desktop.
Shim between RecyclerView.Adapter and ParseAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
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
How do i this parse in my main activity?