Search in sources :

Example 71 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project MadMax by deviz92.

the class ExpenseCommentsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    RecyclerView recyclerView;
    RecyclerView.LayoutManager layoutManager;
    String expenseID;
    View view = inflater.inflate(R.layout.skeleton_list, container, false);
    Bundle fragmentArguments = getArguments();
    expenseID = fragmentArguments.getString("expenseID");
    RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(getResources().getColor(R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
    recyclerView = (RecyclerView) view.findViewById(R.id.rv_skeleton);
    layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(divider);
    expenseCommentsViewAdapter = new ExpenseCommentsViewAdapter(this.getContext(), this, commentsMap, getFragmentManager());
    recyclerView.setAdapter(expenseCommentsViewAdapter);
    DatabaseReference expenseRef = databaseReference.child("expenses");
    expenseRef.child(expenseID).child("comments").addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot commentSnapshot) {
            for (DataSnapshot comment : commentSnapshot.getChildren()) {
                FirebaseUtils.getInstance().getComment(comment.getKey(), commentsMap, expenseCommentsViewAdapter);
                Log.d(TAG, comment.getKey());
            }
            expenseCommentsViewAdapter.update(commentsMap);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Log.w(TAG, "Failed to read value.", error.toException());
        }
    });
    return view;
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DatabaseError(com.google.firebase.database.DatabaseError) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 72 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.

the class ChatFragment method onDownvoteClick.

@Override
public void onDownvoteClick(int p) {
    // Log.d("vote" , "down : ");
    ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
    String chat_key = chatMessageHelper.getMessageID();
    DatabaseReference message_root = currPageData.child(chat_key);
    // get upvote data
    DatabaseReference downvote_count = message_root.child("downvotes");
    downvote_count.runTransaction(new Transaction.Handler() {

        @Override
        public Transaction.Result doTransaction(MutableData currentData) {
            Log.d("Data", String.valueOf(currentData));
            if (currentData.getValue() == null) {
                currentData.setValue(1);
            } else {
                currentData.setValue((Long) currentData.getValue() + 1);
            }
            // we can also abort by calling Transaction.abort()
            return Transaction.success(currentData);
        }

        // TODO:Error handle here
        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
        }
    });
}
Also used : ChatMessageHelper(ingage.ingage.helpers.ChatMessageHelper) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.google.firebase.database.Transaction) DatabaseReference(com.google.firebase.database.DatabaseReference) MutableData(com.google.firebase.database.MutableData) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 73 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.

the class ChatFragment method removeDownvote.

@Override
public void removeDownvote(int p) {
    ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
    String chat_key = chatMessageHelper.getMessageID();
    DatabaseReference message_root = currPageData.child(chat_key);
    // get upvote data
    DatabaseReference downvote_count = message_root.child("downvotes");
    downvote_count.runTransaction(new Transaction.Handler() {

        @Override
        public Transaction.Result doTransaction(MutableData currentData) {
            Log.d("Data", String.valueOf(currentData));
            if (currentData.getValue() == null) {
                currentData.setValue(0);
            } else {
                currentData.setValue((Long) currentData.getValue() - 1);
            }
            // we can also abort by calling Transaction.abort()
            return Transaction.success(currentData);
        }

        // TODO:Error handle here
        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
        }
    });
}
Also used : ChatMessageHelper(ingage.ingage.helpers.ChatMessageHelper) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.google.firebase.database.Transaction) DatabaseReference(com.google.firebase.database.DatabaseReference) MutableData(com.google.firebase.database.MutableData) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 74 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.

the class ChatFragment method onUpvoteClick.

@Override
public void onUpvoteClick(int p) {
    // Log.d("vote" , "up : ");
    // get correct chat msg with ith key from chatmessage helper
    ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
    String chat_key = chatMessageHelper.getMessageID();
    DatabaseReference message_root = currPageData.child(chat_key);
    // get upvote data
    DatabaseReference upvote_count = message_root.child("upvotes");
    upvote_count.runTransaction(new Transaction.Handler() {

        @Override
        public Transaction.Result doTransaction(MutableData currentData) {
            Log.d("Data", String.valueOf(currentData));
            if (currentData.getValue() == null) {
                currentData.setValue(1);
            } else {
                currentData.setValue((Long) currentData.getValue() + 1);
            }
            // we can also abort by calling Transaction.abort()
            return Transaction.success(currentData);
        }

        // TODO:Error handle here
        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
        }
    });
}
Also used : ChatMessageHelper(ingage.ingage.helpers.ChatMessageHelper) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.google.firebase.database.Transaction) DatabaseReference(com.google.firebase.database.DatabaseReference) MutableData(com.google.firebase.database.MutableData) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 75 with DatabaseReference

use of com.google.firebase.database.DatabaseReference in project MadMax by deviz92.

the class EventsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    RecyclerView recyclerView;
    RecyclerView.LayoutManager layoutManager;
    String groupID;
    View view = inflater.inflate(R.layout.skeleton_list, container, false);
    Bundle fragmentArguments = getArguments();
    groupID = fragmentArguments.getString("groupID");
    recyclerView = (RecyclerView) view.findViewById(R.id.rv_skeleton);
    recyclerView.setHasFixedSize(true);
    RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(getResources().getColor(R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
    recyclerView = (RecyclerView) view.findViewById(R.id.rv_skeleton);
    layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(divider);
    eventsViewAdapter = new EventsViewAdapter(this.getContext(), eventMap);
    recyclerView.setAdapter(eventsViewAdapter);
    DatabaseReference groupRef = databaseReference.child("groups");
    Log.d(TAG, "groupID: " + groupID);
    // retrieving events for current group
    groupRef.child(groupID).child("events").addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot eventSnapshot) {
            for (DataSnapshot event : eventSnapshot.getChildren()) {
                FirebaseUtils.getInstance().getEvent(event.getKey(), eventMap, eventsViewAdapter);
                Log.d(TAG, event.getKey());
            }
            eventsViewAdapter.update(eventMap);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Log.w(TAG, "Failed to read value.", error.toException());
        }
    });
    return view;
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DatabaseError(com.google.firebase.database.DatabaseError) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener)

Aggregations

DatabaseReference (com.google.firebase.database.DatabaseReference)157 DatabaseError (com.google.firebase.database.DatabaseError)95 DataSnapshot (com.google.firebase.database.DataSnapshot)87 ValueEventListener (com.google.firebase.database.ValueEventListener)61 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)50 HashMap (java.util.HashMap)24 View (android.view.View)18 MutableData (com.google.firebase.database.MutableData)17 Transaction (com.google.firebase.database.Transaction)17 Intent (android.content.Intent)16 FirebaseUser (com.google.firebase.auth.FirebaseUser)13 ArrayList (java.util.ArrayList)12 TextView (android.widget.TextView)11 Query (com.google.firebase.database.Query)11 Map (java.util.Map)11 ProgressDialog (android.app.ProgressDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)10 ChildEventListener (com.google.firebase.database.ChildEventListener)9 SharedPreferences (android.content.SharedPreferences)8 ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)8