Search in sources :

Example 11 with Event

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

the class NewMemberActivity 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(this, "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 12 with Event

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

the class NewMemberActivity method onOptionsItemSelected.

// When I click SAVE
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemThatWasClickedId = item.getItemId();
    if (itemThatWasClickedId == R.id.action_save) {
        for (User newMemeber : alreadySelected.values()) {
            FirebaseUtils.getInstance().joinGroupFirebase(newMemeber.getID(), groupID);
            // add event for GROUP_MEMBER_ADD
            User currentUser = MainActivity.getCurrentUser();
            Event event = new Event(groupID, Event.EventType.GROUP_MEMBER_ADD, currentUser.getName() + " " + currentUser.getSurname(), newMemeber.getName() + " " + newMemeber.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);
        }
        for (User user : friends.values()) {
            if (user.getIsInGroupForInvite().equals(groupID)) {
                FirebaseUtils.getInstance().removeMemberFirebase(user.getID(), groupID);
                // add event for GROUP_MEMBER_REMOVE
                User currentUser = MainActivity.getCurrentUser();
                Event event = new Event(groupID, Event.EventType.GROUP_MEMBER_REMOVE, currentUser.getName() + " " + currentUser.getSurname(), user.getName() + " " + user.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);
            }
        }
        friends.clear();
        alreadySelected.clear();
        Toast.makeText(getApplicationContext(), getString(R.string.member_add), Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : User(com.polito.mad17.madmax.entities.User) Event(com.polito.mad17.madmax.entities.Event) Intent(android.content.Intent) SimpleDateFormat(java.text.SimpleDateFormat)

Example 13 with Event

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

the class PayExpenseActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;
    switch(item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            Log.d(TAG, "Clicked up button");
            /*
                Intent intent = new Intent(this, GroupDetailActivity.class);
                intent.putExtra("groupID", groupID);
                intent.putExtra("userID", userID);
                startActivity(intent);
                */
            onBackPressed();
            return true;
        case R.id.action_save:
            Log.d(TAG, "Clicked pay expense");
            Double money = null;
            String text = amountEditText.getText().toString();
            if (!text.isEmpty()) {
                try {
                    // it means it is double
                    money = Double.parseDouble(text);
                } catch (Exception e1) {
                    // this means it is not double
                    e1.printStackTrace();
                }
            }
            if (money != null) {
                if (money > debt) {
                    Toast.makeText(PayExpenseActivity.this, getString(R.string.cannot_pay_more), Toast.LENGTH_SHORT).show();
                    return true;
                } else if (money <= 0) {
                    Toast.makeText(PayExpenseActivity.this, getString(R.string.invalid_amount), Toast.LENGTH_SHORT).show();
                    return true;
                } else {
                    Toast.makeText(PayExpenseActivity.this, getString(R.string.paid), Toast.LENGTH_SHORT).show();
                    payDebtForExpense(userID, expenseID, money);
                    // add event for USER_PAY
                    User currentUser = MainActivity.getCurrentUser();
                    String userID = currentUser.getID();
                    Event event = new Event(groupID, Event.EventType.USER_PAY, userID, money + " €");
                    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);
                    intent = new Intent(this, ExpenseDetailActivity.class);
                    intent.putExtra("groupID", groupID);
                    intent.putExtra("userID", userID);
                    intent.putExtra("expenseID", expenseID);
                    finish();
                    startActivity(intent);
                    return true;
                }
            } else {
                Log.d(TAG, "Error: money is null");
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : User(com.polito.mad17.madmax.entities.User) Event(com.polito.mad17.madmax.entities.Event) Intent(android.content.Intent) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with Event

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

the class EventsViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final EventViewHolder eventViewHolder, int position) {
    final Event event = getItem(position).getValue();
    User currentUser = MainActivity.getCurrentUser();
    DatabaseReference databaseReference = FirebaseUtils.getDatabaseReference();
    switch(event.getEventType()) {
        case GROUP_ADD:
            eventViewHolder.imageView.setImageResource(R.drawable.group_add);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_ADD) + " \"" + event.getObject() + "\"");
            break;
        /*case GROUP_REMOVE:
                eventViewHolder.imageView.setImageResource(R.drawable.group_remove);
                event.setDescription("\"" + event.getSubject() + "\" " + context.getString(R.string.GROUP_REMOVE) + " \"" + event.getObject() + "\"");
                break;*/
        case GROUP_EDIT:
            eventViewHolder.imageView.setImageResource(R.drawable.group_edit);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_EDIT) + " \"" + event.getObject() + "\"");
            break;
        case GROUP_MEMBER_ADD:
            eventViewHolder.imageView.setImageResource(R.drawable.user_add);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_MEMBER_ADD) + " " + event.getObject());
            break;
        case GROUP_MEMBER_REMOVE:
            eventViewHolder.imageView.setImageResource(R.drawable.user_remove);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.GROUP_MEMBER_REMOVE) + " " + event.getObject());
            break;
        case EXPENSE_ADD:
            eventViewHolder.imageView.setImageResource(R.drawable.expense_add);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.EXPENSE_ADD) + " \"" + event.getObject() + "\"");
            break;
        case EXPENSE_REMOVE:
            eventViewHolder.imageView.setImageResource(R.drawable.expense_remove);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.EXPENSE_REMOVE) + " \"" + event.getObject() + "\"");
            break;
        case EXPENSE_EDIT:
            eventViewHolder.imageView.setImageResource(R.drawable.expense_edit);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.EXPENSE_EDIT) + " \"" + event.getObject() + "\"");
            break;
        case PENDING_EXPENSE_ADD:
            eventViewHolder.imageView.setImageResource(R.drawable.expense_add);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_ADD) + " \"" + event.getObject() + "\"");
            break;
        case PENDING_EXPENSE_REMOVE:
            eventViewHolder.imageView.setImageResource(R.drawable.expense_remove);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_REMOVE) + " \"" + event.getObject() + "\"");
            break;
        case PENDING_EXPENSE_EDIT:
            eventViewHolder.imageView.setImageResource(R.drawable.expense_edit);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_EDIT) + " \"" + event.getObject() + "\"");
            break;
        case PENDING_EXPENSE_VOTE_UP:
            eventViewHolder.imageView.setImageResource(R.drawable.thumb_up_black);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_VOTE) + " \"" + event.getObject() + "\"");
            break;
        case PENDING_EXPENSE_VOTE_DOWN:
            eventViewHolder.imageView.setImageResource(R.drawable.thumb_down_black);
            event.setDescription(event.getSubject() + " " + context.getString(R.string.PENDING_EXPENSE_VOTE) + " \"" + event.getObject() + "\"");
            break;
        case PENDING_EXPENSE_APPROVED:
            eventViewHolder.imageView.setImageResource(R.drawable.expense_add);
            event.setDescription(context.getString(R.string.PENDING_EXPENSE) + " \"" + event.getObject() + "\" " + context.getString(R.string.PENDING_EXPENSE_APPROVED));
            break;
        case PENDING_EXPENSE_NEGLECTED:
            eventViewHolder.imageView.setImageResource(R.drawable.pending_expense_neglected);
            event.setDescription(context.getString(R.string.PENDING_EXPENSE) + " \"" + event.getObject() + "\" " + context.getString(R.string.PENDING_EXPENSE_NEGLECTED));
            break;
        /*case FRIEND_INVITE:
                eventViewHolder.imageView.setImageResource(R.drawable.user_add);
                event.setDescription(context.getString(R.string.FRIEND_INVITE) + " \"" + event.getObject() + "\"");
                break;*/
        case FRIEND_GROUP_INVITE:
            eventViewHolder.imageView.setImageResource(R.drawable.user_add);
            event.setDescription(context.getString(R.string.FRIEND_GROUP_INVITE) + " " + event.getObject());
            break;
        case // instead of the username the subject must be the ID of the user
        USER_PAY:
            eventViewHolder.imageView.setImageResource(R.drawable.user_pay);
            if (currentUser.getID().equals(event.getSubject())) {
                event.setDescription(context.getString(R.string.ME_PAY) + " " + event.getObject());
            } else {
                databaseReference.child("users").child(event.getSubject()).addListenerForSingleValueEvent(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        event.setDescription(dataSnapshot.child("name").getValue(String.class) + " " + dataSnapshot.child("surname").getValue(String.class) + " " + context.getString(R.string.FRIEND_PAY) + " " + event.getObject());
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Log.w(TAG, databaseError.toException());
                    }
                });
            }
            break;
        case // instead of the username the subject must be the ID of the user
        USER_COMMENT_ADD:
            eventViewHolder.imageView.setImageResource(R.drawable.user_comment);
            if (currentUser.getID().equals(event.getSubject())) {
                event.setDescription(context.getString(R.string.ME_COMMENT_ADD) + " \"" + event.getObject() + "\"");
            } else {
                databaseReference.child("users").child(event.getSubject()).addListenerForSingleValueEvent(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        event.setDescription(dataSnapshot.child("name").getValue(String.class) + " " + dataSnapshot.child("surname").getValue(String.class) + " " + context.getString(R.string.FRIEND_COMMENT_ADD) + " \"" + event.getObject() + "\"");
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Log.w(TAG, databaseError.toException());
                    }
                });
            }
            break;
        default:
            eventViewHolder.imageView.setImageResource(R.drawable.event_default);
            event.setDescription("\"" + event.getSubject() + "\" " + context.getString(R.string.did) + " \"" + event.getObject() + "\"");
    }
    eventViewHolder.descriptionTextView.setText(event.getDescription());
    eventViewHolder.timestampTextView.setText(context.getString(R.string.day) + " " + event.getDate() + " " + context.getString(R.string.at) + " " + event.getTime());
}
Also used : User(com.polito.mad17.madmax.entities.User) DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) Event(com.polito.mad17.madmax.entities.Event) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 15 with Event

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

the class NewGroupActivity method onOptionsItemSelected.

// When i click SAVE
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemThatWasClickedId = item.getItemId();
    if (itemThatWasClickedId == R.id.action_save) {
        // display message if text field is empty
        if (TextUtils.isEmpty(nameGroup.getText().toString())) {
            nameGroup.setError(getString(R.string.required));
            return false;
        }
        Log.d(TAG, "Second step: invite members to group");
        // String deepLink = getString(R.string.invitation_deep_link) + "?groupToBeAddedID=" + groupID+ "?inviterToGroupUID=" + MainActivity.getCurrentUID();
        newgroup_id = databaseReference.child("groups").push().getKey();
        String name = nameGroup.getText().toString();
        String description = descriptionGroup.getText().toString();
        // id is useless
        final Group newGroup = new Group("0", name, "noImage", description, 1);
        // for saving image
        StorageReference uProfileImageFilenameRef = storageReference.child("groups").child(newgroup_id).child(newgroup_id + "_profileImage.jpg");
        // Get the data from an ImageView as bytes
        imageGroup.setDrawingCacheEnabled(true);
        imageGroup.buildDrawingCache();
        Bitmap bitmap = imageGroup.getDrawingCache();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] imageData = baos.toByteArray();
        UploadTask uploadTask = uProfileImageFilenameRef.putBytes(imageData);
        uploadTask.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {

            @Override
            public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                if (task.isSuccessful()) {
                    newGroup.setImage(task.getResult().getDownloadUrl().toString());
                    Log.d(TAG, "group img url: " + newGroup.getImage());
                    databaseReference.child("groups").child(newgroup_id).setValue(newGroup);
                    String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
                    databaseReference.child("groups").child(newgroup_id).child("timestamp").setValue(timeStamp);
                    databaseReference.child("groups").child(newgroup_id).child("numberMembers").setValue(1);
                    FirebaseUtils.getInstance().joinGroupFirebase(MainActivity.getCurrentUID(), newgroup_id);
                    Log.d(TAG, "group " + newgroup_id + " created");
                    // add event for GROUP_ADD
                    User currentUser = MainActivity.getCurrentUser();
                    Event event = new Event(newgroup_id, Event.EventType.GROUP_ADD, currentUser.getName() + " " + currentUser.getSurname(), newGroup.getName());
                    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);
                }
            }
        });
        Intent intent = new Intent(getApplicationContext(), NewMemberActivity.class);
        intent.putExtra("groupID", newgroup_id);
        intent.putExtra("groupName", name);
        startActivity(intent);
        finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : Group(com.polito.mad17.madmax.entities.Group) User(com.polito.mad17.madmax.entities.User) StorageReference(com.google.firebase.storage.StorageReference) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Bitmap(android.graphics.Bitmap) UploadTask(com.google.firebase.storage.UploadTask) Event(com.polito.mad17.madmax.entities.Event) MotionEvent(android.view.MotionEvent) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Event (com.polito.mad17.madmax.entities.Event)15 User (com.polito.mad17.madmax.entities.User)15 SimpleDateFormat (java.text.SimpleDateFormat)14 Intent (android.content.Intent)7 DataSnapshot (com.google.firebase.database.DataSnapshot)6 DatabaseError (com.google.firebase.database.DatabaseError)6 ValueEventListener (com.google.firebase.database.ValueEventListener)6 Bitmap (android.graphics.Bitmap)3 NonNull (android.support.annotation.NonNull)3 MotionEvent (android.view.MotionEvent)3 StorageReference (com.google.firebase.storage.StorageReference)3 UploadTask (com.google.firebase.storage.UploadTask)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)2 DatabaseReference (com.google.firebase.database.DatabaseReference)2 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 TabLayout (android.support.design.widget.TabLayout)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1