private void loadWallpapers() { TLRPC.TL_account_getWallPapers req = new TLRPC.TL_account_getWallPapers(); long reqId = ConnectionsManager.getInstance() .performRpc( req, new RPCRequest.RPCRequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { if (error != null) { return; } AndroidUtilities.RunOnUIThread( new Runnable() { @Override public void run() { wallPapers.clear(); TLRPC.Vector res = (TLRPC.Vector) response; wallpappersByIds.clear(); for (Object obj : res.objects) { wallPapers.add((TLRPC.WallPaper) obj); wallpappersByIds.put( ((TLRPC.WallPaper) obj).id, (TLRPC.WallPaper) obj); } listAdapter.notifyDataSetChanged(); if (backgroundImage != null) { processSelectedBackground(); } MessagesStorage.getInstance().putWallpapers(wallPapers); } }); } }); ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid); }
@Override protected void onPause() { super.onPause(); overridePendingTransition(0, 0); if (chatActivityEnterView != null) { chatActivityEnterView.hideEmojiPopup(); chatActivityEnterView.setFieldFocused(false); } ConnectionsManager.getInstance().setAppPaused(true, false); }
@Override protected void onResume() { super.onResume(); if (chatActivityEnterView != null) { chatActivityEnterView.setFieldFocused(true); } ConnectionsManager.getInstance().setAppPaused(false, false); fixLayout(); checkAndUpdateAvatar(); wakeLock.acquire(7000); }
public void updateServerNotificationsSettings() { if ((int) dialog_id == 0) { return; } SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences( "Notifications", Activity.MODE_PRIVATE); TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings(); req.settings = new TLRPC.TL_inputPeerNotifySettings(); req.settings.sound = "default"; req.settings.events_mask = 0; req.settings.mute_until = preferences.getInt("notify2_" + dialog_id, 0) != 2 ? 0 : Integer.MAX_VALUE; req.settings.show_previews = preferences.getBoolean("preview_" + dialog_id, true); req.peer = new TLRPC.TL_inputNotifyPeer(); if ((int) dialog_id < 0) { ((TLRPC.TL_inputNotifyPeer) req.peer).peer = new TLRPC.TL_inputPeerChat(); ((TLRPC.TL_inputNotifyPeer) req.peer).peer.chat_id = -(int) dialog_id; } else { TLRPC.User user = MessagesController.getInstance().users.get((int) dialog_id); if (user == null) { return; } if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) { ((TLRPC.TL_inputNotifyPeer) req.peer).peer = new TLRPC.TL_inputPeerForeign(); ((TLRPC.TL_inputNotifyPeer) req.peer).peer.access_hash = user.access_hash; } else { ((TLRPC.TL_inputNotifyPeer) req.peer).peer = new TLRPC.TL_inputPeerContact(); } ((TLRPC.TL_inputNotifyPeer) req.peer).peer.user_id = (int) dialog_id; } ConnectionsManager.getInstance() .performRpc( req, new RPCRequest.RPCRequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) {} }); }
private void saveName() { TLRPC.User currentUser = UserConfig.getCurrentUser(); if (currentUser == null || lastNameField.getText() == null || firstNameField.getText() == null) { return; } String newFirst = firstNameField.getText().toString(); String newLast = lastNameField.getText().toString(); if (currentUser.first_name != null && currentUser.first_name.equals(newFirst) && currentUser.last_name != null && currentUser.last_name.equals(newLast)) { return; } TLRPC.TL_account_updateProfile req = new TLRPC.TL_account_updateProfile(); currentUser.first_name = req.first_name = newFirst; currentUser.last_name = req.last_name = newLast; TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId()); if (user != null) { user.first_name = req.first_name; user.last_name = req.last_name; } UserConfig.saveConfig(true); NotificationCenter.getInstance().postNotificationName(NotificationCenter.mainUserInfoChanged); NotificationCenter.getInstance() .postNotificationName( NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME); ConnectionsManager.getInstance() .performRpc( req, new RPCRequest.RPCRequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) {} }); }
public static void searchMessagesInChat( String query, long dialog_id, final int guid, int direction) { if (reqId != 0) { ConnectionsManager.getInstance().cancelRpc(reqId, true); reqId = 0; } int max_id = 0; if (query == null || query.length() == 0) { if (direction == 1) { lastReturnedNum++; if (lastReturnedNum < searchResultMessages.size()) { NotificationCenter.getInstance() .postNotificationName( NotificationCenter.chatSearchResultsAvailable, guid, searchResultMessages.get(lastReturnedNum).getId(), getMask()); return; } else { if (messagesSearchEndReached) { lastReturnedNum--; return; } query = lastSearchQuery; max_id = searchResultMessages.get(searchResultMessages.size() - 1).getId(); } } else if (direction == 2) { lastReturnedNum--; if (lastReturnedNum < 0) { lastReturnedNum = 0; return; } NotificationCenter.getInstance() .postNotificationName( NotificationCenter.chatSearchResultsAvailable, guid, searchResultMessages.get(lastReturnedNum).getId(), getMask()); return; } else { return; } } final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search(); req.limit = 21; int lower_part = (int) dialog_id; if (lower_part < 0) { req.peer = new TLRPC.TL_inputPeerChat(); req.peer.chat_id = -lower_part; } else { TLRPC.User user = MessagesController.getInstance().getUser(lower_part); if (user == null) { return; } if (user.access_hash != 0) { req.peer = new TLRPC.TL_inputPeerForeign(); req.peer.access_hash = user.access_hash; } else { req.peer = new TLRPC.TL_inputPeerContact(); } req.peer.user_id = lower_part; } req.q = query; req.max_id = max_id; req.filter = new TLRPC.TL_inputMessagesFilterEmpty(); final int currentReqId = ++lastReqId; lastSearchQuery = query; reqId = ConnectionsManager.getInstance() .performRpc( req, new RPCRequest.RPCRequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread( new Runnable() { @Override public void run() { if (currentReqId == lastReqId) { if (error == null) { TLRPC.messages_Messages res = (TLRPC.messages_Messages) response; MessagesStorage.getInstance() .putUsersAndChats(res.users, res.chats, true, true); MessagesController.getInstance().putUsers(res.users, false); MessagesController.getInstance().putChats(res.chats, false); if (req.max_id == 0) { lastReturnedNum = 0; searchResultMessages.clear(); } boolean added = false; for (int a = 0; a < Math.min(res.messages.size(), 20); a++) { TLRPC.Message message = res.messages.get(a); added = true; searchResultMessages.add(new MessageObject(message, null, false)); } messagesSearchEndReached = res.messages.size() != 21; if (searchResultMessages.isEmpty()) { NotificationCenter.getInstance() .postNotificationName( NotificationCenter.chatSearchResultsAvailable, guid, 0, getMask()); } else { if (added) { NotificationCenter.getInstance() .postNotificationName( NotificationCenter.chatSearchResultsAvailable, guid, searchResultMessages.get(lastReturnedNum).getId(), getMask()); } } } } reqId = 0; } }); } }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors); }
public void build(int width, int height) { CharSequence nameString = ""; TextPaint currentNamePaint; if (encryptedChat != null) { drawNameLock = true; if (!LocaleController.isRTL) { nameLockLeft = Utilities.dp(61 + (usePadding ? 11 : 0)); nameLeft = Utilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth(); } else { nameLockLeft = width - Utilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth(); nameLeft = usePadding ? Utilities.dp(11) : 0; } } else { drawNameLock = false; if (!LocaleController.isRTL) { nameLeft = Utilities.dp(61 + (usePadding ? 11 : 0)); } else { nameLeft = usePadding ? Utilities.dp(11) : 0; } } if (currentName != null) { nameString = currentName; } else { String nameString2 = ""; if (chat != null) { nameString2 = chat.title; } else if (user != null) { nameString2 = Utilities.formatName(user.first_name, user.last_name); } nameString = nameString2.replace("\n", " "); } if (nameString.length() == 0) { if (user.phone != null && user.phone.length() != 0) { nameString = PhoneFormat.getInstance().format("+" + user.phone); } else { nameString = LocaleController.getString("HiddenName", R.string.HiddenName); } } if (encryptedChat != null) { currentNamePaint = nameEncryptedPaint; } else { currentNamePaint = namePaint; } if (!LocaleController.isRTL) { onlineWidth = nameWidth = width - nameLeft - Utilities.dp(3 + (usePadding ? 11 : 0)); } else { onlineWidth = nameWidth = width - nameLeft - Utilities.dp(61 + (usePadding ? 11 : 0)); } if (drawNameLock) { nameWidth -= Utilities.dp(6) + lockDrawable.getIntrinsicWidth(); } CharSequence nameStringFinal = TextUtils.ellipsize( nameString, currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END); nameLayout = new StaticLayout( nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); if (chat == null) { if (!LocaleController.isRTL) { onlineLeft = Utilities.dp(61 + (usePadding ? 11 : 0)); } else { onlineLeft = usePadding ? Utilities.dp(11) : 0; } String onlineString = ""; TextPaint currentOnlinePaint = offlinePaint; if (subLabel != null) { onlineString = subLabel; } else { if (user != null) { if (user.status == null) { onlineString = getResources().getString(R.string.Offline); } else { int currentTime = ConnectionsManager.getInstance().getCurrentTime(); if (user.id == UserConfig.clientUserId || user.status.expires > currentTime) { currentOnlinePaint = onlinePaint; onlineString = getResources().getString(R.string.Online); } else { if (user.status.expires <= 10000) { onlineString = getResources().getString(R.string.Invisible); } else { onlineString = LocaleController.formatDateOnline(user.status.expires); } } } } } CharSequence onlineStringFinal = TextUtils.ellipsize( onlineString, currentOnlinePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END); onlineLayout = new StaticLayout( onlineStringFinal, currentOnlinePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); nameTop = Utilities.dp(12); } else { onlineLayout = null; nameTop = Utilities.dp(22); } if (!LocaleController.isRTL) { avatarLeft = usePadding ? Utilities.dp(11) : 0; } else { avatarLeft = width - Utilities.dp(50 + (usePadding ? 11 : 0)); } avatarImage.imageX = avatarLeft; avatarImage.imageY = avatarTop; avatarImage.imageW = Utilities.dp(50); avatarImage.imageH = Utilities.dp(50); double widthpx = 0; float left = 0; if (LocaleController.isRTL) { if (nameLayout.getLineCount() > 0) { left = nameLayout.getLineLeft(0); if (left == 0) { widthpx = Math.ceil(nameLayout.getLineWidth(0)); if (widthpx < nameWidth) { nameLeft += (nameWidth - widthpx); } } } if (onlineLayout != null && onlineLayout.getLineCount() > 0) { left = onlineLayout.getLineLeft(0); if (left == 0) { widthpx = Math.ceil(onlineLayout.getLineWidth(0)); if (widthpx < onlineWidth) { onlineLeft += (onlineWidth - widthpx); } } } } else { if (nameLayout.getLineCount() > 0) { left = nameLayout.getLineRight(0); if (left == nameWidth) { widthpx = Math.ceil(nameLayout.getLineWidth(0)); if (widthpx < nameWidth) { nameLeft -= (nameWidth - widthpx); } } } if (onlineLayout != null && onlineLayout.getLineCount() > 0) { left = onlineLayout.getLineRight(0); if (left == onlineWidth) { widthpx = Math.ceil(onlineLayout.getLineWidth(0)); if (widthpx < onlineWidth) { onlineLeft -= (onlineWidth - widthpx); } } } } }
@Override public View getItemView(int section, int position, View convertView, ViewGroup parent) { TLRPC.User user; int size; if (searchWas && searching) { user = MessagesController.getInstance().getUser(searchResult.get(position).id); size = searchResult.size(); } else { ArrayList<TLRPC.TL_contact> arr = ContactsController.getInstance() .usersSectionsDict .get(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); user = MessagesController.getInstance().getUser(arr.get(position).user_id); size = arr.size(); } if (convertView == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = li.inflate(R.layout.group_create_row_layout, parent, false); } ContactListRowHolder holder = (ContactListRowHolder) convertView.getTag(); if (holder == null) { holder = new ContactListRowHolder(convertView); convertView.setTag(holder); } ImageView checkButton = (ImageView) convertView.findViewById(R.id.settings_row_check_button); if (selectedContacts.containsKey(user.id)) { checkButton.setImageResource(R.drawable.btn_check_on_holo_light); } else { checkButton.setImageResource(R.drawable.btn_check_off_holo_light); } View divider = convertView.findViewById(R.id.settings_row_divider); if (position == size - 1) { divider.setVisibility(View.INVISIBLE); } else { divider.setVisibility(View.VISIBLE); } if (searchWas && searching) { holder.nameTextView.setText(searchResultNames.get(position)); } else { String name = ContactsController.formatName(user.first_name, user.last_name); if (name.length() == 0) { if (user.phone != null && user.phone.length() != 0) { name = PhoneFormat.getInstance().format("+" + user.phone); } else { name = LocaleController.getString("HiddenName", R.string.HiddenName); } } holder.nameTextView.setText(name); } TLRPC.FileLocation photo = null; if (user.photo != null) { photo = user.photo.photo_small; } int placeHolderId = AndroidUtilities.getUserAvatarForId(user.id); holder.avatarImage.setImage(photo, "50_50", placeHolderId); holder.messageTextView.setText(LocaleController.formatUserStatus(user)); if (user.status != null && user.status.expires > ConnectionsManager.getInstance().getCurrentTime()) { holder.messageTextView.setTextColor(0xff357aa8); } else { holder.messageTextView.setTextColor(0xff808080); } return convertView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); classGuid = ConnectionsManager.getInstance().generateClassGuid(); NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout); NotificationCenter.getInstance().addObserver(this, NotificationCenter.pushMessagesUpdated); NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset); NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded); typingDotsDrawable = new TypingDotsDrawable(); recordStatusDrawable = new RecordStatusDrawable(); SizeNotifierRelativeLayout contentView = new SizeNotifierRelativeLayout(this); setContentView(contentView); contentView.setBackgroundColor(0x99000000); RelativeLayout relativeLayout = new RelativeLayout(this); contentView.addView(relativeLayout); RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = LayoutHelper.MATCH_PARENT; relativeLayout.setLayoutParams(layoutParams3); RelativeLayout popupContainer = new RelativeLayout(this); popupContainer.setBackgroundColor(0xffffffff); relativeLayout.addView(popupContainer); layoutParams3 = (RelativeLayout.LayoutParams) popupContainer.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = AndroidUtilities.dp(240); layoutParams3.leftMargin = AndroidUtilities.dp(12); layoutParams3.rightMargin = AndroidUtilities.dp(12); layoutParams3.addRule(RelativeLayout.CENTER_IN_PARENT); popupContainer.setLayoutParams(layoutParams3); if (chatActivityEnterView != null) { chatActivityEnterView.onDestroy(); } chatActivityEnterView = new ChatActivityEnterView(this, contentView, null, false); popupContainer.addView(chatActivityEnterView); layoutParams3 = (RelativeLayout.LayoutParams) chatActivityEnterView.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); chatActivityEnterView.setLayoutParams(layoutParams3); chatActivityEnterView.setDelegate( new ChatActivityEnterView.ChatActivityEnterViewDelegate() { @Override public void onMessageSend(String message) { if (currentMessageObject == null) { return; } if (currentMessageNum >= 0 && currentMessageNum < NotificationsController.getInstance().popupMessages.size()) { NotificationsController.getInstance().popupMessages.remove(currentMessageNum); } MessagesController.getInstance() .markDialogAsRead( currentMessageObject.getDialogId(), currentMessageObject.getId(), Math.max(0, currentMessageObject.getId()), 0, currentMessageObject.messageOwner.date, true, true); currentMessageObject = null; getNewMessage(); } @Override public void onTextChanged(CharSequence text, boolean big) {} @Override public void needSendTyping() { if (currentMessageObject != null) { MessagesController.getInstance() .sendTyping(currentMessageObject.getDialogId(), 0, classGuid); } } @Override public void onAttachButtonHidden() {} @Override public void onAttachButtonShow() {} @Override public void onWindowSizeChanged(int size) {} }); messageContainer = new FrameLayoutTouch(this); popupContainer.addView(messageContainer, 0); actionBar = new ActionBar(this); actionBar.setOccupyStatusBar(false); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setBackgroundColor(0xff54759e); actionBar.setItemsBackground(R.drawable.bar_selector); popupContainer.addView(actionBar); ViewGroup.LayoutParams layoutParams = actionBar.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; actionBar.setLayoutParams(layoutParams); ActionBarMenu menu = actionBar.createMenu(); View view = menu.addItemResource(2, R.layout.popup_count_layout); countText = (TextView) view.findViewById(R.id.count_text); avatarContainer = new FrameLayoutFixed(this); avatarContainer.setBackgroundResource(R.drawable.bar_selector); avatarContainer.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); actionBar.addView(avatarContainer); FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) avatarContainer.getLayoutParams(); layoutParams2.height = LayoutHelper.MATCH_PARENT; layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.rightMargin = AndroidUtilities.dp(48); layoutParams2.leftMargin = AndroidUtilities.dp(60); layoutParams2.gravity = Gravity.TOP | Gravity.LEFT; avatarContainer.setLayoutParams(layoutParams2); avatarImageView = new BackupImageView(this); avatarImageView.setRoundRadius(AndroidUtilities.dp(21)); avatarContainer.addView(avatarImageView); layoutParams2 = (FrameLayout.LayoutParams) avatarImageView.getLayoutParams(); layoutParams2.width = AndroidUtilities.dp(42); layoutParams2.height = AndroidUtilities.dp(42); layoutParams2.topMargin = AndroidUtilities.dp(3); avatarImageView.setLayoutParams(layoutParams2); nameTextView = new TextView(this); nameTextView.setTextColor(0xffffffff); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); nameTextView.setLines(1); nameTextView.setMaxLines(1); nameTextView.setSingleLine(true); nameTextView.setEllipsize(TextUtils.TruncateAt.END); nameTextView.setGravity(Gravity.LEFT); nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); avatarContainer.addView(nameTextView); layoutParams2 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.leftMargin = AndroidUtilities.dp(54); layoutParams2.bottomMargin = AndroidUtilities.dp(22); layoutParams2.gravity = Gravity.BOTTOM; nameTextView.setLayoutParams(layoutParams2); onlineTextView = new TextView(this); onlineTextView.setTextColor(0xffd7e8f7); onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); onlineTextView.setLines(1); onlineTextView.setMaxLines(1); onlineTextView.setSingleLine(true); onlineTextView.setEllipsize(TextUtils.TruncateAt.END); onlineTextView.setGravity(Gravity.LEFT); avatarContainer.addView(onlineTextView); layoutParams2 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.leftMargin = AndroidUtilities.dp(54); layoutParams2.bottomMargin = AndroidUtilities.dp(4); layoutParams2.gravity = Gravity.BOTTOM; onlineTextView.setLayoutParams(layoutParams2); actionBar.setActionBarMenuOnItemClick( new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { onFinish(); finish(); } else if (id == 1) { openCurrentMessage(); } else if (id == 2) { switchToNextMessage(); } } }); PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock( PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen"); wakeLock.setReferenceCounted(false); handleIntent(getIntent()); }