Search in sources :

Example 6 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class StickerSetCell method setStickersSet.

public void setStickersSet(TLRPC.TL_messages_stickerSet set, boolean divider) {
    needDivider = divider;
    stickersSet = set;
    imageView.setVisibility(VISIBLE);
    if (progressView != null) {
        progressView.setVisibility(INVISIBLE);
    }
    textView.setTranslationY(0);
    textView.setText(stickersSet.set.title);
    if (stickersSet.set.archived) {
        textView.setAlpha(0.5f);
        valueTextView.setAlpha(0.5f);
        imageView.setAlpha(0.5f);
    } else {
        textView.setAlpha(1.0f);
        valueTextView.setAlpha(1.0f);
        imageView.setAlpha(1.0f);
    }
    ArrayList<TLRPC.Document> documents = set.documents;
    if (documents != null && !documents.isEmpty()) {
        valueTextView.setText(LocaleController.formatPluralString("Stickers", documents.size()));
        TLRPC.Document sticker = documents.get(0);
        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) || MessageObject.isVideoSticker(sticker)) {
            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 {
        valueTextView.setText(LocaleController.formatPluralString("Stickers", 0));
        imageView.setImageDrawable(null);
    }
}
Also used : TLObject(org.telegram.tgnet.TLObject) SvgHelper(org.telegram.messenger.SvgHelper) TLRPC(org.telegram.tgnet.TLRPC) ImageLocation(org.telegram.messenger.ImageLocation)

Example 7 with TLObject

use of org.telegram.tgnet.TLObject 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 8 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogsSearchAdapter method getItemViewType.

@Override
public int getItemViewType(int i) {
    if (isRecentSearchDisplayed()) {
        int offset = (!MediaDataController.getInstance(currentAccount).hints.isEmpty() ? 1 : 0);
        if (i < offset) {
            return 5;
        }
        if (i == offset) {
            return 1;
        }
        return 0;
    }
    if (!searchResultHashtags.isEmpty()) {
        return i == 0 ? 1 : 4;
    }
    ArrayList<TLObject> globalSearch = searchAdapterHelper.getGlobalSearch();
    int localCount = searchResult.size();
    int localServerCount = searchAdapterHelper.getLocalServerSearch().size();
    int phoneCount = searchAdapterHelper.getPhoneSearch().size();
    if (phoneCount > 3 && phoneCollapsed) {
        phoneCount = 3;
    }
    int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
    if (globalCount > 4 && globalSearchCollapsed) {
        globalCount = 4;
    }
    int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
    if (i >= 0 && i < localCount) {
        return 0;
    } else {
        i -= localCount;
        if (i >= 0 && i < localServerCount) {
            return 0;
        } else {
            i -= localServerCount;
            if (i >= 0 && i < phoneCount) {
                Object object = getItem(i);
                if (object instanceof String) {
                    String str = (String) object;
                    if ("section".equals(str)) {
                        return 1;
                    } else {
                        return 6;
                    }
                }
                return 0;
            } else {
                i -= phoneCount;
                if (i >= 0 && i < globalCount) {
                    if (i == 0) {
                        return 1;
                    } else {
                        return 0;
                    }
                } else {
                    i -= globalCount;
                    if (i >= 0 && i < messagesCount) {
                        if (i == 0) {
                            return 1;
                        } else {
                            return 2;
                        }
                    }
                }
            }
        }
    }
    return 3;
}
Also used : TLObject(org.telegram.tgnet.TLObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject)

Example 9 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogsSearchAdapter method getItem.

public Object getItem(int i) {
    if (isRecentSearchDisplayed()) {
        int offset = (!MediaDataController.getInstance(currentAccount).hints.isEmpty() ? 1 : 0);
        if (i > offset && i - 1 - offset < recentSearchObjects.size()) {
            TLObject object = recentSearchObjects.get(i - 1 - offset).object;
            if (object instanceof TLRPC.User) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(((TLRPC.User) object).id);
                if (user != null) {
                    object = user;
                }
            } else if (object instanceof TLRPC.Chat) {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(((TLRPC.Chat) object).id);
                if (chat != null) {
                    object = chat;
                }
            }
            return object;
        } else {
            return null;
        }
    }
    if (!searchResultHashtags.isEmpty()) {
        if (i > 0) {
            return searchResultHashtags.get(i - 1);
        } else {
            return null;
        }
    }
    ArrayList<TLObject> globalSearch = searchAdapterHelper.getGlobalSearch();
    ArrayList<TLObject> localServerSearch = searchAdapterHelper.getLocalServerSearch();
    ArrayList<Object> phoneSearch = searchAdapterHelper.getPhoneSearch();
    int localCount = searchResult.size();
    int localServerCount = localServerSearch.size();
    int phoneCount = phoneSearch.size();
    if (phoneCount > 3 && phoneCollapsed) {
        phoneCount = 3;
    }
    int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
    if (globalCount > 4 && globalSearchCollapsed) {
        globalCount = 4;
    }
    int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
    if (i >= 0 && i < localCount) {
        return searchResult.get(i);
    } else {
        i -= localCount;
        if (i >= 0 && i < localServerCount) {
            return localServerSearch.get(i);
        } else {
            i -= localServerCount;
            if (i >= 0 && i < phoneCount) {
                return phoneSearch.get(i);
            } else {
                i -= phoneCount;
                if (i > 0 && i < globalCount) {
                    return globalSearch.get(i - 1);
                } else {
                    i -= globalCount;
                    if (i > 0 && i < messagesCount) {
                        return searchResultMessages.get(i - 1);
                    }
                }
            }
        }
    }
    return null;
}
Also used : TLObject(org.telegram.tgnet.TLObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) TLRPC(org.telegram.tgnet.TLRPC)

Example 10 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class BaseLocationAdapter method searchPlacesWithQuery.

public void searchPlacesWithQuery(final String query, final Location coordinate, boolean searchUser, boolean animated) {
    if (coordinate == null || lastSearchLocation != null && coordinate.distanceTo(lastSearchLocation) < 200) {
        return;
    }
    lastSearchLocation = new Location(coordinate);
    lastSearchQuery = query;
    if (searching) {
        searching = false;
        if (currentRequestNum != 0) {
            ConnectionsManager.getInstance(currentAccount).cancelRequest(currentRequestNum, true);
            currentRequestNum = 0;
        }
    }
    int oldItemCount = getItemCount();
    boolean wasSearching = searching;
    searching = true;
    boolean wasSearched = searched;
    searched = true;
    TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat(MessagesController.getInstance(currentAccount).venueSearchBot);
    if (!(object instanceof TLRPC.User)) {
        if (searchUser) {
            searchBotUser();
        }
        return;
    }
    TLRPC.User user = (TLRPC.User) object;
    TLRPC.TL_messages_getInlineBotResults req = new TLRPC.TL_messages_getInlineBotResults();
    req.query = query == null ? "" : query;
    req.bot = MessagesController.getInstance(currentAccount).getInputUser(user);
    req.offset = "";
    req.geo_point = new TLRPC.TL_inputGeoPoint();
    req.geo_point.lat = AndroidUtilities.fixLocationCoord(coordinate.getLatitude());
    req.geo_point._long = AndroidUtilities.fixLocationCoord(coordinate.getLongitude());
    req.flags |= 1;
    if (DialogObject.isEncryptedDialog(dialogId)) {
        req.peer = new TLRPC.TL_inputPeerEmpty();
    } else {
        req.peer = MessagesController.getInstance(currentAccount).getInputPeer(dialogId);
    }
    currentRequestNum = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (error == null) {
            currentRequestNum = 0;
            searching = false;
            places.clear();
            iconUrls.clear();
            searchInProgress = false;
            lastFoundQuery = query;
            TLRPC.messages_BotResults res = (TLRPC.messages_BotResults) response;
            for (int a = 0, size = res.results.size(); a < size; a++) {
                TLRPC.BotInlineResult result = res.results.get(a);
                if (!"venue".equals(result.type) || !(result.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) {
                    continue;
                }
                TLRPC.TL_botInlineMessageMediaVenue mediaVenue = (TLRPC.TL_botInlineMessageMediaVenue) result.send_message;
                iconUrls.add("https://ss3.4sqi.net/img/categories_v2/" + mediaVenue.venue_type + "_64.png");
                TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue();
                venue.geo = mediaVenue.geo;
                venue.address = mediaVenue.address;
                venue.title = mediaVenue.title;
                venue.venue_type = mediaVenue.venue_type;
                venue.venue_id = mediaVenue.venue_id;
                venue.provider = mediaVenue.provider;
                places.add(venue);
            }
        }
        if (delegate != null) {
            delegate.didLoadSearchResult(places);
        }
        notifyDataSetChanged();
    }));
    notifyDataSetChanged();
// notifyStartSearch(wasSearched, wasSearching, oldItemCount, animated);
}
Also used : Utilities(org.telegram.messenger.Utilities) DialogObject(org.telegram.messenger.DialogObject) AndroidUtilities(org.telegram.messenger.AndroidUtilities) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) MessagesController(org.telegram.messenger.MessagesController) ArrayList(java.util.ArrayList) UserConfig(org.telegram.messenger.UserConfig) MessagesStorage(org.telegram.messenger.MessagesStorage) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) Location(android.location.Location) Build(android.os.Build) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) Location(android.location.Location)

Aggregations

TLObject (org.telegram.tgnet.TLObject)85 TLRPC (org.telegram.tgnet.TLRPC)79 Paint (android.graphics.Paint)36 ArrayList (java.util.ArrayList)36 TextPaint (android.text.TextPaint)25 SuppressLint (android.annotation.SuppressLint)22 ConnectionsManager (org.telegram.tgnet.ConnectionsManager)22 File (java.io.File)21 HashMap (java.util.HashMap)20 Context (android.content.Context)19 Build (android.os.Build)19 TextUtils (android.text.TextUtils)19 MessageObject (org.telegram.messenger.MessageObject)19 Theme (org.telegram.ui.ActionBar.Theme)19 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)18 LongSparseArray (androidx.collection.LongSparseArray)17 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)17 Bundle (android.os.Bundle)16 SpannableStringBuilder (android.text.SpannableStringBuilder)16 ChatObject (org.telegram.messenger.ChatObject)16