Search in sources :

Example 1 with AlCallback

use of com.applozic.mobicomkit.listners.AlCallback in project Applozic-Android-SDK by AppLozic.

the class MobiComAttachmentSelectorActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    try {
        if (imagesAdapter != null) {
            View view = galleryImagesGridView.getChildAt(imagesAdapter.getCount() - 1);
            if (view != null) {
                ImageView imageView = view.findViewById(R.id.galleryImageView);
                if (imageView != null) {
                    imageView.setEnabled(true);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (resultCode == Activity.RESULT_OK) {
        final Uri selectedFileUri = (intent == null ? null : intent.getData());
        Utils.printLog(MobiComAttachmentSelectorActivity.this, TAG, "selectedFileUri :: " + selectedFileUri);
        if (selectedFileUri != null) {
            if (getApplicationContext() instanceof AttachmentFilteringListener) {
                AttachmentFilteringListener filteringListener = (AttachmentFilteringListener) getApplicationContext();
                filteringListener.onAttachmentSelected(this, selectedFileUri, new AlCallback() {

                    @Override
                    public void onSuccess(Object response) {
                        processUri(selectedFileUri);
                    }

                    @Override
                    public void onError(Object error) {
                        Utils.printLog(getApplicationContext(), TAG, "Error in file : " + GsonUtils.getJsonFromObject(error, Object.class));
                    }
                });
            } else {
                processUri(selectedFileUri);
            }
        }
    }
    super.onActivityResult(requestCode, resultCode, intent);
}
Also used : ImageView(android.widget.ImageView) AlCallback(com.applozic.mobicomkit.listners.AlCallback) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) Uri(android.net.Uri) PatternSyntaxException(java.util.regex.PatternSyntaxException) AttachmentFilteringListener(com.applozic.mobicomkit.listners.AttachmentFilteringListener)

Example 2 with AlCallback

use of com.applozic.mobicomkit.listners.AlCallback in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method onItemClick.

@Override
public boolean onItemClick(int position, MenuItem item) {
    if (messageList.size() <= position || position == -1) {
        return true;
    }
    final Message message = messageList.get(position);
    if (message.isTempDateType() || message.isCustom()) {
        return true;
    }
    switch(item.getItemId()) {
        case 0:
            if (getActivity() == null) {
                break;
            }
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplozicService.getContext(getContext()).getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setText(message.getMessage());
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText(ApplozicService.getContext(getContext()).getString(R.string.copied_message), message.getMessage());
                clipboard.setPrimaryClip(clip);
            }
            break;
        case 1:
            conversationUIService.startContactActivityForResult(message, null);
            break;
        case 2:
            messageDatabaseService.deleteMessageFromDb(message);
            deleteMessageFromDeviceList(message.getKeyString());
            Message messageToResend = new Message(message);
            messageToResend.setCreatedAtTime(System.currentTimeMillis() + MobiComUserPreference.getInstance(getActivity()).getDeviceTimeOffset());
            conversationService.sendMessage(messageToResend, userDisplayName);
            break;
        case 3:
            String messageKeyString = message.getKeyString();
            AlTask.execute(new DeleteConversationAsyncTask(conversationService, message, contact));
            deleteMessageFromDeviceList(messageKeyString);
            break;
        case 4:
            final String deleteForAllMessageKey = message.getKeyString();
            final ProgressDialog progressBar = new ProgressDialog(getContext());
            progressBar.show();
            progressBar.setMessage(Utils.getString(getContext(), R.string.delete_thread_text));
            AlTask.execute(new MessageDeleteTask(getContext(), deleteForAllMessageKey, true, new AlCallback() {

                @Override
                public void onSuccess(Object response) {
                    int index = messageList.indexOf(message);
                    message.setAsDeletedForAll();
                    messageDatabaseService.replaceExistingMessage(message);
                    updateMessageAtIndex(index, message, recyclerDetailConversationAdapter);
                    if (progressBar != null) {
                        progressBar.dismiss();
                    }
                }

                @Override
                public void onError(Object error) {
                    if (progressBar != null) {
                        progressBar.dismiss();
                    }
                    Toast.makeText(ApplozicService.getContext(getContext()), Utils.getString(getContext(), R.string.delete_conversation_failed), Toast.LENGTH_SHORT).show();
                }
            }));
            break;
        case 5:
            String messageJson = GsonUtils.getJsonFromObject(message, Message.class);
            conversationUIService.startMessageInfoFragment(messageJson);
            break;
        case 6:
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            if (message.getFilePaths() != null) {
                Uri shareUri = null;
                if (Utils.hasNougat()) {
                    shareUri = ALFileProvider.getUriForFile(ApplozicService.getContext(getContext()), Utils.getMetaDataValue(getActivity(), MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", new File(message.getFilePaths().get(0)));
                } else {
                    shareUri = Uri.fromFile(new File(message.getFilePaths().get(0)));
                }
                shareIntent.setDataAndType(shareUri, "text/x-vcard");
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri);
                if (!TextUtils.isEmpty(message.getMessage())) {
                    shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
                }
                shareIntent.setType(FileUtils.getMimeType(new File(message.getFilePaths().get(0))));
            } else {
                shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
                shareIntent.setType("text/plain");
            }
            startActivity(Intent.createChooser(shareIntent, ApplozicService.getContext(getContext()).getString(R.string.send_message_to)));
            break;
        case 7:
            try {
                Configuration config = ApplozicService.getContext(getContext()).getResources().getConfiguration();
                messageMetaData = new HashMap<>();
                String displayName;
                if (message.getGroupId() != null) {
                    if (loggedInUserId.equals(message.getContactIds()) || TextUtils.isEmpty(message.getContactIds())) {
                        displayName = ApplozicService.getContext(getContext()).getString(R.string.you_string);
                    } else {
                        displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
                    }
                } else {
                    if (message.isTypeOutbox()) {
                        displayName = ApplozicService.getContext(getContext()).getString(R.string.you_string);
                    } else {
                        displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
                    }
                }
                nameTextView.setText(displayName);
                if (message.hasAttachment()) {
                    FileMeta fileMeta = message.getFileMetas();
                    imageViewForAttachmentType.setVisibility(VISIBLE);
                    if (fileMeta.getContentType().contains("image")) {
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_image_camera_alt);
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.photo_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        galleryImageView.setVisibility(VISIBLE);
                        imageViewRLayout.setVisibility(VISIBLE);
                        imageThumbnailLoader.loadImage(message, galleryImageView);
                    } else if (fileMeta.getContentType().contains("video")) {
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_video);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                            if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
                                imageViewForAttachmentType.setScaleX(-1);
                            }
                        }
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.video_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        if (message.getFilePaths() != null && message.getFilePaths().size() > 0) {
                            if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) {
                                galleryImageView.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString()));
                            } else {
                                imageCache.addBitmapToCache(message.getKeyString(), fileClientService.getOrCreateVideoThumbnail(message.getFilePaths().get(0)));
                                galleryImageView.setImageBitmap(fileClientService.getOrCreateVideoThumbnail(message.getFilePaths().get(0)));
                            }
                        }
                        galleryImageView.setVisibility(VISIBLE);
                        imageViewRLayout.setVisibility(VISIBLE);
                    } else if (fileMeta.getContentType().contains("audio")) {
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_music_note);
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.audio_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        galleryImageView.setVisibility(View.GONE);
                        imageViewRLayout.setVisibility(View.GONE);
                    } else if (message.isContactMessage()) {
                        MobiComVCFParser parser = new MobiComVCFParser();
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
                        try {
                            VCFContactData data = parser.parseCVFContactData(message.getFilePaths().get(0));
                            if (data != null) {
                                messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.contact_string));
                                messageTextView.append(" " + data.getName());
                            }
                        } catch (Exception e) {
                            imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.contact_string));
                        }
                        galleryImageView.setVisibility(View.GONE);
                        imageViewRLayout.setVisibility(View.GONE);
                    } else {
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_attachment);
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.attachment_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        galleryImageView.setVisibility(View.GONE);
                        imageViewRLayout.setVisibility(View.GONE);
                    }
                    imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(ApplozicService.getContext(getContext()), R.color.apploizc_lite_gray_color));
                } else if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
                    imageViewForAttachmentType.setVisibility(VISIBLE);
                    galleryImageView.setVisibility(VISIBLE);
                    imageViewRLayout.setVisibility(VISIBLE);
                    messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.al_location_string));
                    imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_location_on_white_24dp);
                    imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(ApplozicService.getContext(getContext()), R.color.apploizc_lite_gray_color));
                    messageImageLoader.setLoadingImage(R.drawable.applozic_map_offline_thumbnail);
                    messageImageLoader.loadImage(LocationUtils.loadStaticMap(message.getMessage(), geoApiKey), galleryImageView);
                } else {
                    imageViewForAttachmentType.setVisibility(View.GONE);
                    imageViewRLayout.setVisibility(View.GONE);
                    galleryImageView.setVisibility(View.GONE);
                    messageTextView.setText(message.getMessage());
                }
                messageMetaData.put(Message.MetaDataType.AL_REPLY.getValue(), message.getKeyString());
                if (messageMetaData != null && !messageMetaData.isEmpty()) {
                    String replyMessageKey = messageMetaData.get(Message.MetaDataType.AL_REPLY.getValue());
                    if (!TextUtils.isEmpty(replyMessageKey) && (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())))) {
                        messageDatabaseService.updateMessageReplyType(replyMessageKey, Message.ReplyMessage.REPLY_MESSAGE.getValue());
                    }
                }
                attachReplyCancelLayout.setVisibility(VISIBLE);
                replayRelativeLayout.setVisibility(VISIBLE);
            } catch (Exception e) {
            }
            break;
        case 8:
            AlTask.execute(new AlMessageReportTask(message.getKeyString(), conversationService, new AlCallback() {

                @Override
                public void onSuccess(Object response) {
                    Toast.makeText(getContext(), ApplozicService.getContext(getContext()).getString(R.string.message_reported_successfully), Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onError(Object error) {
                    Toast.makeText(getContext(), ApplozicService.getContext(getContext()).getString(R.string.failed_to_report_message), Toast.LENGTH_SHORT).show();
                }
            }));
            break;
    }
    return true;
}
Also used : VCFContactData(com.applozic.mobicomkit.contact.VCFContactData) AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) Message(com.applozic.mobicomkit.api.conversation.Message) Configuration(android.content.res.Configuration) ViewConfiguration(android.view.ViewConfiguration) MobiComVCFParser(com.applozic.mobicomkit.contact.MobiComVCFParser) DeleteConversationAsyncTask(com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) Context(android.content.Context) AlMessageReportTask(com.applozic.mobicomkit.api.conversation.AlMessageReportTask) Intent(android.content.Intent) AlCallback(com.applozic.mobicomkit.listners.AlCallback) Collections.disjoint(java.util.Collections.disjoint) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException) MessageDeleteTask(com.applozic.mobicomkit.api.conversation.MessageDeleteTask) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 3 with AlCallback

use of com.applozic.mobicomkit.listners.AlCallback in project Applozic-Android-SDK by AppLozic.

the class MobiComKitPeopleActivity method onGroupSelected.

@Override
public void onGroupSelected(final Channel channel) {
    Intent intent = null;
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (!ChannelService.getInstance(MobiComKitPeopleActivity.this).processIsUserPresentInChannel(channel.getKey())) {
            Toast.makeText(this, getString(R.string.unable_share_message), Toast.LENGTH_SHORT).show();
            return;
        }
        if ("text/plain".equals(type)) {
            intent = new Intent(this, ConversationActivity.class);
            intent.putExtra(GROUP_ID, channel.getKey());
            intent.putExtra(GROUP_NAME, channel.getName());
            intent.putExtra(ConversationUIService.DEFAULT_TEXT, intentExtra.getStringExtra(Intent.EXTRA_TEXT));
            startActivity(intent);
            finish();
        } else if (type.startsWith("image/") || type.startsWith("audio/") || type.startsWith("video/")) {
            final Uri fileUri = (Uri) intentExtra.getParcelableExtra(Intent.EXTRA_STREAM);
            if (fileUri != null) {
                long maxSize = alCustomizationSettings.getMaxAttachmentSizeAllowed() * 1024 * 1024;
                if (FileUtils.isMaxUploadSizeReached(this, fileUri, maxSize)) {
                    Toast.makeText(this, getString(R.string.info_attachment_max_allowed_file_size), Toast.LENGTH_LONG).show();
                    return;
                }
                if (getApplicationContext() instanceof AttachmentFilteringListener) {
                    ((AttachmentFilteringListener) getApplicationContext()).onAttachmentSelected(this, fileUri, new AlCallback() {

                        @Override
                        public void onSuccess(Object response) {
                            processAttachmentUri(fileUri, null, channel);
                        }

                        @Override
                        public void onError(Object error) {
                            Utils.printLog(getApplicationContext(), TAG, "Error in file : " + GsonUtils.getJsonFromObject(error, Object.class));
                        }
                    });
                } else {
                    processAttachmentUri(fileUri, null, channel);
                }
            }
        }
    } else {
        intent = new Intent();
        intent.putExtra(GROUP_ID, channel.getKey());
        intent.putExtra(GROUP_NAME, channel.getName());
        finishActivity(intent);
    }
}
Also used : ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) Intent(android.content.Intent) AlCallback(com.applozic.mobicomkit.listners.AlCallback) Uri(android.net.Uri) AttachmentFilteringListener(com.applozic.mobicomkit.listners.AttachmentFilteringListener)

Example 4 with AlCallback

use of com.applozic.mobicomkit.listners.AlCallback in project Applozic-Android-SDK by AppLozic.

the class MobiComKitPeopleActivity method onCustomContactSelected.

@Override
public void onCustomContactSelected(final Contact contact) {
    Intent intent = null;
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (contact.isBlocked()) {
            Toast.makeText(this, getString(R.string.user_is_blocked), Toast.LENGTH_SHORT).show();
            return;
        }
        if ("text/plain".equals(type)) {
            intent = new Intent(this, ConversationActivity.class);
            intent.putExtra(USER_ID, contact.getUserId());
            intent.putExtra(ConversationUIService.DEFAULT_TEXT, intentExtra.getStringExtra(Intent.EXTRA_TEXT));
            startActivity(intent);
            finish();
        } else if (type.startsWith("image/") || type.startsWith("audio/") || type.startsWith("video/")) {
            final Uri fileUri = (Uri) intentExtra.getParcelableExtra(Intent.EXTRA_STREAM);
            long maxSize = alCustomizationSettings.getMaxAttachmentSizeAllowed() * 1024 * 1024;
            if (FileUtils.isMaxUploadSizeReached(this, fileUri, maxSize)) {
                Toast.makeText(this, getString(R.string.info_attachment_max_allowed_file_size), Toast.LENGTH_LONG).show();
                return;
            }
            if (getApplicationContext() instanceof AttachmentFilteringListener) {
                ((AttachmentFilteringListener) getApplicationContext()).onAttachmentSelected(this, fileUri, new AlCallback() {

                    @Override
                    public void onSuccess(Object response) {
                        processAttachmentUri(fileUri, contact, null);
                    }

                    @Override
                    public void onError(Object error) {
                        Utils.printLog(getApplicationContext(), TAG, "Error in file : " + GsonUtils.getJsonFromObject(error, Object.class));
                    }
                });
            } else {
                processAttachmentUri(fileUri, contact, null);
            }
        }
    } else {
        if (ApplozicClient.getInstance(this).isStartGroupOfTwo()) {
            ProgressDialog progressDialog = ProgressDialog.show(this, "", getString(R.string.please_wait_creating_group_of_two), true);
            AlTask.execute(new AlGroupOfTwoCreateTask(MobiComKitPeopleActivity.this, MobiComUserPreference.getInstance(this).getParentGroupKey(), contact, new AlGroupOfTwoCreateTask.ChannelCreateListener() {

                @Override
                public void onSuccess(@NonNull Channel channel) {
                    if (progressDialog != null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    if (channel != null) {
                        Intent intent = new Intent(MobiComKitPeopleActivity.this, ConversationActivity.class);
                        intent.putExtra(ConversationUIService.GROUP_ID, channel.getKey());
                        intent.putExtra(ConversationUIService.GROUP_NAME, channel.getName());
                        startActivity(intent);
                    }
                }

                @Override
                public void onFailure() {
                    if (progressDialog != null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                }
            }));
        } else {
            intent = new Intent();
            intent.putExtra(USER_ID, contact.getUserId());
            finishActivity(intent);
        }
    }
}
Also used : ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) AlGroupOfTwoCreateTask(com.applozic.mobicomkit.api.conversation.AlGroupOfTwoCreateTask) NonNull(androidx.annotation.NonNull) Channel(com.applozic.mobicommons.people.channel.Channel) Intent(android.content.Intent) AlCallback(com.applozic.mobicomkit.listners.AlCallback) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) AttachmentFilteringListener(com.applozic.mobicomkit.listners.AttachmentFilteringListener)

Example 5 with AlCallback

use of com.applozic.mobicomkit.listners.AlCallback in project Applozic-Android-SDK by AppLozic.

the class AlAuthService method refreshToken.

// deprecated >>>
// Cleanup: private
/**
 * @deprecated Use {@link RefreshAuthTokenTask}.
 *
 * <p>Get a fresh token from the server and replaces the current (invalid) one with it.</p>
 */
@Deprecated
public static void refreshToken(@NonNull Context context, @Nullable String loadingMessage, @Nullable final AlCallback callback) {
    final ProgressDialog progressDialog = new ProgressDialog(getActivity(context));
    progressDialog.setMessage(loadingMessage);
    progressDialog.setCancelable(false);
    progressDialog.show();
    refreshToken(context, new AlCallback() {

        @Override
        public void onSuccess(Object response) {
            if (progressDialog != null) {
                progressDialog.dismiss();
            }
            if (callback != null) {
                callback.onSuccess(response);
            }
        }

        @Override
        public void onError(Object error) {
            if (progressDialog != null) {
                progressDialog.dismiss();
            }
            if (callback != null) {
                callback.onSuccess(error);
            }
        }
    });
}
Also used : AlCallback(com.applozic.mobicomkit.listners.AlCallback) ProgressDialog(android.app.ProgressDialog)

Aggregations

AlCallback (com.applozic.mobicomkit.listners.AlCallback)7 Uri (android.net.Uri)4 ProgressDialog (android.app.ProgressDialog)3 Intent (android.content.Intent)3 AttachmentFilteringListener (com.applozic.mobicomkit.listners.AttachmentFilteringListener)3 ConversationActivity (com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 Context (android.content.Context)1 Configuration (android.content.res.Configuration)1 View (android.view.View)1 ViewConfiguration (android.view.ViewConfiguration)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 NonNull (androidx.annotation.NonNull)1 User (com.applozic.mobicomkit.api.account.user.User)1 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)1 AlGroupOfTwoCreateTask (com.applozic.mobicomkit.api.conversation.AlGroupOfTwoCreateTask)1 AlMessageReportTask (com.applozic.mobicomkit.api.conversation.AlMessageReportTask)1 Message (com.applozic.mobicomkit.api.conversation.Message)1 MessageDeleteTask (com.applozic.mobicomkit.api.conversation.MessageDeleteTask)1