use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ImageUpdater method didSelectPhotos.
private void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos) {
if (!photos.isEmpty()) {
SendMessagesHelper.SendingMediaInfo info = photos.get(0);
Bitmap bitmap = null;
MessageObject avatarObject = null;
if (info.isVideo || info.videoEditedInfo != null) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.id = 0;
message.message = "";
message.media = new TLRPC.TL_messageMediaEmpty();
message.action = new TLRPC.TL_messageActionEmpty();
message.dialog_id = 0;
avatarObject = new MessageObject(UserConfig.selectedAccount, message, false, false);
avatarObject.messageOwner.attachPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_avatar.mp4").getAbsolutePath();
avatarObject.videoEditedInfo = info.videoEditedInfo;
bitmap = ImageLoader.loadBitmap(info.thumbPath, null, 800, 800, true);
} else if (info.path != null) {
bitmap = ImageLoader.loadBitmap(info.path, null, 800, 800, true);
} else if (info.searchImage != null) {
if (info.searchImage.photo != null) {
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(info.searchImage.photo.sizes, AndroidUtilities.getPhotoSize());
if (photoSize != null) {
File path = FileLoader.getPathToAttach(photoSize, true);
finalPath = path.getAbsolutePath();
if (!path.exists()) {
path = FileLoader.getPathToAttach(photoSize, false);
if (!path.exists()) {
path = null;
}
}
if (path != null) {
bitmap = ImageLoader.loadBitmap(path.getAbsolutePath(), null, 800, 800, true);
} else {
NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.fileLoadFailed);
uploadingImage = FileLoader.getAttachFileName(photoSize.location);
imageReceiver.setImage(ImageLocation.getForPhoto(photoSize, info.searchImage.photo), null, null, "jpg", null, 1);
}
}
} else if (info.searchImage.imageUrl != null) {
String md5 = Utilities.MD5(info.searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(info.searchImage.imageUrl, "jpg");
File cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), md5);
finalPath = cacheFile.getAbsolutePath();
if (cacheFile.exists() && cacheFile.length() != 0) {
bitmap = ImageLoader.loadBitmap(cacheFile.getAbsolutePath(), null, 800, 800, true);
} else {
uploadingImage = info.searchImage.imageUrl;
NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.httpFileDidLoad);
NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.httpFileDidFailedLoad);
imageReceiver.setImage(info.searchImage.imageUrl, null, null, "jpg", 1);
}
}
}
processBitmap(bitmap, avatarObject);
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupedPhotosListView method updateAfterScroll.
private void updateAfterScroll() {
int indexChange = 0;
int dx = drawDx;
if (Math.abs(dx) > itemWidth / 2 + itemSpacing) {
if (dx > 0) {
dx -= itemWidth / 2 + itemSpacing;
indexChange++;
} else {
dx += itemWidth / 2 + itemSpacing;
indexChange--;
}
indexChange += dx / (itemWidth + itemSpacing * 2);
}
nextPhotoScrolling = currentImage - indexChange;
int currentIndex = delegate.getCurrentIndex();
ArrayList<ImageLocation> imagesArrLocations = delegate.getImagesArrLocations();
ArrayList<MessageObject> imagesArr = delegate.getImagesArr();
List<TLRPC.PageBlock> pageBlockArr = delegate.getPageBlockArr();
if (currentIndex != nextPhotoScrolling && nextPhotoScrolling >= 0 && nextPhotoScrolling < currentPhotos.size()) {
Object photo = currentObjects.get(nextPhotoScrolling);
int nextPhoto = -1;
if (imagesArr != null && !imagesArr.isEmpty()) {
MessageObject messageObject = (MessageObject) photo;
nextPhoto = imagesArr.indexOf(messageObject);
} else if (pageBlockArr != null && !pageBlockArr.isEmpty()) {
TLRPC.PageBlock pageBlock = (TLRPC.PageBlock) photo;
nextPhoto = pageBlockArr.indexOf(pageBlock);
} else if (imagesArrLocations != null && !imagesArrLocations.isEmpty()) {
ImageLocation location = (ImageLocation) photo;
nextPhoto = imagesArrLocations.indexOf(location);
}
if (nextPhoto >= 0) {
ignoreChanges = true;
delegate.setCurrentIndex(nextPhoto);
}
}
if (!scrolling) {
scrolling = true;
stopedScrolling = false;
}
fillImages(true, drawDx);
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupedPhotosListView method onSingleTapUp.
@Override
public boolean onSingleTapUp(MotionEvent e) {
int currentIndex = delegate.getCurrentIndex();
ArrayList<ImageLocation> imagesArrLocations = delegate.getImagesArrLocations();
ArrayList<MessageObject> imagesArr = delegate.getImagesArr();
List<TLRPC.PageBlock> pageBlockArr = delegate.getPageBlockArr();
stopScrolling();
int count = imagesToDraw.size();
for (int a = 0; a < count; a++) {
ImageReceiver receiver = imagesToDraw.get(a);
if (receiver.isInsideImage(e.getX(), e.getY())) {
int num = receiver.getParam();
if (num < 0 || num >= currentObjects.size()) {
return true;
}
if (imagesArr != null && !imagesArr.isEmpty()) {
MessageObject messageObject = (MessageObject) currentObjects.get(num);
int idx = imagesArr.indexOf(messageObject);
if (currentIndex == idx) {
return true;
}
moveLineProgress = 1.0f;
animateAllLine = true;
delegate.setCurrentIndex(idx);
} else if (pageBlockArr != null && !pageBlockArr.isEmpty()) {
TLRPC.PageBlock pageBlock = (TLRPC.PageBlock) currentObjects.get(num);
int idx = pageBlockArr.indexOf(pageBlock);
if (currentIndex == idx) {
return true;
}
moveLineProgress = 1.0f;
animateAllLine = true;
delegate.setCurrentIndex(idx);
} else if (imagesArrLocations != null && !imagesArrLocations.isEmpty()) {
ImageLocation location = (ImageLocation) currentObjects.get(num);
int idx = imagesArrLocations.indexOf(location);
if (currentIndex == idx) {
return true;
}
moveLineProgress = 1.0f;
animateAllLine = true;
delegate.setCurrentIndex(idx);
}
break;
}
}
return false;
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupedPhotosListView method fillList.
public void fillList() {
if (ignoreChanges) {
ignoreChanges = false;
return;
}
int currentIndex = delegate.getCurrentIndex();
ArrayList<ImageLocation> imagesArrLocations = delegate.getImagesArrLocations();
ArrayList<MessageObject> imagesArr = delegate.getImagesArr();
List<TLRPC.PageBlock> pageBlockArr = delegate.getPageBlockArr();
int slideshowMessageId = delegate.getSlideshowMessageId();
int currentAccount = delegate.getCurrentAccount();
hasPhotos = false;
boolean changed = false;
int newCount = 0;
Object currentObject = null;
if (imagesArrLocations != null && !imagesArrLocations.isEmpty()) {
if (currentIndex >= imagesArrLocations.size()) {
currentIndex = imagesArrLocations.size() - 1;
}
ImageLocation location = imagesArrLocations.get(currentIndex);
newCount = imagesArrLocations.size();
currentObject = location;
hasPhotos = true;
} else if (imagesArr != null && !imagesArr.isEmpty()) {
if (currentIndex >= imagesArr.size()) {
currentIndex = imagesArr.size() - 1;
}
MessageObject messageObject = imagesArr.get(currentIndex);
currentObject = messageObject;
long localGroupId = messageObject.getGroupIdForUse();
if (localGroupId != currentGroupId) {
changed = true;
currentGroupId = localGroupId;
}
if (currentGroupId != 0) {
hasPhotos = true;
int max = Math.min(currentIndex + 10, imagesArr.size());
for (int a = currentIndex; a < max; a++) {
MessageObject object = imagesArr.get(a);
if (slideshowMessageId != 0 || object.getGroupIdForUse() == currentGroupId) {
newCount++;
} else {
break;
}
}
int min = Math.max(currentIndex - 10, 0);
for (int a = currentIndex - 1; a >= min; a--) {
MessageObject object = imagesArr.get(a);
if (slideshowMessageId != 0 || object.getGroupIdForUse() == currentGroupId) {
newCount++;
} else {
break;
}
}
}
} else if (pageBlockArr != null && !pageBlockArr.isEmpty()) {
TLRPC.PageBlock pageBlock = pageBlockArr.get(currentIndex);
currentObject = pageBlock;
if (pageBlock.groupId != currentGroupId) {
changed = true;
currentGroupId = pageBlock.groupId;
}
if (currentGroupId != 0) {
hasPhotos = true;
for (int a = currentIndex, size = pageBlockArr.size(); a < size; a++) {
TLRPC.PageBlock object = pageBlockArr.get(a);
if (object.groupId == currentGroupId) {
newCount++;
} else {
break;
}
}
for (int a = currentIndex - 1; a >= 0; a--) {
TLRPC.PageBlock object = pageBlockArr.get(a);
if (object.groupId == currentGroupId) {
newCount++;
} else {
break;
}
}
}
}
if (currentObject == null) {
return;
}
if (animationsEnabled) {
if (!hasPhotos) {
if (showAnimator != null) {
showAnimator.cancel();
showAnimator = null;
}
if (drawAlpha > 0f && currentPhotos.size() > 1) {
if (hideAnimator == null) {
hideAnimator = ValueAnimator.ofFloat(drawAlpha, 0f);
hideAnimator.setDuration((long) (200 * drawAlpha));
hideAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (hideAnimator == animation) {
hideAnimator = null;
fillList();
}
}
});
hideAnimator.addUpdateListener(a -> {
drawAlpha = (float) a.getAnimatedValue();
invalidate();
});
hideAnimator.start();
}
return;
}
} else {
if (hideAnimator != null) {
final Animator a = hideAnimator;
hideAnimator = null;
a.cancel();
}
if (drawAlpha < 1f && showAnimator == null) {
showAnimator = ValueAnimator.ofFloat(drawAlpha, 1f);
showAnimator.setDuration((long) (200 * (1f - drawAlpha)));
showAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
if (delegate != null) {
delegate.onShowAnimationStart();
}
}
@Override
public void onAnimationEnd(Animator animation) {
if (showAnimator == animation) {
showAnimator = null;
}
}
});
showAnimator.addUpdateListener(a -> {
drawAlpha = (float) a.getAnimatedValue();
invalidate();
});
}
}
}
if (!changed) {
if (newCount != currentPhotos.size() || !currentObjects.contains(currentObject)) {
changed = true;
} else {
int newImageIndex = currentObjects.indexOf(currentObject);
if (currentImage != newImageIndex && newImageIndex != -1) {
boolean animate = animateAllLine;
if (!animate && !moving && (newImageIndex == currentImage - 1 || newImageIndex == currentImage + 1)) {
animate = true;
animateToItemFast = true;
}
if (animate) {
nextImage = animateToItem = newImageIndex;
animateToDX = (currentImage - newImageIndex) * (itemWidth + itemSpacing);
moving = true;
animateAllLine = false;
lastUpdateTime = System.currentTimeMillis();
invalidate();
} else {
fillImages(true, (currentImage - newImageIndex) * (itemWidth + itemSpacing));
currentImage = newImageIndex;
moving = false;
}
drawDx = 0;
}
}
}
if (changed) {
int oldCount = currentPhotos.size();
animateAllLine = false;
currentPhotos.clear();
currentObjects.clear();
if (imagesArrLocations != null && !imagesArrLocations.isEmpty()) {
currentObjects.addAll(imagesArrLocations);
currentPhotos.addAll(imagesArrLocations);
currentImage = currentIndex;
animateToItem = -1;
animateToItemFast = false;
} else if (imagesArr != null && !imagesArr.isEmpty()) {
if (currentGroupId != 0 || slideshowMessageId != 0) {
int max = Math.min(currentIndex + 10, imagesArr.size());
for (int a = currentIndex; a < max; a++) {
MessageObject object = imagesArr.get(a);
if (slideshowMessageId != 0 || object.getGroupIdForUse() == currentGroupId) {
currentObjects.add(object);
currentPhotos.add(ImageLocation.getForObject(FileLoader.getClosestPhotoSizeWithSize(object.photoThumbs, 56, true), object.photoThumbsObject));
} else {
break;
}
}
currentImage = 0;
animateToItem = -1;
animateToItemFast = false;
int min = Math.max(currentIndex - 10, 0);
for (int a = currentIndex - 1; a >= min; a--) {
MessageObject object = imagesArr.get(a);
if (slideshowMessageId != 0 || object.getGroupIdForUse() == currentGroupId) {
currentObjects.add(0, object);
currentPhotos.add(0, ImageLocation.getForObject(FileLoader.getClosestPhotoSizeWithSize(object.photoThumbs, 56, true), object.photoThumbsObject));
currentImage++;
} else {
break;
}
}
}
} else if (pageBlockArr != null && !pageBlockArr.isEmpty()) {
if (currentGroupId != 0) {
for (int a = currentIndex, size = pageBlockArr.size(); a < size; a++) {
TLRPC.PageBlock object = pageBlockArr.get(a);
if (object.groupId == currentGroupId) {
currentObjects.add(object);
currentPhotos.add(ImageLocation.getForObject(object.thumb, object.thumbObject));
} else {
break;
}
}
currentImage = 0;
animateToItem = -1;
animateToItemFast = false;
for (int a = currentIndex - 1; a >= 0; a--) {
TLRPC.PageBlock object = pageBlockArr.get(a);
if (object.groupId == currentGroupId) {
currentObjects.add(0, object);
currentPhotos.add(0, ImageLocation.getForObject(object.thumb, object.thumbObject));
currentImage++;
} else {
break;
}
}
}
}
if (currentPhotos.size() == 1) {
currentPhotos.clear();
currentObjects.clear();
}
if (currentPhotos.size() != oldCount) {
requestLayout();
}
fillImages(false, 0);
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method didReceivedNotification.
@Override
@SuppressWarnings("unchecked")
public void didReceivedNotification(int id, final int account, Object... args) {
if (id == NotificationCenter.appDidLogout) {
switchToAvailableAccountOrLogout();
} else if (id == NotificationCenter.closeOtherAppActivities) {
if (args[0] != this) {
onFinish();
finish();
}
} else if (id == NotificationCenter.didUpdateConnectionState) {
int state = ConnectionsManager.getInstance(account).getConnectionState();
if (currentConnectionState != state) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("switch to state " + state);
}
currentConnectionState = state;
updateCurrentConnectionState(account);
}
} else if (id == NotificationCenter.mainUserInfoChanged) {
drawerLayoutAdapter.notifyDataSetChanged();
} else if (id == NotificationCenter.needShowAlert) {
final Integer reason = (Integer) args[0];
if (reason == 6 || reason == 3 && proxyErrorDialog != null) {
return;
} else if (reason == 4) {
showTosActivity(account, (TLRPC.TL_help_termsOfService) args[1]);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (reason != 2 && reason != 3) {
builder.setNegativeButton(LocaleController.getString("MoreInfo", R.string.MoreInfo), (dialogInterface, i) -> {
if (!mainFragmentsStack.isEmpty()) {
MessagesController.getInstance(account).openByUserName("spambot", mainFragmentsStack.get(mainFragmentsStack.size() - 1), 1);
}
});
}
if (reason == 5) {
builder.setMessage(LocaleController.getString("NobodyLikesSpam3", R.string.NobodyLikesSpam3));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
} else if (reason == 0) {
builder.setMessage(LocaleController.getString("NobodyLikesSpam1", R.string.NobodyLikesSpam1));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
} else if (reason == 1) {
builder.setMessage(LocaleController.getString("NobodyLikesSpam2", R.string.NobodyLikesSpam2));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
} else if (reason == 2) {
builder.setMessage((String) args[1]);
String type = (String) args[2];
if (type.startsWith("AUTH_KEY_DROP_")) {
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setNegativeButton(LocaleController.getString("LogOut", R.string.LogOut), (dialog, which) -> MessagesController.getInstance(currentAccount).performLogout(2));
} else {
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
}
} else if (reason == 3) {
builder.setTitle(LocaleController.getString("Proxy", R.string.Proxy));
builder.setMessage(LocaleController.getString("UseProxyTelegramError", R.string.UseProxyTelegramError));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
proxyErrorDialog = showAlertDialog(builder);
return;
}
if (!mainFragmentsStack.isEmpty()) {
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
}
} else if (id == NotificationCenter.wasUnableToFindCurrentLocation) {
final HashMap<String, MessageObject> waitingForLocation = (HashMap<String, MessageObject>) args[0];
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setNegativeButton(LocaleController.getString("ShareYouLocationUnableManually", R.string.ShareYouLocationUnableManually), (dialogInterface, i) -> {
if (mainFragmentsStack.isEmpty()) {
return;
}
BaseFragment lastFragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
if (!AndroidUtilities.isGoogleMapsInstalled(lastFragment)) {
return;
}
LocationActivity fragment = new LocationActivity(0);
fragment.setDelegate((location, live, notify, scheduleDate) -> {
for (HashMap.Entry<String, MessageObject> entry : waitingForLocation.entrySet()) {
MessageObject messageObject = entry.getValue();
SendMessagesHelper.getInstance(account).sendMessage(location, messageObject.getDialogId(), messageObject, null, null, null, notify, scheduleDate);
}
});
presentFragment(fragment);
});
builder.setMessage(LocaleController.getString("ShareYouLocationUnable", R.string.ShareYouLocationUnable));
if (!mainFragmentsStack.isEmpty()) {
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
}
} else if (id == NotificationCenter.didSetNewWallpapper) {
if (sideMenu != null) {
View child = sideMenu.getChildAt(0);
if (child != null) {
child.invalidate();
}
}
if (backgroundTablet != null) {
backgroundTablet.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
}
} else if (id == NotificationCenter.didSetPasscode) {
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture) {
try {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
FileLog.e(e);
}
} else if (!AndroidUtilities.hasFlagSecureFragment()) {
try {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
FileLog.e(e);
}
}
} else if (id == NotificationCenter.reloadInterface) {
boolean last = mainFragmentsStack.size() > 1 && mainFragmentsStack.get(mainFragmentsStack.size() - 1) instanceof ProfileActivity;
if (last) {
ProfileActivity profileActivity = (ProfileActivity) mainFragmentsStack.get(mainFragmentsStack.size() - 1);
if (!profileActivity.isSettings()) {
last = false;
}
}
rebuildAllFragments(last);
} else if (id == NotificationCenter.suggestedLangpack) {
showLanguageAlert(false);
} else if (id == NotificationCenter.openArticle) {
if (mainFragmentsStack.isEmpty()) {
return;
}
ArticleViewer.getInstance().setParentActivity(this, mainFragmentsStack.get(mainFragmentsStack.size() - 1));
ArticleViewer.getInstance().open((TLRPC.TL_webPage) args[0], (String) args[1]);
} else if (id == NotificationCenter.hasNewContactsToImport) {
if (actionBarLayout == null || actionBarLayout.fragmentsStack.isEmpty()) {
return;
}
final int type = (Integer) args[0];
final HashMap<String, ContactsController.Contact> contactHashMap = (HashMap<String, ContactsController.Contact>) args[1];
final boolean first = (Boolean) args[2];
final boolean schedule = (Boolean) args[3];
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
builder.setTitle(LocaleController.getString("UpdateContactsTitle", R.string.UpdateContactsTitle));
builder.setMessage(LocaleController.getString("UpdateContactsMessage", R.string.UpdateContactsMessage));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, false));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
builder.setOnBackButtonListener((dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
AlertDialog dialog = builder.create();
fragment.showDialog(dialog);
dialog.setCanceledOnTouchOutside(false);
} else if (id == NotificationCenter.didSetNewTheme) {
Boolean nightTheme = (Boolean) args[0];
if (!nightTheme) {
if (sideMenu != null) {
sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
sideMenu.setGlowColor(Theme.getColor(Theme.key_chats_menuBackground));
sideMenu.setListSelectorColor(Theme.getColor(Theme.key_listSelector));
sideMenu.getAdapter().notifyDataSetChanged();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
setTaskDescription(new ActivityManager.TaskDescription(null, null, Theme.getColor(Theme.key_actionBarDefault) | 0xff000000));
} catch (Exception ignore) {
}
}
}
drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
boolean checkNavigationBarColor = true;
if (args.length > 1) {
checkNavigationBarColor = (boolean) args[1];
}
checkSystemBarColors(true, checkNavigationBarColor);
} else if (id == NotificationCenter.needSetDayNightTheme) {
boolean instant = false;
if (Build.VERSION.SDK_INT >= 21 && args[2] != null) {
if (themeSwitchImageView.getVisibility() == View.VISIBLE) {
return;
}
try {
int[] pos = (int[]) args[2];
boolean toDark = (Boolean) args[4];
RLottieImageView darkThemeView = (RLottieImageView) args[5];
int w = drawerLayoutContainer.getMeasuredWidth();
int h = drawerLayoutContainer.getMeasuredHeight();
if (!toDark) {
darkThemeView.setVisibility(View.INVISIBLE);
}
Bitmap bitmap = Bitmap.createBitmap(drawerLayoutContainer.getMeasuredWidth(), drawerLayoutContainer.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
HashMap<View, Integer> viewLayerTypes = new HashMap<>();
invalidateCachedViews(drawerLayoutContainer);
drawerLayoutContainer.draw(canvas);
frameLayout.removeView(themeSwitchImageView);
if (toDark) {
frameLayout.addView(themeSwitchImageView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
themeSwitchSunView.setVisibility(View.GONE);
} else {
frameLayout.addView(themeSwitchImageView, 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
themeSwitchSunView.setTranslationX(pos[0] - AndroidUtilities.dp(14));
themeSwitchSunView.setTranslationY(pos[1] - AndroidUtilities.dp(14));
themeSwitchSunView.setVisibility(View.VISIBLE);
themeSwitchSunView.invalidate();
}
themeSwitchImageView.setImageBitmap(bitmap);
themeSwitchImageView.setVisibility(View.VISIBLE);
themeSwitchSunDrawable = darkThemeView.getAnimatedDrawable();
float finalRadius = (float) Math.max(Math.sqrt((w - pos[0]) * (w - pos[0]) + (h - pos[1]) * (h - pos[1])), Math.sqrt(pos[0] * pos[0] + (h - pos[1]) * (h - pos[1])));
float finalRadius2 = (float) Math.max(Math.sqrt((w - pos[0]) * (w - pos[0]) + pos[1] * pos[1]), Math.sqrt(pos[0] * pos[0] + pos[1] * pos[1]));
finalRadius = Math.max(finalRadius, finalRadius2);
Animator anim = ViewAnimationUtils.createCircularReveal(toDark ? drawerLayoutContainer : themeSwitchImageView, pos[0], pos[1], toDark ? 0 : finalRadius, toDark ? finalRadius : 0);
anim.setDuration(400);
anim.setInterpolator(Easings.easeInOutQuad);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
themeSwitchImageView.setImageDrawable(null);
themeSwitchImageView.setVisibility(View.GONE);
themeSwitchSunView.setVisibility(View.GONE);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeAccentListUpdated);
if (!toDark) {
darkThemeView.setVisibility(View.VISIBLE);
}
DrawerProfileCell.switchingTheme = false;
}
});
anim.start();
instant = true;
} catch (Throwable e) {
FileLog.e(e);
try {
themeSwitchImageView.setImageDrawable(null);
frameLayout.removeView(themeSwitchImageView);
DrawerProfileCell.switchingTheme = false;
} catch (Exception e2) {
FileLog.e(e2);
}
}
} else {
DrawerProfileCell.switchingTheme = false;
}
Theme.ThemeInfo theme = (Theme.ThemeInfo) args[0];
boolean nigthTheme = (Boolean) args[1];
int accentId = (Integer) args[3];
actionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
if (AndroidUtilities.isTablet()) {
layersActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
rightActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
}
} else if (id == NotificationCenter.notificationsCountUpdated) {
if (sideMenu != null) {
Integer accountNum = (Integer) args[0];
int count = sideMenu.getChildCount();
for (int a = 0; a < count; a++) {
View child = sideMenu.getChildAt(a);
if (child instanceof DrawerUserCell) {
if (((DrawerUserCell) child).getAccountNumber() == accountNum) {
child.invalidate();
break;
}
}
}
}
} else if (id == NotificationCenter.fileLoaded) {
String path = (String) args[0];
if (SharedConfig.isAppUpdateAvailable()) {
String name = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
if (name.equals(path)) {
updateAppUpdateViews(true);
}
}
if (loadingThemeFileName != null) {
if (loadingThemeFileName.equals(path)) {
loadingThemeFileName = null;
File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
Theme.ThemeInfo themeInfo = Theme.fillThemeValues(locFile, loadingTheme.title, loadingTheme);
if (themeInfo != null) {
if (themeInfo.pathToWallpaper != null) {
File file = new File(themeInfo.pathToWallpaper);
if (!file.exists()) {
TLRPC.TL_account_getWallPaper req = new TLRPC.TL_account_getWallPaper();
TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
inputWallPaperSlug.slug = themeInfo.slug;
req.wallpaper = inputWallPaperSlug;
ConnectionsManager.getInstance(themeInfo.account).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_wallPaper) {
TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) response;
loadingThemeInfo = themeInfo;
loadingThemeWallpaperName = FileLoader.getAttachFileName(wallPaper.document);
loadingThemeWallpaper = wallPaper;
FileLoader.getInstance(themeInfo.account).loadFile(wallPaper.document, wallPaper, 1, 1);
} else {
onThemeLoadFinish();
}
}));
return;
}
}
Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
if (finalThemeInfo != null) {
presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
}
}
onThemeLoadFinish();
}
} else if (loadingThemeWallpaperName != null) {
if (loadingThemeWallpaperName.equals(path)) {
loadingThemeWallpaperName = null;
File file = (File) args[1];
if (loadingThemeAccent) {
openThemeAccentPreview(loadingTheme, loadingThemeWallpaper, loadingThemeInfo);
onThemeLoadFinish();
} else {
Theme.ThemeInfo info = loadingThemeInfo;
Utilities.globalQueue.postRunnable(() -> {
info.createBackground(file, info.pathToWallpaper);
AndroidUtilities.runOnUIThread(() -> {
if (loadingTheme == null) {
return;
}
File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
if (finalThemeInfo != null) {
presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
}
onThemeLoadFinish();
});
});
}
}
}
} else if (id == NotificationCenter.fileLoadFailed) {
String path = (String) args[0];
if (path.equals(loadingThemeFileName) || path.equals(loadingThemeWallpaperName)) {
onThemeLoadFinish();
}
if (SharedConfig.isAppUpdateAvailable()) {
String name = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
if (name.equals(path)) {
updateAppUpdateViews(true);
}
}
} else if (id == NotificationCenter.screenStateChanged) {
if (ApplicationLoader.mainInterfacePaused) {
return;
}
if (ApplicationLoader.isScreenOn) {
onPasscodeResume();
} else {
onPasscodePause();
}
} else if (id == NotificationCenter.needCheckSystemBarColors) {
checkSystemBarColors();
} else if (id == NotificationCenter.historyImportProgressChanged) {
if (args.length > 1 && !mainFragmentsStack.isEmpty()) {
AlertsCreator.processError(currentAccount, (TLRPC.TL_error) args[2], mainFragmentsStack.get(mainFragmentsStack.size() - 1), (TLObject) args[1]);
}
} else if (id == NotificationCenter.stickersImportComplete) {
MediaDataController.getInstance(account).toggleStickerSet(this, (TLObject) args[0], 2, !mainFragmentsStack.isEmpty() ? mainFragmentsStack.get(mainFragmentsStack.size() - 1) : null, false, true);
} else if (id == NotificationCenter.newSuggestionsAvailable) {
sideMenu.invalidateViews();
} else if (id == NotificationCenter.showBulletin) {
if (!mainFragmentsStack.isEmpty()) {
int type = (int) args[0];
FrameLayout container = null;
BaseFragment fragment = null;
if (GroupCallActivity.groupCallUiVisible && GroupCallActivity.groupCallInstance != null) {
container = GroupCallActivity.groupCallInstance.getContainer();
}
if (container == null) {
fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
}
if (type == Bulletin.TYPE_NAME_CHANGED) {
long peerId = (long) args[1];
String text = peerId > 0 ? LocaleController.getString("YourNameChanged", R.string.YourNameChanged) : LocaleController.getString("CannelTitleChanged", R.string.ChannelTitleChanged);
(container != null ? BulletinFactory.of(container, null) : BulletinFactory.of(fragment)).createErrorBulletin(text).show();
} else if (type == Bulletin.TYPE_BIO_CHANGED) {
long peerId = (long) args[1];
String text = peerId > 0 ? LocaleController.getString("YourBioChanged", R.string.YourBioChanged) : LocaleController.getString("CannelDescriptionChanged", R.string.ChannelDescriptionChanged);
(container != null ? BulletinFactory.of(container, null) : BulletinFactory.of(fragment)).createErrorBulletin(text).show();
} else if (type == Bulletin.TYPE_STICKER) {
TLRPC.Document sticker = (TLRPC.Document) args[1];
StickerSetBulletinLayout layout = new StickerSetBulletinLayout(this, null, (int) args[2], sticker, null);
if (fragment != null) {
Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT).show();
} else {
Bulletin.make(container, layout, Bulletin.DURATION_SHORT).show();
}
} else if (type == Bulletin.TYPE_ERROR) {
if (fragment != null) {
BulletinFactory.of(fragment).createErrorBulletin((String) args[1]).show();
} else {
BulletinFactory.of(container, null).createErrorBulletin((String) args[1]).show();
}
}
}
} else if (id == NotificationCenter.groupCallUpdated) {
checkWasMutedByAdmin(false);
} else if (id == NotificationCenter.fileLoadProgressChanged) {
if (updateTextView != null && SharedConfig.isAppUpdateAvailable()) {
String location = (String) args[0];
String fileName = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
if (fileName != null && fileName.equals(location)) {
Long loadedSize = (Long) args[1];
Long totalSize = (Long) args[2];
float loadProgress = loadedSize / (float) totalSize;
updateLayoutIcon.setProgress(loadProgress, true);
updateTextView.setText(LocaleController.formatString("AppUpdateDownloading", R.string.AppUpdateDownloading, (int) (loadProgress * 100)));
}
}
} else if (id == NotificationCenter.appUpdateAvailable) {
updateAppUpdateViews(mainFragmentsStack.size() == 1);
}
}
Aggregations