use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class SecretChatHelper method decryptMessage.
protected ArrayList<TLRPC.Message> decryptMessage(TLRPC.EncryptedMessage message) {
TLRPC.EncryptedChat chat = getMessagesController().getEncryptedChatDB(message.chat_id, true);
if (chat == null || chat instanceof TLRPC.TL_encryptedChatDiscarded) {
return null;
}
try {
if (chat instanceof TLRPC.TL_encryptedChatWaiting) {
ArrayList<TLRPC.Update> updates = pendingSecretMessages.get(chat.id);
if (updates == null) {
updates = new ArrayList<>();
pendingSecretMessages.put(chat.id, updates);
}
TLRPC.TL_updateNewEncryptedMessage updateNewEncryptedMessage = new TLRPC.TL_updateNewEncryptedMessage();
updateNewEncryptedMessage.message = message;
updates.add(updateNewEncryptedMessage);
return null;
}
NativeByteBuffer is = new NativeByteBuffer(message.bytes.length);
is.writeBytes(message.bytes);
is.position(0);
long fingerprint = is.readInt64(false);
byte[] keyToDecrypt = null;
boolean new_key_used = false;
if (chat.key_fingerprint == fingerprint) {
keyToDecrypt = chat.auth_key;
} else if (chat.future_key_fingerprint != 0 && chat.future_key_fingerprint == fingerprint) {
keyToDecrypt = chat.future_auth_key;
new_key_used = true;
}
int mtprotoVersion = 2;
int decryptedWithVersion = 2;
if (keyToDecrypt != null) {
byte[] messageKey = is.readData(16, false);
boolean incoming = chat.admin_id == getUserConfig().getClientUserId();
boolean tryAnotherDecrypt = true;
if (decryptedWithVersion == 2 && chat.mtproto_seq != 0) {
tryAnotherDecrypt = false;
}
if (!decryptWithMtProtoVersion(is, keyToDecrypt, messageKey, mtprotoVersion, incoming, tryAnotherDecrypt)) {
if (mtprotoVersion == 2) {
decryptedWithVersion = 1;
if (!tryAnotherDecrypt || !decryptWithMtProtoVersion(is, keyToDecrypt, messageKey, 1, incoming, false)) {
return null;
}
} else {
decryptedWithVersion = 2;
if (!decryptWithMtProtoVersion(is, keyToDecrypt, messageKey, 2, incoming, true)) {
return null;
}
}
}
TLObject object = TLClassStore.Instance().TLdeserialize(is, is.readInt32(false), false);
is.reuse();
if (!new_key_used) {
chat.key_use_count_in++;
}
if (object instanceof TLRPC.TL_decryptedMessageLayer) {
TLRPC.TL_decryptedMessageLayer layer = (TLRPC.TL_decryptedMessageLayer) object;
if (chat.seq_in == 0 && chat.seq_out == 0) {
if (chat.admin_id == getUserConfig().getClientUserId()) {
chat.seq_out = 1;
chat.seq_in = -2;
} else {
chat.seq_in = -1;
}
}
if (layer.random_bytes.length < 15) {
if (BuildVars.LOGS_ENABLED) {
FileLog.e("got random bytes less than needed");
}
return null;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("current chat in_seq = " + chat.seq_in + " out_seq = " + chat.seq_out);
FileLog.d("got message with in_seq = " + layer.in_seq_no + " out_seq = " + layer.out_seq_no);
}
if (layer.out_seq_no <= chat.seq_in) {
return null;
}
if (decryptedWithVersion == 1 && chat.mtproto_seq != 0 && layer.out_seq_no >= chat.mtproto_seq) {
return null;
}
if (chat.seq_in != layer.out_seq_no - 2) {
if (BuildVars.LOGS_ENABLED) {
FileLog.e("got hole");
}
sendResendMessage(chat, chat.seq_in + 2, layer.out_seq_no - 2, null);
ArrayList<TL_decryptedMessageHolder> arr = secretHolesQueue.get(chat.id);
if (arr == null) {
arr = new ArrayList<>();
secretHolesQueue.put(chat.id, arr);
}
if (arr.size() >= 4) {
secretHolesQueue.remove(chat.id);
TLRPC.TL_encryptedChatDiscarded newChat = new TLRPC.TL_encryptedChatDiscarded();
newChat.id = chat.id;
newChat.user_id = chat.user_id;
newChat.auth_key = chat.auth_key;
newChat.key_create_date = chat.key_create_date;
newChat.key_use_count_in = chat.key_use_count_in;
newChat.key_use_count_out = chat.key_use_count_out;
newChat.seq_in = chat.seq_in;
newChat.seq_out = chat.seq_out;
AndroidUtilities.runOnUIThread(() -> {
getMessagesController().putEncryptedChat(newChat, false);
getMessagesStorage().updateEncryptedChat(newChat);
getNotificationCenter().postNotificationName(NotificationCenter.encryptedChatUpdated, newChat);
});
declineSecretChat(chat.id, false);
return null;
}
TL_decryptedMessageHolder holder = new TL_decryptedMessageHolder();
holder.layer = layer;
holder.file = message.file;
holder.date = message.date;
holder.new_key_used = new_key_used;
holder.decryptedWithVersion = decryptedWithVersion;
arr.add(holder);
return null;
}
if (decryptedWithVersion == 2) {
chat.mtproto_seq = Math.min(chat.mtproto_seq, chat.seq_in);
}
applyPeerLayer(chat, layer.layer);
chat.seq_in = layer.out_seq_no;
chat.in_seq_no = layer.in_seq_no;
getMessagesStorage().updateEncryptedChatSeq(chat, true);
object = layer.message;
} else if (!(object instanceof TLRPC.TL_decryptedMessageService && ((TLRPC.TL_decryptedMessageService) object).action instanceof TLRPC.TL_decryptedMessageActionNotifyLayer)) {
return null;
}
ArrayList<TLRPC.Message> messages = new ArrayList<>();
TLRPC.Message decryptedMessage = processDecryptedObject(chat, message.file, message.date, object, new_key_used);
if (decryptedMessage != null) {
messages.add(decryptedMessage);
}
checkSecretHoles(chat, messages);
return messages;
} else {
is.reuse();
if (BuildVars.LOGS_ENABLED) {
FileLog.e(String.format("fingerprint mismatch %x", fingerprint));
}
}
} catch (Exception e) {
FileLog.e(e);
}
return null;
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class UndoView method showWithAction.
public void showWithAction(ArrayList<Long> dialogIds, int action, Object infoObject, Object infoObject2, Runnable actionRunnable, Runnable cancelRunnable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && currentAction == ACTION_MESSAGE_COPIED || currentAction == ACTION_USERNAME_COPIED || currentAction == ACTION_HASHTAG_COPIED || currentAction == ACTION_TEXT_COPIED || currentAction == ACTION_LINK_COPIED || currentAction == ACTION_PHONE_COPIED || currentAction == ACTION_EMAIL_COPIED || currentAction == ACTION_VOIP_LINK_COPIED) {
return;
}
if (currentActionRunnable != null) {
currentActionRunnable.run();
}
isShown = true;
currentActionRunnable = actionRunnable;
currentCancelRunnable = cancelRunnable;
currentDialogIds = dialogIds;
long did = dialogIds.get(0);
currentAction = action;
timeLeft = 5000;
currentInfoObject = infoObject;
lastUpdateTime = SystemClock.elapsedRealtime();
undoTextView.setText(LocaleController.getString("Undo", R.string.Undo).toUpperCase());
undoImageView.setVisibility(VISIBLE);
leftImageView.setPadding(0, 0, 0, 0);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
avatarImageView.setVisibility(GONE);
infoTextView.setGravity(Gravity.LEFT | Gravity.TOP);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) infoTextView.getLayoutParams();
layoutParams.height = LayoutHelper.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(13);
layoutParams.bottomMargin = 0;
leftImageView.setScaleType(ImageView.ScaleType.CENTER);
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) leftImageView.getLayoutParams();
layoutParams2.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
layoutParams2.topMargin = layoutParams2.bottomMargin = 0;
layoutParams2.leftMargin = AndroidUtilities.dp(3);
layoutParams2.width = AndroidUtilities.dp(54);
layoutParams2.height = LayoutHelper.WRAP_CONTENT;
infoTextView.setMinHeight(0);
boolean infoOnly = false;
boolean reversedPlay = false;
int reversedPlayEndFrame = 0;
if (actionRunnable == null && cancelRunnable == null) {
setOnClickListener(view -> hide(false, 1));
setOnTouchListener(null);
} else {
setOnClickListener(null);
setOnTouchListener((v, event) -> true);
}
infoTextView.setMovementMethod(null);
if (isTooltipAction()) {
CharSequence infoText;
String subInfoText;
int icon;
int size = 36;
boolean iconIsDrawable = false;
if (action == ACTION_REPORT_SENT) {
subinfoTextView.setSingleLine(false);
infoText = LocaleController.getString("ReportChatSent", R.string.ReportChatSent);
subInfoText = LocaleController.formatString("ReportSentInfo", R.string.ReportSentInfo);
icon = R.raw.ic_admin;
timeLeft = 4000;
} else if (action == ACTION_VOIP_INVITED) {
TLRPC.User user = (TLRPC.User) infoObject;
TLRPC.Chat chat = (TLRPC.Chat) infoObject2;
if (ChatObject.isChannelOrGiga(chat)) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipChannelInvitedUser", R.string.VoipChannelInvitedUser, UserObject.getFirstName(user)));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupInvitedUser", R.string.VoipGroupInvitedUser, UserObject.getFirstName(user)));
}
subInfoText = null;
icon = 0;
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
avatarDrawable.setInfo(user);
avatarImageView.setForUserOrChat(user, avatarDrawable);
avatarImageView.setVisibility(VISIBLE);
timeLeft = 3000;
} else if (action == ACTION_VOIP_USER_JOINED) {
TLRPC.Chat currentChat = (TLRPC.Chat) infoObject2;
if (infoObject instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) infoObject;
if (ChatObject.isChannelOrGiga(currentChat)) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipChannelUserJoined", R.string.VoipChannelUserJoined, UserObject.getFirstName(user)));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipChatUserJoined", R.string.VoipChatUserJoined, UserObject.getFirstName(user)));
}
} else {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
if (ChatObject.isChannelOrGiga(currentChat)) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipChannelChatJoined", R.string.VoipChannelChatJoined, chat.title));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipChatChatJoined", R.string.VoipChatChatJoined, chat.title));
}
}
subInfoText = null;
icon = 0;
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
avatarDrawable.setInfo((TLObject) infoObject);
avatarImageView.setForUserOrChat((TLObject) infoObject, avatarDrawable);
avatarImageView.setVisibility(VISIBLE);
timeLeft = 3000;
} else if (action == ACTION_VOIP_USER_CHANGED) {
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
String name;
if (infoObject instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) infoObject;
avatarDrawable.setInfo(user);
avatarImageView.setForUserOrChat(user, avatarDrawable);
name = ContactsController.formatName(user.first_name, user.last_name);
} else {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
avatarDrawable.setInfo(chat);
avatarImageView.setForUserOrChat(chat, avatarDrawable);
name = chat.title;
}
TLRPC.Chat currentChat = (TLRPC.Chat) infoObject2;
if (ChatObject.isChannelOrGiga(currentChat)) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipChannelUserChanged", R.string.VoipChannelUserChanged, name));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupUserChanged", R.string.VoipGroupUserChanged, name));
}
subInfoText = null;
icon = 0;
avatarImageView.setVisibility(VISIBLE);
timeLeft = 3000;
} else if (action == ACTION_VOIP_LINK_COPIED) {
infoText = LocaleController.getString("VoipGroupCopyInviteLinkCopied", R.string.VoipGroupCopyInviteLinkCopied);
subInfoText = null;
icon = R.raw.voip_invite;
timeLeft = 3000;
} else if (action == ACTION_PAYMENT_SUCCESS) {
infoText = (CharSequence) infoObject;
subInfoText = null;
icon = R.raw.payment_success;
timeLeft = 5000;
if (parentFragment != null && infoObject2 instanceof TLRPC.Message) {
TLRPC.Message message = (TLRPC.Message) infoObject2;
setOnTouchListener(null);
infoTextView.setMovementMethod(null);
setOnClickListener(v -> {
hide(true, 1);
TLRPC.TL_payments_getPaymentReceipt req = new TLRPC.TL_payments_getPaymentReceipt();
req.msg_id = message.id;
req.peer = parentFragment.getMessagesController().getInputPeer(message.peer_id);
parentFragment.getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_payments_paymentReceipt) {
parentFragment.presentFragment(new PaymentFormActivity((TLRPC.TL_payments_paymentReceipt) response));
}
}), ConnectionsManager.RequestFlagFailOnServerErrors);
});
}
} else if (action == ACTION_VOIP_MUTED) {
String name;
if (infoObject instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) infoObject;
name = UserObject.getFirstName(user);
} else {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
name = chat.title;
}
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupUserCantNowSpeak", R.string.VoipGroupUserCantNowSpeak, name));
subInfoText = null;
icon = R.raw.voip_muted;
timeLeft = 3000;
} else if (action == ACTION_VOIP_MUTED_FOR_YOU) {
String name;
if (infoObject instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) infoObject;
name = UserObject.getFirstName(user);
} else if (infoObject instanceof TLRPC.Chat) {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
name = chat.title;
} else {
name = "";
}
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupUserCantNowSpeakForYou", R.string.VoipGroupUserCantNowSpeakForYou, name));
subInfoText = null;
icon = R.raw.voip_muted;
timeLeft = 3000;
} else if (action == ACTION_VOIP_UNMUTED) {
String name;
if (infoObject instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) infoObject;
name = UserObject.getFirstName(user);
} else {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
name = chat.title;
}
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupUserCanNowSpeak", R.string.VoipGroupUserCanNowSpeak, name));
subInfoText = null;
icon = R.raw.voip_unmuted;
timeLeft = 3000;
} else if (action == ACTION_VOIP_CAN_NOW_SPEAK) {
if (infoObject instanceof TLRPC.Chat) {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupYouCanNowSpeakIn", R.string.VoipGroupYouCanNowSpeakIn, chat.title));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.getString("VoipGroupYouCanNowSpeak", R.string.VoipGroupYouCanNowSpeak));
}
subInfoText = null;
icon = R.raw.voip_allow_talk;
timeLeft = 3000;
} else if (action == ACTION_VOIP_SOUND_MUTED) {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
if (ChatObject.isChannelOrGiga(chat)) {
infoText = AndroidUtilities.replaceTags(LocaleController.getString("VoipChannelSoundMuted", R.string.VoipChannelSoundMuted));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.getString("VoipGroupSoundMuted", R.string.VoipGroupSoundMuted));
}
subInfoText = null;
icon = R.raw.ic_mute;
timeLeft = 3000;
} else if (action == ACTION_VOIP_SOUND_UNMUTED) {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
if (ChatObject.isChannelOrGiga(chat)) {
infoText = AndroidUtilities.replaceTags(LocaleController.getString("VoipChannelSoundUnmuted", R.string.VoipChannelSoundUnmuted));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.getString("VoipGroupSoundUnmuted", R.string.VoipGroupSoundUnmuted));
}
subInfoText = null;
icon = R.raw.ic_unmute;
timeLeft = 3000;
} else if (currentAction == ACTION_VOIP_RECORDING_STARTED || currentAction == ACTION_VOIP_VIDEO_RECORDING_STARTED) {
infoText = AndroidUtilities.replaceTags(currentAction == ACTION_VOIP_RECORDING_STARTED ? LocaleController.getString("VoipGroupAudioRecordStarted", R.string.VoipGroupAudioRecordStarted) : LocaleController.getString("VoipGroupVideoRecordStarted", R.string.VoipGroupVideoRecordStarted));
subInfoText = null;
icon = R.raw.voip_record_start;
timeLeft = 3000;
} else if (currentAction == ACTION_VOIP_RECORDING_FINISHED || currentAction == ACTION_VOIP_VIDEO_RECORDING_FINISHED) {
String text = currentAction == ACTION_VOIP_RECORDING_FINISHED ? LocaleController.getString("VoipGroupAudioRecordSaved", R.string.VoipGroupAudioRecordSaved) : LocaleController.getString("VoipGroupVideoRecordSaved", R.string.VoipGroupVideoRecordSaved);
subInfoText = null;
icon = R.raw.voip_record_saved;
timeLeft = 4000;
infoTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
SpannableStringBuilder builder = new SpannableStringBuilder(text);
int index1 = text.indexOf("**");
int index2 = text.lastIndexOf("**");
if (index1 >= 0 && index2 >= 0 && index1 != index2) {
builder.replace(index2, index2 + 2, "");
builder.replace(index1, index1 + 2, "");
try {
builder.setSpan(new URLSpanNoUnderline("tg://openmessage?user_id=" + UserConfig.getInstance(currentAccount).getClientUserId()), index1, index2 - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} catch (Exception e) {
FileLog.e(e);
}
}
infoText = builder;
} else if (action == ACTION_VOIP_UNMUTED_FOR_YOU) {
String name;
if (infoObject instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) infoObject;
name = UserObject.getFirstName(user);
} else {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
name = chat.title;
}
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupUserCanNowSpeakForYou", R.string.VoipGroupUserCanNowSpeakForYou, name));
subInfoText = null;
icon = R.raw.voip_unmuted;
timeLeft = 3000;
} else if (action == ACTION_VOIP_REMOVED) {
String name;
if (infoObject instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) infoObject;
name = UserObject.getFirstName(user);
} else {
TLRPC.Chat chat = (TLRPC.Chat) infoObject;
name = chat.title;
}
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupRemovedFromGroup", R.string.VoipGroupRemovedFromGroup, name));
subInfoText = null;
icon = R.raw.voip_group_removed;
timeLeft = 3000;
} else if (action == ACTION_OWNER_TRANSFERED_CHANNEL || action == ACTION_OWNER_TRANSFERED_GROUP) {
TLRPC.User user = (TLRPC.User) infoObject;
if (action == ACTION_OWNER_TRANSFERED_CHANNEL) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("EditAdminTransferChannelToast", R.string.EditAdminTransferChannelToast, UserObject.getFirstName(user)));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("EditAdminTransferGroupToast", R.string.EditAdminTransferGroupToast, UserObject.getFirstName(user)));
}
subInfoText = null;
icon = R.raw.contact_check;
} else if (action == ACTION_CONTACT_ADDED) {
TLRPC.User user = (TLRPC.User) infoObject;
infoText = LocaleController.formatString("NowInContacts", R.string.NowInContacts, UserObject.getFirstName(user));
subInfoText = null;
icon = R.raw.contact_check;
} else if (action == ACTION_PROFILE_PHOTO_CHANGED) {
if (DialogObject.isUserDialog(did)) {
if (infoObject == null) {
infoText = LocaleController.getString("MainProfilePhotoSetHint", R.string.MainProfilePhotoSetHint);
} else {
infoText = LocaleController.getString("MainProfileVideoSetHint", R.string.MainProfileVideoSetHint);
}
} else {
TLRPC.Chat chat = MessagesController.getInstance(UserConfig.selectedAccount).getChat(-did);
if (ChatObject.isChannel(chat) && !chat.megagroup) {
if (infoObject == null) {
infoText = LocaleController.getString("MainChannelProfilePhotoSetHint", R.string.MainChannelProfilePhotoSetHint);
} else {
infoText = LocaleController.getString("MainChannelProfileVideoSetHint", R.string.MainChannelProfileVideoSetHint);
}
} else {
if (infoObject == null) {
infoText = LocaleController.getString("MainGroupProfilePhotoSetHint", R.string.MainGroupProfilePhotoSetHint);
} else {
infoText = LocaleController.getString("MainGroupProfileVideoSetHint", R.string.MainGroupProfileVideoSetHint);
}
}
}
subInfoText = null;
icon = R.raw.contact_check;
} else if (action == ACTION_CHAT_UNARCHIVED) {
infoText = LocaleController.getString("ChatWasMovedToMainList", R.string.ChatWasMovedToMainList);
subInfoText = null;
icon = R.raw.contact_check;
} else if (action == ACTION_ARCHIVE_HIDDEN) {
infoText = LocaleController.getString("ArchiveHidden", R.string.ArchiveHidden);
subInfoText = LocaleController.getString("ArchiveHiddenInfo", R.string.ArchiveHiddenInfo);
icon = R.raw.chats_swipearchive;
size = 48;
} else if (currentAction == ACTION_QUIZ_CORRECT) {
infoText = LocaleController.getString("QuizWellDone", R.string.QuizWellDone);
subInfoText = LocaleController.getString("QuizWellDoneInfo", R.string.QuizWellDoneInfo);
icon = R.raw.wallet_congrats;
size = 44;
} else if (currentAction == ACTION_QUIZ_INCORRECT) {
infoText = LocaleController.getString("QuizWrongAnswer", R.string.QuizWrongAnswer);
subInfoText = LocaleController.getString("QuizWrongAnswerInfo", R.string.QuizWrongAnswerInfo);
icon = R.raw.wallet_science;
size = 44;
} else if (action == ACTION_ARCHIVE_PINNED) {
infoText = LocaleController.getString("ArchivePinned", R.string.ArchivePinned);
if (MessagesController.getInstance(currentAccount).dialogFilters.isEmpty()) {
subInfoText = LocaleController.getString("ArchivePinnedInfo", R.string.ArchivePinnedInfo);
} else {
subInfoText = null;
}
icon = R.raw.chats_infotip;
} else if (action == ACTION_ADDED_TO_FOLDER || action == ACTION_REMOVED_FROM_FOLDER) {
MessagesController.DialogFilter filter = (MessagesController.DialogFilter) infoObject2;
if (did != 0) {
long dialogId = did;
if (DialogObject.isEncryptedDialog(did)) {
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(DialogObject.getEncryptedChatId(dialogId));
dialogId = encryptedChat.user_id;
}
if (DialogObject.isUserDialog(dialogId)) {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(dialogId);
if (action == ACTION_ADDED_TO_FOLDER) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("FilterUserAddedToExisting", R.string.FilterUserAddedToExisting, UserObject.getFirstName(user), filter.name));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("FilterUserRemovedFrom", R.string.FilterUserRemovedFrom, UserObject.getFirstName(user), filter.name));
}
} else {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-dialogId);
if (action == ACTION_ADDED_TO_FOLDER) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("FilterChatAddedToExisting", R.string.FilterChatAddedToExisting, chat.title, filter.name));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("FilterChatRemovedFrom", R.string.FilterChatRemovedFrom, chat.title, filter.name));
}
}
} else {
if (action == ACTION_ADDED_TO_FOLDER) {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("FilterChatsAddedToExisting", R.string.FilterChatsAddedToExisting, LocaleController.formatPluralString("ChatsSelected", (Integer) infoObject), filter.name));
} else {
infoText = AndroidUtilities.replaceTags(LocaleController.formatString("FilterChatsRemovedFrom", R.string.FilterChatsRemovedFrom, LocaleController.formatPluralString("ChatsSelected", (Integer) infoObject), filter.name));
}
}
subInfoText = null;
icon = action == ACTION_ADDED_TO_FOLDER ? R.raw.folder_in : R.raw.folder_out;
} else if (action == ACTION_CACHE_WAS_CLEARED) {
infoText = this.infoText;
subInfoText = null;
icon = R.raw.chats_infotip;
} else if (action == ACTION_PIN_DIALOGS || action == ACTION_UNPIN_DIALOGS) {
int count = (Integer) infoObject;
if (action == ACTION_PIN_DIALOGS) {
infoText = LocaleController.formatPluralString("PinnedDialogsCount", count);
} else {
infoText = LocaleController.formatPluralString("UnpinnedDialogsCount", count);
}
subInfoText = null;
icon = currentAction == ACTION_PIN_DIALOGS ? R.raw.ic_pin : R.raw.ic_unpin;
} else {
if (action == ACTION_ARCHIVE_HINT) {
infoText = LocaleController.getString("ChatArchived", R.string.ChatArchived);
} else {
infoText = LocaleController.getString("ChatsArchived", R.string.ChatsArchived);
}
if (MessagesController.getInstance(currentAccount).dialogFilters.isEmpty()) {
subInfoText = LocaleController.getString("ChatArchivedInfo", R.string.ChatArchivedInfo);
} else {
subInfoText = null;
}
icon = R.raw.chats_infotip;
}
infoTextView.setText(infoText);
if (icon != 0) {
if (iconIsDrawable) {
leftImageView.setImageResource(icon);
} else {
leftImageView.setAnimation(icon, size, size);
RLottieDrawable drawable = leftImageView.getAnimatedDrawable();
drawable.setPlayInDirectionOfCustomEndFrame(reversedPlay);
drawable.setCustomEndFrame(reversedPlay ? reversedPlayEndFrame : drawable.getFramesCount());
}
leftImageView.setVisibility(VISIBLE);
if (!iconIsDrawable) {
leftImageView.setProgress(reversedPlay ? 1 : 0);
leftImageView.playAnimation();
}
} else {
leftImageView.setVisibility(GONE);
}
if (subInfoText != null) {
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.topMargin = AndroidUtilities.dp(6);
layoutParams.rightMargin = AndroidUtilities.dp(8);
layoutParams = (FrameLayout.LayoutParams) subinfoTextView.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(8);
subinfoTextView.setText(subInfoText);
subinfoTextView.setVisibility(VISIBLE);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
infoTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
} else {
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.topMargin = AndroidUtilities.dp(13);
layoutParams.rightMargin = AndroidUtilities.dp(8);
subinfoTextView.setVisibility(GONE);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
infoTextView.setTypeface(Typeface.DEFAULT);
}
undoButton.setVisibility(GONE);
} else if (currentAction == ACTION_IMPORT_NOT_MUTUAL || currentAction == ACTION_IMPORT_GROUP_NOT_ADMIN || currentAction == ACTION_IMPORT_INFO || currentAction == ACTION_PLAYBACK_SPEED_DISABLED || currentAction == ACTION_PLAYBACK_SPEED_ENABLED || currentAction == ACTION_MESSAGE_COPIED || currentAction == ACTION_FWD_MESSAGES || currentAction == ACTION_NOTIFY_ON || currentAction == ACTION_NOTIFY_OFF || currentAction == ACTION_USERNAME_COPIED || currentAction == ACTION_HASHTAG_COPIED || currentAction == ACTION_TEXT_COPIED || currentAction == ACTION_LINK_COPIED || currentAction == ACTION_PHONE_COPIED || currentAction == ACTION_AUTO_DELETE_OFF || currentAction == ACTION_AUTO_DELETE_ON || currentAction == ACTION_GIGAGROUP_CANCEL || currentAction == ACTION_GIGAGROUP_SUCCESS || currentAction == ACTION_VOIP_INVITE_LINK_SENT || currentAction == ACTION_PIN_DIALOGS || currentAction == ACTION_UNPIN_DIALOGS || currentAction == ACTION_SHARE_BACKGROUND || currentAction == ACTION_EMAIL_COPIED) {
undoImageView.setVisibility(GONE);
leftImageView.setVisibility(VISIBLE);
infoTextView.setTypeface(Typeface.DEFAULT);
long hapticDelay = -1;
if (currentAction == ACTION_GIGAGROUP_SUCCESS) {
infoTextView.setText(LocaleController.getString("BroadcastGroupConvertSuccess", R.string.BroadcastGroupConvertSuccess));
leftImageView.setAnimation(R.raw.gigagroup_convert, 36, 36);
infoOnly = true;
layoutParams.topMargin = AndroidUtilities.dp(9);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
} else if (currentAction == ACTION_GIGAGROUP_CANCEL) {
infoTextView.setText(LocaleController.getString("GigagroupConvertCancelHint", R.string.GigagroupConvertCancelHint));
leftImageView.setAnimation(R.raw.chats_infotip, 36, 36);
infoOnly = true;
layoutParams.topMargin = AndroidUtilities.dp(9);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
} else if (action == ACTION_AUTO_DELETE_ON) {
TLRPC.User user = (TLRPC.User) infoObject;
int ttl = (Integer) infoObject2;
String time;
subinfoTextView.setSingleLine(false);
if (ttl >= 30 * 24 * 60 * 60) {
time = LocaleController.formatPluralString("Months", ttl / (30 * 24 * 60 * 60));
} else if (ttl > 24 * 60 * 60) {
time = LocaleController.formatPluralString("Days", ttl / (24 * 60 * 60));
} else if (ttl >= 60 * 60) {
time = LocaleController.formatPluralString("Hours", ttl / (60 * 60));
} else if (ttl >= 60) {
time = LocaleController.formatPluralString("Minutes", ttl / 60);
} else {
time = LocaleController.formatPluralString("Seconds", ttl);
}
infoTextView.setText(LocaleController.formatString("AutoDeleteHintOnText", R.string.AutoDeleteHintOnText, time));
leftImageView.setAnimation(R.raw.fire_on, 36, 36);
layoutParams.topMargin = AndroidUtilities.dp(9);
timeLeft = 4000;
infoOnly = true;
leftImageView.setPadding(0, 0, 0, AndroidUtilities.dp(3));
} else if (currentAction == ACTION_AUTO_DELETE_OFF) {
infoTextView.setText(LocaleController.getString("AutoDeleteHintOffText", R.string.AutoDeleteHintOffText));
leftImageView.setAnimation(R.raw.fire_off, 36, 36);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
timeLeft = 3000;
leftImageView.setPadding(0, 0, 0, AndroidUtilities.dp(4));
} else if (currentAction == ACTION_IMPORT_NOT_MUTUAL) {
infoTextView.setText(LocaleController.getString("ImportMutualError", R.string.ImportMutualError));
leftImageView.setAnimation(R.raw.error, 36, 36);
infoOnly = true;
layoutParams.topMargin = AndroidUtilities.dp(9);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
} else if (currentAction == ACTION_IMPORT_GROUP_NOT_ADMIN) {
infoTextView.setText(LocaleController.getString("ImportNotAdmin", R.string.ImportNotAdmin));
leftImageView.setAnimation(R.raw.error, 36, 36);
infoOnly = true;
layoutParams.topMargin = AndroidUtilities.dp(9);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
} else if (currentAction == ACTION_IMPORT_INFO) {
infoTextView.setText(LocaleController.getString("ImportedInfo", R.string.ImportedInfo));
leftImageView.setAnimation(R.raw.imported, 36, 36);
leftImageView.setPadding(0, 0, 0, AndroidUtilities.dp(5));
infoOnly = true;
layoutParams.topMargin = AndroidUtilities.dp(9);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
} else if (currentAction == ACTION_PLAYBACK_SPEED_DISABLED) {
infoTextView.setText(LocaleController.getString("AudioSpeedNormal", R.string.AudioSpeedNormal));
leftImageView.setAnimation(R.raw.audio_stop_speed, 36, 36);
timeLeft = 3000;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
} else if (currentAction == ACTION_PLAYBACK_SPEED_ENABLED) {
infoTextView.setText(LocaleController.getString("AudioSpeedFast", R.string.AudioSpeedFast));
leftImageView.setAnimation(R.raw.audio_speed, 36, 36);
timeLeft = 3000;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
} else if (currentAction == ACTION_MESSAGE_COPIED || currentAction == ACTION_USERNAME_COPIED || currentAction == ACTION_HASHTAG_COPIED || currentAction == ACTION_TEXT_COPIED || currentAction == ACTION_LINK_COPIED || currentAction == ACTION_PHONE_COPIED || currentAction == ACTION_EMAIL_COPIED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
return;
}
int iconRawId = R.raw.copy;
if (currentAction == ACTION_EMAIL_COPIED) {
infoTextView.setText(LocaleController.getString("EmailCopied", R.string.EmailCopied));
} else if (currentAction == ACTION_PHONE_COPIED) {
infoTextView.setText(LocaleController.getString("PhoneCopied", R.string.PhoneCopied));
} else if (currentAction == ACTION_USERNAME_COPIED) {
infoTextView.setText(LocaleController.getString("UsernameCopied", R.string.UsernameCopied));
} else if (currentAction == ACTION_HASHTAG_COPIED) {
infoTextView.setText(LocaleController.getString("HashtagCopied", R.string.HashtagCopied));
} else if (currentAction == ACTION_MESSAGE_COPIED) {
infoTextView.setText(LocaleController.getString("MessageCopied", R.string.MessageCopied));
} else if (currentAction == ACTION_LINK_COPIED) {
iconRawId = R.raw.voip_invite;
infoTextView.setText(LocaleController.getString("LinkCopied", R.string.LinkCopied));
} else {
infoTextView.setText(LocaleController.getString("TextCopied", R.string.TextCopied));
}
leftImageView.setAnimation(iconRawId, 30, 30);
timeLeft = 3000;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
} else if (currentAction == ACTION_NOTIFY_ON) {
infoTextView.setText(LocaleController.getString("ChannelNotifyMembersInfoOn", R.string.ChannelNotifyMembersInfoOn));
leftImageView.setAnimation(R.raw.silent_unmute, 30, 30);
timeLeft = 3000;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
} else if (currentAction == ACTION_NOTIFY_OFF) {
infoTextView.setText(LocaleController.getString("ChannelNotifyMembersInfoOff", R.string.ChannelNotifyMembersInfoOff));
leftImageView.setAnimation(R.raw.silent_mute, 30, 30);
timeLeft = 3000;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
} else if (currentAction == ACTION_VOIP_INVITE_LINK_SENT) {
if (infoObject2 == null) {
if (did == UserConfig.getInstance(currentAccount).clientUserId) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("InvLinkToSavedMessages", R.string.InvLinkToSavedMessages)));
} else {
if (DialogObject.isChatDialog(did)) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-did);
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("InvLinkToGroup", R.string.InvLinkToGroup, chat.title)));
} else {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(did);
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("InvLinkToUser", R.string.InvLinkToUser, UserObject.getFirstName(user))));
}
}
} else {
int amount = (Integer) infoObject2;
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("InvLinkToChats", R.string.InvLinkToChats, LocaleController.formatPluralString("Chats", amount))));
}
leftImageView.setAnimation(R.raw.contact_check, 36, 36);
timeLeft = 3000;
} else if (currentAction == ACTION_FWD_MESSAGES) {
Integer count = (Integer) infoObject;
if (infoObject2 == null) {
if (did == UserConfig.getInstance(currentAccount).clientUserId) {
if (count == 1) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("FwdMessageToSavedMessages", R.string.FwdMessageToSavedMessages)));
} else {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("FwdMessagesToSavedMessages", R.string.FwdMessagesToSavedMessages)));
}
leftImageView.setAnimation(R.raw.saved_messages, 30, 30);
} else {
if (DialogObject.isChatDialog(did)) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-did);
if (count == 1) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessageToGroup", R.string.FwdMessageToGroup, chat.title)));
} else {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessagesToGroup", R.string.FwdMessagesToGroup, chat.title)));
}
} else {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(did);
if (count == 1) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessageToUser", R.string.FwdMessageToUser, UserObject.getFirstName(user))));
} else {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessagesToUser", R.string.FwdMessagesToUser, UserObject.getFirstName(user))));
}
}
leftImageView.setAnimation(R.raw.forward, 30, 30);
hapticDelay = 300;
}
} else {
int amount = (Integer) infoObject2;
if (count == 1) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessageToChats", R.string.FwdMessageToChats, LocaleController.formatPluralString("Chats", amount))));
} else {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("FwdMessagesToChats", R.string.FwdMessagesToChats, LocaleController.formatPluralString("Chats", amount))));
}
leftImageView.setAnimation(R.raw.forward, 30, 30);
hapticDelay = 300;
}
timeLeft = 3000;
} else if (currentAction == ACTION_SHARE_BACKGROUND) {
Integer count = (Integer) infoObject;
if (infoObject2 == null) {
if (did == UserConfig.getInstance(currentAccount).clientUserId) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("BackgroundToSavedMessages", R.string.BackgroundToSavedMessages)));
leftImageView.setAnimation(R.raw.saved_messages, 30, 30);
} else {
if (DialogObject.isChatDialog(did)) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-did);
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("BackgroundToGroup", R.string.BackgroundToGroup, chat.title)));
} else {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(did);
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("BackgroundToUser", R.string.BackgroundToUser, UserObject.getFirstName(user))));
}
leftImageView.setAnimation(R.raw.forward, 30, 30);
}
} else {
int amount = (Integer) infoObject2;
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("BackgroundToChats", R.string.BackgroundToChats, LocaleController.formatPluralString("Chats", amount))));
leftImageView.setAnimation(R.raw.forward, 30, 30);
}
timeLeft = 3000;
}
subinfoTextView.setVisibility(GONE);
undoTextView.setTextColor(getThemedColor(Theme.key_undo_cancelColor));
undoButton.setVisibility(GONE);
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.rightMargin = AndroidUtilities.dp(8);
leftImageView.setProgress(0);
leftImageView.playAnimation();
if (hapticDelay > 0) {
leftImageView.postDelayed(() -> {
leftImageView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}, hapticDelay);
}
} else if (currentAction == ACTION_PROXIMITY_SET || currentAction == ACTION_PROXIMITY_REMOVED) {
int radius = (Integer) infoObject;
TLRPC.User user = (TLRPC.User) infoObject2;
undoImageView.setVisibility(GONE);
leftImageView.setVisibility(VISIBLE);
if (radius != 0) {
infoTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
leftImageView.clearLayerColors();
leftImageView.setLayerColor("BODY.**", getThemedColor(Theme.key_undo_infoColor));
leftImageView.setLayerColor("Wibe Big.**", getThemedColor(Theme.key_undo_infoColor));
leftImageView.setLayerColor("Wibe Big 3.**", getThemedColor(Theme.key_undo_infoColor));
leftImageView.setLayerColor("Wibe Small.**", getThemedColor(Theme.key_undo_infoColor));
infoTextView.setText(LocaleController.getString("ProximityAlertSet", R.string.ProximityAlertSet));
leftImageView.setAnimation(R.raw.ic_unmute, 28, 28);
subinfoTextView.setVisibility(VISIBLE);
subinfoTextView.setSingleLine(false);
subinfoTextView.setMaxLines(3);
if (user != null) {
subinfoTextView.setText(LocaleController.formatString("ProximityAlertSetInfoUser", R.string.ProximityAlertSetInfoUser, UserObject.getFirstName(user), LocaleController.formatDistance(radius, 2)));
} else {
subinfoTextView.setText(LocaleController.formatString("ProximityAlertSetInfoGroup2", R.string.ProximityAlertSetInfoGroup2, LocaleController.formatDistance(radius, 2)));
}
undoButton.setVisibility(GONE);
layoutParams.topMargin = AndroidUtilities.dp(6);
} else {
infoTextView.setTypeface(Typeface.DEFAULT);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
leftImageView.clearLayerColors();
leftImageView.setLayerColor("Body Main.**", getThemedColor(Theme.key_undo_infoColor));
leftImageView.setLayerColor("Body Top.**", getThemedColor(Theme.key_undo_infoColor));
leftImageView.setLayerColor("Line.**", getThemedColor(Theme.key_undo_infoColor));
leftImageView.setLayerColor("Curve Big.**", getThemedColor(Theme.key_undo_infoColor));
leftImageView.setLayerColor("Curve Small.**", getThemedColor(Theme.key_undo_infoColor));
layoutParams.topMargin = AndroidUtilities.dp(14);
infoTextView.setText(LocaleController.getString("ProximityAlertCancelled", R.string.ProximityAlertCancelled));
leftImageView.setAnimation(R.raw.ic_mute, 28, 28);
subinfoTextView.setVisibility(GONE);
undoTextView.setTextColor(getThemedColor(Theme.key_undo_cancelColor));
undoButton.setVisibility(VISIBLE);
}
layoutParams.leftMargin = AndroidUtilities.dp(58);
leftImageView.setProgress(0);
leftImageView.playAnimation();
} else if (currentAction == ACTION_QR_SESSION_ACCEPTED) {
TLRPC.TL_authorization authorization = (TLRPC.TL_authorization) infoObject;
infoTextView.setText(LocaleController.getString("AuthAnotherClientOk", R.string.AuthAnotherClientOk));
leftImageView.setAnimation(R.raw.contact_check, 36, 36);
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.topMargin = AndroidUtilities.dp(6);
subinfoTextView.setText(authorization.app_name);
subinfoTextView.setVisibility(VISIBLE);
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
infoTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
undoTextView.setTextColor(getThemedColor(Theme.key_windowBackgroundWhiteRedText2));
undoImageView.setVisibility(GONE);
undoButton.setVisibility(VISIBLE);
leftImageView.setVisibility(VISIBLE);
leftImageView.setProgress(0);
leftImageView.playAnimation();
} else if (currentAction == ACTION_FILTERS_AVAILABLE) {
timeLeft = 10000;
undoTextView.setText(LocaleController.getString("Open", R.string.Open).toUpperCase());
infoTextView.setText(LocaleController.getString("FilterAvailableTitle", R.string.FilterAvailableTitle));
leftImageView.setAnimation(R.raw.filter_new, 36, 36);
int margin = (int) Math.ceil(undoTextView.getPaint().measureText(undoTextView.getText().toString())) + AndroidUtilities.dp(26);
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.rightMargin = margin;
layoutParams.topMargin = AndroidUtilities.dp(6);
layoutParams = (FrameLayout.LayoutParams) subinfoTextView.getLayoutParams();
layoutParams.rightMargin = margin;
String text = LocaleController.getString("FilterAvailableText", R.string.FilterAvailableText);
SpannableStringBuilder builder = new SpannableStringBuilder(text);
int index1 = text.indexOf('*');
int index2 = text.lastIndexOf('*');
if (index1 >= 0 && index2 >= 0 && index1 != index2) {
builder.replace(index2, index2 + 1, "");
builder.replace(index1, index1 + 1, "");
builder.setSpan(new URLSpanNoUnderline("tg://settings/folders"), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
subinfoTextView.setText(builder);
subinfoTextView.setVisibility(VISIBLE);
subinfoTextView.setSingleLine(false);
subinfoTextView.setMaxLines(2);
undoButton.setVisibility(VISIBLE);
undoImageView.setVisibility(GONE);
leftImageView.setVisibility(VISIBLE);
leftImageView.setProgress(0);
leftImageView.playAnimation();
} else if (currentAction == ACTION_DICE_INFO || currentAction == ACTION_DICE_NO_SEND_INFO) {
timeLeft = 4000;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
infoTextView.setGravity(Gravity.CENTER_VERTICAL);
infoTextView.setMinHeight(AndroidUtilities.dp(30));
String emoji = (String) infoObject;
if ("\uD83C\uDFB2".equals(emoji)) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DiceInfo2", R.string.DiceInfo2)));
leftImageView.setImageResource(R.drawable.dice);
} else {
if ("\uD83C\uDFAF".equals(emoji)) {
infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DartInfo", R.string.DartInfo)));
} else {
String info = LocaleController.getServerString("DiceEmojiInfo_" + emoji);
if (!TextUtils.isEmpty(info)) {
infoTextView.setText(Emoji.replaceEmoji(info, infoTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
} else {
infoTextView.setText(Emoji.replaceEmoji(LocaleController.formatString("DiceEmojiInfo", R.string.DiceEmojiInfo, emoji), infoTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
}
}
leftImageView.setImageDrawable(Emoji.getEmojiDrawable(emoji));
leftImageView.setScaleType(ImageView.ScaleType.FIT_XY);
layoutParams.topMargin = AndroidUtilities.dp(14);
layoutParams.bottomMargin = AndroidUtilities.dp(14);
layoutParams2.leftMargin = AndroidUtilities.dp(14);
layoutParams2.width = AndroidUtilities.dp(26);
layoutParams2.height = AndroidUtilities.dp(26);
}
undoTextView.setText(LocaleController.getString("SendDice", R.string.SendDice));
int margin;
if (currentAction == ACTION_DICE_INFO) {
margin = (int) Math.ceil(undoTextView.getPaint().measureText(undoTextView.getText().toString())) + AndroidUtilities.dp(26);
undoTextView.setVisibility(VISIBLE);
undoTextView.setTextColor(getThemedColor(Theme.key_undo_cancelColor));
undoImageView.setVisibility(GONE);
undoButton.setVisibility(VISIBLE);
} else {
margin = AndroidUtilities.dp(8);
undoTextView.setVisibility(GONE);
undoButton.setVisibility(GONE);
}
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.rightMargin = margin;
layoutParams.topMargin = AndroidUtilities.dp(6);
layoutParams.bottomMargin = AndroidUtilities.dp(7);
layoutParams.height = TableLayout.LayoutParams.MATCH_PARENT;
subinfoTextView.setVisibility(GONE);
leftImageView.setVisibility(VISIBLE);
} else if (currentAction == ACTION_TEXT_INFO) {
CharSequence info = (CharSequence) infoObject;
timeLeft = Math.max(4000, Math.min(info.length() / 50 * 1600, 10000));
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
infoTextView.setGravity(Gravity.CENTER_VERTICAL);
infoTextView.setText(info);
undoTextView.setVisibility(GONE);
undoButton.setVisibility(GONE);
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.rightMargin = AndroidUtilities.dp(8);
layoutParams.topMargin = AndroidUtilities.dp(6);
layoutParams.bottomMargin = AndroidUtilities.dp(7);
layoutParams.height = TableLayout.LayoutParams.MATCH_PARENT;
layoutParams2.gravity = Gravity.TOP | Gravity.LEFT;
layoutParams2.topMargin = layoutParams2.bottomMargin = AndroidUtilities.dp(8);
leftImageView.setVisibility(VISIBLE);
leftImageView.setAnimation(R.raw.chats_infotip, 36, 36);
leftImageView.setProgress(0);
leftImageView.playAnimation();
infoTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
} else if (currentAction == ACTION_THEME_CHANGED) {
infoTextView.setText(LocaleController.getString("ColorThemeChanged", R.string.ColorThemeChanged));
leftImageView.setImageResource(R.drawable.toast_pallete);
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.rightMargin = AndroidUtilities.dp(48);
layoutParams.topMargin = AndroidUtilities.dp(6);
layoutParams = (FrameLayout.LayoutParams) subinfoTextView.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(48);
String text = LocaleController.getString("ColorThemeChangedInfo", R.string.ColorThemeChangedInfo);
SpannableStringBuilder builder = new SpannableStringBuilder(text);
int index1 = text.indexOf('*');
int index2 = text.lastIndexOf('*');
if (index1 >= 0 && index2 >= 0 && index1 != index2) {
builder.replace(index2, index2 + 1, "");
builder.replace(index1, index1 + 1, "");
builder.setSpan(new URLSpanNoUnderline("tg://settings/themes"), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
subinfoTextView.setText(builder);
subinfoTextView.setVisibility(VISIBLE);
subinfoTextView.setSingleLine(false);
subinfoTextView.setMaxLines(2);
undoTextView.setVisibility(GONE);
undoButton.setVisibility(VISIBLE);
leftImageView.setVisibility(VISIBLE);
} else if (currentAction == ACTION_ARCHIVE || currentAction == ACTION_ARCHIVE_FEW) {
if (action == ACTION_ARCHIVE) {
infoTextView.setText(LocaleController.getString("ChatArchived", R.string.ChatArchived));
} else {
infoTextView.setText(LocaleController.getString("ChatsArchived", R.string.ChatsArchived));
}
layoutParams.leftMargin = AndroidUtilities.dp(58);
layoutParams.topMargin = AndroidUtilities.dp(13);
layoutParams.rightMargin = 0;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
undoButton.setVisibility(VISIBLE);
infoTextView.setTypeface(Typeface.DEFAULT);
subinfoTextView.setVisibility(GONE);
leftImageView.setVisibility(VISIBLE);
leftImageView.setAnimation(R.raw.chats_archived, 36, 36);
leftImageView.setProgress(0);
leftImageView.playAnimation();
} else {
layoutParams.leftMargin = AndroidUtilities.dp(45);
layoutParams.topMargin = AndroidUtilities.dp(13);
layoutParams.rightMargin = 0;
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
undoButton.setVisibility(VISIBLE);
infoTextView.setTypeface(Typeface.DEFAULT);
subinfoTextView.setVisibility(GONE);
leftImageView.setVisibility(GONE);
if (currentAction == ACTION_CLEAR_DATES || currentAction == ACTION_CLEAR || currentAction == ACTION_CLEAR_FEW) {
infoTextView.setText(LocaleController.getString("HistoryClearedUndo", R.string.HistoryClearedUndo));
} else if (currentAction == ACTION_DELETE_FEW) {
infoTextView.setText(LocaleController.getString("ChatsDeletedUndo", R.string.ChatsDeletedUndo));
} else {
if (DialogObject.isChatDialog(did)) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-did);
if (ChatObject.isChannel(chat) && !chat.megagroup) {
infoTextView.setText(LocaleController.getString("ChannelDeletedUndo", R.string.ChannelDeletedUndo));
} else {
infoTextView.setText(LocaleController.getString("GroupDeletedUndo", R.string.GroupDeletedUndo));
}
} else {
infoTextView.setText(LocaleController.getString("ChatDeletedUndo", R.string.ChatDeletedUndo));
}
}
if (currentAction != ACTION_CLEAR_DATES) {
for (int a = 0; a < dialogIds.size(); a++) {
MessagesController.getInstance(currentAccount).addDialogAction(dialogIds.get(a), currentAction == ACTION_CLEAR || currentAction == ACTION_CLEAR_FEW);
}
}
}
AndroidUtilities.makeAccessibilityAnnouncement(infoTextView.getText() + (subinfoTextView.getVisibility() == VISIBLE ? ". " + subinfoTextView.getText() : ""));
if (isMultilineSubInfo()) {
ViewGroup parent = (ViewGroup) getParent();
int width = parent.getMeasuredWidth();
if (width == 0) {
width = AndroidUtilities.displaySize.x;
}
width -= AndroidUtilities.dp(16);
measureChildWithMargins(subinfoTextView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 0, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0);
undoViewHeight = subinfoTextView.getMeasuredHeight() + AndroidUtilities.dp(27 + 10);
} else if (hasSubInfo()) {
undoViewHeight = AndroidUtilities.dp(52);
} else if (getParent() instanceof ViewGroup) {
ViewGroup parent = (ViewGroup) getParent();
int width = parent.getMeasuredWidth() - parent.getPaddingLeft() - parent.getPaddingRight();
if (width <= 0) {
width = AndroidUtilities.displaySize.x;
}
width -= AndroidUtilities.dp(16);
measureChildWithMargins(infoTextView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 0, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0);
undoViewHeight = infoTextView.getMeasuredHeight() + AndroidUtilities.dp(currentAction == ACTION_DICE_INFO || currentAction == ACTION_DICE_NO_SEND_INFO || currentAction == ACTION_TEXT_INFO ? 14 : 28);
if (currentAction == ACTION_TEXT_INFO) {
undoViewHeight = Math.max(undoViewHeight, AndroidUtilities.dp(52));
} else if (currentAction == ACTION_PROXIMITY_REMOVED) {
undoViewHeight = Math.max(undoViewHeight, AndroidUtilities.dp(50));
} else if (infoOnly) {
undoViewHeight -= AndroidUtilities.dp(8);
}
}
if (getVisibility() != VISIBLE) {
setVisibility(VISIBLE);
setEnterOffset((fromTop ? -1.0f : 1.0f) * (AndroidUtilities.dp(8) + undoViewHeight));
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "enterOffset", (fromTop ? -1.0f : 1.0f) * (AndroidUtilities.dp(8) + undoViewHeight), (fromTop ? 1.0f : -1.0f)));
animatorSet.setInterpolator(new DecelerateInterpolator());
animatorSet.setDuration(180);
animatorSet.start();
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class FileLoadOperation method startDownloadRequest.
protected void startDownloadRequest() {
if (paused || reuploadingCdn || state != stateDownloading || streamPriorityStartOffset == 0 && (!nextPartWasPreloaded && (requestInfos.size() + delayedRequestInfos.size() >= currentMaxDownloadRequests) || isPreloadVideoOperation && (requestedBytesCount > preloadMaxBytes || moovFound != 0 && requestInfos.size() > 0))) {
return;
}
int count = 1;
if (streamPriorityStartOffset == 0 && !nextPartWasPreloaded && (!isPreloadVideoOperation || moovFound != 0) && totalBytesCount > 0) {
count = Math.max(0, currentMaxDownloadRequests - requestInfos.size());
}
for (int a = 0; a < count; a++) {
int downloadOffset;
if (isPreloadVideoOperation) {
if (moovFound != 0 && preloadNotRequestedBytesCount <= 0) {
return;
}
if (nextPreloadDownloadOffset == -1) {
downloadOffset = 0;
boolean found = false;
int tries = preloadMaxBytes / currentDownloadChunkSize + 2;
while (tries != 0) {
if (requestedPreloadedBytesRanges.get(downloadOffset, 0) == 0) {
found = true;
break;
}
downloadOffset += currentDownloadChunkSize;
if (downloadOffset > totalBytesCount) {
break;
}
if (moovFound == 2 && downloadOffset == currentDownloadChunkSize * 8) {
downloadOffset = (totalBytesCount - preloadMaxBytes / 2) / currentDownloadChunkSize * currentDownloadChunkSize;
}
tries--;
}
if (!found && requestInfos.isEmpty()) {
onFinishLoadingFile(false);
}
} else {
downloadOffset = nextPreloadDownloadOffset;
}
if (requestedPreloadedBytesRanges == null) {
requestedPreloadedBytesRanges = new SparseIntArray();
}
requestedPreloadedBytesRanges.put(downloadOffset, 1);
if (BuildVars.DEBUG_VERSION) {
FileLog.d("start next preload from " + downloadOffset + " size " + totalBytesCount + " for " + cacheFilePreload);
}
preloadNotRequestedBytesCount -= currentDownloadChunkSize;
} else {
if (notRequestedBytesRanges != null) {
int sreamOffset = streamPriorityStartOffset != 0 ? streamPriorityStartOffset : streamStartOffset;
int size = notRequestedBytesRanges.size();
int minStart = Integer.MAX_VALUE;
int minStreamStart = Integer.MAX_VALUE;
for (int b = 0; b < size; b++) {
Range range = notRequestedBytesRanges.get(b);
if (sreamOffset != 0) {
if (range.start <= sreamOffset && range.end > sreamOffset) {
minStreamStart = sreamOffset;
minStart = Integer.MAX_VALUE;
break;
}
if (sreamOffset < range.start && range.start < minStreamStart) {
minStreamStart = range.start;
}
}
minStart = Math.min(minStart, range.start);
}
if (minStreamStart != Integer.MAX_VALUE) {
downloadOffset = minStreamStart;
} else if (minStart != Integer.MAX_VALUE) {
downloadOffset = minStart;
} else {
break;
}
} else {
downloadOffset = requestedBytesCount;
}
}
if (!isPreloadVideoOperation && notRequestedBytesRanges != null) {
addPart(notRequestedBytesRanges, downloadOffset, downloadOffset + currentDownloadChunkSize, false);
}
if (totalBytesCount > 0 && downloadOffset >= totalBytesCount) {
break;
}
boolean isLast = totalBytesCount <= 0 || a == count - 1 || totalBytesCount > 0 && downloadOffset + currentDownloadChunkSize >= totalBytesCount;
final TLObject request;
int connectionType = requestsCount % 2 == 0 ? ConnectionsManager.ConnectionTypeDownload : ConnectionsManager.ConnectionTypeDownload2;
int flags = (isForceRequest ? ConnectionsManager.RequestFlagForceDownload : 0);
if (isCdn) {
TLRPC.TL_upload_getCdnFile req = new TLRPC.TL_upload_getCdnFile();
req.file_token = cdnToken;
req.offset = downloadOffset;
req.limit = currentDownloadChunkSize;
request = req;
flags |= ConnectionsManager.RequestFlagEnableUnauthorized;
} else {
if (webLocation != null) {
TLRPC.TL_upload_getWebFile req = new TLRPC.TL_upload_getWebFile();
req.location = webLocation;
req.offset = downloadOffset;
req.limit = currentDownloadChunkSize;
request = req;
} else {
TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
req.location = location;
req.offset = downloadOffset;
req.limit = currentDownloadChunkSize;
req.cdn_supported = true;
request = req;
}
}
requestedBytesCount += currentDownloadChunkSize;
final RequestInfo requestInfo = new RequestInfo();
requestInfos.add(requestInfo);
requestInfo.offset = downloadOffset;
if (!isPreloadVideoOperation && supportsPreloading && preloadStream != null && preloadedBytesRanges != null) {
PreloadRange range = preloadedBytesRanges.get(requestInfo.offset);
if (range != null) {
requestInfo.response = new TLRPC.TL_upload_file();
try {
NativeByteBuffer buffer = new NativeByteBuffer(range.length);
preloadStream.seek(range.fileOffset);
preloadStream.getChannel().read(buffer.buffer);
buffer.buffer.position(0);
requestInfo.response.bytes = buffer;
Utilities.stageQueue.postRunnable(() -> {
processRequestResult(requestInfo, null);
requestInfo.response.freeResources();
});
continue;
} catch (Exception ignore) {
}
}
}
if (streamPriorityStartOffset != 0) {
if (BuildVars.DEBUG_VERSION) {
FileLog.d("frame get offset = " + streamPriorityStartOffset);
}
streamPriorityStartOffset = 0;
priorityRequestInfo = requestInfo;
}
if (location instanceof TLRPC.TL_inputPeerPhotoFileLocation) {
TLRPC.TL_inputPeerPhotoFileLocation inputPeerPhotoFileLocation = (TLRPC.TL_inputPeerPhotoFileLocation) location;
if (inputPeerPhotoFileLocation.photo_id == 0) {
requestReference(requestInfo);
continue;
}
}
requestInfo.requestToken = ConnectionsManager.getInstance(currentAccount).sendRequest(request, (response, error) -> {
if (!requestInfos.contains(requestInfo)) {
return;
}
if (requestInfo == priorityRequestInfo) {
if (BuildVars.DEBUG_VERSION) {
FileLog.d("frame get request completed " + priorityRequestInfo.offset);
}
priorityRequestInfo = null;
}
if (error != null) {
if (FileRefController.isFileRefError(error.text)) {
requestReference(requestInfo);
return;
} else if (request instanceof TLRPC.TL_upload_getCdnFile) {
if (error.text.equals("FILE_TOKEN_INVALID")) {
isCdn = false;
clearOperaion(requestInfo, false);
startDownloadRequest();
return;
}
}
}
if (response instanceof TLRPC.TL_upload_fileCdnRedirect) {
TLRPC.TL_upload_fileCdnRedirect res = (TLRPC.TL_upload_fileCdnRedirect) response;
if (!res.file_hashes.isEmpty()) {
if (cdnHashes == null) {
cdnHashes = new SparseArray<>();
}
for (int a1 = 0; a1 < res.file_hashes.size(); a1++) {
TLRPC.TL_fileHash hash = res.file_hashes.get(a1);
cdnHashes.put(hash.offset, hash);
}
}
if (res.encryption_iv == null || res.encryption_key == null || res.encryption_iv.length != 16 || res.encryption_key.length != 32) {
error = new TLRPC.TL_error();
error.text = "bad redirect response";
error.code = 400;
processRequestResult(requestInfo, error);
} else {
isCdn = true;
if (notCheckedCdnRanges == null) {
notCheckedCdnRanges = new ArrayList<>();
notCheckedCdnRanges.add(new Range(0, maxCdnParts));
}
cdnDatacenterId = res.dc_id;
cdnIv = res.encryption_iv;
cdnKey = res.encryption_key;
cdnToken = res.file_token;
clearOperaion(requestInfo, false);
startDownloadRequest();
}
} else if (response instanceof TLRPC.TL_upload_cdnFileReuploadNeeded) {
if (!reuploadingCdn) {
clearOperaion(requestInfo, false);
reuploadingCdn = true;
TLRPC.TL_upload_cdnFileReuploadNeeded res = (TLRPC.TL_upload_cdnFileReuploadNeeded) response;
TLRPC.TL_upload_reuploadCdnFile req = new TLRPC.TL_upload_reuploadCdnFile();
req.file_token = cdnToken;
req.request_token = res.request_token;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response1, error1) -> {
reuploadingCdn = false;
if (error1 == null) {
TLRPC.Vector vector = (TLRPC.Vector) response1;
if (!vector.objects.isEmpty()) {
if (cdnHashes == null) {
cdnHashes = new SparseArray<>();
}
for (int a1 = 0; a1 < vector.objects.size(); a1++) {
TLRPC.TL_fileHash hash = (TLRPC.TL_fileHash) vector.objects.get(a1);
cdnHashes.put(hash.offset, hash);
}
}
startDownloadRequest();
} else {
if (error1.text.equals("FILE_TOKEN_INVALID") || error1.text.equals("REQUEST_TOKEN_INVALID")) {
isCdn = false;
clearOperaion(requestInfo, false);
startDownloadRequest();
} else {
onFail(false, 0);
}
}
}, null, null, 0, datacenterId, ConnectionsManager.ConnectionTypeGeneric, true);
}
} else {
if (response instanceof TLRPC.TL_upload_file) {
requestInfo.response = (TLRPC.TL_upload_file) response;
} else if (response instanceof TLRPC.TL_upload_webFile) {
requestInfo.responseWeb = (TLRPC.TL_upload_webFile) response;
if (totalBytesCount == 0 && requestInfo.responseWeb.size != 0) {
totalBytesCount = requestInfo.responseWeb.size;
}
} else {
requestInfo.responseCdn = (TLRPC.TL_upload_cdnFile) response;
}
if (response != null) {
if (currentType == ConnectionsManager.FileTypeAudio) {
StatsController.getInstance(currentAccount).incrementReceivedBytesCount(response.networkType, StatsController.TYPE_AUDIOS, response.getObjectSize() + 4);
} else if (currentType == ConnectionsManager.FileTypeVideo) {
StatsController.getInstance(currentAccount).incrementReceivedBytesCount(response.networkType, StatsController.TYPE_VIDEOS, response.getObjectSize() + 4);
} else if (currentType == ConnectionsManager.FileTypePhoto) {
StatsController.getInstance(currentAccount).incrementReceivedBytesCount(response.networkType, StatsController.TYPE_PHOTOS, response.getObjectSize() + 4);
} else if (currentType == ConnectionsManager.FileTypeFile) {
StatsController.getInstance(currentAccount).incrementReceivedBytesCount(response.networkType, StatsController.TYPE_FILES, response.getObjectSize() + 4);
}
}
processRequestResult(requestInfo, error);
}
}, null, null, flags, isCdn ? cdnDatacenterId : datacenterId, connectionType, isLast);
requestsCount++;
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class FeaturedStickerSetCell method setStickersSet.
public void setStickersSet(TLRPC.StickerSetCovered set, boolean divider, boolean unread) {
boolean sameSet = set == stickersSet && wasLayout;
needDivider = divider;
stickersSet = set;
setWillNotDraw(!needDivider);
textView.setText(stickersSet.set.title);
if (unread) {
Drawable drawable = new Drawable() {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
@Override
public void draw(Canvas canvas) {
paint.setColor(0xff44a8ea);
canvas.drawCircle(AndroidUtilities.dp(4), AndroidUtilities.dp(5), AndroidUtilities.dp(3), paint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSPARENT;
}
@Override
public int getIntrinsicWidth() {
return AndroidUtilities.dp(12);
}
@Override
public int getIntrinsicHeight() {
return AndroidUtilities.dp(8);
}
};
textView.setCompoundDrawablesWithIntrinsicBounds(LocaleController.isRTL ? null : drawable, null, LocaleController.isRTL ? drawable : null, null);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
valueTextView.setText(LocaleController.formatPluralString("Stickers", set.set.count));
TLRPC.Document sticker;
if (set.cover != null) {
sticker = set.cover;
} else if (!set.covers.isEmpty()) {
sticker = set.covers.get(0);
} else {
sticker = null;
}
if (sticker != null) {
TLObject object = FileLoader.getClosestPhotoSizeWithSize(set.set.thumbs, 90);
if (object == null) {
object = sticker;
}
SvgHelper.SvgDrawable svgThumb = DocumentObject.getSvgThumb(set.set.thumbs, Theme.key_windowBackgroundGray, 1.0f);
ImageLocation imageLocation;
if (object instanceof TLRPC.Document) {
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(sticker.thumbs, 90);
imageLocation = ImageLocation.getForDocument(thumb, sticker);
} else {
TLRPC.PhotoSize thumb = (TLRPC.PhotoSize) object;
imageLocation = ImageLocation.getForSticker(thumb, sticker, set.set.thumb_version);
}
if (object instanceof TLRPC.Document && MessageObject.isAnimatedStickerDocument(sticker, true)) {
if (svgThumb != null) {
imageView.setImage(ImageLocation.getForDocument(sticker), "50_50", svgThumb, 0, set);
} else {
imageView.setImage(ImageLocation.getForDocument(sticker), "50_50", imageLocation, null, 0, set);
}
} else if (imageLocation != null && imageLocation.imageType == FileLoader.IMAGE_TYPE_LOTTIE) {
imageView.setImage(imageLocation, "50_50", "tgs", svgThumb, set);
} else {
imageView.setImage(imageLocation, "50_50", "webp", svgThumb, set);
}
} else {
imageView.setImage(null, null, "webp", null, set);
}
if (sameSet) {
boolean wasInstalled = isInstalled;
if (isInstalled = MediaDataController.getInstance(currentAccount).isStickerPackInstalled(set.set.id)) {
if (!wasInstalled) {
checkImage.setVisibility(VISIBLE);
addButton.setClickable(false);
if (currentAnimation != null) {
currentAnimation.cancel();
}
currentAnimation = new AnimatorSet();
currentAnimation.setDuration(200);
currentAnimation.playTogether(ObjectAnimator.ofFloat(addButton, "alpha", 1.0f, 0.0f), ObjectAnimator.ofFloat(addButton, "scaleX", 1.0f, 0.01f), ObjectAnimator.ofFloat(addButton, "scaleY", 1.0f, 0.01f), ObjectAnimator.ofFloat(checkImage, "alpha", 0.0f, 1.0f), ObjectAnimator.ofFloat(checkImage, "scaleX", 0.01f, 1.0f), ObjectAnimator.ofFloat(checkImage, "scaleY", 0.01f, 1.0f));
currentAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
if (currentAnimation != null && currentAnimation.equals(animator)) {
addButton.setVisibility(INVISIBLE);
}
}
@Override
public void onAnimationCancel(Animator animator) {
if (currentAnimation != null && currentAnimation.equals(animator)) {
currentAnimation = null;
}
}
});
currentAnimation.start();
}
} else {
if (wasInstalled) {
addButton.setVisibility(VISIBLE);
addButton.setClickable(true);
if (currentAnimation != null) {
currentAnimation.cancel();
}
currentAnimation = new AnimatorSet();
currentAnimation.setDuration(200);
currentAnimation.playTogether(ObjectAnimator.ofFloat(checkImage, "alpha", 1.0f, 0.0f), ObjectAnimator.ofFloat(checkImage, "scaleX", 1.0f, 0.01f), ObjectAnimator.ofFloat(checkImage, "scaleY", 1.0f, 0.01f), ObjectAnimator.ofFloat(addButton, "alpha", 0.0f, 1.0f), ObjectAnimator.ofFloat(addButton, "scaleX", 0.01f, 1.0f), ObjectAnimator.ofFloat(addButton, "scaleY", 0.01f, 1.0f));
currentAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
if (currentAnimation != null && currentAnimation.equals(animator)) {
checkImage.setVisibility(INVISIBLE);
}
}
@Override
public void onAnimationCancel(Animator animator) {
if (currentAnimation != null && currentAnimation.equals(animator)) {
currentAnimation = null;
}
}
});
currentAnimation.start();
}
}
} else {
if (currentAnimation != null) {
currentAnimation.cancel();
}
if (isInstalled = MediaDataController.getInstance(currentAccount).isStickerPackInstalled(set.set.id)) {
addButton.setVisibility(INVISIBLE);
addButton.setClickable(false);
checkImage.setVisibility(VISIBLE);
checkImage.setScaleX(1.0f);
checkImage.setScaleY(1.0f);
checkImage.setAlpha(1.0f);
} else {
addButton.setVisibility(VISIBLE);
addButton.setClickable(true);
checkImage.setVisibility(INVISIBLE);
addButton.setScaleX(1.0f);
addButton.setScaleY(1.0f);
addButton.setAlpha(1.0f);
}
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class FeaturedStickerSetCell2 method setStickersSet.
public void setStickersSet(TLRPC.StickerSetCovered set, boolean divider, boolean unread, boolean forceInstalled, boolean animated) {
if (currentAnimation != null) {
currentAnimation.cancel();
currentAnimation = null;
}
needDivider = divider;
stickersSet = set;
setWillNotDraw(!needDivider);
textView.setText(stickersSet.set.title);
if (unread) {
Drawable drawable = new Drawable() {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
@Override
public void draw(Canvas canvas) {
paint.setColor(0xff44a8ea);
canvas.drawCircle(AndroidUtilities.dp(4), AndroidUtilities.dp(5), AndroidUtilities.dp(3), paint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSPARENT;
}
@Override
public int getIntrinsicWidth() {
return AndroidUtilities.dp(12);
}
@Override
public int getIntrinsicHeight() {
return AndroidUtilities.dp(8);
}
};
textView.setCompoundDrawablesWithIntrinsicBounds(LocaleController.isRTL ? null : drawable, null, LocaleController.isRTL ? drawable : null, null);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
valueTextView.setText(LocaleController.formatPluralString("Stickers", set.set.count));
TLRPC.Document sticker;
if (set.cover != null) {
sticker = set.cover;
} else if (!set.covers.isEmpty()) {
sticker = set.covers.get(0);
} else {
sticker = null;
}
if (sticker != null) {
if (MessageObject.canAutoplayAnimatedSticker(sticker)) {
TLObject object = FileLoader.getClosestPhotoSizeWithSize(set.set.thumbs, 90);
if (object == null) {
object = sticker;
}
SvgHelper.SvgDrawable svgThumb = DocumentObject.getSvgThumb(set.set.thumbs, Theme.key_windowBackgroundGray, 1.0f);
ImageLocation imageLocation;
if (object instanceof TLRPC.Document) {
// first sticker in set as a thumb
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(sticker.thumbs, 90);
imageLocation = ImageLocation.getForDocument(thumb, sticker);
} else {
// unique thumb
TLRPC.PhotoSize thumb = (TLRPC.PhotoSize) object;
imageLocation = ImageLocation.getForSticker(thumb, sticker, set.set.thumb_version);
}
if (object instanceof TLRPC.Document && MessageObject.isAnimatedStickerDocument(sticker, true)) {
if (svgThumb != null) {
imageView.setImage(ImageLocation.getForDocument(sticker), "50_50", svgThumb, 0, set);
} else {
imageView.setImage(ImageLocation.getForDocument(sticker), "50_50", imageLocation, null, 0, set);
}
} else if (imageLocation != null && imageLocation.imageType == FileLoader.IMAGE_TYPE_LOTTIE) {
imageView.setImage(imageLocation, "50_50", "tgs", svgThumb, set);
} else {
imageView.setImage(imageLocation, "50_50", "webp", svgThumb, set);
}
} else {
final TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(sticker.thumbs, 90);
if (thumb != null) {
imageView.setImage(ImageLocation.getForDocument(thumb, sticker), "50_50", "webp", null, set);
} else {
imageView.setImage(ImageLocation.getForDocument(sticker), "50_50", "webp", null, set);
}
}
} else {
imageView.setImage(null, null, "webp", null, set);
}
addButton.setVisibility(VISIBLE);
isInstalled = forceInstalled || MediaDataController.getInstance(currentAccount).isStickerPackInstalled(set.set.id);
if (animated) {
if (isInstalled) {
delButton.setVisibility(VISIBLE);
} else {
addButton.setVisibility(VISIBLE);
}
currentAnimation = new AnimatorSet();
currentAnimation.setDuration(250);
currentAnimation.playTogether(ObjectAnimator.ofFloat(delButton, View.ALPHA, isInstalled ? 1.0f : 0.0f), ObjectAnimator.ofFloat(delButton, View.SCALE_X, isInstalled ? 1.0f : 0.0f), ObjectAnimator.ofFloat(delButton, View.SCALE_Y, isInstalled ? 1.0f : 0.0f), ObjectAnimator.ofFloat(addButton, View.ALPHA, isInstalled ? 0.0f : 1.0f), ObjectAnimator.ofFloat(addButton, View.SCALE_X, isInstalled ? 0.0f : 1.0f), ObjectAnimator.ofFloat(addButton, View.SCALE_Y, isInstalled ? 0.0f : 1.0f));
currentAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (isInstalled) {
addButton.setVisibility(INVISIBLE);
} else {
delButton.setVisibility(INVISIBLE);
}
}
});
currentAnimation.setInterpolator(new OvershootInterpolator(1.02f));
currentAnimation.start();
} else {
if (isInstalled) {
delButton.setVisibility(VISIBLE);
delButton.setAlpha(1.0f);
delButton.setScaleX(1.0f);
delButton.setScaleY(1.0f);
addButton.setVisibility(INVISIBLE);
addButton.setAlpha(0.0f);
addButton.setScaleX(0.0f);
addButton.setScaleY(0.0f);
} else {
addButton.setVisibility(VISIBLE);
addButton.setAlpha(1.0f);
addButton.setScaleX(1.0f);
addButton.setScaleY(1.0f);
delButton.setVisibility(INVISIBLE);
delButton.setAlpha(0.0f);
delButton.setScaleX(0.0f);
delButton.setScaleY(0.0f);
}
}
}
Aggregations