From 7fcd94d5c911e7b7ca9e823d7d603eeb90c418d0 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sun, 23 Jul 2017 20:29:17 +0300 Subject: [PATCH] Bug fixes --- .../org/telegram/messenger/BuildVars.java | 2 +- .../messenger/NotificationCenter.java | 3 +- .../messenger/NotificationsController.java | 31 ++++++---- .../ui/ActionBar/ActionBarLayout.java | 58 ++++++------------- .../org/telegram/ui/Cells/AboutLinkCell.java | 13 ++--- .../java/org/telegram/ui/DialogsActivity.java | 5 +- .../java/org/telegram/ui/ProfileActivity.java | 16 ++--- 7 files changed, 59 insertions(+), 69 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index 58fb9e129..a15c16ce4 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -11,7 +11,7 @@ package org.telegram.messenger; public class BuildVars { public static boolean DEBUG_VERSION = false; public static boolean DEBUG_PRIVATE_VERSION = false; - public static int BUILD_VERSION = 1041; + public static int BUILD_VERSION = 1042; public static String BUILD_VERSION_STRING = "4.2"; public static int APP_ID = 0; //obtain your own APP_ID at https://core.telegram.org/api/obtaining_api_id public static String APP_HASH = ""; //obtain your own APP_HASH at https://core.telegram.org/api/obtaining_api_id diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java index 29168ea1b..be1288cb6 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java @@ -174,7 +174,8 @@ public class NotificationCenter { public void setAnimationInProgress(boolean value) { animationInProgress = value; if (!animationInProgress && !delayedPosts.isEmpty()) { - for (DelayedPost delayedPost : delayedPosts) { + for (int a = 0; a < delayedPosts.size(); a++) { + DelayedPost delayedPost = delayedPosts.get(a); postNotificationNameInternal(delayedPost.id, true, delayedPost.args); } delayedPosts.clear(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java index 9a003bca0..3a95dee61 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java @@ -39,6 +39,7 @@ import org.telegram.tgnet.TLRPC; import org.telegram.ui.LaunchActivity; import org.telegram.ui.PopupNotificationActivity; +import java.io.File; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; @@ -1826,12 +1827,15 @@ public class NotificationsController { mBuilder.setLargeIcon(img.getBitmap()); } else { try { - float scaleFactor = 160.0f / AndroidUtilities.dp(50); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; - Bitmap bitmap = BitmapFactory.decodeFile(FileLoader.getPathToAttach(photoPath, true).toString(), options); - if (bitmap != null) { - mBuilder.setLargeIcon(bitmap); + File file = FileLoader.getPathToAttach(photoPath, true); + if (file.exists()) { + float scaleFactor = 160.0f / AndroidUtilities.dp(50); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; + Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options); + if (bitmap != null) { + mBuilder.setLargeIcon(bitmap); + } } } catch (Throwable e) { //ignore @@ -2085,12 +2089,15 @@ public class NotificationsController { builder.setLargeIcon(img.getBitmap()); } else { try { - float scaleFactor = 160.0f / AndroidUtilities.dp(50); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; - Bitmap bitmap = BitmapFactory.decodeFile(FileLoader.getPathToAttach(photoPath, true).toString(), options); - if (bitmap != null) { - builder.setLargeIcon(bitmap); + File file = FileLoader.getPathToAttach(photoPath, true); + if (file.exists()) { + float scaleFactor = 160.0f / AndroidUtilities.dp(50); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; + Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options); + if (bitmap != null) { + builder.setLargeIcon(bitmap); + } } } catch (Throwable e) { //ignore diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java index c67cf8aea..8e88e033f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java @@ -19,7 +19,6 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.os.Handler; import android.view.Gravity; import android.view.KeyEvent; import android.view.Menu; @@ -234,9 +233,9 @@ public class ActionBarLayout extends FrameLayout { currentAnimation = null; } if (onCloseAnimationEndRunnable != null) { - onCloseAnimationEnd(false); + onCloseAnimationEnd(); } else if (onOpenAnimationEndRunnable != null) { - onOpenAnimationEnd(false); + onOpenAnimationEnd(); } } if (!fragmentsStack.isEmpty()) { @@ -523,9 +522,9 @@ public class ActionBarLayout extends FrameLayout { } } - private void onAnimationEndCheck(boolean byCheck, boolean customAnimation) { - onCloseAnimationEnd(customAnimation); - onOpenAnimationEnd(customAnimation); + private void onAnimationEndCheck(boolean byCheck) { + onCloseAnimationEnd(); + onOpenAnimationEnd(); if (waitingForKeyboardCloseRunnable != null) { AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable); waitingForKeyboardCloseRunnable = null; @@ -551,7 +550,7 @@ public class ActionBarLayout extends FrameLayout { public boolean checkTransitionAnimation() { if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 1500) { - onAnimationEndCheck(true, false); + onAnimationEndCheck(true); } return transitionAnimationInProgress; } @@ -627,7 +626,7 @@ public class ActionBarLayout extends FrameLayout { if (animationProgress < 1) { startLayoutAnimation(open, false); } else { - onAnimationEndCheck(false, false); + onAnimationEndCheck(false); } } }); @@ -730,7 +729,7 @@ public class ActionBarLayout extends FrameLayout { currentAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { - onAnimationEndCheck(false, true); + onAnimationEndCheck(false); } }); currentAnimation.start(); @@ -750,7 +749,7 @@ public class ActionBarLayout extends FrameLayout { AnimatorSet animation = fragment.onCustomTransitionAnimation(true, new Runnable() { @Override public void run() { - onAnimationEndCheck(false, true); + onAnimationEndCheck(false); } }); if (animation == null) { @@ -921,7 +920,7 @@ public class ActionBarLayout extends FrameLayout { AnimatorSet animation = currentFragment.onCustomTransitionAnimation(false, new Runnable() { @Override public void run() { - onAnimationEndCheck(false, true); + onAnimationEndCheck(false); } }); if (animation == null) { @@ -985,7 +984,7 @@ public class ActionBarLayout extends FrameLayout { @Override public void onAnimationEnd(Animator animation) { - onAnimationEndCheck(false, true); + onAnimationEndCheck(false); } }); currentAnimation.start(); @@ -1113,21 +1112,12 @@ public class ActionBarLayout extends FrameLayout { inActionMode = false; } - private void onCloseAnimationEnd(boolean post) { + private void onCloseAnimationEnd() { if (transitionAnimationInProgress && onCloseAnimationEndRunnable != null) { transitionAnimationInProgress = false; transitionAnimationStartTime = 0; - if (post) { - new Handler().post(new Runnable() { - public void run() { - onCloseAnimationEndRunnable.run(); - onCloseAnimationEndRunnable = null; - } - }); - } else { - onCloseAnimationEndRunnable.run(); - onCloseAnimationEndRunnable = null; - } + onCloseAnimationEndRunnable.run(); + onCloseAnimationEndRunnable = null; checkNeedRebuild(); } } @@ -1139,22 +1129,12 @@ public class ActionBarLayout extends FrameLayout { } } - private void onOpenAnimationEnd(boolean post) { + private void onOpenAnimationEnd() { if (transitionAnimationInProgress && onOpenAnimationEndRunnable != null) { transitionAnimationInProgress = false; transitionAnimationStartTime = 0; - if (post) { - AndroidUtilities.runOnUIThread(new Runnable() { - @Override - public void run() { - onOpenAnimationEndRunnable.run(); - onOpenAnimationEndRunnable = null; - } - }); - } else { - onOpenAnimationEndRunnable.run(); - onOpenAnimationEndRunnable = null; - } + onOpenAnimationEndRunnable.run(); + onOpenAnimationEndRunnable = null; checkNeedRebuild(); } } @@ -1169,9 +1149,9 @@ public class ActionBarLayout extends FrameLayout { currentAnimation = null; } if (onCloseAnimationEndRunnable != null) { - onCloseAnimationEnd(false); + onCloseAnimationEnd(); } else if (onOpenAnimationEndRunnable != null) { - onOpenAnimationEnd(false); + onOpenAnimationEnd(); } containerView.invalidate(); if (intent != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java index 3d7735b9d..7baf9813d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java @@ -17,6 +17,7 @@ import android.text.Layout; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.StaticLayout; +import android.text.TextUtils; import android.text.style.ClickableSpan; import android.text.style.URLSpan; import android.view.Gravity; @@ -80,11 +81,7 @@ public class AboutLinkCell extends FrameLayout { } public void setTextAndIcon(String text, int resId, boolean parseLinks) { - if (text == null || text.length() == 0) { - setVisibility(GONE); - return; - } - if (text != null && oldText != null && text.equals(oldText)) { + if (TextUtils.isEmpty(text) || text != null && oldText != null && text.equals(oldText)) { return; } oldText = text; @@ -174,8 +171,10 @@ public class AboutLinkCell extends FrameLayout { @SuppressLint("DrawAllocation") @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - textLayout = new StaticLayout(stringBuilder, Theme.profile_aboutTextPaint, MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(71 + 16), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); - super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(textLayout.getHeight() + AndroidUtilities.dp(16), MeasureSpec.EXACTLY)); + if (stringBuilder != null) { + textLayout = new StaticLayout(stringBuilder, Theme.profile_aboutTextPaint, MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(71 + 16), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + } + super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((textLayout != null ? textLayout.getHeight() : AndroidUtilities.dp(20)) + AndroidUtilities.dp(16), MeasureSpec.EXACTLY)); } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index fe76e7eb1..145b9b053 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -947,7 +947,10 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } String[] items = permissons.toArray(new String[permissons.size()]); - activity.requestPermissions(items, 1); + try { + activity.requestPermissions(items, 1); + } catch (Exception ignore) { + } } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index bdbd54feb..923f88557 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -2212,10 +2212,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if ((user == null || !user.bot) && !TextUtils.isEmpty(user.phone)) { phoneRow = rowCount++; } + TLRPC.TL_userFull userFull = MessagesController.getInstance().getUserFull(user.id); - String about = userFull != null ? userFull.about : null; boolean hasUsername = user != null && !TextUtils.isEmpty(user.username); - if (about != null) { + if (userFull != null && !TextUtils.isEmpty(userFull.about)) { if (phoneRow != -1) { userSectionRow = rowCount++; } @@ -2228,7 +2228,9 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (hasUsername) { usernameRow = rowCount++; } - sectionRow = rowCount++; + if (phoneRow != -1 || userInfoRow != -1 || userInfoDetailedRow != -1 || usernameRow != -1) { + sectionRow = rowCount++; + } if (user_id != UserConfig.getClientUserId()) { settingsNotificationsRow = rowCount++; } @@ -2721,7 +2723,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } else if (i == usernameRow) { String text; final TLRPC.User user = MessagesController.getInstance().getUser(user_id); - if (user != null && user.username != null && user.username.length() != 0) { + if (user != null && !TextUtils.isEmpty(user.username)) { text = "@" + user.username; } else { text = "-"; @@ -2741,9 +2743,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. textDetailCell.setTextAndValue(text, MessagesController.getInstance().linkPrefix + "/" + currentChat.username); } else if (i == userInfoDetailedRow) { TLRPC.TL_userFull userFull = MessagesController.getInstance().getUserFull(user_id); - String about = userFull != null ? userFull.about : null; textDetailCell.setMultiline(true); - textDetailCell.setTextAndValueAndIcon(about, LocaleController.getString("UserBio", R.string.UserBio), R.drawable.profile_info, 11); + textDetailCell.setTextAndValueAndIcon(userFull != null ? userFull.about : null, LocaleController.getString("UserBio", R.string.UserBio), R.drawable.profile_info, 11); } break; case 3: @@ -2903,8 +2904,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. AboutLinkCell aboutLinkCell = (AboutLinkCell) holder.itemView; if (i == userInfoRow) { TLRPC.TL_userFull userFull = MessagesController.getInstance().getUserFull(user_id); - String about = userFull != null ? userFull.about : null; - aboutLinkCell.setTextAndIcon(about, R.drawable.profile_info, false); + aboutLinkCell.setTextAndIcon(userFull != null ? userFull.about : null, R.drawable.profile_info, false); } else if (i == channelInfoRow) { String text = info.about; while (text.contains("\n\n\n")) {