From b54a41dc6cb7949df5b205a41ee2db6127474c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 2 Feb 2021 01:24:58 +0800 Subject: [PATCH] Minor fixes --- TMessagesProj/build.gradle | 10 +- .../messenger/MessagesController.java | 2 +- .../org/telegram/messenger/UserConfig.java | 4 + .../telegram/tgnet/ConnectionsManager.java | 37 ++-- .../ui/Components/ChatActivityEnterView.java | 8 +- .../java/org/telegram/ui/LoginActivity.java | 14 +- .../org/telegram/ui/SessionsActivity.java | 163 +++++++++--------- 7 files changed, 134 insertions(+), 104 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index d049e2406..d797076f6 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -1,8 +1,11 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -def verName = "7.4.2-preview-5" -def verCode = 172 +def verName = "7.4.2-preview-6" +def verCode = 174 + +def officialVer = "7.4.2" +def officialCode = 2227 def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json") @@ -161,6 +164,9 @@ android { appHash = properties.getProperty("TELEGRAM_APP_HASH") ?: System.getenv("TELEGRAM_APP_HASH") ?: appHash } + + buildConfigField 'String', 'OFFICIAL_VERSION', "\"" + officialVer + "\"" + buildConfigField 'int', 'OFFICIAL_VERSION_CODE', officialCode + "" buildConfigField 'int', 'APP_ID', appId buildConfigField 'String', 'APP_HASH', "\"" + appHash + "\"" diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 9a379520b..e72e88887 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -7604,7 +7604,7 @@ public class MessagesController extends BaseController implements NotificationCe migratingDialogs = false; getNotificationCenter().postNotificationName(NotificationCenter.needReloadRecentDialogsSearch); } else { - generateUpdateMessage(); + // generateUpdateMessage(); if (!added && loadType == DIALOGS_LOAD_TYPE_CACHE && dialogsEndReached.get(folderId)) { loadDialogs(folderId, 0, count, false); } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java b/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java index a67cbd385..94c5a01f2 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java @@ -66,6 +66,7 @@ public class UserConfig extends BaseController { public long lastUpdateCheckTime; public long autoDownloadConfigLoadTime; public boolean isBot; + public boolean official; public volatile byte[] savedPasswordHash; public volatile byte[] savedSaltedPassword; @@ -151,6 +152,8 @@ public class UserConfig extends BaseController { editor.putInt("sharingMyLocationUntil", sharingMyLocationUntil); editor.putInt("lastMyLocationShareTime", lastMyLocationShareTime); editor.putBoolean("isBot", isBot); + editor.putBoolean("official", official); + editor.putBoolean("filtersLoaded", filtersLoaded); if (tonEncryptedData != null) { editor.putString("tonEncryptedData", tonEncryptedData); @@ -303,6 +306,7 @@ public class UserConfig extends BaseController { autoDownloadConfigLoadTime = preferences.getLong("autoDownloadConfigLoadTime", 0); hasValidDialogLoadIds = preferences.contains("2dialogsLoadOffsetId") || preferences.getBoolean("hasValidDialogLoadIds", false); isBot = preferences.getBoolean("isBot",false); + official = preferences.getBoolean("official", false); tonEncryptedData = preferences.getString("tonEncryptedData", null); tonPublicKey = preferences.getString("tonPublicKey", null); tonKeyName = preferences.getString("tonKeyName", "walletKey" + currentAccount); diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java index 707c7d527..eb78916d8 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java @@ -2,7 +2,6 @@ package org.telegram.tgnet; import android.annotation.SuppressLint; import android.content.SharedPreferences; -import android.content.pm.PackageInfo; import android.os.AsyncTask; import android.os.Build; import android.os.SystemClock; @@ -52,8 +51,6 @@ import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.parts.ProxySwitcher; import tw.nekomimi.nekogram.utils.DnsFactory; -//import org.telegram.messenger.BuildConfig; - public class ConnectionsManager extends BaseController { public final static int ConnectionTypeGeneric = 1; @@ -171,21 +168,34 @@ public class ConnectionsManager extends BaseController { systemLangCode = LocaleController.getSystemLocaleStringIso639().toLowerCase(); langCode = LocaleController.getLocaleStringIso639().toLowerCase(); deviceModel = Build.MANUFACTURER + Build.MODEL; - PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0); - appVersion = pInfo.versionName + " (" + pInfo.versionCode + ")"; - if (BuildVars.DEBUG_PRIVATE_VERSION) { - appVersion += " pbeta"; - } else if (BuildVars.DEBUG_VERSION) { - appVersion += " beta"; - } systemVersion = "SDK " + Build.VERSION.SDK_INT; } catch (Exception e) { systemLangCode = "en"; langCode = ""; deviceModel = "Android unknown"; - appVersion = "App version unknown"; systemVersion = "SDK " + Build.VERSION.SDK_INT; } + + getUserConfig().loadConfig(); + + int version; + int appId; + String fingerprint; + if (getUserConfig().official || !getUserConfig().isClientActivated()) { + fingerprint = "49C1522548EBACD46CE322B6FD47F6092BB745D0F88082145CAF35E14DCC38E1"; + version = BuildConfig.OFFICIAL_VERSION_CODE; + appId = BuildVars.OFFICAL_APP_ID; + appVersion = BuildConfig.OFFICIAL_VERSION + " (" + BuildConfig.OFFICIAL_VERSION_CODE * 10 + 9 + ")"; + if (BuildVars.DEBUG_VERSION) { + appVersion += " beta"; + } + } else { + fingerprint = AndroidUtilities.getCertificateSHA256Fingerprint(); + version = BuildConfig.VERSION_CODE; + appId = BuildConfig.APP_ID; + appVersion = BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")"; + } + if (systemLangCode.trim().length() == 0) { systemLangCode = "en"; } @@ -198,16 +208,13 @@ public class ConnectionsManager extends BaseController { if (systemVersion.trim().length() == 0) { systemVersion = "SDK Unknown"; } - getUserConfig().loadConfig(); String pushString = SharedConfig.pushString; if (TextUtils.isEmpty(pushString) && !TextUtils.isEmpty(SharedConfig.pushStringStatus)) { pushString = SharedConfig.pushStringStatus; } - String fingerprint = AndroidUtilities.getCertificateSHA256Fingerprint(); int timezoneOffset = (TimeZone.getDefault().getRawOffset() + TimeZone.getDefault().getDSTSavings()) / 1000; - - init(BuildVars.BUILD_VERSION, TLRPC.LAYER, BuildConfig.APP_ID, deviceModel, systemVersion, appVersion, langCode, systemLangCode, configPath, FileLog.getNetworkLogPath(), pushString, fingerprint, timezoneOffset, getUserConfig().getClientUserId(), enablePushConnection); + init(version, TLRPC.LAYER, appId, deviceModel, systemVersion, appVersion, langCode, systemLangCode, configPath, FileLog.getNetworkLogPath(), pushString, fingerprint, timezoneOffset, getUserConfig().getClientUserId(), enablePushConnection); } public boolean isPushConnectionEnabled() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java index 903c43390..c8f19b77c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -3439,7 +3439,13 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe UIUtil.runOnIoDispatcher(() -> { String replaced; if (useRegex) { - replaced = ReUtil.replaceAll(finalText, originText, replaceText); + try { + replaced = ReUtil.replaceAll(finalText, originText, replaceText); + } catch (Exception e) { + UIUtil.runOnUIThread(progress::dismiss); + AlertUtil.showToast(e); + return; + } } else { replaced = StrUtil.replace(finalText, originText, replaceText); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java index e64474913..97a53ad97 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java @@ -111,7 +111,6 @@ import org.telegram.ui.Components.LayoutHelper; import org.telegram.ui.Components.ProxyDrawable; import org.telegram.ui.Components.RadialProgressView; import org.telegram.ui.Components.SlideView; -import org.telegram.ui.Components.VerticalPositionAutoAnimator; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -810,12 +809,14 @@ public class LoginActivity extends BaseFragment implements NotificationCenter.No exportLoginTokenRequest.api_id = NekoXConfig.currentAppId(); exportLoginTokenRequest.api_hash = NekoXConfig.currentAppHash(); exportLoginTokenRequest.except_ids = new ArrayList<>(); - for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { - UserConfig userConfig = UserConfig.getInstance(a); - if (!userConfig.isClientActivated()) { - continue; + if (NekoXConfig.customApi == 0) { + for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { + UserConfig userConfig = UserConfig.getInstance(a); + if (!userConfig.isClientActivated()) { + continue; + } + exportLoginTokenRequest.except_ids.add(a); } - exportLoginTokenRequest.except_ids.add(a); } } @@ -1551,6 +1552,7 @@ public class LoginActivity extends BaseFragment implements NotificationCenter.No ConnectionsManager.getInstance(currentAccount).setUserId(res.user.id); UserConfig.getInstance(currentAccount).clearConfig(); MessagesController.getInstance(currentAccount).cleanup(); + UserConfig.getInstance(currentAccount).official = NekoXConfig.currentAppId() == BuildVars.OFFICAL_APP_ID; UserConfig.getInstance(currentAccount).syncContacts = syncContacts; UserConfig.getInstance(currentAccount).setCurrentUser(res.user); UserConfig.getInstance(currentAccount).saveConfig(true); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SessionsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SessionsActivity.java index 1c6fc4669..2e048ea1d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SessionsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SessionsActivity.java @@ -58,6 +58,10 @@ import java.util.ArrayList; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import kotlin.Unit; +import tw.nekomimi.nekogram.BottomBuilder; +import tw.nekomimi.nekogram.utils.AlertUtil; + public class SessionsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { private ListAdapter listAdapter; @@ -115,7 +119,7 @@ public class SessionsActivity extends BaseFragment implements NotificationCenter TLRPC.TL_authorization newAuthorizationToOpen; @Override - public View createView(Context context) { + public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); if (currentType == 0) { @@ -288,18 +292,70 @@ public class SessionsActivity extends BaseFragment implements NotificationCenter if (button != null) { button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2)); } - } else if (position >= otherSessionsStartRow && position < otherSessionsEndRow || position >= passwordSessionsStartRow && position < passwordSessionsEndRow) { + } else if (position == currentSessionRow || position >= otherSessionsStartRow && position < otherSessionsEndRow || position >= passwordSessionsStartRow && position < passwordSessionsEndRow) { if (getParentActivity() == null) { return; } - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - final boolean[] param = new boolean[1]; - String buttonText; + if (currentType == 0) { - builder.setMessage(LocaleController.getString("TerminateSessionText", R.string.TerminateSessionText)); - builder.setTitle(LocaleController.getString("AreYouSureSessionTitle", R.string.AreYouSureSessionTitle)); - buttonText = LocaleController.getString("Terminate", R.string.Terminate); + final TLRPC.TL_authorization authorization; + if (position == currentSessionRow) { + authorization = currentSession; + } else if (position >= otherSessionsStartRow && position < otherSessionsEndRow) { + authorization = (TLRPC.TL_authorization) sessions.get(position - otherSessionsStartRow); + } else { + authorization = (TLRPC.TL_authorization) passwordSessions.get(position - passwordSessionsStartRow); + } + + BottomBuilder builder = new BottomBuilder(getParentActivity()); + + String title = authorization.app_name + " " + authorization.app_version + "\n"; + title += authorization.device_model + ", " + authorization.system_version + "\n"; + title += "Login: " + LocaleController.getInstance().chatFullDate.format(authorization.date_created * 1000L) + "\n"; + title += "Active: " + LocaleController.getInstance().chatFullDate.format(authorization.date_active * 1000L) + "\n"; + if (!authorization.official_app) { + title += "Unofficial application " + authorization.api_id + "\n"; + } + title += authorization.ip + " - " + authorization.region + " " + authorization.country; + + if (!authorization.current) { + builder.addTitle(LocaleController.getString("TerminateSessionText", R.string.TerminateSessionText), title); + builder.addItem(LocaleController.getString("Terminate", R.string.Terminate), R.drawable.baseline_delete_forever_24, true, __ -> { + TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization(); + req.hash = authorization.hash; + ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + if (error != null) { + AlertUtil.showToast(error); + return; + } + sessions.remove(authorization); + passwordSessions.remove(authorization); + updateRows(); + if (listAdapter != null) { + listAdapter.notifyDataSetChanged(); + } + })); + return Unit.INSTANCE; + }); + } else { + builder.addTitle(title); + } + + builder.addCancelItem(); + + String finalTitle = title; + builder.addItem(LocaleController.getString("Copy", R.string.Copy), R.drawable.baseline_content_copy_24, __ -> { + AlertUtil.copyAndAlert(finalTitle); + return Unit.INSTANCE; + }); + + builder.show(); + + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + final boolean[] param = new boolean[1]; + String buttonText; final TLRPC.TL_webAuthorization authorization = (TLRPC.TL_webAuthorization) sessions.get(position - otherSessionsStartRow); builder.setMessage(LocaleController.formatString("TerminateWebSessionText", R.string.TerminateWebSessionText, authorization.domain)); @@ -331,41 +387,14 @@ public class SessionsActivity extends BaseFragment implements NotificationCenter }); builder.setCustomViewOffset(16); builder.setView(frameLayout1); - } - builder.setPositiveButton(buttonText, (dialogInterface, option) -> { - if (getParentActivity() == null) { - return; - } - final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3); - progressDialog.setCanCacnel(false); - progressDialog.show(); - if (currentType == 0) { - final TLRPC.TL_authorization authorization; - if (position >= otherSessionsStartRow && position < otherSessionsEndRow) { - authorization = (TLRPC.TL_authorization) sessions.get(position - otherSessionsStartRow); - } else { - authorization = (TLRPC.TL_authorization) passwordSessions.get(position - passwordSessionsStartRow); + builder.setPositiveButton(buttonText, (dialogInterface, option) -> { + if (getParentActivity() == null) { + return; } - TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization(); - req.hash = authorization.hash; - ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { - try { - progressDialog.dismiss(); - } catch (Exception e) { - FileLog.e(e); - } - if (error == null) { - sessions.remove(authorization); - passwordSessions.remove(authorization); - updateRows(); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - } - })); - } else { - final TLRPC.TL_webAuthorization authorization = (TLRPC.TL_webAuthorization) sessions.get(position - otherSessionsStartRow); + final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3); + progressDialog.setCanCacnel(false); + progressDialog.show(); TLRPC.TL_account_resetWebAuthorization req = new TLRPC.TL_account_resetWebAuthorization(); req.hash = authorization.hash; ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { @@ -385,48 +414,23 @@ public class SessionsActivity extends BaseFragment implements NotificationCenter if (param[0]) { MessagesController.getInstance(currentAccount).blockPeer(authorization.bot_id); } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + AlertDialog alertDialog = builder.create(); + showDialog(alertDialog); + TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); + if (button != null) { + button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2)); } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - AlertDialog alertDialog = builder.create(); - showDialog(alertDialog); - TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); - if (button != null) { - button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2)); + + } + + if (newAuthorizationToOpen != null) { + AndroidUtilities.runOnUIThread(() -> undoView.showWithAction(0, UndoView.ACTION_QR_SESSION_ACCEPTED, newAuthorizationToOpen), 3000L); } } }); - if (currentType == 0) { - undoView = new UndoView(context) { - @Override - public void hide(boolean apply, int animated) { - if (!apply) { - TLRPC.TL_authorization authorization = (TLRPC.TL_authorization) getCurrentInfoObject(); - TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization(); - req.hash = authorization.hash; - ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { - if (error == null) { - sessions.remove(authorization); - passwordSessions.remove(authorization); - updateRows(); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - loadSessions(true); - } - })); - } - super.hide(apply, animated); - } - }; - frameLayout.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8)); - } - - if (newAuthorizationToOpen != null) { - AndroidUtilities.runOnUIThread(() -> undoView.showWithAction(0, UndoView.ACTION_QR_SESSION_ACCEPTED, newAuthorizationToOpen), 3000L); - } - return fragmentView; } @@ -578,7 +582,7 @@ public class SessionsActivity extends BaseFragment implements NotificationCenter @Override public boolean isEnabled(RecyclerView.ViewHolder holder) { int position = holder.getAdapterPosition(); - return position == terminateAllSessionsRow || position == qrCodeRow || position >= otherSessionsStartRow && position < otherSessionsEndRow || position >= passwordSessionsStartRow && position < passwordSessionsEndRow; + return position == currentSessionRow || position == terminateAllSessionsRow || position == qrCodeRow || position >= otherSessionsStartRow && position < otherSessionsEndRow || position >= passwordSessionsStartRow && position < passwordSessionsEndRow; } @Override @@ -709,6 +713,7 @@ public class SessionsActivity extends BaseFragment implements NotificationCenter } return 0; } + } @Override