From e1c101c334c80387cf10ca9857052e70e19c60af Mon Sep 17 00:00:00 2001 From: DrKLO Date: Thu, 25 Feb 2021 19:58:14 +0300 Subject: [PATCH] Update to 7.5.0 (2246) --- TMessagesProj/build.gradle | 2 +- TMessagesProj/jni/tgnet/Connection.cpp | 14 +- .../jni/tgnet/ConnectionsManager.cpp | 2 + TMessagesProj/jni/tgnet/ConnectionsManager.h | 2 + TMessagesProj/src/main/AndroidManifest.xml | 1 + .../org/telegram/messenger/BuildVars.java | 2 +- .../messenger/MessagesController.java | 24 ++-- .../messenger/NotificationsController.java | 3 + .../NotificationsDisabledReceiver.java | 51 ++++++- .../main/java/org/telegram/tgnet/TLRPC.java | 17 +++ .../telegram/ui/ChannelCreateActivity.java | 2 +- .../ui/Components/InviteLinkBottomSheet.java | 8 ++ .../ui/Components/LinkActionView.java | 3 +- .../Components/PermanentLinkBottomSheet.java | 2 +- .../org/telegram/ui/ManageLinksActivity.java | 128 +++++++++--------- .../main/res/layout/contacts_widget_item.xml | 4 +- .../src/main/res/layout/widget_edititem.xml | 2 + 17 files changed, 178 insertions(+), 89 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 47b4ff29e..e6287620e 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -288,7 +288,7 @@ android { } } - defaultConfig.versionCode = 2245 + defaultConfig.versionCode = 2246 applicationVariants.all { variant -> variant.outputs.all { output -> diff --git a/TMessagesProj/jni/tgnet/Connection.cpp b/TMessagesProj/jni/tgnet/Connection.cpp index 8823eda2e..0158a78e0 100644 --- a/TMessagesProj/jni/tgnet/Connection.cpp +++ b/TMessagesProj/jni/tgnet/Connection.cpp @@ -297,9 +297,17 @@ void Connection::connect() { if (strategy == USE_IPV6_ONLY) { ipv6 = TcpAddressFlagIpv6; } else if (strategy == USE_IPV4_IPV6_RANDOM) { - uint8_t value; - RAND_bytes(&value, 1); - ipv6 = value % 2 == 0 ? TcpAddressFlagIpv6 : 0; + if (ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolUsefullData) { + ipv6 = ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolIsIpv6 ? TcpAddressFlagIpv6 : 0; + } else { + uint8_t value; + RAND_bytes(&value, 1); + ipv6 = value % 3 == 0 ? TcpAddressFlagIpv6 : 0; + ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolIsIpv6 = ipv6 != 0; + } + if (connectionType == ConnectionTypeGeneric) { + ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolUsefullData = false; + } } else { ipv6 = 0; } diff --git a/TMessagesProj/jni/tgnet/ConnectionsManager.cpp b/TMessagesProj/jni/tgnet/ConnectionsManager.cpp index 69e0f6979..428e3691c 100644 --- a/TMessagesProj/jni/tgnet/ConnectionsManager.cpp +++ b/TMessagesProj/jni/tgnet/ConnectionsManager.cpp @@ -887,6 +887,7 @@ void ConnectionsManager::onConnectionDataReceived(Connection *connection, Native processServerResponse(object, messageId, 0, 0, connection, 0, 0); connection->addProcessedMessageId(messageId); } + lastProtocolUsefullData = true; connection->setHasUsefullData(); delete object; } @@ -940,6 +941,7 @@ void ConnectionsManager::onConnectionDataReceived(Connection *connection, Native } if (!processedStatus) { if (object != nullptr) { + lastProtocolUsefullData = true; connection->setHasUsefullData(); if (LOGS_ENABLED) DEBUG_D("connection(%p, account%u, dc%u, type %d) received object %s", connection, instanceNum, datacenter->getDatacenterId(), connection->getConnectionType(), typeid(*object).name()); processServerResponse(object, messageId, messageSeqNo, messageServerSalt, connection, 0, 0); diff --git a/TMessagesProj/jni/tgnet/ConnectionsManager.h b/TMessagesProj/jni/tgnet/ConnectionsManager.h index 21e2b6ae2..d44a9d589 100644 --- a/TMessagesProj/jni/tgnet/ConnectionsManager.h +++ b/TMessagesProj/jni/tgnet/ConnectionsManager.h @@ -193,6 +193,8 @@ private: bool networkAvailable = true; bool networkSlow = false; uint8_t ipStrategy = USE_IPV4_ONLY; + bool lastProtocolIsIpv6 = false; + bool lastProtocolUsefullData = false; std::vector activeConnections; std::vector activeConnectionsCopy; int epolFd; diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml index a658cdc60..f09039892 100644 --- a/TMessagesProj/src/main/AndroidManifest.xml +++ b/TMessagesProj/src/main/AndroidManifest.xml @@ -48,6 +48,7 @@ + diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index b8970d449..3b491f0d2 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 = 2245; + public static int BUILD_VERSION = 2246; public static String BUILD_VERSION_STRING = "7.5.0"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 4d0c78c1c..ac041dab8 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -12648,9 +12648,11 @@ public class MessagesController extends BaseController implements NotificationCe }*/ } if ((update.notify_settings.flags & 4) != 0) { - editor.putInt("EnableGroup2", update.notify_settings.mute_until); - editor.putBoolean("overwrite_group", true); - AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_GROUP)); + if (notificationsPreferences.getInt("EnableGroup2", 0) != update.notify_settings.mute_until) { + editor.putInt("EnableGroup2", update.notify_settings.mute_until); + editor.putBoolean("overwrite_group", true); + AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_GROUP)); + } } } else if (update.peer instanceof TLRPC.TL_notifyUsers) { if ((update.notify_settings.flags & 1) != 0) { @@ -12664,9 +12666,11 @@ public class MessagesController extends BaseController implements NotificationCe }*/ } if ((update.notify_settings.flags & 4) != 0) { - editor.putInt("EnableAll2", update.notify_settings.mute_until); - editor.putBoolean("overwrite_private", true); - AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_PRIVATE)); + if (notificationsPreferences.getInt("EnableAll2", 0) != update.notify_settings.mute_until) { + editor.putInt("EnableAll2", update.notify_settings.mute_until); + editor.putBoolean("overwrite_private", true); + AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_PRIVATE)); + } } } else if (update.peer instanceof TLRPC.TL_notifyBroadcasts) { if ((update.notify_settings.flags & 1) != 0) { @@ -12680,9 +12684,11 @@ public class MessagesController extends BaseController implements NotificationCe }*/ } if ((update.notify_settings.flags & 4) != 0) { - editor.putInt("EnableChannel2", update.notify_settings.mute_until); - editor.putBoolean("overwrite_channel", true); - AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_CHANNEL)); + if (notificationsPreferences.getInt("EnableChannel2", 0) != update.notify_settings.mute_until) { + editor.putInt("EnableChannel2", update.notify_settings.mute_until); + editor.putBoolean("overwrite_channel", true); + AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_CHANNEL)); + } } } getMessagesStorage().updateMutedDialogsFiltersCounters(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java index 2fe145520..6e52e325c 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java @@ -104,6 +104,8 @@ public class NotificationsController extends BaseController { private int lastBadgeCount = -1; private String launcherClassName; + public long lastNotificationChannelCreateTime; + private Boolean groupsCreated; public static long globalSecretChatId = -(1L << 32); @@ -3169,6 +3171,7 @@ public class NotificationsController extends BaseController { if (BuildVars.LOGS_ENABLED) { FileLog.d("create new channel " + channelId); } + lastNotificationChannelCreateTime = SystemClock.elapsedRealtime(); systemNotificationManager.createNotificationChannel(notificationChannel); preferences.edit().putString(key, channelId).putString(key + "_s", newSettingsHash).commit(); } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsDisabledReceiver.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsDisabledReceiver.java index 0fa0e7e30..2a61efa4c 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsDisabledReceiver.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsDisabledReceiver.java @@ -8,19 +8,25 @@ package org.telegram.messenger; +import android.annotation.TargetApi; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.os.SystemClock; import android.text.TextUtils; import static android.app.NotificationManager.EXTRA_BLOCKED_STATE; import static android.app.NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID; +@TargetApi(28) public class NotificationsDisabledReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + if (!"android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED".equals(intent.getAction())) { + return; + } String channelId = intent.getStringExtra(EXTRA_NOTIFICATION_CHANNEL_ID); boolean state = intent.getBooleanExtra(EXTRA_BLOCKED_STATE, false); if (TextUtils.isEmpty(channelId) || channelId.contains("_ia_")) { @@ -35,22 +41,59 @@ public class NotificationsDisabledReceiver extends BroadcastReceiver { if (account < 0 || account >= UserConfig.MAX_ACCOUNT_COUNT) { return; } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("received disabled notification channel event for " + channelId + " state = " + state); + } + if (SystemClock.elapsedRealtime() - AccountInstance.getInstance(account).getNotificationsController().lastNotificationChannelCreateTime <= 1000) { + if (BuildVars.LOGS_ENABLED) { + FileLog.d("received disable notification event right after creating notification channel, ignoring"); + } + return; + } SharedPreferences preferences = AccountInstance.getInstance(account).getNotificationsSettings(); - SharedPreferences.Editor editor = preferences.edit(); if (args[1].startsWith("channel")) { - editor.putInt(NotificationsController.getGlobalNotificationsKey(NotificationsController.TYPE_CHANNEL), state ? Integer.MAX_VALUE : 0).commit(); + String currentChannel = preferences.getString("channels", null); + if (!channelId.equals(currentChannel)) { + return; + } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("apply channel " + channelId + " state"); + } + preferences.edit().putInt(NotificationsController.getGlobalNotificationsKey(NotificationsController.TYPE_CHANNEL), state ? Integer.MAX_VALUE : 0).commit(); AccountInstance.getInstance(account).getNotificationsController().updateServerNotificationsSettings(NotificationsController.TYPE_CHANNEL); } else if (args[1].startsWith("groups")) { - editor.putInt(NotificationsController.getGlobalNotificationsKey(NotificationsController.TYPE_GROUP), state ? Integer.MAX_VALUE : 0).commit(); + String currentChannel = preferences.getString("groups", null); + if (!channelId.equals(currentChannel)) { + return; + } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("apply channel " + channelId + " state"); + } + preferences.edit().putInt(NotificationsController.getGlobalNotificationsKey(NotificationsController.TYPE_GROUP), state ? Integer.MAX_VALUE : 0).commit(); AccountInstance.getInstance(account).getNotificationsController().updateServerNotificationsSettings(NotificationsController.TYPE_GROUP); } else if (args[1].startsWith("private")) { - editor.putInt(NotificationsController.getGlobalNotificationsKey(NotificationsController.TYPE_PRIVATE), state ? Integer.MAX_VALUE : 0).commit(); + String currentChannel = preferences.getString("private", null); + if (!channelId.equals(currentChannel)) { + return; + } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("apply channel " + channelId + " state"); + } + preferences.edit().putInt(NotificationsController.getGlobalNotificationsKey(NotificationsController.TYPE_PRIVATE), state ? Integer.MAX_VALUE : 0).commit(); AccountInstance.getInstance(account).getNotificationsController().updateServerNotificationsSettings(NotificationsController.TYPE_PRIVATE); } else { long dialogId = Utilities.parseLong(args[1]); if (dialogId == 0) { return; } + String currentChannel = preferences.getString("org.telegram.key" + dialogId, null); + if (!channelId.equals(currentChannel)) { + return; + } + if (BuildVars.LOGS_ENABLED) { + FileLog.d("apply channel " + channelId + " state"); + } + SharedPreferences.Editor editor = preferences.edit(); editor.putInt("notify2_" + dialogId, state ? 2 : 0); if (!state) { editor.remove("notifyuntil_" + dialogId); diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java index dd015b46f..e5bfa51a3 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java @@ -43223,6 +43223,23 @@ public class TLRPC { } } + public static class TL_messages_getExportedChatInvite extends TLObject { + public static int constructor = 0x73746f5c; + + public InputPeer peer; + public String link; + + public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) { + return messages_ExportedChatInvite.TLdeserialize(stream, constructor, exception); + } + + public void serializeToStream(AbstractSerializedData stream) { + stream.writeInt32(constructor); + peer.serializeToStream(stream); + stream.writeString(link); + } + } + public static class TL_messages_editExportedChatInvite extends TLObject { public static int constructor = 0x2e4ffbe; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChannelCreateActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChannelCreateActivity.java index 61c050cf3..203d005f3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChannelCreateActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChannelCreateActivity.java @@ -720,7 +720,7 @@ public class ChannelCreateActivity extends BaseFragment implements NotificationC permanentLinkView = new LinkActionView(context, this, null, chatId, true, ChatObject.isChannel(getMessagesController().getChat(chatId))); //permanentLinkView.showOptions(false); - permanentLinkView.showRevokeOption(true); + permanentLinkView.hideRevokeOption(true); permanentLinkView.setUsers(0, null); privateContainer.addView(permanentLinkView); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/InviteLinkBottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/InviteLinkBottomSheet.java index 495c6ca2d..283f59488 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/InviteLinkBottomSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/InviteLinkBottomSheet.java @@ -91,6 +91,8 @@ public class InviteLinkBottomSheet extends BottomSheet { private boolean isChannel; private final long timeDif; + private boolean canEdit = true; + public InviteLinkBottomSheet(Context context, TLRPC.TL_chatInviteExported invite, TLRPC.ChatFull info, HashMap users, BaseFragment fragment, int chatId, boolean permanent, boolean isChannel) { super(context, false); this.invite = invite; @@ -677,6 +679,8 @@ public class InviteLinkBottomSheet extends BottomSheet { actionView.setLink(invite.link); actionView.setRevoke(invite.revoked); actionView.setPermanent(invite.permanent); + actionView.setCanEdit(canEdit); + actionView.hideRevokeOption(!canEdit); break; case 4: TimerPrivacyCell privacyCell = (TimerPrivacyCell) holder.itemView; @@ -915,4 +919,8 @@ public class InviteLinkBottomSheet extends BottomSheet { super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(84), MeasureSpec.EXACTLY)); } } + + public void setCanEdit(boolean canEdit) { + this.canEdit = canEdit; + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java index 892daca52..7436ff5a0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java @@ -303,6 +303,7 @@ public class LinkActionView extends LinearLayout { } }); actionBarPopupWindow.setOutsideTouchable(true); + actionBarPopupWindow.setFocusable(true); actionBarPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); actionBarPopupWindow.setAnimationStyle(R.style.PopupContextAnimation); actionBarPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED); @@ -417,7 +418,7 @@ public class LinkActionView extends LinearLayout { optionsView.setVisibility(b ? View.VISIBLE : View.GONE); } - public void showRevokeOption(boolean b) { + public void hideRevokeOption(boolean b) { if (hideRevokeOption != b) { hideRevokeOption = b; optionsView.setVisibility(View.VISIBLE); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/PermanentLinkBottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/PermanentLinkBottomSheet.java index 9a5e28292..f03edee43 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/PermanentLinkBottomSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/PermanentLinkBottomSheet.java @@ -54,7 +54,7 @@ public class PermanentLinkBottomSheet extends BottomSheet { linkIcon.setCustomEndFrame(42); imageView.setAnimation(linkIcon); linkActionView.setUsers(0, null); - linkActionView.showRevokeOption(true); + linkActionView.hideRevokeOption(true); linkActionView.setDelegate(() -> generateLink(true)); titleView = new TextView(context); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ManageLinksActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ManageLinksActivity.java index 0be024b2d..1db63e51b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ManageLinksActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ManageLinksActivity.java @@ -75,7 +75,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; -public class ManageLinksActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { +public class ManageLinksActivity extends BaseFragment { private ListAdapter listViewAdapter; private RecyclerListView listView; @@ -142,11 +142,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen long timeDif; private boolean isPublic; - - @Override - public void didReceivedNotification(int id, int account, Object... args) { - - } + private boolean canEdit; Runnable updateTimerRunnable = new Runnable() { @Override @@ -168,7 +164,6 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen } }; - private static class EmptyView extends LinearLayout implements NotificationCenter.NotificationCenterDelegate { private BackupImageView stickerView; @@ -237,11 +232,14 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen } else { this.adminId = adminId; } + + TLRPC.User user = getMessagesController().getUser(this.adminId); + canEdit = (this.adminId == getAccountInstance().getUserConfig().clientUserId) || (user != null && !user.bot); } boolean loadRevoked = false; - private void loadLinks() { + private void loadLinks(boolean notify) { if (loadAdmins && !adminsLoaded) { linksLoading = true; TLRPC.TL_messages_getAdminsWithInvites req = new TLRPC.TL_messages_getAdminsWithInvites(); @@ -273,16 +271,16 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen recyclerItemsEnterAnimator.showItemsAnimated(oldRowsCount + 1); } } + if (!hasMore || (invites.size() + revokedInvites.size() + admins.size()) >= 5) { + resumeDelayedFragmentAnimation(); + } if (!hasMore && !loadRevoked) { hasMore = true; loadRevoked = true; - loadLinks(); + loadLinks(false); } updateRows(true); - if (!hasMore || (invites.size() + revokedInvites.size() + admins.size()) >= 5) { - resumeDelayedFragmentAnimation(); - } }); }); }); @@ -407,13 +405,11 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen } if (loadNext) { - loadLinks(); + loadLinks(false); } - if (updateByDiffUtils && isOpened && listViewAdapter != null && listView.getChildCount() > 0) { - updateRows(false); - callback.fillPositions(callback.newPositionToItem); - DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); - AndroidUtilities.updateVisibleRows(listView); + + if (updateByDiffUtils && listViewAdapter != null && listView.getChildCount() > 0) { + updateRecyclerViewAnimated(callback); } else { updateRows(true); } @@ -422,6 +418,9 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen }); getConnectionsManager().bindRequestToGuid(reqId, getClassGuid()); } + if (notify) { + updateRows(true); + } } private void updateRows(boolean notify) { @@ -468,7 +467,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen if (!otherAdmin) { dividerRow = rowCount++; createNewLinkRow = rowCount++; - } else if (!invites.isEmpty() || (linksLoading && !loadRevoked)) { + } else if (!invites.isEmpty()) { dividerRow = rowCount++; linksHeaderRow = rowCount++; } @@ -509,7 +508,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen revokeAllRow = rowCount++; } - if (!loadAdmins && !loadRevoked && (linksLoading || hasMore)) { + if (!loadAdmins && !loadRevoked && (linksLoading || hasMore) && !otherAdmin) { linksLoadingRow = rowCount++; } @@ -571,7 +570,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen if (hasMore && !linksLoading) { int lastPosition = layoutManager.findLastVisibleItemPosition(); if (rowCount - lastPosition < 10) { - loadLinks(); + loadLinks(true); } } } @@ -601,6 +600,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen } else if (position >= linksStartRow && position < linksEndRow) { TLRPC.TL_chatInviteExported invite = invites.get(position - linksStartRow); inviteLinkBottomSheet = new InviteLinkBottomSheet(context, invite, info, users, this, currentChatId, false, isChannel); + inviteLinkBottomSheet.setCanEdit(canEdit); inviteLinkBottomSheet.show(); } else if (position >= revokedLinksStartRow && position < revokedLinksEndRow) { TLRPC.TL_chatInviteExported invite = revokedInvites.get(position - revokedLinksStartRow); @@ -628,9 +628,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen if (error == null) { DiffCallback callback = saveListState(); revokedInvites.clear(); - updateRows(false); - callback.fillPositions(callback.newPositionToItem); - DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); + updateRecyclerViewAnimated(callback); } })); }); @@ -671,7 +669,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen this.invite = (TLRPC.TL_chatInviteExported) invite; isPublic = !TextUtils.isEmpty(currentChat.username); - loadLinks(); + loadLinks(true); } @Override @@ -765,7 +763,6 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen @Override public void showUsersForPermanentLink() { - boolean canEdit = adminId == getAccountInstance().getUserConfig().clientUserId; inviteLinkBottomSheet = new InviteLinkBottomSheet(linkActionView.getContext(), invite, info, users, ManageLinksActivity.this, currentChatId, true, isChannel); inviteLinkBottomSheet.show(); } @@ -828,10 +825,10 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen if (info != null) { linkActionView.setLink("https://t.me/" + currentChat.username); linkActionView.setUsers(0, null); - linkActionView.showRevokeOption(true); + linkActionView.hideRevokeOption(true); } } else { - linkActionView.showRevokeOption(false); + linkActionView.hideRevokeOption(!canEdit); if (invite != null) { TLRPC.TL_chatInviteExported inviteExported = invite; linkActionView.setLink(inviteExported.link); @@ -971,10 +968,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen oldInvite.revoked = true; DiffCallback callback = saveListState(); revokedInvites.add(0, oldInvite); - updateRows(false); - callback.fillPositions(callback.newPositionToItem); - DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); - AndroidUtilities.updateVisibleRows(listView); + updateRecyclerViewAnimated(callback); BulletinFactory.of(this).createSimpleBulletin(R.raw.linkbroken, LocaleController.getString("InviteRevokedHint", R.string.InviteRevokedHint)).show(); } @@ -1114,10 +1108,12 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen ArrayList icons = new ArrayList<>(); final ArrayList actions = new ArrayList<>(); + boolean redLastItem = false; if (invite.revoked) { items.add(LocaleController.getString("Delete", R.string.Delete)); icons.add(R.drawable.msg_delete); actions.add(4); + redLastItem = true; } else { items.add(LocaleController.getString("Copy", R.string.Copy)); icons.add(R.drawable.msg_copy); @@ -1127,15 +1123,18 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen icons.add(R.drawable.msg_share); actions.add(1); - if (!invite.permanent) { + if (!invite.permanent && canEdit) { items.add(LocaleController.getString("Edit", R.string.Edit)); icons.add(R.drawable.msg_edit); actions.add(2); } - items.add(LocaleController.getString("RevokeLink", R.string.RevokeLink)); - icons.add(R.drawable.msg_delete); - actions.add(3); + if (canEdit) { + items.add(LocaleController.getString("RevokeLink", R.string.RevokeLink)); + icons.add(R.drawable.msg_delete); + actions.add(3); + redLastItem = true; + } } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); @@ -1197,9 +1196,9 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen builder.setTitle(LocaleController.getString("InviteLink", R.string.InviteLink)); AlertDialog alert = builder.create(); builder.show(); - //if (adminId == getAccountInstance().getUserConfig().getClientUserId()) { - alert.setItemColor(items.size() - 1, Theme.getColor(Theme.key_dialogTextRed2), Theme.getColor(Theme.key_dialogRedIcon)); - // } + if (redLastItem) { + alert.setItemColor(items.size() - 1, Theme.getColor(Theme.key_dialogTextRed2), Theme.getColor(Theme.key_dialogRedIcon)); + } }); optionsView.setBackground(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1)); addView(optionsView, LayoutHelper.createFrame(40, 48, Gravity.RIGHT | Gravity.CENTER_VERTICAL)); @@ -1481,20 +1480,14 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen invite.revoked = true; DiffCallback callback = saveListState(); - if (isPublic) { + if (isPublic && adminId == getAccountInstance().getUserConfig().getClientUserId()) { invites.remove(invite); invites.add(0, (TLRPC.TL_chatInviteExported) replaced.new_invite); + } else if (this.invite != null) { + this.invite = (TLRPC.TL_chatInviteExported) replaced.new_invite; } revokedInvites.add(0, invite); - updateRows(false); - - if (getParentActivity() == null) { - listViewAdapter.notifyDataSetChanged(); - return; - } - callback.fillPositions(callback.newPositionToItem); - DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); - AndroidUtilities.updateVisibleRows(listView); + updateRecyclerViewAnimated(callback); } else { linkEditActivityCallback.onLinkEdited(invite, response); if (info != null) { @@ -1517,10 +1510,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen AndroidUtilities.runOnUIThread(() -> { DiffCallback callback = saveListState(); invites.add(0, (TLRPC.TL_chatInviteExported) response); - updateRows(false); - callback.fillPositions(callback.newPositionToItem); - DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); - AndroidUtilities.updateVisibleRows(listView); + updateRecyclerViewAnimated(callback); if (info != null) { info.invitesCount++; getMessagesStorage().saveChatLinksCount(currentChatId, info.invitesCount); @@ -1540,13 +1530,10 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen DiffCallback callback = saveListState(); invites.remove(i); revokedInvites.add(0, edited); - updateRows(false); - callback.fillPositions(callback.newPositionToItem); - DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); - AndroidUtilities.updateVisibleRows(listView); + updateRecyclerViewAnimated(callback); } else { invites.set(i, edited); - listViewAdapter.notifyDataSetChanged(); + updateRows(true); } return; } @@ -1560,10 +1547,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen if (revokedInvites.get(i).link.equals(removedInvite.link)) { DiffCallback callback = saveListState(); revokedInvites.remove(i); - updateRows(false); - callback.fillPositions(callback.newPositionToItem); - DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); - AndroidUtilities.updateVisibleRows(listView); + updateRecyclerViewAnimated(callback); return; } } @@ -1575,6 +1559,17 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen } }; + private void updateRecyclerViewAnimated(DiffCallback callback) { + if (isPaused || listViewAdapter == null || listView == null) { + updateRows(true); + return; + } + updateRows(false); + callback.fillPositions(callback.newPositionToItem); + DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter); + AndroidUtilities.updateVisibleRows(listView); + } + private class DiffCallback extends DiffUtil.Callback { @@ -1644,15 +1639,15 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen put(++pointer, dividerRow, sparseIntArray); put(++pointer, createNewLinkRow, sparseIntArray); put(++pointer, revokedHeader, sparseIntArray); - put(++pointer, revokedDivider, sparseIntArray); - put(++pointer, lastDivider, sparseIntArray); - put(++pointer, revokeAllDivider, sparseIntArray); + // put(++pointer, revokedDivider, sparseIntArray); + // put(++pointer, lastDivider, sparseIntArray); + // put(++pointer, revokeAllDivider, sparseIntArray); put(++pointer, revokeAllRow, sparseIntArray); put(++pointer, createLinkHelpRow, sparseIntArray); put(++pointer, creatorRow, sparseIntArray); put(++pointer, creatorDividerRow, sparseIntArray); put(++pointer, adminsHeaderRow, sparseIntArray); - put(++pointer, adminsDividerRow, sparseIntArray); + // put(++pointer, adminsDividerRow, sparseIntArray); put(++pointer, linksHeaderRow, sparseIntArray); put(++pointer, linksLoadingRow, sparseIntArray); } @@ -1766,6 +1761,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen } int animationIndex = -1; + @Override protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) { super.onTransitionAnimationEnd(isOpen, backward); diff --git a/TMessagesProj/src/main/res/layout/contacts_widget_item.xml b/TMessagesProj/src/main/res/layout/contacts_widget_item.xml index 4c0d4102f..9ac5fdc75 100644 --- a/TMessagesProj/src/main/res/layout/contacts_widget_item.xml +++ b/TMessagesProj/src/main/res/layout/contacts_widget_item.xml @@ -43,7 +43,7 @@ android:layout_gravity="center" android:layout_marginBottom="27dp" android:layout_marginLeft="20dp" - android:layout_marginRight="2dp" + android:layout_marginRight="4dp" android:id="@+id/contacts_widget_item_badge_bg1">