use of org.telegram.ui.Cells.SharedAudioCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlertAudioLayout method onItemClick.
private void onItemClick(View view) {
if (!(view instanceof SharedAudioCell)) {
return;
}
SharedAudioCell audioCell = (SharedAudioCell) view;
MediaController.AudioEntry audioEntry = (MediaController.AudioEntry) audioCell.getTag();
boolean add;
if (selectedAudios.indexOfKey(audioEntry.id) >= 0) {
selectedAudios.remove(audioEntry.id);
selectedAudiosOrder.remove(audioEntry);
audioCell.setChecked(false, true);
add = false;
} else {
if (maxSelectedFiles >= 0 && selectedAudios.size() >= maxSelectedFiles) {
showErrorBox(LocaleController.formatString("PassportUploadMaxReached", R.string.PassportUploadMaxReached, LocaleController.formatPluralString("Files", maxSelectedFiles)));
return;
}
selectedAudios.put(audioEntry.id, audioEntry);
selectedAudiosOrder.add(audioEntry);
audioCell.setChecked(true, true);
add = true;
}
parentAlert.updateCountButton(add ? 1 : 2);
}
use of org.telegram.ui.Cells.SharedAudioCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlertAudioLayout method didReceivedNotification.
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged) {
if (id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.messagePlayingPlayStateChanged) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
if (view instanceof SharedAudioCell) {
SharedAudioCell cell = (SharedAudioCell) view;
MessageObject messageObject = cell.getMessage();
if (messageObject != null) {
cell.updateButtonState(false, true);
}
}
}
} else if (id == NotificationCenter.messagePlayingDidStart) {
MessageObject messageObject = (MessageObject) args[0];
if (messageObject.eventId != 0) {
return;
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
if (view instanceof SharedAudioCell) {
SharedAudioCell cell = (SharedAudioCell) view;
MessageObject messageObject1 = cell.getMessage();
if (messageObject1 != null) {
cell.updateButtonState(false, true);
}
}
}
}
}
}
use of org.telegram.ui.Cells.SharedAudioCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class SharedMediaLayout method didReceivedNotification.
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.mediaDidLoad) {
long uid = (Long) args[0];
int guid = (Integer) args[3];
int requestIndex = (Integer) args[7];
int type = (Integer) args[4];
boolean fromStart = (boolean) args[6];
if (type == 6 || type == 7) {
type = 0;
}
if (guid == profileActivity.getClassGuid() && requestIndex == sharedMediaData[type].requestIndex) {
if (type != 0 && type != 1 && type != 2 && type != 4) {
sharedMediaData[type].totalCount = (Integer) args[1];
}
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[2];
boolean enc = DialogObject.isEncryptedDialog(dialog_id);
int loadIndex = uid == dialog_id ? 0 : 1;
RecyclerListView.Adapter adapter = null;
if (type == 0) {
adapter = photoVideoAdapter;
} else if (type == 1) {
adapter = documentsAdapter;
} else if (type == 2) {
adapter = voiceAdapter;
} else if (type == 3) {
adapter = linksAdapter;
} else if (type == 4) {
adapter = audioAdapter;
} else if (type == 5) {
adapter = gifAdapter;
}
int oldItemCount;
int oldMessagesCount = sharedMediaData[type].messages.size();
if (adapter != null) {
oldItemCount = adapter.getItemCount();
if (adapter instanceof RecyclerListView.SectionsAdapter) {
RecyclerListView.SectionsAdapter sectionsAdapter = (RecyclerListView.SectionsAdapter) adapter;
sectionsAdapter.notifySectionsChanged();
}
} else {
oldItemCount = 0;
}
sharedMediaData[type].loading = false;
SparseBooleanArray addedMesages = new SparseBooleanArray();
if (fromStart) {
for (int a = arr.size() - 1; a >= 0; a--) {
MessageObject message = arr.get(a);
boolean added = sharedMediaData[type].addMessage(message, loadIndex, true, enc);
if (added) {
addedMesages.put(message.getId(), true);
sharedMediaData[type].startOffset--;
if (sharedMediaData[type].startOffset < 0) {
sharedMediaData[type].startOffset = 0;
}
}
}
sharedMediaData[type].startReached = (Boolean) args[5];
if (sharedMediaData[type].startReached) {
sharedMediaData[type].startOffset = 0;
}
} else {
for (int a = 0; a < arr.size(); a++) {
MessageObject message = arr.get(a);
if (sharedMediaData[type].addMessage(message, loadIndex, false, enc)) {
addedMesages.put(message.getId(), true);
sharedMediaData[type].endLoadingStubs--;
if (sharedMediaData[type].endLoadingStubs < 0) {
sharedMediaData[type].endLoadingStubs = 0;
}
}
}
if (sharedMediaData[type].loadingAfterFastScroll && sharedMediaData[type].messages.size() > 0) {
sharedMediaData[type].min_id = sharedMediaData[type].messages.get(0).getId();
}
sharedMediaData[type].endReached[loadIndex] = (Boolean) args[5];
if (sharedMediaData[type].endReached[loadIndex]) {
sharedMediaData[type].totalCount = sharedMediaData[type].messages.size() + sharedMediaData[type].startOffset;
}
}
if (!fromStart && loadIndex == 0 && sharedMediaData[type].endReached[loadIndex] && mergeDialogId != 0) {
sharedMediaData[type].loading = true;
profileActivity.getMediaDataController().loadMedia(mergeDialogId, 50, sharedMediaData[type].max_id[1], 0, type, 1, profileActivity.getClassGuid(), sharedMediaData[type].requestIndex);
}
if (adapter != null) {
RecyclerListView listView = null;
for (int a = 0; a < mediaPages.length; a++) {
if (mediaPages[a].listView.getAdapter() == adapter) {
listView = mediaPages[a].listView;
mediaPages[a].listView.stopScroll();
}
}
int newItemCount = adapter.getItemCount();
if (adapter == photoVideoAdapter) {
if (photoVideoAdapter.getItemCount() == oldItemCount) {
AndroidUtilities.updateVisibleRows(listView);
} else {
photoVideoAdapter.notifyDataSetChanged();
}
} else {
adapter.notifyDataSetChanged();
}
if (sharedMediaData[type].messages.isEmpty() && !sharedMediaData[type].loading) {
if (listView != null) {
animateItemsEnter(listView, oldItemCount, addedMesages);
}
} else {
if (listView != null && (adapter == photoVideoAdapter || newItemCount >= oldItemCount)) {
animateItemsEnter(listView, oldItemCount, addedMesages);
}
}
if (listView != null && !sharedMediaData[type].loadingAfterFastScroll) {
if (oldMessagesCount == 0) {
for (int k = 0; k < 2; k++) {
if (mediaPages[k].selectedType == 0) {
int position = photoVideoAdapter.getPositionForIndex(0);
((LinearLayoutManager) listView.getLayoutManager()).scrollToPositionWithOffset(position, 0);
}
}
} else {
saveScrollPosition();
}
}
}
if (sharedMediaData[type].loadingAfterFastScroll) {
if (sharedMediaData[type].messages.size() == 0) {
loadFromStart(type);
} else {
sharedMediaData[type].loadingAfterFastScroll = false;
}
}
scrolling = true;
} else if (sharedMediaPreloader != null && sharedMediaData[type].messages.isEmpty() && !sharedMediaData[type].loadingAfterFastScroll) {
if (fillMediaData(type)) {
RecyclerListView.Adapter adapter = null;
if (type == 0) {
adapter = photoVideoAdapter;
} else if (type == 1) {
adapter = documentsAdapter;
} else if (type == 2) {
adapter = voiceAdapter;
} else if (type == 3) {
adapter = linksAdapter;
} else if (type == 4) {
adapter = audioAdapter;
} else if (type == 5) {
adapter = gifAdapter;
}
if (adapter != null) {
for (int a = 0; a < mediaPages.length; a++) {
if (mediaPages[a].listView.getAdapter() == adapter) {
mediaPages[a].listView.stopScroll();
}
}
adapter.notifyDataSetChanged();
}
scrolling = true;
}
}
} else if (id == NotificationCenter.messagesDeleted) {
boolean scheduled = (Boolean) args[2];
if (scheduled) {
return;
}
TLRPC.Chat currentChat = null;
if (DialogObject.isChatDialog(dialog_id)) {
currentChat = profileActivity.getMessagesController().getChat(-dialog_id);
}
long channelId = (Long) args[1];
int loadIndex = 0;
if (ChatObject.isChannel(currentChat)) {
if (channelId == 0 && mergeDialogId != 0) {
loadIndex = 1;
} else if (channelId == currentChat.id) {
loadIndex = 0;
} else {
return;
}
} else if (channelId != 0) {
return;
}
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>) args[0];
boolean updated = false;
int type = -1;
for (int a = 0, N = markAsDeletedMessages.size(); a < N; a++) {
for (int b = 0; b < sharedMediaData.length; b++) {
if (sharedMediaData[b].deleteMessage(markAsDeletedMessages.get(a), loadIndex) != null) {
type = b;
updated = true;
}
}
}
if (updated) {
scrolling = true;
if (photoVideoAdapter != null) {
photoVideoAdapter.notifyDataSetChanged();
}
if (documentsAdapter != null) {
documentsAdapter.notifyDataSetChanged();
}
if (voiceAdapter != null) {
voiceAdapter.notifyDataSetChanged();
}
if (linksAdapter != null) {
linksAdapter.notifyDataSetChanged();
}
if (audioAdapter != null) {
audioAdapter.notifyDataSetChanged();
}
if (gifAdapter != null) {
gifAdapter.notifyDataSetChanged();
}
if (type == 0 || type == 1 || type == 2 || type == 4) {
loadFastScrollData(true);
}
}
MediaPage mediaPage = getMediaPage(type);
} else if (id == NotificationCenter.didReceiveNewMessages) {
boolean scheduled = (Boolean) args[2];
if (scheduled) {
return;
}
long uid = (Long) args[0];
if (uid == dialog_id) {
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[1];
boolean enc = DialogObject.isEncryptedDialog(dialog_id);
boolean updated = false;
for (int a = 0; a < arr.size(); a++) {
MessageObject obj = arr.get(a);
if (obj.messageOwner.media == null || obj.needDrawBluredPreview()) {
continue;
}
int type = MediaDataController.getMediaType(obj.messageOwner);
if (type == -1) {
return;
}
if (sharedMediaData[type].startReached && sharedMediaData[type].addMessage(obj, obj.getDialogId() == dialog_id ? 0 : 1, true, enc)) {
updated = true;
hasMedia[type] = 1;
}
}
if (updated) {
scrolling = true;
for (int a = 0; a < mediaPages.length; a++) {
RecyclerListView.Adapter adapter = null;
if (mediaPages[a].selectedType == 0) {
adapter = photoVideoAdapter;
} else if (mediaPages[a].selectedType == 1) {
adapter = documentsAdapter;
} else if (mediaPages[a].selectedType == 2) {
adapter = voiceAdapter;
} else if (mediaPages[a].selectedType == 3) {
adapter = linksAdapter;
} else if (mediaPages[a].selectedType == 4) {
adapter = audioAdapter;
} else if (mediaPages[a].selectedType == 5) {
adapter = gifAdapter;
}
if (adapter != null) {
int count = adapter.getItemCount();
photoVideoAdapter.notifyDataSetChanged();
documentsAdapter.notifyDataSetChanged();
voiceAdapter.notifyDataSetChanged();
linksAdapter.notifyDataSetChanged();
audioAdapter.notifyDataSetChanged();
gifAdapter.notifyDataSetChanged();
}
}
updateTabs(true);
}
}
} else if (id == NotificationCenter.messageReceivedByServer) {
Boolean scheduled = (Boolean) args[6];
if (scheduled) {
return;
}
Integer msgId = (Integer) args[0];
Integer newMsgId = (Integer) args[1];
for (int a = 0; a < sharedMediaData.length; a++) {
sharedMediaData[a].replaceMid(msgId, newMsgId);
}
} else if (id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged || id == NotificationCenter.messagePlayingDidReset) {
if (id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.messagePlayingPlayStateChanged) {
for (int b = 0; b < mediaPages.length; b++) {
int count = mediaPages[b].listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = mediaPages[b].listView.getChildAt(a);
if (view instanceof SharedAudioCell) {
SharedAudioCell cell = (SharedAudioCell) view;
MessageObject messageObject = cell.getMessage();
if (messageObject != null) {
cell.updateButtonState(false, true);
}
}
}
}
} else {
MessageObject messageObject = (MessageObject) args[0];
if (messageObject.eventId != 0) {
return;
}
for (int b = 0; b < mediaPages.length; b++) {
int count = mediaPages[b].listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = mediaPages[b].listView.getChildAt(a);
if (view instanceof SharedAudioCell) {
SharedAudioCell cell = (SharedAudioCell) view;
MessageObject messageObject1 = cell.getMessage();
if (messageObject1 != null) {
cell.updateButtonState(false, true);
}
}
}
}
}
}
}
use of org.telegram.ui.Cells.SharedAudioCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class SharedMediaLayout method onItemClick.
private void onItemClick(int index, View view, MessageObject message, int a, int selectedMode) {
if (message == null || photoVideoChangeColumnsAnimation) {
return;
}
if (isActionModeShowed) {
int loadIndex = message.getDialogId() == dialog_id ? 0 : 1;
if (selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0) {
selectedFiles[loadIndex].remove(message.getId());
if (!message.canDeleteMessage(false, null)) {
cantDeleteMessagesCount--;
}
} else {
if (selectedFiles[0].size() + selectedFiles[1].size() >= 100) {
return;
}
selectedFiles[loadIndex].put(message.getId(), message);
if (!message.canDeleteMessage(false, null)) {
cantDeleteMessagesCount++;
}
}
if (selectedFiles[0].size() == 0 && selectedFiles[1].size() == 0) {
showActionMode(false);
} else {
selectedMessagesCountTextView.setNumber(selectedFiles[0].size() + selectedFiles[1].size(), true);
deleteItem.setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
if (gotoItem != null) {
gotoItem.setVisibility(selectedFiles[0].size() == 1 ? View.VISIBLE : View.GONE);
}
}
scrolling = false;
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
} else if (view instanceof SharedPhotoVideoCell) {
((SharedPhotoVideoCell) view).setChecked(a, selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
} else if (view instanceof SharedLinkCell) {
((SharedLinkCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
} else if (view instanceof SharedAudioCell) {
((SharedAudioCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
} else if (view instanceof ContextLinkCell) {
((ContextLinkCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
} else if (view instanceof SharedPhotoVideoCell2) {
((SharedPhotoVideoCell2) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
}
} else {
if (selectedMode == 0) {
int i = index - sharedMediaData[selectedMode].startOffset;
if (i >= 0 && i < sharedMediaData[selectedMode].messages.size()) {
PhotoViewer.getInstance().setParentActivity(profileActivity.getParentActivity());
PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, i, dialog_id, mergeDialogId, provider);
}
} else if (selectedMode == 2 || selectedMode == 4) {
if (view instanceof SharedAudioCell) {
((SharedAudioCell) view).didPressedButton();
}
} else if (selectedMode == 5) {
PhotoViewer.getInstance().setParentActivity(profileActivity.getParentActivity());
index = sharedMediaData[selectedMode].messages.indexOf(message);
if (index < 0) {
ArrayList<MessageObject> documents = new ArrayList<>();
documents.add(message);
PhotoViewer.getInstance().openPhoto(documents, 0, 0, 0, provider);
} else {
PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, index, dialog_id, mergeDialogId, provider);
}
} else if (selectedMode == 1) {
if (view instanceof SharedDocumentCell) {
SharedDocumentCell cell = (SharedDocumentCell) view;
TLRPC.Document document = message.getDocument();
if (cell.isLoaded()) {
if (message.canPreviewDocument()) {
PhotoViewer.getInstance().setParentActivity(profileActivity.getParentActivity());
index = sharedMediaData[selectedMode].messages.indexOf(message);
if (index < 0) {
ArrayList<MessageObject> documents = new ArrayList<>();
documents.add(message);
PhotoViewer.getInstance().openPhoto(documents, 0, 0, 0, provider);
} else {
PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, index, dialog_id, mergeDialogId, provider);
}
return;
}
AndroidUtilities.openDocument(message, profileActivity.getParentActivity(), profileActivity);
} else if (!cell.isLoading()) {
MessageObject messageObject = cell.getMessage();
profileActivity.getFileLoader().loadFile(document, messageObject, 0, 0);
cell.updateFileExistIcon(true);
} else {
profileActivity.getFileLoader().cancelLoadFile(document);
cell.updateFileExistIcon(true);
}
}
} else if (selectedMode == 3) {
try {
TLRPC.WebPage webPage = message.messageOwner.media != null ? message.messageOwner.media.webpage : null;
String link = null;
if (webPage != null && !(webPage instanceof TLRPC.TL_webPageEmpty)) {
if (webPage.cached_page != null) {
ArticleViewer.getInstance().setParentActivity(profileActivity.getParentActivity(), profileActivity);
ArticleViewer.getInstance().open(message);
return;
} else if (webPage.embed_url != null && webPage.embed_url.length() != 0) {
openWebView(webPage, message);
return;
} else {
link = webPage.url;
}
}
if (link == null) {
link = ((SharedLinkCell) view).getLink(0);
}
if (link != null) {
openUrl(link);
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
updateForwardItem();
}
use of org.telegram.ui.Cells.SharedAudioCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class SharedMediaLayout method onItemLongClick.
private boolean onItemLongClick(MessageObject item, View view, int a) {
if (isActionModeShowed || profileActivity.getParentActivity() == null || item == null) {
return false;
}
AndroidUtilities.hideKeyboard(profileActivity.getParentActivity().getCurrentFocus());
selectedFiles[item.getDialogId() == dialog_id ? 0 : 1].put(item.getId(), item);
if (!item.canDeleteMessage(false, null)) {
cantDeleteMessagesCount++;
}
deleteItem.setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
if (gotoItem != null) {
gotoItem.setVisibility(View.VISIBLE);
}
selectedMessagesCountTextView.setNumber(1, false);
AnimatorSet animatorSet = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
for (int i = 0; i < actionModeViews.size(); i++) {
View view2 = actionModeViews.get(i);
AndroidUtilities.clearDrawableAnimation(view2);
animators.add(ObjectAnimator.ofFloat(view2, View.SCALE_Y, 0.1f, 1.0f));
}
animatorSet.playTogether(animators);
animatorSet.setDuration(250);
animatorSet.start();
scrolling = false;
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(true, true);
} else if (view instanceof SharedPhotoVideoCell) {
((SharedPhotoVideoCell) view).setChecked(a, true, true);
} else if (view instanceof SharedLinkCell) {
((SharedLinkCell) view).setChecked(true, true);
} else if (view instanceof SharedAudioCell) {
((SharedAudioCell) view).setChecked(true, true);
} else if (view instanceof ContextLinkCell) {
((ContextLinkCell) view).setChecked(true, true);
} else if (view instanceof SharedPhotoVideoCell2) {
((SharedPhotoVideoCell2) view).setChecked(true, true);
}
if (!isActionModeShowed) {
showActionMode(true);
}
updateForwardItem();
return true;
}
Aggregations