Search in sources :

Example 16 with User

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

the class HashMapFriendsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final View result;
    if (convertView == null) {
        result = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
    } else {
        result = convertView;
    }
    Map.Entry<String, User> item = getItem(position);
    TextView name = (TextView) result.findViewById(R.id.tv_sender);
    TextView balanceText = (TextView) result.findViewById(R.id.tv_balance_text);
    balanceText.setVisibility(View.INVISIBLE);
    TextView balance = (TextView) result.findViewById(R.id.tv_balance);
    balance.setVisibility(View.INVISIBLE);
    name.setText(item.getValue().getName() + " " + item.getValue().getSurname());
    ImageView photo = (ImageView) result.findViewById(R.id.img_photo);
    // Loading profile image
    Glide.with(parent.getContext()).load(item.getValue().getProfileImage()).placeholder(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(parent.getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(photo);
    balance.setVisibility(View.GONE);
    return result;
}
Also used : User(com.polito.mad17.madmax.entities.User) CropCircleTransformation(com.polito.mad17.madmax.entities.CropCircleTransformation) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Map(java.util.Map)

Example 17 with User

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

the class ProfileEdit method onCreate.

@Override
@TargetApi(23)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_profile);
    nameView = (EditText) this.findViewById(R.id.name);
    nameView.setText(currentUser.getName());
    surnameView = (EditText) this.findViewById(R.id.surname);
    surnameView.setText(currentUser.getSurname());
    usernameView = (EditText) this.findViewById(R.id.sender_photo);
    usernameView.setText(currentUser.getUsername());
    // emailView = (EditText) this.findViewById(R.id.email);
    // emailView.setText(currentUser.getEmail());
    passwordView = (EditText) this.findViewById(R.id.password);
    // progressDialog = new ProgressDialog(ProfileEdit.this);
    profileImageView = (ImageView) this.findViewById(R.id.profile_image);
    String profileImage = currentUser.getProfileImage();
    if (profileImage != null && !profileImage.equals("")) {
        // Loading image
        Glide.with(this).load(profileImage).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(profileImageView);
        Log.d(TAG, "image url: " + MainActivity.getCurrentUser().getProfileImage());
    } else {
        // Loading image
        Glide.with(this).load(R.drawable.user_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(profileImageView);
    }
    profileImageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.i(TAG, "image clicked");
            if (MainActivity.shouldAskPermission()) {
                String[] perms = { "android.permission.READ_EXTERNAL_STORAGE" };
                int permsRequestCode = 200;
                requestPermissions(perms, permsRequestCode);
            }
            // allow to the user the choose his profile image
            Intent intent = new Intent();
            // Show only images, no videos or anything else
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            // Always show the chooser (if there are multiple options available)
            startActivityForResult(Intent.createChooser(intent, "Select picture"), PICK_IMAGE_REQUEST);
        // now see onActivityResult
        }
    });
    saveButton = (Button) this.findViewById(R.id.btn_save);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.i(TAG, "save clicked");
            if (updateAccount()) {
                Toast.makeText(ProfileEdit.this, getString(R.string.saved), Toast.LENGTH_SHORT).show();
                Intent i = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(i);
                finish();
            }
        }
    });
}
Also used : Intent(android.content.Intent) MainActivity(com.polito.mad17.madmax.activities.MainActivity) ImageView(android.widget.ImageView) View(android.view.View) TargetApi(android.annotation.TargetApi)

Example 18 with User

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

the class FirebaseServiceMessage method onMessageReceived.

/*    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate");
    }*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    String body = remoteMessage.getNotification().getBody();
    Map<String, String> data = remoteMessage.getData();
    Log.d(TAG, "notification body: " + body);
    String message[], messageContent = null;
    // Creates an explicit intent for an Activity in the app
    Intent resultIntent = null;
    messageContent = body;
    switch(data.get("notificationTitle")) {
        case "notification_invite":
            resultIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
            resultIntent.putExtra("groupID", data.get("groupID"));
            break;
        case "notification_expense_added":
            resultIntent = new Intent(getApplicationContext(), ExpenseDetailActivity.class);
            resultIntent.putExtra("groupID", data.get("groupID"));
            resultIntent.putExtra("expenseID", data.get("expenseID"));
            break;
        case "notification_expense_removed":
            resultIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
            resultIntent.putExtra("groupID", data.get("groupID"));
            resultIntent.putExtra("expenseID", data.get("expenseID"));
            break;
        case "notification_proposalExpense_added":
            resultIntent = new Intent(getApplicationContext(), PendingExpenseDetailActivity.class);
            resultIntent.putExtra("expenseID", data.get("expenseID"));
            break;
    }
    // User provaCurrent = MainActivity.getCurrentUser();
    resultIntent.putExtra("userID", getCurrentUID());
    NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.icon).setContentTitle(remoteMessage.getNotification().getTitle()).setContentText(messageContent);
    // The stack builder object will contain an artificial back stack for the started Activity.
    // This ensures that navigating backward from the Activity leads out of your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    // mId allows you to update the notification later on.
    mNotificationManager.notify(1, notification);
/*String body = remoteMessage.getNotification().getBody();
        Log.d(TAG, "notification body: "+body);
        Map<String, String> data = remoteMessage.getData();
        showNotification(remoteMessage.getNotification().getTitle(), body, data);*/
}
Also used : NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) GroupDetailActivity(com.polito.mad17.madmax.activities.groups.GroupDetailActivity) ExpenseDetailActivity(com.polito.mad17.madmax.activities.expenses.ExpenseDetailActivity) PendingExpenseDetailActivity(com.polito.mad17.madmax.activities.expenses.PendingExpenseDetailActivity) NotificationCompat(android.support.v7.app.NotificationCompat) PendingExpenseDetailActivity(com.polito.mad17.madmax.activities.expenses.PendingExpenseDetailActivity) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder)

Example 19 with User

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

the class FirebaseUtils method removeExpenseFirebase.

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

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String groupID = dataSnapshot.child("groupID").getValue(String.class);
            // aggiunto da riky per mandare la notifica a tutti tranne a chi ha eliminato la spesa
            databaseReference.child("expenses").child(expenseID).child("deletedBy").setValue(MainActivity.getCurrentUID());
            // Elimino spesa dal gruppo
            databaseReference.child("groups").child(groupID).child("expenses").child(expenseID).setValue(false);
            // Per ogni participant elimino la spesa dal suo elenco spese
            for (DataSnapshot participantSnapshot : dataSnapshot.child("participants").getChildren()) {
                String participantID = participantSnapshot.getKey();
                databaseReference.child("users").child(participantID).child("expenses").child(expenseID).setValue(false);
            }
            // Elimino commenti sulla spesa
            databaseReference.child("comments").child(groupID).removeValue();
            // Elimino spesa
            databaseReference.child("expenses").child(expenseID).child("deleted").setValue(true);
            // Toast.makeText(context,context.getString(R.string.expense_removed),Toast.LENGTH_SHORT).show();
            // add event for EXPENSE_REMOVE
            databaseReference.child("expenses").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.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, GroupDetailActivity.class);
                intent.putExtra("groupID", groupID);
                intent.putExtra("userID", MainActivity.getCurrentUID());
                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 20 with User

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

the class FirebaseUtils method leaveGroupFirebase.

public Integer leaveGroupFirebase(String userID, final String groupID) {
    Group g = GroupsFragment.groups.get(groupID);
    if (g != null) {
        HashMap<String, Double> balances = g.getCurrencyBalances();
        Boolean debt = false;
        Log.d(TAG, g.getName() + " contains those balances: ");
        if (balances != null) {
            for (Map.Entry<String, Double> entry : balances.entrySet()) {
                Log.d(TAG, entry.getKey() + " " + entry.getValue());
                if (entry.getValue() < 0)
                    debt = true;
            }
        }
        if (debt) {
            Log.d(TAG, "Cannot leave group");
            return 0;
        } else {
            Log.d(TAG, "Nessuno debito, abbandono in corso");
            // Elimino gruppo da lista gruppi dello user
            databaseReference.child("users").child(userID).child("groups").child(groupID).setValue(false);
            // Elimino user dalla lista dei members del gruppo
            databaseReference.child("groups").child(groupID).child("members").child(userID).child("deleted").setValue(true);
            // Elimino gruppo da cache
            GroupsFragment.groups.remove(groupID);
            // Elimino gruppo dagli shared groups tra me e ogni membro del gruppo
            deleteSharedGroup(MainActivity.getCurrentUID(), groupID);
            return 2;
        }
    } else {
        Log.d(TAG, "Bilancio del gruppo: " + groupID + " non disponibile adesso. Riprovare.");
        return null;
    }
}
Also used : Group(com.polito.mad17.madmax.entities.Group) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

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