Search in sources :

Example 1 with EmptyTextProgressView

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

the class WallpapersListActivity method createView.

@Override
public View createView(Context context) {
    colorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    colorFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    colorFramePaint.setStrokeWidth(AndroidUtilities.dp(1));
    colorFramePaint.setStyle(Paint.Style.STROKE);
    colorFramePaint.setColor(0x33000000);
    updater = new WallpaperUpdater(getParentActivity(), this, new WallpaperUpdater.WallpaperUpdaterDelegate() {

        @Override
        public void didSelectWallpaper(File file, Bitmap bitmap, boolean gallery) {
            presentFragment(new ThemePreviewActivity(new FileWallpaper("", file, file), bitmap), gallery);
        }

        @Override
        public void needOpenColorPicker() {
        }
    });
    hasOwnBackground = true;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (currentType == TYPE_ALL) {
        actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
    } else if (currentType == TYPE_COLOR) {
        actionBar.setTitle(LocaleController.getString("SelectColorTitle", R.string.SelectColorTitle));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (actionBar.isActionModeShowed()) {
                    selectedWallPapers.clear();
                    actionBar.hideActionMode();
                    updateRowsSelection();
                } else {
                    finishFragment();
                }
            } else if (id == delete) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.formatPluralString("DeleteBackground", selectedWallPapers.size()));
                builder.setMessage(LocaleController.formatString("DeleteChatBackgroundsAlert", R.string.DeleteChatBackgroundsAlert));
                builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
                    progressDialog = new AlertDialog(getParentActivity(), 3);
                    progressDialog.setCanCacnel(false);
                    progressDialog.show();
                    ArrayList<Integer> ids = new ArrayList<>();
                    int[] deleteCount = new int[] { 0 };
                    for (int b = 0; b < selectedWallPapers.size(); b++) {
                        Object object = selectedWallPapers.valueAt(b);
                        if (object instanceof ColorWallpaper) {
                            ColorWallpaper colorWallpaper = (ColorWallpaper) object;
                            if (colorWallpaper.parentWallpaper != null && colorWallpaper.parentWallpaper.id < 0) {
                                getMessagesStorage().deleteWallpaper(colorWallpaper.parentWallpaper.id);
                                localWallPapers.remove(colorWallpaper);
                                localDict.remove(colorWallpaper.getHash());
                            } else {
                                object = colorWallpaper.parentWallpaper;
                            }
                        }
                        if (!(object instanceof TLRPC.WallPaper)) {
                            continue;
                        }
                        deleteCount[0]++;
                        TLRPC.WallPaper wallPaper = (TLRPC.WallPaper) object;
                        TLRPC.TL_account_saveWallPaper req = new TLRPC.TL_account_saveWallPaper();
                        req.settings = new TLRPC.TL_wallPaperSettings();
                        req.unsave = true;
                        if (object instanceof TLRPC.TL_wallPaperNoFile) {
                            TLRPC.TL_inputWallPaperNoFile inputWallPaper = new TLRPC.TL_inputWallPaperNoFile();
                            inputWallPaper.id = wallPaper.id;
                            req.wallpaper = inputWallPaper;
                        } else {
                            TLRPC.TL_inputWallPaper inputWallPaper = new TLRPC.TL_inputWallPaper();
                            inputWallPaper.id = wallPaper.id;
                            inputWallPaper.access_hash = wallPaper.access_hash;
                            req.wallpaper = inputWallPaper;
                        }
                        if (wallPaper.slug != null && wallPaper.slug.equals(selectedBackgroundSlug)) {
                            selectedBackgroundSlug = Theme.hasWallpaperFromTheme() ? Theme.THEME_BACKGROUND_SLUG : Theme.DEFAULT_BACKGROUND_SLUG;
                            Theme.getActiveTheme().setOverrideWallpaper(null);
                            Theme.reloadWallpaper();
                        }
                        ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                            deleteCount[0]--;
                            if (deleteCount[0] == 0) {
                                loadWallpapers(true);
                            }
                        }));
                    }
                    if (deleteCount[0] == 0) {
                        loadWallpapers(true);
                    }
                    selectedWallPapers.clear();
                    actionBar.hideActionMode();
                    actionBar.closeSearchField();
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                AlertDialog alertDialog = builder.create();
                showDialog(alertDialog);
                TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
            } else if (id == forward) {
                Bundle args = new Bundle();
                args.putBoolean("onlySelect", true);
                args.putInt("dialogsType", 3);
                DialogsActivity fragment = new DialogsActivity(args);
                fragment.setDelegate((fragment1, dids, message, param) -> {
                    StringBuilder fmessage = new StringBuilder();
                    for (int b = 0; b < selectedWallPapers.size(); b++) {
                        Object object = selectedWallPapers.valueAt(b);
                        String link;
                        if (object instanceof TLRPC.TL_wallPaper) {
                            link = AndroidUtilities.getWallPaperUrl(object);
                        } else if (object instanceof ColorWallpaper) {
                            link = ((ColorWallpaper) object).getUrl();
                        } else {
                            continue;
                        }
                        if (!TextUtils.isEmpty(link)) {
                            if (fmessage.length() > 0) {
                                fmessage.append('\n');
                            }
                            fmessage.append(link);
                        }
                    }
                    selectedWallPapers.clear();
                    actionBar.hideActionMode();
                    actionBar.closeSearchField();
                    if (dids.size() > 1 || dids.get(0) == UserConfig.getInstance(currentAccount).getClientUserId() || message != null) {
                        updateRowsSelection();
                        for (int a = 0; a < dids.size(); a++) {
                            long did = dids.get(a);
                            if (message != null) {
                                SendMessagesHelper.getInstance(currentAccount).sendMessage(message.toString(), did, null, null, null, true, null, null, null, true, 0, null);
                            }
                            if (!TextUtils.isEmpty(fmessage)) {
                                SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessage.toString(), did, null, null, null, true, null, null, null, true, 0, null);
                            }
                        }
                        fragment1.finishFragment();
                    } else {
                        long did = dids.get(0);
                        Bundle args1 = new Bundle();
                        args1.putBoolean("scrollToTopOnResume", true);
                        if (DialogObject.isEncryptedDialog(did)) {
                            args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
                        } else {
                            if (DialogObject.isUserDialog(did)) {
                                args1.putLong("user_id", did);
                            } else if (DialogObject.isChatDialog(did)) {
                                args1.putLong("chat_id", -did);
                            }
                            if (!MessagesController.getInstance(currentAccount).checkCanOpenChat(args1, fragment1)) {
                                return;
                            }
                        }
                        NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
                        ChatActivity chatActivity = new ChatActivity(args1);
                        presentFragment(chatActivity, true);
                        SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessage.toString(), did, null, null, null, true, null, null, null, true, 0, null);
                    }
                });
                presentFragment(fragment);
            }
        }
    });
    if (currentType == TYPE_ALL) {
        ActionBarMenu menu = actionBar.createMenu();
        searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

            @Override
            public void onSearchExpand() {
                listView.setAdapter(searchAdapter);
                listView.invalidate();
            }

            @Override
            public void onSearchCollapse() {
                listView.setAdapter(listAdapter);
                listView.invalidate();
                searchAdapter.processSearch(null, true);
                searchItem.setSearchFieldCaption(null);
                onCaptionCleared();
            }

            @Override
            public void onTextChanged(EditText editText) {
                searchAdapter.processSearch(editText.getText().toString(), false);
            }

            @Override
            public void onCaptionCleared() {
                searchAdapter.clearColor();
                searchItem.setSearchFieldHint(LocaleController.getString("SearchBackgrounds", R.string.SearchBackgrounds));
            }
        });
        searchItem.setSearchFieldHint(LocaleController.getString("SearchBackgrounds", R.string.SearchBackgrounds));
        final ActionBarMenu actionMode = actionBar.createActionMode(false, null);
        actionMode.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefault));
        actionBar.setItemsColor(Theme.getColor(Theme.key_actionBarDefaultIcon), true);
        actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultSelector), true);
        selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
        selectedMessagesCountTextView.setTextSize(18);
        selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        selectedMessagesCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultIcon));
        selectedMessagesCountTextView.setOnTouchListener((v, event) -> true);
        actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
        actionModeViews.add(actionMode.addItemWithWidth(forward, R.drawable.msg_forward, AndroidUtilities.dp(54), LocaleController.getString("Forward", R.string.Forward)));
        actionModeViews.add(actionMode.addItemWithWidth(delete, R.drawable.msg_delete, AndroidUtilities.dp(54), LocaleController.getString("Delete", R.string.Delete)));
        selectedWallPapers.clear();
    }
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    listView = new RecyclerListView(context) {

        private Paint paint = new Paint();

        @Override
        public boolean hasOverlappingRendering() {
            return false;
        }

        @Override
        public void onDraw(Canvas c) {
            ViewHolder holder;
            if (getAdapter() == listAdapter && resetInfoRow != -1) {
                holder = findViewHolderForAdapterPosition(resetInfoRow);
            } else {
                holder = null;
            }
            int bottom;
            int height = getMeasuredHeight();
            if (holder != null) {
                bottom = holder.itemView.getBottom();
                if (holder.itemView.getBottom() >= height) {
                    bottom = height;
                }
            } else {
                bottom = height;
            }
            paint.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            c.drawRect(0, 0, getMeasuredWidth(), bottom, paint);
            if (bottom != height) {
                paint.setColor(Theme.getColor(Theme.key_windowBackgroundGray));
                c.drawRect(0, bottom, getMeasuredWidth(), height, paint);
            }
        }
    };
    listView.setClipToPadding(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    });
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
    listView.setAdapter(listAdapter = new ListAdapter(context));
    searchAdapter = new SearchAdapter(context);
    listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue));
    listView.setOnItemClickListener((view, position) -> {
        if (getParentActivity() == null || listView.getAdapter() == searchAdapter) {
            return;
        }
        if (position == uploadImageRow) {
            updater.openGallery();
        } else if (position == setColorRow) {
            WallpapersListActivity activity = new WallpapersListActivity(TYPE_COLOR);
            activity.patterns = patterns;
            presentFragment(activity);
        } else if (position == resetRow) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("ResetChatBackgroundsAlertTitle", R.string.ResetChatBackgroundsAlertTitle));
            builder.setMessage(LocaleController.getString("ResetChatBackgroundsAlert", R.string.ResetChatBackgroundsAlert));
            builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
                if (actionBar.isActionModeShowed()) {
                    selectedWallPapers.clear();
                    actionBar.hideActionMode();
                    updateRowsSelection();
                }
                progressDialog = new AlertDialog(getParentActivity(), 3);
                progressDialog.setCanCacnel(false);
                progressDialog.show();
                TLRPC.TL_account_resetWallPapers req = new TLRPC.TL_account_resetWallPapers();
                ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> loadWallpapers(false)));
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog dialog = builder.create();
            showDialog(dialog);
            TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

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

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (listView.getAdapter() == searchAdapter) {
                int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
                int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
                if (visibleItemCount > 0) {
                    int totalItemCount = layoutManager.getItemCount();
                    if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2) {
                        searchAdapter.loadMoreResults();
                    }
                }
            }
        }
    });
    searchEmptyView = new EmptyTextProgressView(context);
    searchEmptyView.setVisibility(View.GONE);
    searchEmptyView.setShowAtCenter(true);
    searchEmptyView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    listView.setEmptyView(searchEmptyView);
    frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    updateRows();
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Bundle(android.os.Bundle) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) ColorDrawable(android.graphics.drawable.ColorDrawable) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) TextCell(org.telegram.ui.Cells.TextCell) MediaController(org.telegram.messenger.MediaController) View(android.view.View) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) ForegroundColorSpan(android.text.style.ForegroundColorSpan) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Utilities(org.telegram.messenger.Utilities) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) Surface(android.view.Surface) ObjectAnimator(android.animation.ObjectAnimator) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LongSparseArray(android.util.LongSparseArray) FileLoader(org.telegram.messenger.FileLoader) Context(android.content.Context) Spanned(android.text.Spanned) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) WallpaperUpdater(org.telegram.ui.Components.WallpaperUpdater) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) ColorPicker(org.telegram.ui.Components.ColorPicker) MediaDataController(org.telegram.messenger.MediaDataController) DialogInterface(android.content.DialogInterface) DialogObject(org.telegram.messenger.DialogObject) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) SpannableString(android.text.SpannableString) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) Gravity(android.view.Gravity) WallpaperCell(org.telegram.ui.Cells.WallpaperCell) NumberTextView(org.telegram.ui.Components.NumberTextView) SharedPreferences(android.content.SharedPreferences) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Bitmap(android.graphics.Bitmap) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) EditText(android.widget.EditText) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) WallpaperUpdater(org.telegram.ui.Components.WallpaperUpdater) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) TLObject(org.telegram.tgnet.TLObject) DialogObject(org.telegram.messenger.DialogObject) File(java.io.File) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Bitmap(android.graphics.Bitmap) NumberTextView(org.telegram.ui.Components.NumberTextView) Bundle(android.os.Bundle) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) Paint(android.graphics.Paint) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with EmptyTextProgressView

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

the class MessageStatisticActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    emptyView = new EmptyTextProgressView(context);
    emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyView.setVisibility(View.GONE);
    progressLayout = new LinearLayout(context);
    progressLayout.setOrientation(LinearLayout.VERTICAL);
    imageView = new RLottieImageView(context);
    imageView.setAutoRepeat(true);
    imageView.setAnimation(R.raw.statistic_preload, 120, 120);
    imageView.playAnimation();
    TextView loadingTitle = new TextView(context);
    loadingTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    loadingTitle.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    loadingTitle.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle));
    loadingTitle.setTag(Theme.key_player_actionBarTitle);
    loadingTitle.setText(LocaleController.getString("LoadingStats", R.string.LoadingStats));
    loadingTitle.setGravity(Gravity.CENTER_HORIZONTAL);
    TextView loadingSubtitle = new TextView(context);
    loadingSubtitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    loadingSubtitle.setTextColor(Theme.getColor(Theme.key_player_actionBarSubtitle));
    loadingSubtitle.setTag(Theme.key_player_actionBarSubtitle);
    loadingSubtitle.setText(LocaleController.getString("LoadingStatsDescription", R.string.LoadingStatsDescription));
    loadingSubtitle.setGravity(Gravity.CENTER_HORIZONTAL);
    progressLayout.addView(imageView, LayoutHelper.createLinear(120, 120, Gravity.CENTER_HORIZONTAL, 0, 0, 0, 20));
    progressLayout.addView(loadingTitle, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 0, 0, 10));
    progressLayout.addView(loadingSubtitle, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
    progressLayout.setAlpha(0);
    frameLayout.addView(progressLayout, LayoutHelper.createFrame(240, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 0, 0, 30));
    listView = new RecyclerListView(context);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    ((SimpleItemAnimator) listView.getItemAnimator()).setSupportsChangeAnimations(false);
    listView.setAdapter(listViewAdapter = new ListAdapter(context));
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
    listView.setOnItemClickListener((view, position) -> {
        if (position >= startRow && position < endRow) {
            TLRPC.Message message = messages.get(position - startRow);
            long did = MessageObject.getDialogId(message);
            Bundle args = new Bundle();
            if (DialogObject.isUserDialog(did)) {
                args.putLong("user_id", did);
            } else {
                args.putLong("chat_id", -did);
            }
            args.putInt("message_id", message.id);
            args.putBoolean("need_remove_previous_same_chat_activity", false);
            if (getMessagesController().checkCanOpenChat(args, this)) {
                presentFragment(new ChatActivity(args));
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
            int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
            int totalItemCount = recyclerView.getAdapter().getItemCount();
            if (visibleItemCount > 0) {
                if (!endReached && !loading && !messages.isEmpty() && firstVisibleItem + visibleItemCount >= totalItemCount - 5 && statsLoaded) {
                    loadChats(100);
                }
            }
        }
    });
    emptyView.showTextView();
    listContainer = new FrameLayout(context);
    listContainer.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listContainer.setVisibility(View.GONE);
    frameLayout.addView(listContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    AndroidUtilities.runOnUIThread(showProgressbar, 300);
    updateRows();
    listView.setEmptyView(emptyView);
    avatarContainer = new ChatAvatarContainer(context, null, false) {

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            thumbImage.setImageCoords(avatarContainer.getSubtitleTextView().getX(), avatarContainer.getSubtitleTextView().getY(), AndroidUtilities.dp(18), AndroidUtilities.dp(18));
            thumbImage.draw(canvas);
            if (drawPlay) {
                int x = (int) (thumbImage.getCenterX() - Theme.dialogs_playDrawable.getIntrinsicWidth() / 2);
                int y = (int) (thumbImage.getCenterY() - Theme.dialogs_playDrawable.getIntrinsicHeight() / 2);
                Theme.dialogs_playDrawable.setBounds(x, y, x + Theme.dialogs_playDrawable.getIntrinsicWidth(), y + Theme.dialogs_playDrawable.getIntrinsicHeight());
                Theme.dialogs_playDrawable.draw(canvas);
            }
        }

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            thumbImage.onAttachedToWindow();
        }

        @Override
        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            thumbImage.onDetachedFromWindow();
        }
    };
    thumbImage = new ImageReceiver();
    thumbImage.setParentView(avatarContainer);
    thumbImage.setRoundRadius(AndroidUtilities.dp(2));
    actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, !inPreviewMode ? 56 : 0, 0, 40, 0));
    TLRPC.Chat chatLocal = getMessagesController().getChat(chatId);
    if (chatLocal != null) {
        avatarContainer.setChatAvatar(chatLocal);
        avatarContainer.setTitle(chatLocal.title);
    }
    boolean hasThumb = false;
    if (!messageObject.needDrawBluredPreview() && (messageObject.isPhoto() || messageObject.isNewGif() || messageObject.isVideo())) {
        String type = messageObject.isWebpage() ? messageObject.messageOwner.media.webpage.type : null;
        if (!("app".equals(type) || "profile".equals(type) || "article".equals(type) || type != null && type.startsWith("telegram_"))) {
            TLRPC.PhotoSize smallThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 40);
            TLRPC.PhotoSize bigThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
            if (smallThumb == bigThumb) {
                bigThumb = null;
            }
            if (smallThumb != null) {
                hasThumb = true;
                drawPlay = messageObject.isVideo();
                String fileName = FileLoader.getAttachFileName(bigThumb);
                if (messageObject.mediaExists || DownloadController.getInstance(currentAccount).canDownloadMedia(messageObject) || FileLoader.getInstance(currentAccount).isLoadingFile(fileName)) {
                    int size;
                    if (messageObject.type == MessageObject.TYPE_PHOTO) {
                        size = bigThumb != null ? bigThumb.size : 0;
                    } else {
                        size = 0;
                    }
                    thumbImage.setImage(ImageLocation.getForObject(bigThumb, messageObject.photoThumbsObject), "20_20", ImageLocation.getForObject(smallThumb, messageObject.photoThumbsObject), "20_20", size, null, messageObject, 0);
                } else {
                    thumbImage.setImage(null, null, ImageLocation.getForObject(smallThumb, messageObject.photoThumbsObject), "20_20", (Drawable) null, messageObject, 0);
                }
            }
        }
    }
    CharSequence message;
    if (!TextUtils.isEmpty(messageObject.caption)) {
        message = messageObject.caption;
    } else if (!TextUtils.isEmpty(messageObject.messageOwner.message)) {
        message = messageObject.messageText;
        if (message.length() > 150) {
            message = message.subSequence(0, 150);
        }
        message = Emoji.replaceEmoji(message, avatarContainer.getSubtitleTextView().getTextPaint().getFontMetricsInt(), AndroidUtilities.dp(17), false);
    } else {
        message = messageObject.messageText;
    }
    if (hasThumb) {
        SpannableStringBuilder builder = new SpannableStringBuilder(message);
        builder.insert(0, " ");
        builder.setSpan(new DialogCell.FixedWidthSpan(AndroidUtilities.dp(18 + 6)), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        avatarContainer.setSubtitle(builder);
    } else {
        avatarContainer.setSubtitle(messageObject.messageText);
    }
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(final int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == 1) {
                Bundle args = new Bundle();
                if (messageObject.messageOwner.fwd_from == null) {
                    args.putLong("chat_id", messageObject.getChatId());
                } else {
                    args.putLong("chat_id", -messageObject.getFromChatId());
                }
                presentFragment(new StatisticActivity(args));
            }
        }
    });
    avatarContainer.setTitleColors(Theme.getColor(Theme.key_player_actionBarTitle), Theme.getColor(Theme.key_player_actionBarSubtitle));
    avatarContainer.getSubtitleTextView().setLinkTextColor(Theme.getColor(Theme.key_player_actionBarSubtitle));
    actionBar.setItemsColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2), false);
    actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarActionModeDefaultSelector), false);
    actionBar.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    avatarContainer.setOnClickListener(view -> {
        if (getParentLayout().fragmentsStack.size() > 1) {
            BaseFragment previousFragemnt = getParentLayout().fragmentsStack.get(getParentLayout().fragmentsStack.size() - 2);
            if (previousFragemnt instanceof ChatActivity && ((ChatActivity) previousFragemnt).getCurrentChat().id == chatId) {
                finishFragment();
                return;
            }
        }
        Bundle args = new Bundle();
        args.putLong("chat_id", chatId);
        args.putInt("message_id", messageId);
        args.putBoolean("need_remove_previous_same_chat_activity", false);
        ChatActivity a = new ChatActivity(args);
        presentFragment(a);
    });
    updateMenu();
    return fragmentView;
}
Also used : RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ImageReceiver(org.telegram.messenger.ImageReceiver) DialogCell(org.telegram.ui.Cells.DialogCell) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) ChatAvatarContainer(org.telegram.ui.Components.ChatAvatarContainer) Bundle(android.os.Bundle) Canvas(android.graphics.Canvas) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 3 with EmptyTextProgressView

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

the class InviteContactsActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    searchWas = false;
    allSpans.clear();
    selectedContacts.clear();
    currentDeletingSpan = null;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("InviteFriends", R.string.InviteFriends));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    fragmentView = new ViewGroup(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(width, height);
            int maxSize;
            if (AndroidUtilities.isTablet() || height > width) {
                maxSize = AndroidUtilities.dp(144);
            } else {
                maxSize = AndroidUtilities.dp(56);
            }
            int h;
            infoTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.AT_MOST));
            counterView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), MeasureSpec.EXACTLY));
            if (infoTextView.getVisibility() == VISIBLE) {
                h = infoTextView.getMeasuredHeight();
            } else {
                h = counterView.getMeasuredHeight();
            }
            scrollView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.AT_MOST));
            listView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight() - h, MeasureSpec.EXACTLY));
            emptyView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight() - AndroidUtilities.dp(72), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            scrollView.layout(0, 0, scrollView.getMeasuredWidth(), scrollView.getMeasuredHeight());
            listView.layout(0, scrollView.getMeasuredHeight(), listView.getMeasuredWidth(), scrollView.getMeasuredHeight() + listView.getMeasuredHeight());
            emptyView.layout(0, scrollView.getMeasuredHeight() + AndroidUtilities.dp(72), emptyView.getMeasuredWidth(), scrollView.getMeasuredHeight() + emptyView.getMeasuredHeight());
            int y = bottom - top - infoTextView.getMeasuredHeight();
            infoTextView.layout(0, y, infoTextView.getMeasuredWidth(), y + infoTextView.getMeasuredHeight());
            y = bottom - top - counterView.getMeasuredHeight();
            counterView.layout(0, y, counterView.getMeasuredWidth(), y + counterView.getMeasuredHeight());
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == listView || child == emptyView) {
                parentLayout.drawHeaderShadow(canvas, scrollView.getMeasuredHeight());
            }
            return result;
        }
    };
    ViewGroup frameLayout = (ViewGroup) fragmentView;
    scrollView = new ScrollView(context) {

        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (ignoreScrollEvent) {
                ignoreScrollEvent = false;
                return false;
            }
            rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
            rectangle.top += fieldY + AndroidUtilities.dp(20);
            rectangle.bottom += fieldY + AndroidUtilities.dp(50);
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }
    };
    scrollView.setVerticalScrollBarEnabled(false);
    AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_windowBackgroundWhite));
    frameLayout.addView(scrollView);
    spansContainer = new SpansContainer(context);
    scrollView.addView(spansContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    editText = new EditTextBoldCursor(context) {

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (currentDeletingSpan != null) {
                currentDeletingSpan.cancelDeleteAnimation();
                currentDeletingSpan = null;
            }
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!AndroidUtilities.showKeyboard(this)) {
                    clearFocus();
                    requestFocus();
                }
            }
            return super.onTouchEvent(event);
        }
    };
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    editText.setHintColor(Theme.getColor(Theme.key_groupcreate_hintText));
    editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorColor(Theme.getColor(Theme.key_groupcreate_cursor));
    editText.setCursorWidth(1.5f);
    editText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    editText.setSingleLine(true);
    editText.setBackgroundDrawable(null);
    editText.setVerticalScrollBarEnabled(false);
    editText.setHorizontalScrollBarEnabled(false);
    editText.setTextIsSelectable(false);
    editText.setPadding(0, 0, 0, 0);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    editText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    spansContainer.addView(editText);
    editText.setHintText(LocaleController.getString("SearchFriends", R.string.SearchFriends));
    editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    /*editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                return actionId == EditorInfo.IME_ACTION_DONE && onDonePressed();
            }
        });*/
    editText.setOnKeyListener(new View.OnKeyListener() {

        private boolean wasEmpty;

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                wasEmpty = editText.length() == 0;
            } else if (event.getAction() == KeyEvent.ACTION_UP && wasEmpty && !allSpans.isEmpty()) {
                spansContainer.removeSpan(allSpans.get(allSpans.size() - 1));
                updateHint();
                checkVisibleRows();
                return true;
            }
            return false;
        }
    });
    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editText.length() != 0) {
                searching = true;
                searchWas = true;
                adapter.setSearching(true);
                adapter.searchDialogs(editText.getText().toString());
                listView.setFastScrollVisible(false);
                listView.setVerticalScrollBarEnabled(true);
                emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
            } else {
                closeSearch();
            }
        }
    });
    emptyView = new EmptyTextProgressView(context);
    if (ContactsController.getInstance(currentAccount).isLoadingContacts()) {
        emptyView.showProgress();
    } else {
        emptyView.showTextView();
    }
    emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
    frameLayout.addView(emptyView);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    listView = new RecyclerListView(context);
    listView.setEmptyView(emptyView);
    listView.setAdapter(adapter = new InviteAdapter(context));
    listView.setLayoutManager(linearLayoutManager);
    listView.setVerticalScrollBarEnabled(true);
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT);
    listView.addItemDecoration(decoration = new GroupCreateDividerItemDecoration());
    frameLayout.addView(listView);
    listView.setOnItemClickListener((view, position) -> {
        if (position == 0 && !searching) {
            try {
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                String text = ContactsController.getInstance(currentAccount).getInviteText(0);
                intent.putExtra(Intent.EXTRA_TEXT, text);
                getParentActivity().startActivityForResult(Intent.createChooser(intent, text), 500);
            } catch (Exception e) {
                FileLog.e(e);
            }
            return;
        }
        if (!(view instanceof InviteUserCell)) {
            return;
        }
        InviteUserCell cell = (InviteUserCell) view;
        ContactsController.Contact contact = cell.getContact();
        if (contact == null) {
            return;
        }
        boolean exists;
        if (exists = selectedContacts.containsKey(contact.key)) {
            GroupCreateSpan span = selectedContacts.get(contact.key);
            spansContainer.removeSpan(span);
        } else {
            GroupCreateSpan span = new GroupCreateSpan(editText.getContext(), contact);
            spansContainer.addSpan(span);
            span.setOnClickListener(InviteContactsActivity.this);
        }
        updateHint();
        if (searching || searchWas) {
            AndroidUtilities.showKeyboard(editText);
        } else {
            cell.setChecked(!exists, true);
        }
        if (editText.length() > 0) {
            editText.setText(null);
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(editText);
            }
        }
    });
    infoTextView = new TextView(context);
    infoTextView.setBackgroundColor(Theme.getColor(Theme.key_contacts_inviteBackground));
    infoTextView.setTextColor(Theme.getColor(Theme.key_contacts_inviteText));
    infoTextView.setGravity(Gravity.CENTER);
    infoTextView.setText(LocaleController.getString("InviteFriendsHelp", R.string.InviteFriendsHelp));
    infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    infoTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    infoTextView.setPadding(AndroidUtilities.dp(17), AndroidUtilities.dp(9), AndroidUtilities.dp(17), AndroidUtilities.dp(9));
    frameLayout.addView(infoTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM));
    counterView = new FrameLayout(context);
    counterView.setBackgroundColor(Theme.getColor(Theme.key_contacts_inviteBackground));
    counterView.setVisibility(View.INVISIBLE);
    frameLayout.addView(counterView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
    counterView.setOnClickListener(v -> {
        try {
            StringBuilder builder = new StringBuilder();
            int num = 0;
            for (int a = 0; a < allSpans.size(); a++) {
                ContactsController.Contact contact = allSpans.get(a).getContact();
                if (builder.length() != 0) {
                    builder.append(';');
                }
                builder.append(contact.phones.get(0));
                if (a == 0 && allSpans.size() == 1) {
                    num = contact.imported;
                }
            }
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + builder.toString()));
            intent.putExtra("sms_body", ContactsController.getInstance(currentAccount).getInviteText(num));
            getParentActivity().startActivityForResult(intent, 500);
        } catch (Exception e) {
            FileLog.e(e);
        }
        finishFragment();
    });
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    counterView.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
    counterTextView = new TextView(context);
    counterTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    counterTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    counterTextView.setTextColor(Theme.getColor(Theme.key_contacts_inviteBackground));
    counterTextView.setGravity(Gravity.CENTER);
    counterTextView.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(10), Theme.getColor(Theme.key_contacts_inviteText)));
    counterTextView.setMinWidth(AndroidUtilities.dp(20));
    counterTextView.setPadding(AndroidUtilities.dp(6), 0, AndroidUtilities.dp(6), AndroidUtilities.dp(1));
    linearLayout.addView(counterTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 20, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));
    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setTextColor(Theme.getColor(Theme.key_contacts_inviteText));
    textView.setGravity(Gravity.CENTER);
    textView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    textView.setText(LocaleController.getString("InviteToTelegram", R.string.InviteToTelegram).toUpperCase());
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
    updateHint();
    adapter.notifyDataSetChanged();
    return fragmentView;
}
Also used : ContactsController(org.telegram.messenger.ContactsController) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerListView(org.telegram.ui.Components.RecyclerListView) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) Menu(android.view.Menu) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) InviteUserCell(org.telegram.ui.Cells.InviteUserCell) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) MenuItem(android.view.MenuItem) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) Intent(android.content.Intent) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) MotionEvent(android.view.MotionEvent) GroupCreateDividerItemDecoration(org.telegram.ui.Components.GroupCreateDividerItemDecoration) ScrollView(android.widget.ScrollView) ActionMode(android.view.ActionMode) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayout(android.widget.LinearLayout) GroupCreateSpan(org.telegram.ui.Components.GroupCreateSpan)

Example 4 with EmptyTextProgressView

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

the class CountrySelectActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            searching = true;
        }

        @Override
        public void onSearchCollapse() {
            searchListViewAdapter.search(null);
            searching = false;
            searchWas = false;
            listView.setAdapter(listViewAdapter);
            listView.setFastScrollVisible(true);
        }

        @Override
        public void onTextChanged(EditText editText) {
            String text = editText.getText().toString();
            searchListViewAdapter.search(text);
            if (text.length() != 0) {
                searchWas = true;
            }
        }
    });
    item.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    searching = false;
    searchWas = false;
    listViewAdapter = new CountryAdapter(context, existingCountries);
    searchListViewAdapter = new CountrySearchAdapter(context, listViewAdapter.getCountries());
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    emptyView = new EmptyTextProgressView(context);
    emptyView.showTextView();
    emptyView.setShowAtCenter(true);
    emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView = new RecyclerListView(context);
    listView.setSectionsType(1);
    listView.setEmptyView(emptyView);
    listView.setVerticalScrollBarEnabled(false);
    listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setAdapter(listViewAdapter);
    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) -> {
        Country country;
        if (searching && searchWas) {
            country = searchListViewAdapter.getItem(position);
        } else {
            int section = listViewAdapter.getSectionForPosition(position);
            int row = listViewAdapter.getPositionInSectionForPosition(position);
            if (row < 0 || section < 0) {
                return;
            }
            country = listViewAdapter.getItem(section, row);
        }
        if (position < 0) {
            return;
        }
        finishFragment();
        if (country != null && delegate != null) {
            delegate.didSelectCountry(country);
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }
    });
    return fragmentView;
}
Also used : EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) ActionBar(org.telegram.ui.ActionBar.ActionBar)

Example 5 with EmptyTextProgressView

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

the class FilterUsersActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    searchWas = false;
    allSpans.clear();
    selectedContacts.clear();
    currentDeletingSpan = null;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (isInclude) {
        actionBar.setTitle(LocaleController.getString("FilterAlwaysShow", R.string.FilterAlwaysShow));
    } else {
        actionBar.setTitle(LocaleController.getString("FilterNeverShow", R.string.FilterNeverShow));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                onDonePressed(true);
            }
        }
    });
    fragmentView = new ViewGroup(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(width, height);
            int maxSize;
            if (AndroidUtilities.isTablet() || height > width) {
                maxSize = AndroidUtilities.dp(144);
            } else {
                maxSize = AndroidUtilities.dp(56);
            }
            scrollView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.AT_MOST));
            listView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight(), MeasureSpec.EXACTLY));
            emptyView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight(), MeasureSpec.EXACTLY));
            if (floatingButton != null) {
                int w = AndroidUtilities.dp(Build.VERSION.SDK_INT >= 21 ? 56 : 60);
                floatingButton.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY));
            }
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            scrollView.layout(0, 0, scrollView.getMeasuredWidth(), scrollView.getMeasuredHeight());
            listView.layout(0, scrollView.getMeasuredHeight(), listView.getMeasuredWidth(), scrollView.getMeasuredHeight() + listView.getMeasuredHeight());
            emptyView.layout(0, scrollView.getMeasuredHeight(), emptyView.getMeasuredWidth(), scrollView.getMeasuredHeight() + emptyView.getMeasuredHeight());
            if (floatingButton != null) {
                int l = LocaleController.isRTL ? AndroidUtilities.dp(14) : (right - left) - AndroidUtilities.dp(14) - floatingButton.getMeasuredWidth();
                int t = bottom - top - AndroidUtilities.dp(14) - floatingButton.getMeasuredHeight();
                floatingButton.layout(l, t, l + floatingButton.getMeasuredWidth(), t + floatingButton.getMeasuredHeight());
            }
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == listView || child == emptyView) {
                parentLayout.drawHeaderShadow(canvas, scrollView.getMeasuredHeight());
            }
            return result;
        }
    };
    ViewGroup frameLayout = (ViewGroup) fragmentView;
    scrollView = new ScrollView(context) {

        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (ignoreScrollEvent) {
                ignoreScrollEvent = false;
                return false;
            }
            rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
            rectangle.top += fieldY + AndroidUtilities.dp(20);
            rectangle.bottom += fieldY + AndroidUtilities.dp(50);
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }
    };
    scrollView.setVerticalScrollBarEnabled(false);
    AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_windowBackgroundWhite));
    frameLayout.addView(scrollView);
    spansContainer = new SpansContainer(context);
    scrollView.addView(spansContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    spansContainer.setOnClickListener(v -> {
        editText.clearFocus();
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    });
    editText = new EditTextBoldCursor(context) {

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (currentDeletingSpan != null) {
                currentDeletingSpan.cancelDeleteAnimation();
                currentDeletingSpan = null;
            }
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!AndroidUtilities.showKeyboard(this)) {
                    clearFocus();
                    requestFocus();
                }
            }
            return super.onTouchEvent(event);
        }
    };
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setHintColor(Theme.getColor(Theme.key_groupcreate_hintText));
    editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorColor(Theme.getColor(Theme.key_groupcreate_cursor));
    editText.setCursorWidth(1.5f);
    editText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    editText.setSingleLine(true);
    editText.setBackgroundDrawable(null);
    editText.setVerticalScrollBarEnabled(false);
    editText.setHorizontalScrollBarEnabled(false);
    editText.setTextIsSelectable(false);
    editText.setPadding(0, 0, 0, 0);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    editText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    spansContainer.addView(editText);
    editText.setHintText(LocaleController.getString("SearchForPeopleAndGroups", R.string.SearchForPeopleAndGroups));
    editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    // editText.setOnEditorActionListener((v, actionId, event) -> actionId == EditorInfo.IME_ACTION_DONE && onDonePressed(true));
    editText.setOnKeyListener(new View.OnKeyListener() {

        private boolean wasEmpty;

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    wasEmpty = editText.length() == 0;
                } else if (event.getAction() == KeyEvent.ACTION_UP && wasEmpty && !allSpans.isEmpty()) {
                    GroupCreateSpan span = allSpans.get(allSpans.size() - 1);
                    spansContainer.removeSpan(span);
                    if (span.getUid() == Integer.MIN_VALUE) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_CONTACTS;
                    } else if (span.getUid() == Integer.MIN_VALUE + 1) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS;
                    } else if (span.getUid() == Integer.MIN_VALUE + 2) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_GROUPS;
                    } else if (span.getUid() == Integer.MIN_VALUE + 3) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_CHANNELS;
                    } else if (span.getUid() == Integer.MIN_VALUE + 4) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_BOTS;
                    } else if (span.getUid() == Integer.MIN_VALUE + 5) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED;
                    } else if (span.getUid() == Integer.MIN_VALUE + 6) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_READ;
                    } else if (span.getUid() == Integer.MIN_VALUE + 7) {
                        filterFlags &= ~MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED;
                    }
                    updateHint();
                    checkVisibleRows();
                    return true;
                }
            }
            return false;
        }
    });
    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editText.length() != 0) {
                if (!adapter.searching) {
                    searching = true;
                    searchWas = true;
                    adapter.setSearching(true);
                    listView.setFastScrollVisible(false);
                    listView.setVerticalScrollBarEnabled(true);
                    emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                    emptyView.showProgress();
                }
                adapter.searchDialogs(editText.getText().toString());
            } else {
                closeSearch();
            }
        }
    });
    emptyView = new EmptyTextProgressView(context);
    if (ContactsController.getInstance(currentAccount).isLoadingContacts()) {
        emptyView.showProgress();
    } else {
        emptyView.showTextView();
    }
    emptyView.setShowAtCenter(true);
    emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
    frameLayout.addView(emptyView);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    listView = new RecyclerListView(context);
    listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
    listView.setEmptyView(emptyView);
    listView.setAdapter(adapter = new GroupCreateAdapter(context));
    listView.setLayoutManager(linearLayoutManager);
    listView.setVerticalScrollBarEnabled(false);
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT);
    listView.addItemDecoration(new ItemDecoration());
    frameLayout.addView(listView);
    listView.setOnItemClickListener((view, position) -> {
        if (view instanceof GroupCreateUserCell) {
            GroupCreateUserCell cell = (GroupCreateUserCell) view;
            Object object = cell.getObject();
            long id;
            if (object instanceof String) {
                int flag;
                if (isInclude) {
                    if (position == 1) {
                        flag = MessagesController.DIALOG_FILTER_FLAG_CONTACTS;
                        id = Integer.MIN_VALUE;
                    } else if (position == 2) {
                        flag = MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS;
                        id = Integer.MIN_VALUE + 1;
                    } else if (position == 3) {
                        flag = MessagesController.DIALOG_FILTER_FLAG_GROUPS;
                        id = Integer.MIN_VALUE + 2;
                    } else if (position == 4) {
                        flag = MessagesController.DIALOG_FILTER_FLAG_CHANNELS;
                        id = Integer.MIN_VALUE + 3;
                    } else {
                        flag = MessagesController.DIALOG_FILTER_FLAG_BOTS;
                        id = Integer.MIN_VALUE + 4;
                    }
                } else {
                    if (position == 1) {
                        flag = MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED;
                        id = Integer.MIN_VALUE + 5;
                    } else if (position == 2) {
                        flag = MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_READ;
                        id = Integer.MIN_VALUE + 6;
                    } else {
                        flag = MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED;
                        id = Integer.MIN_VALUE + 7;
                    }
                }
                if (cell.isChecked()) {
                    filterFlags &= ~flag;
                } else {
                    filterFlags |= flag;
                }
            } else {
                if (object instanceof TLRPC.User) {
                    id = ((TLRPC.User) object).id;
                } else if (object instanceof TLRPC.Chat) {
                    id = -((TLRPC.Chat) object).id;
                } else {
                    return;
                }
            }
            boolean exists;
            if (exists = selectedContacts.indexOfKey(id) >= 0) {
                GroupCreateSpan span = selectedContacts.get(id);
                spansContainer.removeSpan(span);
            } else {
                if (!(object instanceof String) && selectedCount >= 100) {
                    return;
                }
                if (object instanceof TLRPC.User) {
                    TLRPC.User user = (TLRPC.User) object;
                    MessagesController.getInstance(currentAccount).putUser(user, !searching);
                } else if (object instanceof TLRPC.Chat) {
                    TLRPC.Chat chat = (TLRPC.Chat) object;
                    MessagesController.getInstance(currentAccount).putChat(chat, !searching);
                }
                GroupCreateSpan span = new GroupCreateSpan(editText.getContext(), object);
                spansContainer.addSpan(span, true);
                span.setOnClickListener(FilterUsersActivity.this);
            }
            updateHint();
            if (searching || searchWas) {
                AndroidUtilities.showKeyboard(editText);
            } else {
                cell.setChecked(!exists, true);
            }
            if (editText.length() > 0) {
                editText.setText(null);
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(editText);
            }
        }
    });
    floatingButton = new ImageView(context);
    floatingButton.setScaleType(ImageView.ScaleType.CENTER);
    Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        drawable = combinedDrawable;
    }
    floatingButton.setBackgroundDrawable(drawable);
    floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
    floatingButton.setImageResource(R.drawable.floating_check);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
        floatingButton.setStateListAnimator(animator);
        floatingButton.setOutlineProvider(new ViewOutlineProvider() {

            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    frameLayout.addView(floatingButton);
    floatingButton.setOnClickListener(v -> onDonePressed(true));
    /*floatingButton.setVisibility(View.INVISIBLE);
        floatingButton.setScaleX(0.0f);
        floatingButton.setScaleY(0.0f);
        floatingButton.setAlpha(0.0f);*/
    floatingButton.setContentDescription(LocaleController.getString("Next", R.string.Next));
    for (int position = 1, N = (isInclude ? 5 : 3); position <= N; position++) {
        int id;
        int flag;
        Object object;
        if (isInclude) {
            if (position == 1) {
                object = "contacts";
                flag = MessagesController.DIALOG_FILTER_FLAG_CONTACTS;
            } else if (position == 2) {
                object = "non_contacts";
                flag = MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS;
            } else if (position == 3) {
                object = "groups";
                flag = MessagesController.DIALOG_FILTER_FLAG_GROUPS;
            } else if (position == 4) {
                object = "channels";
                flag = MessagesController.DIALOG_FILTER_FLAG_CHANNELS;
            } else {
                object = "bots";
                flag = MessagesController.DIALOG_FILTER_FLAG_BOTS;
            }
        } else {
            if (position == 1) {
                object = "muted";
                flag = MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED;
            } else if (position == 2) {
                object = "read";
                flag = MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_READ;
            } else {
                object = "archived";
                flag = MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED;
            }
        }
        if ((filterFlags & flag) != 0) {
            GroupCreateSpan span = new GroupCreateSpan(editText.getContext(), object);
            spansContainer.addSpan(span, false);
            span.setOnClickListener(FilterUsersActivity.this);
        }
    }
    if (initialIds != null && !initialIds.isEmpty()) {
        TLObject object;
        for (int a = 0, N = initialIds.size(); a < N; a++) {
            Long id = initialIds.get(a);
            if (id > 0) {
                object = getMessagesController().getUser(id);
            } else {
                object = getMessagesController().getChat(-id);
            }
            if (object == null) {
                continue;
            }
            GroupCreateSpan span = new GroupCreateSpan(editText.getContext(), object);
            spansContainer.addSpan(span, false);
            span.setOnClickListener(FilterUsersActivity.this);
        }
    }
    updateHint();
    return fragmentView;
}
Also used : LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) ImageView(android.widget.ImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) ActionMode(android.view.ActionMode) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) TLObject(org.telegram.tgnet.TLObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) GroupCreateSpan(org.telegram.ui.Components.GroupCreateSpan) StateListAnimator(android.animation.StateListAnimator) GroupCreateUserCell(org.telegram.ui.Cells.GroupCreateUserCell) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Menu(android.view.Menu) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) Outline(android.graphics.Outline) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) ScrollView(android.widget.ScrollView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) ScrollView(android.widget.ScrollView) TLObject(org.telegram.tgnet.TLObject) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

EmptyTextProgressView (org.telegram.ui.Components.EmptyTextProgressView)18 ActionBar (org.telegram.ui.ActionBar.ActionBar)17 RecyclerListView (org.telegram.ui.Components.RecyclerListView)17 FrameLayout (android.widget.FrameLayout)16 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)15 TextView (android.widget.TextView)13 RecyclerView (androidx.recyclerview.widget.RecyclerView)13 TLRPC (org.telegram.tgnet.TLRPC)10 ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)10 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)10 View (android.view.View)9 ViewGroup (android.view.ViewGroup)9 EditText (android.widget.EditText)9 ActionBarMenuItem (org.telegram.ui.ActionBar.ActionBarMenuItem)9 SharedPreferences (android.content.SharedPreferences)7 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)7 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 Intent (android.content.Intent)6 Bundle (android.os.Bundle)6