use of org.telegram.messenger.AccountInstance in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method showBlockReportSpamReplyAlert.
public static void showBlockReportSpamReplyAlert(ChatActivity fragment, MessageObject messageObject, long peerId, Theme.ResourcesProvider resourcesProvider, Runnable hideDim) {
if (fragment == null || fragment.getParentActivity() == null || messageObject == null) {
return;
}
AccountInstance accountInstance = fragment.getAccountInstance();
TLRPC.User user = peerId > 0 ? accountInstance.getMessagesController().getUser(peerId) : null;
TLRPC.Chat chat = peerId < 0 ? accountInstance.getMessagesController().getChat(-peerId) : null;
if (user == null && chat == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity(), resourcesProvider);
builder.setDimEnabled(hideDim == null);
builder.setOnPreDismissListener(di -> {
if (hideDim != null) {
hideDim.run();
}
});
builder.setTitle(LocaleController.getString("BlockUser", R.string.BlockUser));
if (user != null) {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserReplyAlert", R.string.BlockUserReplyAlert, UserObject.getFirstName(user))));
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserReplyAlert", R.string.BlockUserReplyAlert, chat.title)));
}
CheckBoxCell[] cells = new CheckBoxCell[1];
LinearLayout linearLayout = new LinearLayout(fragment.getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
cells[0] = new CheckBoxCell(fragment.getParentActivity(), 1, resourcesProvider);
cells[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
cells[0].setTag(0);
cells[0].setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", true, false);
cells[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
linearLayout.addView(cells[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
cells[0].setOnClickListener(v -> {
Integer num = (Integer) v.getTag();
cells[num].setChecked(!cells[num].isChecked(), true);
});
builder.setCustomViewOffset(12);
builder.setView(linearLayout);
builder.setPositiveButton(LocaleController.getString("BlockAndDeleteReplies", R.string.BlockAndDeleteReplies), (dialogInterface, i) -> {
if (user != null) {
accountInstance.getMessagesStorage().deleteUserChatHistory(fragment.getDialogId(), user.id);
} else {
accountInstance.getMessagesStorage().deleteUserChatHistory(fragment.getDialogId(), -chat.id);
}
TLRPC.TL_contacts_blockFromReplies request = new TLRPC.TL_contacts_blockFromReplies();
request.msg_id = messageObject.getId();
request.delete_message = true;
request.delete_history = true;
if (cells[0].isChecked()) {
request.report_spam = true;
if (fragment.getParentActivity() != null) {
if (fragment instanceof ChatActivity) {
fragment.getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
} else if (fragment != null) {
BulletinFactory.of(fragment).createReportSent(resourcesProvider).show();
} else {
Toast.makeText(fragment.getParentActivity(), LocaleController.getString("ReportChatSent", R.string.ReportChatSent), Toast.LENGTH_SHORT).show();
}
}
}
accountInstance.getConnectionsManager().sendRequest(request, (response, error) -> {
if (response instanceof TLRPC.Updates) {
accountInstance.getMessagesController().processUpdates((TLRPC.Updates) response, false);
}
});
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
fragment.showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.messenger.AccountInstance in project Telegram-FOSS by Telegram-FOSS-Team.
the class ConnectionsManager method onLogout.
public static void onLogout(final int currentAccount) {
AndroidUtilities.runOnUIThread(() -> {
AccountInstance accountInstance = AccountInstance.getInstance(currentAccount);
if (accountInstance.getUserConfig().getClientUserId() != 0) {
accountInstance.getUserConfig().clearConfig();
accountInstance.getMessagesController().performLogout(0);
}
});
}
use of org.telegram.messenger.AccountInstance in project Telegram-FOSS by Telegram-FOSS-Team.
the class VoIPHelper method showRateAlert.
public static void showRateAlert(final Context context, final Runnable onDismiss, boolean isVideo, final long callID, final long accessHash, final int account, final boolean userInitiative) {
final File log = getLogFile(callID);
final int[] page = { 0 };
LinearLayout alertView = new LinearLayout(context);
alertView.setOrientation(LinearLayout.VERTICAL);
int pad = AndroidUtilities.dp(16);
alertView.setPadding(pad, pad, pad, 0);
TextView text = new TextView(context);
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
text.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
text.setGravity(Gravity.CENTER);
text.setText(LocaleController.getString("VoipRateCallAlert", R.string.VoipRateCallAlert));
alertView.addView(text);
final BetterRatingView bar = new BetterRatingView(context);
alertView.addView(bar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 0));
final LinearLayout problemsWrap = new LinearLayout(context);
problemsWrap.setOrientation(LinearLayout.VERTICAL);
View.OnClickListener problemCheckboxClickListener = v -> {
CheckBoxCell check = (CheckBoxCell) v;
check.setChecked(!check.isChecked(), true);
};
final String[] problems = { isVideo ? "distorted_video" : null, isVideo ? "pixelated_video" : null, "echo", "noise", "interruptions", "distorted_speech", "silent_local", "silent_remote", "dropped" };
for (int i = 0; i < problems.length; i++) {
if (problems[i] == null) {
continue;
}
CheckBoxCell check = new CheckBoxCell(context, 1);
check.setClipToPadding(false);
check.setTag(problems[i]);
String label = null;
switch(i) {
case 0:
label = LocaleController.getString("RateCallVideoDistorted", R.string.RateCallVideoDistorted);
break;
case 1:
label = LocaleController.getString("RateCallVideoPixelated", R.string.RateCallVideoPixelated);
break;
case 2:
label = LocaleController.getString("RateCallEcho", R.string.RateCallEcho);
break;
case 3:
label = LocaleController.getString("RateCallNoise", R.string.RateCallNoise);
break;
case 4:
label = LocaleController.getString("RateCallInterruptions", R.string.RateCallInterruptions);
break;
case 5:
label = LocaleController.getString("RateCallDistorted", R.string.RateCallDistorted);
break;
case 6:
label = LocaleController.getString("RateCallSilentLocal", R.string.RateCallSilentLocal);
break;
case 7:
label = LocaleController.getString("RateCallSilentRemote", R.string.RateCallSilentRemote);
break;
case 8:
label = LocaleController.getString("RateCallDropped", R.string.RateCallDropped);
break;
}
check.setText(label, null, false, false);
check.setOnClickListener(problemCheckboxClickListener);
check.setTag(problems[i]);
problemsWrap.addView(check);
}
alertView.addView(problemsWrap, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
problemsWrap.setVisibility(View.GONE);
final EditTextBoldCursor commentBox = new EditTextBoldCursor(context);
commentBox.setHint(LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
commentBox.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
commentBox.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
commentBox.setHintTextColor(Theme.getColor(Theme.key_dialogTextHint));
commentBox.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
commentBox.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4));
commentBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
commentBox.setVisibility(View.GONE);
alertView.addView(commentBox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 8, 8, 8, 0));
final boolean[] includeLogs = { true };
final CheckBoxCell checkbox = new CheckBoxCell(context, 1);
View.OnClickListener checkClickListener = v -> {
includeLogs[0] = !includeLogs[0];
checkbox.setChecked(includeLogs[0], true);
};
checkbox.setText(LocaleController.getString("CallReportIncludeLogs", R.string.CallReportIncludeLogs), null, true, false);
checkbox.setClipToPadding(false);
checkbox.setOnClickListener(checkClickListener);
alertView.addView(checkbox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
final TextView logsText = new TextView(context);
logsText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
logsText.setTextColor(Theme.getColor(Theme.key_dialogTextGray3));
logsText.setText(LocaleController.getString("CallReportLogsExplain", R.string.CallReportLogsExplain));
logsText.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
logsText.setOnClickListener(checkClickListener);
alertView.addView(logsText);
checkbox.setVisibility(View.GONE);
logsText.setVisibility(View.GONE);
if (!log.exists()) {
includeLogs[0] = false;
}
final AlertDialog alert = new AlertDialog.Builder(context).setTitle(LocaleController.getString("CallMessageReportProblem", R.string.CallMessageReportProblem)).setView(alertView).setPositiveButton(LocaleController.getString("Send", R.string.Send), (dialog, which) -> {
// SendMessagesHelper.getInstance(currentAccount).sendMessage(commentBox.getText().toString(), VOIP_SUPPORT_ID, null, null, true, null, null, null);
}).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null).setOnDismissListener(dialog -> {
if (onDismiss != null)
onDismiss.run();
}).create();
if (BuildVars.LOGS_ENABLED && log.exists()) {
alert.setNeutralButton("Send log", (dialog, which) -> {
Intent intent = new Intent(context, LaunchActivity.class);
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(log));
context.startActivity(intent);
});
}
alert.show();
alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
final View btn = alert.getButton(DialogInterface.BUTTON_POSITIVE);
btn.setEnabled(false);
bar.setOnRatingChangeListener(rating -> {
btn.setEnabled(rating > 0);
/*commentBox.setHint(rating<4 ? LocaleController.getString("CallReportHint", R.string.CallReportHint) : LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
commentBox.setVisibility(rating < 5 && rating > 0 ? View.VISIBLE : View.GONE);
if (commentBox.getVisibility() == View.GONE) {
((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(commentBox.getWindowToken(), 0);
}
*/
((TextView) btn).setText((rating < 4 ? LocaleController.getString("Next", R.string.Next) : LocaleController.getString("Send", R.string.Send)).toUpperCase());
});
btn.setOnClickListener(v -> {
int rating = bar.getRating();
if (rating >= 4 || page[0] == 1) {
final int currentAccount = UserConfig.selectedAccount;
final TLRPC.TL_phone_setCallRating req = new TLRPC.TL_phone_setCallRating();
req.rating = bar.getRating();
ArrayList<String> problemTags = new ArrayList<>();
for (int i = 0; i < problemsWrap.getChildCount(); i++) {
CheckBoxCell check = (CheckBoxCell) problemsWrap.getChildAt(i);
if (check.isChecked())
problemTags.add("#" + check.getTag());
}
if (req.rating < 5) {
req.comment = commentBox.getText().toString();
} else {
req.comment = "";
}
if (!problemTags.isEmpty() && !includeLogs[0]) {
req.comment += " " + TextUtils.join(" ", problemTags);
}
req.peer = new TLRPC.TL_inputPhoneCall();
req.peer.access_hash = accessHash;
req.peer.id = callID;
req.user_initiative = userInitiative;
ConnectionsManager.getInstance(account).sendRequest(req, (response, error) -> {
if (response instanceof TLRPC.TL_updates) {
TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
MessagesController.getInstance(currentAccount).processUpdates(updates, false);
}
if (includeLogs[0] && log.exists() && req.rating < 4) {
AccountInstance accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount);
SendMessagesHelper.prepareSendingDocument(accountInstance, log.getAbsolutePath(), log.getAbsolutePath(), null, TextUtils.join(" ", problemTags), "text/plain", VOIP_SUPPORT_ID, null, null, null, null, true, 0);
Toast.makeText(context, LocaleController.getString("CallReportSent", R.string.CallReportSent), Toast.LENGTH_LONG).show();
}
});
alert.dismiss();
} else {
page[0] = 1;
bar.setVisibility(View.GONE);
// text.setText(LocaleController.getString("CallReportHint", R.string.CallReportHint));
text.setVisibility(View.GONE);
alert.setTitle(LocaleController.getString("CallReportHint", R.string.CallReportHint));
commentBox.setVisibility(View.VISIBLE);
if (log.exists()) {
checkbox.setVisibility(View.VISIBLE);
logsText.setVisibility(View.VISIBLE);
}
problemsWrap.setVisibility(View.VISIBLE);
((TextView) btn).setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
}
});
}
use of org.telegram.messenger.AccountInstance in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method didSelectDialogs.
@Override
public void didSelectDialogs(DialogsActivity dialogsFragment, ArrayList<Long> dids, CharSequence message, boolean param) {
final int account = dialogsFragment != null ? dialogsFragment.getCurrentAccount() : currentAccount;
if (exportingChatUri != null) {
Uri uri = exportingChatUri;
ArrayList<Uri> documentsUris = documentsUrisArray != null ? new ArrayList<>(documentsUrisArray) : null;
final AlertDialog progressDialog = new AlertDialog(this, 3);
SendMessagesHelper.getInstance(account).prepareImportHistory(dids.get(0), exportingChatUri, documentsUrisArray, (result) -> {
if (result != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
if (!AndroidUtilities.isTablet()) {
NotificationCenter.getInstance(account).postNotificationName(NotificationCenter.closeChats);
}
if (DialogObject.isUserDialog(result)) {
args.putLong("user_id", result);
} else {
args.putLong("chat_id", -result);
}
ChatActivity fragment = new ChatActivity(args);
fragment.setOpenImport();
actionBarLayout.presentFragment(fragment, dialogsFragment != null || param, dialogsFragment == null, true, false);
} else {
documentsUrisArray = documentsUris;
if (documentsUrisArray == null) {
documentsUrisArray = new ArrayList<>();
}
documentsUrisArray.add(0, uri);
openDialogsToSend(true);
}
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
});
try {
progressDialog.showDelayed(300);
} catch (Exception ignore) {
}
} else {
boolean notify = dialogsFragment == null || dialogsFragment.notify;
final ChatActivity fragment;
if (dids.size() <= 1) {
final long did = dids.get(0);
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
if (!AndroidUtilities.isTablet()) {
NotificationCenter.getInstance(account).postNotificationName(NotificationCenter.closeChats);
}
if (DialogObject.isEncryptedDialog(did)) {
args.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else if (DialogObject.isUserDialog(did)) {
args.putLong("user_id", did);
} else {
args.putLong("chat_id", -did);
}
if (!MessagesController.getInstance(account).checkCanOpenChat(args, dialogsFragment)) {
return;
}
fragment = new ChatActivity(args);
} else {
fragment = null;
}
int attachesCount = 0;
if (contactsToSend != null) {
attachesCount += contactsToSend.size();
}
if (videoPath != null) {
attachesCount++;
}
if (photoPathsArray != null) {
attachesCount += photoPathsArray.size();
}
if (documentsPathsArray != null) {
attachesCount += documentsPathsArray.size();
}
if (documentsUrisArray != null) {
attachesCount += documentsUrisArray.size();
}
if (videoPath == null && photoPathsArray == null && documentsPathsArray == null && documentsUrisArray == null && sendingText != null) {
attachesCount++;
}
for (int i = 0; i < dids.size(); i++) {
final long did = dids.get(i);
if (AlertsCreator.checkSlowMode(this, currentAccount, did, attachesCount > 1)) {
return;
}
}
if (contactsToSend != null && contactsToSend.size() == 1 && !mainFragmentsStack.isEmpty()) {
PhonebookShareAlert alert = new PhonebookShareAlert(mainFragmentsStack.get(mainFragmentsStack.size() - 1), null, null, contactsToSendUri, null, null, null);
alert.setDelegate((user, notify2, scheduleDate) -> {
if (fragment != null) {
actionBarLayout.presentFragment(fragment, true, false, true, false);
}
for (int i = 0; i < dids.size(); i++) {
SendMessagesHelper.getInstance(account).sendMessage(user, dids.get(i), null, null, null, null, notify2, scheduleDate);
}
});
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(alert);
} else {
String captionToSend = null;
for (int i = 0; i < dids.size(); i++) {
final long did = dids.get(i);
AccountInstance accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount);
boolean photosEditorOpened = false;
if (fragment != null) {
boolean withoutAnimation = dialogsFragment == null || (videoPath != null || (photoPathsArray != null && photoPathsArray.size() > 0));
actionBarLayout.presentFragment(fragment, dialogsFragment != null, withoutAnimation, true, false);
if (videoPath != null) {
fragment.openVideoEditor(videoPath, sendingText);
sendingText = null;
} else if (photoPathsArray != null && photoPathsArray.size() > 0) {
photosEditorOpened = fragment.openPhotosEditor(photoPathsArray, message == null || message.length() == 0 ? sendingText : message);
if (photosEditorOpened) {
sendingText = null;
}
}
} else {
if (videoPath != null) {
if (sendingText != null && sendingText.length() <= 1024) {
captionToSend = sendingText;
sendingText = null;
}
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(videoPath);
SendMessagesHelper.prepareSendingDocuments(accountInstance, arrayList, arrayList, null, captionToSend, null, did, null, null, null, null, notify, 0);
}
}
if (photoPathsArray != null && !photosEditorOpened) {
if (sendingText != null && sendingText.length() <= 1024 && photoPathsArray.size() == 1) {
photoPathsArray.get(0).caption = sendingText;
sendingText = null;
}
SendMessagesHelper.prepareSendingMedia(accountInstance, photoPathsArray, did, null, null, null, false, false, null, notify, 0);
}
if (documentsPathsArray != null || documentsUrisArray != null) {
if (sendingText != null && sendingText.length() <= 1024 && ((documentsPathsArray != null ? documentsPathsArray.size() : 0) + (documentsUrisArray != null ? documentsUrisArray.size() : 0)) == 1) {
captionToSend = sendingText;
sendingText = null;
}
SendMessagesHelper.prepareSendingDocuments(accountInstance, documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, captionToSend, documentsMimeType, did, null, null, null, null, notify, 0);
}
if (sendingLocation != null) {
SendMessagesHelper.prepareSendingLocation(accountInstance, sendingLocation, did);
sendingText = null;
}
if (sendingText != null) {
SendMessagesHelper.prepareSendingText(accountInstance, sendingText, did, true, 0);
}
if (contactsToSend != null && !contactsToSend.isEmpty()) {
for (int a = 0; a < contactsToSend.size(); a++) {
TLRPC.User user = contactsToSend.get(a);
SendMessagesHelper.getInstance(account).sendMessage(user, did, null, null, null, null, notify, 0);
}
}
if (!TextUtils.isEmpty(message)) {
SendMessagesHelper.prepareSendingText(accountInstance, message.toString(), did, notify, 0);
}
}
}
if (dialogsFragment != null && fragment == null) {
dialogsFragment.finishFragment();
}
}
photoPathsArray = null;
videoPath = null;
sendingText = null;
sendingLocation = null;
documentsPathsArray = null;
documentsOriginalPathsArray = null;
contactsToSend = null;
contactsToSendUri = null;
exportingChatUri = null;
}
use of org.telegram.messenger.AccountInstance 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