Search in sources :

Example 1 with GigagroupConvertAlert

use of org.telegram.ui.Components.GigagroupConvertAlert in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatUsersActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (type == TYPE_KICKED) {
        actionBar.setTitle(LocaleController.getString("ChannelPermissions", R.string.ChannelPermissions));
    } else if (type == TYPE_BANNED) {
        actionBar.setTitle(LocaleController.getString("ChannelBlacklist", R.string.ChannelBlacklist));
    } else if (type == TYPE_ADMIN) {
        actionBar.setTitle(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators));
    } else if (type == TYPE_USERS) {
        if (selectType == SELECT_TYPE_MEMBERS) {
            if (isChannel) {
                actionBar.setTitle(LocaleController.getString("ChannelSubscribers", R.string.ChannelSubscribers));
            } else {
                actionBar.setTitle(LocaleController.getString("ChannelMembers", R.string.ChannelMembers));
            }
        } else {
            if (selectType == SELECT_TYPE_ADMIN) {
                actionBar.setTitle(LocaleController.getString("ChannelAddAdmin", R.string.ChannelAddAdmin));
            } else if (selectType == SELECT_TYPE_BLOCK) {
                actionBar.setTitle(LocaleController.getString("ChannelBlockUser", R.string.ChannelBlockUser));
            } else if (selectType == SELECT_TYPE_EXCEPTION) {
                actionBar.setTitle(LocaleController.getString("ChannelAddException", R.string.ChannelAddException));
            }
        }
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (checkDiscard()) {
                    finishFragment();
                }
            } else if (id == done_button) {
                processDone();
            }
        }
    });
    if (selectType != SELECT_TYPE_MEMBERS || type == TYPE_USERS || type == TYPE_BANNED || type == TYPE_KICKED) {
        searchListViewAdapter = new SearchAdapter(context);
        ActionBarMenu menu = actionBar.createMenu();
        searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

            @Override
            public void onSearchExpand() {
                searching = true;
                if (doneItem != null) {
                    doneItem.setVisibility(View.GONE);
                }
            }

            @Override
            public void onSearchCollapse() {
                searchListViewAdapter.searchUsers(null);
                searching = false;
                listView.setAnimateEmptyView(false, 0);
                listView.setAdapter(listViewAdapter);
                listViewAdapter.notifyDataSetChanged();
                listView.setFastScrollVisible(true);
                listView.setVerticalScrollBarEnabled(false);
                if (doneItem != null) {
                    doneItem.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onTextChanged(EditText editText) {
                if (searchListViewAdapter == null) {
                    return;
                }
                String text = editText.getText().toString();
                int oldItemsCount = listView.getAdapter() == null ? 0 : listView.getAdapter().getItemCount();
                searchListViewAdapter.searchUsers(text);
                if (TextUtils.isEmpty(text) && listView != null && listView.getAdapter() != listViewAdapter) {
                    listView.setAnimateEmptyView(false, 0);
                    listView.setAdapter(listViewAdapter);
                    if (oldItemsCount == 0) {
                        showItemsAnimated(0);
                    }
                }
                progressBar.setVisibility(View.GONE);
                flickerLoadingView.setVisibility(View.VISIBLE);
            }
        });
        if (type == TYPE_KICKED) {
            searchItem.setSearchFieldHint(LocaleController.getString("ChannelSearchException", R.string.ChannelSearchException));
        } else {
            searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
        }
        if (!(ChatObject.isChannel(currentChat) || currentChat.creator)) {
            searchItem.setVisibility(View.GONE);
        }
        if (type == TYPE_KICKED) {
            doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
        }
    }
    fragmentView = new FrameLayout(context) {

        @Override
        protected void dispatchDraw(Canvas canvas) {
            canvas.drawColor(Theme.getColor(listView.getAdapter() == searchListViewAdapter ? Theme.key_windowBackgroundWhite : Theme.key_windowBackgroundGray));
            super.dispatchDraw(canvas);
        }
    };
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    FrameLayout progressLayout = new FrameLayout(context);
    flickerLoadingView = new FlickerLoadingView(context);
    flickerLoadingView.setViewType(FlickerLoadingView.USERS_TYPE);
    flickerLoadingView.showDate(false);
    flickerLoadingView.setUseHeaderOffset(true);
    progressLayout.addView(flickerLoadingView);
    progressBar = new RadialProgressView(context);
    progressLayout.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
    flickerLoadingView.setVisibility(View.GONE);
    progressBar.setVisibility(View.GONE);
    emptyView = new StickerEmptyView(context, progressLayout, StickerEmptyView.STICKER_TYPE_SEARCH);
    emptyView.title.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
    emptyView.setVisibility(View.GONE);
    emptyView.setAnimateLayoutChange(true);
    emptyView.showProgress(true, false);
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    emptyView.addView(progressLayout, 0);
    listView = new RecyclerListView(context) {

        @Override
        public void invalidate() {
            super.invalidate();
            if (fragmentView != null) {
                fragmentView.invalidate();
            }
        }
    };
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {

        @Override
        public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
            if (!firstLoaded && type == TYPE_BANNED && participants.size() == 0) {
                return 0;
            }
            return super.scrollVerticallyBy(dy, recycler, state);
        }
    });
    DefaultItemAnimator itemAnimator = new DefaultItemAnimator() {

        @Override
        protected long getAddAnimationDelay(long removeDuration, long moveDuration, long changeDuration) {
            return 0;
        }

        @Override
        protected long getMoveAnimationDelay() {
            return 0;
        }

        @Override
        public long getMoveDuration() {
            return 220;
        }

        @Override
        public long getRemoveDuration() {
            return 220;
        }

        @Override
        public long getAddDuration() {
            return 220;
        }

        int animationIndex = -1;

        @Override
        protected void onAllAnimationsDone() {
            super.onAllAnimationsDone();
            getNotificationCenter().onAnimationFinish(animationIndex);
        }

        @Override
        public void runPendingAnimations() {
            boolean removalsPending = !mPendingRemovals.isEmpty();
            boolean movesPending = !mPendingMoves.isEmpty();
            boolean changesPending = !mPendingChanges.isEmpty();
            boolean additionsPending = !mPendingAdditions.isEmpty();
            if (removalsPending || movesPending || additionsPending || changesPending) {
                animationIndex = getNotificationCenter().setAnimationInProgress(animationIndex, null);
            }
            super.runPendingAnimations();
        }
    };
    listView.setItemAnimator(itemAnimator);
    itemAnimator.setSupportsChangeAnimations(false);
    listView.setAnimateEmptyView(true, 0);
    listView.setAdapter(listViewAdapter = new ListAdapter(context));
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemClickListener((view, position) -> {
        boolean listAdapter = listView.getAdapter() == listViewAdapter;
        if (listAdapter) {
            if (position == addNewRow) {
                if (type == TYPE_BANNED || type == TYPE_KICKED) {
                    Bundle bundle = new Bundle();
                    bundle.putLong("chat_id", chatId);
                    bundle.putInt("type", ChatUsersActivity.TYPE_USERS);
                    bundle.putInt("selectType", type == TYPE_BANNED ? ChatUsersActivity.SELECT_TYPE_BLOCK : ChatUsersActivity.SELECT_TYPE_EXCEPTION);
                    ChatUsersActivity fragment = new ChatUsersActivity(bundle);
                    fragment.setInfo(info);
                    fragment.setDelegate(new ChatUsersActivityDelegate() {

                        @Override
                        public void didAddParticipantToList(long uid, TLObject participant) {
                            if (participantsMap.get(uid) == null) {
                                DiffCallback diffCallback = saveState();
                                participants.add(participant);
                                participantsMap.put(uid, participant);
                                sortUsers(participants);
                                updateListAnimated(diffCallback);
                            }
                        }

                        @Override
                        public void didKickParticipant(long uid) {
                            if (participantsMap.get(uid) == null) {
                                DiffCallback diffCallback = saveState();
                                TLRPC.TL_channelParticipantBanned chatParticipant = new TLRPC.TL_channelParticipantBanned();
                                if (uid > 0) {
                                    chatParticipant.peer = new TLRPC.TL_peerUser();
                                    chatParticipant.peer.user_id = uid;
                                } else {
                                    chatParticipant.peer = new TLRPC.TL_peerChannel();
                                    chatParticipant.peer.channel_id = -uid;
                                }
                                chatParticipant.date = getConnectionsManager().getCurrentTime();
                                chatParticipant.kicked_by = getAccountInstance().getUserConfig().clientUserId;
                                info.kicked_count++;
                                participants.add(chatParticipant);
                                participantsMap.put(uid, chatParticipant);
                                sortUsers(participants);
                                updateListAnimated(diffCallback);
                            }
                        }
                    });
                    presentFragment(fragment);
                } else if (type == TYPE_ADMIN) {
                    Bundle bundle = new Bundle();
                    bundle.putLong("chat_id", chatId);
                    bundle.putInt("type", ChatUsersActivity.TYPE_USERS);
                    bundle.putInt("selectType", ChatUsersActivity.SELECT_TYPE_ADMIN);
                    ChatUsersActivity fragment = new ChatUsersActivity(bundle);
                    fragment.setDelegate(new ChatUsersActivityDelegate() {

                        @Override
                        public void didAddParticipantToList(long uid, TLObject participant) {
                            if (participant != null && participantsMap.get(uid) == null) {
                                DiffCallback diffCallback = saveState();
                                participants.add(participant);
                                participantsMap.put(uid, participant);
                                sortAdmins(participants);
                                updateListAnimated(diffCallback);
                            }
                        }

                        @Override
                        public void didChangeOwner(TLRPC.User user) {
                            onOwnerChaged(user);
                        }

                        @Override
                        public void didSelectUser(long uid) {
                            final TLRPC.User user = getMessagesController().getUser(uid);
                            if (user != null) {
                                AndroidUtilities.runOnUIThread(() -> {
                                    if (BulletinFactory.canShowBulletin(ChatUsersActivity.this)) {
                                        BulletinFactory.createPromoteToAdminBulletin(ChatUsersActivity.this, user.first_name).show();
                                    }
                                }, 200);
                            }
                            if (participantsMap.get(uid) == null) {
                                DiffCallback diffCallback = saveState();
                                TLRPC.TL_channelParticipantAdmin chatParticipant = new TLRPC.TL_channelParticipantAdmin();
                                chatParticipant.peer = new TLRPC.TL_peerUser();
                                chatParticipant.peer.user_id = user.id;
                                chatParticipant.date = getConnectionsManager().getCurrentTime();
                                chatParticipant.promoted_by = getAccountInstance().getUserConfig().clientUserId;
                                participants.add(chatParticipant);
                                participantsMap.put(user.id, chatParticipant);
                                sortAdmins(participants);
                                updateListAnimated(diffCallback);
                            }
                        }
                    });
                    fragment.setInfo(info);
                    presentFragment(fragment);
                } else if (type == TYPE_USERS) {
                    Bundle args = new Bundle();
                    args.putBoolean("addToGroup", true);
                    args.putLong(isChannel ? "channelId" : "chatId", currentChat.id);
                    GroupCreateActivity fragment = new GroupCreateActivity(args);
                    fragment.setInfo(info);
                    fragment.setIgnoreUsers(contactsMap != null && contactsMap.size() != 0 ? contactsMap : participantsMap);
                    fragment.setDelegate(new GroupCreateActivity.ContactsAddActivityDelegate() {

                        @Override
                        public void didSelectUsers(ArrayList<TLRPC.User> users, int fwdCount) {
                            DiffCallback savedState = saveState();
                            ArrayList<TLObject> array = contactsMap != null && contactsMap.size() != 0 ? contacts : participants;
                            LongSparseArray<TLObject> map = contactsMap != null && contactsMap.size() != 0 ? contactsMap : participantsMap;
                            int k = 0;
                            for (int a = 0, N = users.size(); a < N; a++) {
                                TLRPC.User user = users.get(a);
                                getMessagesController().addUserToChat(chatId, user, fwdCount, null, ChatUsersActivity.this, null);
                                getMessagesController().putUser(user, false);
                                if (map.get(user.id) == null) {
                                    if (ChatObject.isChannel(currentChat)) {
                                        TLRPC.TL_channelParticipant channelParticipant1 = new TLRPC.TL_channelParticipant();
                                        channelParticipant1.inviter_id = getUserConfig().getClientUserId();
                                        channelParticipant1.peer = new TLRPC.TL_peerUser();
                                        channelParticipant1.peer.user_id = user.id;
                                        channelParticipant1.date = getConnectionsManager().getCurrentTime();
                                        array.add(k, channelParticipant1);
                                        k++;
                                        map.put(user.id, channelParticipant1);
                                    } else {
                                        TLRPC.ChatParticipant participant = new TLRPC.TL_chatParticipant();
                                        participant.user_id = user.id;
                                        participant.inviter_id = getUserConfig().getClientUserId();
                                        array.add(k, participant);
                                        k++;
                                        map.put(user.id, participant);
                                    }
                                }
                            }
                            if (array == participants) {
                                sortAdmins(participants);
                            }
                            updateListAnimated(savedState);
                        }

                        @Override
                        public void needAddBot(TLRPC.User user) {
                            openRightsEdit(user.id, null, null, null, "", true, ChatRightsEditActivity.TYPE_ADMIN, false);
                        }
                    });
                    presentFragment(fragment);
                }
                return;
            } else if (position == recentActionsRow) {
                presentFragment(new ChannelAdminLogActivity(currentChat));
                return;
            } else if (position == removedUsersRow) {
                Bundle args = new Bundle();
                args.putLong("chat_id", chatId);
                args.putInt("type", ChatUsersActivity.TYPE_BANNED);
                ChatUsersActivity fragment = new ChatUsersActivity(args);
                fragment.setInfo(info);
                presentFragment(fragment);
                return;
            } else if (position == gigaConvertRow) {
                showDialog(new GigagroupConvertAlert(getParentActivity(), ChatUsersActivity.this) {

                    @Override
                    protected void onCovert() {
                        getMessagesController().convertToGigaGroup(getParentActivity(), currentChat, ChatUsersActivity.this, (result) -> {
                            if (result && parentLayout != null) {
                                BaseFragment editActivity = parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2);
                                if (editActivity instanceof ChatEditActivity) {
                                    editActivity.removeSelfFromStack();
                                    Bundle args = new Bundle();
                                    args.putLong("chat_id", chatId);
                                    ChatEditActivity fragment = new ChatEditActivity(args);
                                    fragment.setInfo(info);
                                    parentLayout.addFragmentToStack(fragment, parentLayout.fragmentsStack.size() - 1);
                                    finishFragment();
                                    fragment.showConvertTooltip();
                                } else {
                                    finishFragment();
                                }
                            }
                        });
                    }

                    @Override
                    protected void onCancel() {
                    }
                });
            } else if (position == addNew2Row) {
                ManageLinksActivity fragment = new ManageLinksActivity(chatId, 0, 0);
                fragment.setInfo(info, info.exported_invite);
                presentFragment(fragment);
                return;
            } else if (position > permissionsSectionRow && position <= changeInfoRow) {
                TextCheckCell2 checkCell = (TextCheckCell2) view;
                if (!checkCell.isEnabled()) {
                    return;
                }
                if (checkCell.hasIcon()) {
                    if (!TextUtils.isEmpty(currentChat.username) && (position == pinMessagesRow || position == changeInfoRow)) {
                        BulletinFactory.of(this).createErrorBulletin(LocaleController.getString("EditCantEditPermissionsPublic", R.string.EditCantEditPermissionsPublic)).show();
                    } else {
                        BulletinFactory.of(this).createErrorBulletin(LocaleController.getString("EditCantEditPermissions", R.string.EditCantEditPermissions)).show();
                    }
                    return;
                }
                checkCell.setChecked(!checkCell.isChecked());
                if (position == changeInfoRow) {
                    defaultBannedRights.change_info = !defaultBannedRights.change_info;
                } else if (position == addUsersRow) {
                    defaultBannedRights.invite_users = !defaultBannedRights.invite_users;
                } else if (position == pinMessagesRow) {
                    defaultBannedRights.pin_messages = !defaultBannedRights.pin_messages;
                } else {
                    boolean disabled = !checkCell.isChecked();
                    if (position == sendMessagesRow) {
                        defaultBannedRights.send_messages = !defaultBannedRights.send_messages;
                    } else if (position == sendMediaRow) {
                        defaultBannedRights.send_media = !defaultBannedRights.send_media;
                    } else if (position == sendStickersRow) {
                        defaultBannedRights.send_stickers = defaultBannedRights.send_games = defaultBannedRights.send_gifs = defaultBannedRights.send_inline = !defaultBannedRights.send_stickers;
                    } else if (position == embedLinksRow) {
                        defaultBannedRights.embed_links = !defaultBannedRights.embed_links;
                    } else if (position == sendPollsRow) {
                        defaultBannedRights.send_polls = !defaultBannedRights.send_polls;
                    }
                    if (disabled) {
                        if (defaultBannedRights.view_messages && !defaultBannedRights.send_messages) {
                            defaultBannedRights.send_messages = true;
                            RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMessagesRow);
                            if (holder != null) {
                                ((TextCheckCell2) holder.itemView).setChecked(false);
                            }
                        }
                        if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.send_media) {
                            defaultBannedRights.send_media = true;
                            RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMediaRow);
                            if (holder != null) {
                                ((TextCheckCell2) holder.itemView).setChecked(false);
                            }
                        }
                        if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.send_polls) {
                            defaultBannedRights.send_polls = true;
                            RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendPollsRow);
                            if (holder != null) {
                                ((TextCheckCell2) holder.itemView).setChecked(false);
                            }
                        }
                        if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.send_stickers) {
                            defaultBannedRights.send_stickers = defaultBannedRights.send_games = defaultBannedRights.send_gifs = defaultBannedRights.send_inline = true;
                            RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendStickersRow);
                            if (holder != null) {
                                ((TextCheckCell2) holder.itemView).setChecked(false);
                            }
                        }
                        if ((defaultBannedRights.view_messages || defaultBannedRights.send_messages) && !defaultBannedRights.embed_links) {
                            defaultBannedRights.embed_links = true;
                            RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(embedLinksRow);
                            if (holder != null) {
                                ((TextCheckCell2) holder.itemView).setChecked(false);
                            }
                        }
                    } else {
                        if ((!defaultBannedRights.embed_links || !defaultBannedRights.send_inline || !defaultBannedRights.send_media || !defaultBannedRights.send_polls) && defaultBannedRights.send_messages) {
                            defaultBannedRights.send_messages = false;
                            RecyclerListView.ViewHolder holder = listView.findViewHolderForAdapterPosition(sendMessagesRow);
                            if (holder != null) {
                                ((TextCheckCell2) holder.itemView).setChecked(true);
                            }
                        }
                    }
                }
                return;
            }
        }
        TLRPC.TL_chatBannedRights bannedRights = null;
        TLRPC.TL_chatAdminRights adminRights = null;
        String rank = "";
        final TLObject participant;
        long peerId = 0;
        long promoted_by = 0;
        boolean canEditAdmin = false;
        if (listAdapter) {
            participant = listViewAdapter.getItem(position);
            if (participant instanceof TLRPC.ChannelParticipant) {
                TLRPC.ChannelParticipant channelParticipant = (TLRPC.ChannelParticipant) participant;
                peerId = MessageObject.getPeerId(channelParticipant.peer);
                bannedRights = channelParticipant.banned_rights;
                adminRights = channelParticipant.admin_rights;
                rank = channelParticipant.rank;
                canEditAdmin = !(channelParticipant instanceof TLRPC.TL_channelParticipantAdmin || channelParticipant instanceof TLRPC.TL_channelParticipantCreator) || channelParticipant.can_edit;
                if (participant instanceof TLRPC.TL_channelParticipantCreator) {
                    adminRights = ((TLRPC.TL_channelParticipantCreator) participant).admin_rights;
                    if (adminRights == null) {
                        adminRights = new TLRPC.TL_chatAdminRights();
                        adminRights.change_info = adminRights.post_messages = adminRights.edit_messages = adminRights.delete_messages = adminRights.ban_users = adminRights.invite_users = adminRights.pin_messages = adminRights.add_admins = true;
                        if (!isChannel) {
                            adminRights.manage_call = true;
                        }
                    }
                }
            } else if (participant instanceof TLRPC.ChatParticipant) {
                TLRPC.ChatParticipant chatParticipant = (TLRPC.ChatParticipant) participant;
                peerId = chatParticipant.user_id;
                canEditAdmin = currentChat.creator;
                if (participant instanceof TLRPC.TL_chatParticipantCreator) {
                    adminRights = new TLRPC.TL_chatAdminRights();
                    adminRights.change_info = adminRights.post_messages = adminRights.edit_messages = adminRights.delete_messages = adminRights.ban_users = adminRights.invite_users = adminRights.pin_messages = adminRights.add_admins = true;
                    if (!isChannel) {
                        adminRights.manage_call = true;
                    }
                }
            }
        } else {
            TLObject object = searchListViewAdapter.getItem(position);
            if (object instanceof TLRPC.User) {
                TLRPC.User user = (TLRPC.User) object;
                getMessagesController().putUser(user, false);
                participant = getAnyParticipant(peerId = user.id);
            } else if (object instanceof TLRPC.ChannelParticipant || object instanceof TLRPC.ChatParticipant) {
                participant = object;
            } else {
                participant = null;
            }
            if (participant instanceof TLRPC.ChannelParticipant) {
                TLRPC.ChannelParticipant channelParticipant = (TLRPC.ChannelParticipant) participant;
                peerId = MessageObject.getPeerId(channelParticipant.peer);
                canEditAdmin = !(channelParticipant instanceof TLRPC.TL_channelParticipantAdmin || channelParticipant instanceof TLRPC.TL_channelParticipantCreator) || channelParticipant.can_edit;
                bannedRights = channelParticipant.banned_rights;
                adminRights = channelParticipant.admin_rights;
                rank = channelParticipant.rank;
            } else if (participant instanceof TLRPC.ChatParticipant) {
                TLRPC.ChatParticipant chatParticipant = (TLRPC.ChatParticipant) participant;
                peerId = chatParticipant.user_id;
                canEditAdmin = currentChat.creator;
                bannedRights = null;
                adminRights = null;
            } else if (participant == null) {
                canEditAdmin = true;
            }
        }
        if (peerId != 0) {
            if (selectType != SELECT_TYPE_MEMBERS) {
                if (selectType == SELECT_TYPE_EXCEPTION || selectType == SELECT_TYPE_ADMIN) {
                    if (selectType != SELECT_TYPE_ADMIN && canEditAdmin && (participant instanceof TLRPC.TL_channelParticipantAdmin || participant instanceof TLRPC.TL_chatParticipantAdmin)) {
                        final TLRPC.User user = getMessagesController().getUser(peerId);
                        final TLRPC.TL_chatBannedRights br = bannedRights;
                        final TLRPC.TL_chatAdminRights ar = adminRights;
                        final boolean canEdit = canEditAdmin;
                        final String rankFinal = rank;
                        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                        builder.setMessage(LocaleController.formatString("AdminWillBeRemoved", R.string.AdminWillBeRemoved, UserObject.getUserName(user)));
                        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> openRightsEdit(user.id, participant, ar, br, rankFinal, canEdit, selectType == SELECT_TYPE_ADMIN ? 0 : 1, false));
                        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                        showDialog(builder.create());
                    } else {
                        openRightsEdit(peerId, participant, adminRights, bannedRights, rank, canEditAdmin, selectType == SELECT_TYPE_ADMIN ? 0 : 1, selectType == SELECT_TYPE_ADMIN || selectType == SELECT_TYPE_EXCEPTION);
                    }
                } else {
                    removeParticipant(peerId);
                }
            } else {
                boolean canEdit = false;
                if (type == TYPE_ADMIN) {
                    canEdit = peerId != getUserConfig().getClientUserId() && (currentChat.creator || canEditAdmin);
                } else if (type == TYPE_BANNED || type == TYPE_KICKED) {
                    canEdit = ChatObject.canBlockUsers(currentChat);
                }
                if (type == TYPE_BANNED || type != TYPE_ADMIN && isChannel || type == TYPE_USERS && selectType == SELECT_TYPE_MEMBERS) {
                    if (peerId == getUserConfig().getClientUserId()) {
                        return;
                    }
                    Bundle args = new Bundle();
                    if (peerId > 0) {
                        args.putLong("user_id", peerId);
                    } else {
                        args.putLong("chat_id", -peerId);
                    }
                    presentFragment(new ProfileActivity(args));
                } else {
                    if (bannedRights == null) {
                        bannedRights = new TLRPC.TL_chatBannedRights();
                        bannedRights.view_messages = true;
                        bannedRights.send_stickers = true;
                        bannedRights.send_media = true;
                        bannedRights.embed_links = true;
                        bannedRights.send_messages = true;
                        bannedRights.send_games = true;
                        bannedRights.send_inline = true;
                        bannedRights.send_gifs = true;
                        bannedRights.pin_messages = true;
                        bannedRights.send_polls = true;
                        bannedRights.invite_users = true;
                        bannedRights.change_info = true;
                    }
                    ChatRightsEditActivity fragment = new ChatRightsEditActivity(peerId, chatId, adminRights, defaultBannedRights, bannedRights, rank, type == TYPE_ADMIN ? ChatRightsEditActivity.TYPE_ADMIN : ChatRightsEditActivity.TYPE_BANNED, canEdit, participant == null);
                    fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {

                        @Override
                        public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
                            if (participant instanceof TLRPC.ChannelParticipant) {
                                TLRPC.ChannelParticipant channelParticipant = (TLRPC.ChannelParticipant) participant;
                                channelParticipant.admin_rights = rightsAdmin;
                                channelParticipant.banned_rights = rightsBanned;
                                channelParticipant.rank = rank;
                                updateParticipantWithRights(channelParticipant, rightsAdmin, rightsBanned, 0, false);
                            }
                        }

                        @Override
                        public void didChangeOwner(TLRPC.User user) {
                            onOwnerChaged(user);
                        }
                    });
                    presentFragment(fragment);
                }
            }
        }
    });
    listView.setOnItemLongClickListener((view, position) -> !(getParentActivity() == null || listView.getAdapter() != listViewAdapter) && createMenuForParticipant(listViewAdapter.getItem(position), false));
    if (searchItem != null) {
        listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            }
        });
    }
    undoView = new UndoView(context);
    frameLayout.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
    updateRows();
    listView.setEmptyView(emptyView);
    listView.setAnimateEmptyView(false, 0);
    if (needOpenSearch) {
        searchItem.openSearch(false);
    }
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) TLRPC(org.telegram.tgnet.TLRPC) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) RadialProgressView(org.telegram.ui.Components.RadialProgressView) Canvas(android.graphics.Canvas) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) TextCheckCell2(org.telegram.ui.Cells.TextCheckCell2) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) GigagroupConvertAlert(org.telegram.ui.Components.GigagroupConvertAlert) LongSparseArray(androidx.collection.LongSparseArray) RecyclerListView(org.telegram.ui.Components.RecyclerListView) UndoView(org.telegram.ui.Components.UndoView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) Bundle(android.os.Bundle) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TLObject(org.telegram.tgnet.TLObject) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with GigagroupConvertAlert

use of org.telegram.ui.Components.GigagroupConvertAlert in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method showGigagroupConvertAlert.

private void showGigagroupConvertAlert() {
    if (chatInfo != null && !paused && currentChat.creator && currentChat.megagroup && !currentChat.gigagroup && chatInfo.pending_suggestions.contains("CONVERT_GIGAGROUP") && visibleDialog == null) {
        AndroidUtilities.runOnUIThread(() -> {
            if (chatInfo != null && !paused && currentChat.creator && currentChat.megagroup && !currentChat.gigagroup && chatInfo.pending_suggestions.contains("CONVERT_GIGAGROUP") && visibleDialog == null) {
                SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                int lastShowTime = preferences.getInt("group_convert_time", 0);
                int timeout = BuildVars.DEBUG_PRIVATE_VERSION ? 120 : 60 * 60 * 24 * 7;
                int currentTime = getConnectionsManager().getCurrentTime();
                if (Math.abs(currentTime - lastShowTime) >= timeout) {
                    if (visibleDialog == null && getParentActivity() != null) {
                        preferences.edit().putInt("group_convert_time", currentTime).commit();
                        showDialog(AlertsCreator.createGigagroupConvertAlert(getParentActivity(), (dialog, which) -> showDialog(new GigagroupConvertAlert(getParentActivity(), ChatActivity.this) {

                            @Override
                            protected void onCovert() {
                                getMessagesController().convertToGigaGroup(getParentActivity(), currentChat, ChatActivity.this, (result) -> {
                                    if (result) {
                                        undoView.showWithAction(0, UndoView.ACTION_GIGAGROUP_SUCCESS, null);
                                    }
                                });
                            }

                            @Override
                            protected void onCancel() {
                                undoView.showWithAction(0, UndoView.ACTION_GIGAGROUP_CANCEL, null);
                                getMessagesController().removeSuggestion(dialog_id, "CONVERT_GIGAGROUP");
                            }
                        }), (dialog, which) -> undoView.showWithAction(0, UndoView.ACTION_GIGAGROUP_CANCEL, null)).create());
                    }
                }
            }
        }, 1000);
    }
}
Also used : GigagroupConvertAlert(org.telegram.ui.Components.GigagroupConvertAlert) SharedPreferences(android.content.SharedPreferences) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Aggregations

Paint (android.graphics.Paint)2 TextPaint (android.text.TextPaint)2 GigagroupConvertAlert (org.telegram.ui.Components.GigagroupConvertAlert)2 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 Canvas (android.graphics.Canvas)1 Bundle (android.os.Bundle)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 LongSparseArray (androidx.collection.LongSparseArray)1 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ArrayList (java.util.ArrayList)1 TLObject (org.telegram.tgnet.TLObject)1 TLRPC (org.telegram.tgnet.TLRPC)1 ActionBar (org.telegram.ui.ActionBar.ActionBar)1 ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)1 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)1