Search in sources :

Example 16 with CombinedDrawable

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

the class ThemeDescription method setColor.

public void setColor(int color, boolean useDefault, boolean save) {
    if (save) {
        Theme.setColor(currentKey, color, useDefault);
    }
    currentColor = color;
    if (alphaOverride > 0) {
        color = Color.argb(alphaOverride, Color.red(color), Color.green(color), Color.blue(color));
    }
    if (paintToUpdate != null) {
        for (int a = 0; a < paintToUpdate.length; a++) {
            if ((changeFlags & FLAG_LINKCOLOR) != 0 && paintToUpdate[a] instanceof TextPaint) {
                ((TextPaint) paintToUpdate[a]).linkColor = color;
            } else {
                paintToUpdate[a].setColor(color);
            }
        }
    }
    if (drawablesToUpdate != null) {
        for (int a = 0; a < drawablesToUpdate.length; a++) {
            if (drawablesToUpdate[a] == null) {
                continue;
            }
            if (drawablesToUpdate[a] instanceof BackDrawable) {
                ((BackDrawable) drawablesToUpdate[a]).setColor(color);
            } else if (drawablesToUpdate[a] instanceof ScamDrawable) {
                ((ScamDrawable) drawablesToUpdate[a]).setColor(color);
            } else if (drawablesToUpdate[a] instanceof RLottieDrawable) {
                if (lottieLayerName != null) {
                    ((RLottieDrawable) drawablesToUpdate[a]).setLayerColor(lottieLayerName + ".**", color);
                }
            } else if (drawablesToUpdate[a] instanceof CombinedDrawable) {
                if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                    ((CombinedDrawable) drawablesToUpdate[a]).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                } else {
                    ((CombinedDrawable) drawablesToUpdate[a]).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                }
            } else if (drawablesToUpdate[a] instanceof AvatarDrawable) {
                ((AvatarDrawable) drawablesToUpdate[a]).setColor(color);
            } else if (drawablesToUpdate[a] instanceof AnimatedArrowDrawable) {
                ((AnimatedArrowDrawable) drawablesToUpdate[a]).setColor(color);
            } else {
                drawablesToUpdate[a].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
            }
        }
    }
    if (viewToInvalidate != null && listClasses == null && listClassesFieldName == null) {
        if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
            if ((changeFlags & FLAG_BACKGROUND) != 0) {
                Drawable background = viewToInvalidate.getBackground();
                if (background instanceof MessageBackgroundDrawable) {
                    ((MessageBackgroundDrawable) background).setColor(color);
                    ((MessageBackgroundDrawable) background).setCustomPaint(null);
                } else {
                    viewToInvalidate.setBackgroundColor(color);
                }
            }
            if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                    if (viewToInvalidate instanceof EditTextBoldCursor) {
                        ((EditTextBoldCursor) viewToInvalidate).setErrorLineColor(color);
                    }
                } else {
                    Drawable drawable = viewToInvalidate.getBackground();
                    if (drawable instanceof CombinedDrawable) {
                        if ((changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0) {
                            drawable = ((CombinedDrawable) drawable).getBackground();
                        } else {
                            drawable = ((CombinedDrawable) drawable).getIcon();
                        }
                    }
                    if (drawable != null) {
                        if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
                            Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                        } else if (drawable instanceof ShapeDrawable) {
                            ((ShapeDrawable) drawable).getPaint().setColor(color);
                        } else {
                            drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                        }
                    }
                }
            }
        }
    }
    if (viewToInvalidate instanceof ActionBar) {
        if ((changeFlags & FLAG_AB_ITEMSCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsColor(color, false);
        }
        if ((changeFlags & FLAG_AB_TITLECOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setTitleColor(color);
        }
        if ((changeFlags & FLAG_AB_SELECTORCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsBackgroundColor(color, false);
        }
        if ((changeFlags & FLAG_AB_AM_SELECTORCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsBackgroundColor(color, true);
        }
        if ((changeFlags & FLAG_AB_AM_ITEMSCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsColor(color, true);
        }
        if ((changeFlags & FLAG_AB_SUBTITLECOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setSubtitleColor(color);
        }
        if ((changeFlags & FLAG_AB_AM_BACKGROUND) != 0) {
            ((ActionBar) viewToInvalidate).setActionModeColor(color);
        }
        if ((changeFlags & FLAG_AB_AM_TOPBACKGROUND) != 0) {
            ((ActionBar) viewToInvalidate).setActionModeTopColor(color);
        }
        if ((changeFlags & FLAG_AB_SEARCHPLACEHOLDER) != 0) {
            ((ActionBar) viewToInvalidate).setSearchTextColor(color, true);
        }
        if ((changeFlags & FLAG_AB_SEARCH) != 0) {
            ((ActionBar) viewToInvalidate).setSearchTextColor(color, false);
        }
        if ((changeFlags & FLAG_AB_SUBMENUITEM) != 0) {
            ((ActionBar) viewToInvalidate).setPopupItemsColor(color, (changeFlags & FLAG_IMAGECOLOR) != 0, false);
        }
        if ((changeFlags & FLAG_AB_SUBMENUBACKGROUND) != 0) {
            ((ActionBar) viewToInvalidate).setPopupBackgroundColor(color, false);
        }
    }
    if (viewToInvalidate instanceof VideoTimelineView) {
        ((VideoTimelineView) viewToInvalidate).setColor(color);
    }
    if (viewToInvalidate instanceof EmptyTextProgressView) {
        if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
            ((EmptyTextProgressView) viewToInvalidate).setTextColor(color);
        } else if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
            ((EmptyTextProgressView) viewToInvalidate).setProgressBarColor(color);
        }
    }
    if (viewToInvalidate instanceof RadialProgressView) {
        ((RadialProgressView) viewToInvalidate).setProgressColor(color);
    } else if (viewToInvalidate instanceof LineProgressView) {
        if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
            ((LineProgressView) viewToInvalidate).setProgressColor(color);
        } else {
            ((LineProgressView) viewToInvalidate).setBackColor(color);
        }
    } else if (viewToInvalidate instanceof ContextProgressView) {
        ((ContextProgressView) viewToInvalidate).updateColors();
    } else if (viewToInvalidate instanceof SeekBarView) {
        if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
            ((SeekBarView) viewToInvalidate).setOuterColor(color);
        }
    }
    if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
        if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
            if (viewToInvalidate instanceof TextView) {
                ((TextView) viewToInvalidate).setTextColor(color);
            } else if (viewToInvalidate instanceof NumberTextView) {
                ((NumberTextView) viewToInvalidate).setTextColor(color);
            } else if (viewToInvalidate instanceof SimpleTextView) {
                ((SimpleTextView) viewToInvalidate).setTextColor(color);
            } else if (viewToInvalidate instanceof ChatBigEmptyView) {
                ((ChatBigEmptyView) viewToInvalidate).setTextColor(color);
            }
        }
    }
    if ((changeFlags & FLAG_CURSORCOLOR) != 0) {
        if (viewToInvalidate instanceof EditTextBoldCursor) {
            ((EditTextBoldCursor) viewToInvalidate).setCursorColor(color);
        }
    }
    if ((changeFlags & FLAG_HINTTEXTCOLOR) != 0) {
        if (viewToInvalidate instanceof EditTextBoldCursor) {
            if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                ((EditTextBoldCursor) viewToInvalidate).setHeaderHintColor(color);
            } else {
                ((EditTextBoldCursor) viewToInvalidate).setHintColor(color);
            }
        } else if (viewToInvalidate instanceof EditText) {
            ((EditText) viewToInvalidate).setHintTextColor(color);
        }
    }
    if (viewToInvalidate != null && (changeFlags & FLAG_SERVICEBACKGROUND) != 0) {
    }
    if ((changeFlags & FLAG_IMAGECOLOR) != 0) {
        if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
            if (viewToInvalidate instanceof ImageView) {
                if ((changeFlags & FLAG_USEBACKGROUNDDRAWABLE) != 0) {
                    Drawable drawable = ((ImageView) viewToInvalidate).getDrawable();
                    if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
                        Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                    }
                } else {
                    ((ImageView) viewToInvalidate).setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                }
            } else if (viewToInvalidate instanceof BackupImageView) {
            // ((BackupImageView) viewToInvalidate).setResourceImageColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
            } else if (viewToInvalidate instanceof SimpleTextView) {
                SimpleTextView textView = (SimpleTextView) viewToInvalidate;
                textView.setSideDrawablesColor(color);
            } else if (viewToInvalidate instanceof TextView) {
                Drawable[] drawables = ((TextView) viewToInvalidate).getCompoundDrawables();
                if (drawables != null) {
                    for (int a = 0; a < drawables.length; a++) {
                        if (drawables[a] != null) {
                            drawables[a].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                        }
                    }
                }
            }
        }
    }
    if (viewToInvalidate instanceof ScrollView) {
        if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
            AndroidUtilities.setScrollViewEdgeEffectColor((ScrollView) viewToInvalidate, color);
        }
    }
    if (viewToInvalidate instanceof ViewPager) {
        if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
            AndroidUtilities.setViewPagerEdgeEffectColor((ViewPager) viewToInvalidate, color);
        }
    }
    if (viewToInvalidate instanceof RecyclerListView) {
        RecyclerListView recyclerListView = (RecyclerListView) viewToInvalidate;
        if ((changeFlags & FLAG_SELECTOR) != 0) {
            recyclerListView.setListSelectorColor(color);
        }
        if ((changeFlags & FLAG_FASTSCROLL) != 0) {
            recyclerListView.updateFastScrollColors();
        }
        if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
            recyclerListView.setGlowColor(color);
        }
        if ((changeFlags & FLAG_SECTIONS) != 0) {
            ArrayList<View> headers = recyclerListView.getHeaders();
            if (headers != null) {
                for (int a = 0; a < headers.size(); a++) {
                    processViewColor(headers.get(a), color);
                }
            }
            headers = recyclerListView.getHeadersCache();
            if (headers != null) {
                for (int a = 0; a < headers.size(); a++) {
                    processViewColor(headers.get(a), color);
                }
            }
            View header = recyclerListView.getPinnedHeader();
            if (header != null) {
                processViewColor(header, color);
            }
        }
    } else if (viewToInvalidate != null && (listClasses == null || listClasses.length == 0)) {
        if ((changeFlags & FLAG_SELECTOR) != 0) {
            viewToInvalidate.setBackgroundDrawable(Theme.getSelectorDrawable(false));
        } else if ((changeFlags & FLAG_SELECTORWHITE) != 0) {
            viewToInvalidate.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        }
    }
    if (listClasses != null) {
        if (viewToInvalidate instanceof RecyclerListView) {
            RecyclerListView recyclerListView = (RecyclerListView) viewToInvalidate;
            recyclerListView.getRecycledViewPool().clear();
            int count = recyclerListView.getHiddenChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(recyclerListView.getHiddenChildAt(a), color);
            }
            count = recyclerListView.getCachedChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(recyclerListView.getCachedChildAt(a), color);
            }
            count = recyclerListView.getAttachedScrapChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(recyclerListView.getAttachedScrapChildAt(a), color);
            }
        }
        if (viewToInvalidate instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) viewToInvalidate;
            int count = viewGroup.getChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(viewGroup.getChildAt(a), color);
            }
        }
        processViewColor(viewToInvalidate, color);
    }
    if (delegate != null) {
        delegate.didSetColor();
    }
    if (viewToInvalidate != null) {
        viewToInvalidate.invalidate();
    }
}
Also used : ContextProgressView(org.telegram.ui.Components.ContextProgressView) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) StateListDrawable(android.graphics.drawable.StateListDrawable) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ScamDrawable(org.telegram.ui.Components.ScamDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) BackupImageView(org.telegram.ui.Components.BackupImageView) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) NumberTextView(org.telegram.ui.Components.NumberTextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) VideoTimelineView(org.telegram.ui.Components.VideoTimelineView) EditText(android.widget.EditText) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) ViewGroup(android.view.ViewGroup) AnimatedArrowDrawable(org.telegram.ui.Components.AnimatedArrowDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) LetterDrawable(org.telegram.ui.Components.LetterDrawable) ScamDrawable(org.telegram.ui.Components.ScamDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) SeekBarView(org.telegram.ui.Components.SeekBarView) ViewPager(androidx.viewpager.widget.ViewPager) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) ContextProgressView(org.telegram.ui.Components.ContextProgressView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) VideoTimelineView(org.telegram.ui.Components.VideoTimelineView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) SeekBarView(org.telegram.ui.Components.SeekBarView) BackupImageView(org.telegram.ui.Components.BackupImageView) LineProgressView(org.telegram.ui.Components.LineProgressView) NumberTextView(org.telegram.ui.Components.NumberTextView) ScrollView(android.widget.ScrollView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) RippleDrawable(android.graphics.drawable.RippleDrawable) ScrollView(android.widget.ScrollView) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) LineProgressView(org.telegram.ui.Components.LineProgressView) AnimatedArrowDrawable(org.telegram.ui.Components.AnimatedArrowDrawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable)

Example 17 with CombinedDrawable

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

the class ThemeDescription method processViewColor.

private void processViewColor(View child, int color) {
    for (int b = 0; b < listClasses.length; b++) {
        if (listClasses[b].isInstance(child)) {
            child.invalidate();
            boolean passedCheck;
            if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, child)) {
                passedCheck = true;
                child.invalidate();
                if (listClassesFieldName == null && (changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                    Drawable drawable = child.getBackground();
                    if (drawable != null) {
                        if ((changeFlags & FLAG_CELLBACKGROUNDCOLOR) != 0) {
                            if (drawable instanceof CombinedDrawable) {
                                Drawable back = ((CombinedDrawable) drawable).getBackground();
                                if (back instanceof ColorDrawable) {
                                    ((ColorDrawable) back).setColor(color);
                                }
                            }
                        } else {
                            if (drawable instanceof CombinedDrawable) {
                                drawable = ((CombinedDrawable) drawable).getIcon();
                            } else if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
                                Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                            }
                            drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                        }
                    }
                } else if ((changeFlags & FLAG_CELLBACKGROUNDCOLOR) != 0) {
                    child.setBackgroundColor(color);
                } else if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
                    if (child instanceof TextView) {
                        ((TextView) child).setTextColor(color);
                    } else if (child instanceof AudioPlayerAlert.ClippingTextViewSwitcher) {
                        for (int i = 0; i < 2; i++) {
                            TextView textView = i == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) child).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) child).getNextTextView();
                            if (textView != null) {
                                textView.setTextColor(color);
                            }
                        }
                    }
                } else if ((changeFlags & FLAG_SERVICEBACKGROUND) != 0) {
                } else if ((changeFlags & FLAG_SELECTOR) != 0) {
                    child.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                } else if ((changeFlags & FLAG_SELECTORWHITE) != 0) {
                    child.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                }
            } else {
                passedCheck = false;
            }
            if (listClassesFieldName != null) {
                String key = listClasses[b] + "_" + listClassesFieldName[b];
                if (notFoundCachedFields != null && notFoundCachedFields.containsKey(key)) {
                    continue;
                }
                try {
                    Field field = cachedFields.get(key);
                    if (field == null) {
                        field = listClasses[b].getDeclaredField(listClassesFieldName[b]);
                        if (field != null) {
                            field.setAccessible(true);
                            cachedFields.put(key, field);
                        }
                    }
                    if (field != null) {
                        Object object = field.get(child);
                        if (object != null) {
                            if (!passedCheck && object instanceof View && !checkTag(currentKey, (View) object)) {
                                continue;
                            }
                            if (object instanceof View) {
                                ((View) object).invalidate();
                            }
                            if (lottieLayerName != null && object instanceof RLottieImageView) {
                                ((RLottieImageView) object).setLayerColor(lottieLayerName + ".**", color);
                            }
                            if ((changeFlags & FLAG_USEBACKGROUNDDRAWABLE) != 0 && object instanceof View) {
                                object = ((View) object).getBackground();
                            }
                            if ((changeFlags & FLAG_BACKGROUND) != 0 && object instanceof View) {
                                View view = (View) object;
                                Drawable background = view.getBackground();
                                if (background instanceof MessageBackgroundDrawable) {
                                    ((MessageBackgroundDrawable) background).setColor(color);
                                    ((MessageBackgroundDrawable) background).setCustomPaint(null);
                                } else {
                                    view.setBackgroundColor(color);
                                }
                            } else if (object instanceof EditTextCaption) {
                                if ((changeFlags & FLAG_HINTTEXTCOLOR) != 0) {
                                    ((EditTextCaption) object).setHintColor(color);
                                    ((EditTextCaption) object).setHintTextColor(color);
                                } else if ((changeFlags & FLAG_CURSORCOLOR) != 0) {
                                    ((EditTextCaption) object).setCursorColor(color);
                                } else {
                                    ((EditTextCaption) object).setTextColor(color);
                                }
                            } else if (object instanceof SimpleTextView) {
                                if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    ((SimpleTextView) object).setLinkTextColor(color);
                                } else {
                                    ((SimpleTextView) object).setTextColor(color);
                                }
                            } else if (object instanceof TextView) {
                                TextView textView = (TextView) object;
                                if ((changeFlags & FLAG_IMAGECOLOR) != 0) {
                                    Drawable[] drawables = textView.getCompoundDrawables();
                                    if (drawables != null) {
                                        for (int a = 0; a < drawables.length; a++) {
                                            if (drawables[a] != null) {
                                                drawables[a].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                            }
                                        }
                                    }
                                } else if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    textView.getPaint().linkColor = color;
                                    textView.invalidate();
                                } else if ((changeFlags & FLAG_FASTSCROLL) != 0) {
                                    CharSequence text = textView.getText();
                                    if (text instanceof SpannedString) {
                                        TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                        if (spans != null && spans.length > 0) {
                                            for (int i = 0; i < spans.length; i++) {
                                                spans[i].setColor(color);
                                            }
                                        }
                                    }
                                } else {
                                    textView.setTextColor(color);
                                }
                            } else if (object instanceof ImageView) {
                                ImageView imageView = (ImageView) object;
                                Drawable drawable = imageView.getDrawable();
                                if (drawable instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) drawable).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) drawable).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else {
                                    imageView.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof BackupImageView) {
                                Drawable drawable = ((BackupImageView) object).getImageReceiver().getStaticThumb();
                                if (drawable instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) drawable).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) drawable).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else if (drawable != null) {
                                    drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof Drawable) {
                                if (object instanceof LetterDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((LetterDrawable) object).setBackgroundColor(color);
                                    } else {
                                        ((LetterDrawable) object).setColor(color);
                                    }
                                } else if (object instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) object).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) object).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else if (object instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && object instanceof RippleDrawable) {
                                    Theme.setSelectorDrawableColor((Drawable) object, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                                } else if (object instanceof GradientDrawable) {
                                    ((GradientDrawable) object).setColor(color);
                                } else {
                                    ((Drawable) object).setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof CheckBox) {
                                if ((changeFlags & FLAG_CHECKBOX) != 0) {
                                    ((CheckBox) object).setBackgroundColor(color);
                                } else if ((changeFlags & FLAG_CHECKBOXCHECK) != 0) {
                                    ((CheckBox) object).setCheckColor(color);
                                }
                            } else if (object instanceof GroupCreateCheckBox) {
                                ((GroupCreateCheckBox) object).updateColors();
                            } else if (object instanceof Integer) {
                                field.set(child, color);
                            } else if (object instanceof RadioButton) {
                                if ((changeFlags & FLAG_CHECKBOX) != 0) {
                                    ((RadioButton) object).setBackgroundColor(color);
                                    ((RadioButton) object).invalidate();
                                } else if ((changeFlags & FLAG_CHECKBOXCHECK) != 0) {
                                    ((RadioButton) object).setCheckedColor(color);
                                    ((RadioButton) object).invalidate();
                                }
                            } else if (object instanceof TextPaint) {
                                if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    ((TextPaint) object).linkColor = color;
                                } else {
                                    ((TextPaint) object).setColor(color);
                                }
                            } else if (object instanceof LineProgressView) {
                                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                                    ((LineProgressView) object).setProgressColor(color);
                                } else {
                                    ((LineProgressView) object).setBackColor(color);
                                }
                            } else if (object instanceof RadialProgressView) {
                                ((RadialProgressView) object).setProgressColor(color);
                            } else if (object instanceof Paint) {
                                ((Paint) object).setColor(color);
                                child.invalidate();
                            } else if (object instanceof SeekBarView) {
                                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                                    ((SeekBarView) object).setOuterColor(color);
                                } else {
                                    ((SeekBarView) object).setInnerColor(color);
                                }
                            } else if (object instanceof AudioPlayerAlert.ClippingTextViewSwitcher) {
                                if ((changeFlags & FLAG_FASTSCROLL) != 0) {
                                    for (int k = 0; k < 2; k++) {
                                        TextView textView = k == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getNextTextView();
                                        if (textView != null) {
                                            CharSequence text = textView.getText();
                                            if (text instanceof SpannedString) {
                                                TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                                if (spans != null && spans.length > 0) {
                                                    for (int i = 0; i < spans.length; i++) {
                                                        spans[i].setColor(color);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
                                    if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, (View) object)) {
                                        for (int i = 0; i < 2; i++) {
                                            TextView textView = i == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getNextTextView();
                                            if (textView != null) {
                                                textView.setTextColor(color);
                                                CharSequence text = textView.getText();
                                                if (text instanceof SpannedString) {
                                                    TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                                    if (spans != null && spans.length > 0) {
                                                        for (int spanIdx = 0; spanIdx < spans.length; spanIdx++) {
                                                            spans[spanIdx].setColor(color);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Throwable e) {
                    FileLog.e(e);
                    notFoundCachedFields.put(key, true);
                }
            } else if (child instanceof GroupCreateSpan) {
                ((GroupCreateSpan) child).updateColors();
            }
        }
    }
}
Also used : SpannedString(android.text.SpannedString) RLottieImageView(org.telegram.ui.Components.RLottieImageView) AudioPlayerAlert(org.telegram.ui.Components.AudioPlayerAlert) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) SpannedString(android.text.SpannedString) StateListDrawable(android.graphics.drawable.StateListDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) Field(java.lang.reflect.Field) BackupImageView(org.telegram.ui.Components.BackupImageView) GroupCreateCheckBox(org.telegram.ui.Components.GroupCreateCheckBox) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) EditTextCaption(org.telegram.ui.Components.EditTextCaption) AnimatedArrowDrawable(org.telegram.ui.Components.AnimatedArrowDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) LetterDrawable(org.telegram.ui.Components.LetterDrawable) ScamDrawable(org.telegram.ui.Components.ScamDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) RadioButton(org.telegram.ui.Components.RadioButton) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) ContextProgressView(org.telegram.ui.Components.ContextProgressView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) VideoTimelineView(org.telegram.ui.Components.VideoTimelineView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) SeekBarView(org.telegram.ui.Components.SeekBarView) BackupImageView(org.telegram.ui.Components.BackupImageView) LineProgressView(org.telegram.ui.Components.LineProgressView) NumberTextView(org.telegram.ui.Components.NumberTextView) ScrollView(android.widget.ScrollView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) SeekBarView(org.telegram.ui.Components.SeekBarView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TextPaint(android.text.TextPaint) ColorDrawable(android.graphics.drawable.ColorDrawable) CheckBox(org.telegram.ui.Components.CheckBox) GroupCreateCheckBox(org.telegram.ui.Components.GroupCreateCheckBox) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) LetterDrawable(org.telegram.ui.Components.LetterDrawable) LineProgressView(org.telegram.ui.Components.LineProgressView) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) GroupCreateSpan(org.telegram.ui.Components.GroupCreateSpan)

Example 18 with CombinedDrawable

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

the class Theme method createRoundRectDrawableWithIcon.

public static Drawable createRoundRectDrawableWithIcon(int rad, int iconRes) {
    ShapeDrawable defaultDrawable = new ShapeDrawable(new RoundRectShape(new float[] { rad, rad, rad, rad, rad, rad, rad, rad }, null, null));
    defaultDrawable.getPaint().setColor(0xffffffff);
    Drawable drawable = ApplicationLoader.applicationContext.getResources().getDrawable(iconRes).mutate();
    return new CombinedDrawable(defaultDrawable, drawable);
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) TypingDotsDrawable(org.telegram.ui.Components.TypingDotsDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) StatusDrawable(org.telegram.ui.Components.StatusDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) FragmentContextViewWavesDrawable(org.telegram.ui.Components.FragmentContextViewWavesDrawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) RoundStatusDrawable(org.telegram.ui.Components.RoundStatusDrawable) BackgroundGradientDrawable(org.telegram.ui.Components.BackgroundGradientDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ChoosingStickerStatusDrawable(org.telegram.ui.Components.ChoosingStickerStatusDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) PlayingGameDrawable(org.telegram.ui.Components.PlayingGameDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ScamDrawable(org.telegram.ui.Components.ScamDrawable) MotionBackgroundDrawable(org.telegram.ui.Components.MotionBackgroundDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) AudioVisualizerDrawable(org.telegram.ui.Components.AudioVisualizerDrawable) SendingFileDrawable(org.telegram.ui.Components.SendingFileDrawable) RecordStatusDrawable(org.telegram.ui.Components.RecordStatusDrawable) MsgClockDrawable(org.telegram.ui.Components.MsgClockDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable)

Example 19 with CombinedDrawable

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

the class ContactsActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    searchWas = false;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (destroyAfterSelect) {
        if (returnAsResult) {
            actionBar.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact));
        } else {
            if (createSecretChat) {
                actionBar.setTitle(LocaleController.getString("NewSecretChat", R.string.NewSecretChat));
            } else {
                actionBar.setTitle(LocaleController.getString("NewMessageTitle", R.string.NewMessageTitle));
            }
        }
    } else {
        actionBar.setTitle(LocaleController.getString("Contacts", R.string.Contacts));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == sort_button) {
                SharedConfig.toggleSortContactsByName();
                sortByName = SharedConfig.sortContactsByName;
                listViewAdapter.setSortType(sortByName ? 1 : 2, false);
                sortItem.setIcon(sortByName ? R.drawable.contacts_sort_time : R.drawable.contacts_sort_name);
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

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

        @Override
        public void onSearchCollapse() {
            searchListViewAdapter.searchDialogs(null);
            searching = false;
            searchWas = false;
            listView.setAdapter(listViewAdapter);
            listView.setSectionsType(1);
            listViewAdapter.notifyDataSetChanged();
            listView.setFastScrollVisible(true);
            listView.setVerticalScrollBarEnabled(false);
            // emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
            if (floatingButtonContainer != null) {
                floatingButtonContainer.setVisibility(View.VISIBLE);
                floatingHidden = true;
                floatingButtonContainer.setTranslationY(AndroidUtilities.dp(100));
                hideFloatingButton(false);
            }
            if (sortItem != null) {
                sortItem.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onTextChanged(EditText editText) {
            if (searchListViewAdapter == null) {
                return;
            }
            String text = editText.getText().toString();
            if (text.length() != 0) {
                searchWas = true;
                if (listView != null) {
                    listView.setAdapter(searchListViewAdapter);
                    listView.setSectionsType(0);
                    searchListViewAdapter.notifyDataSetChanged();
                    listView.setFastScrollVisible(false);
                    listView.setVerticalScrollBarEnabled(true);
                }
                emptyView.showProgress(true, true);
                searchListViewAdapter.searchDialogs(text);
            } else {
                if (listView != null) {
                    listView.setAdapter(listViewAdapter);
                    listView.setSectionsType(1);
                }
            }
        }
    });
    item.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    item.setContentDescription(LocaleController.getString("Search", R.string.Search));
    if (!createSecretChat && !returnAsResult) {
        sortItem = menu.addItem(sort_button, sortByName ? R.drawable.contacts_sort_time : R.drawable.contacts_sort_name);
        sortItem.setContentDescription(LocaleController.getString("AccDescrContactSorting", R.string.AccDescrContactSorting));
    }
    searchListViewAdapter = new SearchAdapter(context, ignoreUsers, allowUsernameSearch, false, false, allowBots, allowSelf, true, 0) {

        @Override
        protected void onSearchProgressChanged() {
            if (!searchInProgress() && getItemCount() == 0) {
                emptyView.showProgress(false, true);
            }
            showItemsAnimated();
        }
    };
    int inviteViaLink;
    if (chatId != 0) {
        TLRPC.Chat chat = getMessagesController().getChat(chatId);
        inviteViaLink = ChatObject.canUserDoAdminAction(chat, ChatObject.ACTION_INVITE) ? 1 : 0;
    } else if (channelId != 0) {
        TLRPC.Chat chat = getMessagesController().getChat(channelId);
        inviteViaLink = ChatObject.canUserDoAdminAction(chat, ChatObject.ACTION_INVITE) && TextUtils.isEmpty(chat.username) ? 2 : 0;
    } else {
        inviteViaLink = 0;
    }
    try {
        hasGps = ApplicationLoader.applicationContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
    } catch (Throwable e) {
        hasGps = false;
    }
    listViewAdapter = new ContactsAdapter(context, onlyUsers ? 1 : 0, needPhonebook, ignoreUsers, inviteViaLink, hasGps) {

        @Override
        public void notifyDataSetChanged() {
            super.notifyDataSetChanged();
            if (listView != null && listView.getAdapter() == this) {
                int count = super.getItemCount();
                if (needPhonebook) {
                    // emptyView.setVisibility(count == 2 ? View.VISIBLE : View.GONE);
                    listView.setFastScrollVisible(count != 2);
                } else {
                    // emptyView.setVisibility(count == 0 ? View.VISIBLE : View.GONE);
                    listView.setFastScrollVisible(count != 0);
                }
            }
        }
    };
    listViewAdapter.setSortType(sortItem != null ? (sortByName ? 1 : 2) : 0, false);
    listViewAdapter.setDisableSections(disableSections);
    fragmentView = new FrameLayout(context) {

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            if (listView.getAdapter() == listViewAdapter) {
                if (emptyView.getVisibility() == VISIBLE) {
                    emptyView.setTranslationY(AndroidUtilities.dp(74));
                }
            } else {
                emptyView.setTranslationY(AndroidUtilities.dp(0));
            }
        }
    };
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    FlickerLoadingView flickerLoadingView = new FlickerLoadingView(context);
    flickerLoadingView.setViewType(FlickerLoadingView.USERS_TYPE);
    flickerLoadingView.showDate(false);
    emptyView = new StickerEmptyView(context, flickerLoadingView, StickerEmptyView.STICKER_TYPE_SEARCH);
    emptyView.addView(flickerLoadingView, 0);
    emptyView.setAnimateLayoutChange(true);
    emptyView.showProgress(true, false);
    emptyView.title.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView = new RecyclerListView(context) {

        @Override
        public void setPadding(int left, int top, int right, int bottom) {
            super.setPadding(left, top, right, bottom);
            if (emptyView != null) {
                emptyView.setPadding(left, top, right, bottom);
            }
        }
    };
    listView.setSectionsType(1);
    listView.setVerticalScrollBarEnabled(false);
    listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setAdapter(listViewAdapter);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setEmptyView(emptyView);
    listView.setAnimateEmptyView(true, 0);
    listView.setOnItemClickListener((view, position) -> {
        if (listView.getAdapter() == searchListViewAdapter) {
            Object object = searchListViewAdapter.getItem(position);
            if (object instanceof TLRPC.User) {
                TLRPC.User user = (TLRPC.User) object;
                if (searchListViewAdapter.isGlobalSearch(position)) {
                    ArrayList<TLRPC.User> users = new ArrayList<>();
                    users.add(user);
                    getMessagesController().putUsers(users, false);
                    MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, false, true);
                }
                if (returnAsResult) {
                    if (ignoreUsers != null && ignoreUsers.indexOfKey(user.id) >= 0) {
                        return;
                    }
                    didSelectResult(user, true, null);
                } else {
                    if (createSecretChat) {
                        if (user.id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                            return;
                        }
                        creatingChat = true;
                        SecretChatHelper.getInstance(currentAccount).startSecretChat(getParentActivity(), user);
                    } else {
                        Bundle args = new Bundle();
                        args.putLong("user_id", user.id);
                        if (getMessagesController().checkCanOpenChat(args, ContactsActivity.this)) {
                            presentFragment(new ChatActivity(args), true);
                        }
                    }
                }
            } else if (object instanceof String) {
                String str = (String) object;
                if (!str.equals("section")) {
                    NewContactActivity activity = new NewContactActivity();
                    activity.setInitialPhoneNumber(str, true);
                    presentFragment(activity);
                }
            }
        } else {
            int section = listViewAdapter.getSectionForPosition(position);
            int row = listViewAdapter.getPositionInSectionForPosition(position);
            if (row < 0 || section < 0) {
                return;
            }
            if ((!onlyUsers || inviteViaLink != 0) && section == 0) {
                if (needPhonebook) {
                    if (row == 0) {
                        presentFragment(new InviteContactsActivity());
                    } else if (row == 1 && hasGps) {
                        if (Build.VERSION.SDK_INT >= 23) {
                            Activity activity = getParentActivity();
                            if (activity != null) {
                                if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                                    presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ACCESS));
                                    return;
                                }
                            }
                        }
                        boolean enabled = true;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                            LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
                            enabled = lm.isLocationEnabled();
                        } else if (Build.VERSION.SDK_INT >= 19) {
                            try {
                                int mode = Settings.Secure.getInt(ApplicationLoader.applicationContext.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
                                enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
                            } catch (Throwable e) {
                                FileLog.e(e);
                            }
                        }
                        if (!enabled) {
                            presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ENABLED));
                            return;
                        }
                        presentFragment(new PeopleNearbyActivity());
                    }
                } else if (inviteViaLink != 0) {
                    if (row == 0) {
                        presentFragment(new GroupInviteActivity(chatId != 0 ? chatId : channelId));
                    }
                } else {
                    if (row == 0) {
                        Bundle args = new Bundle();
                        presentFragment(new GroupCreateActivity(args), false);
                    } else if (row == 1) {
                        Bundle args = new Bundle();
                        args.putBoolean("onlyUsers", true);
                        args.putBoolean("destroyAfterSelect", true);
                        args.putBoolean("createSecretChat", true);
                        args.putBoolean("allowBots", false);
                        args.putBoolean("allowSelf", false);
                        presentFragment(new ContactsActivity(args), false);
                    } else if (row == 2) {
                        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                        if (!BuildVars.DEBUG_VERSION && preferences.getBoolean("channel_intro", false)) {
                            Bundle args = new Bundle();
                            args.putInt("step", 0);
                            presentFragment(new ChannelCreateActivity(args));
                        } else {
                            presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANNEL_CREATE));
                            preferences.edit().putBoolean("channel_intro", true).commit();
                        }
                    }
                }
            } else {
                Object item1 = listViewAdapter.getItem(section, row);
                if (item1 instanceof TLRPC.User) {
                    TLRPC.User user = (TLRPC.User) item1;
                    if (returnAsResult) {
                        if (ignoreUsers != null && ignoreUsers.indexOfKey(user.id) >= 0) {
                            return;
                        }
                        didSelectResult(user, true, null);
                    } else {
                        if (createSecretChat) {
                            creatingChat = true;
                            SecretChatHelper.getInstance(currentAccount).startSecretChat(getParentActivity(), user);
                        } else {
                            Bundle args = new Bundle();
                            args.putLong("user_id", user.id);
                            if (getMessagesController().checkCanOpenChat(args, ContactsActivity.this)) {
                                presentFragment(new ChatActivity(args), true);
                            }
                        }
                    }
                } else if (item1 instanceof ContactsController.Contact) {
                    ContactsController.Contact contact = (ContactsController.Contact) item1;
                    String usePhone = null;
                    if (!contact.phones.isEmpty()) {
                        usePhone = contact.phones.get(0);
                    }
                    if (usePhone == null || getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser));
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    final String arg1 = usePhone;
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
                        try {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null));
                            intent.putExtra("sms_body", ContactsController.getInstance(currentAccount).getInviteText(1));
                            getParentActivity().startActivityForResult(intent, 500);
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        private boolean scrollingManually;

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                if (searching && searchWas) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
                scrollingManually = true;
            } else {
                scrollingManually = false;
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (floatingButtonContainer != null && floatingButtonContainer.getVisibility() != View.GONE) {
                int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
                final View topChild = recyclerView.getChildAt(0);
                int firstViewTop = 0;
                if (topChild != null) {
                    firstViewTop = topChild.getTop();
                }
                boolean goingDown;
                boolean changed = true;
                if (prevPosition == firstVisibleItem) {
                    final int topDelta = prevTop - firstViewTop;
                    goingDown = firstViewTop < prevTop;
                    changed = Math.abs(topDelta) > 1;
                } else {
                    goingDown = firstVisibleItem > prevPosition;
                }
                if (changed && scrollUpdated && (goingDown || scrollingManually)) {
                    hideFloatingButton(goingDown);
                }
                prevPosition = firstVisibleItem;
                prevTop = firstViewTop;
                scrollUpdated = true;
            }
        }
    });
    if (!createSecretChat && !returnAsResult) {
        floatingButtonContainer = new FrameLayout(context);
        frameLayout.addView(floatingButtonContainer, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 4 : 0, 0, LocaleController.isRTL ? 0 : 4, 0));
        floatingButtonContainer.setOnClickListener(v -> presentFragment(new NewContactActivity()));
        floatingButton = new RLottieImageView(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));
        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        boolean configAnimationsEnabled = preferences.getBoolean("view_animations", true);
        floatingButton.setAnimation(configAnimationsEnabled ? R.raw.write_contacts_fab_icon : R.raw.write_contacts_fab_icon_reverse, 52, 52);
        floatingButtonContainer.setContentDescription(LocaleController.getString("CreateNewContact", R.string.CreateNewContact));
        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));
                }
            });
        }
        floatingButtonContainer.addView(floatingButton, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60), (Build.VERSION.SDK_INT >= 21 ? 56 : 60), Gravity.LEFT | Gravity.TOP, 10, 6, 10, 0));
    }
    if (initialSearchString != null) {
        actionBar.openSearchField(initialSearchString, false);
        initialSearchString = null;
    }
    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) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Manifest(android.Manifest) ApplicationLoader(org.telegram.messenger.ApplicationLoader) StateListAnimator(android.animation.StateListAnimator) TextCell(org.telegram.ui.Cells.TextCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContactsAdapter(org.telegram.ui.Adapters.ContactsAdapter) TargetApi(android.annotation.TargetApi) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Utilities(org.telegram.messenger.Utilities) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) UserConfig(org.telegram.messenger.UserConfig) SecretChatHelper(org.telegram.messenger.SecretChatHelper) LetterSectionCell(org.telegram.ui.Cells.LetterSectionCell) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LocationManager(android.location.LocationManager) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) TextWatcher(android.text.TextWatcher) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Dialog(android.app.Dialog) Intent(android.content.Intent) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) Settings(android.provider.Settings) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) LongSparseArray(androidx.collection.LongSparseArray) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) SearchAdapter(org.telegram.ui.Adapters.SearchAdapter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ValueAnimator(android.animation.ValueAnimator) ArrayList(java.util.ArrayList) Activity(android.app.Activity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) ContactsAdapter(org.telegram.ui.Adapters.ContactsAdapter) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) ContactsController(org.telegram.messenger.ContactsController) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StateListAnimator(android.animation.StateListAnimator) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) LocationManager(android.location.LocationManager) SearchAdapter(org.telegram.ui.Adapters.SearchAdapter) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Intent(android.content.Intent) Outline(android.graphics.Outline) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) FrameLayout(android.widget.FrameLayout) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 20 with CombinedDrawable

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

the class DataAutoDownloadActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    if (currentType == 0) {
        actionBar.setTitle(LocaleController.getString("AutoDownloadOnMobileData", R.string.AutoDownloadOnMobileData));
    } else if (currentType == 1) {
        actionBar.setTitle(LocaleController.getString("AutoDownloadOnWiFiData", R.string.AutoDownloadOnWiFiData));
    } else if (currentType == 2) {
        actionBar.setTitle(LocaleController.getString("AutoDownloadOnRoamingData", R.string.AutoDownloadOnRoamingData));
    }
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    listView = new RecyclerListView(context);
    listView.setVerticalScrollBarEnabled(false);
    ((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position, x, y) -> {
        if (position == autoDownloadRow) {
            if (currentPresetNum != 3) {
                if (currentPresetNum == 0) {
                    typePreset.set(lowPreset);
                } else if (currentPresetNum == 1) {
                    typePreset.set(mediumPreset);
                } else if (currentPresetNum == 2) {
                    typePreset.set(highPreset);
                }
            }
            TextCheckCell cell = (TextCheckCell) view;
            boolean checked = cell.isChecked();
            if (!checked && typePreset.enabled) {
                System.arraycopy(defaultPreset.mask, 0, typePreset.mask, 0, 4);
            } else {
                typePreset.enabled = !typePreset.enabled;
            }
            view.setTag(typePreset.enabled ? Theme.key_windowBackgroundChecked : Theme.key_windowBackgroundUnchecked);
            cell.setBackgroundColorAnimated(!checked, Theme.getColor(typePreset.enabled ? Theme.key_windowBackgroundChecked : Theme.key_windowBackgroundUnchecked));
            updateRows();
            if (typePreset.enabled) {
                listAdapter.notifyItemRangeInserted(autoDownloadSectionRow + 1, 8);
            } else {
                listAdapter.notifyItemRangeRemoved(autoDownloadSectionRow + 1, 8);
            }
            listAdapter.notifyItemChanged(autoDownloadSectionRow);
            SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
            editor.putString(key, typePreset.toString());
            editor.putInt(key2, currentPresetNum = 3);
            if (currentType == 0) {
                DownloadController.getInstance(currentAccount).currentMobilePreset = currentPresetNum;
            } else if (currentType == 1) {
                DownloadController.getInstance(currentAccount).currentWifiPreset = currentPresetNum;
            } else {
                DownloadController.getInstance(currentAccount).currentRoamingPreset = currentPresetNum;
            }
            editor.commit();
            cell.setChecked(!checked);
            DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
            wereAnyChanges = true;
        } else if (position == photosRow || position == videosRow || position == filesRow) {
            if (!view.isEnabled()) {
                return;
            }
            int type;
            if (position == photosRow) {
                type = DownloadController.AUTODOWNLOAD_TYPE_PHOTO;
            } else if (position == videosRow) {
                type = DownloadController.AUTODOWNLOAD_TYPE_VIDEO;
            } else {
                type = DownloadController.AUTODOWNLOAD_TYPE_DOCUMENT;
            }
            int index = DownloadController.typeToIndex(type);
            DownloadController.Preset currentPreset;
            String key;
            String key2;
            if (currentType == 0) {
                currentPreset = DownloadController.getInstance(currentAccount).getCurrentMobilePreset();
                key = "mobilePreset";
                key2 = "currentMobilePreset";
            } else if (currentType == 1) {
                currentPreset = DownloadController.getInstance(currentAccount).getCurrentWiFiPreset();
                key = "wifiPreset";
                key2 = "currentWifiPreset";
            } else {
                currentPreset = DownloadController.getInstance(currentAccount).getCurrentRoamingPreset();
                key = "roamingPreset";
                key2 = "currentRoamingPreset";
            }
            NotificationsCheckCell cell = (NotificationsCheckCell) view;
            boolean checked = cell.isChecked();
            if (LocaleController.isRTL && x <= AndroidUtilities.dp(76) || !LocaleController.isRTL && x >= view.getMeasuredWidth() - AndroidUtilities.dp(76)) {
                if (currentPresetNum != 3) {
                    if (currentPresetNum == 0) {
                        typePreset.set(lowPreset);
                    } else if (currentPresetNum == 1) {
                        typePreset.set(mediumPreset);
                    } else if (currentPresetNum == 2) {
                        typePreset.set(highPreset);
                    }
                }
                boolean hasAny = false;
                for (int a = 0; a < typePreset.mask.length; a++) {
                    if ((currentPreset.mask[a] & type) != 0) {
                        hasAny = true;
                        break;
                    }
                }
                for (int a = 0; a < typePreset.mask.length; a++) {
                    if (checked) {
                        typePreset.mask[a] &= ~type;
                    } else if (!hasAny) {
                        typePreset.mask[a] |= type;
                    }
                }
                SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
                editor.putString(key, typePreset.toString());
                editor.putInt(key2, currentPresetNum = 3);
                if (currentType == 0) {
                    DownloadController.getInstance(currentAccount).currentMobilePreset = currentPresetNum;
                } else if (currentType == 1) {
                    DownloadController.getInstance(currentAccount).currentWifiPreset = currentPresetNum;
                } else {
                    DownloadController.getInstance(currentAccount).currentRoamingPreset = currentPresetNum;
                }
                editor.commit();
                cell.setChecked(!checked);
                RecyclerView.ViewHolder holder = listView.findContainingViewHolder(view);
                if (holder != null) {
                    listAdapter.onBindViewHolder(holder, position);
                }
                DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
                wereAnyChanges = true;
                fillPresets();
            } else {
                if (getParentActivity() == null) {
                    return;
                }
                BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
                builder.setApplyTopPadding(false);
                builder.setApplyBottomPadding(false);
                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                builder.setCustomView(linearLayout);
                HeaderCell headerCell = new HeaderCell(getParentActivity(), Theme.key_dialogTextBlue2, 21, 15, false);
                if (position == photosRow) {
                    headerCell.setText(LocaleController.getString("AutoDownloadPhotosTitle", R.string.AutoDownloadPhotosTitle));
                } else if (position == videosRow) {
                    headerCell.setText(LocaleController.getString("AutoDownloadVideosTitle", R.string.AutoDownloadVideosTitle));
                } else {
                    headerCell.setText(LocaleController.getString("AutoDownloadFilesTitle", R.string.AutoDownloadFilesTitle));
                }
                linearLayout.addView(headerCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                final MaxFileSizeCell[] sizeCell = new MaxFileSizeCell[1];
                final TextCheckCell[] checkCell = new TextCheckCell[1];
                final AnimatorSet[] animatorSet = new AnimatorSet[1];
                TextCheckBoxCell[] cells = new TextCheckBoxCell[4];
                for (int a = 0; a < 4; a++) {
                    TextCheckBoxCell checkBoxCell = cells[a] = new TextCheckBoxCell(getParentActivity(), true, false);
                    if (a == 0) {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadContacts", R.string.AutodownloadContacts), (currentPreset.mask[DownloadController.PRESET_NUM_CONTACT] & type) != 0, true);
                    } else if (a == 1) {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadPrivateChats", R.string.AutodownloadPrivateChats), (currentPreset.mask[DownloadController.PRESET_NUM_PM] & type) != 0, true);
                    } else if (a == 2) {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadGroupChats", R.string.AutodownloadGroupChats), (currentPreset.mask[DownloadController.PRESET_NUM_GROUP] & type) != 0, true);
                    } else {
                        cells[a].setTextAndCheck(LocaleController.getString("AutodownloadChannels", R.string.AutodownloadChannels), (currentPreset.mask[DownloadController.PRESET_NUM_CHANNEL] & type) != 0, position != photosRow);
                    }
                    cells[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
                    cells[a].setOnClickListener(v -> {
                        if (!v.isEnabled()) {
                            return;
                        }
                        checkBoxCell.setChecked(!checkBoxCell.isChecked());
                        boolean hasAny = false;
                        for (int b = 0; b < cells.length; b++) {
                            if (cells[b].isChecked()) {
                                hasAny = true;
                                break;
                            }
                        }
                        if (position == videosRow && sizeCell[0].isEnabled() != hasAny) {
                            ArrayList<Animator> animators = new ArrayList<>();
                            sizeCell[0].setEnabled(hasAny, animators);
                            if (sizeCell[0].getSize() > 2 * 1024 * 1024) {
                                checkCell[0].setEnabled(hasAny, animators);
                            }
                            if (animatorSet[0] != null) {
                                animatorSet[0].cancel();
                                animatorSet[0] = null;
                            }
                            animatorSet[0] = new AnimatorSet();
                            animatorSet[0].playTogether(animators);
                            animatorSet[0].addListener(new AnimatorListenerAdapter() {

                                @Override
                                public void onAnimationEnd(Animator animator) {
                                    if (animator.equals(animatorSet[0])) {
                                        animatorSet[0] = null;
                                    }
                                }
                            });
                            animatorSet[0].setDuration(150);
                            animatorSet[0].start();
                        }
                    });
                    linearLayout.addView(cells[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50));
                }
                if (position != photosRow) {
                    TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(getParentActivity());
                    sizeCell[0] = new MaxFileSizeCell(getParentActivity()) {

                        @Override
                        protected void didChangedSizeValue(int value) {
                            if (position == videosRow) {
                                infoCell.setText(LocaleController.formatString("AutoDownloadPreloadVideoInfo", R.string.AutoDownloadPreloadVideoInfo, AndroidUtilities.formatFileSize(value)));
                                boolean enabled = value > 2 * 1024 * 1024;
                                if (enabled != checkCell[0].isEnabled()) {
                                    ArrayList<Animator> animators = new ArrayList<>();
                                    checkCell[0].setEnabled(enabled, animators);
                                    if (animatorSet[0] != null) {
                                        animatorSet[0].cancel();
                                        animatorSet[0] = null;
                                    }
                                    animatorSet[0] = new AnimatorSet();
                                    animatorSet[0].playTogether(animators);
                                    animatorSet[0].addListener(new AnimatorListenerAdapter() {

                                        @Override
                                        public void onAnimationEnd(Animator animator) {
                                            if (animator.equals(animatorSet[0])) {
                                                animatorSet[0] = null;
                                            }
                                        }
                                    });
                                    animatorSet[0].setDuration(150);
                                    animatorSet[0].start();
                                }
                            }
                        }
                    };
                    sizeCell[0].setSize(currentPreset.sizes[index]);
                    linearLayout.addView(sizeCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                    checkCell[0] = new TextCheckCell(getParentActivity(), 21, true);
                    linearLayout.addView(checkCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
                    checkCell[0].setOnClickListener(v -> checkCell[0].setChecked(!checkCell[0].isChecked()));
                    Drawable drawable = Theme.getThemedDrawable(getParentActivity(), R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
                    CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
                    combinedDrawable.setFullsize(true);
                    infoCell.setBackgroundDrawable(combinedDrawable);
                    linearLayout.addView(infoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                    if (position == videosRow) {
                        sizeCell[0].setText(LocaleController.getString("AutoDownloadMaxVideoSize", R.string.AutoDownloadMaxVideoSize));
                        checkCell[0].setTextAndCheck(LocaleController.getString("AutoDownloadPreloadVideo", R.string.AutoDownloadPreloadVideo), currentPreset.preloadVideo, false);
                        infoCell.setText(LocaleController.formatString("AutoDownloadPreloadVideoInfo", R.string.AutoDownloadPreloadVideoInfo, AndroidUtilities.formatFileSize(currentPreset.sizes[index])));
                    } else {
                        sizeCell[0].setText(LocaleController.getString("AutoDownloadMaxFileSize", R.string.AutoDownloadMaxFileSize));
                        checkCell[0].setTextAndCheck(LocaleController.getString("AutoDownloadPreloadMusic", R.string.AutoDownloadPreloadMusic), currentPreset.preloadMusic, false);
                        infoCell.setText(LocaleController.getString("AutoDownloadPreloadMusicInfo", R.string.AutoDownloadPreloadMusicInfo));
                    }
                } else {
                    sizeCell[0] = null;
                    checkCell[0] = null;
                    View divider = new View(getParentActivity());
                    divider.setBackgroundColor(Theme.getColor(Theme.key_divider));
                    linearLayout.addView(divider, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
                }
                if (position == videosRow) {
                    boolean hasAny = false;
                    for (int b = 0; b < cells.length; b++) {
                        if (cells[b].isChecked()) {
                            hasAny = true;
                            break;
                        }
                    }
                    if (!hasAny) {
                        sizeCell[0].setEnabled(false, null);
                        checkCell[0].setEnabled(false, null);
                    }
                    if (currentPreset.sizes[index] <= 2 * 1024 * 1024) {
                        checkCell[0].setEnabled(false, null);
                    }
                }
                FrameLayout buttonsLayout = new FrameLayout(getParentActivity());
                buttonsLayout.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
                linearLayout.addView(buttonsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 52));
                TextView textView = new TextView(getParentActivity());
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
                textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2));
                textView.setGravity(Gravity.CENTER);
                textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                textView.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
                textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
                buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.LEFT));
                textView.setOnClickListener(v14 -> builder.getDismissRunnable().run());
                textView = new TextView(getParentActivity());
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
                textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2));
                textView.setGravity(Gravity.CENTER);
                textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                textView.setText(LocaleController.getString("Save", R.string.Save).toUpperCase());
                textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
                buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
                textView.setOnClickListener(v1 -> {
                    if (currentPresetNum != 3) {
                        if (currentPresetNum == 0) {
                            typePreset.set(lowPreset);
                        } else if (currentPresetNum == 1) {
                            typePreset.set(mediumPreset);
                        } else if (currentPresetNum == 2) {
                            typePreset.set(highPreset);
                        }
                    }
                    for (int a = 0; a < 4; a++) {
                        if (cells[a].isChecked()) {
                            typePreset.mask[a] |= type;
                        } else {
                            typePreset.mask[a] &= ~type;
                        }
                    }
                    if (sizeCell[0] != null) {
                        int size = (int) sizeCell[0].getSize();
                        typePreset.sizes[index] = (int) sizeCell[0].getSize();
                    }
                    if (checkCell[0] != null) {
                        if (position == videosRow) {
                            typePreset.preloadVideo = checkCell[0].isChecked();
                        } else {
                            typePreset.preloadMusic = checkCell[0].isChecked();
                        }
                    }
                    SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
                    editor.putString(key, typePreset.toString());
                    editor.putInt(key2, currentPresetNum = 3);
                    if (currentType == 0) {
                        DownloadController.getInstance(currentAccount).currentMobilePreset = currentPresetNum;
                    } else if (currentType == 1) {
                        DownloadController.getInstance(currentAccount).currentWifiPreset = currentPresetNum;
                    } else {
                        DownloadController.getInstance(currentAccount).currentRoamingPreset = currentPresetNum;
                    }
                    editor.commit();
                    builder.getDismissRunnable().run();
                    RecyclerView.ViewHolder holder = listView.findContainingViewHolder(view);
                    if (holder != null) {
                        animateChecked = true;
                        listAdapter.onBindViewHolder(holder, position);
                        animateChecked = false;
                    }
                    DownloadController.getInstance(currentAccount).checkAutodownloadSettings();
                    wereAnyChanges = true;
                    fillPresets();
                });
                showDialog(builder.create());
            }
        }
    });
    return fragmentView;
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Theme(org.telegram.ui.ActionBar.Theme) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) ColorDrawable(android.graphics.drawable.ColorDrawable) LocaleController(org.telegram.messenger.LocaleController) Animator(android.animation.Animator) HeaderCell(org.telegram.ui.Cells.HeaderCell) MaxFileSizeCell(org.telegram.ui.Cells.MaxFileSizeCell) Drawable(android.graphics.drawable.Drawable) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ActionBar(org.telegram.ui.ActionBar.ActionBar) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Build(android.os.Build) DownloadController(org.telegram.messenger.DownloadController) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) SlideChooseView(org.telegram.ui.Components.SlideChooseView) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ViewGroup(android.view.ViewGroup) MessagesController(org.telegram.messenger.MessagesController) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) Gravity(android.view.Gravity) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) TextCheckBoxCell(org.telegram.ui.Cells.TextCheckBoxCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) HeaderCell(org.telegram.ui.Cells.HeaderCell) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) MaxFileSizeCell(org.telegram.ui.Cells.MaxFileSizeCell) SharedPreferences(android.content.SharedPreferences) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) TextCheckBoxCell(org.telegram.ui.Cells.TextCheckBoxCell) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SlideChooseView(org.telegram.ui.Components.SlideChooseView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) Animator(android.animation.Animator) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) FrameLayout(android.widget.FrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) LinearLayout(android.widget.LinearLayout)

Aggregations

CombinedDrawable (org.telegram.ui.Components.CombinedDrawable)29 Drawable (android.graphics.drawable.Drawable)26 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)21 View (android.view.View)20 RecyclerListView (org.telegram.ui.Components.RecyclerListView)18 ImageView (android.widget.ImageView)16 RecyclerView (androidx.recyclerview.widget.RecyclerView)16 ActionBar (org.telegram.ui.ActionBar.ActionBar)16 ViewGroup (android.view.ViewGroup)15 FrameLayout (android.widget.FrameLayout)15 TLRPC (org.telegram.tgnet.TLRPC)15 Paint (android.graphics.Paint)14 TextView (android.widget.TextView)14 SuppressLint (android.annotation.SuppressLint)12 Context (android.content.Context)12 Outline (android.graphics.Outline)12 Build (android.os.Build)12 ViewOutlineProvider (android.view.ViewOutlineProvider)12 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)12 ArrayList (java.util.ArrayList)12