use of org.telegram.ui.GroupStickersActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivityEnterView method createEmojiView.
private void createEmojiView() {
if (emojiView != null) {
return;
}
emojiView = new EmojiView(allowStickers, allowGifs, getContext(), true, info, sizeNotifierLayout, resourcesProvider) {
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
if (panelAnimation != null && animatingContentType == 0) {
delegate.bottomPanelTranslationYChanged(translationY);
}
}
};
emojiView.setVisibility(GONE);
emojiView.setShowing(false);
emojiView.setDelegate(new EmojiView.EmojiViewDelegate() {
@Override
public boolean onBackspace() {
if (messageEditText.length() == 0) {
return false;
}
messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
return true;
}
@Override
public void onEmojiSelected(String symbol) {
int i = messageEditText.getSelectionEnd();
if (i < 0) {
i = 0;
}
try {
innerTextChange = 2;
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
messageEditText.setText(messageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messageEditText.setSelection(j, j);
} catch (Exception e) {
FileLog.e(e);
} finally {
innerTextChange = 0;
}
}
@Override
public void onStickerSelected(View view, TLRPC.Document sticker, String query, Object parent, MessageObject.SendAnimationData sendAnimationData, boolean notify, int scheduleDate) {
if (trendingStickersAlert != null) {
trendingStickersAlert.dismiss();
trendingStickersAlert = null;
}
if (slowModeTimer > 0 && !isInScheduleMode()) {
if (delegate != null) {
delegate.onUpdateSlowModeButton(view != null ? view : slowModeButton, true, slowModeButton.getText());
}
return;
}
if (stickersExpanded) {
if (searchingType != 0) {
setSearchingTypeInternal(0, true);
emojiView.closeSearch(true, MessageObject.getStickerSetId(sticker));
emojiView.hideSearchKeyboard();
}
setStickersExpanded(false, true, false);
}
ChatActivityEnterView.this.onStickerSelected(sticker, query, parent, sendAnimationData, false, notify, scheduleDate);
if (DialogObject.isEncryptedDialog(dialog_id) && MessageObject.isGifDocument(sticker)) {
accountInstance.getMessagesController().saveGif(parent, sticker);
}
}
@Override
public void onStickersSettingsClick() {
if (parentFragment != null) {
parentFragment.presentFragment(new StickersActivity(MediaDataController.TYPE_IMAGE));
}
}
@Override
public void onGifSelected(View view, Object gif, String query, Object parent, boolean notify, int scheduleDate) {
if (isInScheduleMode() && scheduleDate == 0) {
AlertsCreator.createScheduleDatePickerDialog(parentActivity, parentFragment.getDialogId(), (n, s) -> onGifSelected(view, gif, query, parent, n, s), resourcesProvider);
} else {
if (slowModeTimer > 0 && !isInScheduleMode()) {
if (delegate != null) {
delegate.onUpdateSlowModeButton(view != null ? view : slowModeButton, true, slowModeButton.getText());
}
return;
}
if (stickersExpanded) {
if (searchingType != 0) {
emojiView.hideSearchKeyboard();
}
setStickersExpanded(false, true, false);
}
if (gif instanceof TLRPC.Document) {
TLRPC.Document document = (TLRPC.Document) gif;
SendMessagesHelper.getInstance(currentAccount).sendSticker(document, query, dialog_id, replyingMessageObject, getThreadMessage(), parent, null, notify, scheduleDate);
MediaDataController.getInstance(currentAccount).addRecentGif(document, (int) (System.currentTimeMillis() / 1000));
if (DialogObject.isEncryptedDialog(dialog_id)) {
accountInstance.getMessagesController().saveGif(parent, document);
}
} else if (gif instanceof TLRPC.BotInlineResult) {
TLRPC.BotInlineResult result = (TLRPC.BotInlineResult) gif;
if (result.document != null) {
MediaDataController.getInstance(currentAccount).addRecentGif(result.document, (int) (System.currentTimeMillis() / 1000));
if (DialogObject.isEncryptedDialog(dialog_id)) {
accountInstance.getMessagesController().saveGif(parent, result.document);
}
}
TLRPC.User bot = (TLRPC.User) parent;
HashMap<String, String> params = new HashMap<>();
params.put("id", result.id);
params.put("query_id", "" + result.query_id);
params.put("force_gif", "1");
SendMessagesHelper.prepareSendingBotContextResult(accountInstance, result, params, dialog_id, replyingMessageObject, getThreadMessage(), notify, scheduleDate);
if (searchingType != 0) {
setSearchingTypeInternal(0, true);
emojiView.closeSearch(true);
emojiView.hideSearchKeyboard();
}
}
if (delegate != null) {
delegate.onMessageSend(null, notify, scheduleDate);
}
}
}
@Override
public void onTabOpened(int type) {
delegate.onStickersTab(type == 3);
post(updateExpandabilityRunnable);
}
@Override
public void onClearEmojiRecent() {
if (parentFragment == null || parentActivity == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity, resourcesProvider);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ClearRecentEmoji", R.string.ClearRecentEmoji));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> emojiView.clearRecentEmoji());
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
parentFragment.showDialog(builder.create());
}
@Override
public void onShowStickerSet(TLRPC.StickerSet stickerSet, TLRPC.InputStickerSet inputStickerSet) {
if (trendingStickersAlert != null && !trendingStickersAlert.isDismissed()) {
trendingStickersAlert.getLayout().showStickerSet(stickerSet, inputStickerSet);
return;
}
if (parentFragment == null || parentActivity == null) {
return;
}
if (stickerSet != null) {
inputStickerSet = new TLRPC.TL_inputStickerSetID();
inputStickerSet.access_hash = stickerSet.access_hash;
inputStickerSet.id = stickerSet.id;
}
parentFragment.showDialog(new StickersAlert(parentActivity, parentFragment, inputStickerSet, null, ChatActivityEnterView.this, resourcesProvider));
}
@Override
public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet) {
MediaDataController.getInstance(currentAccount).toggleStickerSet(parentActivity, stickerSet, 2, parentFragment, false, false);
}
@Override
public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
MediaDataController.getInstance(currentAccount).toggleStickerSet(parentActivity, stickerSet, 0, parentFragment, false, false);
}
@Override
public void onStickersGroupClick(long chatId) {
if (parentFragment != null) {
if (AndroidUtilities.isTablet()) {
hidePopup(false);
}
GroupStickersActivity fragment = new GroupStickersActivity(chatId);
fragment.setInfo(info);
parentFragment.presentFragment(fragment);
}
}
@Override
public void onSearchOpenClose(int type) {
setSearchingTypeInternal(type, true);
if (type != 0) {
setStickersExpanded(true, true, false);
}
if (emojiTabOpen && searchingType == 2) {
checkStickresExpandHeight();
}
}
@Override
public boolean isSearchOpened() {
return searchingType != 0;
}
@Override
public boolean isExpanded() {
return stickersExpanded;
}
@Override
public boolean canSchedule() {
return parentFragment != null && parentFragment.canScheduleMessage();
}
@Override
public boolean isInScheduleMode() {
return parentFragment != null && parentFragment.isInScheduleMode();
}
@Override
public long getDialogId() {
return dialog_id;
}
@Override
public int getThreadId() {
return getThreadMessageId();
}
@Override
public void showTrendingStickersAlert(TrendingStickersLayout layout) {
if (parentActivity != null && parentFragment != null) {
trendingStickersAlert = new TrendingStickersAlert(parentActivity, parentFragment, layout, resourcesProvider) {
@Override
public void dismiss() {
super.dismiss();
if (trendingStickersAlert == this) {
trendingStickersAlert = null;
}
if (delegate != null) {
delegate.onTrendingStickersShowed(false);
}
}
};
if (delegate != null) {
delegate.onTrendingStickersShowed(true);
}
trendingStickersAlert.show();
}
}
@Override
public void invalidateEnterView() {
invalidate();
}
@Override
public float getProgressToSearchOpened() {
return searchToOpenProgress;
}
});
emojiView.setDragListener(new EmojiView.DragListener() {
boolean wasExpanded;
int initialOffset;
@Override
public void onDragStart() {
if (!allowDragging()) {
return;
}
if (stickersExpansionAnim != null) {
stickersExpansionAnim.cancel();
}
stickersDragging = true;
wasExpanded = stickersExpanded;
stickersExpanded = true;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 1);
stickersExpandedHeight = sizeNotifierLayout.getHeight() - (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? AndroidUtilities.statusBarHeight : 0) - ActionBar.getCurrentActionBarHeight() - getHeight() + Theme.chat_composeShadowDrawable.getIntrinsicHeight();
if (searchingType == 2) {
stickersExpandedHeight = Math.min(stickersExpandedHeight, AndroidUtilities.dp(120) + (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight));
}
emojiView.getLayoutParams().height = stickersExpandedHeight;
emojiView.setLayerType(LAYER_TYPE_HARDWARE, null);
sizeNotifierLayout.requestLayout();
sizeNotifierLayout.setForeground(new ScrimDrawable());
initialOffset = (int) getTranslationY();
if (delegate != null) {
delegate.onStickersExpandedChange();
}
}
@Override
public void onDragEnd(float velocity) {
if (!allowDragging()) {
return;
}
stickersDragging = false;
if ((wasExpanded && velocity >= AndroidUtilities.dp(200)) || (!wasExpanded && velocity <= AndroidUtilities.dp(-200)) || (wasExpanded && stickersExpansionProgress <= 0.6f) || (!wasExpanded && stickersExpansionProgress >= 0.4f)) {
setStickersExpanded(!wasExpanded, true, true);
} else {
setStickersExpanded(wasExpanded, true, true);
}
}
@Override
public void onDragCancel() {
if (!stickersTabOpen) {
return;
}
stickersDragging = false;
setStickersExpanded(wasExpanded, true, false);
}
@Override
public void onDrag(int offset) {
if (!allowDragging()) {
return;
}
int origHeight = AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight;
offset += initialOffset;
offset = Math.max(Math.min(offset, 0), -(stickersExpandedHeight - origHeight));
emojiView.setTranslationY(offset);
setTranslationY(offset);
stickersExpansionProgress = (float) offset / (-(stickersExpandedHeight - origHeight));
sizeNotifierLayout.invalidate();
}
private boolean allowDragging() {
return stickersTabOpen && !(!stickersExpanded && messageEditText.length() > 0) && emojiView.areThereAnyStickers() && !waitingForKeyboardOpen;
}
});
sizeNotifierLayout.addView(emojiView, sizeNotifierLayout.getChildCount() - 5);
checkChannelRights();
}
Aggregations