Java Code Examples for org.telegram.tgnet.TLRPC#StickerSetCovered

The following examples show how to use org.telegram.tgnet.TLRPC#StickerSetCovered . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmojiView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getItemViewType(int position) {
    if (position == 0) {
        return 4;
    } else if (position == 1 && totalItems == 1) {
        return 5;
    }
    Object object = cache.get(position);
    if (object != null) {
        if (object instanceof TLRPC.Document) {
            return 0;
        } else if (object instanceof TLRPC.StickerSetCovered) {
            return 3;
        } else {
            return 2;
        }
    }
    return 1;
}
 
Example 2
Source File: ArchivedStickersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.needAddArchivedStickers) {
        final List<TLRPC.StickerSetCovered> newSets = new ArrayList<>((List<TLRPC.StickerSetCovered>) args[0]);
        for (int i = newSets.size() - 1; i >= 0; i--) {
            for (int j = 0, size2 = sets.size(); j < size2; j++) {
                if (sets.get(j).set.id == newSets.get(i).set.id) {
                    newSets.remove(i);
                    break;
                }
            }
        }
        if (!newSets.isEmpty()) {
            sets.addAll(0, newSets);
            updateRows();
            if (listAdapter != null) {
                listAdapter.notifyItemRangeInserted(stickersStartRow, newSets.size());
            }
        }
    } else if (id == NotificationCenter.stickersDidLoad) {
        if (listView != null) {
            for (int i = 0, size = listView.getChildCount(); i < size; i++) {
                final View view = listView.getChildAt(i);
                if (view instanceof ArchivedStickerSetCell) {
                    final ArchivedStickerSetCell cell = (ArchivedStickerSetCell) view;
                    final TLRPC.StickerSetCovered stickersSet = cell.getStickersSet();
                    if (stickersSet != null) {
                        final boolean isInstalled = MediaDataController.getInstance(currentAccount).isStickerPackInstalled(stickersSet.set.id);
                        if (isInstalled) {
                            installingStickerSets.remove(stickersSet.set.id);
                            cell.setDrawProgress(false, true);
                        }
                        cell.setChecked(isInstalled, true, false);
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: StickersAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (stickerSetCovereds != null) {
        switch (holder.getItemViewType()) {
            case 0:
                TLRPC.Document sticker = (TLRPC.Document) cache.get(position);
                ((StickerEmojiCell) holder.itemView).setSticker(sticker, positionsToSets.get(position), false);
                break;
            case 1:
                ((EmptyCell) holder.itemView).setHeight(AndroidUtilities.dp(82));
                break;
            case 2:
                TLRPC.StickerSetCovered stickerSetCovered = stickerSetCovereds.get((Integer) cache.get(position));
                FeaturedStickerSetInfoCell cell = (FeaturedStickerSetInfoCell) holder.itemView;
                cell.setStickerSet(stickerSetCovered, false);
                /*boolean installing = installingStickerSets.containsKey(stickerSetCovered.set.id);
                boolean removing = removingStickerSets.containsKey(stickerSetCovered.set.id);
                if (installing || removing) {
                    if (installing && cell.isInstalled()) {
                        installingStickerSets.remove(stickerSetCovered.set.id);
                        installing = false;
                    } else if (removing && !cell.isInstalled()) {
                        removingStickerSets.remove(stickerSetCovered.set.id);
                        removing = false;
                    }
                }
                cell.setDrawProgress(installing || removing);*/
                break;
        }
    } else {
        ((StickerEmojiCell) holder.itemView).setSticker(stickerSet.documents.get(position), stickerSet, showEmoji);
    }
}
 
Example 4
Source File: EmojiView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateVisibleTrendingSets() {
    if (trendingGridAdapter == null || trendingGridAdapter == null) {
        return;
    }
    try {
        int count = trendingGridView.getChildCount();
        for (int a = 0; a < count; a++) {
            View child = trendingGridView.getChildAt(a);
            if (child instanceof FeaturedStickerSetInfoCell) {
                RecyclerListView.Holder holder = (RecyclerListView.Holder) trendingGridView.getChildViewHolder(child);
                if (holder == null) {
                    continue;
                }
                FeaturedStickerSetInfoCell cell = (FeaturedStickerSetInfoCell) child;
                ArrayList<Long> unreadStickers = DataQuery.getInstance(currentAccount).getUnreadStickerSets();
                TLRPC.StickerSetCovered stickerSetCovered = cell.getStickerSet();
                boolean unread = unreadStickers != null && unreadStickers.contains(stickerSetCovered.set.id);
                cell.setStickerSet(stickerSetCovered, unread);
                if (unread) {
                    DataQuery.getInstance(currentAccount).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);
                        removing = false;
                    }
                }
                cell.setDrawProgress(installing || removing);
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 5
Source File: StickersSearchAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public StickersSearchAdapter(Context context, Delegate delegate, TLRPC.StickerSetCovered[] primaryInstallingStickerSets, LongSparseArray<TLRPC.StickerSetCovered> installingStickerSets, LongSparseArray<TLRPC.StickerSetCovered> removingStickerSets) {
    this.context = context;
    this.delegate = delegate;
    this.primaryInstallingStickerSets = primaryInstallingStickerSets;
    this.installingStickerSets = installingStickerSets;
    this.removingStickerSets = removingStickerSets;
}
 
Example 6
Source File: StickersSearchAdapter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void installStickerSet(TLRPC.InputStickerSet inputSet) {
    for (int i = 0; i < serverPacks.size(); i++) {
        final TLRPC.StickerSetCovered setCovered = serverPacks.get(i);
        if (setCovered.set.id == inputSet.id) {
            installStickerSet(setCovered, null);
            break;
        }
    }
}
 
Example 7
Source File: FeaturedStickerSetInfoCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void setStickerSet(TLRPC.StickerSetCovered stickerSet, boolean unread, int index, int searchLength) {
    lastUpdateTime = System.currentTimeMillis();
    if (searchLength != 0) {
        SpannableStringBuilder builder = new SpannableStringBuilder(stickerSet.set.title);
        try {
            builder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4)), index, index + searchLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } catch (Exception ignore) {

        }
        nameTextView.setText(builder);
    } else {
        nameTextView.setText(stickerSet.set.title);
    }
    infoTextView.setText(LocaleController.formatPluralString("Stickers", stickerSet.set.count));
    if (unread) {
        nameTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
    } else {
        nameTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
    if (hasOnClick) {
        addButton.setVisibility(VISIBLE);
        if (isInstalled = DataQuery.getInstance(currentAccount).isStickerPackInstalled(stickerSet.set.id)) {
            addButton.setBackgroundDrawable(delDrawable);
            addButton.setText(LocaleController.getString("StickersRemove", R.string.StickersRemove).toUpperCase());
        } else {
            addButton.setBackgroundDrawable(addDrawable);
            addButton.setText(LocaleController.getString("Add", R.string.Add).toUpperCase());
        }
        addButton.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(17), 0);
    } else {
        addButton.setVisibility(GONE);
    }

    set = stickerSet;
}
 
Example 8
Source File: FeaturedStickerSetInfoCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setStickerSet(TLRPC.StickerSetCovered stickerSet, boolean unread) {
    setStickerSet(stickerSet, unread, 0, 0);
}
 
Example 9
Source File: TrendingStickersLayout.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void refreshStickerSets() {
    int width = getMeasuredWidth();
    if (width != 0) {
        stickersPerRow = Math.max(5, width / AndroidUtilities.dp(72));
        if (layoutManager.getSpanCount() != stickersPerRow) {
            layoutManager.setSpanCount(stickersPerRow);
            loaded = false;
        }
    }
    if (loaded) {
        return;
    }
    cache.clear();
    positionsToSets.clear();
    sets.clear();
    totalItems = 0;
    int num = 0;

    final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
    ArrayList<TLRPC.StickerSetCovered> packs = new ArrayList<>(mediaDataController.getFeaturedStickerSets());
    final int otherStickersSectionPosition = packs.size();
    packs.addAll(otherPacks);

    for (int a = 0; a < packs.size(); a++) {
        TLRPC.StickerSetCovered pack = packs.get(a);
        if (pack.covers.isEmpty() && pack.cover == null) {
            continue;
        }

        if (a == otherStickersSectionPosition) {
            cache.put(totalItems++, ITEM_SECTION);
        }

        sets.add(pack);
        positionsToSets.put(totalItems, pack);
        cache.put(totalItems++, num++);

        int count;
        if (!pack.covers.isEmpty()) {
            count = (int) Math.ceil(pack.covers.size() / (float) stickersPerRow);
            for (int b = 0; b < pack.covers.size(); b++) {
                cache.put(b + totalItems, pack.covers.get(b));
            }
        } else {
            count = 1;
            cache.put(totalItems, pack.cover);
        }
        for (int b = 0; b < count * stickersPerRow; b++) {
            positionsToSets.put(totalItems + b, pack);
        }
        totalItems += count * stickersPerRow;
    }
    if (totalItems != 0) {
        loaded = true;
        hash = mediaDataController.getFeaturesStickersHashWithoutUnread();
    }
    notifyDataSetChanged();
}
 
Example 10
Source File: ArchivedStickerSetCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public TLRPC.StickerSetCovered getStickersSet() {
    return stickersSet;
}
 
Example 11
Source File: ArchivedStickerSetCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public TLRPC.StickerSetCovered getStickersSet() {
    return stickersSet;
}
 
Example 12
Source File: TrendingStickersLayout.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void refreshStickerSets() {
    int width = getMeasuredWidth();
    if (width != 0) {
        stickersPerRow = Math.max(5, width / AndroidUtilities.dp(72));
        if (layoutManager.getSpanCount() != stickersPerRow) {
            layoutManager.setSpanCount(stickersPerRow);
            loaded = false;
        }
    }
    if (loaded) {
        return;
    }
    cache.clear();
    positionsToSets.clear();
    sets.clear();
    totalItems = 0;
    int num = 0;

    final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
    ArrayList<TLRPC.StickerSetCovered> packs = new ArrayList<>(mediaDataController.getFeaturedStickerSets());
    final int otherStickersSectionPosition = packs.size();
    packs.addAll(otherPacks);

    for (int a = 0; a < packs.size(); a++) {
        TLRPC.StickerSetCovered pack = packs.get(a);
        if (pack.covers.isEmpty() && pack.cover == null) {
            continue;
        }

        if (a == otherStickersSectionPosition) {
            cache.put(totalItems++, ITEM_SECTION);
        }

        sets.add(pack);
        positionsToSets.put(totalItems, pack);
        cache.put(totalItems++, num++);

        int count;
        if (!pack.covers.isEmpty()) {
            count = (int) Math.ceil(pack.covers.size() / (float) stickersPerRow);
            for (int b = 0; b < pack.covers.size(); b++) {
                cache.put(b + totalItems, pack.covers.get(b));
            }
        } else {
            count = 1;
            cache.put(totalItems, pack.cover);
        }
        for (int b = 0; b < count * stickersPerRow; b++) {
            positionsToSets.put(totalItems + b, pack);
        }
        totalItems += count * stickersPerRow;
    }
    if (totalItems != 0) {
        loaded = true;
        hash = mediaDataController.getFeaturesStickersHashWithoutUnread();
    }
    notifyDataSetChanged();
}
 
Example 13
Source File: StickersSearchAdapter.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
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);
            removing = false;
        }
    }
    cell.setAddDrawProgress(!forceInstalled && installing, animated);
    mediaDataController.preloadStickerSetThumb(stickerSetCovered);
    cell.setNeedDivider(position > 0);
}
 
Example 14
Source File: TrendingStickersLayout.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
}
 
Example 15
Source File: ArchivedStickerSetCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public TLRPC.StickerSetCovered getStickersSet() {
    return stickersSet;
}
 
Example 16
Source File: StickersAlert.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void notifyDataSetChanged() {
    if (stickerSetCovereds != null) {
        int width = gridView.getMeasuredWidth();
        if (width == 0) {
            width = AndroidUtilities.displaySize.x;
        }
        stickersPerRow = width / AndroidUtilities.dp(72);
        layoutManager.setSpanCount(stickersPerRow);
        cache.clear();
        positionsToSets.clear();
        totalItems = 0;
        stickersRowCount = 0;
        for (int a = 0; a < stickerSetCovereds.size(); a++) {
            TLRPC.StickerSetCovered pack = stickerSetCovereds.get(a);
            if (pack.covers.isEmpty() && pack.cover == null) {
                continue;
            }
            stickersRowCount += Math.ceil(stickerSetCovereds.size() / (float) stickersPerRow);
            positionsToSets.put(totalItems, pack);
            cache.put(totalItems++, a);
            int startRow = totalItems / stickersPerRow;
            int count;
            if (!pack.covers.isEmpty()) {
                count = (int) Math.ceil(pack.covers.size() / (float) stickersPerRow);
                for (int b = 0; b < pack.covers.size(); b++) {
                    cache.put(b + totalItems, pack.covers.get(b));
                }
            } else {
                count = 1;
                cache.put(totalItems, pack.cover);
            }
            for (int b = 0; b < count * stickersPerRow; b++) {
                positionsToSets.put(totalItems + b, pack);
            }
            totalItems += count * stickersPerRow;
        }
    } else {
        totalItems = stickerSet != null ? stickerSet.documents.size() : 0;
    }
    super.notifyDataSetChanged();
}
 
Example 17
Source File: StickersAlert.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void notifyDataSetChanged() {
    if (stickerSetCovereds != null) {
        int width = gridView.getMeasuredWidth();
        if (width == 0) {
            width = AndroidUtilities.displaySize.x;
        }
        stickersPerRow = width / AndroidUtilities.dp(72);
        layoutManager.setSpanCount(stickersPerRow);
        cache.clear();
        positionsToSets.clear();
        totalItems = 0;
        stickersRowCount = 0;
        for (int a = 0; a < stickerSetCovereds.size(); a++) {
            TLRPC.StickerSetCovered pack = stickerSetCovereds.get(a);
            if (pack.covers.isEmpty() && pack.cover == null) {
                continue;
            }
            stickersRowCount += Math.ceil(stickerSetCovereds.size() / (float) stickersPerRow);
            positionsToSets.put(totalItems, pack);
            cache.put(totalItems++, a);
            int startRow = totalItems / stickersPerRow;
            int count;
            if (!pack.covers.isEmpty()) {
                count = (int) Math.ceil(pack.covers.size() / (float) stickersPerRow);
                for (int b = 0; b < pack.covers.size(); b++) {
                    cache.put(b + totalItems, pack.covers.get(b));
                }
            } else {
                count = 1;
                cache.put(totalItems, pack.cover);
            }
            for (int b = 0; b < count * stickersPerRow; b++) {
                positionsToSets.put(totalItems + b, pack);
            }
            totalItems += count * stickersPerRow;
        }
    } else {
        totalItems = stickerSet != null ? stickerSet.documents.size() : 0;
    }
    super.notifyDataSetChanged();
}
 
Example 18
Source File: TrendingStickersLayout.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void bindStickerSetCell(View view, int position, boolean animated) {
    final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
    boolean unread = false;
    final TLRPC.StickerSetCovered stickerSetCovered;
    if (position < totalItems) {
        stickerSetCovered = sets.get((Integer) cache.get(position));
        final ArrayList<Long> unreadStickers = mediaDataController.getUnreadStickerSets();
        unread = unreadStickers != null && unreadStickers.contains(stickerSetCovered.set.id);
        if (unread) {
            mediaDataController.markFaturedStickersByIdAsRead(stickerSetCovered.set.id);
        }
    } else {
        stickerSetCovered = sets.get((Integer) cache.get(position));
    }
    mediaDataController.preloadStickerSetThumb(stickerSetCovered);
    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;
            }
        }
    }
    final boolean isSetInstalled = mediaDataController.isStickerPackInstalled(stickerSetCovered.set.id);
    boolean installing = installingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
    boolean removing = removingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
    if (installing && isSetInstalled) {
        installingStickerSets.remove(stickerSetCovered.set.id);
        installing = false;
    } else if (removing && !isSetInstalled) {
        removingStickerSets.remove(stickerSetCovered.set.id);
        removing = false;
    }
    final FeaturedStickerSetInfoCell cell = (FeaturedStickerSetInfoCell) view;
    cell.setStickerSet(stickerSetCovered, unread, animated, 0, 0, forceInstalled);
    cell.setAddDrawProgress(!forceInstalled && installing, animated);
    cell.setNeedDivider(position > 0 && (cache.get(position - 1) == null || !cache.get(position - 1).equals(ITEM_SECTION)));
}
 
Example 19
Source File: FeaturedStickerSetInfoCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public TLRPC.StickerSetCovered getStickerSet() {
    return set;
}
 
Example 20
Source File: FeaturedStickerSetInfoCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void setStickerSet(TLRPC.StickerSetCovered stickerSet, boolean unread, boolean animated, int index, int searchLength) {
    setStickerSet(stickerSet, unread, animated, index, searchLength, false);
}