Search in sources :

Example 21 with RecyclerListView

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

the class DialogsActivity method updateVisibleRows.

private void updateVisibleRows(int mask, boolean animated) {
    if ((dialogsListFrozen && (mask & MessagesController.UPDATE_MASK_REORDER) == 0) || isPaused) {
        return;
    }
    for (int c = 0; c < 3; c++) {
        RecyclerListView list;
        if (c == 2) {
            list = searchViewPager != null ? searchViewPager.searchListView : null;
        } else if (viewPages != null) {
            list = c < viewPages.length ? viewPages[c].listView : null;
            if (list != null && viewPages[c].getVisibility() != View.VISIBLE) {
                continue;
            }
        } else {
            continue;
        }
        if (list == null) {
            continue;
        }
        int count = list.getChildCount();
        for (int a = 0; a < count; a++) {
            View child = list.getChildAt(a);
            if (child instanceof DialogCell) {
                if (list.getAdapter() != searchViewPager.dialogsSearchAdapter) {
                    DialogCell cell = (DialogCell) child;
                    if ((mask & MessagesController.UPDATE_MASK_REORDER) != 0) {
                        cell.onReorderStateChanged(actionBar.isActionModeShowed(), true);
                        if (dialogsListFrozen) {
                            continue;
                        }
                    }
                    if ((mask & MessagesController.UPDATE_MASK_CHECK) != 0) {
                        cell.setChecked(false, (mask & MessagesController.UPDATE_MASK_CHAT) != 0);
                    } else {
                        if ((mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) != 0) {
                            cell.checkCurrentDialogIndex(dialogsListFrozen);
                            if (viewPages[c].isDefaultDialogType() && AndroidUtilities.isTablet()) {
                                cell.setDialogSelected(cell.getDialogId() == openedDialogId);
                            }
                        } else if ((mask & MessagesController.UPDATE_MASK_SELECT_DIALOG) != 0) {
                            if (viewPages[c].isDefaultDialogType() && AndroidUtilities.isTablet()) {
                                cell.setDialogSelected(cell.getDialogId() == openedDialogId);
                            }
                        } else {
                            cell.update(mask, animated);
                        }
                        if (selectedDialogs != null) {
                            cell.setChecked(selectedDialogs.contains(cell.getDialogId()), false);
                        }
                    }
                }
            }
            if (child instanceof UserCell) {
                ((UserCell) child).update(mask);
            } else if (child instanceof ProfileSearchCell) {
                ProfileSearchCell cell = (ProfileSearchCell) child;
                cell.update(mask);
                if (selectedDialogs != null) {
                    cell.setChecked(selectedDialogs.contains(cell.getDialogId()), false);
                }
            }
            if (dialogsListFrozen) {
                continue;
            }
            if (child instanceof RecyclerListView) {
                RecyclerListView innerListView = (RecyclerListView) child;
                int count2 = innerListView.getChildCount();
                for (int b = 0; b < count2; b++) {
                    View child2 = innerListView.getChildAt(b);
                    if (child2 instanceof HintDialogCell) {
                        ((HintDialogCell) child2).update(mask);
                    }
                }
            }
        }
    }
}
Also used : DialogCell(org.telegram.ui.Cells.DialogCell) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ImageView(android.widget.ImageView) FilterTabsView(org.telegram.ui.Components.FilterTabsView) UndoView(org.telegram.ui.Components.UndoView) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) FragmentContextView(org.telegram.ui.Components.FragmentContextView) ScrollView(android.widget.ScrollView) FiltersView(org.telegram.ui.Adapters.FiltersView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) BackupImageView(org.telegram.ui.Components.BackupImageView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) NumberTextView(org.telegram.ui.Components.NumberTextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) UserCell(org.telegram.ui.Cells.UserCell) DrawerUserCell(org.telegram.ui.Cells.DrawerUserCell) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 22 with RecyclerListView

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

the class GroupStickersActivity method createView.

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

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }
                donePressed = true;
                if (searching) {
                    showEditDoneProgress(true);
                    return;
                }
                saveStickerSet();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
    progressView = new ContextProgressView(context, 1);
    progressView.setAlpha(0.0f);
    progressView.setScaleX(0.1f);
    progressView.setScaleY(0.1f);
    progressView.setVisibility(View.INVISIBLE);
    doneItem.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    nameContainer = new LinearLayout(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onDraw(Canvas canvas) {
            if (selectedStickerSet != null) {
                canvas.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1, Theme.dividerPaint);
            }
        }
    };
    nameContainer.setWeightSum(1.0f);
    nameContainer.setWillNotDraw(false);
    nameContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    nameContainer.setOrientation(LinearLayout.HORIZONTAL);
    nameContainer.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(14), 0);
    editText = new EditTextBoldCursor(context);
    editText.setText(MessagesController.getInstance(currentAccount).linkPrefix + "/addstickers/");
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    editText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setEnabled(false);
    editText.setFocusable(false);
    editText.setBackgroundDrawable(null);
    editText.setPadding(0, 0, 0, 0);
    editText.setGravity(Gravity.CENTER_VERTICAL);
    editText.setSingleLine(true);
    editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    nameContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 42));
    usernameTextView = new EditTextBoldCursor(context);
    usernameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    usernameTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    usernameTextView.setCursorSize(AndroidUtilities.dp(20));
    usernameTextView.setCursorWidth(1.5f);
    usernameTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    usernameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    usernameTextView.setMaxLines(1);
    usernameTextView.setLines(1);
    usernameTextView.setBackgroundDrawable(null);
    usernameTextView.setPadding(0, 0, 0, 0);
    usernameTextView.setSingleLine(true);
    usernameTextView.setGravity(Gravity.CENTER_VERTICAL);
    usernameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    usernameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    usernameTextView.setHint(LocaleController.getString("ChooseStickerSetPlaceholder", R.string.ChooseStickerSetPlaceholder));
    usernameTextView.addTextChangedListener(new TextWatcher() {

        boolean ignoreTextChange;

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (eraseImageView != null) {
                eraseImageView.setVisibility(s.length() > 0 ? View.VISIBLE : View.INVISIBLE);
            }
            if (ignoreTextChange || ignoreTextChanges) {
                return;
            }
            if (s.length() > 5) {
                ignoreTextChange = true;
                try {
                    Uri uri = Uri.parse(s.toString());
                    if (uri != null) {
                        List<String> segments = uri.getPathSegments();
                        if (segments.size() == 2) {
                            if (segments.get(0).toLowerCase().equals("addstickers")) {
                                usernameTextView.setText(segments.get(1));
                                usernameTextView.setSelection(usernameTextView.length());
                            }
                        }
                    }
                } catch (Exception ignore) {
                }
                ignoreTextChange = false;
            }
            resolveStickerSet();
        }
    });
    nameContainer.addView(usernameTextView, LayoutHelper.createLinear(0, 42, 1.0f));
    eraseImageView = new ImageView(context);
    eraseImageView.setScaleType(ImageView.ScaleType.CENTER);
    eraseImageView.setImageResource(R.drawable.ic_close_white);
    eraseImageView.setPadding(AndroidUtilities.dp(16), 0, 0, 0);
    eraseImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3), PorterDuff.Mode.MULTIPLY));
    eraseImageView.setVisibility(View.INVISIBLE);
    eraseImageView.setOnClickListener(v -> {
        searchWas = false;
        selectedStickerSet = null;
        usernameTextView.setText("");
        updateRows();
    });
    nameContainer.addView(eraseImageView, LayoutHelper.createLinear(42, 42, 0.0f));
    if (info != null && info.stickerset != null) {
        ignoreTextChanges = true;
        usernameTextView.setText(info.stickerset.short_name);
        usernameTextView.setSelection(usernameTextView.length());
        ignoreTextChanges = false;
    }
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    listView.setFocusable(true);
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    layoutManager = new LinearLayoutManager(context) {

        @Override
        public boolean requestChildRectangleOnScreen(RecyclerView parent, View child, Rect rect, boolean immediate, boolean focusedChildVisible) {
            return false;
        }

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    };
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    listView.setLayoutManager(layoutManager);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (getParentActivity() == null) {
            return;
        }
        if (position == selectedStickerRow) {
            if (selectedStickerSet == null) {
                return;
            }
            showDialog(new StickersAlert(getParentActivity(), GroupStickersActivity.this, null, selectedStickerSet, null));
        } else if (position >= stickersStartRow && position < stickersEndRow) {
            boolean needScroll = selectedStickerRow == -1;
            int row = layoutManager.findFirstVisibleItemPosition();
            int top = Integer.MAX_VALUE;
            RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.findViewHolderForAdapterPosition(row);
            if (holder != null) {
                top = holder.itemView.getTop();
            }
            selectedStickerSet = MediaDataController.getInstance(currentAccount).getStickerSets(MediaDataController.TYPE_IMAGE).get(position - stickersStartRow);
            ignoreTextChanges = true;
            usernameTextView.setText(selectedStickerSet.set.short_name);
            usernameTextView.setSelection(usernameTextView.length());
            ignoreTextChanges = false;
            AndroidUtilities.hideKeyboard(usernameTextView);
            updateRows();
            if (needScroll && top != Integer.MAX_VALUE) {
                layoutManager.scrollToPositionWithOffset(row + 1, top);
            }
        }
    });
    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) {
        }
    });
    return fragmentView;
}
Also used : ContextProgressView(org.telegram.ui.Components.ContextProgressView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Uri(android.net.Uri) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) StickersAlert(org.telegram.ui.Components.StickersAlert) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayout(android.widget.LinearLayout)

Example 23 with RecyclerListView

use of org.telegram.ui.Components.RecyclerListView 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 24 with RecyclerListView

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

the class DataUsageActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setTitle(LocaleController.getString("NetworkUsage", R.string.NetworkUsage));
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }
    actionBar.setExtraHeight(AndroidUtilities.dp(44));
    actionBar.setAllowOverlayTitle(false);
    actionBar.setAddToContainer(false);
    actionBar.setClipContent(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    hasOwnBackground = true;
    mobileAdapter = new ListAdapter(context, 0);
    wifiAdapter = new ListAdapter(context, 1);
    roamingAdapter = new ListAdapter(context, 2);
    scrollSlidingTextTabStrip = new ScrollSlidingTextTabStrip(context);
    scrollSlidingTextTabStrip.setUseSameWidth(true);
    actionBar.addView(scrollSlidingTextTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 44, Gravity.LEFT | Gravity.BOTTOM));
    scrollSlidingTextTabStrip.setDelegate(new ScrollSlidingTextTabStrip.ScrollSlidingTabStripDelegate() {

        @Override
        public void onPageSelected(int id, boolean forward) {
            if (viewPages[0].selectedType == id) {
                return;
            }
            swipeBackEnabled = id == scrollSlidingTextTabStrip.getFirstTabId();
            viewPages[1].selectedType = id;
            viewPages[1].setVisibility(View.VISIBLE);
            switchToCurrentSelectedMode(true);
            animatingForward = forward;
        }

        @Override
        public void onPageScrolled(float progress) {
            if (progress == 1 && viewPages[1].getVisibility() != View.VISIBLE) {
                return;
            }
            if (animatingForward) {
                viewPages[0].setTranslationX(-progress * viewPages[0].getMeasuredWidth());
                viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() - progress * viewPages[0].getMeasuredWidth());
            } else {
                viewPages[0].setTranslationX(progress * viewPages[0].getMeasuredWidth());
                viewPages[1].setTranslationX(progress * viewPages[0].getMeasuredWidth() - viewPages[0].getMeasuredWidth());
            }
            if (progress == 1) {
                ViewPage tempPage = viewPages[0];
                viewPages[0] = viewPages[1];
                viewPages[1] = tempPage;
                viewPages[1].setVisibility(View.GONE);
            }
        }
    });
    ViewConfiguration configuration = ViewConfiguration.get(context);
    maximumVelocity = configuration.getScaledMaximumFlingVelocity();
    FrameLayout frameLayout;
    fragmentView = frameLayout = new FrameLayout(context) {

        private int startedTrackingPointerId;

        private boolean startedTracking;

        private boolean maybeStartTracking;

        private int startedTrackingX;

        private int startedTrackingY;

        private VelocityTracker velocityTracker;

        private boolean globalIgnoreLayout;

        private boolean prepareForMoving(MotionEvent ev, boolean forward) {
            int id = scrollSlidingTextTabStrip.getNextPageId(forward);
            if (id < 0) {
                return false;
            }
            getParent().requestDisallowInterceptTouchEvent(true);
            maybeStartTracking = false;
            startedTracking = true;
            startedTrackingX = (int) ev.getX();
            actionBar.setEnabled(false);
            scrollSlidingTextTabStrip.setEnabled(false);
            viewPages[1].selectedType = id;
            viewPages[1].setVisibility(View.VISIBLE);
            animatingForward = forward;
            switchToCurrentSelectedMode(true);
            if (forward) {
                viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
            } else {
                viewPages[1].setTranslationX(-viewPages[0].getMeasuredWidth());
            }
            return true;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(widthSize, heightSize);
            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar.getMeasuredHeight();
            globalIgnoreLayout = true;
            for (int a = 0; a < viewPages.length; a++) {
                if (viewPages[a] == null) {
                    continue;
                }
                if (viewPages[a].listView != null) {
                    viewPages[a].listView.setPadding(0, actionBarHeight, 0, AndroidUtilities.dp(4));
                }
            }
            globalIgnoreLayout = false;
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE || child == actionBar) {
                    continue;
                }
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
            }
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            if (parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas, actionBar.getMeasuredHeight() + (int) actionBar.getTranslationY());
            }
        }

        @Override
        public void requestLayout() {
            if (globalIgnoreLayout) {
                return;
            }
            super.requestLayout();
        }

        public boolean checkTabsAnimationInProgress() {
            if (tabsAnimationInProgress) {
                boolean cancel = false;
                if (backAnimation) {
                    if (Math.abs(viewPages[0].getTranslationX()) < 1) {
                        viewPages[0].setTranslationX(0);
                        viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? 1 : -1));
                        cancel = true;
                    }
                } else if (Math.abs(viewPages[1].getTranslationX()) < 1) {
                    viewPages[0].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? -1 : 1));
                    viewPages[1].setTranslationX(0);
                    cancel = true;
                }
                if (cancel) {
                    if (tabsAnimation != null) {
                        tabsAnimation.cancel();
                        tabsAnimation = null;
                    }
                    tabsAnimationInProgress = false;
                }
                return tabsAnimationInProgress;
            }
            return false;
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return checkTabsAnimationInProgress() || scrollSlidingTextTabStrip.isAnimatingIndicator() || onTouchEvent(ev);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            backgroundPaint.setColor(Theme.getColor(Theme.key_windowBackgroundGray));
            canvas.drawRect(0, actionBar.getMeasuredHeight() + actionBar.getTranslationY(), getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
        }

        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            if (!parentLayout.checkTransitionAnimation() && !checkTabsAnimationInProgress()) {
                if (ev != null) {
                    if (velocityTracker == null) {
                        velocityTracker = VelocityTracker.obtain();
                    }
                    velocityTracker.addMovement(ev);
                }
                if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
                    startedTrackingPointerId = ev.getPointerId(0);
                    maybeStartTracking = true;
                    startedTrackingX = (int) ev.getX();
                    startedTrackingY = (int) ev.getY();
                    velocityTracker.clear();
                } else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
                    int dx = (int) (ev.getX() - startedTrackingX);
                    int dy = Math.abs((int) ev.getY() - startedTrackingY);
                    if (startedTracking && (animatingForward && dx > 0 || !animatingForward && dx < 0)) {
                        if (!prepareForMoving(ev, dx < 0)) {
                            maybeStartTracking = true;
                            startedTracking = false;
                            viewPages[0].setTranslationX(0);
                            viewPages[1].setTranslationX(animatingForward ? viewPages[0].getMeasuredWidth() : -viewPages[0].getMeasuredWidth());
                            scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, 0);
                        }
                    }
                    if (maybeStartTracking && !startedTracking) {
                        float touchSlop = AndroidUtilities.getPixelsInCM(0.3f, true);
                        if (Math.abs(dx) >= touchSlop && Math.abs(dx) > dy) {
                            prepareForMoving(ev, dx < 0);
                        }
                    } else if (startedTracking) {
                        if (animatingForward) {
                            viewPages[0].setTranslationX(dx);
                            viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() + dx);
                        } else {
                            viewPages[0].setTranslationX(dx);
                            viewPages[1].setTranslationX(dx - viewPages[0].getMeasuredWidth());
                        }
                        float scrollProgress = Math.abs(dx) / (float) viewPages[0].getMeasuredWidth();
                        scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                    }
                } else if (ev == null || ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
                    velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
                    float velX;
                    float velY;
                    if (ev != null && ev.getAction() != MotionEvent.ACTION_CANCEL) {
                        velX = velocityTracker.getXVelocity();
                        velY = velocityTracker.getYVelocity();
                        if (!startedTracking) {
                            if (Math.abs(velX) >= 3000 && Math.abs(velX) > Math.abs(velY)) {
                                prepareForMoving(ev, velX < 0);
                            }
                        }
                    } else {
                        velX = 0;
                        velY = 0;
                    }
                    if (startedTracking) {
                        float x = viewPages[0].getX();
                        tabsAnimation = new AnimatorSet();
                        backAnimation = Math.abs(x) < viewPages[0].getMeasuredWidth() / 3.0f && (Math.abs(velX) < 3500 || Math.abs(velX) < Math.abs(velY));
                        float distToMove;
                        float dx;
                        if (backAnimation) {
                            dx = Math.abs(x);
                            if (animatingForward) {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, viewPages[1].getMeasuredWidth()));
                            } else {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, -viewPages[1].getMeasuredWidth()));
                            }
                        } else {
                            dx = viewPages[0].getMeasuredWidth() - Math.abs(x);
                            if (animatingForward) {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, -viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
                            } else {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
                            }
                        }
                        tabsAnimation.setInterpolator(interpolator);
                        int width = getMeasuredWidth();
                        int halfWidth = width / 2;
                        float distanceRatio = Math.min(1.0f, 1.0f * dx / (float) width);
                        float distance = (float) halfWidth + (float) halfWidth * AndroidUtilities.distanceInfluenceForSnapDuration(distanceRatio);
                        velX = Math.abs(velX);
                        int duration;
                        if (velX > 0) {
                            duration = 4 * Math.round(1000.0f * Math.abs(distance / velX));
                        } else {
                            float pageDelta = dx / getMeasuredWidth();
                            duration = (int) ((pageDelta + 1.0f) * 100.0f);
                        }
                        duration = Math.max(150, Math.min(duration, 600));
                        tabsAnimation.setDuration(duration);
                        tabsAnimation.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationEnd(Animator animator) {
                                tabsAnimation = null;
                                if (backAnimation) {
                                    viewPages[1].setVisibility(View.GONE);
                                } else {
                                    ViewPage tempPage = viewPages[0];
                                    viewPages[0] = viewPages[1];
                                    viewPages[1] = tempPage;
                                    viewPages[1].setVisibility(View.GONE);
                                    swipeBackEnabled = viewPages[0].selectedType == scrollSlidingTextTabStrip.getFirstTabId();
                                    scrollSlidingTextTabStrip.selectTabWithId(viewPages[0].selectedType, 1.0f);
                                }
                                tabsAnimationInProgress = false;
                                maybeStartTracking = false;
                                startedTracking = false;
                                actionBar.setEnabled(true);
                                scrollSlidingTextTabStrip.setEnabled(true);
                            }
                        });
                        tabsAnimation.start();
                        tabsAnimationInProgress = true;
                        startedTracking = false;
                    } else {
                        maybeStartTracking = false;
                        actionBar.setEnabled(true);
                        scrollSlidingTextTabStrip.setEnabled(true);
                    }
                    if (velocityTracker != null) {
                        velocityTracker.recycle();
                        velocityTracker = null;
                    }
                }
                return startedTracking;
            }
            return false;
        }
    };
    frameLayout.setWillNotDraw(false);
    int scrollToPositionOnRecreate = -1;
    int scrollToOffsetOnRecreate = 0;
    for (int a = 0; a < viewPages.length; a++) {
        if (a == 0) {
            if (viewPages[a] != null && viewPages[a].layoutManager != null) {
                scrollToPositionOnRecreate = viewPages[a].layoutManager.findFirstVisibleItemPosition();
                if (scrollToPositionOnRecreate != viewPages[a].layoutManager.getItemCount() - 1) {
                    RecyclerListView.Holder holder = (RecyclerListView.Holder) viewPages[a].listView.findViewHolderForAdapterPosition(scrollToPositionOnRecreate);
                    if (holder != null) {
                        scrollToOffsetOnRecreate = holder.itemView.getTop();
                    } else {
                        scrollToPositionOnRecreate = -1;
                    }
                } else {
                    scrollToPositionOnRecreate = -1;
                }
            }
        }
        final ViewPage ViewPage = new ViewPage(context) {

            @Override
            public void setTranslationX(float translationX) {
                super.setTranslationX(translationX);
                if (tabsAnimationInProgress) {
                    if (viewPages[0] == this) {
                        float scrollProgress = Math.abs(viewPages[0].getTranslationX()) / (float) viewPages[0].getMeasuredWidth();
                        scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                    }
                }
            }
        };
        frameLayout.addView(ViewPage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        viewPages[a] = ViewPage;
        final LinearLayoutManager layoutManager = viewPages[a].layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {

            @Override
            public boolean supportsPredictiveItemAnimations() {
                return false;
            }
        };
        RecyclerListView listView = new RecyclerListView(context);
        viewPages[a].listView = listView;
        viewPages[a].listView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
        viewPages[a].listView.setItemAnimator(null);
        viewPages[a].listView.setClipToPadding(false);
        viewPages[a].listView.setSectionsType(2);
        viewPages[a].listView.setLayoutManager(layoutManager);
        viewPages[a].addView(viewPages[a].listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        viewPages[a].listView.setOnItemClickListener((view, position) -> {
            if (getParentActivity() == null) {
                return;
            }
            ListAdapter adapter = (ListAdapter) listView.getAdapter();
            if (position == adapter.resetRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("ResetStatisticsAlertTitle", R.string.ResetStatisticsAlertTitle));
                builder.setMessage(LocaleController.getString("ResetStatisticsAlert", R.string.ResetStatisticsAlert));
                builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
                    StatsController.getInstance(currentAccount).resetStats(adapter.currentType);
                    adapter.notifyDataSetChanged();
                });
                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));
                }
            }
        });
        viewPages[a].listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState != RecyclerView.SCROLL_STATE_DRAGGING) {
                    int scrollY = (int) -actionBar.getTranslationY();
                    int actionBarHeight = ActionBar.getCurrentActionBarHeight();
                    if (scrollY != 0 && scrollY != actionBarHeight) {
                        if (scrollY < actionBarHeight / 2) {
                            viewPages[0].listView.smoothScrollBy(0, -scrollY);
                        } else {
                            viewPages[0].listView.smoothScrollBy(0, actionBarHeight - scrollY);
                        }
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (recyclerView == viewPages[0].listView) {
                    float currentTranslation = actionBar.getTranslationY();
                    float newTranslation = currentTranslation - dy;
                    if (newTranslation < -ActionBar.getCurrentActionBarHeight()) {
                        newTranslation = -ActionBar.getCurrentActionBarHeight();
                    } else if (newTranslation > 0) {
                        newTranslation = 0;
                    }
                    if (newTranslation != currentTranslation) {
                        setScrollY(newTranslation);
                    }
                }
            }
        });
        if (a == 0 && scrollToPositionOnRecreate != -1) {
            layoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
        }
        if (a != 0) {
            viewPages[a].setVisibility(View.GONE);
        }
    }
    frameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    updateTabs();
    switchToCurrentSelectedMode(false);
    swipeBackEnabled = scrollSlidingTextTabStrip.getCurrentTabId() == scrollSlidingTextTabStrip.getFirstTabId();
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) AnimatorSet(android.animation.AnimatorSet) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ViewConfiguration(android.view.ViewConfiguration) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView) ScrollSlidingTextTabStrip(org.telegram.ui.Components.ScrollSlidingTextTabStrip) ActionBar(org.telegram.ui.ActionBar.ActionBar) VelocityTracker(android.view.VelocityTracker) Canvas(android.graphics.Canvas) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 25 with RecyclerListView

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

the class ContentPreviewViewer method onInterceptTouchEvent.

public boolean onInterceptTouchEvent(MotionEvent event, final RecyclerListView listView, final int height, ContentPreviewViewerDelegate contentPreviewViewerDelegate, Theme.ResourcesProvider resourcesProvider) {
    delegate = contentPreviewViewerDelegate;
    this.resourcesProvider = resourcesProvider;
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        int count = listView.getChildCount();
        for (int a = 0; a < count; a++) {
            View view = null;
            if (listView instanceof RecyclerListView) {
                view = listView.getChildAt(a);
            }
            if (view == null) {
                return false;
            }
            int top = view.getTop();
            int bottom = view.getBottom();
            int left = view.getLeft();
            int right = view.getRight();
            if (top > y || bottom < y || left > x || right < x) {
                continue;
            }
            int contentType = CONTENT_TYPE_NONE;
            if (view instanceof StickerEmojiCell) {
                if (((StickerEmojiCell) view).showingBitmap()) {
                    contentType = CONTENT_TYPE_STICKER;
                    centerImage.setRoundRadius(0);
                }
            } else if (view instanceof StickerCell) {
                if (((StickerCell) view).showingBitmap()) {
                    contentType = CONTENT_TYPE_STICKER;
                    centerImage.setRoundRadius(0);
                }
            } else if (view instanceof ContextLinkCell) {
                ContextLinkCell cell = (ContextLinkCell) view;
                if (cell.showingBitmap()) {
                    if (cell.isSticker()) {
                        contentType = CONTENT_TYPE_STICKER;
                        centerImage.setRoundRadius(0);
                    } else if (cell.isGif()) {
                        contentType = CONTENT_TYPE_GIF;
                        centerImage.setRoundRadius(AndroidUtilities.dp(6));
                    }
                }
            }
            if (contentType == CONTENT_TYPE_NONE) {
                return false;
            }
            startX = x;
            startY = y;
            currentPreviewCell = view;
            int contentTypeFinal = contentType;
            openPreviewRunnable = () -> {
                if (openPreviewRunnable == null) {
                    return;
                }
                listView.setOnItemClickListener((RecyclerListView.OnItemClickListener) null);
                listView.requestDisallowInterceptTouchEvent(true);
                openPreviewRunnable = null;
                setParentActivity((Activity) listView.getContext());
                setKeyboardHeight(height);
                clearsInputField = false;
                if (currentPreviewCell instanceof StickerEmojiCell) {
                    StickerEmojiCell stickerEmojiCell = (StickerEmojiCell) currentPreviewCell;
                    open(stickerEmojiCell.getSticker(), stickerEmojiCell.getStickerPath(), stickerEmojiCell.getEmoji(), delegate != null ? delegate.getQuery(false) : null, null, contentTypeFinal, stickerEmojiCell.isRecent(), stickerEmojiCell.getParentObject(), resourcesProvider);
                    stickerEmojiCell.setScaled(true);
                } else if (currentPreviewCell instanceof StickerCell) {
                    StickerCell stickerCell = (StickerCell) currentPreviewCell;
                    open(stickerCell.getSticker(), null, null, delegate != null ? delegate.getQuery(false) : null, null, contentTypeFinal, false, stickerCell.getParentObject(), resourcesProvider);
                    stickerCell.setScaled(true);
                    clearsInputField = stickerCell.isClearsInputField();
                } else if (currentPreviewCell instanceof ContextLinkCell) {
                    ContextLinkCell contextLinkCell = (ContextLinkCell) currentPreviewCell;
                    open(contextLinkCell.getDocument(), null, null, delegate != null ? delegate.getQuery(true) : null, contextLinkCell.getBotInlineResult(), contentTypeFinal, false, contextLinkCell.getBotInlineResult() != null ? contextLinkCell.getInlineBot() : contextLinkCell.getParentObject(), resourcesProvider);
                    if (contentTypeFinal != CONTENT_TYPE_GIF) {
                        contextLinkCell.setScaled(true);
                    }
                }
                currentPreviewCell.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
            };
            AndroidUtilities.runOnUIThread(openPreviewRunnable, 200);
            return true;
        }
    }
    return false;
}
Also used : StickerCell(org.telegram.ui.Cells.StickerCell) StickerEmojiCell(org.telegram.ui.Cells.StickerEmojiCell) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) View(android.view.View) EmojiView(org.telegram.ui.Components.EmojiView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Aggregations

RecyclerListView (org.telegram.ui.Components.RecyclerListView)79 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)67 RecyclerView (androidx.recyclerview.widget.RecyclerView)60 ActionBar (org.telegram.ui.ActionBar.ActionBar)59 FrameLayout (android.widget.FrameLayout)58 View (android.view.View)54 TextView (android.widget.TextView)44 TLRPC (org.telegram.tgnet.TLRPC)40 ViewGroup (android.view.ViewGroup)36 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)35 Paint (android.graphics.Paint)34 ArrayList (java.util.ArrayList)33 ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)31 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)31 Canvas (android.graphics.Canvas)28 LocaleController (org.telegram.messenger.LocaleController)28 Theme (org.telegram.ui.ActionBar.Theme)28 Context (android.content.Context)27 AndroidUtilities (org.telegram.messenger.AndroidUtilities)27 R (org.telegram.messenger.R)27