Search in sources :

Example 51 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatSharedMediaAdapter method setImageData.

private void setImageData(ImageViewHolder viewHolder, int i) {
    BaseMessage message = messageArrayList.get(i);
    boolean isImageNotSafe = Extensions.getImageModeration(context, message);
    String smallUrl = Extensions.getThumbnailGeneration(context, message);
    if (smallUrl != null) {
        Glide.with(context).asBitmap().load(smallUrl).into(viewHolder.imageView);
    } else {
        Glide.with(context).asBitmap().load(((MediaMessage) message).getAttachment().getFileUrl()).into(viewHolder.imageView);
    }
    if (isImageNotSafe) {
        viewHolder.imageView.setAlpha(0.3f);
        viewHolder.sensitiveLayout.setVisibility(View.VISIBLE);
    } else {
        viewHolder.imageView.setAlpha(1f);
        viewHolder.sensitiveLayout.setVisibility(View.GONE);
    }
    viewHolder.imageView.setOnClickListener(view -> {
        if (isImageNotSafe) {
            AlertDialog.Builder alert = new AlertDialog.Builder(context);
            alert.setTitle("Unsafe Content");
            alert.setIcon(R.drawable.ic_hand);
            alert.setMessage("Are you surely want to see this unsafe content");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MediaUtils.openFile(((MediaMessage) message).getAttachment().getFileUrl(), context);
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            alert.create().show();
        } else {
            Intent intent = new Intent(context, CometChatMediaViewActivity.class);
            intent.putExtra(UIKitConstants.IntentStrings.NAME, message.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.UID, message.getSender().getUid());
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, message.getSentAt());
            intent.putExtra(UIKitConstants.IntentStrings.INTENT_MEDIA_MESSAGE, ((MediaMessage) message).getAttachment().getFileUrl());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, message.getType());
            context.startActivity(intent);
        }
    });
    viewHolder.itemView.setTag(R.string.baseMessage, message);
}
Also used : AlertDialog(android.app.AlertDialog) MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent)

Example 52 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatSharedImages method setImageAdapter.

/**
 * This method is used to setAdapter for Image messages.
 * @param baseMessageList is object of List<BaseMessage> which contains list of messages.
 * @see CometChatSharedMediaAdapter
 */
private void setImageAdapter(List<BaseMessage> baseMessageList) {
    List<BaseMessage> filteredList = removeDeletedMessage(baseMessageList);
    messageList.addAll(filteredList);
    if (adapter == null) {
        adapter = new CometChatSharedMediaAdapter(getContext(), filteredList);
        rvFiles.setAdapter(adapter);
    } else
        adapter.updateMessageList(filteredList);
}
Also used : BaseMessage(com.cometchat.pro.models.BaseMessage) CometChatSharedMediaAdapter(com.cometchat.pro.uikit.ui_components.shared.cometchatSharedMedia.adapter.CometChatSharedMediaAdapter)

Example 53 with BaseMessage

use of com.cometchat.pro.models.BaseMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MyFirebaseMessagingService method onMessageReceived.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    try {
        count++;
        json = new JSONObject(remoteMessage.getData());
        Log.d(TAG, "JSONObject: " + json.toString());
        JSONObject messageData = new JSONObject(json.getString("message"));
        BaseMessage baseMessage = CometChatHelper.processMessage(new JSONObject(remoteMessage.getData().get("message")));
        if (baseMessage instanceof Call) {
            call = (Call) baseMessage;
            isCall = true;
        }
        showNotifcation(baseMessage);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : Call(com.cometchat.pro.core.Call) JSONObject(org.json.JSONObject) BaseMessage(com.cometchat.pro.models.BaseMessage) JSONException(org.json.JSONException)

Aggregations

BaseMessage (com.cometchat.pro.models.BaseMessage)53 View (android.view.View)19 ImageView (android.widget.ImageView)19 TextView (android.widget.TextView)19 CardView (androidx.cardview.widget.CardView)19 RecyclerView (androidx.recyclerview.widget.RecyclerView)19 MaterialCardView (com.google.android.material.card.MaterialCardView)19 Intent (android.content.Intent)18 MediaMessage (com.cometchat.pro.models.MediaMessage)14 JSONException (org.json.JSONException)14 CometChatException (com.cometchat.pro.exceptions.CometChatException)11 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)11 JSONObject (org.json.JSONObject)10 TextMessage (com.cometchat.pro.models.TextMessage)8 User (com.cometchat.pro.models.User)7 AlertDialog (android.app.AlertDialog)6 DialogInterface (android.content.DialogInterface)6 CustomMessage (com.cometchat.pro.models.CustomMessage)5 Call (com.cometchat.pro.core.Call)4 Attachment (com.cometchat.pro.models.Attachment)4