Search in sources :

Example 21 with User

use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.

the class FirebaseUtils method removePendingExpenseFirebase.

public void removePendingExpenseFirebase(final String expenseID, final Context context) {
    databaseReference.child("proposedExpenses").child(expenseID).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String groupID = dataSnapshot.child("groupID").getValue(String.class);
            // Elimino spesa pending dal gruppo
            databaseReference.child("groups").child(groupID).child("proposedExpenses").child(expenseID).setValue(false);
            // Per ogni participant elimino la spesa pending dal suo elenco spese pending
            for (DataSnapshot participantSnapshot : dataSnapshot.child("participants").getChildren()) {
                String participantID = participantSnapshot.getKey();
                databaseReference.child("users").child(participantID).child("proposedExpenses").child(expenseID).setValue(false);
            }
            // todo Elimino commenti sulla spesa pending
            // databaseReference.child("comments").child(groupID).removeValue();
            // Elimino spesa pending
            databaseReference.child("proposedExpenses").child(expenseID).child("deleted").setValue(true);
            // Toast.makeText(context, context.getString(R.string.expense_removed), Toast.LENGTH_SHORT).show();
            // add event for PENDING_EXPENSE_REMOVE
            databaseReference.child("proposedExpenses").child(expenseID).addListenerForSingleValueEvent(new ValueEventListener() {

                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    User currentUser = MainActivity.getCurrentUser();
                    Event event = new Event(dataSnapshot.child("groupID").getValue(String.class), Event.EventType.PENDING_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());
                }
            });
        /*Intent intent = new Intent(context, MainActivity.class);
                intent.putExtra("currentFragment", 2);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);*/
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : User(com.polito.mad17.madmax.entities.User) DatabaseError(com.google.firebase.database.DatabaseError) Event(com.polito.mad17.madmax.entities.Event) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) SimpleDateFormat(java.text.SimpleDateFormat)

Example 22 with User

use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.

the class DetailFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.i(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);
    if (requestCode == MainActivity.REQUEST_INVITE_GROUP) {
        if (resultCode == RESULT_OK) {
            // Get the invitation IDs of all sent messages
            String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
            for (String id : ids) {
                Log.i(TAG, "onActivityResult: sent invitation " + id);
            }
            // add event for FRIEND_GROUP_INVITE
            User currentUser = MainActivity.getCurrentUser();
            Event event = new Event(groupID, Event.EventType.FRIEND_GROUP_INVITE, currentUser.getName() + " " + currentUser.getSurname());
            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);
        } else {
            // Sending failed or it was canceled, show failure message to the user
            Log.e(TAG, "onActivityResult: failed sent");
        // Toast.makeText(getActivity(), "Unable to send invitation", Toast.LENGTH_SHORT).show();
        }
    }
}
Also used : User(com.polito.mad17.madmax.entities.User) Event(com.polito.mad17.madmax.entities.Event) SimpleDateFormat(java.text.SimpleDateFormat)

Example 23 with User

use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate");
    FirebaseUtils.getInstance().setUp();
    firebaseDatabase = FirebaseUtils.getFirebaseDatabase();
    databaseReference = FirebaseUtils.getDatabaseReference();
    usersRef = databaseReference.child("users");
    groupRef = databaseReference.child("groups");
    auth = FirebaseAuth.getInstance();
    // get data from firebase invite, if present
    startingIntent = getIntent();
    Uri data = startingIntent.getData();
    if (data != null) {
        inviterID = data.getQueryParameter("inviterID");
        groupToBeAddedID = data.getQueryParameter("groupToBeAddedID");
    } else {
        // nretrieving data from the intent inviterID & groupToBeAddedID as the group ID where to add the current user
        if (startingIntent.hasExtra("inviterID")) {
            // to be used to set the current user as friend of the inviter
            Log.d(TAG, "there is an invite");
            inviterID = startingIntent.getStringExtra("inviterID");
            startingIntent.removeExtra("inviterID");
        } else
            inviterID = null;
        if (startingIntent.hasExtra("groupToBeAddedID")) {
            groupToBeAddedID = startingIntent.getStringExtra("groupToBeAddedID");
            startingIntent.removeExtra("groupToBeAddedID");
        } else
            groupToBeAddedID = null;
    }
    currentFragment = startingIntent.getIntExtra("currentFragment", 1);
    if (auth.getCurrentUser() == null || !auth.getCurrentUser().isEmailVerified()) {
        if (auth.getCurrentUser() != null) {
            auth.signOut();
        }
        Intent doLogin = new Intent(getApplicationContext(), LoginSignUpActivity.class).setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        if (inviterID != null)
            doLogin.putExtra("inviterID", inviterID);
        if (groupToBeAddedID != null)
            doLogin.putExtra("groupToBeAddedID", groupToBeAddedID);
        startActivity(doLogin);
        // 0 for no animation
        overridePendingTransition(0, 0);
        finish();
    }
    if (auth.getCurrentUser() != null) {
        currentUID = auth.getCurrentUser().getUid();
    }
    // in the main we don't want an expansible bar
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
    appBarLayout.setExpanded(false);
    // todo: capire come bloccare la barra nel main
    // insert tabs and current fragment in the main layout
    mainView.addView(getLayoutInflater().inflate(R.layout.skeleton_tab, null));
    tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText(friends));
    tabLayout.addTab(tabLayout.newTab().setText(R.string.groups));
    tabLayout.addTab(tabLayout.newTab().setText(R.string.pending));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            Log.d(TAG, String.valueOf(tab.getPosition()));
            updateFab(tab.getPosition());
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    viewPager = (ViewPager) findViewById(R.id.main_view_pager);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    adapter = new MainActivityPagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
    viewPager.setAdapter(adapter);
    progressDialog = new ProgressDialog(this);
}
Also used : TabLayout(android.support.design.widget.TabLayout) LoginSignUpActivity(com.polito.mad17.madmax.activities.login.LoginSignUpActivity) Intent(android.content.Intent) AppBarLayout(android.support.design.widget.AppBarLayout) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri)

Example 24 with User

use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.

the class NewCommentDialogFragment method onCreateDialog.

@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    final String groupID = arguments.getString("groupID");
    final String expenseID = arguments.getString("expenseID");
    final String expenseName = arguments.getString("expenseName");
    final Boolean isExpense = arguments.getBoolean("isExpense");
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.prompt_comment).setView(R.layout.new_comment_dialog).setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            User currentUser = MainActivity.getCurrentUser();
            EditText message = (EditText) getDialog().findViewById(R.id.comment_message);
            // add comment
            Comment comment = new Comment(expenseID, currentUser.getName() + " " + currentUser.getSurname(), currentUser.getProfileImage(), message.getText().toString());
            comment.setDate(new SimpleDateFormat("yyyy.MM.dd").format(new java.util.Date()));
            comment.setTime(new SimpleDateFormat("HH:mm").format(new java.util.Date()));
            FirebaseUtils.getInstance().addComment(comment, isExpense);
            // add event for USER_COMMENT_ADD
            Event event = new Event(groupID, Event.EventType.USER_COMMENT_ADD, // instead of the username the subject must be the ID of the user
            currentUser.getID(), expenseName);
            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);
            // Send the positive button event back to the host activity
            newCommentDialogListener.onDialogPositiveClick(NewCommentDialogFragment.this);
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
        // User cancelled the dialog
        // Send the negative button event back to the host activity
        // newCommentDialogListener.onDialogNegativeClick(NewCommentDialogFragment.this);
        }
    });
    // Create the AlertDialog object and return it
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) Comment(com.polito.mad17.madmax.entities.Comment) User(com.polito.mad17.madmax.entities.User) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) Event(com.polito.mad17.madmax.entities.Event) SimpleDateFormat(java.text.SimpleDateFormat) NonNull(android.support.annotation.NonNull)

Example 25 with User

use of com.polito.mad17.madmax.entities.User in project MadMax by deviz92.

the class PayGroupActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pay_group);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String defaultCurrency = sharedPref.getString(SettingsFragment.DEFAULT_CURRENCY, "");
    Intent intent = getIntent();
    groupID = intent.getStringExtra("groupID");
    userID = intent.getStringExtra("userID");
    groupName = intent.getStringExtra("groupName");
    groupImageURL = intent.getStringExtra("groupImage");
    totBalances = (HashMap<String, Double>) intent.getSerializableExtra("totBalances");
    shownCurrency = intent.getStringExtra("shownCurrency");
    debt = totBalances.get(shownCurrency);
    debt = abs(Math.floor(debt * 100) / 100);
    currency = (Spinner) findViewById(R.id.currency);
    amountEditText = (EditText) findViewById(R.id.amount);
    amountEditText.setFilters(new InputFilter[] { new DecimalDigitsInputFilter(7, 2) });
    groupNameTextView = (TextView) findViewById(R.id.tv_receiver);
    groupNameTextView.setText(groupName);
    amountEditText.setText(debt.toString());
    // creating spinner for currencies
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currencies, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    currency.setAdapter(adapter);
    // set the defaultCurrency value for the spinner based on the user preferences
    int spinnerPosition = adapter.getPosition(shownCurrency);
    currency.setSelection(spinnerPosition);
    userImage = (ImageView) findViewById(R.id.sender_photo);
    groupImage = (ImageView) findViewById(R.id.receiver_photo);
    userImageURL = MainActivity.getCurrentUser().getProfileImage();
    userImage = (ImageView) findViewById(R.id.sender_photo);
    if (userImageURL != null) {
        Glide.with(getLayoutInflater().getContext()).load(userImageURL).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(userImage);
    } else {
        Glide.with(getLayoutInflater().getContext()).load(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(userImage);
    }
    groupImage = (ImageView) findViewById(R.id.receiver_photo);
    if (groupImageURL != null) {
        Glide.with(getLayoutInflater().getContext()).load(groupImageURL).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(groupImage);
    } else {
        Glide.with(getLayoutInflater().getContext()).load(R.drawable.group_default).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(groupImage);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) CropCircleTransformation(com.polito.mad17.madmax.entities.CropCircleTransformation) Intent(android.content.Intent) DecimalDigitsInputFilter(com.polito.mad17.madmax.activities.DecimalDigitsInputFilter)

Aggregations

User (com.polito.mad17.madmax.entities.User)27 Intent (android.content.Intent)17 DataSnapshot (com.google.firebase.database.DataSnapshot)16 DatabaseError (com.google.firebase.database.DatabaseError)16 ValueEventListener (com.google.firebase.database.ValueEventListener)16 Event (com.polito.mad17.madmax.entities.Event)15 SimpleDateFormat (java.text.SimpleDateFormat)14 View (android.view.View)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ImageView (android.widget.ImageView)6 CropCircleTransformation (com.polito.mad17.madmax.entities.CropCircleTransformation)6 Bitmap (android.graphics.Bitmap)4 NonNull (android.support.annotation.NonNull)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 StorageReference (com.google.firebase.storage.StorageReference)4 UploadTask (com.google.firebase.storage.UploadTask)4 Group (com.polito.mad17.madmax.entities.Group)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4