use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class ShowMediaListener method popUpMenuTopSheet.
public void popUpMenuTopSheet(RealmRoomMessage roomMessage) {
List<Integer> items = new ArrayList<>();
items.add(R.string.save_to_gallery);
MessageObject messageObject = MessageObject.create(roomMessage);
ProtoGlobal.RoomMessageType messageType = ProtoGlobal.RoomMessageType.forNumber(messageObject.messageType);
if (messageType == ProtoGlobal.RoomMessageType.VIDEO || messageType == ProtoGlobal.RoomMessageType.VIDEO_TEXT) {
items.add(R.string.share_video_file);
} else {
items.add(R.string.share_image);
}
if (RoomObject.isRoomPublic(room)) {
if (MessageObject.canSharePublic(messageObject)) {
items.add(R.string.share_file_link);
}
}
new TopSheetDialog(getContext()).setListDataWithResourceId(items, -1, position -> {
if (items.get(position) == R.string.save_to_gallery) {
saveToGallery(messageObject);
} else if (items.get(position) == R.string.share_file_link) {
shareMediaLink(messageObject);
} else {
shareContent(messageObject);
}
}).show();
}
use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class FragmentShearedMedia method initComponent.
private void initComponent(View view) {
FrameLayout toolbarLayout = view.findViewById(R.id.frg_shared_media_ll_toolbar_layout);
FragmentMediaContainer mediaContainer = new FragmentMediaContainer(getContext(), this);
mediaContainer.setListener(i -> {
switch(i) {
case FragmentMediaContainer.CALL_TAG:
getActivity().startActivity(new Intent(getContext(), CallActivity.class));
break;
case FragmentMediaContainer.MEDIA_TAG:
if (!MusicPlayer.isVoice) {
Intent intent = new Intent(context, ActivityMain.class);
intent.putExtra(ActivityMain.openMediaPlayer, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(intent);
}
break;
case FragmentMediaContainer.PLAY_TAG:
break;
}
});
sharedMediaToolbar = new Toolbar(getContext());
sharedMediaToolbar.setBackIcon(new BackDrawable(false));
sharedMediaToolbar.createToolbarItems();
sharedMediaToolbar.setTitle(getString(R.string.shared_media));
sharedMediaToolbar.setListener(i -> {
switch(i) {
case -1:
if (isSelectedMode) {
adapter.resetSelected();
sharedMediaToolbar.hideActionToolbar();
return;
}
popBackStackFragment();
break;
case deleteTag:
DbManager.getInstance().doRealmTask(realm -> {
String count = SelectedList.size() + "";
final RealmRoom realmRoom = RealmRoom.getRealmRoom(realm, roomId);
if (roomType == ProtoGlobal.Room.Type.CHAT && bothDeleteMessageId != null && bothDeleteMessageId.size() > 0) {
// TODO: 1/10/21 OPTIMAZE CODE
// show both Delete check box
String delete;
if (HelperCalander.isPersianUnicode) {
delete = HelperCalander.convertToUnicodeFarsiNumber(requireContext().getResources().getString(R.string.st_desc_delete) + count);
} else {
delete = HelperCalander.convertToUnicodeFarsiNumber(requireContext().getResources().getString(R.string.st_desc_delete) + "the");
}
new MaterialDialog.Builder(getContext()).limitIconToDefaultSize().content(delete).title(R.string.message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive((dialog, which) -> {
if (!dialog.isPromptCheckBoxChecked()) {
bothDeleteMessageId = null;
}
if (realmRoom != null) {
ArrayList<Long> selectedListForDel = new ArrayList<>();
ArrayList<Long> selectedDocumentListForDel = new ArrayList<>();
for (StructShearedMedia item : SelectedList) {
selectedListForDel.add(item.messageId);
selectedDocumentListForDel.add(item.documentId);
}
getMessageController().deleteSelectedMessage(roomType.getNumber(), roomId, selectedListForDel, selectedDocumentListForDel, bothDeleteMessageId);
}
resetItems();
}).checkBoxPromptRes(R.string.delete_item_dialog, false, null).show();
} else {
new MaterialDialog.Builder(requireContext()).title(R.string.message).content(getContext().getResources().getString(R.string.st_desc_delete) + count).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
bothDeleteMessageId = null;
if (realmRoom != null) {
ArrayList<Long> messageIds = new ArrayList<>();
ArrayList<Long> documentIds = new ArrayList<>();
for (StructShearedMedia item : SelectedList) {
messageIds.add(item.messageId);
documentIds.add(item.documentId);
}
getMessageController().deleteSelectedMessage(roomType.getNumber(), roomId, messageIds, documentIds, bothDeleteMessageId);
}
resetItems();
}
}).show();
}
});
break;
case forwardTag:
ArrayList<MessageObject> messageInfos = new ArrayList<>(SelectedList.size());
for (StructShearedMedia media : SelectedList) {
messageInfos.add(MessageObject.create(media.item));
}
FragmentChat.mForwardMessages = messageInfos;
adapter.resetSelected();
if (getActivity() instanceof ActivityMain) {
((ActivityMain) getActivity()).setForwardMessage(true);
((ActivityMain) getActivity()).removeAllFragmentFromMain();
/*new HelperFragment(getActivity().getSupportFragmentManager()).popBackStack(3);*/
}
break;
case seeInChatTag:
if (SelectedList.size() == 1) {
long messageId = SelectedList.get(0).messageId;
long documentId = SelectedList.get(0).documentId;
RealmRoomMessage.setGap(messageId, documentId);
goToPositionFromShardMedia.goToPosition(messageId, documentId);
goToPosition = true;
popBackStackFragment();
adapter.resetSelected();
popBackStackFragment();
}
break;
}
});
createActionMode();
toolbarLayout.addView(mediaContainer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, 39, Gravity.BOTTOM, 0, 60, 0, 0));
toolbarLayout.addView(sharedMediaToolbar);
progressBar = view.findViewById(R.id.asm_progress_bar_waiting);
AppUtils.setProgresColler(progressBar);
mediaTypesLayout = view.findViewById(R.id.asm_ll_media_types_buttons);
complete = new OnComplete() {
@Override
public void complete(boolean result, String messageOne, String MessageTwo) {
int whatAction = 0;
String number = "0";
if (messageOne != null) {
if (messageOne.length() > 0)
whatAction = Integer.parseInt(messageOne);
}
if (MessageTwo != null)
if (MessageTwo.length() > 0)
number = MessageTwo;
callBack(result, whatAction, number);
}
};
recyclerView = view.findViewById(R.id.asm_recycler_view_sheared_media);
recyclerView.setItemViewCacheSize(400);
recyclerView.setItemAnimator(null);
onScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(final RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (isThereAnyMoreItemToLoad) {
if (!isSendRequestForLoading) {
int lastVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
if (lastVisiblePosition + 30 >= offset) {
new RequestClientSearchRoomHistory().clientSearchRoomHistory(roomId, nextMessageId, nextDocumentId, mFilter);
isSendRequestForLoading = true;
progressBar.setVisibility(View.VISIBLE);
}
}
}
}
};
recyclerView.addOnScrollListener(onScrollListener);
checkSelectedDefaultTab();
makeSharedTypesViews();
checkSharedButtonsBackgrounds();
}
use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method bindView.
@Override
@CallSuper
public void bindView(final VH holder, List<Object> payloads) {
super.bindView(holder, payloads);
if (messageObject == null) {
return;
}
NewChatItemHolder mHolder;
if (holder instanceof NewChatItemHolder) {
mHolder = (NewChatItemHolder) holder;
} else if (holder instanceof LogItem.ViewHolder || holder instanceof LogWalletCardToCard.ViewHolder || holder instanceof LogWalletBill.ViewHolder || holder instanceof LogWalletTopup.ViewHolder || holder instanceof LogWallet.ViewHolder) {
messageClickListener.onItemShowingMessageId(messageObject);
return;
} else {
return;
}
this.holder = holder;
if (messageObject.forwardedMessage == null && messageObject.isSenderMe() && attachment != null && messageObject.status == MessageObject.STATUS_SENDING) {
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_PROGRESS, this);
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPRESS, this);
if (!Uploader.getInstance().isCompressingOrUploading(messageObject.id + "")) {
// TODO: 12/29/20 MESSAGE_REFACTOR
UploadObject fileObject = UploadObject.createForMessage(messageObject, type);
if (fileObject != null) {
Uploader.getInstance().upload(fileObject);
}
} else {
MessageProgress messageProgress = ((IProgress) holder).getProgress();
int progress = Uploader.getInstance().getUploadProgress(messageObject.id + "");
messageProgress.withProgress(progress);
receivedEvent(EventManager.ON_UPLOAD_PROGRESS, AccountManager.selectedAccount, String.valueOf(messageObject.id), progress);
}
} else {
EventManager.getInstance(currentAccount).removeObserver(EventManager.ON_UPLOAD_PROGRESS, this);
EventManager.getInstance(currentAccount).removeObserver(EventManager.ON_UPLOAD_COMPRESS, this);
}
if (attachment != null) {
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPRESS, this);
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPLETED, this);
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_FILE_DOWNLOAD_COMPLETED, this);
}
// TODO: 12/29/20 MESSAGE_REFACTOR
mHolder.getItemContainer().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OnClickRow(mHolder, view);
}
});
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OnClickRow(mHolder, view);
}
});
if (holder instanceof CardToCardItem.ViewHolder) {
CardToCardItem.ViewHolder cardToCardHolder = (CardToCardItem.ViewHolder) holder;
cardToCardHolder.getRootView().setMinWidth(G.maxChatBox - i_Dp(R.dimen.dp100));
cardToCardHolder.getInnerLayout().setMinimumWidth(G.maxChatBox - i_Dp(R.dimen.dp100));
if (messageObject.forwardedMessage == null && messageObject.additionalData != null && messageObject.additionalType == AdditionalType.CARD_TO_CARD_MESSAGE) {
CardToCardValue value = new CardToCardValue();
try {
JSONArray rootJsonArray = new JSONArray(messageObject.additionalData);
for (int i = 0; i < rootJsonArray.length(); i++) {
JSONArray valuJsonArray = rootJsonArray.getJSONArray(i);
for (int j = 0; j < valuJsonArray.length(); j++) {
JSONObject rootJsonObject = new JSONObject(valuJsonArray.getJSONObject(i).toString());
JSONObject valueObject = rootJsonObject.getJSONObject("value");
String cardNumber = valueObject.getString("cardNumber");
int amount = valueObject.getInt("amount");
long userId = valueObject.getLong("userId");
value.setAmount(amount);
value.setCardNumber(cardNumber);
value.setUserId(userId);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
cardToCardHolder.setValue(value);
}
cardToCardHolder.setOnCardToCard(cardToCard -> {
CardToCardHelper.NewCallCardToCard(G.currentActivity, cardToCard.getUserId(), cardToCard.getAmount(), cardToCard.getCardNumber());
});
}
if (holder instanceof ChatItemWithTextHolder) {
ChatItemWithTextHolder withTextHolder = (ChatItemWithTextHolder) holder;
// withTextHolder.messageView.setHasEmoji(structMessage.hasEmojiInText());
int maxsize = 0;
withTextHolder.removeButtonLayout();
if ((type == ProtoGlobal.Room.Type.CHANNEL) || (type == ProtoGlobal.Room.Type.CHAT) && messageObject.forwardedMessage != null) {
maxsize = G.maxChatBox - 16;
}
if (maxsize > 0)
withTextHolder.messageView.setMaxWidth(maxsize);
if (messageObject.hasLink) {
try {
BetterLinkMovementMethod.linkify(Linkify.ALL, withTextHolder.messageView).setOnLinkClickListener((tv, url) -> {
return FragmentChat.isInSelectionMode;
}).setOnLinkLongClickListener((tv, url) -> {
if (!FragmentChat.isInSelectionMode) {
if (HelperUrl.isTextLink(url)) {
G.isLinkClicked = true;
messageClickListener.onOpenLinkDialog(url);
}
}
return true;
});
} catch (AndroidRuntimeException runtimeException) {
/**
*this try-catch added to fixing bug following bug:
* this bug happens because the "Android System WebView" started being
* installed as its own application from Android 5.0 and greater and this
* code happens to be running while "Android System WebView" is being updated.
* While its being updated the package doesn't exist so it causes this exception
*/
Toast.makeText(context, R.string.please_try_again, Toast.LENGTH_LONG).show();
}
} else {
// remove BetterLinkMovementMethod
}
try {
if (messageObject.forwardedMessage == null && messageObject.additionalData != null && messageObject.additionalType == AdditionalType.UNDER_MESSAGE_BUTTON) {
HashMap<Integer, JSONArray> buttonList = MakeButtons.parseData(messageObject.additionalData);
int rowSize = buttonList.size();
for (int i = 0; i < rowSize; i++) {
int columSize = buttonList.get(i).length();
LinearLayout childLayout = MakeButtons.createLayout(((ChatItemWithTextHolder) holder).getContext());
for (int j = 0; j < columSize; j++) {
ButtonEntity buttonEntity = new Gson().fromJson(buttonList.get(i).get(j).toString(), ButtonEntity.class);
buttonEntity.setJsonObject(buttonList.get(i).get(j).toString());
childLayout = MakeButtons.addButtons(theme, buttonEntity, buttonList.get(i).length(), 1f, childLayout, (view, btnEntity) -> {
if (FragmentChat.isInSelectionMode) {
holder.itemView.performLongClick();
return;
}
mAdapter.onBotButtonClicked(() -> onBotBtnClick(view, btnEntity));
});
}
withTextHolder.addButtonLayout(childLayout);
}
}
} catch (Exception e) {
e.printStackTrace();
}
((LinearLayout.LayoutParams) ((LinearLayout) withTextHolder.messageView.getParent()).getLayoutParams()).gravity = AndroidUtils.isTextRtl(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.message : messageObject.message) ? Gravity.RIGHT : Gravity.LEFT;
}
/**
* for return message that start showing to view
*/
messageClickListener.onItemShowingMessageId(messageObject);
if (isSelected() || messageObject.isSelected) {
((FrameLayout) holder.itemView).setForeground(new ColorDrawable(G.context.getResources().getColor(R.color.colorChatMessageSelectableItemBg)));
} else {
((FrameLayout) holder.itemView).setForeground(new ColorDrawable(Color.TRANSPARENT));
}
/**
* only will be called when message layout is directional-base (e.g. single chat)
*/
if (directionalBased) {
if (!messageObject.isSenderMe() || type == ProtoGlobal.Room.Type.CHANNEL) {
updateLayoutForReceive(holder);
} else if (messageObject.isSenderMe()) {
updateLayoutForSend(holder);
}
}
if (!messageObject.isTimeOrLogMessage()) {
/**
* check failed state ,because if is failed we want show to user even is in channel
*/
if (mAdapter.getRealmRoom() != null && mAdapter.getRealmRoom().isValid() && mAdapter.getRealmRoom().getType() == ProtoGlobal.Room.Type.CHANNEL && ProtoGlobal.RoomMessageStatus.FAILED != ProtoGlobal.RoomMessageStatus.valueOf(messageObject.status)) {
mHolder.getMessageStatusTv().setVisibility(View.GONE);
} else {
mHolder.getMessageStatusTv().setVisibility(View.VISIBLE);
AppUtils.rightMessageStatus(mHolder.getMessageStatusTv(), ProtoGlobal.RoomMessageStatus.forNumber(messageObject.status), ProtoGlobal.RoomMessageType.forNumber(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType), messageObject.isSenderMe());
}
}
if (// TODO: 12/29/20 MESSAGE_REFACTOR
messageObject.edited)
if (messageObject.channelExtra != null && messageObject.channelExtra.getSignature() != null && messageObject.forwardedMessage.channelExtra.getSignature().length() > 0)
mHolder.getSignatureTv().setText(mHolder.getResources().getString(R.string.edited) + " " + messageObject.forwardedMessage.channelExtra.getSignature());
else {
mHolder.getSignatureTv().setText(mHolder.getResources().getString(R.string.edited));
}
else
mHolder.getSignatureTv().setText("");
/**
* display user avatar only if chat type is GROUP
*/
View messageSenderAvatar = mHolder.getItemContainer().findViewById(R.id.messageSenderAvatar);
if (messageSenderAvatar != null) {
messageSenderAvatar.setVisibility(View.GONE);
}
replyMessageIfNeeded(holder);
forwardMessageIfNeeded(holder);
View messageSenderName = mHolder.getContentBloke().findViewById(R.id.messageSenderName);
if (messageSenderName != null) {
messageSenderName.setVisibility(View.GONE);
}
if (type == ProtoGlobal.Room.Type.GROUP) {
if (!messageObject.isSenderMe()) {
addSenderNameToGroupIfNeed(mHolder);
if (messageSenderAvatar == null) {
messageSenderAvatar = ViewMaker.makeCircleImageView();
mHolder.getItemContainer().addView(messageSenderAvatar, 0);
}
messageSenderAvatar.setVisibility(View.VISIBLE);
messageSenderAvatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (FragmentChat.isInSelectionMode) {
holder.itemView.performLongClick();
return;
}
messageClickListener.onSenderAvatarClick(v, messageObject, holder.getAdapterPosition());
}
});
messageSenderAvatar.setOnLongClickListener(getLongClickPerform(holder));
final ImageView copyMessageSenderAvatar = (ImageView) messageSenderAvatar;
mAdapter.avatarHandler.getAvatar(new ParamWithAvatarType(copyMessageSenderAvatar, messageObject.userId).avatarType(AvatarHandler.AvatarType.USER));
}
} else {
FrameLayout forwardContainer = mHolder.getItemContainer().findViewById(R.id.messageForwardContainer);
ContextThemeWrapper wrapper = new ContextThemeWrapper(holder.itemView.getContext(), Theme.getInstance().getTheme(holder.itemView.getContext()));
if (forwardContainer == null) {
forwardContainer = new FrameLayout(holder.itemView.getContext());
forwardContainer.setId(R.id.messageForwardContainer);
if (mAdapter.getRealmRoom() != null && mAdapter.getRealmRoom().getChatRoom() != null && mAdapter.getRealmRoom().getChatRoom().getPeerId() == AccountManager.getInstance().getCurrentUser().getId()) {
mHolder.getItemContainer().addView(forwardContainer, 0, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.MATCH_PARENT, Gravity.BOTTOM));
} else {
mHolder.getItemContainer().addView(forwardContainer, 1, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.MATCH_PARENT, Gravity.BOTTOM));
}
forwardContainer.addView(mHolder.getChannelForwardIv(), LayoutCreator.createFrame(26, 26, Gravity.BOTTOM, 4, 4, 8, 4));
forwardContainer.setVisibility(View.GONE);
}
if (type == ProtoGlobal.Room.Type.CHANNEL) {
mHolder.getChannelForwardIv().setImageDrawable(VectorDrawableCompat.create(holder.itemView.getContext().getResources(), R.drawable.ic_channel_forward_light, wrapper.getTheme()));
forwardContainer.setVisibility(View.VISIBLE);
mHolder.getChannelForwardIv().setOnClickListener(v -> {
if (isAllowToForward(messageObject))
messageClickListener.onForwardClick(messageObject);
});
}
if (type == ProtoGlobal.Room.Type.CHAT && mAdapter.getRealmRoom().getChatRoom() != null && mAdapter.getRealmRoom().getChatRoom().getPeerId() == AccountManager.getInstance().getCurrentUser().getId() && !messageObject.isGiftSticker()) {
mHolder.getChannelForwardIv().setImageDrawable(VectorDrawableCompat.create(holder.itemView.getContext().getResources(), R.drawable.ic_cloud_forward, wrapper.getTheme()));
forwardContainer.setVisibility(View.VISIBLE);
mHolder.getChannelForwardIv().setOnClickListener(v -> {
if (isAllowToForward(messageObject))
messageClickListener.onForwardFromCloudClick(messageObject);
});
}
}
/**
* set message time
*/
String time = HelperCalander.getClocktime(messageObject.createTime, false);
if (HelperCalander.isPersianUnicode) {
mHolder.getMessageTimeTv().setText(HelperCalander.convertToUnicodeFarsiNumber(time));
} else {
mHolder.getMessageTimeTv().setText(time);
}
prepareAttachmentIfNeeded(holder, messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType);
/**
* show vote layout for channel otherwise hide layout also get message state for channel
*/
mHolder.getVoteContainer().setVisibility(View.GONE);
mHolder.getViewContainer().setVisibility(View.GONE);
if (!(holder instanceof StickerItem.ViewHolder)) {
if ((type == ProtoGlobal.Room.Type.CHANNEL)) {
showSeenContainer(holder);
}
}
// TODO: 12/29/20 MESSAGE_REFACTOR
if (messageObject.channelExtra != null && messageObject.channelExtra.getSignature() != null && messageObject.channelExtra.getSignature().length() > 0) {
mHolder.getContentBloke().setMinimumWidth(LayoutCreator.dp(200));
} else if (messageObject.edited) {
mHolder.getContentBloke().setMinimumWidth(LayoutCreator.dp(100));
}
}
use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method receivedEvent.
@Override
public void receivedEvent(int id, int account, Object... args) {
if (id == EventManager.ON_UPLOAD_PROGRESS) {
G.runOnUiThread(() -> {
String messageKey = (String) args[0];
String messageId = String.valueOf(messageObject.id);
long fileSize = 0;
if (args.length == 3) {
fileSize = (long) args[2];
} else {
fileSize = attachment.size;
}
if (messageKey.equals(messageId)) {
int progress = (int) args[1];
String progressString = String.valueOf(progress);
String attachmentSizeString = AndroidUtils.humanReadableByteCount(fileSize, true);
if (G.selectedLanguage.equals("fa")) {
progressString = HelperCalander.convertToUnicodeFarsiNumber(progressString);
attachmentSizeString = HelperCalander.convertToUnicodeFarsiNumber(attachmentSizeString);
}
if (holder instanceof FileItem.ViewHolder || holder instanceof VideoWithTextItem.ViewHolder) {
TextView progressTextView = ((IProgress) holder).getProgressTextView();
progressTextView.setText(String.format(Locale.US, "%s%% — %s", progressString, attachmentSizeString));
} else if (holder instanceof AudioItem.ViewHolder) {
AudioItem.ViewHolder audioHolder = (AudioItem.ViewHolder) holder;
audioHolder.getSongTimeTv().setText(String.format(Locale.US, "%s%% — %s", progressString, attachmentSizeString));
}
MessageProgress progressView = ((IProgress) holder).getProgress();
if (progressView.getTag() != null && progressView.getTag().equals(messageObject.id) && messageObject.status != MessageObject.STATUS_FAILED) {
if (progress >= 1 && progress != 100) {
progressView.withProgress(progress);
}
}
}
});
} else if (id == EventManager.ON_UPLOAD_COMPRESS) {
G.runOnUiThread(() -> {
String messageKey = (String) args[0];
String messageId = String.valueOf(messageObject.id);
if (messageKey.equals(messageId) && holder instanceof VideoWithTextItem.ViewHolder) {
VideoWithTextItem.ViewHolder videoHolder = (VideoWithTextItem.ViewHolder) holder;
int progress = (int) args[1];
if (progress <= 99) {
String progressString = String.valueOf(progress);
if (G.selectedLanguage.equals("fa")) {
progressString = HelperCalander.convertToUnicodeFarsiNumber(progressString);
}
videoHolder.duration.setText(String.format(G.context.getResources().getString(R.string.video_duration), progressString + "%" + G.context.getResources().getString(R.string.compressing) + "—" + AndroidUtils.humanReadableByteCount(attachment.size, true), AndroidUtils.formatDuration((int) (attachment.duration * 1000L))));
} else {
long fileSize;
if (args.length == 3) {
fileSize = (long) args[2];
} else {
fileSize = attachment.size;
}
videoHolder.duration.setText(String.format(G.context.getResources().getString(R.string.video_duration), AndroidUtils.humanReadableByteCount(fileSize, true) + " ", AndroidUtils.formatDuration((int) (attachment.duration * 1000L)) + G.context.getResources().getString(R.string.Uploading)));
}
}
});
} else if (id == EventManager.ON_UPLOAD_COMPLETED) {
G.runOnUiThread(() -> {
long messageId = (long) args[1];
if (messageId == messageObject.id) {
ProtoGlobal.RoomMessageType messageType = (ProtoGlobal.RoomMessageType) args[0];
if (attachment == null || args[2] == null || args[3] == null) {
return;
}
attachment.token = (String) args[3];
onProgressFinish(holder, attachment, messageType.getNumber());
loadImageOrThumbnail(messageType);
}
});
} else if (id == EventManager.ON_FILE_DOWNLOAD_COMPLETED) {
G.runOnUiThread(() -> {
MessageObject downloadedMessage = (MessageObject) args[0];
if (downloadedMessage.id == messageObject.id) {
attachment.filePath = downloadedMessage.attachment.filePath;
attachment.token = downloadedMessage.attachment.token;
ProtoGlobal.RoomMessageType messageType = ProtoGlobal.RoomMessageType.forNumber(downloadedMessage.messageType);
onProgressFinish(holder, downloadedMessage.attachment, messageType.getNumber());
loadImageOrThumbnail(messageType);
}
});
}
}
use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method onBotBtnClick.
public void onBotBtnClick(View v, ButtonEntity buttonEntity) {
DbManager.getInstance().doRealmTask(realm -> {
try {
if (v.getId() == ButtonActionType.USERNAME_LINK) {
// TODO: fixed this and do not use G.currentActivity
HelperUrl.checkUsernameAndGoToRoomWithMessageId(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(1), HelperUrl.ChatEntry.chat, 0, 0);
} else if (v.getId() == ButtonActionType.BOT_ACTION) {
long messageId = System.currentTimeMillis();
RealmRoomMessage roomMessage = new RealmRoomMessage();
roomMessage.setMessageId(messageId);
roomMessage.setMessageType(ProtoGlobal.RoomMessageType.TEXT);
roomMessage.setRoomId(messageObject.roomId);
roomMessage.setMessage(((ArrayList<String>) v.getTag()).get(1));
roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
roomMessage.setUserId(AccountManager.getInstance().getCurrentUser().getId());
roomMessage.setCreateTime(TimeUtils.currentLocalTime());
if (((ArrayList<String>) v.getTag()).get(2) != null) {
RealmAdditional additional = new RealmAdditional();
additional.setId(AppUtils.makeRandomId());
additional.setAdditionalData(((ArrayList<String>) v.getTag()).get(2));
additional.setAdditionalType(3);
roomMessage.setRealmAdditional(additional);
}
new Thread(() -> {
DbManager.getInstance().doRealmTransaction(realm12 -> {
realm12.copyToRealmOrUpdate(roomMessage);
});
}).start();
MessageObject botMessage = MessageObject.create(roomMessage);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(type, messageObject.roomId, botMessage);
messageClickListener.sendFromBot(botMessage);
} else if (v.getId() == ButtonActionType.JOIN_LINK) {
// TODO: fixed this and do not use G.currentActivity
HelperUrl.checkAndJoinToRoom(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(14));
} else if (v.getId() == ButtonActionType.WEB_LINK) {
HelperUrl.openBrowser(((ArrayList<String>) v.getTag()).get(0));
} else if (v.getId() == ButtonActionType.WEBVIEW_LINK) {
messageClickListener.sendFromBot(((ArrayList<String>) v.getTag()).get(0));
} else if (v.getId() == ButtonActionType.REQUEST_PHONE) {
try {
new MaterialDialog.Builder(G.currentActivity).title(R.string.access_phone_number).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Long identity = System.currentTimeMillis();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmUserInfo realmUserInfo = RealmUserInfo.getRealmUserInfo(realm);
RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(messageObject.roomId, identity, realmUserInfo.getUserInfo().getPhoneNumber(), realmUserInfo.getUserInfo().getPhoneNumber(), 0, realm, ProtoGlobal.RoomMessageType.TEXT);
MessageObject botMessage = MessageObject.create(realmRoomMessage);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(type, messageObject.roomId, botMessage);
messageClickListener.sendFromBot(botMessage);
}
});
}
}).show();
} catch (Exception e) {
}
} else if (v.getId() == ButtonActionType.REQUEST_LOCATION) {
try {
new MaterialDialog.Builder(G.currentActivity).title(R.string.access_location).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (G.locationListener != null) {
isLocationFromBot = true;
G.locationListener.requestLocation();
}
}
}).show();
} catch (Exception e) {
}
} else if (v.getId() == ButtonActionType.PAY_DIRECT) {
JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
RealmRoom room = realm.where(RealmRoom.class).equalTo("id", messageObject.roomId).findFirst();
new HelperFragment(G.currentActivity.getSupportFragmentManager()).loadPayment(room.getTitle(), jsonObject.getString("token"), null);
} else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.CARD_TO_CARD.getNumber()) {
JSONObject rootJsonObject = new JSONObject(buttonEntity.getJsonObject());
JSONObject valueObject = rootJsonObject.getJSONObject("value");
String cardNumber = valueObject.getString("cardNumber");
int amount = valueObject.getInt("amount");
long userId = valueObject.getLong("userId");
CardToCardHelper.NewCallCardToCard(G.currentActivity, userId, amount, cardNumber);
} else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.BILL_MENU.getNumber()) {
try {
JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills, jsonObject)).setReplace(false).load();
} catch (JSONException e) {
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills)).setReplace(false).load();
}
} else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.TRAFFIC_BILL_MENU.getNumber()) {
try {
JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime, jsonObject)).setReplace(false).load();
} catch (JSONException e) {
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime)).setReplace(false).load();
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(G.context, "دستور با خطا مواجه شد", Toast.LENGTH_LONG).show();
}
});
/**
* The data was sent via the button via the view tag. Right now I only do this for the card due to lack of time with the new object
*/
}
Aggregations