From 644fc7ccea9deee3686dc9c824893baa4ce4bef6 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sun, 25 May 2014 02:47:05 +0400 Subject: [PATCH] Optimized battery consumption, fixed blurry photos on some devices, added option to auto download media only via WiFi, changed way of contacts changes monitoring https://github.com/DrKLO/Telegram/pull/422 https://github.com/rubenlagus/Telegram/commit/d96ce3c140bd49c5c8c63cea2b c9afad8a16b8bb --- TMessagesProj/build.gradle | 4 +- .../java/jawnae/pyronet/PyroSelector.java | 2 +- .../telegram/messenger/BuffersStorage.java | 24 +- .../messenger/ConnectionsManager.java | 197 +++++++++-------- .../messenger/ContactsController.java | 131 +++++++---- .../messenger/MessagesController.java | 9 - .../telegram/messenger/MessagesStorage.java | 2 - .../org/telegram/messenger/Utilities.java | 2 - .../org/telegram/objects/MessageObject.java | 11 +- .../ContactsActivitySearchAdapter.java | 2 +- .../org/telegram/ui/ApplicationLoader.java | 4 + .../org/telegram/ui/Cells/ChatMediaCell.java | 21 +- .../java/org/telegram/ui/ChatActivity.java | 14 +- .../org/telegram/ui/ContactsActivity.java | 18 +- .../telegram/ui/CountrySelectActivity.java | 15 ++ .../org/telegram/ui/GalleryImageViewer.java | 33 +-- .../org/telegram/ui/GroupCreateActivity.java | 14 ++ .../telegram/ui/LanguageSelectActivity.java | 15 ++ .../org/telegram/ui/MessagesActivity.java | 11 +- .../org/telegram/ui/SettingsActivity.java | 207 +++++++++++------- .../ui/Views/SectionedBaseAdapter.java | 2 - .../src/main/res/values-ar/strings.xml | 3 + .../src/main/res/values-de/strings.xml | 3 + .../src/main/res/values-es/strings.xml | 3 + .../src/main/res/values-it/strings.xml | 3 + .../src/main/res/values-nl/strings.xml | 3 + TMessagesProj/src/main/res/values/strings.xml | 5 + 27 files changed, 457 insertions(+), 301 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 0cf0b3990..55ccd56ae 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 231 - versionName "1.4.13" + versionCode 233 + versionName "1.4.14" } } diff --git a/TMessagesProj/src/main/java/jawnae/pyronet/PyroSelector.java b/TMessagesProj/src/main/java/jawnae/pyronet/PyroSelector.java index 5db9e2ffc..ce89abcd2 100755 --- a/TMessagesProj/src/main/java/jawnae/pyronet/PyroSelector.java +++ b/TMessagesProj/src/main/java/jawnae/pyronet/PyroSelector.java @@ -83,7 +83,7 @@ public class PyroSelector { } public void select() { - this.select(10); + this.select(0); } public void select(long eventTimeout) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java index 50a69b526..5d25fae38 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java @@ -42,18 +42,18 @@ public class BuffersStorage { for (int a = 0; a < 5; a++) { freeBuffers128.add(new ByteBufferDesc(128)); } - for (int a = 0; a < 5; a++) { - freeBuffers1024.add(new ByteBufferDesc(1024 + 200)); - } - for (int a = 0; a < 2; a++) { - freeBuffers4096.add(new ByteBufferDesc(4096 + 200)); - } - for (int a = 0; a < 2; a++) { - freeBuffers16384.add(new ByteBufferDesc(16384 + 200)); - } - for (int a = 0; a < 2; a++) { - freeBuffers32768.add(new ByteBufferDesc(40000)); - } +// for (int a = 0; a < 5; a++) { +// freeBuffers1024.add(new ByteBufferDesc(1024 + 200)); +// } +// for (int a = 0; a < 2; a++) { +// freeBuffers4096.add(new ByteBufferDesc(4096 + 200)); +// } +// for (int a = 0; a < 2; a++) { +// freeBuffers16384.add(new ByteBufferDesc(16384 + 200)); +// } +// for (int a = 0; a < 2; a++) { +// freeBuffers32768.add(new ByteBufferDesc(40000)); +// } } public ByteBufferDesc getFreeBuffer(int size) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java index a5a14fff3..ac5b2321d 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java @@ -23,8 +23,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Locale; -import java.util.Timer; -import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -64,8 +62,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. private boolean registeringForPush = false; private boolean paused = false; - private Runnable stageRunnable; - private Runnable pingRunnable; private long lastPingTime = System.currentTimeMillis(); private long lastPushPingTime = System.currentTimeMillis(); private int nextSleepTimeout = 30000; @@ -84,6 +80,89 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. return localInstance; } + static long t = System.currentTimeMillis(); + private Runnable stageRunnable = new Runnable() { + @Override + public void run() { + Utilities.stageQueue.handler.removeCallbacks(stageRunnable); + t = System.currentTimeMillis(); + if (datacenters != null) { + if (lastPushPingTime < System.currentTimeMillis() - 29000) { + lastPushPingTime = System.currentTimeMillis(); + Datacenter datacenter = datacenterWithId(currentDatacenterId); + if (datacenter != null) { + generatePing(datacenter, true); + } + } + } + + long currentTime = System.currentTimeMillis(); + if (ApplicationLoader.lastPauseTime != 0 && ApplicationLoader.lastPauseTime < currentTime - nextSleepTimeout) { + boolean dontSleep = false; + for (RPCRequest request : runningRequests) { + if (request.retryCount < 10 && (request.runningStartTime + 60 > (int)(currentTime / 1000)) && ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0)) { + dontSleep = true; + break; + } + } + if (!dontSleep) { + for (RPCRequest request : requestQueue) { + if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { + dontSleep = true; + break; + } + } + } + if (!dontSleep) { + if (!paused) { + FileLog.e("tmessages", "pausing network and timers by sleep time = " + nextSleepTimeout); + for (Datacenter datacenter : datacenters.values()) { + if (datacenter.connection != null) { + datacenter.connection.suspendConnection(true); + } + if (datacenter.uploadConnection != null) { + datacenter.uploadConnection.suspendConnection(true); + } + if (datacenter.downloadConnection != null) { + datacenter.downloadConnection.suspendConnection(true); + } + } + } + try { + paused = true; + Utilities.stageQueue.postRunnable(stageRunnable, 1000); + return; + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else { + ApplicationLoader.lastPauseTime += 30 * 1000; + FileLog.e("tmessages", "don't sleep 30 seconds because of upload or download request"); + } + } + if (paused) { + paused = false; + FileLog.e("tmessages", "resume network and timers"); + } + + if (datacenters != null) { + MessagesController.getInstance().updateTimerProc(); + if (datacenterWithId(currentDatacenterId).authKey != null) { + if (lastPingTime < System.currentTimeMillis() - 19000) { + lastPingTime = System.currentTimeMillis(); + generatePing(); + } + if (!updatingDcSettings && lastDcUpdateTime < (int)(System.currentTimeMillis() / 1000) - DC_UPDATE_TIME) { + updateDcSettings(0); + } + processRequestQueue(0, 0); + } + } + + Utilities.stageQueue.postRunnable(stageRunnable, 1000); + } + }; + public ConnectionsManager() { currentAppVersion = ApplicationLoader.getAppVersion(); lastOutgoingMessageId = 0; @@ -94,89 +173,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. connectionState = 1; } - Timer serviceTimer = new Timer(); - serviceTimer.schedule(new TimerTask() { - @Override - public void run() { - Utilities.stageQueue.postRunnable(new Runnable() { - @Override - public void run() { - if (datacenters != null) { - if (lastPushPingTime < System.currentTimeMillis() - 29000) { - lastPushPingTime = System.currentTimeMillis(); - Datacenter datacenter = datacenterWithId(currentDatacenterId); - if (datacenter != null) { - generatePing(datacenter, true); - } - } - } - - long currentTime = System.currentTimeMillis(); - if (ApplicationLoader.lastPauseTime != 0 && ApplicationLoader.lastPauseTime < currentTime - nextSleepTimeout) { - boolean dontSleep = false; - for (RPCRequest request : runningRequests) { - if (request.retryCount < 10 && (request.runningStartTime + 60 > (int)(currentTime / 1000)) && ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0)) { - dontSleep = true; - break; - } - } - if (!dontSleep) { - for (RPCRequest request : requestQueue) { - if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0 || (request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - dontSleep = true; - break; - } - } - } - if (!dontSleep) { - if (!paused) { - FileLog.e("tmessages", "pausing network and timers by sleep time = " + nextSleepTimeout); - for (Datacenter datacenter : datacenters.values()) { - if (datacenter.connection != null) { - datacenter.connection.suspendConnection(true); - } - if (datacenter.uploadConnection != null) { - datacenter.uploadConnection.suspendConnection(true); - } - if (datacenter.downloadConnection != null) { - datacenter.downloadConnection.suspendConnection(true); - } - } - } - try { - paused = true; - Thread.sleep(500); - return; - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } else { - ApplicationLoader.lastPauseTime += 30 * 1000; - FileLog.e("tmessages", "don't sleep 30 seconds because of upload or download request"); - } - } - if (paused) { - paused = false; - FileLog.e("tmessages", "resume network and timers"); - } - - if (datacenters != null) { - MessagesController.getInstance().updateTimerProc(); - if (datacenterWithId(currentDatacenterId).authKey != null) { - if (lastPingTime < System.currentTimeMillis() - 19000) { - lastPingTime = System.currentTimeMillis(); - generatePing(); - } - if (!updatingDcSettings && lastDcUpdateTime < (int)(System.currentTimeMillis() / 1000) - DC_UPDATE_TIME) { - updateDcSettings(0); - } - processRequestQueue(0, 0); - } - } - } - }); - } - }, 1000, 1000); + Utilities.stageQueue.postRunnable(stageRunnable, 1000); } public void resumeNetworkMaybe() { @@ -196,6 +193,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. } public void applicationMovedToForeground() { + Utilities.stageQueue.postRunnable(stageRunnable); Utilities.stageQueue.postRunnable(new Runnable() { @Override public void run() { @@ -848,23 +846,36 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. } public static boolean isNetworkOnline() { - boolean status = false; try { ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo netInfo = cm.getNetworkInfo(0); + NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { - status = true; + return true; } else { - netInfo = cm.getNetworkInfo(1); + netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if(netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { - status = true; + return true; } } } catch(Exception e) { FileLog.e("tmessages", e); return true; } - return status; + return false; + } + + public static boolean isConnectedToWiFi() { + try { + ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { + return true; + } + } catch(Exception e) { + FileLog.e("tmessages", e); + return true; + } + return false; } public int getCurrentTime() { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java index ba0f5d848..96d81319e 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ContactsController.java @@ -13,7 +13,6 @@ import android.accounts.AccountManager; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; import android.content.ContentResolver; -import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.provider.BaseColumns; @@ -37,6 +36,10 @@ 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 ArrayList delayedContactsUpdate = new ArrayList(); public static class Contact { @@ -75,37 +78,6 @@ public class ContactsController { public HashMap contactsByPhone = new HashMap(); - private class MyContentObserver extends ContentObserver { - - public MyContentObserver() { - super(null); - } - - @Override - public void onChange(boolean selfChange) { - super.onChange(selfChange); - synchronized (observerLock) { - if (ignoreChanges) { - FileLog.e("tmessages", "contacts changed - ignore"); - return; - } - } - - Utilities.stageQueue.postRunnable(new Runnable() { - @Override - public void run() { - MessagesController.getInstance().scheduleContactsReload = System.currentTimeMillis() + 2000; - FileLog.e("tmessages", "contacts changed schedule - apply in " + MessagesController.getInstance().scheduleContactsReload); - } - }); - } - - @Override - public boolean deliverSelfNotifications() { - return false; - } - } - private static volatile ContactsController Instance = null; public static ContactsController getInstance() { ContactsController localInstance = Instance; @@ -120,15 +92,6 @@ public class ContactsController { return localInstance; } - public ContactsController() { - Utilities.globalQueue.postRunnable(new Runnable() { - @Override - public void run() { - ApplicationLoader.applicationContext.getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, new MyContentObserver()); - } - }); - } - public void cleanup() { contactsBook.clear(); contactsBookSPhones.clear(); @@ -145,6 +108,10 @@ public class ContactsController { contactsSyncInProgress = false; contactsLoaded = false; contactsBookLoaded = false; + lastContactsPhonesCount = -1; + lastContactsPhonesMaxId = -1; + lastContactsNamesCount = -1; + lastContactsNamesMaxId = -1; } public void checkAppAccount() { @@ -183,6 +150,85 @@ public class ContactsController { } } + public void checkContacts() { + Utilities.globalQueue.postRunnable(new Runnable() { + @Override + public void run() { + if (checkContactsInternal()) { + FileLog.e("tmessages", "detected contacts change"); + ContactsController.getInstance().performSyncPhoneBook(ContactsController.getInstance().getContactsCopy(ContactsController.getInstance().contactsBook), true, false, true); + } + } + }); + } + + private boolean checkContactsInternal() { + boolean reload = false; + try { + 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; + } + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + 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); + } + 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); + } + 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; + } + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + return reload; + } + public void readContacts() { if (loadingContacts) { return; @@ -414,6 +460,9 @@ public class ContactsController { } FileLog.e("tmessages", "start read contacts from phone"); + if (!schedule) { + checkContactsInternal(); + } final HashMap contactsMap = readContactsFromPhoneBook(); final HashMap contactsBookShort = new HashMap(); int oldCount = contactHashMap.size(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 2c07ba8de..6dc1c08e4 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -95,7 +95,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter private int sound; public boolean enableJoined = true; public int fontSize = Utilities.dp(16); - public long scheduleContactsReload = 0; public MessageObject currentPushMessage; @@ -300,7 +299,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter updatesStartWaitTime = 0; currentDeletingTaskTime = 0; - scheduleContactsReload = 0; currentDeletingTaskMids = null; gettingNewDeleteTask = false; currentDeletingTask = null; @@ -763,11 +761,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter checkDeletingTask(); if (UserConfig.clientUserId != 0) { - if (scheduleContactsReload != 0 && currentTime > scheduleContactsReload) { - ContactsController.getInstance().performSyncPhoneBook(ContactsController.getInstance().getContactsCopy(ContactsController.getInstance().contactsBook), true, false, true); - scheduleContactsReload = 0; - } - if (ApplicationLoader.lastPauseTime == 0) { if (statusSettingState != 1 && (lastStatusUpdateTime == 0 || lastStatusUpdateTime <= System.currentTimeMillis() - 55000 || offlineSent)) { statusSettingState = 1; @@ -820,8 +813,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter FileLog.e("tmessages", "UPDATES WAIT TIMEOUT - CHECK QUEUE"); processUpdatesQueue(false); } - } else { - scheduleContactsReload = 0; } if (!printingUsers.isEmpty() || lastPrintingStringCount != printingUsers.size()) { boolean updated = false; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java index 7185b4b32..c7ad58057 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java @@ -997,8 +997,6 @@ public class MessagesStorage { @Override public void run() { try { - database.executeFast("DELETE FROM user_contacts_v6 WHERE 1").stepThis().dispose(); - database.executeFast("DELETE FROM user_phones_v6 WHERE 1").stepThis().dispose(); database.beginTransaction(); SQLitePreparedStatement state = database.executeFast("REPLACE INTO user_contacts_v6 VALUES(?, ?, ?)"); SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO user_phones_v6 VALUES(?, ?, ?, ?)"); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java index dadd28f4c..f53287526 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java @@ -47,9 +47,7 @@ import java.io.OutputStream; import java.math.BigInteger; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.nio.channels.Channels; import java.nio.channels.FileChannel; -import java.nio.channels.ReadableByteChannel; import java.security.KeyFactory; import java.security.MessageDigest; import java.security.PublicKey; diff --git a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java index f18a7ae84..17edcef7b 100644 --- a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java @@ -340,16 +340,7 @@ public class MessageObject { } else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) { ArrayList sizes = messageOwner.media.photo.sizes; if (sizes.size() > 0) { - int width = (int)(Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f); - int height = width + Utilities.dp(100); - if (width > 800) { - width = 800; - } - if (height > 800) { - height = 800; - } - - TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, width, height); + TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800); if (sizeFull != null) { return getAttachFileName(sizeFull); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java index 2c2bb6189..99bcfcb75 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java @@ -148,7 +148,7 @@ public class ContactsActivitySearchAdapter extends BaseFragmentAdapter { @Override public boolean hasStableIds() { - return false; + return true; } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java index ea68c1ad5..71a5ce5ea 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java @@ -30,6 +30,7 @@ import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.gcm.GoogleCloudMessaging; +import org.telegram.messenger.ContactsController; import org.telegram.messenger.NotificationsService; import org.telegram.messenger.BuildVars; import org.telegram.messenger.ConnectionsManager; @@ -197,6 +198,9 @@ public class ApplicationLoader extends Application { } public static void resetLastPauseTime() { + if (lastPauseTime != 0 && System.currentTimeMillis() - lastPauseTime > 5000) { + ContactsController.getInstance().checkContacts(); + } lastPauseTime = 0; ConnectionsManager.getInstance().applicationMovedToForeground(); } 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 d33b330a1..dfa978ac4 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -20,6 +20,7 @@ import android.view.MotionEvent; import android.view.SoundEffectConstants; import android.view.View; +import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.FileLoader; import org.telegram.messenger.MediaController; import org.telegram.messenger.MessagesController; @@ -57,7 +58,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD private String currentPhotoFilter; private ImageReceiver photoImage; private ProgressView progressView; - public boolean downloadPhotos = true; + public int downloadPhotos = 0; private boolean progressVisible = false; private int TAG; @@ -350,12 +351,22 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD photoHeight = 800; } - currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, photoWidth, photoHeight); + currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, 800, 800); if (currentPhotoObject != null) { float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth; int w = (int) (currentPhotoObject.photoOwner.w / scale); int h = (int) (currentPhotoObject.photoOwner.h / scale); + if (w == 0) { + if (messageObject.type == 3) { + w = infoWidth + infoOffset + Utilities.dp(16); + } else { + w = Utilities.dp(100); + } + } + if (h == 0) { + h = Utilities.dp(100); + } if (h > photoHeight) { float scale2 = h; h = photoHeight; @@ -387,7 +398,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD MediaController.getInstance().removeLoadingFileObserver(this); } } - if (photoExist || downloadPhotos) { + if (photoExist || downloadPhotos == 0 || downloadPhotos == 2 && ConnectionsManager.isConnectedToWiFi()) { if (messageObject.imagePreview != null) { photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), currentPhotoObject.photoOwner.size); } else { @@ -458,7 +469,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD if (!cacheFile.exists()) { MediaController.getInstance().addLoadingFileObserver(fileName, this); if (!FileLoader.getInstance().isLoadingFile(fileName)) { - if (currentMessageObject.type != 1 || !downloadPhotos) { + if (currentMessageObject.type != 1 || downloadPhotos == 1 || downloadPhotos == 2 && !ConnectionsManager.isConnectedToWiFi()) { buttonState = 0; progressVisible = false; } else { @@ -467,7 +478,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } progressView.setProgress(0); } else { - if (currentMessageObject.type != 1 || !downloadPhotos) { + if (currentMessageObject.type != 1 || downloadPhotos == 1 || downloadPhotos == 2 && !ConnectionsManager.isConnectedToWiFi()) { buttonState = 1; } else { buttonState = -1; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index fdc86b837..8e0f38510 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -147,8 +147,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa public boolean scrollToTopOnResume = false; private boolean scrollToTopUnReadOnResume = false; private boolean isCustomTheme = false; - private boolean downloadPhotos = true; - private boolean downloadAudios = true; + private int downloadPhotos = 0; + private int downloadAudios = 0; private ImageView topPlaneClose; private View pagedownButton; private TextView topPanelText; @@ -442,14 +442,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa sendByEnter = preferences.getBoolean("send_by_enter", false); if (currentChat != null) { - downloadPhotos = preferences.getBoolean("photo_download_chat", true); + downloadPhotos = preferences.getInt("photo_download_chat2", 0); } else { - downloadPhotos = preferences.getBoolean("photo_download_user", true); + downloadPhotos = preferences.getInt("photo_download_user2", 0); } if (currentChat != null) { - downloadAudios = preferences.getBoolean("audio_download_chat", true); + downloadAudios = preferences.getInt("audio_download_chat2", 0); } else { - downloadAudios = preferences.getBoolean("audio_download_user", true); + downloadAudios = preferences.getInt("audio_download_user2", 0); } return true; @@ -3844,7 +3844,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ((ChatBaseCell)view).isChat = currentChat != null; ((ChatBaseCell)view).setMessageObject(message); ((ChatBaseCell)view).setCheckPressed(!disableSelection, disableSelection && selected); - if (view instanceof ChatAudioCell && downloadAudios) { + if (view instanceof ChatAudioCell && (downloadAudios == 0 || downloadAudios == 2 && ConnectionsManager.isConnectedToWiFi())) { ((ChatAudioCell)view).downloadAudioIfNeed(); } else if (view instanceof ChatMediaCell) { ((ChatMediaCell)view).downloadPhotos = downloadPhotos; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java index f0a3b6c61..cee664fbc 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java @@ -25,6 +25,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.TextView; @@ -196,7 +197,6 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } else { return; } - } } else { if (section == 0) { @@ -294,6 +294,19 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } } }); + + listView.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView absListView, int i) { + if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { + Utilities.hideKeyboard(searchView); + } + } + + @Override + public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + } + }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -432,6 +445,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { + Utilities.hideKeyboard(searchView); return true; } @@ -440,7 +454,6 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter if (searchListViewAdapter == null) { return true; } - searchListViewAdapter.searchDialogs(s); if (s.length() != 0) { searchWas = true; if (listView != null) { @@ -456,6 +469,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); } } + searchListViewAdapter.searchDialogs(s); return true; } }); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java index bf4662c90..6495937d3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java @@ -21,6 +21,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; @@ -148,6 +149,19 @@ public class CountrySelectActivity extends ActionBarActivity { } }); + listView.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView absListView, int i) { + if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { + Utilities.hideKeyboard(searchView); + } + } + + @Override + public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + } + }); + getWindow().setBackgroundDrawableResource(R.drawable.transparent); } @@ -220,6 +234,7 @@ public class CountrySelectActivity extends ActionBarActivity { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { + Utilities.hideKeyboard(searchView); return true; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java index 227e83c6e..0c865c868 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java @@ -533,16 +533,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif } } } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) { - int width = (int)(Math.min(displaySize.x, displaySize.y) * 0.7f); - int height = width + Utilities.dp(100); - if (width > 800) { - width = 800; - } - if (height > 800) { - height = 800; - } - - TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, width, height); + TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 800, 800); if (sizeFull != null) { TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation(); location.local_id = sizeFull.location.local_id; @@ -591,16 +582,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif } else { ArrayList sizes = obj.messageOwner.action.photo.sizes; if (sizes.size() > 0) { - int width = (int)(Math.min(displaySize.x, displaySize.y) * 0.7f); - int height = width + Utilities.dp(100); - if (width > 800) { - width = 800; - } - if (height > 800) { - height = 800; - } - - TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, width, height); + TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800); if (sizeFull != null) { currentFileName = sizeFull.location.volume_id + "_" + sizeFull.location.local_id + ".jpg"; } @@ -990,16 +972,7 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif ArrayList sizes = message.messageOwner.media.photo.sizes; iv.isVideo = false; if (sizes.size() > 0) { - int width = (int)(Math.min(displaySize.x, displaySize.y) * 0.7f); - int height = width + Utilities.dp(100); - if (width > 800) { - width = 800; - } - if (height > 800) { - height = 800; - } - - TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, width, height); + TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800); if (message.imagePreview != null) { iv.setImage(sizeFull.location, null, message.imagePreview, sizeFull.size); } else { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java index 2142380a4..96ecd5144 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java @@ -31,6 +31,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ImageView; @@ -279,6 +280,19 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen } } }); + + listView.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView absListView, int i) { + if (i == SCROLL_STATE_TOUCH_SCROLL) { + Utilities.hideKeyboard(userSelectEditText); + } + } + + @Override + public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + } + }); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java index d95c21d47..d05d51b34 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java @@ -22,6 +22,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; @@ -178,6 +179,19 @@ public class LanguageSelectActivity extends BaseFragment { } }); + listView.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView absListView, int i) { + if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { + Utilities.hideKeyboard(searchView); + } + } + + @Override + public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + } + }); + searching = false; searchWas = false; } else { @@ -281,6 +295,7 @@ public class LanguageSelectActivity extends BaseFragment { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { + Utilities.hideKeyboard(searchView); return true; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java index 006d466b3..674ba1047 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java @@ -274,7 +274,9 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter messagesListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { - + if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { + Utilities.hideKeyboard(searchView); + } } @Override @@ -498,13 +500,13 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter public void run() { for (TLObject obj : result) { if (obj instanceof TLRPC.User) { - TLRPC.User user = (TLRPC.User)obj; + TLRPC.User user = (TLRPC.User) obj; MessagesController.getInstance().users.putIfAbsent(user.id, user); } else if (obj instanceof TLRPC.Chat) { - TLRPC.Chat chat = (TLRPC.Chat)obj; + TLRPC.Chat chat = (TLRPC.Chat) obj; MessagesController.getInstance().chats.putIfAbsent(chat.id, chat); } else if (obj instanceof TLRPC.EncryptedChat) { - TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)obj; + TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) obj; MessagesController.getInstance().encryptedChats.putIfAbsent(chat.id, chat); } } @@ -593,6 +595,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { + Utilities.hideKeyboard(searchView); return true; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index b72b9bdce..97b0bedaa 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -96,6 +96,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter private int telegramFaqRow; private int languageRow; private int versionRow; + private int contactsSectionRow; + private int contactsReimportRow; + private int contactsSortRow; private int rowCount; private static class LinkMovementMethodMy extends LinkMovementMethod { @@ -192,6 +195,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter messagesSectionRow = rowCount++; textSizeRow = rowCount++; sendByEnterRow = rowCount++; + //contactsSectionRow = rowCount++; + //contactsSortRow = rowCount++; + //contactsReimportRow = rowCount++; supportSectionRow = rowCount++; if (BuildVars.DEBUG_VERSION) { sendLogsRow = rowCount++; @@ -228,7 +234,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override - public void onItemClick(AdapterView adapterView, View view, int i, long l) { + public void onItemClick(AdapterView adapterView, View view, final int i, long l) { if (parentActivity == null) { return; } @@ -328,42 +334,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.show().setCanceledOnTouchOutside(true); - } else if (i == photoDownloadChatRow) { - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - boolean value = preferences.getBoolean("photo_download_chat", true); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("photo_download_chat", !value); - editor.commit(); - if (listView != null) { - listView.invalidateViews(); - } - } else if (i == photoDownloadPrivateRow) { - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - boolean value = preferences.getBoolean("photo_download_user", true); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("photo_download_user", !value); - editor.commit(); - if (listView != null) { - listView.invalidateViews(); - } - } else if (i == audioDownloadChatRow) { - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - boolean value = preferences.getBoolean("audio_download_chat", true); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("audio_download_chat", !value); - editor.commit(); - if (listView != null) { - listView.invalidateViews(); - } - } else if (i == audioDownloadPrivateRow) { - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - boolean value = preferences.getBoolean("audio_download_user", true); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("audio_download_user", !value); - editor.commit(); - if (listView != null) { - listView.invalidateViews(); - } } else if (i == languageRow) { ((LaunchActivity)parentActivity).presentFragment(new LanguageSelectActivity(), "settings_lang", false); } else if (i == switchBackendButtonRow) { @@ -385,6 +355,58 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } catch (Exception e) { FileLog.e("tmessages", e); } + } else if (i == contactsReimportRow) { + + } else if (i == contactsSortRow) { + AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy)); + builder.setItems(new CharSequence[] { + LocaleController.getString("Default", R.string.Default), + LocaleController.getString("SortFirstName", R.string.SortFirstName), + LocaleController.getString("SortLastName", R.string.SortLastName) + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = preferences.edit(); + editor.putInt("sortContactsBy", which); + editor.commit(); + if (listView != null) { + listView.invalidateViews(); + } + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + builder.show().setCanceledOnTouchOutside(true); + } else if (i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) { + AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); + builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); + builder.setItems(new CharSequence[] { + LocaleController.getString("Enabled", R.string.Enabled), + LocaleController.getString("Disabled", R.string.Disabled), + LocaleController.getString("WiFiOnly", R.string.WiFiOnly) + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = preferences.edit(); + if (i == photoDownloadChatRow) { + editor.putInt("photo_download_chat2", which); + } else if (i == photoDownloadPrivateRow) { + editor.putInt("photo_download_user2", which); + } else if (i == audioDownloadChatRow) { + editor.putInt("audio_download_chat2", which); + } else if (i == audioDownloadPrivateRow) { + editor.putInt("audio_download_user2", which); + } + editor.commit(); + if (listView != null) { + listView.invalidateViews(); + } + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + builder.show().setCanceledOnTouchOutside(true); } } }); @@ -617,7 +639,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter return i == textSizeRow || i == enableAnimationsRow || i == blockedRow || i == notificationRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == sendByEnterRow || i == terminateSessionsRow || i == photoDownloadPrivateRow || i == photoDownloadChatRow || i == clearLogsRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow || i == languageRow || - i == switchBackendButtonRow || i == telegramFaqRow; + i == switchBackendButtonRow || i == telegramFaqRow || i == contactsSortRow || i == contactsReimportRow; } @Override @@ -789,6 +811,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter textView.setText(LocaleController.getString("AutomaticPhotoDownload", R.string.AutomaticPhotoDownload)); } else if (i == audioDownloadSection) { textView.setText(LocaleController.getString("AutomaticAudioDownload", R.string.AutomaticAudioDownload)); + } else if (i == contactsSectionRow) { + textView.setText(LocaleController.getString("Contacts", R.string.Contacts).toUpperCase()); } } else if (type == 2) { if (view == null) { @@ -832,6 +856,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } else if (i == telegramFaqRow) { textView.setText(LocaleController.getString("TelegramFAQ", R.string.TelegramFaq)); divider.setVisibility(View.VISIBLE); + } else if (i == contactsReimportRow) { + textView.setText(LocaleController.getString("ImportContacts", R.string.ImportContacts)); + divider.setVisibility(View.INVISIBLE); } } else if (type == 3) { if (view == null) { @@ -860,42 +887,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } else { checkButton.setImageResource(R.drawable.btn_check_off); } - } else if (i == photoDownloadChatRow) { - textView.setText(LocaleController.getString("AutomaticPhotoDownloadGroups", R.string.AutomaticPhotoDownloadGroups)); - divider.setVisibility(View.VISIBLE); - boolean enabled = preferences.getBoolean("photo_download_chat", true); - if (enabled) { - checkButton.setImageResource(R.drawable.btn_check_on); - } else { - checkButton.setImageResource(R.drawable.btn_check_off); - } - } else if (i == photoDownloadPrivateRow) { - textView.setText(LocaleController.getString("AutomaticPhotoDownloadPrivateChats", R.string.AutomaticPhotoDownloadPrivateChats)); - divider.setVisibility(View.INVISIBLE); - boolean enabled = preferences.getBoolean("photo_download_user", true); - if (enabled) { - checkButton.setImageResource(R.drawable.btn_check_on); - } else { - checkButton.setImageResource(R.drawable.btn_check_off); - } - } else if (i == audioDownloadChatRow) { - textView.setText(LocaleController.getString("AutomaticPhotoDownloadGroups", R.string.AutomaticPhotoDownloadGroups)); - divider.setVisibility(View.VISIBLE); - boolean enabled = preferences.getBoolean("audio_download_chat", true); - if (enabled) { - checkButton.setImageResource(R.drawable.btn_check_on); - } else { - checkButton.setImageResource(R.drawable.btn_check_off); - } - } else if (i == audioDownloadPrivateRow) { - textView.setText(LocaleController.getString("AutomaticPhotoDownloadPrivateChats", R.string.AutomaticPhotoDownloadPrivateChats)); - divider.setVisibility(View.INVISIBLE); - boolean enabled = preferences.getBoolean("audio_download_user", true); - if (enabled) { - checkButton.setImageResource(R.drawable.btn_check_on); - } else { - checkButton.setImageResource(R.drawable.btn_check_off); - } } // if (i == 7) { // textView.setText(LocaleController.getString(R.string.SaveIncomingPhotos)); @@ -952,6 +943,66 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter detailTextView.setText(LocaleController.getCurrentLanguageName()); textView.setText(LocaleController.getString("Language", R.string.Language)); divider.setVisibility(View.VISIBLE); + } else if (i == contactsSortRow) { + textView.setText(LocaleController.getString("SortBy", R.string.SortBy)); + divider.setVisibility(View.VISIBLE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + int sort = preferences.getInt("sortContactsBy", 0); + if (sort == 0) { + detailTextView.setText(LocaleController.getString("Default", R.string.Default)); + } else if (sort == 1) { + detailTextView.setText(LocaleController.getString("FirstName", R.string.SortFirstName)); + } else if (sort == 2) { + detailTextView.setText(LocaleController.getString("LastName", R.string.SortLastName)); + } + } else if (i == photoDownloadChatRow) { + textView.setText(LocaleController.getString("AutomaticPhotoDownloadGroups", R.string.AutomaticPhotoDownloadGroups)); + divider.setVisibility(View.VISIBLE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + int value = preferences.getInt("photo_download_chat2", 0); + if (value == 0) { + detailTextView.setText(LocaleController.getString("Enabled", R.string.Enabled)); + } else if (value == 1) { + detailTextView.setText(LocaleController.getString("Disabled", R.string.Disabled)); + } else if (value == 2) { + detailTextView.setText(LocaleController.getString("WiFiOnly", R.string.WiFiOnly)); + } + } else if (i == photoDownloadPrivateRow) { + textView.setText(LocaleController.getString("AutomaticPhotoDownloadPrivateChats", R.string.AutomaticPhotoDownloadPrivateChats)); + divider.setVisibility(View.INVISIBLE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + int value = preferences.getInt("photo_download_user2", 0); + if (value == 0) { + detailTextView.setText(LocaleController.getString("Enabled", R.string.Enabled)); + } else if (value == 1) { + detailTextView.setText(LocaleController.getString("Disabled", R.string.Disabled)); + } else if (value == 2) { + detailTextView.setText(LocaleController.getString("WiFiOnly", R.string.WiFiOnly)); + } + } else if (i == audioDownloadChatRow) { + textView.setText(LocaleController.getString("AutomaticPhotoDownloadGroups", R.string.AutomaticPhotoDownloadGroups)); + divider.setVisibility(View.VISIBLE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + int value = preferences.getInt("audio_download_chat2", 0); + if (value == 0) { + detailTextView.setText(LocaleController.getString("Enabled", R.string.Enabled)); + } else if (value == 1) { + detailTextView.setText(LocaleController.getString("Disabled", R.string.Disabled)); + } else if (value == 2) { + detailTextView.setText(LocaleController.getString("WiFiOnly", R.string.WiFiOnly)); + } + } else if (i == audioDownloadPrivateRow) { + textView.setText(LocaleController.getString("AutomaticPhotoDownloadPrivateChats", R.string.AutomaticPhotoDownloadPrivateChats)); + divider.setVisibility(View.INVISIBLE); + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + int value = preferences.getInt("audio_download_user2", 0); + if (value == 0) { + detailTextView.setText(LocaleController.getString("Enabled", R.string.Enabled)); + } else if (value == 1) { + detailTextView.setText(LocaleController.getString("Disabled", R.string.Disabled)); + } else if (value == 2) { + detailTextView.setText(LocaleController.getString("WiFiOnly", R.string.WiFiOnly)); + } } } else if (type == 6) { if (view == null) { @@ -973,13 +1024,13 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter public int getItemViewType(int i) { if (i == profileRow) { return 0; - } else if (i == numberSectionRow || i == settingsSectionRow || i == supportSectionRow || i == messagesSectionRow || i == photoDownloadSection || i == audioDownloadSection) { + } else if (i == numberSectionRow || i == settingsSectionRow || i == supportSectionRow || i == messagesSectionRow || i == photoDownloadSection || i == audioDownloadSection || i == contactsSectionRow) { return 1; - } else if (i == textSizeRow || i == languageRow) { + } else if (i == textSizeRow || i == languageRow || i == contactsSortRow || i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) { return 5; - } else if (i == enableAnimationsRow || i == sendByEnterRow || i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) { + } else if (i == enableAnimationsRow || i == sendByEnterRow) { return 3; - } else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow || i == clearLogsRow || i == switchBackendButtonRow || i == telegramFaqRow) { + } else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow || i == clearLogsRow || i == switchBackendButtonRow || i == telegramFaqRow || i == contactsReimportRow) { return 2; } else if (i == logoutRow) { return 4; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java index 6e2a00440..5cfa5f3e0 100755 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java @@ -11,7 +11,6 @@ package org.telegram.ui.Views; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; -import android.widget.BaseAdapter; import org.telegram.ui.Adapters.BaseFragmentAdapter; @@ -223,5 +222,4 @@ public abstract class SectionedBaseAdapter extends BaseFragmentAdapter implement mSectionCount = getSectionCount(); return mSectionCount; } - } diff --git a/TMessagesProj/src/main/res/values-ar/strings.xml b/TMessagesProj/src/main/res/values-ar/strings.xml index d7c463859..29c593995 100644 --- a/TMessagesProj/src/main/res/values-ar/strings.xml +++ b/TMessagesProj/src/main/res/values-ar/strings.xml @@ -267,6 +267,9 @@ Disabled Notifications Service If google play services are enough for you to receive notifications, you can disable Notifications Service. However we recommend you to leave it enabled to keep app running in background and receive instant notifications. + Sort By + Import Contacts + via WiFi only لا توجد وسائط بعد diff --git a/TMessagesProj/src/main/res/values-de/strings.xml b/TMessagesProj/src/main/res/values-de/strings.xml index 18cfea7ca..1b626516a 100644 --- a/TMessagesProj/src/main/res/values-de/strings.xml +++ b/TMessagesProj/src/main/res/values-de/strings.xml @@ -267,6 +267,9 @@ Disabled Notifications Service If google play services are enough for you to receive notifications, you can disable Notifications Service. However we recommend you to leave it enabled to keep app running in background and receive instant notifications. + Sort By + Import Contacts + via WiFi only Noch keine geteilten Medien vorhanden diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml index 79b4ee648..80afd8a70 100644 --- a/TMessagesProj/src/main/res/values-es/strings.xml +++ b/TMessagesProj/src/main/res/values-es/strings.xml @@ -267,6 +267,9 @@ Disabled Notifications Service If google play services are enough for you to receive notifications, you can disable Notifications Service. However we recommend you to leave it enabled to keep app running in background and receive instant notifications. + Sort By + Import Contacts + via WiFi only 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 32022a3d9..1ed6fa4db 100644 --- a/TMessagesProj/src/main/res/values-it/strings.xml +++ b/TMessagesProj/src/main/res/values-it/strings.xml @@ -267,6 +267,9 @@ Disabled Notifications Service If google play services are enough for you to receive notifications, you can disable Notifications Service. However we recommend you to leave it enabled to keep app running in background and receive instant notifications. + Sort By + Import Contacts + via WiFi only Nessun media condiviso diff --git a/TMessagesProj/src/main/res/values-nl/strings.xml b/TMessagesProj/src/main/res/values-nl/strings.xml index 25b48141b..48f82d53d 100644 --- a/TMessagesProj/src/main/res/values-nl/strings.xml +++ b/TMessagesProj/src/main/res/values-nl/strings.xml @@ -267,6 +267,9 @@ Disabled Notifications Service If google play services are enough for you to receive notifications, you can disable Notifications Service. However we recommend you to leave it enabled to keep app running in background and receive instant notifications. + Sort By + Import Contacts + via WiFi only Nog geen media gedeeld diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 9dcb4b3a8..c673551e6 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -267,6 +267,11 @@ Disabled Notifications Service If google play services are enough for you to receive notifications, you can disable Notifications Service. However we recommend you to leave it enabled to keep app running in background and receive instant notifications. + Sort By + Import Contacts + via WiFi only + First name + Last name No shared media yet