Update to 7.5.0 (2246)

This commit is contained in:
DrKLO 2021-02-25 19:58:14 +03:00
parent c44841a55b
commit e1c101c334
17 changed files with 178 additions and 89 deletions

View file

@ -288,7 +288,7 @@ android {
} }
} }
defaultConfig.versionCode = 2245 defaultConfig.versionCode = 2246
applicationVariants.all { variant -> applicationVariants.all { variant ->
variant.outputs.all { output -> variant.outputs.all { output ->

View file

@ -297,9 +297,17 @@ void Connection::connect() {
if (strategy == USE_IPV6_ONLY) { if (strategy == USE_IPV6_ONLY) {
ipv6 = TcpAddressFlagIpv6; ipv6 = TcpAddressFlagIpv6;
} else if (strategy == USE_IPV4_IPV6_RANDOM) { } else if (strategy == USE_IPV4_IPV6_RANDOM) {
uint8_t value; if (ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolUsefullData) {
RAND_bytes(&value, 1); ipv6 = ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolIsIpv6 ? TcpAddressFlagIpv6 : 0;
ipv6 = value % 2 == 0 ? 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 { } else {
ipv6 = 0; ipv6 = 0;
} }

View file

@ -887,6 +887,7 @@ void ConnectionsManager::onConnectionDataReceived(Connection *connection, Native
processServerResponse(object, messageId, 0, 0, connection, 0, 0); processServerResponse(object, messageId, 0, 0, connection, 0, 0);
connection->addProcessedMessageId(messageId); connection->addProcessedMessageId(messageId);
} }
lastProtocolUsefullData = true;
connection->setHasUsefullData(); connection->setHasUsefullData();
delete object; delete object;
} }
@ -940,6 +941,7 @@ void ConnectionsManager::onConnectionDataReceived(Connection *connection, Native
} }
if (!processedStatus) { if (!processedStatus) {
if (object != nullptr) { if (object != nullptr) {
lastProtocolUsefullData = true;
connection->setHasUsefullData(); 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()); 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); processServerResponse(object, messageId, messageSeqNo, messageServerSalt, connection, 0, 0);

View file

@ -193,6 +193,8 @@ private:
bool networkAvailable = true; bool networkAvailable = true;
bool networkSlow = false; bool networkSlow = false;
uint8_t ipStrategy = USE_IPV4_ONLY; uint8_t ipStrategy = USE_IPV4_ONLY;
bool lastProtocolIsIpv6 = false;
bool lastProtocolUsefullData = false;
std::vector<ConnectionSocket *> activeConnections; std::vector<ConnectionSocket *> activeConnections;
std::vector<ConnectionSocket *> activeConnectionsCopy; std::vector<ConnectionSocket *> activeConnectionsCopy;
int epolFd; int epolFd;

View file

@ -48,6 +48,7 @@
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/> <uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/> <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="com.sec.android.provider.badge.permission.READ"/> <uses-permission android:name="com.sec.android.provider.badge.permission.READ"/>
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/> <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/>

View file

@ -18,7 +18,7 @@ public class BuildVars {
public static boolean LOGS_ENABLED = false; public static boolean LOGS_ENABLED = false;
public static boolean USE_CLOUD_STRINGS = true; public static boolean USE_CLOUD_STRINGS = true;
public static boolean CHECK_UPDATES = 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 String BUILD_VERSION_STRING = "7.5.0";
public static int APP_ID = 4; public static int APP_ID = 4;
public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103";

View file

@ -12648,9 +12648,11 @@ public class MessagesController extends BaseController implements NotificationCe
}*/ }*/
} }
if ((update.notify_settings.flags & 4) != 0) { if ((update.notify_settings.flags & 4) != 0) {
editor.putInt("EnableGroup2", update.notify_settings.mute_until); if (notificationsPreferences.getInt("EnableGroup2", 0) != update.notify_settings.mute_until) {
editor.putBoolean("overwrite_group", true); editor.putInt("EnableGroup2", update.notify_settings.mute_until);
AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_GROUP)); editor.putBoolean("overwrite_group", true);
AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_GROUP));
}
} }
} else if (update.peer instanceof TLRPC.TL_notifyUsers) { } else if (update.peer instanceof TLRPC.TL_notifyUsers) {
if ((update.notify_settings.flags & 1) != 0) { 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) { if ((update.notify_settings.flags & 4) != 0) {
editor.putInt("EnableAll2", update.notify_settings.mute_until); if (notificationsPreferences.getInt("EnableAll2", 0) != update.notify_settings.mute_until) {
editor.putBoolean("overwrite_private", true); editor.putInt("EnableAll2", update.notify_settings.mute_until);
AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_PRIVATE)); editor.putBoolean("overwrite_private", true);
AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_PRIVATE));
}
} }
} else if (update.peer instanceof TLRPC.TL_notifyBroadcasts) { } else if (update.peer instanceof TLRPC.TL_notifyBroadcasts) {
if ((update.notify_settings.flags & 1) != 0) { 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) { if ((update.notify_settings.flags & 4) != 0) {
editor.putInt("EnableChannel2", update.notify_settings.mute_until); if (notificationsPreferences.getInt("EnableChannel2", 0) != update.notify_settings.mute_until) {
editor.putBoolean("overwrite_channel", true); editor.putInt("EnableChannel2", update.notify_settings.mute_until);
AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_CHANNEL)); editor.putBoolean("overwrite_channel", true);
AndroidUtilities.runOnUIThread(() -> getNotificationsController().deleteNotificationChannelGlobal(NotificationsController.TYPE_CHANNEL));
}
} }
} }
getMessagesStorage().updateMutedDialogsFiltersCounters(); getMessagesStorage().updateMutedDialogsFiltersCounters();

View file

@ -104,6 +104,8 @@ public class NotificationsController extends BaseController {
private int lastBadgeCount = -1; private int lastBadgeCount = -1;
private String launcherClassName; private String launcherClassName;
public long lastNotificationChannelCreateTime;
private Boolean groupsCreated; private Boolean groupsCreated;
public static long globalSecretChatId = -(1L << 32); public static long globalSecretChatId = -(1L << 32);
@ -3169,6 +3171,7 @@ public class NotificationsController extends BaseController {
if (BuildVars.LOGS_ENABLED) { if (BuildVars.LOGS_ENABLED) {
FileLog.d("create new channel " + channelId); FileLog.d("create new channel " + channelId);
} }
lastNotificationChannelCreateTime = SystemClock.elapsedRealtime();
systemNotificationManager.createNotificationChannel(notificationChannel); systemNotificationManager.createNotificationChannel(notificationChannel);
preferences.edit().putString(key, channelId).putString(key + "_s", newSettingsHash).commit(); preferences.edit().putString(key, channelId).putString(key + "_s", newSettingsHash).commit();
} }

View file

@ -8,19 +8,25 @@
package org.telegram.messenger; package org.telegram.messenger;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.SystemClock;
import android.text.TextUtils; import android.text.TextUtils;
import static android.app.NotificationManager.EXTRA_BLOCKED_STATE; import static android.app.NotificationManager.EXTRA_BLOCKED_STATE;
import static android.app.NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID; import static android.app.NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID;
@TargetApi(28)
public class NotificationsDisabledReceiver extends BroadcastReceiver { public class NotificationsDisabledReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { 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); String channelId = intent.getStringExtra(EXTRA_NOTIFICATION_CHANNEL_ID);
boolean state = intent.getBooleanExtra(EXTRA_BLOCKED_STATE, false); boolean state = intent.getBooleanExtra(EXTRA_BLOCKED_STATE, false);
if (TextUtils.isEmpty(channelId) || channelId.contains("_ia_")) { if (TextUtils.isEmpty(channelId) || channelId.contains("_ia_")) {
@ -35,22 +41,59 @@ public class NotificationsDisabledReceiver extends BroadcastReceiver {
if (account < 0 || account >= UserConfig.MAX_ACCOUNT_COUNT) { if (account < 0 || account >= UserConfig.MAX_ACCOUNT_COUNT) {
return; 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 preferences = AccountInstance.getInstance(account).getNotificationsSettings();
SharedPreferences.Editor editor = preferences.edit();
if (args[1].startsWith("channel")) { 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); AccountInstance.getInstance(account).getNotificationsController().updateServerNotificationsSettings(NotificationsController.TYPE_CHANNEL);
} else if (args[1].startsWith("groups")) { } 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); AccountInstance.getInstance(account).getNotificationsController().updateServerNotificationsSettings(NotificationsController.TYPE_GROUP);
} else if (args[1].startsWith("private")) { } 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); AccountInstance.getInstance(account).getNotificationsController().updateServerNotificationsSettings(NotificationsController.TYPE_PRIVATE);
} else { } else {
long dialogId = Utilities.parseLong(args[1]); long dialogId = Utilities.parseLong(args[1]);
if (dialogId == 0) { if (dialogId == 0) {
return; 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); editor.putInt("notify2_" + dialogId, state ? 2 : 0);
if (!state) { if (!state) {
editor.remove("notifyuntil_" + dialogId); editor.remove("notifyuntil_" + dialogId);

View file

@ -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 class TL_messages_editExportedChatInvite extends TLObject {
public static int constructor = 0x2e4ffbe; public static int constructor = 0x2e4ffbe;

View file

@ -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 = new LinkActionView(context, this, null, chatId, true, ChatObject.isChannel(getMessagesController().getChat(chatId)));
//permanentLinkView.showOptions(false); //permanentLinkView.showOptions(false);
permanentLinkView.showRevokeOption(true); permanentLinkView.hideRevokeOption(true);
permanentLinkView.setUsers(0, null); permanentLinkView.setUsers(0, null);
privateContainer.addView(permanentLinkView); privateContainer.addView(permanentLinkView);

View file

@ -91,6 +91,8 @@ public class InviteLinkBottomSheet extends BottomSheet {
private boolean isChannel; private boolean isChannel;
private final long timeDif; private final long timeDif;
private boolean canEdit = true;
public InviteLinkBottomSheet(Context context, TLRPC.TL_chatInviteExported invite, TLRPC.ChatFull info, HashMap<Integer, TLRPC.User> users, BaseFragment fragment, int chatId, boolean permanent, boolean isChannel) { public InviteLinkBottomSheet(Context context, TLRPC.TL_chatInviteExported invite, TLRPC.ChatFull info, HashMap<Integer, TLRPC.User> users, BaseFragment fragment, int chatId, boolean permanent, boolean isChannel) {
super(context, false); super(context, false);
this.invite = invite; this.invite = invite;
@ -677,6 +679,8 @@ public class InviteLinkBottomSheet extends BottomSheet {
actionView.setLink(invite.link); actionView.setLink(invite.link);
actionView.setRevoke(invite.revoked); actionView.setRevoke(invite.revoked);
actionView.setPermanent(invite.permanent); actionView.setPermanent(invite.permanent);
actionView.setCanEdit(canEdit);
actionView.hideRevokeOption(!canEdit);
break; break;
case 4: case 4:
TimerPrivacyCell privacyCell = (TimerPrivacyCell) holder.itemView; TimerPrivacyCell privacyCell = (TimerPrivacyCell) holder.itemView;
@ -915,4 +919,8 @@ public class InviteLinkBottomSheet extends BottomSheet {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(84), MeasureSpec.EXACTLY)); super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(84), MeasureSpec.EXACTLY));
} }
} }
public void setCanEdit(boolean canEdit) {
this.canEdit = canEdit;
}
} }

View file

@ -303,6 +303,7 @@ public class LinkActionView extends LinearLayout {
} }
}); });
actionBarPopupWindow.setOutsideTouchable(true); actionBarPopupWindow.setOutsideTouchable(true);
actionBarPopupWindow.setFocusable(true);
actionBarPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); actionBarPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
actionBarPopupWindow.setAnimationStyle(R.style.PopupContextAnimation); actionBarPopupWindow.setAnimationStyle(R.style.PopupContextAnimation);
actionBarPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED); actionBarPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
@ -417,7 +418,7 @@ public class LinkActionView extends LinearLayout {
optionsView.setVisibility(b ? View.VISIBLE : View.GONE); optionsView.setVisibility(b ? View.VISIBLE : View.GONE);
} }
public void showRevokeOption(boolean b) { public void hideRevokeOption(boolean b) {
if (hideRevokeOption != b) { if (hideRevokeOption != b) {
hideRevokeOption = b; hideRevokeOption = b;
optionsView.setVisibility(View.VISIBLE); optionsView.setVisibility(View.VISIBLE);

View file

@ -54,7 +54,7 @@ public class PermanentLinkBottomSheet extends BottomSheet {
linkIcon.setCustomEndFrame(42); linkIcon.setCustomEndFrame(42);
imageView.setAnimation(linkIcon); imageView.setAnimation(linkIcon);
linkActionView.setUsers(0, null); linkActionView.setUsers(0, null);
linkActionView.showRevokeOption(true); linkActionView.hideRevokeOption(true);
linkActionView.setDelegate(() -> generateLink(true)); linkActionView.setDelegate(() -> generateLink(true));
titleView = new TextView(context); titleView = new TextView(context);

View file

@ -75,7 +75,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
public class ManageLinksActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { public class ManageLinksActivity extends BaseFragment {
private ListAdapter listViewAdapter; private ListAdapter listViewAdapter;
private RecyclerListView listView; private RecyclerListView listView;
@ -142,11 +142,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
long timeDif; long timeDif;
private boolean isPublic; private boolean isPublic;
private boolean canEdit;
@Override
public void didReceivedNotification(int id, int account, Object... args) {
}
Runnable updateTimerRunnable = new Runnable() { Runnable updateTimerRunnable = new Runnable() {
@Override @Override
@ -168,7 +164,6 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
} }
}; };
private static class EmptyView extends LinearLayout implements NotificationCenter.NotificationCenterDelegate { private static class EmptyView extends LinearLayout implements NotificationCenter.NotificationCenterDelegate {
private BackupImageView stickerView; private BackupImageView stickerView;
@ -237,11 +232,14 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
} else { } else {
this.adminId = adminId; this.adminId = adminId;
} }
TLRPC.User user = getMessagesController().getUser(this.adminId);
canEdit = (this.adminId == getAccountInstance().getUserConfig().clientUserId) || (user != null && !user.bot);
} }
boolean loadRevoked = false; boolean loadRevoked = false;
private void loadLinks() { private void loadLinks(boolean notify) {
if (loadAdmins && !adminsLoaded) { if (loadAdmins && !adminsLoaded) {
linksLoading = true; linksLoading = true;
TLRPC.TL_messages_getAdminsWithInvites req = new TLRPC.TL_messages_getAdminsWithInvites(); 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); recyclerItemsEnterAnimator.showItemsAnimated(oldRowsCount + 1);
} }
} }
if (!hasMore || (invites.size() + revokedInvites.size() + admins.size()) >= 5) {
resumeDelayedFragmentAnimation();
}
if (!hasMore && !loadRevoked) { if (!hasMore && !loadRevoked) {
hasMore = true; hasMore = true;
loadRevoked = true; loadRevoked = true;
loadLinks(); loadLinks(false);
} }
updateRows(true); 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) { if (loadNext) {
loadLinks(); loadLinks(false);
} }
if (updateByDiffUtils && isOpened && listViewAdapter != null && listView.getChildCount() > 0) {
updateRows(false); if (updateByDiffUtils && listViewAdapter != null && listView.getChildCount() > 0) {
callback.fillPositions(callback.newPositionToItem); updateRecyclerViewAnimated(callback);
DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter);
AndroidUtilities.updateVisibleRows(listView);
} else { } else {
updateRows(true); updateRows(true);
} }
@ -422,6 +418,9 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
}); });
getConnectionsManager().bindRequestToGuid(reqId, getClassGuid()); getConnectionsManager().bindRequestToGuid(reqId, getClassGuid());
} }
if (notify) {
updateRows(true);
}
} }
private void updateRows(boolean notify) { private void updateRows(boolean notify) {
@ -468,7 +467,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
if (!otherAdmin) { if (!otherAdmin) {
dividerRow = rowCount++; dividerRow = rowCount++;
createNewLinkRow = rowCount++; createNewLinkRow = rowCount++;
} else if (!invites.isEmpty() || (linksLoading && !loadRevoked)) { } else if (!invites.isEmpty()) {
dividerRow = rowCount++; dividerRow = rowCount++;
linksHeaderRow = rowCount++; linksHeaderRow = rowCount++;
} }
@ -509,7 +508,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
revokeAllRow = rowCount++; revokeAllRow = rowCount++;
} }
if (!loadAdmins && !loadRevoked && (linksLoading || hasMore)) { if (!loadAdmins && !loadRevoked && (linksLoading || hasMore) && !otherAdmin) {
linksLoadingRow = rowCount++; linksLoadingRow = rowCount++;
} }
@ -571,7 +570,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
if (hasMore && !linksLoading) { if (hasMore && !linksLoading) {
int lastPosition = layoutManager.findLastVisibleItemPosition(); int lastPosition = layoutManager.findLastVisibleItemPosition();
if (rowCount - lastPosition < 10) { if (rowCount - lastPosition < 10) {
loadLinks(); loadLinks(true);
} }
} }
} }
@ -601,6 +600,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
} else if (position >= linksStartRow && position < linksEndRow) { } else if (position >= linksStartRow && position < linksEndRow) {
TLRPC.TL_chatInviteExported invite = invites.get(position - linksStartRow); TLRPC.TL_chatInviteExported invite = invites.get(position - linksStartRow);
inviteLinkBottomSheet = new InviteLinkBottomSheet(context, invite, info, users, this, currentChatId, false, isChannel); inviteLinkBottomSheet = new InviteLinkBottomSheet(context, invite, info, users, this, currentChatId, false, isChannel);
inviteLinkBottomSheet.setCanEdit(canEdit);
inviteLinkBottomSheet.show(); inviteLinkBottomSheet.show();
} else if (position >= revokedLinksStartRow && position < revokedLinksEndRow) { } else if (position >= revokedLinksStartRow && position < revokedLinksEndRow) {
TLRPC.TL_chatInviteExported invite = revokedInvites.get(position - revokedLinksStartRow); TLRPC.TL_chatInviteExported invite = revokedInvites.get(position - revokedLinksStartRow);
@ -628,9 +628,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
if (error == null) { if (error == null) {
DiffCallback callback = saveListState(); DiffCallback callback = saveListState();
revokedInvites.clear(); revokedInvites.clear();
updateRows(false); updateRecyclerViewAnimated(callback);
callback.fillPositions(callback.newPositionToItem);
DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter);
} }
})); }));
}); });
@ -671,7 +669,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
this.invite = (TLRPC.TL_chatInviteExported) invite; this.invite = (TLRPC.TL_chatInviteExported) invite;
isPublic = !TextUtils.isEmpty(currentChat.username); isPublic = !TextUtils.isEmpty(currentChat.username);
loadLinks(); loadLinks(true);
} }
@Override @Override
@ -765,7 +763,6 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
@Override @Override
public void showUsersForPermanentLink() { public void showUsersForPermanentLink() {
boolean canEdit = adminId == getAccountInstance().getUserConfig().clientUserId;
inviteLinkBottomSheet = new InviteLinkBottomSheet(linkActionView.getContext(), invite, info, users, ManageLinksActivity.this, currentChatId, true, isChannel); inviteLinkBottomSheet = new InviteLinkBottomSheet(linkActionView.getContext(), invite, info, users, ManageLinksActivity.this, currentChatId, true, isChannel);
inviteLinkBottomSheet.show(); inviteLinkBottomSheet.show();
} }
@ -828,10 +825,10 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
if (info != null) { if (info != null) {
linkActionView.setLink("https://t.me/" + currentChat.username); linkActionView.setLink("https://t.me/" + currentChat.username);
linkActionView.setUsers(0, null); linkActionView.setUsers(0, null);
linkActionView.showRevokeOption(true); linkActionView.hideRevokeOption(true);
} }
} else { } else {
linkActionView.showRevokeOption(false); linkActionView.hideRevokeOption(!canEdit);
if (invite != null) { if (invite != null) {
TLRPC.TL_chatInviteExported inviteExported = invite; TLRPC.TL_chatInviteExported inviteExported = invite;
linkActionView.setLink(inviteExported.link); linkActionView.setLink(inviteExported.link);
@ -971,10 +968,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
oldInvite.revoked = true; oldInvite.revoked = true;
DiffCallback callback = saveListState(); DiffCallback callback = saveListState();
revokedInvites.add(0, oldInvite); revokedInvites.add(0, oldInvite);
updateRows(false); updateRecyclerViewAnimated(callback);
callback.fillPositions(callback.newPositionToItem);
DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter);
AndroidUtilities.updateVisibleRows(listView);
BulletinFactory.of(this).createSimpleBulletin(R.raw.linkbroken, LocaleController.getString("InviteRevokedHint", R.string.InviteRevokedHint)).show(); 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<Integer> icons = new ArrayList<>(); ArrayList<Integer> icons = new ArrayList<>();
final ArrayList<Integer> actions = new ArrayList<>(); final ArrayList<Integer> actions = new ArrayList<>();
boolean redLastItem = false;
if (invite.revoked) { if (invite.revoked) {
items.add(LocaleController.getString("Delete", R.string.Delete)); items.add(LocaleController.getString("Delete", R.string.Delete));
icons.add(R.drawable.msg_delete); icons.add(R.drawable.msg_delete);
actions.add(4); actions.add(4);
redLastItem = true;
} else { } else {
items.add(LocaleController.getString("Copy", R.string.Copy)); items.add(LocaleController.getString("Copy", R.string.Copy));
icons.add(R.drawable.msg_copy); icons.add(R.drawable.msg_copy);
@ -1127,15 +1123,18 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
icons.add(R.drawable.msg_share); icons.add(R.drawable.msg_share);
actions.add(1); actions.add(1);
if (!invite.permanent) { if (!invite.permanent && canEdit) {
items.add(LocaleController.getString("Edit", R.string.Edit)); items.add(LocaleController.getString("Edit", R.string.Edit));
icons.add(R.drawable.msg_edit); icons.add(R.drawable.msg_edit);
actions.add(2); actions.add(2);
} }
items.add(LocaleController.getString("RevokeLink", R.string.RevokeLink)); if (canEdit) {
icons.add(R.drawable.msg_delete); items.add(LocaleController.getString("RevokeLink", R.string.RevokeLink));
actions.add(3); icons.add(R.drawable.msg_delete);
actions.add(3);
redLastItem = true;
}
} }
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); 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)); builder.setTitle(LocaleController.getString("InviteLink", R.string.InviteLink));
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
builder.show(); builder.show();
//if (adminId == getAccountInstance().getUserConfig().getClientUserId()) { if (redLastItem) {
alert.setItemColor(items.size() - 1, Theme.getColor(Theme.key_dialogTextRed2), Theme.getColor(Theme.key_dialogRedIcon)); 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)); optionsView.setBackground(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
addView(optionsView, LayoutHelper.createFrame(40, 48, Gravity.RIGHT | Gravity.CENTER_VERTICAL)); 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; invite.revoked = true;
DiffCallback callback = saveListState(); DiffCallback callback = saveListState();
if (isPublic) { if (isPublic && adminId == getAccountInstance().getUserConfig().getClientUserId()) {
invites.remove(invite); invites.remove(invite);
invites.add(0, (TLRPC.TL_chatInviteExported) replaced.new_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); revokedInvites.add(0, invite);
updateRows(false); updateRecyclerViewAnimated(callback);
if (getParentActivity() == null) {
listViewAdapter.notifyDataSetChanged();
return;
}
callback.fillPositions(callback.newPositionToItem);
DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter);
AndroidUtilities.updateVisibleRows(listView);
} else { } else {
linkEditActivityCallback.onLinkEdited(invite, response); linkEditActivityCallback.onLinkEdited(invite, response);
if (info != null) { if (info != null) {
@ -1517,10 +1510,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
AndroidUtilities.runOnUIThread(() -> { AndroidUtilities.runOnUIThread(() -> {
DiffCallback callback = saveListState(); DiffCallback callback = saveListState();
invites.add(0, (TLRPC.TL_chatInviteExported) response); invites.add(0, (TLRPC.TL_chatInviteExported) response);
updateRows(false); updateRecyclerViewAnimated(callback);
callback.fillPositions(callback.newPositionToItem);
DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter);
AndroidUtilities.updateVisibleRows(listView);
if (info != null) { if (info != null) {
info.invitesCount++; info.invitesCount++;
getMessagesStorage().saveChatLinksCount(currentChatId, info.invitesCount); getMessagesStorage().saveChatLinksCount(currentChatId, info.invitesCount);
@ -1540,13 +1530,10 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
DiffCallback callback = saveListState(); DiffCallback callback = saveListState();
invites.remove(i); invites.remove(i);
revokedInvites.add(0, edited); revokedInvites.add(0, edited);
updateRows(false); updateRecyclerViewAnimated(callback);
callback.fillPositions(callback.newPositionToItem);
DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter);
AndroidUtilities.updateVisibleRows(listView);
} else { } else {
invites.set(i, edited); invites.set(i, edited);
listViewAdapter.notifyDataSetChanged(); updateRows(true);
} }
return; return;
} }
@ -1560,10 +1547,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
if (revokedInvites.get(i).link.equals(removedInvite.link)) { if (revokedInvites.get(i).link.equals(removedInvite.link)) {
DiffCallback callback = saveListState(); DiffCallback callback = saveListState();
revokedInvites.remove(i); revokedInvites.remove(i);
updateRows(false); updateRecyclerViewAnimated(callback);
callback.fillPositions(callback.newPositionToItem);
DiffUtil.calculateDiff(callback).dispatchUpdatesTo(listViewAdapter);
AndroidUtilities.updateVisibleRows(listView);
return; 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 { private class DiffCallback extends DiffUtil.Callback {
@ -1644,15 +1639,15 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
put(++pointer, dividerRow, sparseIntArray); put(++pointer, dividerRow, sparseIntArray);
put(++pointer, createNewLinkRow, sparseIntArray); put(++pointer, createNewLinkRow, sparseIntArray);
put(++pointer, revokedHeader, sparseIntArray); put(++pointer, revokedHeader, sparseIntArray);
put(++pointer, revokedDivider, sparseIntArray); // put(++pointer, revokedDivider, sparseIntArray);
put(++pointer, lastDivider, sparseIntArray); // put(++pointer, lastDivider, sparseIntArray);
put(++pointer, revokeAllDivider, sparseIntArray); // put(++pointer, revokeAllDivider, sparseIntArray);
put(++pointer, revokeAllRow, sparseIntArray); put(++pointer, revokeAllRow, sparseIntArray);
put(++pointer, createLinkHelpRow, sparseIntArray); put(++pointer, createLinkHelpRow, sparseIntArray);
put(++pointer, creatorRow, sparseIntArray); put(++pointer, creatorRow, sparseIntArray);
put(++pointer, creatorDividerRow, sparseIntArray); put(++pointer, creatorDividerRow, sparseIntArray);
put(++pointer, adminsHeaderRow, sparseIntArray); put(++pointer, adminsHeaderRow, sparseIntArray);
put(++pointer, adminsDividerRow, sparseIntArray); // put(++pointer, adminsDividerRow, sparseIntArray);
put(++pointer, linksHeaderRow, sparseIntArray); put(++pointer, linksHeaderRow, sparseIntArray);
put(++pointer, linksLoadingRow, sparseIntArray); put(++pointer, linksLoadingRow, sparseIntArray);
} }
@ -1766,6 +1761,7 @@ public class ManageLinksActivity extends BaseFragment implements NotificationCen
} }
int animationIndex = -1; int animationIndex = -1;
@Override @Override
protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) { protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
super.onTransitionAnimationEnd(isOpen, backward); super.onTransitionAnimationEnd(isOpen, backward);

View file

@ -43,7 +43,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginBottom="27dp" android:layout_marginBottom="27dp"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginRight="2dp" android:layout_marginRight="4dp"
android:id="@+id/contacts_widget_item_badge_bg1"> android:id="@+id/contacts_widget_item_badge_bg1">
<TextView android:id="@+id/contacts_widget_item_badge1" <TextView android:id="@+id/contacts_widget_item_badge1"
@ -99,7 +99,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginBottom="27dp" android:layout_marginBottom="27dp"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginRight="2dp" android:layout_marginRight="4dp"
android:id="@+id/contacts_widget_item_badge_bg2"> android:id="@+id/contacts_widget_item_badge_bg2">
<TextView android:id="@+id/contacts_widget_item_badge2" <TextView android:id="@+id/contacts_widget_item_badge2"

View file

@ -13,6 +13,8 @@
android:paddingRight="10dp" android:paddingRight="10dp"
android:textColor="@color/widget_edit_text" android:textColor="@color/widget_edit_text"
android:layout_gravity="center" android:layout_gravity="center"
android:singleLine="true"
android:ellipsize="end"
android:background="@drawable/widget_edit" android:background="@drawable/widget_edit"
android:gravity="center"/> android:gravity="center"/>