Search in sources :

Example 1 with Comment

use of com.polito.mad17.madmax.entities.Comment 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");
    // 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);
            // 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 2 with Comment

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

the class ExpenseCommentsViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ExpenseCommentsViewHolder expenseCommentsViewHolder, int position) {
    Comment comment = getItem(position).getValue();
    // loading author profile photo
    Glide.with(context).load(comment.getAuthorPhoto()).centerCrop().bitmapTransform(new CropCircleTransformation(context)).diskCacheStrategy(DiskCacheStrategy.ALL).into(expenseCommentsViewHolder.authorPhoto);
    expenseCommentsViewHolder.authorTextView.setText(comment.getAuthor());
    expenseCommentsViewHolder.commentTextView.setText(comment.getMessage());
    expenseCommentsViewHolder.timestampTextView.setText(context.getString(R.string.day) + " " + comment.getDate() + " " + context.getString(R.string.at) + " " + comment.getTime());
}
Also used : Comment(com.polito.mad17.madmax.entities.Comment) CropCircleTransformation(com.polito.mad17.madmax.entities.CropCircleTransformation)

Aggregations

Comment (com.polito.mad17.madmax.entities.Comment)2 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 EditText (android.widget.EditText)1 CropCircleTransformation (com.polito.mad17.madmax.entities.CropCircleTransformation)1 Event (com.polito.mad17.madmax.entities.Event)1 User (com.polito.mad17.madmax.entities.User)1 SimpleDateFormat (java.text.SimpleDateFormat)1