Search in sources :

Example 1 with MediaDataController

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();
}
Also used : SharedPreferences(android.content.SharedPreferences) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) MediaDataController(org.telegram.messenger.MediaDataController) TLObject(org.telegram.tgnet.TLObject)

Example 2 with MediaDataController

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);
                }
            });
        }
    }
}
Also used : ListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback) TLRPC(org.telegram.tgnet.TLRPC) SuppressLint(android.annotation.SuppressLint) MediaDataController(org.telegram.messenger.MediaDataController) ListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback) DiffUtil(androidx.recyclerview.widget.DiffUtil) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with MediaDataController

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);
}
Also used : TLRPC(org.telegram.tgnet.TLRPC) MediaDataController(org.telegram.messenger.MediaDataController)

Example 4 with MediaDataController

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;
    }
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Spannable(android.text.Spannable) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) LinkMovementMethod(android.text.method.LinkMovementMethod) TransitionManager(android.transition.TransitionManager) Drawable(android.graphics.drawable.Drawable) Selection(android.text.Selection) Matcher(java.util.regex.Matcher) MediaController(org.telegram.messenger.MediaController) View(android.view.View) Transition(android.transition.Transition) Emoji(org.telegram.messenger.Emoji) FileRefController(org.telegram.messenger.FileRefController) RecyclerView(androidx.recyclerview.widget.RecyclerView) Utilities(org.telegram.messenger.Utilities) ObjectAnimator(android.animation.ObjectAnimator) ImageLocation(org.telegram.messenger.ImageLocation) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) SparseArray(android.util.SparseArray) HapticFeedbackConstants(android.view.HapticFeedbackConstants) List(java.util.List) TextView(android.widget.TextView) Pattern(java.util.regex.Pattern) EditorInfo(android.view.inputmethod.EditorInfo) EmptyCell(org.telegram.ui.Cells.EmptyCell) TextWatcher(android.text.TextWatcher) FileLoader(org.telegram.messenger.FileLoader) ChatActivity(org.telegram.ui.ChatActivity) Context(android.content.Context) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) FeaturedStickerSetInfoCell(org.telegram.ui.Cells.FeaturedStickerSetInfoCell) Theme(org.telegram.ui.ActionBar.Theme) RequestDelegate(org.telegram.tgnet.RequestDelegate) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) SpannableStringBuilder(android.text.SpannableStringBuilder) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) TransitionValues(android.transition.TransitionValues) Toast(android.widget.Toast) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) StickerEmojiCell(org.telegram.ui.Cells.StickerEmojiCell) Parcelable(android.os.Parcelable) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) ContentPreviewViewer(org.telegram.ui.ContentPreviewViewer) TextUtils(android.text.TextUtils) FileLog(org.telegram.messenger.FileLog) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) android.graphics(android.graphics) TypedValue(android.util.TypedValue) Activity(android.app.Activity) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ValueAnimator(android.animation.ValueAnimator) TransitionValues(android.transition.TransitionValues) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ViewGroup(android.view.ViewGroup) Transition(android.transition.Transition) ValueAnimator(android.animation.ValueAnimator) TLRPC(org.telegram.tgnet.TLRPC) MediaDataController(org.telegram.messenger.MediaDataController)

Aggregations

MediaDataController (org.telegram.messenger.MediaDataController)4 TLRPC (org.telegram.tgnet.TLRPC)4 SuppressLint (android.annotation.SuppressLint)3 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Activity (android.app.Activity)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 android.graphics (android.graphics)1 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Parcelable (android.os.Parcelable)1 Editable (android.text.Editable)1 InputType (android.text.InputType)1