use of org.telegram.messenger.MediaDataController in project Telegram-FOSS by Telegram-FOSS-Team.
the class EmojiView method updateStickerTabs.
private void updateStickerTabs() {
if (stickersTab == null || stickersTab.isDragging()) {
return;
}
recentTabBum = -2;
favTabBum = -2;
trendingTabNum = -2;
hasChatStickers = false;
stickersTabOffset = 0;
int lastPosition = stickersTab.getCurrentPosition();
stickersTab.beginUpdate(getParent() != null && getVisibility() == VISIBLE && (installingStickerSets.size() != 0 || removingStickerSets.size() != 0));
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
SharedPreferences preferences = MessagesController.getEmojiSettings(currentAccount);
featuredStickerSets.clear();
ArrayList<TLRPC.StickerSetCovered> featured = mediaDataController.getFeaturedStickerSets();
for (int a = 0, N = featured.size(); a < N; a++) {
TLRPC.StickerSetCovered set = featured.get(a);
if (mediaDataController.isStickerPackInstalled(set.set.id)) {
continue;
}
featuredStickerSets.add(set);
}
if (trendingAdapter != null) {
trendingAdapter.notifyDataSetChanged();
}
if (!featured.isEmpty() && (featuredStickerSets.isEmpty() || preferences.getLong("featured_hidden", 0) == featured.get(0).set.id)) {
final int id = mediaDataController.getUnreadStickerSets().isEmpty() ? 2 : 3;
final StickerTabView trendingStickersTabView = stickersTab.addStickerIconTab(id, stickerIcons[id]);
trendingStickersTabView.textView.setText(LocaleController.getString("FeaturedStickersShort", R.string.FeaturedStickersShort));
trendingStickersTabView.setContentDescription(LocaleController.getString("FeaturedStickers", R.string.FeaturedStickers));
trendingTabNum = stickersTabOffset;
stickersTabOffset++;
}
if (!favouriteStickers.isEmpty()) {
favTabBum = stickersTabOffset;
stickersTabOffset++;
StickerTabView stickerTabView = stickersTab.addStickerIconTab(1, stickerIcons[1]);
stickerTabView.textView.setText(LocaleController.getString("FavoriteStickersShort", R.string.FavoriteStickersShort));
stickerTabView.setContentDescription(LocaleController.getString("FavoriteStickers", R.string.FavoriteStickers));
}
if (!recentStickers.isEmpty()) {
recentTabBum = stickersTabOffset;
stickersTabOffset++;
StickerTabView stickerTabView = stickersTab.addStickerIconTab(0, stickerIcons[0]);
stickerTabView.textView.setText(LocaleController.getString("RecentStickersShort", R.string.RecentStickersShort));
stickerTabView.setContentDescription(LocaleController.getString("RecentStickers", R.string.RecentStickers));
}
stickerSets.clear();
groupStickerSet = null;
groupStickerPackPosition = -1;
groupStickerPackNum = -10;
ArrayList<TLRPC.TL_messages_stickerSet> packs = mediaDataController.getStickerSets(MediaDataController.TYPE_IMAGE);
for (int i = 0; i < primaryInstallingStickerSets.length; i++) {
final TLRPC.StickerSetCovered installingStickerSet = primaryInstallingStickerSets[i];
if (installingStickerSet != null) {
final TLRPC.TL_messages_stickerSet pack = mediaDataController.getStickerSetById(installingStickerSet.set.id);
if (pack != null && !pack.set.archived) {
primaryInstallingStickerSets[i] = null;
} else {
final TLRPC.TL_messages_stickerSet set = new TLRPC.TL_messages_stickerSet();
set.set = installingStickerSet.set;
if (installingStickerSet.cover != null) {
set.documents.add(installingStickerSet.cover);
} else if (!installingStickerSet.covers.isEmpty()) {
set.documents.addAll(installingStickerSet.covers);
}
if (!set.documents.isEmpty()) {
stickerSets.add(set);
}
}
}
}
for (int a = 0; a < packs.size(); a++) {
TLRPC.TL_messages_stickerSet pack = packs.get(a);
if (pack.set.archived || pack.documents == null || pack.documents.isEmpty()) {
continue;
}
stickerSets.add(pack);
}
if (info != null) {
long hiddenStickerSetId = MessagesController.getEmojiSettings(currentAccount).getLong("group_hide_stickers_" + info.id, -1);
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(info.id);
if (chat == null || info.stickerset == null || !ChatObject.hasAdminRights(chat)) {
groupStickersHidden = hiddenStickerSetId != -1;
} else if (info.stickerset != null) {
groupStickersHidden = hiddenStickerSetId == info.stickerset.id;
}
if (info.stickerset != null) {
TLRPC.TL_messages_stickerSet pack = mediaDataController.getGroupStickerSetById(info.stickerset);
if (pack != null && pack.documents != null && !pack.documents.isEmpty() && pack.set != null) {
TLRPC.TL_messages_stickerSet set = new TLRPC.TL_messages_stickerSet();
set.documents = pack.documents;
set.packs = pack.packs;
set.set = pack.set;
if (groupStickersHidden) {
groupStickerPackNum = stickerSets.size();
stickerSets.add(set);
} else {
groupStickerPackNum = 0;
stickerSets.add(0, set);
}
groupStickerSet = info.can_set_stickers ? set : null;
}
} else if (info.can_set_stickers) {
TLRPC.TL_messages_stickerSet pack = new TLRPC.TL_messages_stickerSet();
if (groupStickersHidden) {
groupStickerPackNum = stickerSets.size();
stickerSets.add(pack);
} else {
groupStickerPackNum = 0;
stickerSets.add(0, pack);
}
}
}
for (int a = 0; a < stickerSets.size(); a++) {
if (a == groupStickerPackNum) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(info.id);
if (chat == null) {
stickerSets.remove(0);
a--;
} else {
hasChatStickers = true;
stickersTab.addStickerTab(chat);
}
} else {
TLRPC.TL_messages_stickerSet stickerSet = stickerSets.get(a);
TLRPC.Document document = stickerSet.documents.get(0);
TLObject thumb = FileLoader.getClosestPhotoSizeWithSize(stickerSet.set.thumbs, 90);
if (thumb == null || stickerSet.set.gifs) {
thumb = document;
}
stickersTab.addStickerTab(thumb, document, stickerSet).setContentDescription(stickerSet.set.title + ", " + LocaleController.getString("AccDescrStickerSet", R.string.AccDescrStickerSet));
}
}
stickersTab.commitUpdate();
stickersTab.updateTabStyles();
if (lastPosition != 0) {
stickersTab.onPageScrolled(lastPosition, lastPosition);
}
checkPanels();
}
use of org.telegram.messenger.MediaDataController in project Telegram-FOSS by Telegram-FOSS-Team.
the class StickersActivity method updateRows.
private void updateRows() {
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
final List<TLRPC.TL_messages_stickerSet> newList = mediaDataController.getStickerSets(currentType);
DiffUtil.DiffResult diffResult = null;
if (listAdapter != null) {
if (!isPaused) {
diffResult = DiffUtil.calculateDiff(new DiffUtil.Callback() {
final List<TLRPC.TL_messages_stickerSet> oldList = listAdapter.stickerSets;
@Override
public int getOldListSize() {
return oldList.size();
}
@Override
public int getNewListSize() {
return newList.size();
}
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return oldList.get(oldItemPosition).set.id == newList.get(newItemPosition).set.id;
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
final TLRPC.StickerSet oldSet = oldList.get(oldItemPosition).set;
final TLRPC.StickerSet newSet = newList.get(newItemPosition).set;
return TextUtils.equals(oldSet.title, newSet.title) && oldSet.count == newSet.count;
}
});
}
listAdapter.setStickerSets(newList);
}
rowCount = 0;
if (currentType == MediaDataController.TYPE_IMAGE) {
suggestRow = rowCount++;
loopRow = rowCount++;
loopInfoRow = rowCount++;
featuredRow = rowCount++;
} else {
suggestRow = -1;
loopRow = -1;
loopInfoRow = -1;
featuredRow = -1;
}
if (mediaDataController.getArchivedStickersCount(currentType) != 0) {
final boolean inserted = archivedRow == -1;
archivedRow = rowCount++;
archivedInfoRow = currentType == MediaDataController.TYPE_MASK ? rowCount++ : -1;
if (listAdapter != null && inserted) {
listAdapter.notifyItemRangeInserted(archivedRow, archivedInfoRow != -1 ? 2 : 1);
}
} else {
final int oldArchivedRow = archivedRow;
final int oldArchivedInfoRow = archivedInfoRow;
archivedRow = -1;
archivedInfoRow = -1;
if (listAdapter != null && oldArchivedRow != -1) {
listAdapter.notifyItemRangeRemoved(oldArchivedRow, oldArchivedInfoRow != -1 ? 2 : 1);
}
}
if (currentType == MediaDataController.TYPE_IMAGE) {
masksRow = rowCount++;
stickersBotInfo = rowCount++;
} else {
masksRow = -1;
stickersBotInfo = -1;
}
final int stickerSetsCount = newList.size();
if (stickerSetsCount > 0) {
stickersStartRow = rowCount;
rowCount += stickerSetsCount;
stickersEndRow = rowCount;
if (currentType != MediaDataController.TYPE_MASK) {
stickersShadowRow = rowCount++;
masksInfoRow = -1;
} else {
masksInfoRow = rowCount++;
stickersShadowRow = -1;
}
} else {
stickersStartRow = -1;
stickersEndRow = -1;
stickersShadowRow = -1;
masksInfoRow = -1;
}
if (listAdapter != null) {
if (diffResult != null) {
final int startRow = stickersStartRow >= 0 ? stickersStartRow : rowCount;
listAdapter.notifyItemRangeChanged(0, startRow);
diffResult.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
public void onInserted(int position, int count) {
listAdapter.notifyItemRangeInserted(startRow + position, count);
}
@Override
public void onRemoved(int position, int count) {
listAdapter.notifyItemRangeRemoved(startRow + position, count);
}
@Override
public void onMoved(int fromPosition, int toPosition) {
}
@Override
public void onChanged(int position, int count, @Nullable Object payload) {
listAdapter.notifyItemRangeChanged(startRow + position, count);
}
});
}
}
}
use of org.telegram.messenger.MediaDataController in project Telegram-FOSS by Telegram-FOSS-Team.
the class StickersSearchAdapter method bindFeaturedStickerSetInfoCell.
private void bindFeaturedStickerSetInfoCell(FeaturedStickerSetInfoCell cell, int position, boolean animated) {
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
ArrayList<Long> unreadStickers = mediaDataController.getUnreadStickerSets();
TLRPC.StickerSetCovered stickerSetCovered = (TLRPC.StickerSetCovered) cache.get(position);
boolean unread = unreadStickers != null && unreadStickers.contains(stickerSetCovered.set.id);
boolean forceInstalled = false;
for (int i = 0; i < primaryInstallingStickerSets.length; i++) {
if (primaryInstallingStickerSets[i] != null) {
final TLRPC.TL_messages_stickerSet s = MediaDataController.getInstance(currentAccount).getStickerSetById(primaryInstallingStickerSets[i].set.id);
if (s != null && !s.set.archived) {
primaryInstallingStickerSets[i] = null;
continue;
}
if (primaryInstallingStickerSets[i].set.id == stickerSetCovered.set.id) {
forceInstalled = true;
break;
}
}
}
int idx = TextUtils.isEmpty(searchQuery) ? -1 : AndroidUtilities.indexOfIgnoreCase(stickerSetCovered.set.title, searchQuery);
if (idx >= 0) {
cell.setStickerSet(stickerSetCovered, unread, animated, idx, searchQuery.length(), forceInstalled);
} else {
cell.setStickerSet(stickerSetCovered, unread, animated, 0, 0, forceInstalled);
if (!TextUtils.isEmpty(searchQuery) && AndroidUtilities.indexOfIgnoreCase(stickerSetCovered.set.short_name, searchQuery) == 0) {
cell.setUrl(stickerSetCovered.set.short_name, searchQuery.length());
}
}
if (unread) {
mediaDataController.markFaturedStickersByIdAsRead(stickerSetCovered.set.id);
}
boolean installing = installingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
boolean removing = removingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
if (installing || removing) {
if (installing && cell.isInstalled()) {
installingStickerSets.remove(stickerSetCovered.set.id);
installing = false;
} else if (removing && !cell.isInstalled()) {
removingStickerSets.remove(stickerSetCovered.set.id);
}
}
cell.setAddDrawProgress(!forceInstalled && installing, animated);
mediaDataController.preloadStickerSetThumb(stickerSetCovered);
cell.setNeedDivider(position > 0);
}
use of org.telegram.messenger.MediaDataController in project Telegram-FOSS by Telegram-FOSS-Team.
the class StickersAlert method loadStickerSet.
private void loadStickerSet() {
if (inputStickerSet != null) {
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
if (stickerSet == null && inputStickerSet.short_name != null) {
stickerSet = mediaDataController.getStickerSetByName(inputStickerSet.short_name);
}
if (stickerSet == null) {
stickerSet = mediaDataController.getStickerSetById(inputStickerSet.id);
}
if (stickerSet == null) {
TLRPC.TL_messages_getStickerSet req = new TLRPC.TL_messages_getStickerSet();
req.stickerset = inputStickerSet;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
reqId = 0;
if (error == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Transition addTarget = new Transition() {
@Override
public void captureStartValues(TransitionValues transitionValues) {
transitionValues.values.put("start", true);
transitionValues.values.put("offset", containerView.getTop() + scrollOffsetY);
}
@Override
public void captureEndValues(TransitionValues transitionValues) {
transitionValues.values.put("start", false);
transitionValues.values.put("offset", containerView.getTop() + scrollOffsetY);
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
int scrollOffsetY = StickersAlert.this.scrollOffsetY;
int startValue = (int) startValues.values.get("offset") - (int) endValues.values.get("offset");
final ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setDuration(250);
animator.addUpdateListener(a -> {
float fraction = a.getAnimatedFraction();
gridView.setAlpha(fraction);
titleTextView.setAlpha(fraction);
if (startValue != 0) {
int value = (int) (startValue * (1f - fraction));
setScrollOffsetY(scrollOffsetY + value);
gridView.setTranslationY(value);
}
});
return animator;
}
};
addTarget.addTarget(containerView);
TransitionManager.beginDelayedTransition(container, addTarget);
}
optionsButton.setVisibility(View.VISIBLE);
stickerSet = (TLRPC.TL_messages_stickerSet) response;
showEmoji = !stickerSet.set.masks;
mediaDataController.preloadStickerSetThumb(stickerSet);
updateSendButton();
updateFields();
adapter.notifyDataSetChanged();
} else {
Toast.makeText(getContext(), LocaleController.getString("AddStickersNotFound", R.string.AddStickersNotFound), Toast.LENGTH_SHORT).show();
dismiss();
}
}));
} else {
if (adapter != null) {
updateSendButton();
updateFields();
adapter.notifyDataSetChanged();
}
mediaDataController.preloadStickerSetThumb(stickerSet);
}
}
if (stickerSet != null) {
showEmoji = !stickerSet.set.masks;
}
}
Aggregations