diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index c67ee3ba..24c5e894 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -80,7 +80,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 21 - versionCode 393 - versionName "2.0.3" + versionCode 395 + versionName "2.0.4" } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java index 1bc67365..b87fa176 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java @@ -1542,13 +1542,17 @@ public class MediaController implements NotificationCenter.NotificationCenterDel if (sourceFile.exists()) { ProgressDialog progressDialog = null; if (context != null) { - progressDialog = new ProgressDialog(context); - progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); - progressDialog.setCanceledOnTouchOutside(false); - progressDialog.setCancelable(false); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setMax(100); - progressDialog.show(); + try { + progressDialog = new ProgressDialog(context); + progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); + progressDialog.setCanceledOnTouchOutside(false); + progressDialog.setCancelable(false); + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + progressDialog.setMax(100); + progressDialog.show(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } } final ProgressDialog finalProgress = progressDialog; diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java index 7ad65c2b..e63e291d 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java @@ -238,7 +238,7 @@ public class NotificationsController { PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int minutes = preferences.getInt("repeat_messages", 60); - if (minutes > 0 || personal_count > 0) { + if (minutes > 0 && personal_count > 0) { alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + minutes * 60 * 1000, pintent); } else { alarm.cancel(pintent); diff --git a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java index bdf376f5..8b9f37d8 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java @@ -16,6 +16,7 @@ import android.net.Uri; import android.os.Build; import android.provider.MediaStore; import android.webkit.MimeTypeMap; +import android.widget.Toast; import org.telegram.messenger.BuffersStorage; import org.telegram.messenger.ByteBufferDesc; @@ -23,6 +24,7 @@ import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLog; import org.telegram.messenger.MessageKeyData; +import org.telegram.messenger.R; import org.telegram.messenger.RPCRequest; import org.telegram.messenger.TLObject; import org.telegram.messenger.TLRPC; @@ -1856,9 +1858,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter } } - private static void prepareSendingDocumentInternal(String path, String originalPath, Uri uri, String mime, final long dialog_id) { + private static boolean prepareSendingDocumentInternal(String path, String originalPath, Uri uri, String mime, final long dialog_id) { if ((path == null || path.length() == 0) && uri == null) { - return; + return false; } MimeTypeMap myMime = MimeTypeMap.getSingleton(); if (uri != null) { @@ -1870,10 +1872,13 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter extension = "txt"; } path = MediaController.copyDocumentToCache(uri, extension); + if (path == null) { + return false; + } } final File f = new File(path); if (!f.exists() || f.length() == 0) { - return; + return false; } boolean isEncrypted = (int)dialog_id == 0; @@ -1938,6 +1943,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter SendMessagesHelper.getInstance().sendMessage(documentFinal, originalPathFinal, pathFinal, dialog_id); } }); + return true; } public static void prepareSendingDocument(String path, String originalPath, Uri uri, String mine, long dialog_id) { @@ -1962,16 +1968,34 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter new Thread(new Runnable() { @Override public void run() { + boolean error = false; if (paths != null) { for (int a = 0; a < paths.size(); a++) { - prepareSendingDocumentInternal(paths.get(a), originalPaths.get(a), null, mime, dialog_id); + if (!prepareSendingDocumentInternal(paths.get(a), originalPaths.get(a), null, mime, dialog_id)) { + error = true; + } } } if (uris != null) { for (int a = 0; a < uris.size(); a++) { - prepareSendingDocumentInternal(null, null, uris.get(a), mime, dialog_id); + if (!prepareSendingDocumentInternal(null, null, uris.get(a), mime, dialog_id)) { + error = true; + } } } + if (error) { + AndroidUtilities.runOnUIThread(new Runnable() { + @Override + public void run() { + try { + Toast toast = Toast.makeText(ApplicationLoader.applicationContext, LocaleController.getString("UnsupportedAttachment", R.string.UnsupportedAttachment), Toast.LENGTH_SHORT); + toast.show(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + }); + } } }).start(); } 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 a7875f18..5a9d53fb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java @@ -567,6 +567,7 @@ public class ActionBarLayout extends FrameLayout { containerViewBack.addView(fragment.actionBar); fragment.actionBar.setTitleOverlayText(titleOverlayText); } + containerViewBack.addView(fragmentView); ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams(); layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; @@ -623,6 +624,7 @@ public class ActionBarLayout extends FrameLayout { public void run() { presentFragmentInternalRemoveOld(removeLast, currentFragment); fragment.onOpenAnimationEnd(); + ViewProxy.setTranslationX(containerView, 0); } }; currentAnimation = new AnimatorSetProxy(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java index 5e5a302b..c6f960c0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java @@ -18,6 +18,8 @@ import android.view.ViewTreeObserver; import android.widget.LinearLayout; import android.widget.PopupWindow; +import org.telegram.messenger.FileLog; + import java.lang.reflect.Field; public class ActionBarPopupWindow extends PopupWindow { @@ -157,8 +159,12 @@ public class ActionBarPopupWindow extends PopupWindow { @Override public void showAsDropDown(View anchor, int xoff, int yoff) { - super.showAsDropDown(anchor, xoff, yoff); - registerListener(anchor); + try { + super.showAsDropDown(anchor, xoff, yoff); + registerListener(anchor); + } catch (Exception e) { + FileLog.e("tmessages", e); + } } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java index 6da2759d..0f0eb843 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java @@ -290,7 +290,9 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe view = new UserCell(mContext, 1); } TLRPC.User user = MessagesController.getInstance().getUser(MessagesController.getInstance().blockedUsers.get(i)); - ((UserCell)view).setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown), 0); + if (user != null) { + ((UserCell) view).setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown), 0); + } } else if (type == 1) { if (view == null) { view = new TextInfoCell(mContext); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java index 26bc739b..decbc68e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java @@ -458,6 +458,7 @@ public class DialogCell extends BaseCell { } } + nameWidth = Math.max(AndroidUtilities.dp(12), nameWidth); CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace("\n", " "), currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); try { nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); @@ -510,9 +511,13 @@ public class DialogCell extends BaseCell { } messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(17)); } - + messageWidth = Math.max(AndroidUtilities.dp(12), messageWidth); CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); - messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + try { + messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + } catch (Exception e) { + FileLog.e("tmessages", e); + } double widthpx = 0; float left = 0; @@ -526,7 +531,7 @@ public class DialogCell extends BaseCell { } } } - if (messageLayout.getLineCount() > 0) { + if (messageLayout != null && messageLayout.getLineCount() > 0) { left = messageLayout.getLineLeft(0); if (left == 0) { widthpx = Math.ceil(messageLayout.getLineWidth(0)); @@ -545,7 +550,7 @@ public class DialogCell extends BaseCell { } } } - if (messageLayout.getLineCount() > 0) { + if (messageLayout != null && messageLayout.getLineCount() > 0) { left = messageLayout.getLineRight(0); if (left == messageWidth) { widthpx = Math.ceil(messageLayout.getLineWidth(0)); @@ -677,10 +682,12 @@ public class DialogCell extends BaseCell { timeLayout.draw(canvas); canvas.restore(); - canvas.save(); - canvas.translate(messageLeft, messageTop); - messageLayout.draw(canvas); - canvas.restore(); + if (messageLayout != null) { + canvas.save(); + canvas.translate(messageLeft, messageTop); + messageLayout.draw(canvas); + canvas.restore(); + } if (drawClock) { setDrawableBounds(clockDrawable, checkDrawLeft, checkDrawTop); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index 384ebb61..604f0de2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -386,7 +386,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa if (Intent.ACTION_SEND.equals(intent.getAction())) { boolean error = false; String type = intent.getType(); - if (type != null && type.equals("text/plain")) { + if (type != null && type.equals("text/plain") && intent.getStringExtra(Intent.EXTRA_TEXT) != null) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); @@ -950,6 +950,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa @SuppressWarnings("unchecked") public void didReceivedNotification(int id, Object... args) { if (id == NotificationCenter.appDidLogout) { + if (drawerLayoutAdapter != null) { + drawerLayoutAdapter.notifyDataSetChanged(); + } for (BaseFragment fragment : actionBarLayout.fragmentsStack) { fragment.onFragmentDestroy(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java index 0ed36108..a906231c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java @@ -778,23 +778,27 @@ public class LoginActivity extends BaseFragment { private void updatePhoneField() { ignoreOnPhoneChange = true; - String codeText = codeField.getText().toString(); - String phone = PhoneFormat.getInstance().format("+" + codeText + phoneField.getText().toString()); - int idx = phone.indexOf(" "); - if (idx != -1) { - String resultCode = PhoneFormat.stripExceptNumbers(phone.substring(0, idx)); - if (!codeText.equals(resultCode)) { - phone = PhoneFormat.getInstance().format(phoneField.getText().toString()).trim(); - phoneField.setText(phone); - int len = phoneField.length(); - phoneField.setSelection(phoneField.length()); + try { + String codeText = codeField.getText().toString(); + String phone = PhoneFormat.getInstance().format("+" + codeText + phoneField.getText().toString()); + int idx = phone.indexOf(" "); + if (idx != -1) { + String resultCode = PhoneFormat.stripExceptNumbers(phone.substring(0, idx)); + if (!codeText.equals(resultCode)) { + phone = PhoneFormat.getInstance().format(phoneField.getText().toString()).trim(); + phoneField.setText(phone); + int len = phoneField.length(); + phoneField.setSelection(phoneField.length()); + } else { + phoneField.setText(phone.substring(idx).trim()); + int len = phoneField.length(); + phoneField.setSelection(phoneField.length()); + } } else { - phoneField.setText(phone.substring(idx).trim()); - int len = phoneField.length(); phoneField.setSelection(phoneField.length()); } - } else { - phoneField.setSelection(phoneField.length()); + } catch (Exception e) { + FileLog.e("tmessages", e); } ignoreOnPhoneChange = false; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java index 1ad46ff4..fd10cf9d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java @@ -22,6 +22,7 @@ import android.view.ViewTreeObserver; import android.view.animation.AccelerateDecelerateInterpolator; import android.widget.AbsListView; import android.widget.AdapterView; +import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.EditText; import android.widget.FrameLayout; @@ -32,6 +33,7 @@ import android.widget.TextView; import org.telegram.android.AndroidUtilities; import org.telegram.android.LocaleController; import org.telegram.android.MessageObject; +import org.telegram.messenger.FileLog; import org.telegram.messenger.TLRPC; import org.telegram.android.ContactsController; import org.telegram.android.MessagesController; @@ -537,19 +539,26 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter dialogsSearchAdapter.notifyDataSetChanged(); } if (messagesListView != null) { - if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { - searchEmptyView.setVisibility(View.GONE); - emptyView.setVisibility(View.GONE); - messagesListView.setEmptyView(progressView); - } else { - if (searching && searchWas) { - messagesListView.setEmptyView(searchEmptyView); - emptyView.setVisibility(View.GONE); - } else { - messagesListView.setEmptyView(emptyView); - searchEmptyView.setVisibility(View.GONE); + try { + if (messagesListView.getAdapter() != null && messagesListView.getAdapter() instanceof BaseAdapter) { + ((BaseAdapter) messagesListView.getAdapter()).notifyDataSetChanged(); } - progressView.setVisibility(View.GONE); + if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { + searchEmptyView.setVisibility(View.GONE); + emptyView.setVisibility(View.GONE); + messagesListView.setEmptyView(progressView); + } else { + if (searching && searchWas) { + messagesListView.setEmptyView(searchEmptyView); + emptyView.setVisibility(View.GONE); + } else { + messagesListView.setEmptyView(emptyView); + searchEmptyView.setVisibility(View.GONE); + } + progressView.setVisibility(View.GONE); + } + } catch (Exception e) { + FileLog.e("tmessages", e); //TODO fix it in other way? } } } else if (id == NotificationCenter.emojiDidLoaded) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java index 93b346eb..1376b549 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java @@ -242,12 +242,12 @@ public class PhotoCropActivity extends BaseFragment { } try { return Bitmap.createBitmap(imageToCrop, x, y, size, size); - } catch (Exception e) { + } catch (Throwable e) { FileLog.e("tmessags", e); System.gc(); try { return Bitmap.createBitmap(imageToCrop, x, y, size, size); - } catch (Exception e2) { + } catch (Throwable e2) { FileLog.e("tmessages", e2); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index c581a3bd..e6c74915 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -1579,14 +1579,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat return; } - actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1)); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.userPhotosLoaded); - try { if (windowView.getParent() != null) { WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE); @@ -1596,9 +1588,24 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat FileLog.e("tmessages", e); } - placeProvider = provider; + WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE); - wm.addView(windowView, windowLayoutParams); + try { + wm.addView(windowView, windowLayoutParams); + } catch (Exception e) { + FileLog.e("tmessages", e); + return; + } + + actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1)); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.userPhotosLoaded); + + placeProvider = provider; if (velocityTracker == null) { velocityTracker = VelocityTracker.obtain(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index 87123bba..b7e1bfc6 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -287,10 +287,10 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear().commit(); - NotificationCenter.getInstance().postNotificationName(NotificationCenter.appDidLogout); MessagesController.getInstance().unregistedPush(); MessagesController.getInstance().logOut(); UserConfig.clearConfig(); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.appDidLogout); MessagesStorage.getInstance().cleanUp(false); MessagesController.getInstance().cleanUp(); ContactsController.getInstance().deleteAllAppAccounts(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java index 1dcc1493..ab697708 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java @@ -631,7 +631,11 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.x, View.MeasureSpec.EXACTLY)); } - emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), Gravity.BOTTOM | Gravity.LEFT, 0, 0); + try { + emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), Gravity.BOTTOM | Gravity.LEFT, 0, 0); + } catch (Exception e) { + FileLog.e("tmessages", e); + } if (!keyboardVisible) { if (sizeNotifierRelativeLayout != null) { sizeNotifierRelativeLayout.setPadding(0, 0, 0, currentHeight);