use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupVoipInviteAlert method fillContacts.
private void fillContacts() {
if (!showContacts) {
return;
}
contacts.addAll(ContactsController.getInstance(currentAccount).contacts);
long selfId = UserConfig.getInstance(currentAccount).clientUserId;
for (int a = 0, N = contacts.size(); a < N; a++) {
TLObject object = contacts.get(a);
if (!(object instanceof TLRPC.TL_contact)) {
continue;
}
long userId = ((TLRPC.TL_contact) object).user_id;
if (userId == selfId || ignoredUsers.indexOfKey(userId) >= 0 || invitedUsers.contains(userId)) {
contacts.remove(a);
a--;
N--;
}
}
int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
MessagesController messagesController = MessagesController.getInstance(currentAccount);
Collections.sort(contacts, (o1, o2) -> {
TLRPC.User user1 = messagesController.getUser(((TLRPC.TL_contact) o2).user_id);
TLRPC.User user2 = messagesController.getUser(((TLRPC.TL_contact) o1).user_id);
int status1 = 0;
int status2 = 0;
if (user1 != null) {
if (user1.self) {
status1 = currentTime + 50000;
} else if (user1.status != null) {
status1 = user1.status.expires;
}
}
if (user2 != null) {
if (user2.self) {
status2 = currentTime + 50000;
} else if (user2.status != null) {
status2 = user2.status.expires;
}
}
if (status1 > 0 && status2 > 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 < 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 > 0 || status1 == 0 && status2 != 0) {
return -1;
} else if (status2 < 0 || status1 != 0) {
return 1;
}
return 0;
});
}
use of org.telegram.tgnet.TLObject 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);
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCallActivity method processSelectedOption.
private void processSelectedOption(TLRPC.TL_groupCallParticipant participant, long peerId, int option) {
VoIPService voIPService = VoIPService.getSharedInstance();
if (voIPService == null) {
return;
}
TLObject object;
if (peerId > 0) {
object = accountInstance.getMessagesController().getUser(peerId);
} else {
object = accountInstance.getMessagesController().getChat(-peerId);
}
if (option == 0 || option == 2 || option == 3) {
if (option == 0) {
if (VoIPService.getSharedInstance() == null) {
return;
}
VoIPService.getSharedInstance().editCallMember(object, true, null, null, null, null);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_MUTED, object, null, null, null);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setDialogButtonColorKey(Theme.key_voipgroup_listeningText);
TextView messageTextView = new TextView(getContext());
messageTextView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
FrameLayout frameLayout = new FrameLayout(getContext());
builder.setView(frameLayout);
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
BackupImageView imageView = new BackupImageView(getContext());
imageView.setRoundRadius(AndroidUtilities.dp(20));
frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
avatarDrawable.setInfo(object);
String name;
if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
imageView.setForUserOrChat(user, avatarDrawable);
name = UserObject.getFirstName(user);
} else {
TLRPC.Chat chat = (TLRPC.Chat) object;
imageView.setForUserOrChat(chat, avatarDrawable);
name = chat.title;
}
TextView textView = new TextView(getContext());
textView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
if (option == 2) {
textView.setText(LocaleController.getString("VoipGroupRemoveMemberAlertTitle2", R.string.VoipGroupRemoveMemberAlertTitle2));
if (ChatObject.isChannelOrGiga(currentChat)) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipChannelRemoveMemberAlertText2", R.string.VoipChannelRemoveMemberAlertText2, name, currentChat.title)));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupRemoveMemberAlertText2", R.string.VoipGroupRemoveMemberAlertText2, name, currentChat.title)));
}
} else {
textView.setText(LocaleController.getString("VoipGroupAddMemberTitle", R.string.VoipGroupAddMemberTitle));
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupAddMemberText", R.string.VoipGroupAddMemberText, name, currentChat.title)));
}
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
if (option == 2) {
builder.setPositiveButton(LocaleController.getString("VoipGroupUserRemove", R.string.VoipGroupUserRemove), (dialogInterface, i) -> {
if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
accountInstance.getMessagesController().deleteParticipantFromChat(currentChat.id, user, null);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_REMOVED, user, null, null, null);
} else {
TLRPC.Chat chat = (TLRPC.Chat) object;
accountInstance.getMessagesController().deleteParticipantFromChat(currentChat.id, null, chat, null, false, false);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_REMOVED, chat, null, null, null);
}
});
} else if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
builder.setPositiveButton(LocaleController.getString("VoipGroupAdd", R.string.VoipGroupAdd), (dialogInterface, i) -> {
BaseFragment fragment = parentActivity.getActionBarLayout().fragmentsStack.get(parentActivity.getActionBarLayout().fragmentsStack.size() - 1);
accountInstance.getMessagesController().addUserToChat(currentChat.id, user, 0, null, fragment, () -> inviteUserToCall(peerId, false));
});
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
dialog.setBackgroundColor(Theme.getColor(Theme.key_voipgroup_dialogBackground));
dialog.show();
if (option == 2) {
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_voipgroup_leaveCallMenu));
}
}
} else if (option == 6) {
parentActivity.switchToAccount(currentAccount, true);
Bundle args = new Bundle();
if (peerId > 0) {
args.putLong("user_id", peerId);
} else {
args.putLong("chat_id", -peerId);
}
parentActivity.presentFragment(new ChatActivity(args));
dismiss();
} else if (option == 8) {
parentActivity.switchToAccount(currentAccount, true);
BaseFragment fragment = parentActivity.getActionBarLayout().fragmentsStack.get(parentActivity.getActionBarLayout().fragmentsStack.size() - 1);
if (fragment instanceof ChatActivity) {
if (((ChatActivity) fragment).getDialogId() == peerId) {
dismiss();
return;
}
}
Bundle args = new Bundle();
if (peerId > 0) {
args.putLong("user_id", peerId);
} else {
args.putLong("chat_id", -peerId);
}
parentActivity.presentFragment(new ChatActivity(args));
dismiss();
} else if (option == 7) {
voIPService.editCallMember(object, true, null, null, false, null);
updateMuteButton(MUTE_BUTTON_STATE_MUTED_BY_ADMIN, true);
} else if (option == 9) {
if (currentAvatarUpdater != null && currentAvatarUpdater.isUploadingImage()) {
return;
}
currentAvatarUpdater = new ImageUpdater(true);
currentAvatarUpdater.setOpenWithFrontfaceCamera(true);
currentAvatarUpdater.setForceDarkTheme(true);
currentAvatarUpdater.setSearchAvailable(true, true);
currentAvatarUpdater.setShowingFromDialog(true);
currentAvatarUpdater.parentFragment = parentActivity.getActionBarLayout().getLastFragment();
currentAvatarUpdater.setDelegate(avatarUpdaterDelegate = new AvatarUpdaterDelegate(peerId));
TLRPC.User user = accountInstance.getUserConfig().getCurrentUser();
currentAvatarUpdater.openMenu(user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty), () -> accountInstance.getMessagesController().deleteUserPhoto(null), dialog -> {
});
} else if (option == 10) {
AlertsCreator.createChangeBioAlert(participant.about, peerId, getContext(), currentAccount);
} else if (option == 11) {
AlertsCreator.createChangeNameAlert(peerId, getContext(), currentAccount);
} else {
if (option == 5) {
voIPService.editCallMember(object, true, null, null, null, null);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_MUTED_FOR_YOU, object);
voIPService.setParticipantVolume(participant, 0);
} else {
if ((participant.flags & 128) != 0 && participant.volume == 0) {
participant.volume = 10000;
participant.volume_by_admin = false;
voIPService.editCallMember(object, false, null, participant.volume, null, null);
} else {
voIPService.editCallMember(object, false, null, null, null, null);
}
voIPService.setParticipantVolume(participant, ChatObject.getParticipantVolume(participant));
getUndoView().showWithAction(0, option == 1 ? UndoView.ACTION_VOIP_UNMUTED : UndoView.ACTION_VOIP_UNMUTED_FOR_YOU, object, null, null, null);
}
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCallActivity method updateItems.
private void updateItems() {
if (call == null || call.isScheduled()) {
pipItem.setVisibility(View.INVISIBLE);
screenShareItem.setVisibility(View.GONE);
if (call == null) {
otherItem.setVisibility(View.GONE);
return;
}
}
if (changingPermissions) {
return;
}
TLRPC.Chat newChat = accountInstance.getMessagesController().getChat(currentChat.id);
if (newChat != null) {
currentChat = newChat;
}
if (ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_INVITE) || (!ChatObject.isChannel(currentChat) || currentChat.megagroup) && (!TextUtils.isEmpty(currentChat.username) || ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_INVITE)) || ChatObject.isChannel(currentChat) && !currentChat.megagroup && !TextUtils.isEmpty(currentChat.username)) {
inviteItem.setVisibility(View.VISIBLE);
} else {
inviteItem.setVisibility(View.GONE);
}
TLRPC.TL_groupCallParticipant participant = call.participants.get(MessageObject.getPeerId(selfPeer));
if (call == null || call.isScheduled() || participant != null && !participant.can_self_unmute && participant.muted) {
noiseItem.setVisibility(View.GONE);
} else {
noiseItem.setVisibility(View.VISIBLE);
}
noiseItem.setIcon(SharedConfig.noiseSupression ? R.drawable.msg_noise_on : R.drawable.msg_noise_off);
noiseItem.setSubtext(SharedConfig.noiseSupression ? LocaleController.getString("VoipNoiseCancellationEnabled", R.string.VoipNoiseCancellationEnabled) : LocaleController.getString("VoipNoiseCancellationDisabled", R.string.VoipNoiseCancellationDisabled));
if (ChatObject.canManageCalls(currentChat)) {
leaveItem.setVisibility(View.VISIBLE);
editTitleItem.setVisibility(View.VISIBLE);
if (call.isScheduled()) {
recordItem.setVisibility(View.GONE);
screenItem.setVisibility(View.GONE);
} else {
recordItem.setVisibility(View.VISIBLE);
}
if (!call.canRecordVideo() || call.isScheduled() || Build.VERSION.SDK_INT < 21) {
screenItem.setVisibility(View.GONE);
} else {
screenItem.setVisibility(View.VISIBLE);
}
screenShareItem.setVisibility(View.GONE);
recordCallDrawable.setRecording(call.recording);
if (call.recording) {
if (updateCallRecordRunnable == null) {
AndroidUtilities.runOnUIThread(updateCallRecordRunnable = () -> {
updateRecordCallText();
AndroidUtilities.runOnUIThread(updateCallRecordRunnable, 1000);
}, 1000);
}
recordItem.setText(LocaleController.getString("VoipGroupStopRecordCall", R.string.VoipGroupStopRecordCall));
} else {
if (updateCallRecordRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(updateCallRecordRunnable);
updateCallRecordRunnable = null;
}
recordItem.setText(LocaleController.getString("VoipGroupRecordCall", R.string.VoipGroupRecordCall));
}
if (VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().getVideoState(true) == Instance.VIDEO_STATE_ACTIVE) {
screenItem.setTextAndIcon(LocaleController.getString("VoipChatStopScreenCapture", R.string.VoipChatStopScreenCapture), R.drawable.msg_screencast_off);
} else {
screenItem.setTextAndIcon(LocaleController.getString("VoipChatStartScreenCapture", R.string.VoipChatStartScreenCapture), R.drawable.msg_screencast);
}
updateRecordCallText();
} else {
boolean mutedByAdmin = participant != null && !participant.can_self_unmute && participant.muted && !ChatObject.canManageCalls(currentChat);
boolean sharingScreen = VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().getVideoState(true) == Instance.VIDEO_STATE_ACTIVE;
if (Build.VERSION.SDK_INT >= 21 && !mutedByAdmin && (call.canRecordVideo() || sharingScreen) && !call.isScheduled()) {
if (sharingScreen) {
screenShareItem.setVisibility(View.GONE);
screenItem.setVisibility(View.VISIBLE);
screenItem.setTextAndIcon(LocaleController.getString("VoipChatStopScreenCapture", R.string.VoipChatStopScreenCapture), R.drawable.msg_screencast_off);
screenItem.setContentDescription(LocaleController.getString("VoipChatStopScreenCapture", R.string.VoipChatStopScreenCapture));
} else {
screenItem.setTextAndIcon(LocaleController.getString("VoipChatStartScreenCapture", R.string.VoipChatStartScreenCapture), R.drawable.msg_screencast);
screenItem.setContentDescription(LocaleController.getString("VoipChatStartScreenCapture", R.string.VoipChatStartScreenCapture));
screenShareItem.setVisibility(View.GONE);
screenItem.setVisibility(View.VISIBLE);
}
} else {
screenShareItem.setVisibility(View.GONE);
screenItem.setVisibility(View.GONE);
}
leaveItem.setVisibility(View.GONE);
editTitleItem.setVisibility(View.GONE);
recordItem.setVisibility(View.GONE);
}
if (ChatObject.canManageCalls(currentChat) && call.call.can_change_join_muted) {
permissionItem.setVisibility(View.VISIBLE);
} else {
permissionItem.setVisibility(View.GONE);
}
soundItem.setVisibility(View.VISIBLE);
if (editTitleItem.getVisibility() == View.VISIBLE || permissionItem.getVisibility() == View.VISIBLE || inviteItem.getVisibility() == View.VISIBLE || screenItem.getVisibility() == View.VISIBLE || recordItem.getVisibility() == View.VISIBLE || leaveItem.getVisibility() == View.VISIBLE) {
soundItemDivider.setVisibility(View.VISIBLE);
} else {
soundItemDivider.setVisibility(View.GONE);
}
int margin = 48;
if (VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().hasFewPeers || scheduleHasFewPeers) {
accountSelectCell.setVisibility(View.VISIBLE);
accountGap.setVisibility(View.VISIBLE);
long peerId = MessageObject.getPeerId(selfPeer);
TLObject object;
if (DialogObject.isUserDialog(peerId)) {
object = accountInstance.getMessagesController().getUser(peerId);
} else {
object = accountInstance.getMessagesController().getChat(-peerId);
}
accountSelectCell.setObject(object);
margin += 48;
} else {
margin += 48;
accountSelectCell.setVisibility(View.GONE);
accountGap.setVisibility(View.GONE);
}
otherItem.setVisibility(View.VISIBLE);
FrameLayout.LayoutParams layoutParams = ((FrameLayout.LayoutParams) titleTextView.getLayoutParams());
if (layoutParams.rightMargin != AndroidUtilities.dp(margin)) {
layoutParams.rightMargin = AndroidUtilities.dp(margin);
titleTextView.requestLayout();
}
((FrameLayout.LayoutParams) menuItemsContainer.getLayoutParams()).rightMargin = 0;
actionBar.setTitleRightMargin(AndroidUtilities.dp(48) * 2);
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class FilteredSearchView method search.
public void search(long dialogId, long minDate, long maxDate, FiltersView.MediaFilterData currentSearchFilter, boolean includeFolder, String query, boolean clearOldResults) {
String currentSearchFilterQueryString = String.format(Locale.ENGLISH, "%d%d%d%d%s%s", dialogId, minDate, maxDate, currentSearchFilter == null ? -1 : currentSearchFilter.filterType, query, includeFolder);
boolean filterAndQueryIsSame = lastSearchFilterQueryString != null && lastSearchFilterQueryString.equals(currentSearchFilterQueryString);
boolean forceClear = !filterAndQueryIsSame && clearOldResults;
this.currentSearchFilter = currentSearchFilter;
this.currentSearchDialogId = dialogId;
this.currentSearchMinDate = minDate;
this.currentSearchMaxDate = maxDate;
this.currentSearchString = query;
this.currentIncludeFolder = includeFolder;
if (searchRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(searchRunnable);
}
AndroidUtilities.cancelRunOnUIThread(clearCurrentResultsRunnable);
if (filterAndQueryIsSame && clearOldResults) {
return;
}
if (forceClear || currentSearchFilter == null && dialogId == 0 && minDate == 0 && maxDate == 0) {
messages.clear();
sections.clear();
sectionArrays.clear();
isLoading = true;
emptyView.setVisibility(View.VISIBLE);
if (adapter != null) {
adapter.notifyDataSetChanged();
}
requestIndex++;
firstLoading = true;
if (recyclerListView.getPinnedHeader() != null) {
recyclerListView.getPinnedHeader().setAlpha(0);
}
localTipChats.clear();
localTipDates.clear();
if (!forceClear) {
return;
}
} else if (clearOldResults && !messages.isEmpty()) {
return;
}
isLoading = true;
if (adapter != null) {
adapter.notifyDataSetChanged();
}
if (!filterAndQueryIsSame) {
clearCurrentResultsRunnable.run();
emptyView.showProgress(true, !clearOldResults);
}
if (TextUtils.isEmpty(query)) {
localTipDates.clear();
localTipChats.clear();
if (delegate != null) {
delegate.updateFiltersView(false, null, null, false);
}
}
requestIndex++;
final int requestId = requestIndex;
int currentAccount = UserConfig.selectedAccount;
AndroidUtilities.runOnUIThread(searchRunnable = () -> {
TLObject request;
ArrayList<Object> resultArray = null;
if (dialogId != 0) {
final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.q = query;
req.limit = 20;
req.filter = currentSearchFilter == null ? new TLRPC.TL_inputMessagesFilterEmpty() : currentSearchFilter.filter;
req.peer = AccountInstance.getInstance(currentAccount).getMessagesController().getInputPeer(dialogId);
if (minDate > 0) {
req.min_date = (int) (minDate / 1000);
}
if (maxDate > 0) {
req.max_date = (int) (maxDate / 1000);
}
if (filterAndQueryIsSame && query.equals(lastMessagesSearchString) && !messages.isEmpty()) {
MessageObject lastMessage = messages.get(messages.size() - 1);
req.offset_id = lastMessage.getId();
} else {
req.offset_id = 0;
}
request = req;
} else {
if (!TextUtils.isEmpty(query)) {
resultArray = new ArrayList<>();
ArrayList<CharSequence> resultArrayNames = new ArrayList<>();
ArrayList<TLRPC.User> encUsers = new ArrayList<>();
MessagesStorage.getInstance(currentAccount).localSearch(0, query, resultArray, resultArrayNames, encUsers, includeFolder ? 1 : 0);
}
final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal();
req.limit = 20;
req.q = query;
req.filter = currentSearchFilter == null ? new TLRPC.TL_inputMessagesFilterEmpty() : currentSearchFilter.filter;
if (minDate > 0) {
req.min_date = (int) (minDate / 1000);
}
if (maxDate > 0) {
req.max_date = (int) (maxDate / 1000);
}
if (filterAndQueryIsSame && query.equals(lastMessagesSearchString) && !messages.isEmpty()) {
MessageObject lastMessage = messages.get(messages.size() - 1);
req.offset_id = lastMessage.getId();
req.offset_rate = nextSearchRate;
long id = MessageObject.getPeerId(lastMessage.messageOwner.peer_id);
req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id);
} else {
req.offset_rate = 0;
req.offset_id = 0;
req.offset_peer = new TLRPC.TL_inputPeerEmpty();
}
req.flags |= 1;
req.folder_id = includeFolder ? 1 : 0;
request = req;
}
lastMessagesSearchString = query;
lastSearchFilterQueryString = currentSearchFilterQueryString;
ArrayList<Object> finalResultArray = resultArray;
final ArrayList<FiltersView.DateData> dateData = new ArrayList<>();
FiltersView.fillTipDates(lastMessagesSearchString, dateData);
ConnectionsManager.getInstance(currentAccount).sendRequest(request, (response, error) -> {
ArrayList<MessageObject> messageObjects = new ArrayList<>();
if (error == null) {
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
int n = res.messages.size();
for (int i = 0; i < n; i++) {
MessageObject messageObject = new MessageObject(currentAccount, res.messages.get(i), false, true);
messageObject.setQuery(query);
messageObjects.add(messageObject);
}
}
AndroidUtilities.runOnUIThread(() -> {
if (requestId != requestIndex) {
return;
}
isLoading = false;
if (error != null) {
emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
emptyView.subtitle.setVisibility(View.VISIBLE);
emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
emptyView.showProgress(false, true);
return;
}
emptyView.showProgress(false);
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
nextSearchRate = res.next_rate;
MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
MessagesController.getInstance(currentAccount).putUsers(res.users, false);
MessagesController.getInstance(currentAccount).putChats(res.chats, false);
if (!filterAndQueryIsSame) {
messages.clear();
messagesById.clear();
sections.clear();
sectionArrays.clear();
}
totalCount = res.count;
currentDataQuery = query;
int n = messageObjects.size();
for (int i = 0; i < n; i++) {
MessageObject messageObject = messageObjects.get(i);
ArrayList<MessageObject> messageObjectsByDate = sectionArrays.get(messageObject.monthKey);
if (messageObjectsByDate == null) {
messageObjectsByDate = new ArrayList<>();
sectionArrays.put(messageObject.monthKey, messageObjectsByDate);
sections.add(messageObject.monthKey);
}
messageObjectsByDate.add(messageObject);
messages.add(messageObject);
messagesById.put(messageObject.getId(), messageObject);
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().addPhoto(messageObject, photoViewerClassGuid);
}
}
if (messages.size() > totalCount) {
totalCount = messages.size();
}
endReached = messages.size() >= totalCount;
if (messages.isEmpty()) {
if (currentSearchFilter != null) {
if (TextUtils.isEmpty(currentDataQuery) && dialogId == 0 && minDate == 0) {
emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle", R.string.SearchEmptyViewTitle));
String str;
if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_FILES) {
str = LocaleController.getString("SearchEmptyViewFilteredSubtitleFiles", R.string.SearchEmptyViewFilteredSubtitleFiles);
} else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MEDIA) {
str = LocaleController.getString("SearchEmptyViewFilteredSubtitleMedia", R.string.SearchEmptyViewFilteredSubtitleMedia);
} else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_LINKS) {
str = LocaleController.getString("SearchEmptyViewFilteredSubtitleLinks", R.string.SearchEmptyViewFilteredSubtitleLinks);
} else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MUSIC) {
str = LocaleController.getString("SearchEmptyViewFilteredSubtitleMusic", R.string.SearchEmptyViewFilteredSubtitleMusic);
} else {
str = LocaleController.getString("SearchEmptyViewFilteredSubtitleVoice", R.string.SearchEmptyViewFilteredSubtitleVoice);
}
emptyView.subtitle.setVisibility(View.VISIBLE);
emptyView.subtitle.setText(str);
} else {
emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
emptyView.subtitle.setVisibility(View.VISIBLE);
emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
}
} else {
emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
emptyView.subtitle.setVisibility(View.GONE);
}
}
if (currentSearchFilter != null) {
switch(currentSearchFilter.filterType) {
case FiltersView.FILTER_TYPE_MEDIA:
if (TextUtils.isEmpty(currentDataQuery)) {
adapter = sharedPhotoVideoAdapter;
} else {
adapter = dialogsAdapter;
}
break;
case FiltersView.FILTER_TYPE_FILES:
adapter = sharedDocumentsAdapter;
break;
case FiltersView.FILTER_TYPE_LINKS:
adapter = sharedLinksAdapter;
break;
case FiltersView.FILTER_TYPE_MUSIC:
adapter = sharedAudioAdapter;
break;
case FiltersView.FILTER_TYPE_VOICE:
adapter = sharedVoiceAdapter;
break;
}
} else {
adapter = dialogsAdapter;
}
if (recyclerListView.getAdapter() != adapter) {
recyclerListView.setAdapter(adapter);
}
if (!filterAndQueryIsSame) {
localTipChats.clear();
if (finalResultArray != null) {
localTipChats.addAll(finalResultArray);
}
if (query.length() >= 3 && (LocaleController.getString("SavedMessages", R.string.SavedMessages).toLowerCase().startsWith(query) || "saved messages".startsWith(query))) {
boolean found = false;
for (int i = 0; i < localTipChats.size(); i++) {
if (localTipChats.get(i) instanceof TLRPC.User)
if (UserConfig.getInstance(UserConfig.selectedAccount).getCurrentUser().id == ((TLRPC.User) localTipChats.get(i)).id) {
found = true;
break;
}
}
if (!found) {
localTipChats.add(0, UserConfig.getInstance(UserConfig.selectedAccount).getCurrentUser());
}
}
localTipDates.clear();
localTipDates.addAll(dateData);
localTipArchive = false;
if (query.length() >= 3 && (LocaleController.getString("ArchiveSearchFilter", R.string.ArchiveSearchFilter).toLowerCase().startsWith(query) || "archive".startsWith(query))) {
localTipArchive = true;
}
if (delegate != null) {
delegate.updateFiltersView(TextUtils.isEmpty(currentDataQuery), localTipChats, localTipDates, localTipArchive);
}
}
firstLoading = false;
View progressView = null;
int progressViewPosition = -1;
for (int i = 0; i < n; i++) {
View child = recyclerListView.getChildAt(i);
if (child instanceof FlickerLoadingView) {
progressView = child;
progressViewPosition = recyclerListView.getChildAdapterPosition(child);
}
}
final View finalProgressView = progressView;
if (progressView != null) {
recyclerListView.removeView(progressView);
}
if ((loadingView.getVisibility() == View.VISIBLE && recyclerListView.getChildCount() == 0) || (recyclerListView.getAdapter() != sharedPhotoVideoAdapter && progressView != null)) {
int finalProgressViewPosition = progressViewPosition;
getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
int n = recyclerListView.getChildCount();
AnimatorSet animatorSet = new AnimatorSet();
for (int i = 0; i < n; i++) {
View child = recyclerListView.getChildAt(i);
if (finalProgressView != null) {
if (recyclerListView.getChildAdapterPosition(child) < finalProgressViewPosition) {
continue;
}
}
child.setAlpha(0);
int s = Math.min(recyclerListView.getMeasuredHeight(), Math.max(0, child.getTop()));
int delay = (int) ((s / (float) recyclerListView.getMeasuredHeight()) * 100);
ObjectAnimator a = ObjectAnimator.ofFloat(child, View.ALPHA, 0, 1f);
a.setStartDelay(delay);
a.setDuration(200);
animatorSet.playTogether(a);
}
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
}
});
animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
animatorSet.start();
if (finalProgressView != null && finalProgressView.getParent() == null) {
recyclerListView.addView(finalProgressView);
RecyclerView.LayoutManager layoutManager = recyclerListView.getLayoutManager();
if (layoutManager != null) {
layoutManager.ignoreView(finalProgressView);
Animator animator = ObjectAnimator.ofFloat(finalProgressView, ALPHA, finalProgressView.getAlpha(), 0);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
finalProgressView.setAlpha(1f);
layoutManager.stopIgnoringView(finalProgressView);
recyclerListView.removeView(finalProgressView);
}
});
animator.start();
}
}
return true;
}
});
}
adapter.notifyDataSetChanged();
});
});
}, (filterAndQueryIsSame && !messages.isEmpty()) ? 0 : 350);
if (currentSearchFilter == null) {
loadingView.setViewType(FlickerLoadingView.DIALOG_TYPE);
} else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MEDIA) {
if (!TextUtils.isEmpty(currentSearchString)) {
loadingView.setViewType(FlickerLoadingView.DIALOG_TYPE);
} else {
loadingView.setViewType(FlickerLoadingView.PHOTOS_TYPE);
}
} else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_FILES) {
loadingView.setViewType(FlickerLoadingView.FILES_TYPE);
} else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MUSIC || currentSearchFilter.filterType == FiltersView.FILTER_TYPE_VOICE) {
loadingView.setViewType(FlickerLoadingView.AUDIO_TYPE);
} else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_LINKS) {
loadingView.setViewType(FlickerLoadingView.LINKS_TYPE);
}
}
Aggregations