From 136c9582a873f2af918da834f7927dcc8e6d2846 Mon Sep 17 00:00:00 2001 From: xaxtix Date: Thu, 28 Apr 2022 17:17:48 +0300 Subject: [PATCH] Update to 8.7.3 --- TMessagesProj/build.gradle | 4 +- .../org/telegram/messenger/BuildVars.java | 6 +- .../org/telegram/messenger/ImageLoader.java | 4 +- .../telegram/messenger/voip/VoIPService.java | 48 +++++ .../main/java/org/telegram/tgnet/TLRPC.java | 17 ++ .../ui/Components/AttachBotIntroTopView.java | 22 +- .../Components/BotWebViewMenuContainer.java | 61 +++--- .../ui/Components/BotWebViewSheet.java | 191 ++++++++++++------ .../ui/Components/ChatActivityEnterView.java | 13 +- .../ui/Components/ChatAttachAlert.java | 18 +- .../ChatAttachAlertBotWebViewLayout.java | 14 +- 11 files changed, 278 insertions(+), 120 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index ba60e5633..b20fa134d 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -300,7 +300,7 @@ android { } } - defaultConfig.versionCode = 2634 + defaultConfig.versionCode = 2635 applicationVariants.all { variant -> variant.outputs.all { output -> @@ -319,7 +319,7 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 30 - versionName "8.7.2" + versionName "8.7.3" vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi'] diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index 141eae3e6..ffd074517 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -20,11 +20,11 @@ public class BuildVars { public static boolean USE_CLOUD_STRINGS = true; public static boolean CHECK_UPDATES = true; public static boolean NO_SCOPED_STORAGE = Build.VERSION.SDK_INT <= 29; - public static int BUILD_VERSION = 2634; - public static String BUILD_VERSION_STRING = "8.7.2"; + public static int BUILD_VERSION = 2635; + public static String BUILD_VERSION_STRING = "8.7.3"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; - + public static String SMS_HASH = isStandaloneApp() ? "w0lkcmTZkKh" : (DEBUG_VERSION ? "O2P2z+/jBpJ" : "oLeq9AcOZkT"); public static String PLAYSTORE_APP_URL = "https://play.google.com/store/apps/details?id=org.telegram.messenger"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java index b2e1dcedf..b8bac0fea 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java @@ -2679,7 +2679,7 @@ public class ImageLoader { img.imageType = FileLoader.IMAGE_TYPE_LOTTIE; } else if ("application/x-tgwallpattern".equals(imageLocation.document.mime_type)) { img.imageType = FileLoader.IMAGE_TYPE_SVG; - } else if (BuildVars.DEBUG_PRIVATE_VERSION) { + } else { String name = FileLoader.getDocumentFileName(imageLocation.document); if (name.endsWith(".svg")) { img.imageType = FileLoader.IMAGE_TYPE_SVG; @@ -2711,7 +2711,7 @@ public class ImageLoader { img.imageType = FileLoader.IMAGE_TYPE_LOTTIE; } else if ("application/x-tgwallpattern".equals(document.mime_type)) { img.imageType = FileLoader.IMAGE_TYPE_SVG; - } else if (BuildVars.DEBUG_PRIVATE_VERSION) { + } else { String name = FileLoader.getDocumentFileName(imageLocation.document); if (name.endsWith(".svg")) { img.imageType = FileLoader.IMAGE_TYPE_SVG; 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 9eefe7afd..e24b5f902 100755 --- a/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java @@ -90,6 +90,7 @@ import org.telegram.messenger.BuildConfig; import org.telegram.messenger.BuildVars; import org.telegram.messenger.ChatObject; import org.telegram.messenger.ContactsController; +import org.telegram.messenger.DownloadController; import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLog; import org.telegram.messenger.ImageLoader; @@ -3407,15 +3408,62 @@ public class VoIPService extends Service implements SensorEventListener, AudioMa req.peer = new TLRPC.TL_inputPhoneCall(); req.peer.access_hash = privateCall.access_hash; req.peer.id = privateCall.id; + + File file = new File(VoIPHelper.getLogFilePath(privateCall.id, true)); + String cachedFile = MediaController.copyFileToCache(Uri.fromFile(file), "log"); + ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> { if (BuildVars.LOGS_ENABLED) { FileLog.d("Sent debug logs, response = " + response); } + try { + if (response instanceof TLRPC.TL_boolFalse) { + AndroidUtilities.runOnUIThread(() -> { + uploadLogFile(cachedFile); + }); + } else { + File cacheFile = new File(cachedFile); + cacheFile.delete(); + } + } catch (Exception e) { + FileLog.e(e); + } }); needSendDebugLog = false; } } + private void uploadLogFile(String filePath) { + NotificationCenter.NotificationCenterDelegate uploadDelegate = new NotificationCenter.NotificationCenterDelegate() { + @Override + public void didReceivedNotification(int id, int account, Object... args) { + if (id == NotificationCenter.fileUploaded || id == NotificationCenter.fileUploadFailed) { + final String location = (String) args[0]; + if (location.equals(filePath)) { + if (id == NotificationCenter.fileUploaded) { + TLRPC.TL_phone_saveCallLog req = new TLRPC.TL_phone_saveCallLog(); + final TLRPC.InputFile file = (TLRPC.InputFile) args[1]; + req.file = file; + req.peer = new TLRPC.TL_inputPhoneCall(); + req.peer.access_hash = privateCall.access_hash; + req.peer.id = privateCall.id; + ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> { + if (BuildVars.LOGS_ENABLED) { + FileLog.d("Sent debug file log, response = " + response); + } + }); + } + NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileUploaded); + NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileUploadFailed); + } + } + } + }; + NotificationCenter.getInstance(currentAccount).addObserver(uploadDelegate, NotificationCenter.fileUploaded); + NotificationCenter.getInstance(currentAccount).addObserver(uploadDelegate, NotificationCenter.fileUploadFailed); + FileLoader.getInstance(currentAccount).uploadFile(filePath, false, true, ConnectionsManager.FileTypeFile); + } + private void initializeAccountRelatedThings() { updateServerConfig(); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.appDidLogout); diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java index af0091477..4740da3f4 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java @@ -52484,6 +52484,23 @@ public class TLRPC { } } + public static class TL_phone_saveCallLog extends TLObject { + public static int constructor = 0x41248786; + + public TL_inputPhoneCall peer; + public InputFile file; + + public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) { + return Bool.TLdeserialize(stream, constructor, exception); + } + + public void serializeToStream(AbstractSerializedData stream) { + stream.writeInt32(constructor); + peer.serializeToStream(stream); + file.serializeToStream(stream); + } + } + public static class TL_phone_sendSignalingData extends TLObject { public static int constructor = 0xff7a9383; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/AttachBotIntroTopView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/AttachBotIntroTopView.java index 875acaf2a..47fb79d14 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/AttachBotIntroTopView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/AttachBotIntroTopView.java @@ -32,20 +32,16 @@ public class AttachBotIntroTopView extends View { public AttachBotIntroTopView(Context context) { super(context); - imageReceiver = new ImageReceiver(this) { - @Override - protected boolean setImageBitmapByKey(Drawable drawable, String key, int type, boolean memCache, int guid) { - boolean set = super.setImageBitmapByKey(drawable, key, type, memCache, guid); - ValueAnimator anim = ValueAnimator.ofFloat(0, 1).setDuration(150); - anim.addUpdateListener(animation -> { - imageReceiver.setAlpha((Float) animation.getAnimatedValue()); - invalidate(); - }); - anim.start(); - return set; - } - }; + imageReceiver = new ImageReceiver(this); imageReceiver.setAlpha(0); + imageReceiver.setDelegate((imageReceiver1, set, thumb, memCache) -> { + ValueAnimator anim = ValueAnimator.ofFloat(0, 1).setDuration(150); + anim.addUpdateListener(animation -> { + imageReceiver.setAlpha((Float) animation.getAnimatedValue()); + invalidate(); + }); + anim.start(); + }); attachDrawable = ContextCompat.getDrawable(context, R.drawable.input_attach).mutate().getConstantState().newDrawable(); paint.setStyle(Paint.Style.STROKE); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewMenuContainer.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewMenuContainer.java index 0ced05bc3..9d5d2c8af 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewMenuContainer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewMenuContainer.java @@ -171,9 +171,6 @@ public class BotWebViewMenuContainer extends FrameLayout implements Notification ignoreLayout = false; } - if (AndroidUtilities.isTablet() && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isSmallTablet()) { - widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f), MeasureSpec.EXACTLY); - } super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec) - ActionBar.getCurrentActionBarHeight() - AndroidUtilities.statusBarHeight + AndroidUtilities.dp(24) - AndroidUtilities.dp(5), MeasureSpec.EXACTLY)); } @@ -209,6 +206,7 @@ public class BotWebViewMenuContainer extends FrameLayout implements Notification swipeContainer.setDelegate(this::dismiss); swipeContainer.setTopActionBarOffsetY(ActionBar.getCurrentActionBarHeight() + AndroidUtilities.statusBarHeight - AndroidUtilities.dp(24)); swipeContainer.setSwipeOffsetAnimationDisallowed(true); + swipeContainer.setIsKeyboardVisible(obj -> parentEnterView.getSizeNotifierLayout().getKeyboardHeight() >= AndroidUtilities.dp(20)); addView(swipeContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP, 0, 24, 0, 0)); addView(progressView = new ChatAttachAlertBotWebViewLayout.WebProgressView(context, parentEnterView.getParentFragment().getResourceProvider()), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 0, 0, 0, 5)); @@ -366,38 +364,47 @@ public class BotWebViewMenuContainer extends FrameLayout implements Notification return; } + boolean doNotScroll = false; + float openOffset = -swipeContainer.getOffsetY() + swipeContainer.getTopActionBarOffsetY(); + if (swipeContainer.getSwipeOffsetY() != openOffset) { + swipeContainer.stickTo(openOffset); + doNotScroll = true; + } + int oldh = contentHeight + parentEnterView.getSizeNotifierLayout().measureKeyboardHeight(); setMeasuredDimension(getMeasuredWidth(), contentHeight); ignoreMeasure = true; - if (webViewScrollAnimator != null) { - webViewScrollAnimator.cancel(); - webViewScrollAnimator = null; - } + if (!doNotScroll) { + if (webViewScrollAnimator != null) { + webViewScrollAnimator.cancel(); + webViewScrollAnimator = null; + } - if (webViewContainer.getWebView() != null) { - int fromY = webViewContainer.getWebView().getScrollY(); - int toY = fromY + (oldh - contentHeight); - webViewScrollAnimator = ValueAnimator.ofInt(fromY, toY).setDuration(250); - webViewScrollAnimator.setInterpolator(ChatListItemAnimator.DEFAULT_INTERPOLATOR); - webViewScrollAnimator.addUpdateListener(animation -> { - int val = (int) animation.getAnimatedValue(); - if (webViewContainer.getWebView() != null) { - webViewContainer.getWebView().setScrollY(val); - } - }); - webViewScrollAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { + if (webViewContainer.getWebView() != null) { + int fromY = webViewContainer.getWebView().getScrollY(); + int toY = fromY + (oldh - contentHeight); + webViewScrollAnimator = ValueAnimator.ofInt(fromY, toY).setDuration(250); + webViewScrollAnimator.setInterpolator(ChatListItemAnimator.DEFAULT_INTERPOLATOR); + webViewScrollAnimator.addUpdateListener(animation -> { + int val = (int) animation.getAnimatedValue(); if (webViewContainer.getWebView() != null) { - webViewContainer.getWebView().setScrollY(toY); + webViewContainer.getWebView().setScrollY(val); } - if (animation == webViewScrollAnimator) { - webViewScrollAnimator = null; + }); + webViewScrollAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + if (webViewContainer.getWebView() != null) { + webViewContainer.getWebView().setScrollY(toY); + } + if (animation == webViewScrollAnimator) { + webViewScrollAnimator = null; + } } - } - }); - webViewScrollAnimator.start(); + }); + webViewScrollAnimator.start(); + } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewSheet.java index 89036c35b..09c2c6273 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/BotWebViewSheet.java @@ -22,6 +22,7 @@ import android.view.Window; import android.view.WindowManager; import android.widget.TextView; +import androidx.annotation.IntDef; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.core.graphics.ColorUtils; @@ -47,7 +48,20 @@ import org.telegram.ui.ActionBar.Theme; import org.telegram.ui.ChatActivity; import org.telegram.ui.LaunchActivity; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + public class BotWebViewSheet extends Dialog implements NotificationCenter.NotificationCenterDelegate { + public final static int TYPE_WEB_VIEW_BUTTON = 0, TYPE_SIMPLE_WEB_VIEW_BUTTON = 1, TYPE_BOT_MENU_BUTTON = 2; + + @Retention(RetentionPolicy.SOURCE) + @IntDef(value = { + TYPE_WEB_VIEW_BUTTON, + TYPE_SIMPLE_WEB_VIEW_BUTTON, + TYPE_BOT_MENU_BUTTON + }) + public @interface WebViewType {} + private final static int POLL_PERIOD = 60000; private final static SimpleFloatPropertyCompat ACTION_BAR_TRANSITION_PROGRESS_VALUE = new SimpleFloatPropertyCompat("actionBarTransitionProgress", obj -> obj.actionBarTransitionProgress, (obj, value) -> { @@ -258,8 +272,8 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi AndroidUtilities.rectTmp.set(0, 0, getWidth(), getHeight()); canvas.drawRect(AndroidUtilities.rectTmp, dimPaint); - float radius = AndroidUtilities.dp(16) * (1f - actionBarTransitionProgress); - AndroidUtilities.rectTmp.set(0, AndroidUtilities.lerp(swipeContainer.getTranslationY(), 0, actionBarTransitionProgress), getWidth(), getHeight() + radius); + float radius = AndroidUtilities.dp(16) * (AndroidUtilities.isTablet() ? 1f : 1f - actionBarTransitionProgress); + AndroidUtilities.rectTmp.set(swipeContainer.getLeft(), AndroidUtilities.lerp(swipeContainer.getTranslationY(), 0, actionBarTransitionProgress), swipeContainer.getRight(), getHeight() + radius); canvas.drawRoundRect(AndroidUtilities.rectTmp, radius, radius, backgroundPaint); } @@ -267,12 +281,14 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi public void draw(Canvas canvas) { super.draw(canvas); + float transitionProgress = AndroidUtilities.isTablet() ? 0 : actionBarTransitionProgress; linePaint.setColor(Theme.getColor(Theme.key_dialogGrayLine)); - linePaint.setAlpha((int) (linePaint.getAlpha() * (1f - Math.min(0.5f, actionBarTransitionProgress) / 0.5f))); + linePaint.setAlpha((int) (linePaint.getAlpha() * (1f - Math.min(0.5f, transitionProgress) / 0.5f))); canvas.save(); - float scale = 1f - actionBarTransitionProgress; - float y = AndroidUtilities.lerp(swipeContainer.getTranslationY(), AndroidUtilities.statusBarHeight + ActionBar.getCurrentActionBarHeight() / 2f, actionBarTransitionProgress) + AndroidUtilities.dp(12); + float scale = 1f - transitionProgress; + float y = AndroidUtilities.isTablet() ? AndroidUtilities.lerp(swipeContainer.getTranslationY() + AndroidUtilities.dp(12), AndroidUtilities.statusBarHeight / 2f, actionBarTransitionProgress) : + (AndroidUtilities.lerp(swipeContainer.getTranslationY(), AndroidUtilities.statusBarHeight + ActionBar.getCurrentActionBarHeight() / 2f, transitionProgress) + AndroidUtilities.dp(12)); canvas.scale(scale, scale, getWidth() / 2f, y); canvas.drawLine(getWidth() / 2f - AndroidUtilities.dp(16), y, getWidth() / 2f + AndroidUtilities.dp(16), y, linePaint); canvas.restore(); @@ -286,7 +302,8 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN && event.getY() <= AndroidUtilities.lerp(swipeContainer.getTranslationY() + AndroidUtilities.dp(24), 0, actionBarTransitionProgress)) { + if (event.getAction() == MotionEvent.ACTION_DOWN && (event.getY() <= AndroidUtilities.lerp(swipeContainer.getTranslationY() + AndroidUtilities.dp(24), 0, actionBarTransitionProgress) || + event.getX() > swipeContainer.getRight() || event.getX() < swipeContainer.getLeft())) { dismiss(); return true; } @@ -298,9 +315,17 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi swipeContainer.stickTo(-swipeContainer.getOffsetY() + swipeContainer.getTopActionBarOffsetY()); } }); - frameLayout.addView(swipeContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP, 0, 24, 0, 0)); + frameLayout.addView(swipeContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 24, 0, 0)); - mainButton = new TextView(context); + mainButton = new TextView(context) { + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (AndroidUtilities.isTablet() && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isSmallTablet()) { + widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f), MeasureSpec.EXACTLY); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + }; mainButton.setVisibility(View.GONE); mainButton.setAlpha(0f); mainButton.setSingleLine(); @@ -310,7 +335,7 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi mainButton.setPadding(padding, 0, padding, 0); mainButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); mainButton.setOnClickListener(v -> webViewContainer.onMainButtonPressed()); - frameLayout.addView(mainButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM)); + frameLayout.addView(mainButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL)); mainButtonAutoAnimator = VerticalPositionAutoAnimator.attach(mainButton); radialProgressView = new RadialProgressView(context); @@ -324,7 +349,15 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi actionBarShadow = ContextCompat.getDrawable(getContext(), R.drawable.header_shadow).mutate(); - actionBar = new ActionBar(context, resourcesProvider); + actionBar = new ActionBar(context, resourcesProvider) { + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (AndroidUtilities.isTablet() && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isSmallTablet()) { + widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f), MeasureSpec.EXACTLY); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + }; actionBar.setBackgroundColor(Color.TRANSPARENT); actionBar.setBackButtonImage(R.drawable.ic_ab_back); updateActionBarColors(); @@ -337,9 +370,17 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi } }); actionBar.setAlpha(0f); - frameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP)); + frameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL)); - frameLayout.addView(progressView = new ChatAttachAlertBotWebViewLayout.WebProgressView(context, resourcesProvider), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 0, 0, 0, 0)); + frameLayout.addView(progressView = new ChatAttachAlertBotWebViewLayout.WebProgressView(context, resourcesProvider) { + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (AndroidUtilities.isTablet() && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isSmallTablet()) { + widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f), MeasureSpec.EXACTLY); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + }, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0, 0, 0)); webViewContainer.setWebViewProgressListener(progress -> { progressView.setLoadProgressAnimated(progress); if (progress == 1f) { @@ -382,6 +423,7 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi swipeContainer.setScrollEndListener(()-> webViewContainer.invalidateViewPortHeight(true)); swipeContainer.setDelegate(this::dismiss); swipeContainer.setTopActionBarOffsetY(ActionBar.getCurrentActionBarHeight() + AndroidUtilities.statusBarHeight - AndroidUtilities.dp(24)); + swipeContainer.setIsKeyboardVisible(obj -> frameLayout.getKeyboardHeight() >= AndroidUtilities.dp(20)); setContentView(frameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } @@ -402,7 +444,7 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi private void updateLightStatusBar() { int color = Theme.getColor(Theme.key_windowBackgroundWhite, null, true); - boolean lightStatusBar = ColorUtils.calculateLuminance(color) >= 0.9 && actionBarTransitionProgress >= 0.85f; + boolean lightStatusBar = !AndroidUtilities.isTablet() && ColorUtils.calculateLuminance(color) >= 0.9 && actionBarTransitionProgress >= 0.85f; if (wasLightStatusBar != null && wasLightStatusBar == lightStatusBar) { return; @@ -487,7 +529,7 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi } } - public void requestWebView(int currentAccount, long peerId, long botId, String buttonText, String buttonUrl, boolean simple, int replyToMsgId, boolean silent) { + public void requestWebView(int currentAccount, long peerId, long botId, String buttonText, String buttonUrl, @WebViewType int type, int replyToMsgId, boolean silent) { this.currentAccount = currentAccount; this.peerId = peerId; this.botId = botId; @@ -549,55 +591,88 @@ public class BotWebViewSheet extends Dialog implements NotificationCenter.Notifi webViewContainer.setBotUser(MessagesController.getInstance(currentAccount).getUser(botId)); webViewContainer.loadFlicker(currentAccount, botId); - if (simple) { - TLRPC.TL_messages_requestSimpleWebView req = new TLRPC.TL_messages_requestSimpleWebView(); - req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId); - if (hasThemeParams) { - req.theme_params = new TLRPC.TL_dataJSON(); - req.theme_params.data = themeParams; - req.flags |= 1; - } - req.url = buttonUrl; + switch (type) { + case TYPE_BOT_MENU_BUTTON: { + TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView(); + req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId); + req.peer = MessagesController.getInstance(currentAccount).getInputPeer(botId); - ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(()->{ - if (response instanceof TLRPC.TL_simpleWebViewResultUrl) { - TLRPC.TL_simpleWebViewResultUrl resultUrl = (TLRPC.TL_simpleWebViewResultUrl) response; - queryId = 0; - webViewContainer.loadUrl(resultUrl.url); - swipeContainer.setWebView(webViewContainer.getWebView()); - } - })); - } else { - TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView(); - req.peer = MessagesController.getInstance(currentAccount).getInputPeer(peerId); - req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId); - if (buttonUrl != null) { req.url = buttonUrl; req.flags |= 2; - } - if (replyToMsgId != 0) { - req.reply_to_msg_id = replyToMsgId; - req.flags |= 1; - } - - if (hasThemeParams) { - req.theme_params = new TLRPC.TL_dataJSON(); - req.theme_params.data = themeParams; - req.flags |= 4; - } - - ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { - if (response instanceof TLRPC.TL_webViewResultUrl) { - TLRPC.TL_webViewResultUrl resultUrl = (TLRPC.TL_webViewResultUrl) response; - queryId = resultUrl.query_id; - webViewContainer.loadUrl(resultUrl.url); - swipeContainer.setWebView(webViewContainer.getWebView()); - - AndroidUtilities.runOnUIThread(pollRunnable, POLL_PERIOD); + if (hasThemeParams) { + req.theme_params = new TLRPC.TL_dataJSON(); + req.theme_params.data = themeParams; + req.flags |= 4; } - })); - NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.webViewResultSent); + + ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + if (response instanceof TLRPC.TL_webViewResultUrl) { + TLRPC.TL_webViewResultUrl resultUrl = (TLRPC.TL_webViewResultUrl) response; + queryId = resultUrl.query_id; + webViewContainer.loadUrl(resultUrl.url); + swipeContainer.setWebView(webViewContainer.getWebView()); + + AndroidUtilities.runOnUIThread(pollRunnable, POLL_PERIOD); + } + })); + NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.webViewResultSent); + + break; + } + case TYPE_SIMPLE_WEB_VIEW_BUTTON: { + TLRPC.TL_messages_requestSimpleWebView req = new TLRPC.TL_messages_requestSimpleWebView(); + req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId); + if (hasThemeParams) { + req.theme_params = new TLRPC.TL_dataJSON(); + req.theme_params.data = themeParams; + req.flags |= 1; + } + req.url = buttonUrl; + + ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + if (response instanceof TLRPC.TL_simpleWebViewResultUrl) { + TLRPC.TL_simpleWebViewResultUrl resultUrl = (TLRPC.TL_simpleWebViewResultUrl) response; + queryId = 0; + webViewContainer.loadUrl(resultUrl.url); + swipeContainer.setWebView(webViewContainer.getWebView()); + } + })); + break; + } + case TYPE_WEB_VIEW_BUTTON: { + TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView(); + req.peer = MessagesController.getInstance(currentAccount).getInputPeer(peerId); + req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId); + if (buttonUrl != null) { + req.url = buttonUrl; + req.flags |= 2; + } + + if (replyToMsgId != 0) { + req.reply_to_msg_id = replyToMsgId; + req.flags |= 1; + } + + if (hasThemeParams) { + req.theme_params = new TLRPC.TL_dataJSON(); + req.theme_params.data = themeParams; + req.flags |= 4; + } + + ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + if (response instanceof TLRPC.TL_webViewResultUrl) { + TLRPC.TL_webViewResultUrl resultUrl = (TLRPC.TL_webViewResultUrl) response; + queryId = resultUrl.query_id; + webViewContainer.loadUrl(resultUrl.url); + swipeContainer.setWebView(webViewContainer.getWebView()); + + AndroidUtilities.runOnUIThread(pollRunnable, POLL_PERIOD); + } + })); + NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.webViewResultSent); + break; + } } } 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 44da40dfe..8882e0a40 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -3431,7 +3431,16 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific private void openWebViewMenu() { Runnable onRequestWebView = () -> { AndroidUtilities.hideKeyboard(this); - botWebViewMenuContainer.show(currentAccount, dialog_id, botMenuWebViewUrl); + if (AndroidUtilities.isTablet()) { + BotWebViewSheet webViewSheet = new BotWebViewSheet(getContext(), parentFragment.getResourceProvider()); + webViewSheet.setParentActivity(parentActivity); + webViewSheet.requestWebView(currentAccount, dialog_id, dialog_id, botMenuWebViewTitle, botMenuWebViewUrl, BotWebViewSheet.TYPE_BOT_MENU_BUTTON, 0, false); + webViewSheet.show(); + + botCommandsMenuButton.setOpened(false); + } else { + botWebViewMenuContainer.show(currentAccount, dialog_id, botMenuWebViewUrl); + } }; if (SharedPrefsHelper.isWebViewConfirmShown(currentAccount, dialog_id)) { @@ -7069,7 +7078,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific BotWebViewSheet webViewSheet = new BotWebViewSheet(getContext(), resourcesProvider); webViewSheet.setParentActivity(parentActivity); - webViewSheet.requestWebView(currentAccount, messageObject.messageOwner.dialog_id, botId, button.text, button.url, button instanceof TLRPC.TL_keyboardButtonSimpleWebView, replyMessageObject != null ? replyMessageObject.messageOwner.id : 0, false); + webViewSheet.requestWebView(currentAccount, messageObject.messageOwner.dialog_id, botId, button.text, button.url, button instanceof TLRPC.TL_keyboardButtonSimpleWebView ? BotWebViewSheet.TYPE_SIMPLE_WEB_VIEW_BUTTON : BotWebViewSheet.TYPE_WEB_VIEW_BUTTON, replyMessageObject != null ? replyMessageObject.messageOwner.id : 0, false); webViewSheet.show(); } }; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlert.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlert.java index b782d3e6a..06f605eff 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlert.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlert.java @@ -71,7 +71,6 @@ import org.telegram.messenger.ChatObject; import org.telegram.messenger.ContactsController; import org.telegram.messenger.Emoji; import org.telegram.messenger.ImageLocation; -import org.telegram.messenger.ImageReceiver; import org.telegram.messenger.LocaleController; import org.telegram.messenger.MediaController; import org.telegram.messenger.MediaDataController; @@ -752,17 +751,14 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N imageView = new BackupImageView(context) { { - imageReceiver = new ImageReceiver(this) { - @Override - protected boolean setImageBitmapByKey(Drawable drawable, String key, int type, boolean memCache, int guid) { - if (drawable instanceof RLottieDrawable) { - ((RLottieDrawable) drawable).setCustomEndFrame(0); - ((RLottieDrawable) drawable).stop(); - ((RLottieDrawable) drawable).setProgress(0, false); - } - return super.setImageBitmapByKey(drawable, key, type, memCache, guid); + imageReceiver.setDelegate((imageReceiver1, set, thumb, memCache) -> { + Drawable drawable = imageReceiver1.getDrawable(); + if (drawable instanceof RLottieDrawable) { + ((RLottieDrawable) drawable).setCustomEndFrame(0); + ((RLottieDrawable) drawable).stop(); + ((RLottieDrawable) drawable).setProgress(0, false); } - }; + }); } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertBotWebViewLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertBotWebViewLayout.java index dfe6a65d8..a8a63dc39 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertBotWebViewLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertBotWebViewLayout.java @@ -28,6 +28,7 @@ import androidx.recyclerview.widget.ChatListItemAnimator; import org.json.JSONObject; import org.telegram.messenger.AndroidUtilities; import org.telegram.messenger.FileLog; +import org.telegram.messenger.GenericProvider; import org.telegram.messenger.LocaleController; import org.telegram.messenger.MediaDataController; import org.telegram.messenger.MessagesController; @@ -164,6 +165,7 @@ public class ChatAttachAlertBotWebViewLayout extends ChatAttachAlert.AttachAlert }); swipeContainer.setScrollEndListener(()-> webViewContainer.invalidateViewPortHeight(true)); swipeContainer.setDelegate(() -> parentAlert.dismiss()); + swipeContainer.setIsKeyboardVisible(obj -> parentAlert.sizeNotifierFrameLayout.getKeyboardHeight() >= AndroidUtilities.dp(20)); addView(swipeContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); addView(progressView = new WebProgressView(context, resourcesProvider), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 0, 0, 0, 84)); @@ -542,6 +544,8 @@ public class ChatAttachAlertBotWebViewLayout extends ChatAttachAlert.AttachAlert private int swipeStickyRange; + private GenericProvider isKeyboardVisible = obj -> false; + public WebViewSwipeContainer(@NonNull Context context) { super(context); @@ -574,7 +578,9 @@ public class ChatAttachAlertBotWebViewLayout extends ChatAttachAlert.AttachAlert @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (!isScrolling && !isSwipeDisallowed) { - if (Math.abs(distanceY) >= touchSlop && Math.abs(distanceY) * 1.5f >= Math.abs(distanceX) && (swipeOffsetY != -offsetY + topActionBarOffsetY || webView == null || distanceY < 0 && webView.getScrollY() == 0)) { + if (isKeyboardVisible.provide(null) && swipeOffsetY == -offsetY + topActionBarOffsetY) { + isSwipeDisallowed = true; + } else if (Math.abs(distanceY) >= touchSlop && Math.abs(distanceY) * 1.5f >= Math.abs(distanceX) && (swipeOffsetY != -offsetY + topActionBarOffsetY || webView == null || distanceY < 0 && webView.getScrollY() == 0)) { isScrolling = true; MotionEvent ev = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0); @@ -622,6 +628,10 @@ public class ChatAttachAlertBotWebViewLayout extends ChatAttachAlert.AttachAlert updateStickyRange(); } + public void setIsKeyboardVisible(GenericProvider isKeyboardVisible) { + this.isKeyboardVisible = isKeyboardVisible; + } + @Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); @@ -849,7 +859,7 @@ public class ChatAttachAlertBotWebViewLayout extends ChatAttachAlert.AttachAlert } } - public final static class WebProgressView extends View { + public static class WebProgressView extends View { private final SimpleFloatPropertyCompat LOAD_PROGRESS_PROPERTY = new SimpleFloatPropertyCompat<>("loadProgress", obj -> obj.loadProgress, WebProgressView::setLoadProgress).setMultiplier(100f); private Paint bluePaint = new Paint(Paint.ANTI_ALIAS_FLAG);