Skip to content

Commit d69b5b3

Browse files
author
DrKLO
committed
Bug fixes
1 parent baed412 commit d69b5b3

15 files changed

+137
-65
lines changed

TMessagesProj/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ android {
8080
defaultConfig {
8181
minSdkVersion 8
8282
targetSdkVersion 21
83-
versionCode 393
84-
versionName "2.0.3"
83+
versionCode 395
84+
versionName "2.0.4"
8585
}
8686
}

TMessagesProj/src/main/java/org/telegram/android/MediaController.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,13 +1542,17 @@ public static void saveFile(String fullPath, Context context, final int type, fi
15421542
if (sourceFile.exists()) {
15431543
ProgressDialog progressDialog = null;
15441544
if (context != null) {
1545-
progressDialog = new ProgressDialog(context);
1546-
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
1547-
progressDialog.setCanceledOnTouchOutside(false);
1548-
progressDialog.setCancelable(false);
1549-
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
1550-
progressDialog.setMax(100);
1551-
progressDialog.show();
1545+
try {
1546+
progressDialog = new ProgressDialog(context);
1547+
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
1548+
progressDialog.setCanceledOnTouchOutside(false);
1549+
progressDialog.setCancelable(false);
1550+
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
1551+
progressDialog.setMax(100);
1552+
progressDialog.show();
1553+
} catch (Exception e) {
1554+
FileLog.e("tmessages", e);
1555+
}
15521556
}
15531557

15541558
final ProgressDialog finalProgress = progressDialog;

TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private void scheduleNotificationRepeat() {
238238
PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
239239
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
240240
int minutes = preferences.getInt("repeat_messages", 60);
241-
if (minutes > 0 || personal_count > 0) {
241+
if (minutes > 0 && personal_count > 0) {
242242
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + minutes * 60 * 1000, pintent);
243243
} else {
244244
alarm.cancel(pintent);

TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import android.os.Build;
1717
import android.provider.MediaStore;
1818
import android.webkit.MimeTypeMap;
19+
import android.widget.Toast;
1920

2021
import org.telegram.messenger.BuffersStorage;
2122
import org.telegram.messenger.ByteBufferDesc;
2223
import org.telegram.messenger.ConnectionsManager;
2324
import org.telegram.messenger.FileLoader;
2425
import org.telegram.messenger.FileLog;
2526
import org.telegram.messenger.MessageKeyData;
27+
import org.telegram.messenger.R;
2628
import org.telegram.messenger.RPCRequest;
2729
import org.telegram.messenger.TLObject;
2830
import org.telegram.messenger.TLRPC;
@@ -1856,9 +1858,9 @@ public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
18561858
}
18571859
}
18581860

1859-
private static void prepareSendingDocumentInternal(String path, String originalPath, Uri uri, String mime, final long dialog_id) {
1861+
private static boolean prepareSendingDocumentInternal(String path, String originalPath, Uri uri, String mime, final long dialog_id) {
18601862
if ((path == null || path.length() == 0) && uri == null) {
1861-
return;
1863+
return false;
18621864
}
18631865
MimeTypeMap myMime = MimeTypeMap.getSingleton();
18641866
if (uri != null) {
@@ -1870,10 +1872,13 @@ private static void prepareSendingDocumentInternal(String path, String originalP
18701872
extension = "txt";
18711873
}
18721874
path = MediaController.copyDocumentToCache(uri, extension);
1875+
if (path == null) {
1876+
return false;
1877+
}
18731878
}
18741879
final File f = new File(path);
18751880
if (!f.exists() || f.length() == 0) {
1876-
return;
1881+
return false;
18771882
}
18781883

18791884
boolean isEncrypted = (int)dialog_id == 0;
@@ -1938,6 +1943,7 @@ public void run() {
19381943
SendMessagesHelper.getInstance().sendMessage(documentFinal, originalPathFinal, pathFinal, dialog_id);
19391944
}
19401945
});
1946+
return true;
19411947
}
19421948

19431949
public static void prepareSendingDocument(String path, String originalPath, Uri uri, String mine, long dialog_id) {
@@ -1962,16 +1968,34 @@ public static void prepareSendingDocuments(final ArrayList<String> paths, final
19621968
new Thread(new Runnable() {
19631969
@Override
19641970
public void run() {
1971+
boolean error = false;
19651972
if (paths != null) {
19661973
for (int a = 0; a < paths.size(); a++) {
1967-
prepareSendingDocumentInternal(paths.get(a), originalPaths.get(a), null, mime, dialog_id);
1974+
if (!prepareSendingDocumentInternal(paths.get(a), originalPaths.get(a), null, mime, dialog_id)) {
1975+
error = true;
1976+
}
19681977
}
19691978
}
19701979
if (uris != null) {
19711980
for (int a = 0; a < uris.size(); a++) {
1972-
prepareSendingDocumentInternal(null, null, uris.get(a), mime, dialog_id);
1981+
if (!prepareSendingDocumentInternal(null, null, uris.get(a), mime, dialog_id)) {
1982+
error = true;
1983+
}
19731984
}
19741985
}
1986+
if (error) {
1987+
AndroidUtilities.runOnUIThread(new Runnable() {
1988+
@Override
1989+
public void run() {
1990+
try {
1991+
Toast toast = Toast.makeText(ApplicationLoader.applicationContext, LocaleController.getString("UnsupportedAttachment", R.string.UnsupportedAttachment), Toast.LENGTH_SHORT);
1992+
toast.show();
1993+
} catch (Exception e) {
1994+
FileLog.e("tmessages", e);
1995+
}
1996+
}
1997+
});
1998+
}
19751999
}
19762000
}).start();
19772001
}

TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ public boolean presentFragment(final BaseFragment fragment, final boolean remove
567567
containerViewBack.addView(fragment.actionBar);
568568
fragment.actionBar.setTitleOverlayText(titleOverlayText);
569569
}
570+
570571
containerViewBack.addView(fragmentView);
571572
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
572573
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
@@ -623,6 +624,7 @@ public void onAnimationEnd(Object animation) {
623624
public void run() {
624625
presentFragmentInternalRemoveOld(removeLast, currentFragment);
625626
fragment.onOpenAnimationEnd();
627+
ViewProxy.setTranslationX(containerView, 0);
626628
}
627629
};
628630
currentAnimation = new AnimatorSetProxy();

TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import android.widget.LinearLayout;
1919
import android.widget.PopupWindow;
2020

21+
import org.telegram.messenger.FileLog;
22+
2123
import java.lang.reflect.Field;
2224

2325
public class ActionBarPopupWindow extends PopupWindow {
@@ -157,8 +159,12 @@ private void registerListener(View anchor) {
157159

158160
@Override
159161
public void showAsDropDown(View anchor, int xoff, int yoff) {
160-
super.showAsDropDown(anchor, xoff, yoff);
161-
registerListener(anchor);
162+
try {
163+
super.showAsDropDown(anchor, xoff, yoff);
164+
registerListener(anchor);
165+
} catch (Exception e) {
166+
FileLog.e("tmessages", e);
167+
}
162168
}
163169

164170
@Override

TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ public View getView(int i, View view, ViewGroup viewGroup) {
290290
view = new UserCell(mContext, 1);
291291
}
292292
TLRPC.User user = MessagesController.getInstance().getUser(MessagesController.getInstance().blockedUsers.get(i));
293-
((UserCell)view).setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown), 0);
293+
if (user != null) {
294+
((UserCell) view).setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown), 0);
295+
}
294296
} else if (type == 1) {
295297
if (view == null) {
296298
view = new TextInfoCell(mContext);

TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ public void buildLayout() {
458458
}
459459
}
460460

461+
nameWidth = Math.max(AndroidUtilities.dp(12), nameWidth);
461462
CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace("\n", " "), currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
462463
try {
463464
nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
@@ -510,9 +511,13 @@ public void buildLayout() {
510511
}
511512
messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(17));
512513
}
513-
514+
messageWidth = Math.max(AndroidUtilities.dp(12), messageWidth);
514515
CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
515-
messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
516+
try {
517+
messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
518+
} catch (Exception e) {
519+
FileLog.e("tmessages", e);
520+
}
516521

517522
double widthpx = 0;
518523
float left = 0;
@@ -526,7 +531,7 @@ public void buildLayout() {
526531
}
527532
}
528533
}
529-
if (messageLayout.getLineCount() > 0) {
534+
if (messageLayout != null && messageLayout.getLineCount() > 0) {
530535
left = messageLayout.getLineLeft(0);
531536
if (left == 0) {
532537
widthpx = Math.ceil(messageLayout.getLineWidth(0));
@@ -545,7 +550,7 @@ public void buildLayout() {
545550
}
546551
}
547552
}
548-
if (messageLayout.getLineCount() > 0) {
553+
if (messageLayout != null && messageLayout.getLineCount() > 0) {
549554
left = messageLayout.getLineRight(0);
550555
if (left == messageWidth) {
551556
widthpx = Math.ceil(messageLayout.getLineWidth(0));
@@ -677,10 +682,12 @@ protected void onDraw(Canvas canvas) {
677682
timeLayout.draw(canvas);
678683
canvas.restore();
679684

680-
canvas.save();
681-
canvas.translate(messageLeft, messageTop);
682-
messageLayout.draw(canvas);
683-
canvas.restore();
685+
if (messageLayout != null) {
686+
canvas.save();
687+
canvas.translate(messageLeft, messageTop);
688+
messageLayout.draw(canvas);
689+
canvas.restore();
690+
}
684691

685692
if (drawClock) {
686693
setDrawableBounds(clockDrawable, checkDrawLeft, checkDrawTop);

TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ private void handleIntent(Intent intent, boolean isNew, boolean restore) {
386386
if (Intent.ACTION_SEND.equals(intent.getAction())) {
387387
boolean error = false;
388388
String type = intent.getType();
389-
if (type != null && type.equals("text/plain")) {
389+
if (type != null && type.equals("text/plain") && intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
390390
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
391391
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
392392

@@ -950,6 +950,9 @@ public void onConfigurationChanged(android.content.res.Configuration newConfig)
950950
@SuppressWarnings("unchecked")
951951
public void didReceivedNotification(int id, Object... args) {
952952
if (id == NotificationCenter.appDidLogout) {
953+
if (drawerLayoutAdapter != null) {
954+
drawerLayoutAdapter.notifyDataSetChanged();
955+
}
953956
for (BaseFragment fragment : actionBarLayout.fragmentsStack) {
954957
fragment.onFragmentDestroy();
955958
}

TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -778,23 +778,27 @@ public void selectCountry(String name) {
778778

779779
private void updatePhoneField() {
780780
ignoreOnPhoneChange = true;
781-
String codeText = codeField.getText().toString();
782-
String phone = PhoneFormat.getInstance().format("+" + codeText + phoneField.getText().toString());
783-
int idx = phone.indexOf(" ");
784-
if (idx != -1) {
785-
String resultCode = PhoneFormat.stripExceptNumbers(phone.substring(0, idx));
786-
if (!codeText.equals(resultCode)) {
787-
phone = PhoneFormat.getInstance().format(phoneField.getText().toString()).trim();
788-
phoneField.setText(phone);
789-
int len = phoneField.length();
790-
phoneField.setSelection(phoneField.length());
781+
try {
782+
String codeText = codeField.getText().toString();
783+
String phone = PhoneFormat.getInstance().format("+" + codeText + phoneField.getText().toString());
784+
int idx = phone.indexOf(" ");
785+
if (idx != -1) {
786+
String resultCode = PhoneFormat.stripExceptNumbers(phone.substring(0, idx));
787+
if (!codeText.equals(resultCode)) {
788+
phone = PhoneFormat.getInstance().format(phoneField.getText().toString()).trim();
789+
phoneField.setText(phone);
790+
int len = phoneField.length();
791+
phoneField.setSelection(phoneField.length());
792+
} else {
793+
phoneField.setText(phone.substring(idx).trim());
794+
int len = phoneField.length();
795+
phoneField.setSelection(phoneField.length());
796+
}
791797
} else {
792-
phoneField.setText(phone.substring(idx).trim());
793-
int len = phoneField.length();
794798
phoneField.setSelection(phoneField.length());
795799
}
796-
} else {
797-
phoneField.setSelection(phoneField.length());
800+
} catch (Exception e) {
801+
FileLog.e("tmessages", e);
798802
}
799803
ignoreOnPhoneChange = false;
800804
}

0 commit comments

Comments
 (0)