1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2025-01-19 07:30:17 +01:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
世界 2020-10-15 01:27:09 +00:00
commit 8ac57d1951
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
16 changed files with 127 additions and 57 deletions

View File

@ -57,7 +57,6 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
@ -2253,7 +2252,7 @@ public class AndroidUtilities {
}
public static CharSequence generateSearchName(String name, String name2, String q) {
if (name == null && name2 == null) {
if (name == null && name2 == null || TextUtils.isEmpty(q)) {
return "";
}
SpannableStringBuilder builder = new SpannableStringBuilder();
@ -2286,7 +2285,7 @@ public class AndroidUtilities {
int start = builder.length();
builder.append(query);
builder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4)), start, start + query.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), start, start + query.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
lastIndex = end;
}

View File

@ -11135,7 +11135,7 @@ public class MessagesController extends BaseController implements NotificationCe
messages.put(message.dialog_id, arr);
}
arr.add(obj);
if ((!obj.isOut() || obj.messageOwner.from_scheduled) && obj.isUnread() && !ChatObject.isNotInChat(chat) && chat.min) {
if ((!obj.isOut() || obj.messageOwner.from_scheduled) && obj.isUnread() && (chat == null || !ChatObject.isNotInChat(chat) && !chat.min)) {
if (pushMessages == null) {
pushMessages = new ArrayList<>();
}

View File

@ -1540,7 +1540,11 @@ public class MessagesStorage extends BaseController {
}
if (message.replyMessage == null) {
long messageId = message.reply_to.reply_to_msg_id;
if (message.peer_id.channel_id != 0) {
if (message.reply_to.reply_to_peer_id != null) {
if (message.reply_to.reply_to_peer_id.channel_id != 0) {
messageId |= ((long) message.reply_to.reply_to_peer_id.channel_id) << 32;
}
} else if (message.peer_id.channel_id != 0) {
messageId |= ((long) message.peer_id.channel_id) << 32;
}
if (!replyMessages.contains(messageId)) {
@ -2691,7 +2695,11 @@ public class MessagesStorage extends BaseController {
}
if (message.replyMessage == null) {
long messageId = message.reply_to.reply_to_msg_id;
if (message.peer_id.channel_id != 0) {
if (message.reply_to.reply_to_peer_id != null) {
if (message.reply_to.reply_to_peer_id.channel_id != 0) {
messageId |= ((long) message.reply_to.reply_to_peer_id.channel_id) << 32;
}
} else if (message.peer_id.channel_id != 0) {
messageId |= ((long) message.peer_id.channel_id) << 32;
}
if (!replyMessages.contains(messageId)) {
@ -5881,7 +5889,11 @@ public class MessagesStorage extends BaseController {
if (message.replyMessage == null) {
if (message.reply_to.reply_to_msg_id != 0) {
long messageId = message.reply_to.reply_to_msg_id;
if (message.peer_id.channel_id != 0) {
if (message.reply_to.reply_to_peer_id != null) {
if (message.reply_to.reply_to_peer_id.channel_id != 0) {
messageId |= ((long) message.reply_to.reply_to_peer_id.channel_id) << 32;
}
} else if (message.peer_id.channel_id != 0) {
messageId |= ((long) message.peer_id.channel_id) << 32;
}
if (!replyMessages.contains(messageId)) {
@ -6342,7 +6354,11 @@ public class MessagesStorage extends BaseController {
if (message.replyMessage == null) {
if (message.reply_to.reply_to_msg_id != 0) {
long messageId = message.reply_to.reply_to_msg_id;
if (message.peer_id.channel_id != 0) {
if (message.reply_to.reply_to_peer_id != null) {
if (message.reply_to.reply_to_peer_id.channel_id != 0) {
messageId |= ((long) message.reply_to.reply_to_peer_id.channel_id) << 32;
}
} else if (message.peer_id.channel_id != 0) {
messageId |= ((long) message.peer_id.channel_id) << 32;
}
if (!replyMessages.contains(messageId)) {
@ -10070,7 +10086,11 @@ public class MessagesStorage extends BaseController {
}
if (message.replyMessage == null) {
long messageId = message.reply_to.reply_to_msg_id;
if (message.peer_id.channel_id != 0) {
if (message.reply_to.reply_to_peer_id != null) {
if (message.reply_to.reply_to_peer_id.channel_id != 0) {
messageId |= ((long) message.reply_to.reply_to_peer_id.channel_id) << 32;
}
} else if (message.peer_id.channel_id != 0) {
messageId |= ((long) message.peer_id.channel_id) << 32;
}
if (!replyMessages.contains(messageId)) {

View File

@ -2578,8 +2578,10 @@ public class Theme {
public static final String key_chat_inAudioSelectedProgress = "chat_inAudioSelectedProgress";
public static final String key_chat_outAudioSelectedProgress = "chat_outAudioSelectedProgress";
public static final String key_chat_mediaTimeText = "chat_mediaTimeText";
public static final String key_chat_adminText = "chat_adminText";
public static final String key_chat_adminSelectedText = "chat_adminSelectedText";
public static final String key_chat_inAdminText = "chat_adminText";
public static final String key_chat_inAdminSelectedText = "chat_adminSelectedText";
public static final String key_chat_outAdminText = "chat_outAdminText";
public static final String key_chat_outAdminSelectedText = "chat_outAdminSelectedText";
public static final String key_chat_inTimeText = "chat_inTimeText";
public static final String key_chat_outTimeText = "chat_outTimeText";
public static final String key_chat_inTimeSelectedText = "chat_inTimeSelectedText";
@ -3289,11 +3291,13 @@ public class Theme {
defaultColors.put(key_chat_inAudioSelectedProgress, 0xffeff8fe);
defaultColors.put(key_chat_outAudioSelectedProgress, 0xffe1f8cf);
defaultColors.put(key_chat_mediaTimeText, 0xffffffff);
defaultColors.put(key_chat_inAdminText, 0xffc0c6cb);
defaultColors.put(key_chat_inAdminSelectedText, 0xff89b4c1);
defaultColors.put(key_chat_outAdminText, 0xff70b15c);
defaultColors.put(key_chat_outAdminSelectedText, 0xff70b15c);
defaultColors.put(key_chat_inTimeText, 0xffa1aab3);
defaultColors.put(key_chat_outTimeText, 0xff70b15c);
defaultColors.put(key_chat_adminText, 0xffc0c6cb);
defaultColors.put(key_chat_adminSelectedText, 0xff89b4c1);
defaultColors.put(key_chat_inTimeSelectedText, 0xff89b4c1);
defaultColors.put(key_chat_outTimeText, 0xff70b15c);
defaultColors.put(key_chat_outTimeSelectedText, 0xff70b15c);
defaultColors.put(key_chat_inAudioPerformerText, 0xff2f3438);
defaultColors.put(key_chat_inAudioPerformerSelectedText, 0xff2f3438);
@ -3620,8 +3624,8 @@ public class Theme {
defaultColors.put(key_statisticChartLineEmpty, 0xFFEEEEEE);
defaultColors.put(key_actionBarTipBackground, 0xFF446F94);
fallbackKeys.put(key_chat_adminText, key_chat_inTimeText);
fallbackKeys.put(key_chat_adminSelectedText, key_chat_inTimeSelectedText);
fallbackKeys.put(key_chat_inAdminText, key_chat_inTimeText);
fallbackKeys.put(key_chat_inAdminSelectedText, key_chat_inTimeSelectedText);
fallbackKeys.put(key_player_progressCachedBackground, key_player_progressBackground);
fallbackKeys.put(key_chat_inAudioCacheSeekbar, key_chat_inAudioSeekbar);
fallbackKeys.put(key_chat_outAudioCacheSeekbar, key_chat_outAudioSeekbar);
@ -3749,6 +3753,9 @@ public class Theme {
fallbackKeys.put(key_chat_inPsaNameText, key_avatar_nameInMessageGreen);
fallbackKeys.put(key_chat_outPsaNameText, key_avatar_nameInMessageGreen);
fallbackKeys.put(key_chat_outAdminText, key_chat_outTimeText);
fallbackKeys.put(key_chat_outAdminSelectedText, key_chat_outTimeSelectedText);
themeAccentExclusionKeys.addAll(Arrays.asList(keys_avatar_background));
themeAccentExclusionKeys.addAll(Arrays.asList(keys_avatar_nameInMessage));
themeAccentExclusionKeys.add(key_chat_attachFileBackground);

View File

@ -18,15 +18,17 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.recyclerview.widget.RecyclerView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Cells.DividerCell;
@ -44,8 +46,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import androidx.recyclerview.widget.RecyclerView;
public class ContactsAdapter extends RecyclerListView.SectionsAdapter {
private int currentAccount = UserConfig.selectedAccount;
@ -77,10 +77,10 @@ public class ContactsAdapter extends RecyclerListView.SectionsAdapter {
disableSections = value;
}
public void setSortType(int value) {
public void setSortType(int value, boolean force) {
sortType = value;
if (sortType == 2) {
if (onlineContacts == null) {
if (onlineContacts == null || force) {
onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
int selfId = UserConfig.getInstance(currentAccount).clientUserId;
for (int a = 0, N = onlineContacts.size(); a < N; a++) {
@ -191,7 +191,7 @@ public class ContactsAdapter extends RecyclerListView.SectionsAdapter {
}
}
}
if (needPhonebook) {
if (needPhonebook && position >= 0 && position < ContactsController.getInstance(currentAccount).phoneBookContacts.size()) {
return ContactsController.getInstance(currentAccount).phoneBookContacts.get(position);
}
return null;

View File

@ -10104,7 +10104,12 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
nameLayout.draw(canvas);
canvas.restore();
if (adminLayout != null) {
int color = Theme.getColor(isDrawSelectionBackground() ? Theme.key_chat_adminSelectedText : Theme.key_chat_adminText);
int color;
if (currentMessageObject.isOutOwner()) {
color = Theme.getColor(isDrawSelectionBackground() ? Theme.key_chat_outAdminSelectedText : Theme.key_chat_outAdminText);
} else {
color = Theme.getColor(isDrawSelectionBackground() ? Theme.key_chat_inAdminSelectedText : Theme.key_chat_inAdminText);
}
Theme.chat_adminPaint.setColor(color);
canvas.save();
float ax;

View File

@ -54,7 +54,7 @@ public class SharingLiveLocationCell extends FrameLayout {
private LocationActivity.LiveLocation liveLocation;
private Location location = new Location("network");
private int currentAccount;
private int currentAccount = UserConfig.selectedAccount;
private Runnable invalidateRunnable = new Runnable() {
@Override

View File

@ -2272,6 +2272,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
updateChatListViewTopPadding();
chatListView.setItemAnimator(null);
chatListView.invalidate();
}
@Override
@ -2486,6 +2487,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
int chatListViewTop = (int) chatListView.getY();
int chatListViewBottom = chatListViewTop + chatListView.getMeasuredHeight();
float listTop = chatListView.getTop() + chatListView.getPaddingTop() - AndroidUtilities.dp(4);
if (threadMessageId != 0 && !replyMessageVisible) {
listTop += AndroidUtilities.dp(48);
}
MessageObject.GroupedMessages scrimGroup;
if (scrimView instanceof ChatMessageCell) {
scrimGroup = ((ChatMessageCell) scrimView).getCurrentMessagesGroup();
@ -3042,6 +3046,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private boolean wasTrackingVibrate;
private float replyButtonProgress;
private long lastReplyButtonAnimationTime;
private float cilpTop;
private boolean ignoreLayout;
@ -3061,6 +3066,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (emptyViewContainer != null) {
emptyViewContainer.setTranslationY(translationY / 2f);
}
invalidate();
}
@ -3355,7 +3361,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
}
ArrayList<MessageObject.GroupedMessages> drawingGroups = new ArrayList<>(10);
@Override
@ -3558,8 +3563,14 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
}
}
canvas.save();
cilpTop = actionBar.getY() + actionBar.getMeasuredHeight() - getY();
if (pinnedMessageView != null) {
cilpTop += Math.max(0, AndroidUtilities.dp(48) + pinnedMessageEnterOffset);
}
canvas.clipRect(0, cilpTop, getMeasuredWidth(), getMeasuredHeight());
super.dispatchDraw(canvas);
canvas.restore();
}
@Override
@ -3569,7 +3580,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
boolean skipDraw = child == scrimView;
ChatMessageCell cell;
if (child.getY() > getMeasuredHeight() || child.getY() + child.getMeasuredHeight() < 0) {
if (child.getY() > getMeasuredHeight() || child.getY() + child.getMeasuredHeight() < cilpTop) {
skipDraw = true;
}
@ -11710,20 +11721,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
boolean updateChat = false;
boolean hasFromMe = false;
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[1];
if (currentEncryptedChat != null && arr.size() == 1) {
MessageObject obj = arr.get(0);
if (currentEncryptedChat != null && obj.isOut() && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && getParentActivity() != null) {
if (AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 17 && currentEncryptedChat.ttl > 0 && currentEncryptedChat.ttl <= 60) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setMessage(LocaleController.formatString("CompatibilityChat", R.string.CompatibilityChat, currentUser.first_name, currentUser.first_name));
showDialog(builder.create());
}
}
}
if (chatListItemAniamtor != null) {
chatListItemAniamtor.setShouldAnimateEnterFromBottom(true);
@ -14815,6 +14812,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
animator.addUpdateListener(animation -> {
pinnedMessageEnterOffset = (float) animation.getAnimatedValue();
invalidateChatListViewTopPadding();
chatListView.invalidate();
});
pinnedMessageViewAnimator.playTogether(animator);
pinnedMessageViewAnimator.setDuration(200);
@ -14838,6 +14836,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
pinnedMessageEnterOffset = -AndroidUtilities.dp(50);
pinnedMessageView.setVisibility(View.GONE);
chatListView.invalidate();
}
return true;
}
@ -14917,6 +14916,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
pinnedMessageEnterOffset = translationY;
invalidateChatListViewTopPadding();
chatListView.invalidate();
}
});
pinnedMessageView.setVisibility(View.VISIBLE);
@ -14942,6 +14942,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
pinnedMessageEnterOffset = 0;
invalidateChatListViewTopPadding();
chatListView.invalidate();
if (firstLoading) {
updateChatListViewTopPadding();
}
@ -20649,8 +20650,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_inTimeText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_outTimeText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_inTimeSelectedText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_adminText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_adminSelectedText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_inAdminText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_inAdminSelectedText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_outAdminText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_outAdminSelectedText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_outTimeSelectedText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_inAudioPerformerText));
themeDescriptions.add(new ThemeDescription(chatListView, 0, new Class[]{ChatMessageCell.class}, null, null, null, Theme.key_chat_inAudioPerformerSelectedText));

View File

@ -3056,6 +3056,8 @@ public class AlertsCreator {
if (!(participant.participant instanceof TLRPC.TL_channelParticipantAdmin || participant.participant instanceof TLRPC.TL_channelParticipantCreator)) {
loadType = 0;
}
} else if (error != null && "USER_NOT_PARTICIPANT".equals(error.text)) {
loadType = 0;
}
createDeleteMessagesAlert(fragment, user, chat, encryptedChat, chatInfo, mergeDialogId, selectedMessage, selectedMessages, selectedGroup, scheduled, loadType, onDelete);
}));

View File

@ -1868,7 +1868,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe
public ChatActivityEnterView(Activity context, SizeNotifierFrameLayout parent, ChatActivity fragment, final boolean isChat) {
super(context);
smoothKeyboard = isChat && SharedConfig.smoothKeyboard;
smoothKeyboard = isChat && SharedConfig.smoothKeyboard && !AndroidUtilities.isInMultiwindow && (fragment == null || !fragment.isInBubbleMode());
dotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
dotPaint.setColor(Theme.getColor(Theme.key_chat_emojiPanelNewTrending));
setFocusable(true);
@ -3522,7 +3522,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe
sizeNotifierLayout.removeView(emojiView);
emojiView = null;
} else {
if (emojiViewVisible && (!waitingForKeyboardOpen)) {
if (emojiViewVisible && !waitingForKeyboardOpen) {
removeEmojiViewAfterAnimation = true;
hidePopup(false);
} else {
@ -3533,8 +3533,6 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe
emojiView = null;
}
}
}
allowStickers = value;
allowGifs = value2;
@ -7089,12 +7087,12 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe
}
private void openKeyboardInternal() {
showPopup(AndroidUtilities.usingHardwareInput || isPaused ? 0 : 2, 0);
showPopup(AndroidUtilities.usingHardwareInput || AndroidUtilities.isInMultiwindow || parentFragment != null && parentFragment.isInBubbleMode() || isPaused ? 0 : 2, 0);
messageEditText.requestFocus();
AndroidUtilities.showKeyboard(messageEditText);
if (isPaused) {
showKeyboardOnResume = true;
} else if (!AndroidUtilities.usingHardwareInput && !keyboardVisible && !AndroidUtilities.isInMultiwindow) {
} else if (!AndroidUtilities.usingHardwareInput && !keyboardVisible && !AndroidUtilities.isInMultiwindow && (parentFragment == null || !parentFragment.isInBubbleMode())) {
waitingForKeyboardOpen = true;
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);

View File

@ -3212,7 +3212,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
setBackgroundResource(R.drawable.smiles_popup);
getBackground().setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelBackground), PorterDuff.Mode.SRC_IN));
if (needEmojiSearch) {
bottomTabContainerBackground.setBackgroundDrawable(null);
bottomTabContainerBackground.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
}
currentBackgroundType = 1;
}

View File

@ -228,7 +228,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
} else if (id == sort_button) {
SharedConfig.toggleSortContactsByName();
sortByName = SharedConfig.sortContactsByName;
listViewAdapter.setSortType(sortByName ? 1 : 2);
listViewAdapter.setSortType(sortByName ? 1 : 2, false);
sortItem.setIcon(sortByName ? R.drawable.contacts_sort_time : R.drawable.contacts_sort_name);
}
}
@ -332,7 +332,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
}
};
listViewAdapter.setSortType(sortItem != null ? (sortByName ? 1 : 2) : 0);
listViewAdapter.setSortType(sortItem != null ? (sortByName ? 1 : 2) : 0, false);
listViewAdapter.setDisableSections(disableSections);
fragmentView = new FrameLayout(context) {
@ -852,6 +852,9 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.contactsDidLoad) {
if (listViewAdapter != null) {
if (!sortByName) {
listViewAdapter.setSortType(2, true);
}
listViewAdapter.notifyDataSetChanged();
}
} else if (id == NotificationCenter.updateInterfaces) {

View File

@ -2304,7 +2304,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
final BaseFragment lastFragment = actionBarLayout.getLastFragment();
if (lastFragment != null && lastFragment.getParentActivity() != null) {
final String finalNewContactName = newContactName;
final String finalNewContactPhone = "+" + PhoneFormat.stripExceptNumbers(newContactPhone);
final String finalNewContactPhone = NewContactActivity.getPhoneNumber(this, UserConfig.getInstance(currentAccount).getCurrentUser(), newContactPhone, false);
final AlertDialog newContactAlertDialog = new AlertDialog.Builder(lastFragment.getParentActivity())
.setTitle(LocaleController.getString("NewContactAlertTitle", R.string.NewContactAlertTitle))
.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("NewContactAlertMessage", R.string.NewContactAlertMessage, PhoneFormat.getInstance().format(finalNewContactPhone))))
@ -2409,6 +2409,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
chatActivity.setThreadMessages(arrayList, chat, req.msg_id, res.read_inbox_max_id, res.read_outbox_max_id);
if (commentId != null) {
chatActivity.setHighlightMessageId(commentId);
} else if (threadId != null) {
chatActivity.setHighlightMessageId(messageId);
}
presentFragment(chatActivity);
chatOpened = true;

View File

@ -2114,6 +2114,7 @@ public class LoginActivity extends BaseFragment implements NotificationCenter.No
boolean allowCancelCall = true;
boolean allowReadCallLog = true;
if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
allowCancelCall = getParentActivity().checkSelfPermission(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED;
allowReadCallLog = Build.VERSION.SDK_INT < 28 || getParentActivity().checkSelfPermission(Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED;

View File

@ -516,7 +516,7 @@ public class NewContactActivity extends BaseFragment implements AdapterView.OnIt
}
phoneField.setText(builder);
if (start >= 0) {
phoneField.setSelection(start <= phoneField.length() ? start : phoneField.length());
phoneField.setSelection(Math.min(start, phoneField.length()));
}
phoneField.onTextChange();
ignoreOnPhoneChange = false;
@ -610,6 +610,36 @@ public class NewContactActivity extends BaseFragment implements AdapterView.OnIt
return fragmentView;
}
public static String getPhoneNumber(Context context, TLRPC.User user, String number, boolean withCoutryCode) {
HashMap<String, String> codesMap = new HashMap<>();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
String line;
while ((line = reader.readLine()) != null) {
String[] args = line.split(";");
codesMap.put(args[0], args[2]);
}
reader.close();
} catch (Exception e) {
FileLog.e(e);
}
if (number.startsWith("+")) {
return number;
} else if (withCoutryCode || user == null || TextUtils.isEmpty(user.phone)) {
return "+" + number;
} else {
String phone = user.phone;
for (int a = 4; a >= 1; a--) {
String sub = phone.substring(0, a);
String country = codesMap.get(sub);
if (country != null) {
return "+" + sub + number;
}
}
return number;
}
}
private void invalidateAvatar() {
avatarDrawable.setInfo(5, firstNameField.getText().toString(), lastNameField.getText().toString());
avatarImage.invalidate();

View File

@ -1217,7 +1217,7 @@
<string name="NoContactsYetLine2">Find people nearby to chat with</string>
<string name="NoContactsYetLine3">Search people by username</string>
<string name="NewContactAlertTitle">New contact</string>
<string name="NewContactAlertMessage">Phone number **%1$s** is not in your contact list. Do you want to add it?</string>
<string name="NewContactAlertMessage">Phone number **%1$s** is not in your contacts list. Do you want to add it?</string>
<string name="NewContactAlertButton">Add contact</string>
<!--group create view-->
<string name="SendMessageTo">Add people...</string>