Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Nov 19, 2014
1 parent ea8760f commit ba4cf58
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 40 deletions.
4 changes: 2 additions & 2 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 386
versionName "2.0.0"
versionCode 388
versionName "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ public void run() {

final HashMap<Integer, TLRPC.User> usersDict = new HashMap<Integer, TLRPC.User>();

final boolean isEmpty = contactsArr.isEmpty();

if (!contacts.isEmpty()) {
for (int a = 0; a < contactsArr.size(); a++) {
TLRPC.TL_contact contact = contactsArr.get(a);
Expand Down Expand Up @@ -1003,6 +1005,12 @@ public void run() {
updateUnregisteredContacts(contactsArr);

NotificationCenter.getInstance().postNotificationName(NotificationCenter.contactsDidLoaded);

if (from != 1 && !isEmpty) {
saveContactsLoadTime();
} else {
reloadContactsStatusesMaybe();
}
}
});

Expand Down Expand Up @@ -1037,6 +1045,27 @@ public void run() {
});
}

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<TLRPC.TL_contact> contactsArr) {
final HashMap<String, TLRPC.TL_contact> contactsPhonesShort = new HashMap<String, TLRPC.TL_contact>();

Expand Down Expand Up @@ -1586,6 +1615,7 @@ public void run() {
}

public void reloadContactsStatuses() {
saveContactsLoadTime();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("needGetStatuses", true).commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ public boolean presentFragment(final BaseFragment fragment, final boolean remove
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);
}
Expand Down Expand Up @@ -698,6 +702,10 @@ public void closeLastFragment(boolean animated) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ public void cancelCurrentAnimation() {
}

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(
Expand Down
71 changes: 39 additions & 32 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ public void onFragmentDestroy() {
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);
}
Expand Down Expand Up @@ -996,38 +999,6 @@ public boolean onTouch(View v, MotionEvent event) {
}
}

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);
Expand Down Expand Up @@ -1261,6 +1232,38 @@ public void onClick(DialogInterface dialogInterface, int i) {

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) {
Expand Down Expand Up @@ -2544,6 +2547,10 @@ public void onOpenAnimationEnd() {
cell.setAllowedToSetPhoto(true);
}
}

if (currentUser != null) {
MessagesController.getInstance().loadFullUser(MessagesController.getInstance().getUser(currentUser.id), classGuid);
}
}

private void updateBottomOverlay() {
Expand Down
29 changes: 25 additions & 4 deletions TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ public void onItemClick(int id) {
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
Expand Down Expand Up @@ -527,24 +530,40 @@ public void onGlobalLayout() {
@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);
emptyView.setVisibility(View.GONE);
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) {
Expand All @@ -569,7 +588,9 @@ public void didReceivedNotification(int id, Object... args) {
} else {
openedDialogId = dialog_id;
}
dialogsAdapter.setOpenedDialogId(openedDialogId);
if (dialogsAdapter != null) {
dialogsAdapter.setOpenedDialogId(openedDialogId);
}
updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ public void setDialogId(long id) {
}

public void setFieldText(String text) {
if (messsageEditText == null) {
return;
}
ignoreTextChange = true;
messsageEditText.setText(text);
messsageEditText.setSelection(messsageEditText.getText().length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -112,7 +113,12 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
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 {
Expand All @@ -124,7 +130,9 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
itemNum += count - mAdapter.getPositionInSectionForPosition(firstVisibleItem);
} else {
View child = getChildAt(itemNum - firstVisibleItem);
header.setTag(child.getTop());
if (child != null) {
header.setTag(child.getTop());
}
itemNum += count;
}
}
Expand Down

0 comments on commit ba4cf58

Please sign in to comment.