From 5d042955cd6a42d42bff0acf430a1e0671c2ea43 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Thu, 7 Aug 2014 01:27:24 +0400 Subject: [PATCH] Bug fixes --- TMessagesProj/build.gradle | 2 +- .../telegram/android/ContactsController.java | 88 ++++--------------- .../org/telegram/android/MessagesStorage.java | 2 +- .../org/telegram/objects/MessageObject.java | 2 +- 4 files changed, 18 insertions(+), 76 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index e01ec1f6..6b524b5c 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -83,7 +83,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 302 + versionCode 303 versionName "1.7.0" } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java index 33d2b4bf..9da8a3b5 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java @@ -47,10 +47,7 @@ public class ContactsController { private final Integer observerLock = 1; public boolean contactsLoaded = false; private boolean contactsBookLoaded = false; - private int lastContactsPhonesCount = -1; - private int lastContactsPhonesMaxId = -1; - private int lastContactsNamesCount = -1; - private int lastContactsNamesMaxId = -1; + private String lastContactsVersions = ""; private ArrayList delayedContactsUpdate = new ArrayList(); public static class Contact { @@ -119,10 +116,7 @@ public class ContactsController { contactsSyncInProgress = false; contactsLoaded = false; contactsBookLoaded = false; - lastContactsPhonesCount = -1; - lastContactsPhonesMaxId = -1; - lastContactsNamesCount = -1; - lastContactsNamesMaxId = -1; + lastContactsVersions = ""; } public void checkAppAccount() { @@ -191,70 +185,17 @@ public class ContactsController { ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver(); Cursor pCur = null; try { - pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.Phone._ID}, null, null, ContactsContract.CommonDataKinds.Phone._ID + " desc LIMIT 1"); - if (pCur != null) { - if (pCur.getCount() > 0 && pCur.moveToFirst()) { - int value = pCur.getInt(0); - if (lastContactsPhonesMaxId != -1 && value != lastContactsPhonesMaxId) { - reload = true; - } - lastContactsPhonesMaxId = value; - } + pCur = cr.query(ContactsContract.RawContacts.CONTENT_URI, new String[]{ContactsContract.RawContacts.VERSION}, null, null, null); + StringBuilder currentVersion = new StringBuilder(); + while (pCur.moveToNext()) { + int col = pCur.getColumnIndex(ContactsContract.RawContacts.VERSION); + currentVersion.append(pCur.getString(col)); } - } catch (Exception e) { - FileLog.e("tmessages", e); - } finally { - if (pCur != null) { - pCur.close(); - } - } - try { - pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.Phone._COUNT}, null, null, null); - if (pCur != null) { - if (pCur.getCount() > 0 && pCur.moveToFirst()) { - int value = pCur.getInt(0); - if (lastContactsPhonesCount != -1 && value != lastContactsPhonesCount) { - reload = true; - } - lastContactsPhonesCount = value; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } finally { - if (pCur != null) { - pCur.close(); - } - } - try { - pCur = cr.query(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.Data._COUNT}, ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", null, null); - if (pCur != null) { - if (pCur.getCount() > 0 && pCur.moveToFirst()) { - int value = pCur.getInt(0); - if (lastContactsNamesCount != -1 && value != lastContactsNamesCount) { - reload = true; - } - lastContactsNamesCount = value; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } finally { - if (pCur != null) { - pCur.close(); - } - } - try { - pCur = cr.query(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.Data._ID}, ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", null, ContactsContract.Data._ID + " desc LIMIT 1"); - if (pCur != null) { - if (pCur.getCount() > 0 && pCur.moveToFirst()) { - int value = pCur.getInt(0); - if (lastContactsNamesMaxId != -1 && value != lastContactsNamesMaxId) { - reload = true; - } - lastContactsNamesMaxId = value; - } + String newContactsVersion = currentVersion.toString(); + if (lastContactsVersions.length() != 0 && !lastContactsVersions.equals(newContactsVersion)) { + reload = true; } + lastContactsVersions = newContactsVersion; } catch (Exception e) { FileLog.e("tmessages", e); } finally { @@ -368,7 +309,7 @@ public class ContactsController { String sname2 = pCur.getString(3); String mname = pCur.getString(4); Contact contact = contactsMap.get(id); - if (contact != null) { + if (contact != null && contact.first_name.length() == 0 && contact.last_name.length() == 0) { contact.first_name = fname; contact.last_name = sname; if (contact.first_name == null) { @@ -535,7 +476,8 @@ public class ContactsController { } } - if (existing == null || existing != null && (!existing.first_name.equals(value.first_name) || !existing.last_name.equals(value.last_name))) { + boolean nameChanged = existing != null && (!existing.first_name.equals(value.first_name) || !existing.last_name.equals(value.last_name)); + if (existing == null || nameChanged) { for (int a = 0; a < value.phones.size(); a++) { String sphone = value.shortPhones.get(a); contactsBookShort.put(sphone, value); @@ -550,7 +492,7 @@ public class ContactsController { } } if (request) { - if (contactsByPhone.containsKey(sphone)) { + if (!nameChanged && contactsByPhone.containsKey(sphone)) { continue; } diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java index 98cc2bc8..23d90e7e 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java @@ -2009,7 +2009,7 @@ public class MessagesStorage { } else { state.bindInteger(2, dialog_date != 0 ? dialog_date : value.date); } - state.bindInteger(3, unread_count); + state.bindInteger(3, old_unread_count + unread_count); state.bindInteger(4, messageId); state.step(); } diff --git a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java index 21a10939..fc6f6141 100644 --- a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java @@ -380,7 +380,7 @@ public class MessageObject { photoThumbs.add(obj); } else if (photoThumbs != null && !photoThumbs.isEmpty() && messageOwner.media.document.thumb != null) { PhotoObject photoObject = photoThumbs.get(0); - photoObject.photoOwner.location = messageOwner.media.video.thumb.location; + photoObject.photoOwner.location = messageOwner.media.document.thumb.location; } } }