Java Code Examples for org.telegram.messenger.MessagesController#getInstance()

The following examples show how to use org.telegram.messenger.MessagesController#getInstance() . 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: PhotoPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser(boolean gif) {
    if (searchingUser) {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = gif ? MessagesController.getInstance(currentAccount).gifSearchBot : MessagesController.getInstance(currentAccount).imageSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            AndroidUtilities.runOnUIThread(() -> {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                String str = lastSearchImageString;
                lastSearchImageString = null;
                searchImages(gif, str, "", false);
            });
        }
    });
}
 
Example 2
Source File: DialogsEmptyCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int totalHeight;
    if (getParent() instanceof View) {
        View view = (View) getParent();
        totalHeight = view.getMeasuredHeight();
        if (view.getPaddingTop() != 0 && Build.VERSION.SDK_INT >= 21) {
            totalHeight -= AndroidUtilities.statusBarHeight;
        }
    } else {
        totalHeight = MeasureSpec.getSize(heightMeasureSpec);
    }
    if (totalHeight == 0) {
        totalHeight = AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
    }
    if (currentType == 0 || currentType == 2 || currentType == 3) {
        ArrayList<TLRPC.RecentMeUrl> arrayList = MessagesController.getInstance(currentAccount).hintDialogs;
        if (!arrayList.isEmpty()) {
            totalHeight -= AndroidUtilities.dp(72) * arrayList.size() + arrayList.size() - 1 + AndroidUtilities.dp(12 + 38);
        }
        super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY));
    } else {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(166), MeasureSpec.EXACTLY));
    }
}
 
Example 3
Source File: StickersAlert.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void onSubItemClick(int id) {
    if (stickerSet == null) {
        return;
    }
    String stickersUrl = "https://" + MessagesController.getInstance(currentAccount).linkPrefix + "/addstickers/" + stickerSet.set.short_name;
    if (id == 1) {
        ShareAlert alert = new ShareAlert(getContext(), null, stickersUrl, false, stickersUrl, false);
        if (parentFragment != null) {
            parentFragment.showDialog(alert);
        } else {
            alert.show();
        }
    } else if (id == 2) {
        try {
            AndroidUtilities.addToClipboard(stickersUrl);
            Toast.makeText(ApplicationLoader.applicationContext, LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
 
Example 4
Source File: FilterTabsView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setIsEditing(boolean value) {
    isEditing = value;
    editingForwardAnimation = true;
    listView.invalidateViews();
    invalidate();
    if (!isEditing && orderChanged) {
        MessagesStorage.getInstance(UserConfig.selectedAccount).saveDialogFiltersOrder();
        TLRPC.TL_messages_updateDialogFiltersOrder req = new TLRPC.TL_messages_updateDialogFiltersOrder();
        ArrayList<MessagesController.DialogFilter> filters = MessagesController.getInstance(UserConfig.selectedAccount).dialogFilters;
        for (int a = 0, N = filters.size(); a < N; a++) {
            MessagesController.DialogFilter filter = filters.get(a);
            req.order.add(filters.get(a).id);
        }
        ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, (response, error) -> {

        });
        orderChanged = false;
    }
}
 
Example 5
Source File: DialogsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updateProxyButton(boolean animated)
{
    if (proxyDrawable == null)
        return;

    if (MessagesController.getInstance(currentAccount).blockedCountry)
    {
        if (!actionBar.isSearchFieldVisible())
            proxyItem.setVisibility(View.VISIBLE);

        boolean value = currentConnectionState == ConnectionsManager.ConnectionStateConnected ||
                currentConnectionState == ConnectionsManager.ConnectionStateUpdating;
        proxyDrawable.setConnected(true, value, animated);
        proxyItemVisisble = true;
    }
    else
    {
        proxyItem.setVisibility(View.GONE);
        proxyItemVisisble = false;
    }
}
 
Example 6
Source File: DialogsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updateProxyButton(boolean animated)
{
    if (proxyDrawable == null)
        return;

    if (MessagesController.getInstance(currentAccount).blockedCountry)
    {
        if (!actionBar.isSearchFieldVisible())
            proxyItem.setVisibility(View.VISIBLE);

        boolean value = currentConnectionState == ConnectionsManager.ConnectionStateConnected ||
                currentConnectionState == ConnectionsManager.ConnectionStateUpdating;
        proxyDrawable.setConnected(true, value, animated);
        proxyItemVisisble = true;
    }
    else
    {
        proxyItem.setVisibility(View.GONE);
        proxyItemVisisble = false;
    }
}
 
Example 7
Source File: PhotoViewerCaptionEnterView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setFieldText(CharSequence text) {
    if (messageEditText == null) {
        return;
    }
    messageEditText.setText(text);
    messageEditText.setSelection(messageEditText.getText().length());
    if (delegate != null) {
        delegate.onTextChanged(messageEditText.getText());
    }
    int old = captionMaxLength;
    captionMaxLength = MessagesController.getInstance(UserConfig.selectedAccount).maxCaptionLength;
    if (old != captionMaxLength) {
        InputFilter[] inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(captionMaxLength);
        messageEditText.setFilters(inputFilters);
    }
}
 
Example 8
Source File: DialogsEmptyCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int totalHeight = MeasureSpec.getSize(heightMeasureSpec);
    if (totalHeight == 0) {
        totalHeight = AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
    }
    if (currentType == 0) {
        ArrayList<TLRPC.RecentMeUrl> arrayList = MessagesController.getInstance(currentAccount).hintDialogs;
        if (!arrayList.isEmpty()) {
            totalHeight -= AndroidUtilities.dp(72) * arrayList.size() + arrayList.size() - 1 + AndroidUtilities.dp(12 + 38);
        }
        super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY));
    } else {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.AT_MOST));
    }
}
 
Example 9
Source File: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public boolean processSendingText(CharSequence text)
{
    text = AndroidUtilities.getTrimmedString(text);
    int maxLength = MessagesController.getInstance(currentAccount).maxMessageLength;
    if (text.length() != 0)
    {
        int count = (int) Math.ceil(text.length() / (float) maxLength);
        for (int a = 0; a < count; a++)
        {
            CharSequence[] message = new CharSequence[]{text.subSequence(a * maxLength, Math.min((a + 1) * maxLength, text.length()))};
            ArrayList<TLRPC.MessageEntity> entities = DataQuery.getInstance(currentAccount).getEntities(message);
            SendMessagesHelper.getInstance(currentAccount).sendMessage(message[0].toString(), dialog_id, replyingMessageObject, messageWebPage, messageWebPageSearch, entities, null, null);
        }
        return true;
    }
    return false;
}
 
Example 10
Source File: WallpapersListActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser() {
    if (searchingUser) {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = MessagesController.getInstance(currentAccount).imageSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            AndroidUtilities.runOnUIThread(() -> {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                String str = lastSearchImageString;
                lastSearchImageString = null;
                searchImages(str, "", false);
            });
        }
    });
}
 
Example 11
Source File: GroupCreateActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public GroupCreateActivity(Bundle args) {
    super(args);
    chatType = args.getInt("chatType", ChatObject.CHAT_TYPE_CHAT);
    isAlwaysShare = args.getBoolean("isAlwaysShare", false);
    isNeverShare = args.getBoolean("isNeverShare", false);
    addToGroup = args.getBoolean("addToGroup", false);
    chatAddType = args.getInt("chatAddType", 0);
    chatId = args.getInt("chatId");
    channelId = args.getInt("channelId");
    if (isAlwaysShare || isNeverShare || addToGroup) {
        maxCount = 0;
    } else {
        maxCount = chatType == ChatObject.CHAT_TYPE_CHAT ? MessagesController.getInstance(currentAccount).maxMegagroupCount : MessagesController.getInstance(currentAccount).maxBroadcastCount;
    }
}
 
Example 12
Source File: WebviewActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public WebviewActivity(String url, String botName, String gameName, String startParam, MessageObject messageObject) {
    super();
    currentUrl = url;
    currentBot = botName;
    currentGame = gameName;
    currentMessageObject = messageObject;
    short_param = startParam;
    linkToCopy = "https://" + MessagesController.getInstance(currentAccount).linkPrefix + "/" + currentBot + (TextUtils.isEmpty(startParam) ? "" : "?game=" + startParam);
    type = TYPE_GAME;
}
 
Example 13
Source File: GroupCreateActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public GroupCreateActivity(Bundle args) {
    super(args);
    chatType = args.getInt("chatType", ChatObject.CHAT_TYPE_CHAT);
    isAlwaysShare = args.getBoolean("isAlwaysShare", false);
    isNeverShare = args.getBoolean("isNeverShare", false);
    isGroup = args.getBoolean("isGroup", false);
    chatId = args.getInt("chatId");
    maxCount = chatType == ChatObject.CHAT_TYPE_CHAT ? MessagesController.getInstance(currentAccount).maxMegagroupCount : MessagesController.getInstance(currentAccount).maxBroadcastCount;
}
 
Example 14
Source File: DialogsActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void neeLoadMoreChats()
{
    int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
    int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
    int visibleItemCount = Math.abs(lastVisibleItem - firstVisibleItem) + 1;
    int totalItemCount = listView.getAdapter().getItemCount();

    if (!MessagesController.getInstance(currentAccount).dialogsEndReached &&
            !MessagesController.getInstance(currentAccount).loadingDialogs &&
            lastVisibleItem > 0 && totalItemCount == visibleItemCount)
    {
        //if (Theme.plusChatsToLoad < 5000)
        MessagesController.getInstance(currentAccount).loadDialogs(-1, 1000, true);
    }
}
 
Example 15
Source File: AdminedChannelCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setChannel(TLRPC.Chat channel, boolean last) {
    final String url = MessagesController.getInstance(currentAccount).linkPrefix + "/";
    currentChannel = channel;
    avatarDrawable.setInfo(channel);
    nameTextView.setText(channel.title);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(url + channel.username);
    stringBuilder.setSpan(new URLSpanNoUnderline(""), url.length(), stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    statusTextView.setText(stringBuilder);
    avatarImageView.setImage(ImageLocation.getForChat(channel, false), "50_50", avatarDrawable, currentChannel);
    isLast = last;
}
 
Example 16
Source File: DialogsActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void neeLoadMoreChats()
{
    int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
    int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
    int visibleItemCount = Math.abs(lastVisibleItem - firstVisibleItem) + 1;
    int totalItemCount = listView.getAdapter().getItemCount();

    if (!MessagesController.getInstance(currentAccount).dialogsEndReached &&
            !MessagesController.getInstance(currentAccount).loadingDialogs &&
            lastVisibleItem > 0 && totalItemCount == visibleItemCount)
    {
        //if (Theme.plusChatsToLoad < 5000)
        MessagesController.getInstance(currentAccount).loadDialogs(-1, 1000, true);
    }
}
 
Example 17
Source File: DialogCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void checkCurrentDialogIndex(boolean frozen) {
    ArrayList<TLRPC.Dialog> dialogsArray = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, frozen);
    if (index < dialogsArray.size()) {
        TLRPC.Dialog dialog = dialogsArray.get(index);
        TLRPC.Dialog nextDialog = index + 1 < dialogsArray.size() ? dialogsArray.get(index + 1) : null;
        TLRPC.DraftMessage newDraftMessage = MediaDataController.getInstance(currentAccount).getDraft(currentDialogId);
        MessageObject newMessageObject;
        if (currentDialogFolderId != 0) {
            newMessageObject = findFolderTopMessage();
        } else {
            newMessageObject = MessagesController.getInstance(currentAccount).dialogMessage.get(dialog.id);
        }
        if (currentDialogId != dialog.id ||
                message != null && message.getId() != dialog.top_message ||
                newMessageObject != null && newMessageObject.messageOwner.edit_date != currentEditDate ||
                unreadCount != dialog.unread_count ||
                mentionCount != dialog.unread_mentions_count ||
                markUnread != dialog.unread_mark ||
                message != newMessageObject ||
                message == null && newMessageObject != null || newDraftMessage != draftMessage || drawPin != dialog.pinned) {
            boolean dialogChanged = currentDialogId != dialog.id;
            currentDialogId = dialog.id;
            if (dialog instanceof TLRPC.TL_dialogFolder) {
                TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
                currentDialogFolderId = dialogFolder.folder.id;
            } else {
                currentDialogFolderId = 0;
            }
            if (dialogsType == 7 || dialogsType == 8) {
                MessagesController.DialogFilter filter = MessagesController.getInstance(currentAccount).selectedDialogFilter[dialogsType == 8 ? 1 : 0];
                fullSeparator = dialog instanceof TLRPC.TL_dialog && nextDialog != null && filter != null && filter.pinnedDialogs.indexOfKey(dialog.id) >= 0 && filter.pinnedDialogs.indexOfKey(nextDialog.id) < 0;
                fullSeparator2 = false;
            } else {
                fullSeparator = dialog instanceof TLRPC.TL_dialog && dialog.pinned && nextDialog != null && !nextDialog.pinned;
                fullSeparator2 = dialog instanceof TLRPC.TL_dialogFolder && nextDialog != null && !nextDialog.pinned;
            }
            update(0);
            if (dialogChanged) {
                reorderIconProgress = drawPin && drawReorder ? 1.0f : 0.0f;
            }
            checkOnline();
        }
    }
}
 
Example 18
Source File: FilterTabsView.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void swapElements(int fromIndex, int toIndex) {
    int idx1 = fromIndex - 1;
    int idx2 = toIndex - 1;
    int count = tabs.size() - 1;
    if (idx1 < 0 || idx2 < 0 || idx1 >= count || idx2 >= count) {
        return;
    }
    ArrayList<MessagesController.DialogFilter> filters = MessagesController.getInstance(UserConfig.selectedAccount).dialogFilters;
    MessagesController.DialogFilter filter1 = filters.get(idx1);
    MessagesController.DialogFilter filter2 = filters.get(idx2);
    int temp = filter1.order;
    filter1.order = filter2.order;
    filter2.order = temp;
    filters.set(idx1, filter2);
    filters.set(idx2, filter1);

    Tab tab1 = tabs.get(fromIndex);
    Tab tab2 = tabs.get(toIndex);
    temp = tab1.id;
    tab1.id = tab2.id;
    tab2.id = temp;

    delegate.onPageReorder(tab2.id, tab1.id);

    if (currentPosition == fromIndex) {
        currentPosition = toIndex;
        selectedTabId = tab1.id;
    } else if (currentPosition == toIndex) {
        currentPosition = fromIndex;
        selectedTabId = tab2.id;
    }

    if (previousPosition == fromIndex) {
        previousPosition = toIndex;
        previousId = tab1.id;
    } else if (previousPosition == toIndex) {
        previousPosition = fromIndex;
        previousId = tab2.id;
    }

    tabs.set(fromIndex, tab2);
    tabs.set(toIndex, tab1);

    updateTabsWidths();

    orderChanged = true;
    notifyItemMoved(fromIndex, toIndex);
}
 
Example 19
Source File: DialogsAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemViewType(int i)
{
    if (showContacts)
    {
        if (i == 0)
        {
            return 5;
        }
        else if (i == 1)
        {
            return 8;
        }
        else if (i == 2)
        {
            return 7;
        }
        else
        {
            return 6;
        }
    }
    else if (hasHints)
    {
        int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
        if (i < 2 + count)
        {
            if (i == 0)
            {
                return 2;
            }
            else if (i == 1 + count)
            {
                return 3;
            }
            return 4;
        }
        else
        {
            i -= 2 + count;
        }
    }
    if (i == getDialogsArray().size())
    {
        if (!MessagesController.getInstance(currentAccount).dialogsEndReached)
        {
            return 1;
        }
        else
        {
            return 5;
        }
    }
    return 0;
}
 
Example 20
Source File: DialogsAdapter.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void sortOnlineContacts(boolean notify) {
    if (onlineContacts == null || notify && (SystemClock.elapsedRealtime() - lastSortTime) < 2000) {
        return;
    }
    lastSortTime = SystemClock.elapsedRealtime();
    try {
        int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        MessagesController messagesController = MessagesController.getInstance(currentAccount);
        Collections.sort(onlineContacts, (o1, o2) -> {
            TLRPC.User user1 = messagesController.getUser(o2.user_id);
            TLRPC.User user2 = messagesController.getUser(o1.user_id);
            int status1 = 0;
            int status2 = 0;
            if (user1 != null) {
                if (user1.self) {
                    status1 = currentTime + 50000;
                } else if (user1.status != null) {
                    status1 = user1.status.expires;
                }
            }
            if (user2 != null) {
                if (user2.self) {
                    status2 = currentTime + 50000;
                } else if (user2.status != null) {
                    status2 = user2.status.expires;
                }
            }
            if (status1 > 0 && status2 > 0) {
                if (status1 > status2) {
                    return 1;
                } else if (status1 < status2) {
                    return -1;
                }
                return 0;
            } else if (status1 < 0 && status2 < 0) {
                if (status1 > status2) {
                    return 1;
                } else if (status1 < status2) {
                    return -1;
                }
                return 0;
            } else if (status1 < 0 && status2 > 0 || status1 == 0 && status2 != 0) {
                return -1;
            } else if (status2 < 0 && status1 > 0 || status2 == 0 && status1 != 0) {
                return 1;
            }
            return 0;
        });
        if (notify) {
            notifyDataSetChanged();
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}