Java Code Examples for org.telegram.messenger.ChatObject#isChannel()

The following examples show how to use org.telegram.messenger.ChatObject#isChannel() . 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: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void leaveChatPressed()
{
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    if (ChatObject.isChannel(chat_id, currentAccount) && !currentChat.megagroup)
    {
        builder.setMessage(ChatObject.isChannel(chat_id, currentAccount) ? LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert) : LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
    }
    else
    {
        builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
    }
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> kickUser(0));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    showDialog(builder.create());
}
 
Example 2
Source File: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void checkChannelRights()
{
    if (parentFragment == null)
    {
        return;
    }
    TLRPC.Chat chat = parentFragment.getCurrentChat();
    if (ChatObject.isChannel(chat))
    {
        audioVideoButtonContainer.setAlpha(chat.banned_rights == null || !chat.banned_rights.send_media ? 1.0f : 0.5f);
        if (emojiView != null)
        {
            emojiView.setStickersBanned(chat.banned_rights != null && chat.banned_rights.send_stickers, chat.id);
        }
    }
}
 
Example 3
Source File: ChatUsersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public ChatUsersActivity(Bundle args) {
    super(args);
    chatId = arguments.getInt("chat_id");
    type = arguments.getInt("type");
    needOpenSearch = arguments.getBoolean("open_search");
    selectType = arguments.getInt("selectType");
    currentChat = getMessagesController().getChat(chatId);
    if (currentChat != null && currentChat.default_banned_rights != null) {
        defaultBannedRights.view_messages = currentChat.default_banned_rights.view_messages;
        defaultBannedRights.send_stickers = currentChat.default_banned_rights.send_stickers;
        defaultBannedRights.send_media = currentChat.default_banned_rights.send_media;
        defaultBannedRights.embed_links = currentChat.default_banned_rights.embed_links;
        defaultBannedRights.send_messages = currentChat.default_banned_rights.send_messages;
        defaultBannedRights.send_games = currentChat.default_banned_rights.send_games;
        defaultBannedRights.send_inline = currentChat.default_banned_rights.send_inline;
        defaultBannedRights.send_gifs = currentChat.default_banned_rights.send_gifs;
        defaultBannedRights.pin_messages = currentChat.default_banned_rights.pin_messages;
        defaultBannedRights.send_polls = currentChat.default_banned_rights.send_polls;
        defaultBannedRights.invite_users = currentChat.default_banned_rights.invite_users;
        defaultBannedRights.change_info = currentChat.default_banned_rights.change_info;
    }
    initialBannedRights = ChatObject.getBannedRightsString(defaultBannedRights);
    isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup;
}
 
Example 4
Source File: ChatAttachAlert.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void sendPressed(boolean notify, int scheduleDate) {
    if (buttonPressed) {
        return;
    }
    if (baseFragment instanceof ChatActivity) {
        ChatActivity chatActivity = (ChatActivity) baseFragment;
        TLRPC.Chat chat = chatActivity.getCurrentChat();
        TLRPC.User user = chatActivity.getCurrentUser();
        if (user != null || ChatObject.isChannel(chat) && chat.megagroup || !ChatObject.isChannel(chat)) {
            MessagesController.getNotificationsSettings(currentAccount).edit().putBoolean("silent_" + chatActivity.getDialogId(), !notify).commit();
        }
    }
    applyCaption();
    buttonPressed = true;
    delegate.didPressedButton(7, true, notify, scheduleDate);
}
 
Example 5
Source File: ChatAttachAlert.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void sendPressed(boolean notify, int scheduleDate) {
    if (buttonPressed) {
        return;
    }
    if (baseFragment instanceof ChatActivity) {
        ChatActivity chatActivity = (ChatActivity) baseFragment;
        TLRPC.Chat chat = chatActivity.getCurrentChat();
        TLRPC.User user = chatActivity.getCurrentUser();
        if (user != null || ChatObject.isChannel(chat) && chat.megagroup || !ChatObject.isChannel(chat)) {
            MessagesController.getNotificationsSettings(currentAccount).edit().putBoolean("silent_" + chatActivity.getDialogId(), !notify).commit();
        }
    }
    applyCaption();
    buttonPressed = true;
    delegate.didPressedButton(7, true, notify, scheduleDate);
}
 
Example 6
Source File: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateFieldHint()
{
    boolean isChannel = false;
    if ((int) dialog_id < 0)
    {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-(int) dialog_id);
        isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
    }
    if (editingMessageObject != null)
    {
        messageEditText.setHintText(editingCaption ? LocaleController.getString("Caption", R.string.Caption) : LocaleController.getString("TypeMessage", R.string.TypeMessage));
    }
    else if (isChannel)
    {
        if (silent)
        {
            messageEditText.setHintText(LocaleController.getString("ChannelSilentBroadcast", R.string.ChannelSilentBroadcast));
        }
        else
        {
            messageEditText.setHintText(LocaleController.getString("ChannelBroadcast", R.string.ChannelBroadcast));
        }
    }
    else
    {
        messageEditText.setHintText(LocaleController.getString("TypeMessage", R.string.TypeMessage));
    }
}
 
Example 7
Source File: GroupInviteActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
        case 0:
            TextSettingsCell textCell = (TextSettingsCell) holder.itemView;
            if (position == copyLinkRow) {
                textCell.setText(LocaleController.getString("CopyLink", R.string.CopyLink), true);
            } else if (position == shareLinkRow) {
                textCell.setText(LocaleController.getString("ShareLink", R.string.ShareLink), false);
            } else if (position == revokeLinkRow) {
                textCell.setText(LocaleController.getString("RevokeLink", R.string.RevokeLink), true);
            }
            break;
        case 1:
            TextInfoPrivacyCell privacyCell = (TextInfoPrivacyCell) holder.itemView;
            if (position == shadowRow) {
                privacyCell.setText("");
                privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            } else if (position == linkInfoRow) {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(chat_id);
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    privacyCell.setText(LocaleController.getString("ChannelLinkInfo", R.string.ChannelLinkInfo));
                } else {
                    privacyCell.setText(LocaleController.getString("LinkInfo", R.string.LinkInfo));
                }
                privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            }
            break;
        case 2:
            TextBlockCell textBlockCell = (TextBlockCell) holder.itemView;
            textBlockCell.setText(invite != null ? invite.link : "error", false);
            break;
    }
}
 
Example 8
Source File: ChatUsersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void removeUser(int userId) {
    if (!ChatObject.isChannel(currentChat)) {
        return;
    }
    TLRPC.User user = getMessagesController().getUser(userId);
    getMessagesController().deleteUserFromChat(chatId, user, null);
    finishFragment();
}
 
Example 9
Source File: ChatUsersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.chatInfoDidLoad) {
        TLRPC.ChatFull chatFull = (TLRPC.ChatFull) args[0];
        boolean byChannelUsers = (Boolean) args[2];
        if (chatFull.id == chatId && (!byChannelUsers || !ChatObject.isChannel(currentChat))) {
            boolean hadInfo = info != null;
            info = chatFull;
            if (!hadInfo) {
                selectedSlowmode = initialSlowmode = getCurrentSlowmode();
            }
            AndroidUtilities.runOnUIThread(() -> loadChatParticipants(0, 200));
        }
    }
}
 
Example 10
Source File: ChatEditTypeActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private boolean trySetUsername() {
    if (getParentActivity() == null) {
        return false;
    }
    if (!isPrivate && ((currentChat.username == null && usernameTextView.length() != 0) || (currentChat.username != null && !currentChat.username.equalsIgnoreCase(usernameTextView.getText().toString())))) {
        if (usernameTextView.length() != 0 && !lastNameAvailable) {
            Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
            if (v != null) {
                v.vibrate(200);
            }
            AndroidUtilities.shakeView(checkTextView, 2, 0);
            return false;
        }
    }

    String oldUserName = currentChat.username != null ? currentChat.username : "";
    String newUserName = isPrivate ? "" : usernameTextView.getText().toString();
    if (!oldUserName.equals(newUserName)) {
        if (!ChatObject.isChannel(currentChat)) {
            getMessagesController().convertToMegaGroup(getParentActivity(), chatId, this, param -> {
                if (param != 0) {
                    chatId = param;
                    currentChat = getMessagesController().getChat(param);
                    processDone();
                }
            });
            return false;
        } else {
            getMessagesController().updateChannelUserName(chatId, newUserName);
            currentChat.username = newUserName;
        }
    }
    return true;
}
 
Example 11
Source File: ShareAlert.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<TLRPC.TL_dialog> getDialogs()
{
    if (changed || dialogsList == null)
    {
        changed = false;
        dialogsList = new ArrayList<>();

        ArrayList<TLRPC.TL_dialog> dialogs = MessagesController.getDialogs(currentAccount, dialogsType);
        for (TLRPC.TL_dialog dialog : dialogs)
        {
            int lower_id = (int) dialog.id;
            int high_id = (int) (dialog.id >> 32);
            if (lower_id != 0 && high_id != 1)
            {
                if (lower_id > 0)
                {
                    dialogsList.add(dialog);
                }
                else
                {
                    TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
                    if (!(chat == null || ChatObject.isNotInChat(chat) || ChatObject.isChannel(chat) && !chat.creator &&
                            (chat.admin_rights == null || !chat.admin_rights.post_messages) && !chat.megagroup))
                    {
                        dialogsList.add(dialog);
                    }
                }
            }
        }
    }

    return dialogsList;
}
 
Example 12
Source File: ChatUsersActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void processDone() {
    if (type != TYPE_KICKED) {
        return;
    }
    if (!ChatObject.isChannel(currentChat) && selectedSlowmode != initialSlowmode && info != null) {
        MessagesController.getInstance(currentAccount).convertToMegaGroup(getParentActivity(), chatId, this, param -> {
            if (param != 0) {
                chatId = param;
                currentChat = MessagesController.getInstance(currentAccount).getChat(param);
                processDone();
            }
        });
        return;
    }
    String newBannedRights = ChatObject.getBannedRightsString(defaultBannedRights);
    if (!newBannedRights.equals(initialBannedRights)) {
        getMessagesController().setDefaultBannedRole(chatId, defaultBannedRights, ChatObject.isChannel(currentChat), this);
        TLRPC.Chat chat = getMessagesController().getChat(chatId);
        if (chat != null) {
            chat.default_banned_rights = defaultBannedRights;
        }
    }
    if (selectedSlowmode != initialSlowmode && info != null) {
        info.slowmode_seconds = getSecondsForIndex(selectedSlowmode);
        info.flags |= 131072;
        getMessagesController().setChannelSlowMode(chatId, info.slowmode_seconds);
    }
    finishFragment();
}
 
Example 13
Source File: ProfileNotificationsActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    rowCount = 0;
    if (addingException) {
        avatarRow = rowCount++;
        avatarSectionRow = rowCount++;
        customRow = -1;
        customInfoRow = -1;
    } else {
        avatarRow = -1;
        avatarSectionRow = -1;
        customRow = rowCount++;
        customInfoRow = rowCount++;
    }
    generalRow = rowCount++;
    if (addingException) {
        enableRow = rowCount++;
    } else {
        enableRow = -1;
    }
    if ((int) dialog_id != 0) {
        previewRow = rowCount++;
    } else {
        previewRow = -1;
    }
    soundRow = rowCount++;
    vibrateRow = rowCount++;
    if ((int) dialog_id < 0) {
        smartRow = rowCount++;
    } else {
        smartRow = -1;
    }
    if (Build.VERSION.SDK_INT >= 21) {
        priorityRow = rowCount++;
    } else {
        priorityRow = -1;
    }
    priorityInfoRow = rowCount++;
    boolean isChannel;
    int lower_id = (int) dialog_id;
    if (lower_id < 0) {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
        isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
    } else {
        isChannel = false;
    }
    if (lower_id != 0 && !isChannel) {
        popupRow = rowCount++;
        popupEnabledRow = rowCount++;
        popupDisabledRow = rowCount++;
        popupInfoRow = rowCount++;
    } else {
        popupRow = -1;
        popupEnabledRow = -1;
        popupDisabledRow = -1;
        popupInfoRow = -1;
    }

    if (lower_id > 0) {
        callsRow = rowCount++;
        callsVibrateRow = rowCount++;
        ringtoneRow = rowCount++;
        ringtoneInfoRow = rowCount++;
    } else {
        callsRow = -1;
        callsVibrateRow = -1;
        ringtoneRow = -1;
        ringtoneInfoRow = -1;
    }

    ledRow = rowCount++;
    colorRow = rowCount++;
    ledInfoRow = rowCount++;

    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
    customEnabled = preferences.getBoolean("custom_" + dialog_id, false) || addingException;

    boolean hasOverride = preferences.contains("notify2_" + dialog_id);
    int value = preferences.getInt("notify2_" + dialog_id, 0);
    if (value == 0) {
        if (hasOverride) {
            notificationsEnabled = true;
        } else {
            notificationsEnabled = NotificationsController.getInstance(currentAccount).isGlobalNotificationsEnabled(dialog_id);
        }
    } else if (value == 1) {
        notificationsEnabled = true;
    } else if (value == 2) {
        notificationsEnabled = false;
    } else {
        notificationsEnabled = false;
    }

    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.notificationsSettingsUpdated);
    return super.onFragmentCreate();
}
 
Example 14
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected boolean onCustomOpenAnimation() {
    if (baseFragment instanceof ChatActivity) {
        TLRPC.Chat chat = ((ChatActivity) baseFragment).getCurrentChat();
        if (ChatObject.isChannel(chat)) {
            mediaEnabled = chat.banned_rights == null || !chat.banned_rights.send_media;
            for (int a = 0; a < 5; a++) {
                boolean enabled;
                if (a > 2 && editingMessageObject != null && editingMessageObject.hasValidGroupId()) {
                    attachButtons.get(3 + a).setEnabled(false);
                    attachButtons.get(3 + a).setAlpha(0.2f);
                } else {
                    attachButtons.get(a).setAlpha(mediaEnabled ? 1.0f : 0.2f);
                    attachButtons.get(a).setEnabled(mediaEnabled);
                }
            }
            attachPhotoRecyclerView.setAlpha(mediaEnabled ? 1.0f : 0.2f);
            attachPhotoRecyclerView.setEnabled(mediaEnabled);
            if (!mediaEnabled) {
                if (AndroidUtilities.isBannedForever(chat.banned_rights.until_date)) {
                    mediaBanTooltip.setText(LocaleController.formatString("AttachMediaRestrictedForever", R.string.AttachMediaRestrictedForever));
                } else {
                    mediaBanTooltip.setText(LocaleController.formatString("AttachMediaRestricted", R.string.AttachMediaRestricted, LocaleController.formatDateForBan(chat.banned_rights.until_date)));
                }
            }
            mediaBanTooltip.setVisibility(mediaEnabled ? View.INVISIBLE : View.VISIBLE);
            if (cameraView != null) {
                cameraView.setAlpha(mediaEnabled ? 1.0f : 0.2f);
                cameraView.setEnabled(mediaEnabled);
            }
            if (cameraIcon != null) {
                cameraIcon.setAlpha(mediaEnabled ? 1.0f : 0.2f);
                cameraIcon.setEnabled(mediaEnabled);
            }
        }
    }
    if (useRevealAnimation) {
        startRevealAnimation(true);
        return true;
    }
    return false;
}
 
Example 15
Source File: ChatLinkActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void linkChat(TLRPC.Chat chat, BaseFragment createFragment) {
    if (chat == null) {
        return;
    }
    if (!ChatObject.isChannel(chat)) {
        MessagesController.getInstance(currentAccount).convertToMegaGroup(getParentActivity(), chat.id, this, param -> {
            if (param != 0) {
                MessagesController.getInstance(currentAccount).toogleChannelInvitesHistory(param, false);
                linkChat(getMessagesController().getChat(param), createFragment);
            }
        });
        return;
    }
    final AlertDialog[] progressDialog = new AlertDialog[]{createFragment != null ? null : new AlertDialog(getParentActivity(), 3)};
    TLRPC.TL_channels_setDiscussionGroup req = new TLRPC.TL_channels_setDiscussionGroup();
    req.broadcast = MessagesController.getInputChannel(currentChat);
    req.group = MessagesController.getInputChannel(chat);
    int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (progressDialog[0] != null) {
            try {
                progressDialog[0].dismiss();
            } catch (Throwable ignore) {

            }
            progressDialog[0] = null;
        }
        info.linked_chat_id = chat.id;
        NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, false, null);
        getMessagesController().loadFullChat(currentChatId, 0, true);
        if (createFragment != null) {
            removeSelfFromStack();
            createFragment.finishFragment();
        } else {
            finishFragment();
        }
    }));
    AndroidUtilities.runOnUIThread(() -> {
        if (progressDialog[0] == null) {
            return;
        }
        progressDialog[0].setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(requestId, true));
        showDialog(progressDialog[0]);
    }, 500);
}
 
Example 16
Source File: PollCreateActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void updateRows() {
    rowCount = 0;
    questionHeaderRow = rowCount++;
    questionRow = rowCount++;
    questionSectionRow = rowCount++;
    answerHeaderRow = rowCount++;
    if (answersCount != 0) {
        answerStartRow = rowCount;
        rowCount += answersCount;
    } else {
        answerStartRow = -1;
    }
    if (answersCount != answers.length) {
        addAnswerRow = rowCount++;
    } else {
        addAnswerRow = -1;
    }
    answerSectionRow = rowCount++;
    settingsHeaderRow = rowCount++;
    TLRPC.Chat chat = parentFragment.getCurrentChat();
    if (!ChatObject.isChannel(chat) || chat.megagroup) {
        anonymousRow = rowCount++;
    } else {
        anonymousRow = -1;
    }
    if (quizOnly != 1) {
        multipleRow = rowCount++;
    } else {
        multipleRow = -1;
    }
    if (quizOnly == 0) {
        quizRow = rowCount++;
    } else {
        quizRow = -1;
    }
    settingsSectionRow = rowCount++;
    if (quizPoll) {
        solutionRow = rowCount++;
        solutionInfoRow = rowCount++;
    } else {
        solutionRow = -1;
        solutionInfoRow = -1;
    }
}
 
Example 17
Source File: ProfileNotificationsActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    rowCount = 0;
    if (addingException) {
        avatarRow = rowCount++;
        avatarSectionRow = rowCount++;
        customRow = -1;
        customInfoRow = -1;
    } else {
        avatarRow = -1;
        avatarSectionRow = -1;
        customRow = rowCount++;
        customInfoRow = rowCount++;
    }
    generalRow = rowCount++;
    if (addingException) {
        enableRow = rowCount++;
    } else {
        enableRow = -1;
    }
    if ((int) dialog_id != 0) {
        previewRow = rowCount++;
    } else {
        previewRow = -1;
    }
    soundRow = rowCount++;
    vibrateRow = rowCount++;
    if ((int) dialog_id < 0) {
        smartRow = rowCount++;
    } else {
        smartRow = -1;
    }
    if (Build.VERSION.SDK_INT >= 21) {
        priorityRow = rowCount++;
    } else {
        priorityRow = -1;
    }
    priorityInfoRow = rowCount++;
    boolean isChannel;
    int lower_id = (int) dialog_id;
    if (lower_id < 0) {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
        isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
    } else {
        isChannel = false;
    }
    if (lower_id != 0 && !isChannel) {
        popupRow = rowCount++;
        popupEnabledRow = rowCount++;
        popupDisabledRow = rowCount++;
        popupInfoRow = rowCount++;
    } else {
        popupRow = -1;
        popupEnabledRow = -1;
        popupDisabledRow = -1;
        popupInfoRow = -1;
    }

    if (lower_id > 0) {
        callsRow = rowCount++;
        callsVibrateRow = rowCount++;
        ringtoneRow = rowCount++;
        ringtoneInfoRow = rowCount++;
    } else {
        callsRow = -1;
        callsVibrateRow = -1;
        ringtoneRow = -1;
        ringtoneInfoRow = -1;
    }

    ledRow = rowCount++;
    colorRow = rowCount++;
    ledInfoRow = rowCount++;

    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
    customEnabled = preferences.getBoolean("custom_" + dialog_id, false) || addingException;

    boolean hasOverride = preferences.contains("notify2_" + dialog_id);
    int value = preferences.getInt("notify2_" + dialog_id, 0);
    if (value == 0) {
        if (hasOverride) {
            notificationsEnabled = true;
        } else {
            notificationsEnabled = NotificationsController.getInstance(currentAccount).isGlobalNotificationsEnabled(dialog_id);
        }
    } else if (value == 1) {
        notificationsEnabled = true;
    } else if (value == 2) {
        notificationsEnabled = false;
    } else {
        notificationsEnabled = false;
    }

    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.notificationsSettingsUpdated);
    return super.onFragmentCreate();
}
 
Example 18
Source File: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setDialogId(long id, int account)
{
    dialog_id = id;
    if (currentAccount != account)
    {
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStarted);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStartError);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStopped);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordProgressChanged);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.closeChats);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.audioDidSent);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.audioRouteChanged);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.messagePlayingDidReset);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
        NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.featuredStickersDidLoaded);
        currentAccount = account;
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStarted);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStartError);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStopped);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordProgressChanged);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.closeChats);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.audioDidSent);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.audioRouteChanged);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.featuredStickersDidLoaded);
    }

    int lower_id = (int) dialog_id;
    int high_id = (int) (dialog_id >> 32);
    if ((int) dialog_id < 0)
    {
        TLRPC.Chat currentChat = MessagesController.getInstance(currentAccount).getChat(-(int) dialog_id);
        silent = MessagesController.getNotificationsSettings(currentAccount).getBoolean("silent_" + dialog_id, false);
        canWriteToChannel = ChatObject.isChannel(currentChat) && (currentChat.creator || currentChat.admin_rights != null && currentChat.admin_rights.post_messages) && !currentChat.megagroup;
        if (typingButton != null)
            typingButton.setVisibility(!(ChatObject.isChannel(currentChat) && !currentChat.megagroup) ? VISIBLE : GONE);

        if (notifyButton != null)
        {
            notifyButton.setVisibility(canWriteToChannel ? VISIBLE : GONE);
            notifyButton.setImageResource(silent ? R.drawable.notify_members_off : R.drawable.notify_members_on);
            attachLayout.setPivotX(AndroidUtilities.dp((botButton == null || botButton.getVisibility() == GONE) && (notifyButton == null || notifyButton.getVisibility() == GONE) ? 48 : 96));
        }
        if (attachLayout != null)
        {
            updateFieldRight(attachLayout.getVisibility() == VISIBLE ? 1 : 0);
        }
    }
    checkRoundVideo();
    updateFieldHint();
}
 
Example 19
Source File: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void checkRoundVideo()
{
    if (hasRecordVideo)
    {
        return;
    }
    if (attachLayout == null || Build.VERSION.SDK_INT < 18)
    {
        hasRecordVideo = false;
        setRecordVideoButtonVisible(false, false);
        return;
    }
    int lower_id = (int) dialog_id;
    int high_id = (int) (dialog_id >> 32);
    if (lower_id == 0 && high_id != 0)
    {
        TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(high_id);
        if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 66)
        {
            hasRecordVideo = true;
        }
    }
    else
    {
        hasRecordVideo = true;
    }
    boolean isChannel = false;
    if ((int) dialog_id < 0)
    {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-(int) dialog_id);
        isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
        if (isChannel && !chat.creator && (chat.admin_rights == null || !chat.admin_rights.post_messages))
        {
            hasRecordVideo = false;
        }
    }
    if (!SharedConfig.inappCamera)
    {
        hasRecordVideo = false;
    }
    if (hasRecordVideo)
    {
        if (SharedConfig.hasCameraCache)
        {
            CameraController.getInstance().initCamera(null);
        }
        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        boolean currentModeVideo = preferences.getBoolean(isChannel ? "currentModeVideoChannel" : "currentModeVideo", isChannel);
        setRecordVideoButtonVisible(currentModeVideo, false);
    }
    else
    {
        setRecordVideoButtonVisible(false, false);
    }
}
 
Example 20
Source File: ChatAttachAlertPollLayout.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void updateRows() {
    rowCount = 0;
    paddingRow = rowCount++;

    questionHeaderRow = rowCount++;
    questionRow = rowCount++;
    questionSectionRow = rowCount++;
    answerHeaderRow = rowCount++;
    if (answersCount != 0) {
        answerStartRow = rowCount;
        rowCount += answersCount;
    } else {
        answerStartRow = -1;
    }
    if (answersCount != answers.length) {
        addAnswerRow = rowCount++;
    } else {
        addAnswerRow = -1;
    }
    answerSectionRow = rowCount++;
    settingsHeaderRow = rowCount++;
    TLRPC.Chat chat = ((ChatActivity) parentAlert.baseFragment).getCurrentChat();
    if (!ChatObject.isChannel(chat) || chat.megagroup) {
        anonymousRow = rowCount++;
    } else {
        anonymousRow = -1;
    }
    if (quizOnly != 1) {
        multipleRow = rowCount++;
    } else {
        multipleRow = -1;
    }
    if (quizOnly == 0) {
        quizRow = rowCount++;
    } else {
        quizRow = -1;
    }
    settingsSectionRow = rowCount++;
    if (quizPoll) {
        solutionRow = rowCount++;
        solutionInfoRow = rowCount++;
    } else {
        solutionRow = -1;
        solutionInfoRow = -1;
    }
    emptyRow = rowCount++;
}