Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 14:04:28 +01:00
parent 81b91f4139
commit f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions

View file

View file

@ -0,0 +1,303 @@
package org.telegram.messenger;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.text.TextUtils;
import android.util.Pair;
import org.json.JSONObject;
import org.telegram.ui.Components.Text;
import org.telegram.ui.LaunchActivity;
import org.telegram.ui.Stories.recorder.StoryEntry;
import org.telegram.ui.web.HttpGetFileTask;
import org.telegram.ui.web.HttpGetTask;
import java.io.File;
public class BetaUpdaterController {
private static BetaUpdaterController instance;
public static BetaUpdaterController getInstance() {
if (instance == null) {
instance = new BetaUpdaterController();
}
return instance;
}
private String version;
private int versionCode;
private String changelog;
private String path;
private long lastCheck;
private String fileUrl;
public BetaUpdaterController() {
load();
}
private SharedPreferences getSharedPreferences() {
return ApplicationLoader.applicationContext.getSharedPreferences("beta", Activity.MODE_PRIVATE);
}
private void load() {
final SharedPreferences prefs = getSharedPreferences();
version = prefs.getString("version", null);
versionCode = prefs.getInt("versionCode", 0);
changelog = prefs.getString("changelog", null);
path = prefs.getString("path", null);
lastCheck = prefs.getLong("lastCheck", 0L);
if (getCurrentVersionCode() >= versionCode || !TextUtils.isEmpty(path) && !new File(path).exists()) {
version = null;
versionCode = 0;
path = null;
changelog = null;
lastCheck = 0;
save();
}
}
private void save() {
final SharedPreferences.Editor e = getSharedPreferences().edit();
if (TextUtils.isEmpty(version)) {
e.remove("version");
} else {
e.putString("version", version);
}
if (TextUtils.isEmpty(changelog)) {
e.remove("changelog");
} else {
e.putString("changelog", changelog);
}
if (versionCode == 0) {
e.remove("versionCode");
} else {
e.putInt("versionCode", versionCode);
}
if (TextUtils.isEmpty(path)) {
e.remove("path");
} else {
e.putString("path", path);
}
if (lastCheck == 0) {
e.remove("lastCheck");
} else {
e.putLong("lastCheck", lastCheck);
}
e.apply();
}
private final static long CHECK_INTERVAL_PAUSED = 1000 * 60 * 60 * 24; // 1 day
private final static long CHECK_INTERVAL = 1000 * 60 * 20; // 20 minutes
private final static long CHECK_INTERVAL_PRIVATE = 1000 * 60 * 4; // 5 minutes
private boolean firstCheck = true;
private boolean checkingForUpdate;
private final Runnable scheduledUpdateCheck = () -> checkForUpdate(false, null);
public void checkForUpdate(boolean force, Runnable whenDone) {
if (checkingForUpdate) return;
if (firstCheck) {
force = true;
}
if (!force && System.currentTimeMillis() - lastCheck < (ApplicationLoader.mainInterfacePaused ? CHECK_INTERVAL_PAUSED : (BuildVars.DEBUG_PRIVATE_VERSION ? CHECK_INTERVAL_PRIVATE : CHECK_INTERVAL))) {
if (whenDone != null) {
whenDone.run();
}
return;
}
final String url = org.telegram.messenger.BuildConfig.BETA_URL;
checkingForUpdate = true;
firstCheck = false;
new HttpGetTask(str -> AndroidUtilities.runOnUIThread(() -> {
checkingForUpdate = false;
try {
final JSONObject json = new JSONObject(str);
final String newVersion = json.getString("version");
final int newVersionCode = json.getInt("version_code");
final String fileUrl = json.getString("file_url");
final String changelog = json.optString("changelog", null);
final int oldVersionCode = this.versionCode;
if (
(version == null || SharedConfig.versionBiggerOrEqual(newVersion, version) && newVersionCode > versionCode) &&
SharedConfig.versionBiggerOrEqual(newVersion, getCurrentVersion()) && newVersionCode > getCurrentVersionCode()
) { // received newer version
if (!TextUtils.isEmpty(path)) {
final File file = new File(path);
try {
file.delete();
} catch (Exception e) {
FileLog.e(e);
}
}
path = null;
version = newVersion;
versionCode = newVersionCode;
this.fileUrl = fileUrl;
this.changelog = changelog;
} else if (
version != null && versionCode != 0 && SharedConfig.versionBiggerOrEqual(version, newVersion) && versionCode == newVersionCode
) { // received the same version
this.fileUrl = fileUrl;
this.changelog = changelog;
} else { // received lower version: remove update
if (!TextUtils.isEmpty(path)) {
final File file = new File(path);
try {
file.delete();
} catch (Exception e) {
FileLog.e(e);
}
}
path = null;
if (SharedConfig.versionBiggerOrEqual(getCurrentVersion(), newVersion) && getCurrentVersionCode() < newVersionCode) {
// remote version is still newer than current installed, even though local downloaded was higher
version = newVersion;
versionCode = newVersionCode;
this.fileUrl = fileUrl;
this.changelog = changelog;
} else {
// remove version is the same or less than current installed
version = null;
versionCode = 0;
this.fileUrl = null;
this.changelog = null;
}
}
this.lastCheck = System.currentTimeMillis();
save();
if (this.versionCode != oldVersionCode) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.appUpdateAvailable);
}
AndroidUtilities.cancelRunOnUIThread(this.scheduledUpdateCheck);
AndroidUtilities.runOnUIThread(this.scheduledUpdateCheck, BuildVars.DEBUG_PRIVATE_VERSION ? CHECK_INTERVAL_PRIVATE : CHECK_INTERVAL);
if (whenDone != null) {
whenDone.run();
} else if (this.versionCode != oldVersionCode && !ApplicationLoader.mainInterfacePaused) {
final Context context = LaunchActivity.instance != null ? LaunchActivity.instance : ApplicationLoader.applicationContext;
final BetaUpdate pendingUpdate = getUpdate();
if (context != null && pendingUpdate != null) {
ApplicationLoader.applicationLoaderInstance.showCustomUpdateAppPopup(context, pendingUpdate, UserConfig.selectedAccount);
}
}
} catch (Exception e) {
FileLog.e("Failed to check for beta update at " + url + " received: " + str, e);
}
})).execute(url);
}
public BetaUpdate getUpdate() {
if (version == null || versionCode == 0) {
return null;
}
return new BetaUpdate(version, versionCode, changelog);
}
private boolean downloading;
private float downloadingProgress;
private HttpGetFileTask downloadingTask;
public void downloadUpdate() {
downloadUpdate(false);
}
private void downloadUpdate(boolean triedGettingFileUrl) {
if (downloading || !TextUtils.isEmpty(path)) return;
downloading = true;
downloadingProgress = 0.0f;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.appUpdateLoading);
if (TextUtils.isEmpty(fileUrl)) {
if (!triedGettingFileUrl) {
checkForUpdate(true, () -> downloadUpdate(true));
} else {
downloading = false;
}
return;
}
downloadingTask = new HttpGetFileTask(
downloadedFile -> AndroidUtilities.runOnUIThread(() -> {
if (downloadedFile != null) {
if (!TextUtils.isEmpty(path)) {
final File file = new File(path);
try {
file.delete();
} catch (Exception e) {
FileLog.e(e);
}
}
path = downloadedFile.getAbsolutePath();
save();
downloadingProgress = 1.0f;
downloading = false;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.appUpdateAvailable);
} else {
downloading = false;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.appUpdateAvailable);
}
}),
progress -> {
downloadingProgress = progress;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.appUpdateLoading);
}
).setOverrideExtension("apk");
downloadingTask.execute(fileUrl);
}
public void cancelDownloadingUpdate() {
if (!downloading) return;
if (downloadingTask != null) {
downloadingTask.cancel(false);
}
downloading = false;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.appUpdateAvailable);
}
public boolean isDownloading() {
return downloading;
}
public float getDownloadingProgress() {
return downloadingProgress;
}
public File getDownloadedFile() {
if (path == null)
return null;
final File file = new File(path);
if (!file.exists()) {
path = null;
save();
return null;
}
return file;
}
private String getCurrentVersion() {
try {
return ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0).versionName;
} catch (Exception e) {
FileLog.e(e);
return "";
}
}
private int getCurrentVersionCode() {
try {
return ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0).versionCode;
} catch (Exception e) {
FileLog.e(e);
return 0;
}
}
}

View file

@ -0,0 +1,376 @@
package org.telegram.ui.Components;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Pair;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.widget.NestedScrollView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BetaUpdate;
import org.telegram.messenger.DocumentObject;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.ImageLocation;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessageObject;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.SvgHelper;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.BottomSheet;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Stories.recorder.ButtonWithCounterView;
import java.io.File;
public class UpdateAppAlertDialog extends BottomSheet {
private BetaUpdate appUpdate;
private int accountNum;
private RadialProgress radialProgress;
private FrameLayout radialProgressView;
private AnimatorSet progressAnimation;
private Drawable shadowDrawable;
private TextView textView;
private TextView messageTextView;
private NestedScrollView scrollView;
private AnimatorSet shadowAnimation;
private View shadow;
private boolean ignoreLayout;
private LinearLayout linearLayout;
private int scrollOffsetY;
private int[] location = new int[2];
private boolean animationInProgress;
public class BottomSheetCell extends FrameLayout {
private View background;
private TextView[] textView = new TextView[2];
private boolean hasBackground;
public BottomSheetCell(Context context, boolean withoutBackground) {
super(context);
hasBackground = !withoutBackground;
setBackground(null);
background = new View(context);
if (hasBackground) {
background.setBackground(Theme.AdaptiveRipple.filledRectByKey(Theme.key_featuredStickers_addButton, 4));
}
addView(background, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 16, withoutBackground ? 0 : 16, 16, 16));
for (int a = 0; a < 2; a++) {
textView[a] = new TextView(context);
textView[a].setLines(1);
textView[a].setSingleLine(true);
textView[a].setGravity(Gravity.CENTER_HORIZONTAL);
textView[a].setEllipsize(TextUtils.TruncateAt.END);
textView[a].setGravity(Gravity.CENTER);
if (hasBackground) {
textView[a].setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
textView[a].setTypeface(AndroidUtilities.bold());
} else {
textView[a].setTextColor(Theme.getColor(Theme.key_featuredStickers_addButton));
}
textView[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView[a].setPadding(0, 0, 0, hasBackground ? 0 : AndroidUtilities.dp(13));
addView(textView[a], LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
if (a == 1) {
textView[a].setAlpha(0.0f);
}
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(hasBackground ? 80 : 50), MeasureSpec.EXACTLY));
}
public void setText(CharSequence text, boolean animated) {
if (!animated) {
textView[0].setText(text);
} else {
textView[1].setText(text);
animationInProgress = true;
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(180);
animatorSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
animatorSet.playTogether(
ObjectAnimator.ofFloat(textView[0], View.ALPHA, 1.0f, 0.0f),
ObjectAnimator.ofFloat(textView[0], View.TRANSLATION_Y, 0, -AndroidUtilities.dp(10)),
ObjectAnimator.ofFloat(textView[1], View.ALPHA, 0.0f, 1.0f),
ObjectAnimator.ofFloat(textView[1], View.TRANSLATION_Y, AndroidUtilities.dp(10), 0)
);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
animationInProgress = false;
TextView temp = textView[0];
textView[0] = textView[1];
textView[1] = temp;
}
});
animatorSet.start();
}
}
}
public UpdateAppAlertDialog(Context context, BetaUpdate update, int account) {
super(context, false);
appUpdate = update;
accountNum = account;
setCanceledOnTouchOutside(false);
setApplyTopPadding(false);
setApplyBottomPadding(false);
shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow_round).mutate();
shadowDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogBackground), PorterDuff.Mode.MULTIPLY));
FrameLayout container = new FrameLayout(context) {
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
updateLayout();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) {
dismiss();
return true;
}
return super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
return !isDismissed() && super.onTouchEvent(e);
}
@Override
protected void onDraw(Canvas canvas) {
int top = (int) (scrollOffsetY - backgroundPaddingTop - getTranslationY());
shadowDrawable.setBounds(0, top, getMeasuredWidth(), getMeasuredHeight());
shadowDrawable.draw(canvas);
}
};
container.setWillNotDraw(false);
containerView = container;
scrollView = new NestedScrollView(context) {
private boolean ignoreLayout;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = MeasureSpec.getSize(heightMeasureSpec);
measureChildWithMargins(linearLayout, widthMeasureSpec, 0, heightMeasureSpec, 0);
int contentHeight = linearLayout.getMeasuredHeight();
int padding = (height / 5 * 2);
int visiblePart = height - padding;
if (contentHeight - visiblePart < AndroidUtilities.dp(90) || contentHeight < height / 2 + AndroidUtilities.dp(90)) {
padding = height - contentHeight;
}
if (padding < 0) {
padding = 0;
}
if (getPaddingTop() != padding) {
ignoreLayout = true;
setPadding(0, padding, 0, 0);
ignoreLayout = false;
}
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
updateLayout();
}
@Override
public void requestLayout() {
if (ignoreLayout) {
return;
}
super.requestLayout();
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
updateLayout();
}
};
scrollView.setFillViewport(true);
scrollView.setWillNotDraw(false);
scrollView.setClipToPadding(false);
scrollView.setVerticalScrollBarEnabled(false);
container.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 130));
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
// if (appUpdate.sticker != null) {
// BackupImageView imageView = new BackupImageView(context);
// SvgHelper.SvgDrawable svgThumb = DocumentObject.getSvgThumb(appUpdate.sticker.thumbs, Theme.key_windowBackgroundGray, 1.0f);
// TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(appUpdate.sticker.thumbs, 90);
// ImageLocation imageLocation = ImageLocation.getForDocument(thumb, appUpdate.sticker);
//
// if (svgThumb != null) {
// imageView.setImage(ImageLocation.getForDocument(appUpdate.sticker), "250_250", svgThumb, 0, "update");
// } else {
// imageView.setImage(ImageLocation.getForDocument(appUpdate.sticker), "250_250", imageLocation, null, 0, "update");
// }
// linearLayout.addView(imageView, LayoutHelper.createLinear(160, 160, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 17, 8, 17, 0));
// }
TextView textView = new TextView(context);
textView.setTypeface(AndroidUtilities.bold());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
textView.setSingleLine(true);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setText(LocaleController.getString(R.string.AppUpdateBeta));
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 23, 16, 23, 0));
TextView messageTextView = new TextView(getContext());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextGray3));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
messageTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
messageTextView.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
messageTextView.setText(LocaleController.formatString(R.string.AppBetaUpdateVersion, appUpdate.version, appUpdate.versionCode));
messageTextView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 23, 0, 23, 5));
if (!TextUtils.isEmpty(appUpdate.changelog)) {
TextView changelogTextView = new TextView(getContext());
changelogTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
changelogTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
changelogTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
changelogTextView.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
changelogTextView.setText(Emoji.replaceEmoji(appUpdate.changelog, changelogTextView.getPaint().getFontMetricsInt(), false));
NotificationCenter.listenEmojiLoading(changelogTextView);
changelogTextView.setGravity(Gravity.LEFT | Gravity.TOP);
linearLayout.addView(changelogTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 23, 15, 23, 0));
}
FrameLayout.LayoutParams frameLayoutParams = new FrameLayout.LayoutParams(LayoutHelper.MATCH_PARENT, AndroidUtilities.getShadowHeight(), Gravity.BOTTOM | Gravity.LEFT);
frameLayoutParams.bottomMargin = AndroidUtilities.dp(130);
shadow = new View(context);
shadow.setBackgroundColor(Theme.getColor(Theme.key_dialogShadowLine));
shadow.setAlpha(0.0f);
shadow.setTag(1);
container.addView(shadow, frameLayoutParams);
ButtonWithCounterView doneButton = new ButtonWithCounterView(context, null);
final File file = ApplicationLoader.applicationLoaderInstance.getDownloadedUpdateFile();
if (file != null) {
doneButton.setText(LocaleController.formatString(R.string.AppUpdateNow), false);
doneButton.setOnClickListener(v -> {
if (file == null) return;
Activity activity = AndroidUtilities.findActivity(getContext());
if (activity == null) return;
AndroidUtilities.openForView(file, "Telegram.apk", "application/vnd.android.package-archive", activity, null, false);
dismiss();
});
} else {
doneButton.setText(LocaleController.formatString(R.string.AppUpdateDownloadNow), false);
doneButton.setOnClickListener(v -> {
ApplicationLoader.applicationLoaderInstance.downloadUpdate();
dismiss();
});
}
container.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 20, 0, 20, 48 + 4 + 8));
ButtonWithCounterView scheduleButton = new ButtonWithCounterView(context, false, null);
scheduleButton.setText(LocaleController.getString(R.string.AppUpdateRemindMeLater), false);
scheduleButton.setOnClickListener(v -> dismiss());
container.addView(scheduleButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 20, 4, 20, 8));
}
private void runShadowAnimation(final int num, final boolean show) {
if (show && shadow.getTag() != null || !show && shadow.getTag() == null) {
shadow.setTag(show ? null : 1);
if (show) {
shadow.setVisibility(View.VISIBLE);
}
if (shadowAnimation != null) {
shadowAnimation.cancel();
}
shadowAnimation = new AnimatorSet();
shadowAnimation.playTogether(ObjectAnimator.ofFloat(shadow, View.ALPHA, show ? 1.0f : 0.0f));
shadowAnimation.setDuration(150);
shadowAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (shadowAnimation != null && shadowAnimation.equals(animation)) {
if (!show) {
shadow.setVisibility(View.INVISIBLE);
}
shadowAnimation = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (shadowAnimation != null && shadowAnimation.equals(animation)) {
shadowAnimation = null;
}
}
});
shadowAnimation.start();
}
}
private void updateLayout() {
View child = linearLayout.getChildAt(0);
child.getLocationInWindow(location);
int top = location[1] - AndroidUtilities.dp(24);
int newOffset = Math.max(top, 0);
if (location[1] + linearLayout.getMeasuredHeight() <= container.getMeasuredHeight() - AndroidUtilities.dp(113) + containerView.getTranslationY()) {
runShadowAnimation(0, false);
} else {
runShadowAnimation(0, true);
}
if (scrollOffsetY != newOffset) {
scrollOffsetY = newOffset;
scrollView.invalidate();
}
}
@Override
protected boolean canDismissWithSwipe() {
return false;
}
}

View file

@ -0,0 +1,180 @@
package org.telegram.ui.Components;
import static org.telegram.messenger.AndroidUtilities.dp;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Shader;
import android.os.Build;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Keep;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.IUpdateButton;
import java.io.File;
public class UpdateButton extends IUpdateButton {
private AnimatorSet animator;
private RadialProgress2 icon;
private TextView textView;
@Keep
public UpdateButton(Context context) {
super(context);
setWillNotDraw(false);
setVisibility(View.INVISIBLE);
setTranslationY(dp(48));
if (Build.VERSION.SDK_INT >= 21) {
setBackground(Theme.getSelectorDrawable(0x40ffffff, false));
}
setOnClickListener(v -> {
File file = ApplicationLoader.applicationLoaderInstance.getDownloadedUpdateFile();
if (file == null) return;
Activity activity = AndroidUtilities.findActivity(getContext());
if (activity == null) return;
AndroidUtilities.openForView(file, "Telegram.apk", "application/vnd.android.package-archive", activity, null, false);
});
icon = new RadialProgress2(this);
icon.setColors(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff);
icon.setCircleRadius(dp(11));
icon.setAsMini();
icon.setIcon(MediaActionDrawable.ICON_UPDATE, true, false);
textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
textView.setTypeface(AndroidUtilities.bold());
textView.setText(LocaleController.getString(org.telegram.messenger.R.string.AppUpdateNow).toUpperCase());
textView.setTextColor(0xffffffff);
textView.setPadding(dp(30), 0, 0, 0);
addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 0, 0, 0));
}
private Paint paint = new Paint();
private Matrix matrix = new Matrix();
private LinearGradient updateGradient;
private int lastGradientWidth;
@Override
public void draw(Canvas canvas) {
if (updateGradient != null) {
paint.setColor(0xffffffff);
paint.setShader(updateGradient);
updateGradient.setLocalMatrix(matrix);
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), paint);
icon.setBackgroundGradientDrawable(updateGradient);
icon.draw(canvas);
}
super.draw(canvas);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
if (lastGradientWidth != width) {
updateGradient = new LinearGradient(0, 0, width, 0, new int[]{0xff69BF72, 0xff53B3AD}, new float[]{0.0f, 1.0f}, Shader.TileMode.CLAMP);
lastGradientWidth = width;
}
int x = (getMeasuredWidth() - textView.getMeasuredWidth()) / 2;
icon.setProgressRect(x, dp(13), x + dp(22), dp(13 + 22));
}
private Utilities.Callback<Float> onTranslationUpdate;
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
if (onTranslationUpdate != null) {
onTranslationUpdate.run(translationY);
}
}
@Keep
public void onTranslationUpdate(Utilities.Callback<Float> onTranslationUpdate) {
this.onTranslationUpdate = onTranslationUpdate;
}
@Keep
public void update(boolean animated) {
final boolean show;
if (ApplicationLoader.applicationLoaderInstance.getUpdate() != null) {
show = ApplicationLoader.applicationLoaderInstance.getDownloadedUpdateFile() != null;
} else {
show = false;
}
if (show) {
if (getTag() != null) {
return;
}
if (animator != null) {
animator.cancel();
}
setVisibility(View.VISIBLE);
setTag(1);
if (animated) {
animator = new AnimatorSet();
animator.setDuration(180);
animator.setInterpolator(CubicBezierInterpolator.EASE_OUT);
animator.playTogether(ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0));
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
animator = null;
}
});
animator.start();
} else {
setTranslationY(0);
}
} else {
if (getTag() == null) {
return;
}
setTag(null);
if (animated) {
animator = new AnimatorSet();
animator.setDuration(180);
animator.setInterpolator(CubicBezierInterpolator.EASE_OUT);
animator.playTogether(ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, dp(48)));
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (getTag() == null) {
setVisibility(View.INVISIBLE);
}
animator = null;
}
});
animator.start();
} else {
setTranslationY(dp(48));
setVisibility(View.INVISIBLE);
}
}
}
}

View file

@ -0,0 +1,265 @@
package org.telegram.ui.Components;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Shader;
import android.os.Build;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.ImageLoader;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.SharedConfig;
import org.telegram.ui.ActionBar.SimpleTextView;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.IUpdateLayout;
import java.io.File;
import java.util.ArrayList;
public class UpdateLayout extends IUpdateLayout {
private FrameLayout updateLayout;
private RadialProgress2 updateLayoutIcon;
private SimpleTextView[] updateTextViews;
private TextView updateSizeTextView;
private AnimatorSet updateTextAnimator;
private Activity activity;
private ViewGroup sideMenu;
private ViewGroup sideMenuContainer;
public UpdateLayout(Activity activity, ViewGroup sideMenu, ViewGroup sideMenuContainer) {
super(activity, sideMenu, sideMenuContainer);
this.activity = activity;
this.sideMenu = sideMenu;
this.sideMenuContainer = sideMenuContainer;
}
public void updateFileProgress(Object[] args) {
if (updateLayout == null || updateTextViews == null) return;
if (updateTextViews[0] != null && ApplicationLoader.applicationLoaderInstance.isDownloadingUpdate()) {
final float progress = ApplicationLoader.applicationLoaderInstance.getDownloadingUpdateProgress();
updateLayoutIcon.setProgress(progress, true);
updateTextViews[0].setText(LocaleController.formatString(R.string.AppUpdateDownloading, (int) (progress * 100)));
updateLayout.invalidate();
}
}
public void createUpdateUI(int currentAccount) {
if (sideMenuContainer == null || updateLayout != null) {
return;
}
updateLayout = new FrameLayout(activity) {
private Paint paint = new Paint();
private Matrix matrix = new Matrix();
private LinearGradient updateGradient;
private int lastGradientWidth;
@Override
public void draw(Canvas canvas) {
if (updateGradient != null) {
paint.setColor(0xffffffff);
paint.setShader(updateGradient);
updateGradient.setLocalMatrix(matrix);
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), paint);
updateLayoutIcon.setBackgroundGradientDrawable(updateGradient);
updateLayoutIcon.draw(canvas);
}
super.draw(canvas);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
if (lastGradientWidth != width) {
updateGradient = new LinearGradient(0, 0, width, 0, new int[]{0xff69BF72, 0xff53B3AD}, new float[]{0.0f, 1.0f}, Shader.TileMode.CLAMP);
lastGradientWidth = width;
}
}
};
updateLayout.setWillNotDraw(false);
updateLayout.setVisibility(View.INVISIBLE);
updateLayout.setTranslationY(AndroidUtilities.dp(44));
if (Build.VERSION.SDK_INT >= 21) {
updateLayout.setBackground(Theme.getSelectorDrawable(0x40ffffff, false));
}
sideMenuContainer.addView(updateLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 44, Gravity.LEFT | Gravity.BOTTOM));
updateLayout.setOnClickListener(v -> {
if (updateLayoutIcon.getIcon() == MediaActionDrawable.ICON_DOWNLOAD) {
ApplicationLoader.applicationLoaderInstance.downloadUpdate();
updateAppUpdateViews(currentAccount, true);
} else if (updateLayoutIcon.getIcon() == MediaActionDrawable.ICON_CANCEL) {
ApplicationLoader.applicationLoaderInstance.cancelDownloadingUpdate();
updateAppUpdateViews(currentAccount, true);
} else {
final File file = ApplicationLoader.applicationLoaderInstance.getDownloadedUpdateFile();
if (file != null) {
AndroidUtilities.openForView(file, "Telegram.apk", "application/vnd.android.package-archive", activity, null, false);
}
}
});
updateLayoutIcon = new RadialProgress2(updateLayout);
updateLayoutIcon.setColors(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff);
updateLayoutIcon.setProgressRect(AndroidUtilities.dp(22), AndroidUtilities.dp(11), AndroidUtilities.dp(22 + 22), AndroidUtilities.dp(11 + 22));
updateLayoutIcon.setCircleRadius(AndroidUtilities.dp(11));
updateLayoutIcon.setAsMini();
updateTextViews = new SimpleTextView[2];
for (int i = 0; i < 2; ++i) {
updateTextViews[i] = new SimpleTextView(activity);
updateTextViews[i].setTextSize(15);
updateTextViews[i].setTypeface(AndroidUtilities.bold());
updateTextViews[i].setTextColor(0xffffffff);
updateTextViews[i].setGravity(Gravity.LEFT);
updateLayout.addView(updateTextViews[i], LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 74, 0, 0, 0));
}
updateTextViews[0].setText(LocaleController.getString(R.string.AppUpdateBeta));
updateTextViews[1].setAlpha(0f);
updateTextViews[1].setVisibility(View.GONE);
updateSizeTextView = new TextView(activity);
updateSizeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
updateSizeTextView.setTypeface(AndroidUtilities.bold());
updateSizeTextView.setGravity(Gravity.RIGHT);
updateSizeTextView.setTextColor(0xffffffff);
updateLayout.addView(updateSizeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT, 0, 0, 17, 0));
}
public void updateAppUpdateViews(int currentAccount, boolean animated) {
if (sideMenuContainer == null) {
return;
}
if (ApplicationLoader.applicationLoaderInstance.getUpdate() != null) {
createUpdateUI(currentAccount);
updateSizeTextView.setText("");
File file = ApplicationLoader.applicationLoaderInstance.getDownloadedUpdateFile();
final boolean showSize = false;
if (file != null && file.exists()) {
updateLayoutIcon.setIcon(MediaActionDrawable.ICON_UPDATE, true, animated);
setUpdateText(LocaleController.getString(R.string.AppUpdateNow), animated);
} else if (ApplicationLoader.applicationLoaderInstance.isDownloadingUpdate()) {
updateLayoutIcon.setIcon(MediaActionDrawable.ICON_CANCEL, true, animated);
updateLayoutIcon.setProgress(ApplicationLoader.applicationLoaderInstance.getDownloadingUpdateProgress(), true);
final float progress = ApplicationLoader.applicationLoaderInstance.getDownloadingUpdateProgress();
setUpdateText(LocaleController.formatString(R.string.AppUpdateDownloading, (int) (progress * 100)), animated);
} else {
updateLayoutIcon.setIcon(MediaActionDrawable.ICON_DOWNLOAD, true, animated);
setUpdateText(LocaleController.getString(R.string.AppUpdateBeta), animated);
}
if (showSize) {
if (updateSizeTextView.getTag() != null) {
if (animated) {
updateSizeTextView.setTag(null);
updateSizeTextView.animate().alpha(1.0f).scaleX(1.0f).scaleY(1.0f).setDuration(180).start();
} else {
updateSizeTextView.setAlpha(1.0f);
updateSizeTextView.setScaleX(1.0f);
updateSizeTextView.setScaleY(1.0f);
}
}
} else {
if (updateSizeTextView.getTag() == null) {
if (animated) {
updateSizeTextView.setTag(1);
updateSizeTextView.animate().alpha(0.0f).scaleX(0.0f).scaleY(0.0f).setDuration(180).start();
} else {
updateSizeTextView.setAlpha(0.0f);
updateSizeTextView.setScaleX(0.0f);
updateSizeTextView.setScaleY(0.0f);
}
}
}
if (updateLayout.getTag() != null) {
return;
}
updateLayout.setVisibility(View.VISIBLE);
updateLayout.setTag(1);
if (animated) {
updateLayout.animate().translationY(0).setInterpolator(CubicBezierInterpolator.EASE_OUT).setListener(null).setDuration(180).start();
} else {
updateLayout.setTranslationY(0);
}
} else {
if (updateLayout == null || updateLayout.getTag() == null) {
return;
}
updateLayout.setTag(null);
if (animated) {
updateLayout.animate().translationY(AndroidUtilities.dp(44)).setInterpolator(CubicBezierInterpolator.EASE_OUT).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (updateLayout.getTag() == null) {
updateLayout.setVisibility(View.INVISIBLE);
}
}
}).setDuration(180).start();
} else {
updateLayout.setTranslationY(AndroidUtilities.dp(44));
updateLayout.setVisibility(View.INVISIBLE);
}
}
}
private void setUpdateText(String text, boolean animate) {
if (TextUtils.equals(updateTextViews[0].getText(), text)) {
return;
}
if (updateTextAnimator != null) {
updateTextAnimator.cancel();
updateTextAnimator = null;
}
if (animate) {
updateTextViews[1].setText(updateTextViews[0].getText());
updateTextViews[0].setText(text);
updateTextViews[0].setAlpha(0);
updateTextViews[1].setAlpha(1);
updateTextViews[0].setVisibility(View.VISIBLE);
updateTextViews[1].setVisibility(View.VISIBLE);
ArrayList<Animator> arrayList = new ArrayList<>();
arrayList.add(ObjectAnimator.ofFloat(updateTextViews[1], View.ALPHA, 0));
arrayList.add(ObjectAnimator.ofFloat(updateTextViews[0], View.ALPHA, 1));
updateTextAnimator = new AnimatorSet();
updateTextAnimator.playTogether(arrayList);
updateTextAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (updateTextAnimator == animation) {
updateTextViews[1].setVisibility(View.GONE);
updateTextAnimator = null;
}
}
});
updateTextAnimator.setDuration(320);
updateTextAnimator.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
updateTextAnimator.start();
} else {
updateTextViews[0].setText(text);
updateTextViews[0].setAlpha(1);
updateTextViews[0].setVisibility(View.VISIBLE);
updateTextViews[1].setVisibility(View.GONE);
}
}
}