kirantrathod / Be_You

A chat application. Inspired from Facebook and Whats App.
14 stars 1 forks source link

Delete friend from FriendsActivity on longclick #10

Open ghost opened 6 years ago

ghost commented 6 years ago

It would be something like this:

        mView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {

                deleteUser(user);
                /* TODO: add dialog
                new AlertDialog.Builder(context)
                        .setTitle("Delete Friend")
                        .setMessage("Are you sure want to delete " + user.getName() + "?")
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                                deleteUser(user);
                            }
                        })
                        .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        }).show();*/

                return true;
            }
        });

    }
}

private void deleteUser(final User user) {
    mAdapter.remove(user);
    mFriendsDbRef.child(user.getUid()).removeValue();
}