Skip to content

Instantly share code, notes, and snippets.

View achuinard's full-sized avatar

Anthony Chuinard achuinard

View GitHub Profile
package com.twansoftware.invoicemakerpro.adapter;
import android.content.Context;
import android.support.v7.util.SortedList;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.util.SortedListAdapterCallback;
import android.util.Log;
import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
package com.twansoftware.invoicemakerpro.adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.Map;
public abstract class CustomSortFirebaseRecyclerAdapter<T> extends RecyclerView.Adapter implements ChildEventListener {
protected Query mRef;
private Class<T> mModelClass;
private RecyclerQuestionAnswerer<T> mRecyclerQuestionAnswerer;
protected SortedList<T> mModels;
protected Map<String, T> mModelKeys;
private ChildEventListener mListener;
protected Context mContext;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.FirebaseError;
import com.firebase.client.Query;
import java.util.ArrayList;
public static <T> T loadSynchronous(final Firebase firebaseLocation, Class<T> clazz) {
final DataSnapshotWrapper snapshotWrapper = new DataSnapshotWrapper();
final CountDownLatch latch = new CountDownLatch(1);
firebaseLocation.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println("Location loaded");
snapshotWrapper.snapshot = dataSnapshot;
latch.countDown();
}
public class FirebaseDataSnapshotMapper {
public static void map(Object object, DataSnapshot dataSnapshot) {
try {
final Class<?> aClass = object.getClass();
final Field[] fields = aClass.getDeclaredFields();
for (final Field classField : fields) {
if (classField.isAnnotationPresent(Firemapped.class)) {
classField.setAccessible(true);
final Firemapped annotation = classField.getAnnotation(Firemapped.class);
final DataSnapshot child = dataSnapshot.child(annotation.firebasePath());