Search in sources :

Example 41 with DatabaseError

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

the class GroupDetailActivity method itemLongClicked.

//Apro popup menu quando ho tenuto premuto un friend o gruppo per 1 secondo
@Override
public void itemLongClicked(String fragmentName, final String itemID, View v) {
    Log.i(TAG, "fragmentName " + fragmentName + " itemID " + itemID);
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Bundle bundle = new Bundle();
    Intent intent = null;
    switch(fragmentName) {
        case "FriendsFragment":
            break;
        case "GroupsFragment":
            popup = new PopupMenu(GroupDetailActivity.this, v, Gravity.RIGHT);
            popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
            one = popup.getMenu().findItem(R.id.one);
            one.setTitle("Remove friend");
            popup.getMenu().findItem(R.id.two).setVisible(false);
            popup.getMenu().findItem(R.id.three).setVisible(false);
            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    Toast.makeText(GroupDetailActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
                    return true;
                }
            });
            //showing popup menu
            popup.show();
        case "ExpensesFragment":
            popup = new PopupMenu(GroupDetailActivity.this, v, Gravity.RIGHT);
            popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
            one = popup.getMenu().findItem(R.id.one);
            one.setTitle("Remove expense");
            popup.getMenu().findItem(R.id.two).setVisible(false);
            popup.getMenu().findItem(R.id.three).setVisible(false);
            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    //Toast.makeText(GroupDetailActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
                    FirebaseUtils.getInstance().removeExpenseFirebase(itemID, getApplicationContext());
                    // add event for EXPENSE_REMOVE
                    databaseReference.child("expenses").child(itemID).addListenerForSingleValueEvent(new ValueEventListener() {

                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            User currentUser = MainActivity.getCurrentUser();
                            Event event = new Event(groupID, Event.EventType.EXPENSE_REMOVE, currentUser.getName() + " " + currentUser.getSurname(), dataSnapshot.child("description").getValue(String.class));
                            event.setDate(new SimpleDateFormat("yyyy.MM.dd").format(new java.util.Date()));
                            event.setTime(new SimpleDateFormat("HH:mm").format(new java.util.Date()));
                            FirebaseUtils.getInstance().addEvent(event);
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                            Log.w(TAG, databaseError.toException());
                        }
                    });
                    return true;
                }
            });
            //showing popup menu
            popup.show();
            break;
    }
}
Also used : User(com.polito.mad17.madmax.entities.User) Bundle(android.os.Bundle) Intent(android.content.Intent) MenuItem(android.view.MenuItem) DataSnapshot(com.google.firebase.database.DataSnapshot) FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) DatabaseError(com.google.firebase.database.DatabaseError) Event(com.polito.mad17.madmax.entities.Event) ValueEventListener(com.google.firebase.database.ValueEventListener) SimpleDateFormat(java.text.SimpleDateFormat) PopupMenu(android.support.v7.widget.PopupMenu)

Example 42 with DatabaseError

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

the class PendingExpensesFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    /*getSupportFragmentManager().beginTransaction()
                .add(detailFragment, "detail")
                // Add this transaction to the back stack
                .addToBackStack()
                .commit();*/
    Log.d(TAG, "onCreateView");
    setInterface((OnItemClickInterface) getActivity(), (OnItemLongClickInterface) getActivity());
    View view = inflater.inflate(R.layout.skeleton_list, container, false);
    RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(ContextCompat.getColor(getContext(), 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);
    pendingExpenseViewAdapter = new PendingExpenseViewAdapter(this.getContext(), this, this, pendingExpensesMap);
    recyclerView.setAdapter(pendingExpenseViewAdapter);
    //Ascolto le pending expenses dello user
    databaseReference.child("users").child(MainActivity.getCurrentUser().getID()).child("proposedExpenses").addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //Per ogni pending expense dello user
            for (DataSnapshot pendingExpenseSnap : dataSnapshot.getChildren()) {
                //Se la pending expense non è stata eliminata (NELLO USER)
                if (pendingExpenseSnap.getValue(Boolean.class)) {
                    FirebaseUtils.getInstance().getPendingExpense(pendingExpenseSnap.getKey(), pendingExpensesMap, pendingExpenseViewAdapter);
                    pendingExpenseViewAdapter.update(pendingExpensesMap);
                    pendingExpenseViewAdapter.notifyDataSetChanged();
                } else {
                    //tolgo la spesa da quelle che verranno stampate, così la vedo sparire realtime
                    pendingExpensesMap.remove(pendingExpenseSnap.getKey());
                    pendingExpenseViewAdapter.update(pendingExpensesMap);
                    pendingExpenseViewAdapter.notifyDataSetChanged();
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return view;
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

DatabaseError (com.google.firebase.database.DatabaseError)42 DataSnapshot (com.google.firebase.database.DataSnapshot)40 ValueEventListener (com.google.firebase.database.ValueEventListener)34 View (android.view.View)14 DatabaseReference (com.google.firebase.database.DatabaseReference)14 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)12 RecyclerView (android.support.v7.widget.RecyclerView)12 Intent (android.content.Intent)10 Bundle (android.os.Bundle)10 User (com.polito.mad17.madmax.entities.User)10 MutableData (com.google.firebase.database.MutableData)6 Transaction (com.google.firebase.database.Transaction)6 SimpleDateFormat (java.text.SimpleDateFormat)6 TextView (android.widget.TextView)5 Event (com.polito.mad17.madmax.entities.Event)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ActionBar (android.support.v7.app.ActionBar)3 MenuItem (android.view.MenuItem)3 ImageView (android.widget.ImageView)3