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();
}
}
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();
}
}
}
}
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);
}
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;
}
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;
}
Aggregations