diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index af4e323e5..9f802790d 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -80,7 +80,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 21 - versionCode 386 - versionName "2.0.0" + versionCode 388 + versionName "2.0.1" } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java index 3c8d49cfa..122469c04 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java @@ -850,6 +850,8 @@ public class ContactsController { final HashMap usersDict = new HashMap(); + final boolean isEmpty = contactsArr.isEmpty(); + if (!contacts.isEmpty()) { for (int a = 0; a < contactsArr.size(); a++) { TLRPC.TL_contact contact = contactsArr.get(a); @@ -1003,6 +1005,12 @@ public class ContactsController { updateUnregisteredContacts(contactsArr); NotificationCenter.getInstance().postNotificationName(NotificationCenter.contactsDidLoaded); + + if (from != 1 && !isEmpty) { + saveContactsLoadTime(); + } else { + reloadContactsStatusesMaybe(); + } } }); @@ -1037,6 +1045,27 @@ public class ContactsController { }); } + private void reloadContactsStatusesMaybe() { + try { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + long lastReloadStatusTime = preferences.getLong("lastReloadStatusTime", 0); + if (lastReloadStatusTime < System.currentTimeMillis() - 1000 * 60 * 60 * 24) { + reloadContactsStatuses(); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + + private void saveContactsLoadTime() { + try { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + preferences.edit().putLong("lastReloadStatusTime", System.currentTimeMillis()).commit(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + private void updateUnregisteredContacts(final ArrayList contactsArr) { final HashMap contactsPhonesShort = new HashMap(); @@ -1586,6 +1615,7 @@ public class ContactsController { } public void reloadContactsStatuses() { + saveContactsLoadTime(); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); final SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("needGetStatuses", true).commit(); 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 93ff3a56e..f56a9573d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java @@ -560,6 +560,10 @@ public class ActionBarLayout extends FrameLayout { if (removeActionBarExtraHeight) { fragment.actionBar.setOccupyStatusBar(false); } + ViewGroup parent = (ViewGroup) fragment.actionBar.getParent(); + if (parent != null) { + parent.removeView(fragment.actionBar); + } containerViewBack.addView(fragment.actionBar); fragment.actionBar.setTitleOverlayText(titleOverlayText); } @@ -698,6 +702,10 @@ public class ActionBarLayout extends FrameLayout { if (removeActionBarExtraHeight) { previousFragment.actionBar.setOccupyStatusBar(false); } + ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent(); + if (parent != null) { + parent.removeView(previousFragment.actionBar); + } containerView.addView(previousFragment.actionBar); previousFragment.actionBar.setTitleOverlayText(titleOverlayText); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/DrawerLayoutContainer.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/DrawerLayoutContainer.java index ca98fb079..e14b10258 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/DrawerLayoutContainer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/DrawerLayoutContainer.java @@ -165,6 +165,9 @@ public class DrawerLayoutContainer extends FrameLayout { } public void openDrawer(boolean fast) { + if (AndroidUtilities.isTablet() && parentActionBarLayout != null && parentActionBarLayout.parentActivity != null) { + AndroidUtilities.hideKeyboard(parentActionBarLayout.parentActivity.getCurrentFocus()); + } cancelCurrentAnimation(); AnimatorSetProxy animatorSet = new AnimatorSetProxy(); animatorSet.playTogether( diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 38ac9effc..e60b92f88 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -506,6 +506,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (currentEncryptedChat != null) { MediaController.getInstance().stopMediaObserver(); } + if (currentUser != null) { + MessagesController.getInstance().cancelLoadFullUser(currentUser.id); + } if (!AndroidUtilities.isTablet()) { getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); } @@ -996,38 +999,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } - if (currentEncryptedChat != null) { - emptyView.setVisibility(View.INVISIBLE); - View secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder); - secretChatPlaceholder.setVisibility(View.VISIBLE); - if (isCustomTheme) { - secretChatPlaceholder.setBackgroundResource(R.drawable.system_black); - } else { - secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue); - } - secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text); - secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12)); - - View v = contentView.findViewById(R.id.secret_placeholder); - v.setVisibility(View.VISIBLE); - - if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) { - if (currentUser.first_name.length() > 0) { - secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.first_name)); - } else { - secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.last_name)); - } - } else { - if (currentUser.first_name.length() > 0) { - secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.first_name)); - } else { - secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.last_name)); - } - } - - updateSecretStatus(); - } - if (isCustomTheme) { progressViewInner.setBackgroundResource(R.drawable.system_loader2); emptyView.setBackgroundResource(R.drawable.system_black); @@ -1261,6 +1232,38 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not chatActivityEnterView.setContainerView(getParentActivity(), fragmentView); chatActivityEnterView.addToAttachLayout(menuItem); + + if (currentEncryptedChat != null) { + emptyView.setVisibility(View.INVISIBLE); + View secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder); + secretChatPlaceholder.setVisibility(View.VISIBLE); + if (isCustomTheme) { + secretChatPlaceholder.setBackgroundResource(R.drawable.system_black); + } else { + secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue); + } + secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text); + secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12)); + + View v = contentView.findViewById(R.id.secret_placeholder); + v.setVisibility(View.VISIBLE); + + if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) { + if (currentUser.first_name.length() > 0) { + secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.first_name)); + } else { + secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.last_name)); + } + } else { + if (currentUser.first_name.length() > 0) { + secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.first_name)); + } else { + secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.last_name)); + } + } + + updateSecretStatus(); + } } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -2544,6 +2547,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not cell.setAllowedToSetPhoto(true); } } + + if (currentUser != null) { + MessagesController.getInstance().loadFullUser(MessagesController.getInstance().getUser(currentUser.id), classGuid); + } } private void updateBottomOverlay() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java index 97b858682..732a99d82 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java @@ -223,6 +223,9 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter fragmentView = inflater.inflate(R.layout.messages_list, container, false); dialogsAdapter = new DialogsAdapter(getParentActivity(), serverOnly); + if (AndroidUtilities.isTablet() && openedDialogId != 0) { + dialogsAdapter.setOpenedDialogId(openedDialogId); + } dialogsSearchAdapter = new DialogsSearchAdapter(getParentActivity(), !onlySelect); dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() { @Override @@ -527,9 +530,6 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter @SuppressWarnings("unchecked") public void didReceivedNotification(int id, Object... args) { if (id == NotificationCenter.dialogsNeedReload) { - if (dialogsAdapter != null) { - dialogsAdapter.notifyDataSetChanged(); - } if (messagesListView != null) { if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { searchEmptyView.setVisibility(View.GONE); @@ -537,14 +537,33 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter messagesListView.setEmptyView(progressView); } else { if (searching && searchWas) { + if (dialogsAdapter != null) { + dialogsAdapter.notifyDataSetChanged(); + } + if (dialogsSearchAdapter != null) { + dialogsSearchAdapter.notifyDataSetChanged(); + } messagesListView.setEmptyView(searchEmptyView); emptyView.setVisibility(View.GONE); } else { + if (dialogsAdapter != null) { + dialogsAdapter.notifyDataSetChanged(); + } + if (dialogsSearchAdapter != null) { + dialogsSearchAdapter.notifyDataSetChanged(); + } messagesListView.setEmptyView(emptyView); searchEmptyView.setVisibility(View.GONE); } progressView.setVisibility(View.GONE); } + } else { + if (dialogsAdapter != null) { + dialogsAdapter.notifyDataSetChanged(); + } + if (dialogsSearchAdapter != null) { + dialogsSearchAdapter.notifyDataSetChanged(); + } } } else if (id == NotificationCenter.emojiDidLoaded) { if (messagesListView != null) { @@ -569,7 +588,9 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter } else { openedDialogId = dialog_id; } - dialogsAdapter.setOpenedDialogId(openedDialogId); + if (dialogsAdapter != null) { + dialogsAdapter.setOpenedDialogId(openedDialogId); + } updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } 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 82a2a4264..0f919459a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java @@ -695,6 +695,9 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen } public void setFieldText(String text) { + if (messsageEditText == null) { + return; + } ignoreTextChange = true; messsageEditText.setText(text); messsageEditText.setSelection(messsageEditText.getText().length()); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionsListView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionsListView.java index 9d2ebbecf..ca3b4e248 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionsListView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionsListView.java @@ -17,6 +17,7 @@ import android.widget.AbsListView; import android.widget.ListAdapter; import android.widget.ListView; +import org.telegram.android.AndroidUtilities; import org.telegram.android.LocaleController; import org.telegram.messenger.FileLog; import org.telegram.ui.Adapters.BaseSectionsAdapter; @@ -112,7 +113,12 @@ public class SectionsListView extends ListView implements AbsListView.OnScrollLi header.setTag(-header.getHeight()); } else if (pos == count - 2) { View child = getChildAt(itemNum - firstVisibleItem); - int headerTop = child.getTop(); + int headerTop = 0; + if (child != null) { + headerTop = child.getTop(); + } else { + headerTop = -AndroidUtilities.dp(100); + } if (headerTop < 0) { header.setTag(headerTop); } else { @@ -124,7 +130,9 @@ public class SectionsListView extends ListView implements AbsListView.OnScrollLi itemNum += count - mAdapter.getPositionInSectionForPosition(firstVisibleItem); } else { View child = getChildAt(itemNum - firstVisibleItem); - header.setTag(child.getTop()); + if (child != null) { + header.setTag(child.getTop()); + } itemNum += count; } }