From 51aa4141a41a811e87b829f587753f0b20158a9b Mon Sep 17 00:00:00 2001 From: DrKLO Date: Thu, 3 Apr 2014 14:23:39 +0400 Subject: [PATCH] Bug fixes --- TMessagesProj/build.gradle | 2 +- .../org/telegram/messenger/AwakeService.java | 2 +- .../messenger/ConnectionsManager.java | 5 +-- .../messenger/ContactsController.java | 14 ++------ .../messenger/GcmBroadcastReceiver.java | 4 +-- .../telegram/messenger/LocaleController.java | 7 +++- .../messenger/MessagesController.java | 20 +++-------- .../org/telegram/messenger/NativeLoader.java | 2 +- .../telegram/messenger/ScreenReceiver.java | 6 ++-- .../org/telegram/objects/PhotoObject.java | 3 ++ .../org/telegram/ui/ApplicationLoader.java | 11 +++++++ .../org/telegram/ui/Cells/ChatMediaCell.java | 5 ++- .../ui/SettingsWallpapersActivity.java | 33 ++++++++++--------- .../org/telegram/ui/UserProfileActivity.java | 4 +-- .../src/main/res/values-de/strings.xml | 4 +-- .../src/main/res/values-es/strings.xml | 4 +-- .../src/main/res/values-it/strings.xml | 4 +-- 17 files changed, 68 insertions(+), 62 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 5083c5c47..2e2c6ce5b 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 217 + versionCode 219 versionName "1.4.9" } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AwakeService.java b/TMessagesProj/src/main/java/org/telegram/messenger/AwakeService.java index ea6e029c5..b6843433b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/AwakeService.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/AwakeService.java @@ -37,7 +37,7 @@ public class AwakeService extends Service { public static void startService() { try { - if (MessagesController.isScreenOn && ApplicationLoader.lastPauseTime == 0) { + if (ApplicationLoader.isScreenOn && ApplicationLoader.lastPauseTime == 0) { return; } timeout = 10000; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java index 5916d036e..17a9df38f 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java @@ -2041,13 +2041,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. if (request.serverFailureCount < 1) { discardResponse = true; request.runningMinStartTime = request.runningStartTime + 1; - request.serverFailureCount++; } } else { discardResponse = true; - request.runningMinStartTime = request.runningStartTime + 1; + int delay = Math.min(1, request.serverFailureCount * 2); + request.runningMinStartTime = request.runningStartTime + delay; request.confirmed = false; } + request.serverFailureCount++; } else if (errorCode == 420) { if ((request.flags & RPCRequest.RPCRequestClassFailOnServerErrors) == 0) { double waitTime = 2.0; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java index 65b334bdf..6efd387f0 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java @@ -323,19 +323,9 @@ public class ContactsController { name = PhoneFormat.getInstance().format(phone); } - String[] args = name.split(" ", 2); - Contact contact = new Contact(); - if (args.length > 0) { - contact.first_name = args[0]; - } else { - contact.first_name = ""; - } - if (args.length > 1) { - contact.last_name = args[1]; - } else { - contact.last_name = ""; - } + contact.first_name = name; + contact.last_name = ""; contact.id = pCur.getInt(2); contactsMap.put(contact.id, contact); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java b/TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java index 61282fbde..0ac99fa3b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/GcmBroadcastReceiver.java @@ -49,13 +49,13 @@ public class GcmBroadcastReceiver extends BroadcastReceiver { } } + AwakeService.startService(); + Utilities.RunOnUIThread(new Runnable() { @Override public void run() { ApplicationLoader.postInitApplication(); - AwakeService.startService(); - try { String key = intent.getStringExtra("loc_key"); if ("DC_UPDATE".equals(key)) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java index 5ff6a5fa3..2ba729631 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java @@ -319,13 +319,18 @@ public class LocaleController { } else if(eventType == XmlPullParser.TEXT) { if (attrName != null) { value = parser.getText(); + if (value != null) { + value = value.trim(); + value = value.replace("\\n", "\n"); + value = value.replace("\\", ""); + } } } else if (eventType == XmlPullParser.END_TAG) { value = null; attrName = null; name = null; } - if (name != null && name.equals("string") && value != null && attrName != null) { + if (name != null && name.equals("string") && value != null && attrName != null && value.length() != 0 && attrName.length() != 0) { stringMap.put(attrName, value); name = null; value = null; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 7aac77931..18f693416 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -26,7 +26,6 @@ import android.media.AudioManager; import android.media.SoundPool; import android.net.Uri; import android.os.Build; -import android.os.PowerManager; import android.os.Vibrator; import android.provider.Settings; import android.support.v4.app.NotificationCompat; @@ -100,7 +99,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter public int fontSize = Utilities.dp(16); public long scheduleContactsReload = 0; - public static volatile boolean isScreenOn = true; public MessageObject currentPushMessage; private class UserActionUpdates extends TLRPC.Updates { @@ -201,14 +199,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter } public MessagesController() { - try { - PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE); - isScreenOn = pm.isScreenOn(); - FileLog.e("tmessages", "screen state = " + isScreenOn); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - MessagesStorage storage = MessagesStorage.getInstance(); NotificationCenter.getInstance().addObserver(this, FileLoader.FileDidUpload); NotificationCenter.getInstance().addObserver(this, FileLoader.FileDidFailUpload); @@ -2186,7 +2176,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter } private void performSendEncryptedRequest(final TLRPC.DecryptedMessage req, final MessageObject newMsgObj, final TLRPC.EncryptedChat chat, final TLRPC.InputEncryptedFile encryptedFile) { - if (req == null) { + if (req == null || chat.auth_key == null || chat instanceof TLRPC.TL_encryptedChatRequested || chat instanceof TLRPC.TL_encryptedChatWaiting) { return; } //TLRPC.decryptedMessageLayer messageLayer = new TLRPC.decryptedMessageLayer(); @@ -3373,7 +3363,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter }); } else { gettingDifference = false; - loadCurrentState(); + getDifference(); FileLog.e("tmessages", "get difference error, don't know what to do :("); } } @@ -3424,7 +3414,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter } else { dialog_id = obj.messageOwner.to_id.user_id; } - if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !isScreenOn) { + if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) { showInAppNotification(obj); } } @@ -3483,7 +3473,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter } else { dialog_id = obj.messageOwner.to_id.user_id; } - if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !isScreenOn) { + if (dialog_id != openned_dialog_id || ApplicationLoader.lastPauseTime != 0 || !ApplicationLoader.isScreenOn) { showInAppNotification(obj); } } @@ -4240,7 +4230,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter return; } - if (ApplicationLoader.lastPauseTime == 0 && isScreenOn) { + if (ApplicationLoader.lastPauseTime == 0 && ApplicationLoader.isScreenOn) { boolean inAppSounds = preferences.getBoolean("EnableInAppSounds", true); boolean inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true); boolean inAppPreview = preferences.getBoolean("EnableInAppPreview", true); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java index d6052610c..7816e3f07 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java @@ -34,7 +34,7 @@ public class NativeLoader { return; } - if (Build.VERSION.SDK_INT >= 10) { + if (Build.VERSION.SDK_INT > 10) { try { String folder = null; long libSize = 0; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java b/TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java index 8f79680fc..2abdd5d02 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ScreenReceiver.java @@ -12,15 +12,17 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import org.telegram.ui.ApplicationLoader; + public class ScreenReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { FileLog.e("tmessages", "screen off"); - MessagesController.isScreenOn = false; + ApplicationLoader.isScreenOn = false; } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { FileLog.e("tmessages", "screen on"); - MessagesController.isScreenOn = true; + ApplicationLoader.isScreenOn = true; } } } diff --git a/TMessagesProj/src/main/java/org/telegram/objects/PhotoObject.java b/TMessagesProj/src/main/java/org/telegram/objects/PhotoObject.java index 54731382e..440cd2567 100644 --- a/TMessagesProj/src/main/java/org/telegram/objects/PhotoObject.java +++ b/TMessagesProj/src/main/java/org/telegram/objects/PhotoObject.java @@ -60,6 +60,9 @@ public class PhotoObject { int closestHeight = 9999; TLRPC.PhotoSize closestObject = null; for (TLRPC.PhotoSize obj : sizes) { + if (obj == null) { + continue; + } int diffW = Math.abs(obj.w - width); int diffH = Math.abs(obj.h - height); if (closestObject == null || closestObject instanceof TLRPC.TL_photoCachedSize || closestWidth > diffW || closestHeight > diffH) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java index 3d2b05654..efc7560e4 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java @@ -21,6 +21,7 @@ import android.content.res.Configuration; import android.graphics.Bitmap; import android.os.AsyncTask; import android.os.Handler; +import android.os.PowerManager; import android.view.ViewConfiguration; import com.google.android.gms.common.ConnectionResult; @@ -56,6 +57,7 @@ public class ApplicationLoader extends Application { public static volatile Context applicationContext = null; public static volatile Handler applicationHandler = null; private static volatile boolean applicationInited = false; + public static volatile boolean isScreenOn = false; public static ArrayList fragmentsStack = new ArrayList(); @@ -63,6 +65,7 @@ public class ApplicationLoader extends Application { if (applicationInited) { return; } + applicationInited = true; NativeLoader.initNativeLibs(applicationContext); @@ -82,6 +85,14 @@ public class ApplicationLoader extends Application { e.printStackTrace(); } + try { + PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE); + isScreenOn = pm.isScreenOn(); + FileLog.e("tmessages", "screen state = " + isScreenOn); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + UserConfig.loadConfig(); if (UserConfig.currentUser != null) { boolean changed = false; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java index c470a4fdf..2d9aa5364 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -198,7 +198,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } else if (currentMessageObject.type == 8) { if (buttonState == -1) { buttonState = 2; - gifDrawable.pause(); + if (gifDrawable != null) { + gifDrawable.pause(); + } invalidate(); } else if (buttonState == 2 || buttonState == 0) { didPressedButton(); @@ -344,6 +346,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable); } + invalidate(); /*if ((type == 6 || type == 7) && videoTimeText != null) { int duration = message.messageOwner.media.video.duration; int minutes = duration / 60; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java index 9dc7f6007..4cb4165da 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java @@ -15,7 +15,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; -import android.database.Cursor; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; @@ -80,6 +79,8 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica selectedBackground = preferences.getInt("selectedBackground", 1000001); selectedColor = preferences.getInt("selectedColor", 0); MessagesStorage.getInstance().getWallpapers(); + File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg"); + toFile.delete(); return true; } @@ -171,7 +172,13 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica FileLog.e("tmessages", e); } } else { - done = true; + if (selectedBackground == -1) { + File fromFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg"); + File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); + done = fromFile.renameTo(toFile); + } else { + done = true; + } } if (done) { @@ -203,7 +210,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica Utilities.addMediaToGallery(currentPicturePath); try { Bitmap bitmap = FileLoader.loadBitmap(currentPicturePath, null, Utilities.dp(320), Utilities.dp(480)); - File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); + File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg"); FileOutputStream stream = new FileOutputStream(toFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); selectedBackground = -1; @@ -214,21 +221,12 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica } currentPicturePath = null; } else if (requestCode == 11) { - Uri imageUri = data.getData(); - Cursor cursor = parentActivity.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null); - if (cursor == null) { + if (data == null || data.getData() == null) { return; } - try { - String imageFilePath = null; - if (cursor.moveToFirst()) { - imageFilePath = cursor.getString(0); - } - cursor.close(); - - Bitmap bitmap = FileLoader.loadBitmap(imageFilePath, null, Utilities.dp(320), Utilities.dp(480)); - File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); + Bitmap bitmap = FileLoader.loadBitmap(null, data.getData(), Utilities.dp(320), Utilities.dp(480)); + File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg"); FileOutputStream stream = new FileOutputStream(toFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); selectedBackground = -1; @@ -291,7 +289,10 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica backgroundImage.setBackgroundColor(0); selectedColor = 0; } else if (selectedBackground == -1) { - File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); + File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg"); + if (!toFile.exists()) { + toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); + } if (toFile.exists()) { backgroundImage.setImageURI(Uri.fromFile(toFile)); } else { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java index 4105d6c3a..00045c874 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java @@ -517,8 +517,8 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } else { menu.add(Menu.NONE, share_contact, Menu.NONE, LocaleController.getString("ShareContact", R.string.ShareContact)); menu.add(Menu.NONE, block_contact, Menu.NONE, LocaleController.getString("BlockContact", R.string.BlockContact)); - menu.add(Menu.NONE, block_contact, Menu.NONE, LocaleController.getString("EditContact", R.string.EditContact)); - menu.add(Menu.NONE, block_contact, Menu.NONE, LocaleController.getString("DeleteContact", R.string.DeleteContact)); + menu.add(Menu.NONE, edit_contact, Menu.NONE, LocaleController.getString("EditContact", R.string.EditContact)); + menu.add(Menu.NONE, delete_contact, Menu.NONE, LocaleController.getString("DeleteContact", R.string.DeleteContact)); } } diff --git a/TMessagesProj/src/main/res/values-de/strings.xml b/TMessagesProj/src/main/res/values-de/strings.xml index c7ff15cf3..445a805da 100644 --- a/TMessagesProj/src/main/res/values-de/strings.xml +++ b/TMessagesProj/src/main/res/values-de/strings.xml @@ -258,9 +258,9 @@ Sprache Please note that Telegram Support is done by volunteers. We try to respond as quickly as possible, but it may take a while.
]]>Please take a look at the Telegram FAQ]]>: it has important troubleshooting tips]]> and answers to most questions.
Ask a volunteer - Telegram FAQ + Telegram-FAQ https://telegram.org/faq - Delete localization? + Lokalisierung löschen? Incorrect localization file diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml index ad787b9cd..0a709c4f4 100644 --- a/TMessagesProj/src/main/res/values-es/strings.xml +++ b/TMessagesProj/src/main/res/values-es/strings.xml @@ -258,10 +258,10 @@ Idioma Por favor, ten en cuenta que el Soporte de Telegram está hecho por voluntarios. Intentamos responder lo antes posible, pero puede tomar un tiempo.
]]>Por favor, echa un vistazo a las Preguntas Frecuentes de Telegram]]>: tiene importantes Soluciones a problemas]]> y respuestas para la mayoría de las preguntas.
Preguntar - Telegram FAQ + Preguntas frecuentes https://telegram.org/faq/es ¿Eliminar localización? - Incorrect localization file + Fichero de localización incorrecto No hay fotos ni vídeos compartidos aún diff --git a/TMessagesProj/src/main/res/values-it/strings.xml b/TMessagesProj/src/main/res/values-it/strings.xml index 7b9b01346..1edff811d 100644 --- a/TMessagesProj/src/main/res/values-it/strings.xml +++ b/TMessagesProj/src/main/res/values-it/strings.xml @@ -258,10 +258,10 @@ Lingua Nota che il supporto di Telegram è fornito da volontari. Proviamo a rispondere non appena possibile, ma potrebbe richiedere del tempo.
]]>Dai un\'occhiata alle Domande frequenti]]>: troverai risposte alla maggior parte delle domande e suggerimenti importanti per l\'individuazione del problema]]>.
Chiedi a un volontario - Telegram FAQ + Domande frequenti https://telegram.org/faq Eliminare la localizzazione? - Incorrect localization file + File della localizzazione non valido Nessun media condiviso