From d0e2266da126786ae60ef5e190e81deec2004920 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sat, 26 Dec 2020 09:18:43 +0400 Subject: [PATCH] Update to 7.3.1 (2199) --- TMessagesProj/build.gradle | 4 +- .../SQLite/SQLitePreparedStatement.java | 4 +- .../telegram/messenger/AndroidUtilities.java | 8 +- .../org/telegram/messenger/BuildVars.java | 2 +- .../org/telegram/messenger/ChatObject.java | 254 +++++--- .../messenger/MessagesController.java | 17 +- .../telegram/messenger/MessagesStorage.java | 48 +- .../messenger/NotificationsController.java | 590 ++++++++++-------- .../telegram/messenger/SecretChatHelper.java | 2 +- .../messenger/SendMessagesHelper.java | 6 +- .../org/telegram/messenger/SharedConfig.java | 10 + .../telegram/messenger/voip/VoIPService.java | 37 +- .../telegram/ui/Adapters/DialogsAdapter.java | 2 +- .../telegram/ui/Cells/ChatMessageCell.java | 2 +- .../org/telegram/ui/Cells/DialogCell.java | 9 +- .../ui/Components/FragmentContextView.java | 38 +- .../ui/Components/RecyclerListView.java | 5 + .../org/telegram/ui/ContactsActivity.java | 4 +- .../org/telegram/ui/GroupCallActivity.java | 3 +- .../java/org/telegram/ui/LaunchActivity.java | 3 + .../java/org/telegram/ui/MediaActivity.java | 6 +- .../java/org/telegram/ui/ProfileActivity.java | 17 +- 22 files changed, 658 insertions(+), 413 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index ee88c9428..4ff19657f 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -290,7 +290,7 @@ android { } } - defaultConfig.versionCode = 2197 + defaultConfig.versionCode = 2199 applicationVariants.all { variant -> variant.outputs.all { output -> @@ -309,7 +309,7 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 29 - versionName "7.3.0" + versionName "7.3.1" vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi'] diff --git a/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java b/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java index a44295a59..5d0171d62 100755 --- a/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java +++ b/TMessagesProj/src/main/java/org/telegram/SQLite/SQLitePreparedStatement.java @@ -31,7 +31,7 @@ public class SQLitePreparedStatement { public SQLitePreparedStatement(SQLiteDatabase db, String sql) throws SQLiteException { sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql); - if (BuildVars.DEBUG_VERSION) { + if (BuildVars.LOGS_ENABLED) { query = sql; startTime = SystemClock.elapsedRealtime(); /*if (hashMap == null) { @@ -101,7 +101,7 @@ public class SQLitePreparedStatement { if (isFinalized) { return; } - if (BuildVars.DEBUG_VERSION) { + if (BuildVars.LOGS_ENABLED) { long diff = SystemClock.elapsedRealtime() - startTime; if (diff > 500) { FileLog.d("sqlite query " + query + " took " + diff + "ms"); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java index 71d8c6935..8b9e3ad23 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java @@ -3530,13 +3530,17 @@ public class AndroidUtilities { if ((flags & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) == 0) { flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; decorView.setSystemUiVisibility(flags); - window.setStatusBarColor(0x0f000000); + if (!SharedConfig.noStatusBar) { + window.setStatusBarColor(0x0f000000); + } } } else { if ((flags & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != 0) { flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; decorView.setSystemUiVisibility(flags); - window.setStatusBarColor(0x33000000); + if (!SharedConfig.noStatusBar) { + window.setStatusBarColor(0x33000000); + } } } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index b648960ed..d766334ef 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -18,7 +18,7 @@ public class BuildVars { public static boolean LOGS_ENABLED = false; public static boolean USE_CLOUD_STRINGS = true; public static boolean CHECK_UPDATES = true; - public static int BUILD_VERSION = 2197; + public static int BUILD_VERSION = 2199; public static String BUILD_VERSION_STRING = "7.3.0"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java index 9a7dfbc53..909c99a5b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java @@ -13,7 +13,6 @@ import android.text.TextUtils; import android.util.SparseArray; import org.telegram.messenger.voip.VoIPService; -import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.TLRPC; import java.util.ArrayList; @@ -54,18 +53,23 @@ public class ChatObject { private String nextLoadOffset; public boolean membersLoadEndReached; public boolean loadingMembers; - public int currentAccount; + public boolean reloadingMembers; + public AccountInstance currentAccount; public int speakingMembersCount; private Runnable typingUpdateRunnable = () -> { typingUpdateRunnableScheduled = false; checkOnlineParticipants(); - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.groupCallTypingsUpdated); + currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.groupCallTypingsUpdated); }; private boolean typingUpdateRunnableScheduled; private int lastLoadGuid; private HashSet loadingGuids = new HashSet<>(); + private ArrayList updatesQueue = new ArrayList<>(); + private long updatesStartWaitTime; - public void setCall(int account, int chatId, TLRPC.TL_phone_groupCall groupCall) { + private Runnable checkQueueRunnable; + + public void setCall(AccountInstance account, int chatId, TLRPC.TL_phone_groupCall groupCall) { this.chatId = chatId; currentAccount = account; call = groupCall.call; @@ -85,19 +89,25 @@ public class ChatObject { public void migrateToChat(TLRPC.Chat chat) { chatId = chat.id; VoIPService voIPService = VoIPService.getSharedInstance(); - if (voIPService != null && voIPService.getAccount() == currentAccount && voIPService.getChat() != null && voIPService.getChat().id == -chatId) { + if (voIPService != null && voIPService.getAccount() == currentAccount.getCurrentAccount() && voIPService.getChat() != null && voIPService.getChat().id == -chatId) { voIPService.migrateToChat(chat); } } public void loadMembers(boolean fromBegin) { if (fromBegin) { + if (reloadingMembers) { + return; + } membersLoadEndReached = false; nextLoadOffset = null; } if (membersLoadEndReached) { return; } + if (fromBegin) { + reloadingMembers = true; + } loadingMembers = true; TLRPC.TL_phone_getGroupParticipants req = new TLRPC.TL_phone_getGroupParticipants(); req.call = new TLRPC.TL_inputGroupCall(); @@ -105,11 +115,14 @@ public class ChatObject { req.call.access_hash = call.access_hash; req.offset = nextLoadOffset != null ? nextLoadOffset : ""; req.limit = 20; - ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + currentAccount.getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + loadingMembers = false; + if (fromBegin) { + reloadingMembers = false; + } if (response != null) { - loadingMembers = false; TLRPC.TL_phone_groupParticipants groupParticipants = (TLRPC.TL_phone_groupParticipants) response; - MessagesController.getInstance(currentAccount).putUsers(groupParticipants.users, false); + currentAccount.getMessagesController().putUsers(groupParticipants.users, false); SparseArray old = null; if (TextUtils.isEmpty(req.offset)) { if (participants.size() != 0) { @@ -151,7 +164,7 @@ public class ChatObject { call.participants_count = participants.size(); } sortParticipants(); - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); + currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); } })); } @@ -181,59 +194,68 @@ public class ChatObject { } } if (participantsToLoad != null) { - int guid = ++lastLoadGuid; - loadingGuids.add(guid); - TLRPC.TL_phone_getGroupParticipants req = new TLRPC.TL_phone_getGroupParticipants(); - req.call = new TLRPC.TL_inputGroupCall(); - req.call.id = call.id; - req.call.access_hash = call.access_hash; - req.ids = participantsToLoad; - req.offset = ""; - req.limit = 100; - ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { - if (!loadingGuids.remove(guid)) { - return; - } - if (response != null) { - TLRPC.TL_phone_groupParticipants groupParticipants = (TLRPC.TL_phone_groupParticipants) response; - MessagesController.getInstance(currentAccount).putUsers(groupParticipants.users, false); - for (int a = 0, N = groupParticipants.participants.size(); a < N; a++) { - TLRPC.TL_groupCallParticipant participant = groupParticipants.participants.get(a); - TLRPC.TL_groupCallParticipant oldParticipant = participants.get(participant.user_id); - if (oldParticipant != null) { - sortedParticipants.remove(oldParticipant); - participantsBySources.remove(oldParticipant.source); - } - participants.put(participant.user_id, participant); - sortedParticipants.add(participant); - participantsBySources.put(participant.source, participant); - if (invitedUsersMap.contains(participant.user_id)) { - Integer id = participant.user_id; - invitedUsersMap.remove(id); - invitedUsers.remove(id); - } - } - if (call.participants_count < participants.size()) { - call.participants_count = participants.size(); - } - sortParticipants(); - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); - } - })); + loadUnknownParticipants(participantsToLoad, true); } if (updated) { sortParticipants(); - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); + currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); } } + private void loadUnknownParticipants(ArrayList participantsToLoad, boolean isIds) { + int guid = ++lastLoadGuid; + loadingGuids.add(guid); + TLRPC.TL_phone_getGroupParticipants req = new TLRPC.TL_phone_getGroupParticipants(); + req.call = new TLRPC.TL_inputGroupCall(); + req.call.id = call.id; + req.call.access_hash = call.access_hash; + if (isIds) { + req.ids = participantsToLoad; + } else { + req.sources = participantsToLoad; + } + req.offset = ""; + req.limit = 100; + currentAccount.getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + if (!loadingGuids.remove(guid)) { + return; + } + if (response != null) { + TLRPC.TL_phone_groupParticipants groupParticipants = (TLRPC.TL_phone_groupParticipants) response; + currentAccount.getMessagesController().putUsers(groupParticipants.users, false); + for (int a = 0, N = groupParticipants.participants.size(); a < N; a++) { + TLRPC.TL_groupCallParticipant participant = groupParticipants.participants.get(a); + TLRPC.TL_groupCallParticipant oldParticipant = participants.get(participant.user_id); + if (oldParticipant != null) { + sortedParticipants.remove(oldParticipant); + participantsBySources.remove(oldParticipant.source); + } + participants.put(participant.user_id, participant); + sortedParticipants.add(participant); + participantsBySources.put(participant.source, participant); + if (invitedUsersMap.contains(participant.user_id)) { + Integer id = participant.user_id; + invitedUsersMap.remove(id); + invitedUsers.remove(id); + } + } + if (call.participants_count < participants.size()) { + call.participants_count = participants.size(); + } + sortParticipants(); + currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); + } + })); + } + public void processVoiceLevelsUpdate(int[] ssrc, float[] levels, boolean[] voice) { boolean updated = false; - int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime(); + int currentTime = currentAccount.getConnectionsManager().getCurrentTime(); + ArrayList participantsToLoad = null; for (int a = 0; a < ssrc.length; a++) { TLRPC.TL_groupCallParticipant participant; if (ssrc[a] == 0) { - participant = participants.get(UserConfig.getInstance(currentAccount).getClientUserId()); + participant = participants.get(currentAccount.getUserConfig().getClientUserId()); } else { participant = participantsBySources.get(ssrc[a]); } @@ -249,34 +271,123 @@ public class ChatObject { } else { participant.amplitude = 0; } + } else { + if (participantsToLoad == null) { + participantsToLoad = new ArrayList<>(); + } + participantsToLoad.add(ssrc[a]); } } + if (participantsToLoad != null) { + loadUnknownParticipants(participantsToLoad, false); + } if (updated) { sortParticipants(); - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); + currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); } } - public void processParticipantsUpdate(AccountInstance accountInstance, TLRPC.TL_updateGroupCallParticipants update) { - boolean versioned = false; - for (int a = 0, N = update.participants.size(); a < N; a++) { - TLRPC.TL_groupCallParticipant participant = update.participants.get(a); - if (participant.versioned) { - versioned = true; - break; + private int isValidUpdate(TLRPC.TL_updateGroupCallParticipants update) { + if (call.version + 1 == update.version || call.version == update.version) { + return 0; + } else if (call.version < update.version) { + return 1; + } else { + return 2; + } + } + + private void processUpdatesQueue() { + Collections.sort(updatesQueue, (updates, updates2) -> AndroidUtilities.compare(updates.version, updates2.version)); + if (updatesQueue != null && !updatesQueue.isEmpty()) { + boolean anyProceed = false; + for (int a = 0; a < updatesQueue.size(); a++) { + TLRPC.TL_updateGroupCallParticipants update = updatesQueue.get(a); + int updateState = isValidUpdate(update); + if (updateState == 0) { + processParticipantsUpdate(update, true); + anyProceed = true; + updatesQueue.remove(a); + a--; + } else if (updateState == 1) { + if (updatesStartWaitTime != 0 && (anyProceed || Math.abs(System.currentTimeMillis() - updatesStartWaitTime) <= 1500)) { + if (BuildVars.LOGS_ENABLED) { + FileLog.d("HOLE IN GROUP CALL UPDATES QUEUE - will wait more time"); + } + if (anyProceed) { + updatesStartWaitTime = System.currentTimeMillis(); + } + } else { + if (BuildVars.LOGS_ENABLED) { + FileLog.d("HOLE IN GROUP CALL UPDATES QUEUE - reload participants"); + } + updatesStartWaitTime = 0; + updatesQueue.clear(); + nextLoadOffset = null; + loadMembers(true); + } + return; + } else { + updatesQueue.remove(a); + a--; + } + } + updatesQueue.clear(); + if (BuildVars.LOGS_ENABLED) { + FileLog.d("GROUP CALL UPDATES QUEUE PROCEED - OK"); } } - if (versioned && call.version + 1 < update.version) { - nextLoadOffset = null; - loadMembers(true); - return; + updatesStartWaitTime = 0; + } + + private void checkQueue() { + checkQueueRunnable = null; + if (updatesStartWaitTime != 0 && (System.currentTimeMillis() - updatesStartWaitTime) >= 1500) { + if (BuildVars.LOGS_ENABLED) { + FileLog.d("QUEUE GROUP CALL UPDATES WAIT TIMEOUT - CHECK QUEUE"); + } + processUpdatesQueue(); } - if (update.version < call.version) { - return; + if (!updatesQueue.isEmpty()) { + AndroidUtilities.runOnUIThread(checkQueueRunnable = this::checkQueue, 1000); + } + } + + public void processParticipantsUpdate(TLRPC.TL_updateGroupCallParticipants update, boolean fromQueue) { + if (!fromQueue) { + boolean versioned = false; + for (int a = 0, N = update.participants.size(); a < N; a++) { + TLRPC.TL_groupCallParticipant participant = update.participants.get(a); + if (participant.versioned) { + versioned = true; + break; + } + } + if (versioned && call.version + 1 < update.version) { + if (reloadingMembers || updatesStartWaitTime == 0 || Math.abs(System.currentTimeMillis() - updatesStartWaitTime) <= 1500) { + if (updatesStartWaitTime == 0) { + updatesStartWaitTime = System.currentTimeMillis(); + } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("add TL_updateGroupCallParticipants to queue " + update.version); + } + updatesQueue.add(update); + if (checkQueueRunnable == null) { + AndroidUtilities.runOnUIThread(checkQueueRunnable = this::checkQueue, 1500); + } + } else { + nextLoadOffset = null; + loadMembers(true); + } + return; + } + if (versioned && update.version < call.version) { + return; + } } boolean updated = false; boolean selfUpdated = false; - int selfId = accountInstance.getUserConfig().getClientUserId(); + int selfId = currentAccount.getUserConfig().getClientUserId(); for (int a = 0, N = update.participants.size(); a < N; a++) { TLRPC.TL_groupCallParticipant participant = update.participants.get(a); TLRPC.TL_groupCallParticipant oldParticipant = participants.get(participant.user_id); @@ -320,7 +431,7 @@ public class ChatObject { participantsBySources.put(participant.source, participant); } if (participant.user_id == selfId && participant.active_date == 0) { - participant.active_date = accountInstance.getConnectionsManager().getCurrentTime(); + participant.active_date = currentAccount.getConnectionsManager().getCurrentTime(); } updated = true; } @@ -330,13 +441,16 @@ public class ChatObject { } if (update.version > call.version) { call.version = update.version; + if (!fromQueue) { + processUpdatesQueue(); + } } if (call.participants_count < participants.size()) { call.participants_count = participants.size(); } if (updated) { sortParticipants(); - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, selfUpdated); + currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, selfUpdated); } } @@ -346,7 +460,7 @@ public class ChatObject { loadMembers(true); } call = update.call; - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); + currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.groupCallUpdated, chatId, call.id, false); } public TLRPC.TL_inputGroupCall getInputGroupCall() { @@ -376,7 +490,7 @@ public class ChatObject { typingUpdateRunnableScheduled = false; } speakingMembersCount = 0; - int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime(); + int currentTime = currentAccount.getConnectionsManager().getCurrentTime(); int minDiff = Integer.MAX_VALUE; for (int a = 0, N = sortedParticipants.size(); a < N; a++) { TLRPC.TL_groupCallParticipant participant = sortedParticipants.get(a); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 1415ead84..0adeeba18 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -2724,7 +2724,7 @@ public class MessagesController extends BaseController implements NotificationCe putUsers(groupCall.users, false); ChatObject.Call call = new ChatObject.Call(); - call.setCall(currentAccount, chatId, groupCall); + call.setCall(getAccountInstance(), chatId, groupCall); groupCalls.put(groupCall.call.id, call); groupCallsByChatId.put(chatId, call); getNotificationCenter().postNotificationName(NotificationCenter.groupCallUpdated, chatId, groupCall.call.id, false); @@ -4716,7 +4716,7 @@ public class MessagesController extends BaseController implements NotificationCe for (int a = 0; a < updatesQueueChannels.size(); a++) { int key = updatesQueueChannels.keyAt(a); long updatesStartWaitTime = updatesStartWaitTimeChannels.valueAt(a); - if (updatesStartWaitTime + 1500 < currentTime) { + if (Math.abs(currentTime - updatesStartWaitTime) >= 1500) { if (BuildVars.LOGS_ENABLED) { FileLog.d("QUEUE CHANNEL " + key + " UPDATES WAIT TIMEOUT - CHECK QUEUE"); } @@ -4726,7 +4726,7 @@ public class MessagesController extends BaseController implements NotificationCe } for (int a = 0; a < 3; a++) { - if (getUpdatesStartTime(a) != 0 && getUpdatesStartTime(a) + 1500 < currentTime) { + if (getUpdatesStartTime(a) != 0 && Math.abs(currentTime - getUpdatesStartTime(a)) >= 1500) { if (BuildVars.LOGS_ENABLED) { FileLog.d(a + " QUEUE UPDATES WAIT TIMEOUT - CHECK QUEUE"); } @@ -5779,6 +5779,7 @@ public class MessagesController extends BaseController implements NotificationCe if (BuildVars.LOGS_ENABLED) { FileLog.d("processLoadedMessages size " + messagesRes.messages.size() + " in chat " + dialogId + " count " + count + " max_id " + max_id + " cache " + isCache + " guid " + classGuid + " load_type " + load_type + " last_message_id " + last_message_id + " isChannel " + isChannel + " index " + loadIndex + " firstUnread " + first_unread + " unread_count " + unread_count + " last_date " + last_date + " queryFromServer " + queryFromServer); } + long startProcessTime = SystemClock.elapsedRealtime(); boolean createDialog = false; if (messagesRes instanceof TLRPC.TL_messages_channelMessages) { int channelId = -(int) dialogId; @@ -5897,10 +5898,13 @@ public class MessagesController extends BaseController implements NotificationCe final ArrayList messagesToReload = new ArrayList<>(); final HashMap> webpagesToReload = new HashMap<>(); TLRPC.InputChannel inputChannel = null; + long fileProcessTime = 0; for (int a = 0; a < size; a++) { TLRPC.Message message = messagesRes.messages.get(a); message.dialog_id = dialogId; + long checkFileTime = SystemClock.elapsedRealtime(); MessageObject messageObject = new MessageObject(currentAccount, message, usersDict, chatsDict, true, true); + fileProcessTime += (SystemClock.elapsedRealtime() - checkFileTime); messageObject.scheduled = mode == 1; objects.add(messageObject); if (isCache) { @@ -5925,6 +5929,9 @@ public class MessagesController extends BaseController implements NotificationCe } } } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("process time = " + (SystemClock.elapsedRealtime() - startProcessTime) + " file time = " + fileProcessTime + " for dialog = " + dialogId); + } AndroidUtilities.runOnUIThread(() -> { putUsers(messagesRes.users, isCache); putChats(messagesRes.chats, isCache); @@ -7230,7 +7237,7 @@ public class MessagesController extends BaseController implements NotificationCe } } } else { - if (newMsg == null && oldMsg.isSent() || newMsg != null && newMsg.messageOwner.date > oldMsg.messageOwner.date) { + if (newMsg == null && oldMsg.getId() > 0 || newMsg != null && newMsg.messageOwner.date > oldMsg.messageOwner.date) { dialogs_dict.put(key, value); dialogMessage.put(key, newMsg); if (oldMsg.messageOwner.peer_id.channel_id == 0) { @@ -12435,7 +12442,7 @@ public class MessagesController extends BaseController implements NotificationCe TLRPC.TL_updateGroupCallParticipants update = (TLRPC.TL_updateGroupCallParticipants) baseUpdate; ChatObject.Call call = groupCalls.get(update.call.id); if (call != null) { - call.processParticipantsUpdate(getAccountInstance(), update); + call.processParticipantsUpdate(update, false); } if (VoIPService.getSharedInstance() != null) { VoIPService.getSharedInstance().onGroupCallParticipantsUpdate(update); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java index 51b76084e..7bfa1985b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java @@ -9,6 +9,7 @@ package org.telegram.messenger; import android.content.SharedPreferences; +import android.os.SystemClock; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; @@ -6016,6 +6017,7 @@ public class MessagesStorage extends BaseController { boolean isEnd = false; int num = dialogId == 777000 ? 10 : 1; int messagesCount = 0; + long startLoadTime = SystemClock.elapsedRealtime(); try { ArrayList usersToLoad = new ArrayList<>(); ArrayList chatsToLoad = new ArrayList<>(); @@ -6698,6 +6700,9 @@ public class MessagesStorage extends BaseController { res.users.clear(); FileLog.e(e); } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("messages load time = " + (SystemClock.elapsedRealtime() - startLoadTime) + " for dialog = " + dialogId); + } int countQueryFinal = count_query; int maxIdOverrideFinal = max_id_override; int minUnreadIdFinal = min_unread_id; @@ -8514,7 +8519,7 @@ public class MessagesStorage extends BaseController { }); } - private long[] updateMessageStateAndIdInternal(long random_id, Integer _oldId, int newId, int date, int channelId, int scheduled) { + private long[] updateMessageStateAndIdInternal(long random_id, Long _oldId, int newId, int date, int channelId, int scheduled) { SQLiteCursor cursor = null; long oldMessageId; long newMessageId = newId; @@ -8523,7 +8528,7 @@ public class MessagesStorage extends BaseController { try { cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid FROM randoms WHERE random_id = %d LIMIT 1", random_id)); if (cursor.next()) { - _oldId = cursor.intValue(0); + _oldId = cursor.longValue(0); } } catch (Exception e) { FileLog.e(e); @@ -8535,12 +8540,49 @@ public class MessagesStorage extends BaseController { if (_oldId == null) { return null; } + if (channelId == 0) { + channelId = (int) (_oldId >> 32); + } } oldMessageId = _oldId; if (channelId != 0) { oldMessageId |= ((long) channelId) << 32; newMessageId |= ((long) channelId) << 32; } + if (_oldId < 0 && scheduled == 1) { + SQLitePreparedStatement state = null; + try { + state = database.executeFast("UPDATE randoms SET mid = ? WHERE random_id = ? and mid = ?"); + state.bindLong(1, newMessageId); + state.bindLong(2, random_id); + state.bindLong(3, oldMessageId); + state.step(); + } catch (Exception e) { + FileLog.e(e); + } finally { + if (state != null) { + state.dispose(); + } + } + } else if (_oldId > 0) { + TLRPC.TL_updateDeleteScheduledMessages update = new TLRPC.TL_updateDeleteScheduledMessages(); + update.messages.add((int) oldMessageId); + if (channelId != 0) { + update.peer = new TLRPC.TL_peerChannel(); + update.peer.channel_id = channelId; + } else { + update.peer = new TLRPC.TL_peerUser(); + } + TLRPC.TL_updates updates = new TLRPC.TL_updates(); + updates.updates.add(update); + Utilities.stageQueue.postRunnable(() -> getMessagesController().processUpdates(updates, false)); + try { + database.executeFast(String.format(Locale.US, "DELETE FROM randoms WHERE random_id = %d AND mid = %d", random_id, _oldId)).stepThis().dispose(); + } catch (Exception e) { + FileLog.e(e); + } + return null; + } long did = 0; if (scheduled == -1 || scheduled == 0) { @@ -8671,7 +8713,7 @@ public class MessagesStorage extends BaseController { } } - public long[] updateMessageStateAndId(final long random_id, final Integer _oldId, final int newId, final int date, boolean useQueue, final int channelId, int scheduled) { + public long[] updateMessageStateAndId(final long random_id, final Long _oldId, final int newId, final int date, boolean useQueue, final int channelId, int scheduled) { if (useQueue) { storageQueue.postRunnable(() -> updateMessageStateAndIdInternal(random_id, _oldId, newId, date, channelId, scheduled)); } else { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java index b03a7b039..713cf02a8 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java @@ -2559,7 +2559,7 @@ public class NotificationsController extends BaseController { return; } notificationsQueue.postRunnable(() -> { - if (Math.abs(System.currentTimeMillis() - lastSoundPlay) <= 500) { + if (Math.abs(SystemClock.elapsedRealtime() - lastSoundPlay) <= 500) { return; } try { @@ -2804,20 +2804,54 @@ public class NotificationsController extends BaseController { protected void ensureGroupsCreated() { SharedPreferences preferences = getAccountInstance().getNotificationsSettings(); if (groupsCreated == null) { - groupsCreated = preferences.getBoolean("groupsCreated", false); + groupsCreated = preferences.getBoolean("groupsCreated4", false); } if (!groupsCreated) { try { String keyStart = currentAccount + "channel"; List list = systemNotificationManager.getNotificationChannels(); int count = list.size(); + SharedPreferences.Editor editor = null; for (int a = 0; a < count; a++) { NotificationChannel channel = list.get(a); String id = channel.getId(); if (id.startsWith(keyStart)) { + int importance = channel.getImportance(); + if (importance != NotificationManager.IMPORTANCE_HIGH && importance != NotificationManager.IMPORTANCE_MAX) { //TODO remove after some time, 7.3.0 bug fix + if (id.contains("_ia_")) { + //do nothing + } else if (id.contains("_channels_")) { + if (editor == null) { + editor = getAccountInstance().getNotificationsSettings().edit(); + } + editor.remove("priority_channel").remove("vibrate_channel").remove("ChannelSoundPath").remove("ChannelSound"); + } else if (id.contains("_groups_")) { + if (editor == null) { + editor = getAccountInstance().getNotificationsSettings().edit(); + } + editor.remove("priority_group").remove("vibrate_group").remove("GroupSoundPath").remove("GroupSound"); + } else if (id.contains("_private_")) { + if (editor == null) { + editor = getAccountInstance().getNotificationsSettings().edit(); + } + editor.remove("priority_messages"); + editor.remove("priority_group").remove("vibrate_messages").remove("GlobalSoundPath").remove("GlobalSound"); + } else { + long dialogId = Utilities.parseLong(id.substring(9, id.indexOf('_', 9))); + if (dialogId != 0) { + if (editor == null) { + editor = getAccountInstance().getNotificationsSettings().edit(); + } + editor.remove("priority_" + dialogId).remove("vibrate_" + dialogId).remove("sound_path_" + dialogId).remove("sound_" + dialogId); + } + } + } systemNotificationManager.deleteNotificationChannel(id); } } + if (editor != null) { + editor.commit(); + } } catch (Exception e) { FileLog.e(e); } @@ -2831,13 +2865,15 @@ public class NotificationsController extends BaseController { } else { userName = ""; } + systemNotificationManager.createNotificationChannelGroups(Arrays.asList( new NotificationChannelGroup("channels" + currentAccount, LocaleController.getString("NotificationsChannels", R.string.NotificationsChannels) + userName), new NotificationChannelGroup("groups" + currentAccount, LocaleController.getString("NotificationsGroups", R.string.NotificationsGroups) + userName), new NotificationChannelGroup("private" + currentAccount, LocaleController.getString("NotificationsPrivateChats", R.string.NotificationsPrivateChats) + userName), new NotificationChannelGroup("other" + currentAccount, LocaleController.getString("NotificationsOther", R.string.NotificationsOther) + userName) )); - preferences.edit().putBoolean("groupsCreated", true).commit(); + + preferences.edit().putBoolean("groupsCreated4", true).commit(); groupsCreated = true; } } @@ -2888,184 +2924,192 @@ public class NotificationsController extends BaseController { StringBuilder newSettings = new StringBuilder(); String newSettingsHash = null; - if (!isSilent && channelId != null) { + if (channelId != null) { NotificationChannel existingChannel = systemNotificationManager.getNotificationChannel(channelId); if (existingChannel != null) { - int channelImportance = existingChannel.getImportance(); - Uri channelSound = existingChannel.getSound(); - long[] channelVibrationPattern = existingChannel.getVibrationPattern(); - int channelLedColor = existingChannel.getLightColor(); - if (channelVibrationPattern != null) { - for (int a = 0; a < channelVibrationPattern.length; a++) { - newSettings.append(channelVibrationPattern[a]); + if (!isSilent) { + int channelImportance = existingChannel.getImportance(); + Uri channelSound = existingChannel.getSound(); + long[] channelVibrationPattern = existingChannel.getVibrationPattern(); + boolean vibrate = existingChannel.shouldVibrate(); + if (!vibrate && channelVibrationPattern == null) { + channelVibrationPattern = new long[]{0, 0}; } - } - newSettings.append(channelLedColor); - if (channelSound != null) { - newSettings.append(channelSound.toString()); - } - newSettings.append(channelImportance); - if (secretChat) { - newSettings.append("secret"); - } - newSettingsHash = Utilities.MD5(newSettings.toString()); - newSettings.setLength(0); - if (!settings.equals(newSettingsHash)) { - SharedPreferences.Editor editor = null; - if (channelImportance == NotificationManager.IMPORTANCE_NONE) { - editor = preferences.edit(); - if (isDefault) { - if (!isInApp) { - editor.putInt(getGlobalNotificationsKey(type), Integer.MAX_VALUE); - updateServerNotificationsSettings(type); - } - } else { - editor.putInt("notify2_" + dialogId, 2); - updateServerNotificationsSettings(dialogId, true); + int channelLedColor = existingChannel.getLightColor(); + if (channelVibrationPattern != null) { + for (int a = 0; a < channelVibrationPattern.length; a++) { + newSettings.append(channelVibrationPattern[a]); } - edited = true; - } else if (channelImportance != importance) { - if (!isInApp) { + } + newSettings.append(channelLedColor); + if (channelSound != null) { + newSettings.append(channelSound.toString()); + } + newSettings.append(channelImportance); + if (!isDefault && secretChat) { + newSettings.append("secret"); + } + newSettingsHash = Utilities.MD5(newSettings.toString()); + newSettings.setLength(0); + if (!newSettingsHash.equals(settings)) { + SharedPreferences.Editor editor = null; + if (channelImportance == NotificationManager.IMPORTANCE_NONE) { editor = preferences.edit(); - int priority; - if (channelImportance == NotificationManager.IMPORTANCE_HIGH || channelImportance == NotificationManager.IMPORTANCE_MAX) { - priority = 1; - } else if (channelImportance == NotificationManager.IMPORTANCE_MIN) { - priority = 4; - } else if (channelImportance == NotificationManager.IMPORTANCE_LOW) { - priority = 5; - } else { - priority = 0; - } if (isDefault) { - editor.putInt(getGlobalNotificationsKey(type), 0).commit(); - if (type == TYPE_CHANNEL) { - editor.putInt("priority_channel", priority); - } else if (type == TYPE_GROUP) { - editor.putInt("priority_group", priority); - } else { - editor.putInt("priority_messages", priority); + if (!isInApp) { + editor.putInt(getGlobalNotificationsKey(type), Integer.MAX_VALUE); + updateServerNotificationsSettings(type); } } else { - editor.putInt("notify2_" + dialogId, 0); - editor.remove("notifyuntil_" + dialogId); - editor.putInt("priority_" + dialogId, priority); + editor.putInt("notify2_" + dialogId, 2); + updateServerNotificationsSettings(dialogId, true); } - } - edited = true; - } - if (channelSound == null && sound != null || channelSound != null && (sound == null || !TextUtils.equals(channelSound.toString(), sound.toString()))) { - if (!isInApp) { - if (editor == null) { + edited = true; + } else if (channelImportance != importance) { + if (!isInApp) { editor = preferences.edit(); - } - String newSound; - if (channelSound == null) { - newSound = "NoSound"; + int priority; + if (channelImportance == NotificationManager.IMPORTANCE_HIGH || channelImportance == NotificationManager.IMPORTANCE_MAX) { + priority = 1; + } else if (channelImportance == NotificationManager.IMPORTANCE_MIN) { + priority = 4; + } else if (channelImportance == NotificationManager.IMPORTANCE_LOW) { + priority = 5; + } else { + priority = 0; + } if (isDefault) { + editor.putInt(getGlobalNotificationsKey(type), 0).commit(); if (type == TYPE_CHANNEL) { - editor.putString("ChannelSound", "NoSound"); + editor.putInt("priority_channel", priority); } else if (type == TYPE_GROUP) { - editor.putString("GroupSound", "NoSound"); + editor.putInt("priority_group", priority); } else { - editor.putString("GlobalSound", "NoSound"); + editor.putInt("priority_messages", priority); } } else { - editor.putString("sound_" + dialogId, "NoSound"); + editor.putInt("notify2_" + dialogId, 0); + editor.remove("notifyuntil_" + dialogId); + editor.putInt("priority_" + dialogId, priority); } - } else { - newSound = channelSound.toString(); - Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, channelSound); - String ringtoneName = null; - if (rng != null) { - if (channelSound.equals(Settings.System.DEFAULT_RINGTONE_URI)) { - ringtoneName = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone); - } else { - ringtoneName = rng.getTitle(ApplicationLoader.applicationContext); - } - rng.stop(); + } + edited = true; + } + if (channelSound == null && sound != null || channelSound != null && (sound == null || !TextUtils.equals(channelSound.toString(), sound.toString()))) { + if (!isInApp) { + if (editor == null) { + editor = preferences.edit(); } - if (ringtoneName != null) { + String newSound; + if (channelSound == null) { + newSound = "NoSound"; if (isDefault) { if (type == TYPE_CHANNEL) { - editor.putString("ChannelSound", ringtoneName); + editor.putString("ChannelSound", "NoSound"); } else if (type == TYPE_GROUP) { - editor.putString("GroupSound", ringtoneName); + editor.putString("GroupSound", "NoSound"); } else { - editor.putString("GlobalSound", ringtoneName); + editor.putString("GlobalSound", "NoSound"); } } else { - editor.putString("sound_" + dialogId, ringtoneName); + editor.putString("sound_" + dialogId, "NoSound"); + } + } else { + newSound = channelSound.toString(); + Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, channelSound); + String ringtoneName = null; + if (rng != null) { + if (channelSound.equals(Settings.System.DEFAULT_RINGTONE_URI)) { + ringtoneName = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone); + } else { + ringtoneName = rng.getTitle(ApplicationLoader.applicationContext); + } + rng.stop(); + } + if (ringtoneName != null) { + if (isDefault) { + if (type == TYPE_CHANNEL) { + editor.putString("ChannelSound", ringtoneName); + } else if (type == TYPE_GROUP) { + editor.putString("GroupSound", ringtoneName); + } else { + editor.putString("GlobalSound", ringtoneName); + } + } else { + editor.putString("sound_" + dialogId, ringtoneName); + } } } - } - if (isDefault) { - if (type == TYPE_CHANNEL) { - editor.putString("ChannelSoundPath", newSound); - } else if (type == TYPE_GROUP) { - editor.putString("GroupSoundPath", newSound); + if (isDefault) { + if (type == TYPE_CHANNEL) { + editor.putString("ChannelSoundPath", newSound); + } else if (type == TYPE_GROUP) { + editor.putString("GroupSoundPath", newSound); + } else { + editor.putString("GlobalSoundPath", newSound); + } } else { - editor.putString("GlobalSoundPath", newSound); + editor.putString("sound_path_" + dialogId, newSound); } - } else { - editor.putString("sound_path_" + dialogId, newSound); } + sound = channelSound; + edited = true; } - sound = channelSound; - edited = true; - } - boolean vibrate = existingChannel.shouldVibrate(); - boolean hasVibration = !isEmptyVibration(vibrationPattern); - if (hasVibration != vibrate) { - if (!isInApp) { - if (editor == null) { - editor = preferences.edit(); - } - if (isDefault) { - if (type == TYPE_CHANNEL) { - editor.putInt("vibrate_channel", vibrate ? 0 : 2); - } else if (type == TYPE_GROUP) { - editor.putInt("vibrate_group", vibrate ? 0 : 2); + boolean hasVibration = !isEmptyVibration(vibrationPattern); + if (hasVibration != vibrate) { + if (!isInApp) { + if (editor == null) { + editor = preferences.edit(); + } + if (isDefault) { + if (type == TYPE_CHANNEL) { + editor.putInt("vibrate_channel", vibrate ? 0 : 2); + } else if (type == TYPE_GROUP) { + editor.putInt("vibrate_group", vibrate ? 0 : 2); + } else { + editor.putInt("vibrate_messages", vibrate ? 0 : 2); + } } else { - editor.putInt("vibrate_messages", vibrate ? 0 : 2); + editor.putInt("vibrate_" + dialogId, vibrate ? 0 : 2); } - } else { - editor.putInt("vibrate_" + dialogId, vibrate ? 0 : 2); } + vibrationPattern = channelVibrationPattern; + edited = true; } - vibrationPattern = new long[]{}; - edited = true; - } - if (channelLedColor != ledColor) { - if (!isInApp) { - if (editor == null) { - editor = preferences.edit(); - } - if (isDefault) { - if (type == TYPE_CHANNEL) { - editor.putInt("ChannelLed", channelLedColor); - } else if (type == TYPE_GROUP) { - editor.putInt("GroupLed", channelLedColor); + if (channelLedColor != ledColor) { + if (!isInApp) { + if (editor == null) { + editor = preferences.edit(); + } + if (isDefault) { + if (type == TYPE_CHANNEL) { + editor.putInt("ChannelLed", channelLedColor); + } else if (type == TYPE_GROUP) { + editor.putInt("GroupLed", channelLedColor); + } else { + editor.putInt("MessagesLed", channelLedColor); + } } else { - editor.putInt("MessagesLed", channelLedColor); + editor.putInt("color_" + dialogId, channelLedColor); } - } else { - editor.putInt("color_" + dialogId, channelLedColor); } + ledColor = channelLedColor; + edited = true; + } + if (editor != null) { + editor.commit(); } - ledColor = channelLedColor; - edited = true; - } - if (editor != null) { - editor.commit(); } } + } else { + channelId = null; + settings = null; } } if (edited && newSettingsHash != null) { preferences.edit().putString(key, channelId).putString(key + "_s", newSettingsHash).commit(); - } else if (!isInApp || !isDefault) { + } else if (newSettingsHash == null || !isInApp || !isDefault) { for (int a = 0; a < vibrationPattern.length; a++) { newSettings.append(vibrationPattern[a]); } @@ -3074,12 +3118,12 @@ public class NotificationsController extends BaseController { newSettings.append(sound.toString()); } newSettings.append(importance); - if (secretChat) { + if (!isDefault && secretChat) { newSettings.append("secret"); } newSettingsHash = Utilities.MD5(newSettings.toString()); - if (channelId != null && !settings.equals(newSettingsHash)) { + if (!isSilent && channelId != null && !settings.equals(newSettingsHash)) { systemNotificationManager.deleteNotificationChannel(channelId); channelId = null; } @@ -3174,7 +3218,113 @@ public class NotificationsController extends BaseController { } else { value = notifyOverride != 2; } - if (!notifyAboutLast || !value) { + + String name; + String chatName; + boolean replace = true; + if (((chat_id != 0 && chat == null) || user == null) && lastMessageObject.isFcmMessage()) { + chatName = lastMessageObject.localName; + } else if (chat != null) { + chatName = chat.title; + } else { + chatName = UserObject.getUserName(user); + } + boolean passcode = AndroidUtilities.needShowPasscode() || SharedConfig.isWaitingForPasscodeEnter; + if ((int) dialog_id == 0 || pushDialogs.size() > 1 || passcode) { + if (passcode) { + if (chat_id != 0) { + name = LocaleController.getString("NotificationHiddenChatName", R.string.NotificationHiddenChatName); + } else { + name = LocaleController.getString("NotificationHiddenName", R.string.NotificationHiddenName); + } + } else { + name = LocaleController.getString("AppName", R.string.AppName); + } + replace = false; + } else { + name = chatName; + } + + String detailText; + if (UserConfig.getActivatedAccountsCount() > 1) { + if (pushDialogs.size() == 1) { + detailText = UserObject.getFirstName(getUserConfig().getCurrentUser()); + } else { + detailText = UserObject.getFirstName(getUserConfig().getCurrentUser()) + "・"; + } + } else { + detailText = ""; + } + if (pushDialogs.size() != 1 || Build.VERSION.SDK_INT < 23) { + if (pushDialogs.size() == 1) { + detailText += LocaleController.formatPluralString("NewMessages", total_unread_count); + } else { + detailText += LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size())); + } + } + + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext); + + int silent = 2; + String lastMessage = null; + boolean hasNewMessages = false; + if (pushMessages.size() == 1) { + MessageObject messageObject = pushMessages.get(0); + boolean[] text = new boolean[1]; + String message = lastMessage = getStringForMessage(messageObject, false, text, null); + silent = messageObject.messageOwner.silent ? 1 : 0; + if (message == null) { + return; + } + if (replace) { + if (chat != null) { + message = message.replace(" @ " + name, ""); + } else { + if (text[0]) { + message = message.replace(name + ": ", ""); + } else { + message = message.replace(name + " ", ""); + } + } + } + mBuilder.setContentText(message); + mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); + } else { + mBuilder.setContentText(detailText); + NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); + inboxStyle.setBigContentTitle(name); + int count = Math.min(10, pushMessages.size()); + boolean[] text = new boolean[1]; + for (int i = 0; i < count; i++) { + MessageObject messageObject = pushMessages.get(i); + String message = getStringForMessage(messageObject, false, text, null); + if (message == null || messageObject.messageOwner.date <= dismissDate) { + continue; + } + if (silent == 2) { + lastMessage = message; + silent = messageObject.messageOwner.silent ? 1 : 0; + } + if (pushDialogs.size() == 1) { + if (replace) { + if (chat != null) { + message = message.replace(" @ " + name, ""); + } else { + if (text[0]) { + message = message.replace(name + ": ", ""); + } else { + message = message.replace(name + " ", ""); + } + } + } + } + inboxStyle.addLine(message); + } + inboxStyle.setSummaryText(detailText); + mBuilder.setStyle(inboxStyle); + } + + if (!notifyAboutLast || !value || MediaController.getInstance().isRecordingAudio() || silent == 1) { notifyDisabled = true; } @@ -3191,16 +3341,16 @@ public class NotificationsController extends BaseController { if (notifyMaxCount != 0) { Point dialogInfo = smartNotificationsDialogs.get(dialog_id); if (dialogInfo == null) { - dialogInfo = new Point(1, (int) (System.currentTimeMillis() / 1000)); + dialogInfo = new Point(1, (int) (SystemClock.elapsedRealtime() / 1000)); smartNotificationsDialogs.put(dialog_id, dialogInfo); } else { int lastTime = dialogInfo.y; - if (lastTime + notifyDelay < System.currentTimeMillis() / 1000) { - dialogInfo.set(1, (int) (System.currentTimeMillis() / 1000)); + if (lastTime + notifyDelay < SystemClock.elapsedRealtime() / 1000) { + dialogInfo.set(1, (int) (SystemClock.elapsedRealtime() / 1000)); } else { int count = dialogInfo.x; if (count < notifyMaxCount) { - dialogInfo.set(count + 1, (int) (System.currentTimeMillis() / 1000)); + dialogInfo.set(count + 1, (int) (SystemClock.elapsedRealtime() / 1000)); } else { notifyDisabled = true; } @@ -3342,52 +3492,7 @@ public class NotificationsController extends BaseController { intent.putExtra("currentAccount", currentAccount); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); - String name; - String chatName; - boolean replace = true; - if (((chat_id != 0 && chat == null) || user == null) && lastMessageObject.isFcmMessage()) { - chatName = lastMessageObject.localName; - } else if (chat != null) { - chatName = chat.title; - } else { - chatName = UserObject.getUserName(user); - } - boolean passcode = AndroidUtilities.needShowPasscode() || SharedConfig.isWaitingForPasscodeEnter; - if ((int) dialog_id == 0 || pushDialogs.size() > 1 || passcode) { - if (passcode) { - if (chat_id != 0) { - name = LocaleController.getString("NotificationHiddenChatName", R.string.NotificationHiddenChatName); - } else { - name = LocaleController.getString("NotificationHiddenName", R.string.NotificationHiddenName); - } - } else { - name = LocaleController.getString("AppName", R.string.AppName); - } - replace = false; - } else { - name = chatName; - } - - String detailText; - if (UserConfig.getActivatedAccountsCount() > 1) { - if (pushDialogs.size() == 1) { - detailText = UserObject.getFirstName(getUserConfig().getCurrentUser()); - } else { - detailText = UserObject.getFirstName(getUserConfig().getCurrentUser()) + "・"; - } - } else { - detailText = ""; - } - if (pushDialogs.size() != 1 || Build.VERSION.SDK_INT < 23) { - if (pushDialogs.size() == 1) { - detailText += LocaleController.formatPluralString("NewMessages", total_unread_count); - } else { - detailText += LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size())); - } - } - - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext) - .setContentTitle(name) + mBuilder.setContentTitle(name) .setSmallIcon(R.drawable.notification) .setAutoCancel(true) .setNumber(total_unread_count) @@ -3406,65 +3511,6 @@ public class NotificationsController extends BaseController { mBuilder.addPerson("tel:+" + user.phone); } - int silent = 2; - String lastMessage = null; - boolean hasNewMessages = false; - if (pushMessages.size() == 1) { - MessageObject messageObject = pushMessages.get(0); - boolean[] text = new boolean[1]; - String message = lastMessage = getStringForMessage(messageObject, false, text, null); - silent = messageObject.messageOwner.silent ? 1 : 0; - if (message == null) { - return; - } - if (replace) { - if (chat != null) { - message = message.replace(" @ " + name, ""); - } else { - if (text[0]) { - message = message.replace(name + ": ", ""); - } else { - message = message.replace(name + " ", ""); - } - } - } - mBuilder.setContentText(message); - mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); - } else { - mBuilder.setContentText(detailText); - NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); - inboxStyle.setBigContentTitle(name); - int count = Math.min(10, pushMessages.size()); - boolean[] text = new boolean[1]; - for (int i = 0; i < count; i++) { - MessageObject messageObject = pushMessages.get(i); - String message = getStringForMessage(messageObject, false, text, null); - if (message == null || messageObject.messageOwner.date <= dismissDate) { - continue; - } - if (silent == 2) { - lastMessage = message; - silent = messageObject.messageOwner.silent ? 1 : 0; - } - if (pushDialogs.size() == 1) { - if (replace) { - if (chat != null) { - message = message.replace(" @ " + name, ""); - } else { - if (text[0]) { - message = message.replace(name + ": ", ""); - } else { - message = message.replace(name + " ", ""); - } - } - } - } - inboxStyle.addLine(message); - } - inboxStyle.setSummaryText(detailText); - mBuilder.setStyle(inboxStyle); - } - Intent dismissIntent = new Intent(ApplicationLoader.applicationContext, NotificationDismissReceiver.class); dismissIntent.putExtra("messageDate", lastMessageObject.messageOwner.date); dismissIntent.putExtra("currentAccount", currentAccount); @@ -3529,29 +3575,27 @@ public class NotificationsController extends BaseController { } mBuilder.setTicker(lastMessage); } - if (!MediaController.getInstance().isRecordingAudio()) { - if (soundPath != null && !soundPath.equals("NoSound")) { - if (Build.VERSION.SDK_INT >= 26) { - if (soundPath.equals(defaultPath)) { - sound = Settings.System.DEFAULT_NOTIFICATION_URI; - } else { - sound = Uri.parse(soundPath); - } + if (soundPath != null && !soundPath.equals("NoSound")) { + if (Build.VERSION.SDK_INT >= 26) { + if (soundPath.equals(defaultPath)) { + sound = Settings.System.DEFAULT_NOTIFICATION_URI; } else { - if (soundPath.equals(defaultPath)) { - mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); - } else { - if (Build.VERSION.SDK_INT >= 24 && soundPath.startsWith("file://") && !AndroidUtilities.isInternalUri(Uri.parse(soundPath))) { - try { - Uri uri = FileProvider.getUriForFile(ApplicationLoader.applicationContext, BuildConfig.APPLICATION_ID + ".provider", new File(soundPath.replace("file://", ""))); - ApplicationLoader.applicationContext.grantUriPermission("com.android.systemui", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); - mBuilder.setSound(uri, AudioManager.STREAM_NOTIFICATION); - } catch (Exception e) { - mBuilder.setSound(Uri.parse(soundPath), AudioManager.STREAM_NOTIFICATION); - } - } else { + sound = Uri.parse(soundPath); + } + } else { + if (soundPath.equals(defaultPath)) { + mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); + } else { + if (Build.VERSION.SDK_INT >= 24 && soundPath.startsWith("file://") && !AndroidUtilities.isInternalUri(Uri.parse(soundPath))) { + try { + Uri uri = FileProvider.getUriForFile(ApplicationLoader.applicationContext, BuildConfig.APPLICATION_ID + ".provider", new File(soundPath.replace("file://", ""))); + ApplicationLoader.applicationContext.grantUriPermission("com.android.systemui", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); + mBuilder.setSound(uri, AudioManager.STREAM_NOTIFICATION); + } catch (Exception e) { mBuilder.setSound(Uri.parse(soundPath), AudioManager.STREAM_NOTIFICATION); } + } else { + mBuilder.setSound(Uri.parse(soundPath), AudioManager.STREAM_NOTIFICATION); } } } @@ -3559,7 +3603,7 @@ public class NotificationsController extends BaseController { if (ledColor != 0) { mBuilder.setLights(ledColor, 1000, 1000); } - if (vibrate == 2 || MediaController.getInstance().isRecordingAudio()) { + if (vibrate == 2) { mBuilder.setVibrate(vibrationPattern = new long[]{0, 0}); } else if (vibrate == 1) { mBuilder.setVibrate(vibrationPattern = new long[]{0, 100, 0, 100}); @@ -3609,7 +3653,7 @@ public class NotificationsController extends BaseController { if (Build.VERSION.SDK_INT >= 26) { mBuilder.setChannelId(validateChannelId(dialog_id, chatName, vibrationPattern, ledColor, sound, configImportance, isDefault, isInApp, notifyDisabled, chatType)); } - showExtraNotifications(mBuilder, notifyAboutLast, detailText); + showExtraNotifications(mBuilder, detailText); scheduleNotificationRepeat(); } catch (Exception e) { FileLog.e(e); @@ -3626,7 +3670,7 @@ public class NotificationsController extends BaseController { } @SuppressLint("InlinedApi") - private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast, String summary) { + private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, String summary) { Notification mainNotification = notificationBuilder.build(); if (Build.VERSION.SDK_INT < 18) { notificationManager.notify(notificationId, mainNotification); @@ -4337,10 +4381,10 @@ public class NotificationsController extends BaseController { } notificationsQueue.postRunnable(() -> { try { - if (Math.abs(System.currentTimeMillis() - lastSoundOutPlay) <= 100) { + if (Math.abs(SystemClock.elapsedRealtime() - lastSoundOutPlay) <= 100) { return; } - lastSoundOutPlay = System.currentTimeMillis(); + lastSoundOutPlay = SystemClock.elapsedRealtime(); if (soundPool == null) { soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0); soundPool.setOnLoadCompleteListener((soundPool, sampleId, status) -> { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SecretChatHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/SecretChatHelper.java index cf279aebe..4266e8660 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/SecretChatHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/SecretChatHelper.java @@ -763,7 +763,7 @@ public class SecretChatHelper extends BaseController { if (isSecretInvisibleMessage(newMsgObj)) { res.date = 0; } - getMessagesStorage().updateMessageStateAndId(newMsgObj.random_id, newMsgObj.id, newMsgObj.id, res.date, false, 0, 0); + getMessagesStorage().updateMessageStateAndId(newMsgObj.random_id, (long) newMsgObj.id, newMsgObj.id, res.date, false, 0, 0); AndroidUtilities.runOnUIThread(() -> { newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT; getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, newMsgObj.id, newMsgObj.id, newMsgObj, newMsgObj.dialog_id, 0L, existFlags, false); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java index 4063f27f7..a28d3e87d 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java @@ -1648,7 +1648,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe }); } else { getMessagesStorage().getStorageQueue().postRunnable(() -> { - getMessagesStorage().updateMessageStateAndId(newMsgObj1.random_id, oldId, newMsgObj1.id, 0, false, peer_id.channel_id, scheduleDate != 0 ? 1 : 0); + getMessagesStorage().updateMessageStateAndId(newMsgObj1.random_id, (long) oldId, newMsgObj1.id, 0, false, peer_id.channel_id, scheduleDate != 0 ? 1 : 0); getMessagesStorage().putMessages(sentMessages, true, false, false, 0, scheduleDate != 0); AndroidUtilities.runOnUIThread(() -> { newMsgObj1.send_state = MessageObject.MESSAGE_SEND_STATE_SENT; @@ -4616,7 +4616,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT; getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj, newMsgObj.dialog_id, grouped_id, existFlags, scheduled); getMessagesStorage().getStorageQueue().postRunnable(() -> { - getMessagesStorage().updateMessageStateAndId(newMsgObj.random_id, oldId, newMsgObj.id, 0, false, newMsgObj.peer_id.channel_id, scheduled ? 1 : 0); + getMessagesStorage().updateMessageStateAndId(newMsgObj.random_id, (long) oldId, newMsgObj.id, 0, false, newMsgObj.peer_id.channel_id, scheduled ? 1 : 0); getMessagesStorage().putMessages(sentMessages, true, false, false, 0, scheduled); AndroidUtilities.runOnUIThread(() -> { getMediaDataController().increasePeerRaiting(newMsgObj.dialog_id); @@ -4918,7 +4918,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe } else { getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj, newMsgObj.dialog_id, 0L, existFlags, scheduled); getMessagesStorage().getStorageQueue().postRunnable(() -> { - getMessagesStorage().updateMessageStateAndId(newMsgObj.random_id, oldId, newMsgObj.id, 0, false, newMsgObj.peer_id.channel_id, scheduled ? 1 : 0); + getMessagesStorage().updateMessageStateAndId(newMsgObj.random_id, (long) oldId, newMsgObj.id, 0, false, newMsgObj.peer_id.channel_id, scheduled ? 1 : 0); getMessagesStorage().putMessages(sentMessages, true, false, false, 0, scheduled); AndroidUtilities.runOnUIThread(() -> { getMediaDataController().increasePeerRaiting(newMsgObj.dialog_id); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java b/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java index 10d66765b..18b7bd170 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java @@ -94,6 +94,7 @@ public class SharedConfig { public static boolean saveStreamMedia = true; public static boolean smoothKeyboard = true; public static boolean pauseMusicOnRecord = true; + public static boolean noStatusBar; public static boolean sortContactsByName; public static boolean sortFilesByName; public static boolean shuffleMusic; @@ -278,6 +279,7 @@ public class SharedConfig { devicePerformanceClass = preferences.getInt("devicePerformanceClass", -1); loopStickers = preferences.getBoolean("loopStickers", true); keepMedia = preferences.getInt("keep_media", 2); + noStatusBar = preferences.getBoolean("noStatusBar", false); lastKeepMediaCheckTime = preferences.getInt("lastKeepMediaCheckTime", 0); searchMessagesAsListHintShows = preferences.getInt("searchMessagesAsListHintShows", 0); searchMessagesAsListUsed = preferences.getBoolean("searchMessagesAsListUsed", false); @@ -541,6 +543,14 @@ public class SharedConfig { editor.commit(); } + public static void toggleNoStatusBar() { + noStatusBar = !noStatusBar; + SharedPreferences preferences = MessagesController.getGlobalMainSettings(); + SharedPreferences.Editor editor = preferences.edit(); + editor.putBoolean("noStatusBar", noStatusBar); + editor.commit(); + } + public static void toggleLoopStickers() { loopStickers = !loopStickers; SharedPreferences preferences = MessagesController.getGlobalMainSettings(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java b/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java index f8a5f0397..7a69f5813 100755 --- a/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java @@ -35,6 +35,7 @@ import android.widget.Toast; import org.json.JSONArray; import org.json.JSONObject; +import org.telegram.messenger.AccountInstance; import org.telegram.messenger.AndroidUtilities; import org.telegram.messenger.ApplicationLoader; import org.telegram.messenger.BuildVars; @@ -860,32 +861,6 @@ public class VoIPService extends VoIPBaseService { req.reason = new TLRPC.TL_phoneCallDiscardReasonHangup(); break; } - final boolean wasNotConnected = ConnectionsManager.getInstance(currentAccount).getConnectionState() != ConnectionsManager.ConnectionStateConnected; - final Runnable stopper; - if (wasNotConnected) { - if (onDone != null) { - onDone.run(); - } - callEnded(); - stopper = null; - } else { - stopper = new Runnable() { - private boolean done = false; - - @Override - public void run() { - if (done) { - return; - } - done = true; - if (onDone != null) { - onDone.run(); - } - callEnded(); - } - }; - AndroidUtilities.runOnUIThread(stopper, (int) (Instance.getGlobalServerConfig().hangupUiTimeout * 1000)); - } ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> { if (error != null) { if (BuildVars.LOGS_ENABLED) { @@ -900,13 +875,9 @@ public class VoIPService extends VoIPBaseService { FileLog.d("phone.discardCall " + response); } } - if (!wasNotConnected) { - AndroidUtilities.cancelRunOnUIThread(stopper); - if (onDone != null) { - onDone.run(); - } - } }, ConnectionsManager.RequestFlagFailOnServerErrors); + onDestroyRunnable = onDone; + callEnded(); } public void onSignalingData(TLRPC.TL_updatePhoneCallSignalingData data) { @@ -1222,7 +1193,7 @@ public class VoIPService extends VoIPBaseService { groupCall.call.version = 1; groupCall.call.can_change_join_muted = true; groupCall.chatId = chat.id; - groupCall.currentAccount = currentAccount; + groupCall.currentAccount = AccountInstance.getInstance(currentAccount); dispatchStateChanged(STATE_CREATING); TLRPC.TL_phone_createGroupCall req = new TLRPC.TL_phone_createGroupCall(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java index 310c42025..1e0ba3e1b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java @@ -132,7 +132,7 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter { public int getItemCount() { ArrayList array = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen); int dialogsCount = array.size(); - if (dialogsType != 7 && dialogsType != 8 && dialogsCount == 0 && (folderId != 0 || MessagesController.getInstance(currentAccount).isLoadingDialogs(folderId))) { + if (dialogsType != 7 && dialogsType != 8 && dialogsCount == 0 && (folderId != 0 || MessagesController.getInstance(currentAccount).isLoadingDialogs(folderId) || !MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId))) { onlineContacts = null; if (folderId == 1 && showArchiveHint) { return (currentCount = 2); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java index 8419305aa..ec503a0ba 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java @@ -4847,7 +4847,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate maxPhotoWidth = photoWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f); } else { if (currentPhotoObject != null && (messageObject.type == MessageObject.TYPE_PHOTO || messageObject.type == MessageObject.TYPE_VIDEO || messageObject.type == 8) && currentPhotoObject.w >= currentPhotoObject.h) { - maxPhotoWidth = photoWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(64); + maxPhotoWidth = photoWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp((drawAvatar ? 116 : 64) + (checkNeedDrawShareButton(messageObject) ? 10 : 0)); useFullWidth = true; } else { maxPhotoWidth = photoWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java index 5e6fc8947..c80706e50 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java @@ -841,7 +841,12 @@ public class DialogCell extends BaseCell { startPadding = statusDrawable.getIntrinsicWidth() + AndroidUtilities.dp(3); } SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); - spannableStringBuilder.append(" ").append(TextUtils.replace(printingString, new String[]{"..."}, new String[]{""})).setSpan(new FixedWidthSpan(startPadding), 0, 1, 0); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && LocaleController.isRTL && (int) currentDialogId < 0) { + spannableStringBuilder.append(TextUtils.replace(printingString, new String[]{"..."}, new String[]{""})).append(" "); + spannableStringBuilder.setSpan(new FixedWidthSpan(startPadding), spannableStringBuilder.length() - 1, spannableStringBuilder.length(), 0); + } else { + spannableStringBuilder.append(" ").append(TextUtils.replace(printingString, new String[]{"..."}, new String[]{""})).setSpan(new FixedWidthSpan(startPadding), 0, 1, 0); + } messageString = spannableStringBuilder; currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex]; checkMessage = false; @@ -2430,7 +2435,7 @@ public class DialogCell extends BaseCell { StatusDrawable statusDrawable = Theme.getChatStatusDrawable(printingStringType); if (statusDrawable != null) { canvas.save(); - int left = (LocaleController.isRTL || messageLayout.isRtlCharAt(0)) ? messageLeft + messageLayout.getWidth() - statusDrawable.getIntrinsicWidth() : messageLeft; + int left = (LocaleController.isRTL || messageLayout.isRtlCharAt(0)) ? getMeasuredWidth() - AndroidUtilities.dp(72) - statusDrawable.getIntrinsicWidth() : messageLeft; if (printingStringType == 1 || printingStringType == 4) { canvas.translate(left, messageTop + (printingStringType == 1 ? AndroidUtilities.dp(1) : 0)); } else { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java index 67be47743..5a47bf71e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java @@ -117,6 +117,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent private int animationIndex = -1; boolean checkCallAfterAnimation; + boolean checkPlayerAfterAnimation; @Override public void onAudioSettingsChanged() { @@ -773,7 +774,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent if (VoIPService.getSharedInstance() != null && !VoIPService.getSharedInstance().isHangingUp() && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING && !GroupCallPip.isShowing()) { checkCall(true); - } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && !GroupCallPip.isShowing()) { + } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && !GroupCallPip.isShowing() && !isPlayingVoice()) { checkCall(true); } else { checkPlayer(true); @@ -821,7 +822,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent } } } else if (id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged || id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.didEndCall) { - if (currentStyle == 3) { + if (currentStyle == 3 || currentStyle == 4) { checkCall(false); } checkPlayer(false); @@ -1080,7 +1081,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent } private void checkPlayer(boolean create) { - if (visible && (currentStyle == 3 || currentStyle == 4)) { + if (visible && (currentStyle == 3 || currentStyle == 4 && !isPlayingVoice())) { return; } MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); @@ -1093,7 +1094,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent if (messageObject == null || messageObject.getId() == 0 || messageObject.isVideo()) { lastMessageObject = null; boolean callAvailable = supportsCalls && VoIPService.getSharedInstance() != null && !VoIPService.getSharedInstance().isHangingUp() && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING && !GroupCallPip.isShowing(); - if (!callAvailable && fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && !GroupCallPip.isShowing()) { + if (!isPlayingVoice() && !callAvailable && fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && !GroupCallPip.isShowing()) { callAvailable = true; } if (callAvailable) { @@ -1131,7 +1132,11 @@ public class FragmentContextView extends FrameLayout implements NotificationCent animatorSet = null; if (checkCallAfterAnimation) { checkCall(false); + } else if (checkPlayerAfterAnimation) { + checkPlayer(false); } + checkCallAfterAnimation = false; + checkPlayerAfterAnimation = false; } } }); @@ -1141,6 +1146,10 @@ public class FragmentContextView extends FrameLayout implements NotificationCent setVisibility(View.GONE); } } else { + if (currentStyle != 0 && animatorSet != null && !create) { + checkPlayerAfterAnimation = true; + return; + } int prevStyle = currentStyle; updateStyle(0); if (create && topPadding == 0) { @@ -1180,7 +1189,11 @@ public class FragmentContextView extends FrameLayout implements NotificationCent animatorSet = null; if (checkCallAfterAnimation) { checkCall(false); + } else if (checkPlayerAfterAnimation) { + checkPlayer(false); } + checkCallAfterAnimation = false; + checkPlayerAfterAnimation = false; } } }); @@ -1235,6 +1248,11 @@ public class FragmentContextView extends FrameLayout implements NotificationCent } } + private boolean isPlayingVoice() { + MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); + return messageObject != null && messageObject.isVoice(); + } + public void checkCall(boolean create) { View fragmentView = fragment.getFragmentView(); if (!create && fragmentView != null) { @@ -1253,7 +1271,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent callAvailable = false; } groupActive = false; - if (!GroupCallActivity.groupCallUiVisible && supportsCalls && !callAvailable && fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null) { + if (!isPlayingVoice() && !GroupCallActivity.groupCallUiVisible && supportsCalls && !callAvailable && fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null) { callAvailable = true; groupActive = true; } @@ -1287,13 +1305,17 @@ public class FragmentContextView extends FrameLayout implements NotificationCent animatorSet = null; if (checkCallAfterAnimation) { checkCall(false); + } else if (checkPlayerAfterAnimation) { + checkPlayer(false); } + checkCallAfterAnimation = false; + checkPlayerAfterAnimation = false; } } }); animatorSet.start(); } - } else if (currentStyle == -1 || currentStyle == 4 || currentStyle == 3){ + } else if (currentStyle == -1 || currentStyle == 4 || currentStyle == 3) { visible = false; setVisibility(GONE); } @@ -1382,7 +1404,11 @@ public class FragmentContextView extends FrameLayout implements NotificationCent } if (checkCallAfterAnimation) { checkCall(false); + } else if (checkPlayerAfterAnimation) { + checkPlayer(false); } + checkCallAfterAnimation = false; + checkPlayerAfterAnimation = false; } }); animatorSet.start(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java index f0a83e31c..67605c3f8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java @@ -48,6 +48,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -842,6 +843,10 @@ public class RecyclerListView extends RecyclerView { @Override public void onItemRangeInserted(int positionStart, int itemCount) { checkIfEmpty(true); + if (pinnedHeader != null && pinnedHeader.getAlpha() == 0) { + currentFirst = -1; + invalidateViews(); + } } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java index 88851c093..c3f067f11 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java @@ -630,7 +630,9 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } floatingButton.setBackgroundDrawable(drawable); floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY)); - floatingButton.setAnimation(R.raw.write_contacts_fab_icon, 52, 52); + SharedPreferences preferences = MessagesController.getGlobalMainSettings(); + boolean configAnimationsEnabled = preferences.getBoolean("view_animations", true); + floatingButton.setAnimation(configAnimationsEnabled ? R.raw.write_contacts_fab_icon : R.raw.write_contacts_fab_icon_reverse, 52, 52); floatingButtonContainer.setContentDescription(LocaleController.getString("CreateNewContact", R.string.CreateNewContact)); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java index d5bbc7b25..47323d188 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCallActivity.java @@ -61,7 +61,6 @@ import org.telegram.messenger.LocaleController; import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; -import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserObject; import org.telegram.messenger.Utilities; import org.telegram.messenger.voip.VoIPBaseService; @@ -2125,7 +2124,7 @@ public class GroupCallActivity extends BottomSheet implements NotificationCenter VoIPService.getSharedInstance().hangUp(discard ? 1 : 0); } if (call != null) { - int selfUserId = UserConfig.getInstance(call.currentAccount).clientUserId; + int selfUserId = call.currentAccount.getUserConfig().clientUserId; TLRPC.TL_groupCallParticipant participant = call.participants.get(selfUserId); if (participant != null) { call.participants.delete(selfUserId); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index 83fa5294a..4f1ab0b38 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -872,6 +872,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa } } } + if (SharedConfig.noStatusBar) { + getWindow().setStatusBarColor(0); + } } public void switchToAccount(int account, boolean removeAll) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java index 7c8ae3216..ffd222d2b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java @@ -2130,7 +2130,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No view = new GraySectionCell(mContext); view.setBackgroundColor(Theme.getColor(Theme.key_graySection) & 0xf2ffffff); } - if (sharedMediaData[3].sections.size() == 0 && !sharedMediaData[3].loading) { + if (sharedMediaData[3].sections.size() == 0) { view.setAlpha(0); } else if (section < sharedMediaData[3].sections.size()) { view.setAlpha(1f); @@ -2262,7 +2262,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No view = new GraySectionCell(mContext); view.setBackgroundColor(Theme.getColor(Theme.key_graySection) & 0xf2ffffff); } - if (sharedMediaData[currentType].sections.size() == 0 && !sharedMediaData[currentType].loading) { + if (sharedMediaData[currentType].sections.size() == 0) { view.setAlpha(0); } else if (section < sharedMediaData[currentType].sections.size()) { view.setAlpha(1f); @@ -2433,7 +2433,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No view = new SharedMediaSectionCell(mContext); view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite) & 0xe5ffffff); } - if (sharedMediaData[0].sections.size() == 0 && !sharedMediaData[0].loading) { + if (sharedMediaData[0].sections.size() == 0) { view.setAlpha(0); } else if (section < sharedMediaData[0].sections.size()) { view.setAlpha(1f); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index 47cf21f10..f306618a1 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -2066,7 +2066,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } } - int top = 0; + int top = paddingTop; if (view != null) { top = view.getTop(); } @@ -2075,6 +2075,9 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. layoutManager.scrollToPositionWithOffset(sharedMediaRow, -paddingTop); layout = true; } else if ((!changed || !allowPullingDown) && view != null) { + if (pos == 0 && !allowPullingDown && top > AndroidUtilities.dp(88)) { + top = AndroidUtilities.dp(88); + } layoutManager.scrollToPositionWithOffset(pos, top - paddingTop); layout = true; } @@ -2584,7 +2587,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. LocaleController.getString("DebugMenuReadAllDialogs", R.string.DebugMenuReadAllDialogs), SharedConfig.pauseMusicOnRecord ? LocaleController.getString("DebugMenuDisablePauseMusic", R.string.DebugMenuDisablePauseMusic) : LocaleController.getString("DebugMenuEnablePauseMusic", R.string.DebugMenuEnablePauseMusic), BuildVars.DEBUG_VERSION && !AndroidUtilities.isTablet() && Build.VERSION.SDK_INT >= 23 ? (SharedConfig.smoothKeyboard ? LocaleController.getString("DebugMenuDisableSmoothKeyboard", R.string.DebugMenuDisableSmoothKeyboard) : LocaleController.getString("DebugMenuEnableSmoothKeyboard", R.string.DebugMenuEnableSmoothKeyboard)) : null, - BuildVars.DEBUG_PRIVATE_VERSION ? (SharedConfig.disableVoiceAudioEffects ? "Enable voip audio effects" : "Disable voip audio effects") : null + BuildVars.DEBUG_PRIVATE_VERSION ? (SharedConfig.disableVoiceAudioEffects ? "Enable voip audio effects" : "Disable voip audio effects") : null, + Build.VERSION.SDK_INT >= 21 ? (SharedConfig.noStatusBar ? "Show status bar background" : "Hide status bar background") : null }; builder.setItems(items, (dialog, which) -> { if (which == 0) { @@ -2630,6 +2634,15 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } } else if (which == 13) { SharedConfig.toggleDisableVoiceAudioEffects(); + } else if (which == 14) { + SharedConfig.toggleNoStatusBar(); + if (getParentActivity() != null) { + if (SharedConfig.noStatusBar) { + getParentActivity().getWindow().setStatusBarColor(0); + } else { + getParentActivity().getWindow().setStatusBarColor(0x33000000); + } + } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);