Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Jul 23, 2017
1 parent 5faa453 commit 7fcd94d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public void setAllowedNotificationsDutingAnimation(int notifications[]) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -1826,12 +1827,15 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
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
Expand Down Expand Up @@ -2085,12 +2089,15 @@ else if(user!=null)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand Down Expand Up @@ -234,9 +233,9 @@ public void onResume() {
currentAnimation = null;
}
if (onCloseAnimationEndRunnable != null) {
onCloseAnimationEnd(false);
onCloseAnimationEnd();
} else if (onOpenAnimationEndRunnable != null) {
onOpenAnimationEnd(false);
onOpenAnimationEnd();
}
}
if (!fragmentsStack.isEmpty()) {
Expand Down Expand Up @@ -523,9 +522,9 @@ public void onLowMemory() {
}
}

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;
Expand All @@ -551,7 +550,7 @@ private void onAnimationEndCheck(boolean byCheck, boolean customAnimation) {

public boolean checkTransitionAnimation() {
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 1500) {
onAnimationEndCheck(true, false);
onAnimationEndCheck(true);
}
return transitionAnimationInProgress;
}
Expand Down Expand Up @@ -627,7 +626,7 @@ public void run() {
if (animationProgress < 1) {
startLayoutAnimation(open, false);
} else {
onAnimationEndCheck(false, false);
onAnimationEndCheck(false);
}
}
});
Expand Down Expand Up @@ -730,7 +729,7 @@ public void run() {
currentAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
onAnimationEndCheck(false, true);
onAnimationEndCheck(false);
}
});
currentAnimation.start();
Expand All @@ -750,7 +749,7 @@ public void run() {
AnimatorSet animation = fragment.onCustomTransitionAnimation(true, new Runnable() {
@Override
public void run() {
onAnimationEndCheck(false, true);
onAnimationEndCheck(false);
}
});
if (animation == null) {
Expand Down Expand Up @@ -921,7 +920,7 @@ public void run() {
AnimatorSet animation = currentFragment.onCustomTransitionAnimation(false, new Runnable() {
@Override
public void run() {
onAnimationEndCheck(false, true);
onAnimationEndCheck(false);
}
});
if (animation == null) {
Expand Down Expand Up @@ -985,7 +984,7 @@ public void onAnimationStart(Animator animation) {

@Override
public void onAnimationEnd(Animator animation) {
onAnimationEndCheck(false, true);
onAnimationEndCheck(false);
}
});
currentAnimation.start();
Expand Down Expand Up @@ -1113,21 +1112,12 @@ public void onActionModeFinished(Object mode) {
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();
}
}
Expand All @@ -1139,22 +1129,12 @@ private void checkNeedRebuild() {
}
}

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();
}
}
Expand All @@ -1169,9 +1149,9 @@ public void startActivityForResult(final Intent intent, final int requestCode) {
currentAnimation = null;
}
if (onCloseAnimationEndRunnable != null) {
onCloseAnimationEnd(false);
onCloseAnimationEnd();
} else if (onOpenAnimationEndRunnable != null) {
onOpenAnimationEnd(false);
onOpenAnimationEnd();
}
containerView.invalidate();
if (intent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -80,11 +81,7 @@ private void resetPressedLink() {
}

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;
Expand Down Expand Up @@ -174,8 +171,10 @@ public boolean onTouchEvent(MotionEvent event) {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,10 @@ private void askForPermissons() {
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
Expand Down
16 changes: 8 additions & 8 deletions TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2212,10 +2212,10 @@ private void updateRowsIds() {
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++;
}
Expand All @@ -2228,7 +2228,9 @@ private void updateRowsIds() {
if (hasUsername) {
usernameRow = rowCount++;
}
sectionRow = rowCount++;
if (phoneRow != -1 || userInfoRow != -1 || userInfoDetailedRow != -1 || usernameRow != -1) {
sectionRow = rowCount++;
}
if (user_id != UserConfig.getClientUserId()) {
settingsNotificationsRow = rowCount++;
}
Expand Down Expand Up @@ -2721,7 +2723,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
} 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 = "-";
Expand All @@ -2741,9 +2743,8 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
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:
Expand Down Expand Up @@ -2903,8 +2904,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
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")) {
Expand Down

0 comments on commit 7fcd94d

Please sign in to comment.