Bug fixes

This commit is contained in:
DrKLO 2014-08-08 14:17:06 +04:00
parent 5d042955cd
commit 8f7652bb7e
18 changed files with 117 additions and 32 deletions

View file

@ -892,10 +892,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
public void loadChatInfo(final int chat_id) {
public void loadChatInfo(final int chat_id, Semaphore semaphore) {
currentChatInfo = null;
chatParticipantsId = chat_id;
MessagesStorage.getInstance().loadChatInfo(chat_id);
MessagesStorage.getInstance().loadChatInfo(chat_id, semaphore);
}
public void processChatInfo(final int chat_id, final TLRPC.ChatParticipants info, final ArrayList<TLRPC.User> usersArr, final boolean fromCache) {
@ -1605,7 +1605,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
public void markDialogAsRead(final long dialog_id, final int max_id, final int max_positive_id, final int offset, final int max_date, final boolean was) {
public void markDialogAsRead(final long dialog_id, final int max_id, final int max_positive_id, final int offset, final int max_date, final boolean was, final boolean popup) {
int lower_part = (int)dialog_id;
int high_id = (int)(dialog_id >> 32);
@ -1643,10 +1643,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
dialog.unread_count = 0;
NotificationCenter.getInstance().postNotificationName(dialogsNeedReload);
}
NotificationsController.getInstance().processReadMessages(null, dialog_id, 0, max_positive_id);
HashMap<Long, Integer> dialogsToUpdate = new HashMap<Long, Integer>();
dialogsToUpdate.put(dialog_id, 0);
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true);
if (!popup) {
NotificationsController.getInstance().processReadMessages(null, dialog_id, 0, max_positive_id);
HashMap<Long, Integer> dialogsToUpdate = new HashMap<Long, Integer>();
dialogsToUpdate.put(dialog_id, 0);
NotificationsController.getInstance().processDialogsUpdateRead(dialogsToUpdate, true);
}
}
});
}
@ -1660,7 +1662,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
MessagesStorage.getInstance().processPendingRead(dialog_id, max_positive_id, max_date, true);
TLRPC.TL_messages_affectedHistory res = (TLRPC.TL_messages_affectedHistory) response;
if (res.offset > 0) {
markDialogAsRead(dialog_id, 0, max_positive_id, res.offset, max_date, was);
markDialogAsRead(dialog_id, 0, max_positive_id, res.offset, max_date, was, popup);
}
if (MessagesStorage.lastSeqValue + 1 == res.seq) {

View file

@ -755,7 +755,7 @@ public class MessagesStorage {
});
}
public void loadChatInfo(final int chat_id) {
public void loadChatInfo(final int chat_id, final Semaphore semaphore) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
@ -809,9 +809,16 @@ public class MessagesStorage {
updateChatInfo(chat_id, info, false);
}
}
if (semaphore != null) {
semaphore.release();
}
MessagesController.getInstance().processChatInfo(chat_id, info, loadedUsers, true);
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
if (semaphore != null) {
semaphore.release();
}
}
}
});
@ -946,6 +953,9 @@ public class MessagesStorage {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (!needEncrypted && chat.id < 0) {
continue;
}
resultArrayNames.add(Utilities.generateSearchName(chat.title, null, q));
resultArray.add(chat);
}

View file

@ -24,8 +24,8 @@ import java.util.zip.ZipFile;
public class NativeLoader {
private static final long sizes[] = new long[] {
799376, //armeabi
852644, //armeabi-v7a
803472, //armeabi
856740, //armeabi-v7a
1250356, //x86
0, //mips
};

View file

@ -63,12 +63,12 @@ public class FileLog {
e.printStackTrace();
}
try {
logQueue = new DispatchQueue("logQueue");
currentFile.createNewFile();
FileOutputStream stream = new FileOutputStream(currentFile);
streamWriter = new OutputStreamWriter(stream);
streamWriter.write("-----start log " + dateFormat.format(System.currentTimeMillis()) + "-----\n");
streamWriter.flush();
logQueue = new DispatchQueue("logQueue");
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -394,7 +394,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
photoHeight = h;
backgroundWidth = w + AndroidUtilities.dp(12);
currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / AndroidUtilities.density), (int) (h / AndroidUtilities.density));
if (messageObject.photoThumbs.size() > 1) {
if (messageObject.photoThumbs.size() > 1 || messageObject.type == 3 || messageObject.type == 8) {
currentPhotoFilter += "_b";
}

View file

@ -214,13 +214,24 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
return false;
}
}
MessagesController.getInstance().loadChatInfo(currentChat.id);
if (chatId > 0) {
dialog_id = -chatId;
} else {
isBraodcast = true;
dialog_id = AndroidUtilities.makeBroadcastId(chatId);
}
Semaphore semaphore = null;
if (isBraodcast) {
semaphore = new Semaphore(0);
}
MessagesController.getInstance().loadChatInfo(currentChat.id, semaphore);
if (isBraodcast) {
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
} else if (userId != 0) {
currentUser = MessagesController.getInstance().users.get(userId);
if (currentUser == null) {
@ -878,7 +889,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
if (show) {
if (pagedownButton.getVisibility() == View.GONE) {
if (android.os.Build.VERSION.SDK_INT >= 12 && animated) {
if (android.os.Build.VERSION.SDK_INT > 13 && animated) {
pagedownButton.setVisibility(View.VISIBLE);
pagedownButton.setAlpha(0);
pagedownButton.animate().alpha(1).setDuration(200).start();
@ -888,7 +899,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
} else {
if (pagedownButton.getVisibility() == View.VISIBLE) {
if (android.os.Build.VERSION.SDK_INT >= 12 && animated) {
if (android.os.Build.VERSION.SDK_INT > 13 && animated) {
pagedownButton.animate().alpha(0).setDuration(200).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
@ -1902,9 +1913,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (first && messages.size() > 0) {
if (last_unread_id != 0) {
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, last_unread_id, 0, last_unread_date, wasUnread);
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, last_unread_id, 0, last_unread_date, wasUnread, false);
} else {
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, wasUnread);
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, wasUnread, false);
}
first = false;
}
@ -1985,7 +1996,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
readWithMid = currentMinMsgId;
} else {
if (messages.size() > 0) {
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, currentMinMsgId, 0, currentMaxDate, true);
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, currentMinMsgId, 0, currentMaxDate, true, false);
}
}
}
@ -2088,7 +2099,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
readWithDate = maxDate;
readWithMid = minMessageId;
} else {
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, true);
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, true, false);
}
}
}
@ -2444,7 +2455,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
messageObject.messageOwner.unread = false;
}
readWhenResume = false;
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, readWithMid, 0, readWithDate, true);
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, readWithMid, 0, readWithDate, true, false);
}
fixLayout(true);

View file

@ -291,7 +291,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
@Override
public void restoreSelfArgs(Bundle args) {
MessagesController.getInstance().loadChatInfo(chat_id);
MessagesController.getInstance().loadChatInfo(chat_id, null);
if (avatarUpdater != null) {
avatarUpdater.currentPicturePath = args.getString("path");
}

View file

@ -8,7 +8,9 @@
package org.telegram.ui;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -39,6 +41,8 @@ import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import java.util.List;
public class LocationActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private GoogleMap googleMap;
private TextView distanceTextView;
@ -164,8 +168,7 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
positionMarker(location);
}
});
myLocation = googleMap.getMyLocation();
myLocation = getLastLocation();
if (sendButton != null) {
userLocation = new Location("network");
@ -249,6 +252,19 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
return fragmentView;
}
private Location getLastLocation() {
LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
List<String> providers = lm.getProviders(true);
Location l = null;
for (int i = providers.size() - 1; i >= 0; i--) {
l = lm.getLastKnownLocation(providers.get(i));
if (l != null) {
break;
}
}
return l;
}
private void updateUserData() {
if (messageObject != null && avatarImageView != null) {
int fromId = messageObject.messageOwner.from_id;

View file

@ -54,9 +54,12 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
private Bundle currentParams;
private Timer timeTimer;
private Timer codeTimer;
private static final Integer timerSync = 1;
private volatile int time = 60000;
private volatile int codeTime = 15000;
private double lastCurrentTime;
private double lastCodeTime;
private boolean waitingForSms = false;
private boolean nextPressed = false;
private String lastError = "";
@ -162,6 +165,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
codeField.requestFocus();
destroyTimer();
destroyCodeTimer();
timeText.setText(String.format("%s 1:00", LocaleController.getString("CallText", R.string.CallText)));
lastCurrentTime = System.currentTimeMillis();
problemText.setVisibility(time < 1000 ? VISIBLE : GONE);
@ -169,6 +173,46 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
createTimer();
}
private void createCodeTimer() {
if (codeTimer != null) {
return;
}
codeTime = 15000;
codeTimer = new Timer();
lastCodeTime = System.currentTimeMillis();
codeTimer.schedule(new TimerTask() {
@Override
public void run() {
double currentTime = System.currentTimeMillis();
double diff = currentTime - lastCodeTime;
codeTime -= diff;
lastCodeTime = currentTime;
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
if (codeTime <= 1000) {
problemText.setVisibility(VISIBLE);
destroyCodeTimer();
}
}
});
}
}, 0, 1000);
}
private void destroyCodeTimer() {
try {
synchronized(timerSync) {
if (codeTimer != null) {
codeTimer.cancel();
codeTimer = null;
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
private void createTimer() {
if (timeTimer != null) {
return;
@ -189,9 +233,9 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
int seconds = time / 1000 - minutes * 60;
timeText.setText(String.format("%s %d:%02d", LocaleController.getString("CallText", R.string.CallText), minutes, seconds));
} else {
problemText.setVisibility(VISIBLE);
timeText.setText(LocaleController.getString("Calling", R.string.Calling));
destroyTimer();
createCodeTimer();
TLRPC.TL_auth_sendCall req = new TLRPC.TL_auth_sendCall();
req.phone_number = requestPhone;
req.phone_code_hash = phoneHash;
@ -259,6 +303,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
if (error == null) {
TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization)response;
destroyTimer();
destroyCodeTimer();
UserConfig.clearConfig();
MessagesController.getInstance().cleanUp();
UserConfig.setCurrentUser(res.user);
@ -280,6 +325,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
params.putString("code", req.phone_code);
delegate.setPage(2, true, params, false);
destroyTimer();
destroyCodeTimer();
} else {
createTimer();
if (error.text.contains("PHONE_NUMBER_INVALID")) {
@ -304,6 +350,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
@Override
public void onBackPressed() {
destroyTimer();
destroyCodeTimer();
currentParams = null;
AndroidUtilities.setWaitingForSms(false);
NotificationCenter.getInstance().removeObserver(this, 998);
@ -316,6 +363,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente
AndroidUtilities.setWaitingForSms(false);
NotificationCenter.getInstance().removeObserver(this, 998);
destroyTimer();
destroyCodeTimer();
waitingForSms = false;
}

View file

@ -161,7 +161,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
return;
}
NotificationsController.getInstance().popupMessages.remove(currentMessageNum);
MessagesController.getInstance().markDialogAsRead(currentMessageObject.getDialogId(), currentMessageObject.messageOwner.id, Math.max(0, currentMessageObject.messageOwner.id), 0, currentMessageObject.messageOwner.date, true);
MessagesController.getInstance().markDialogAsRead(currentMessageObject.getDialogId(), currentMessageObject.messageOwner.id, Math.max(0, currentMessageObject.messageOwner.id), 0, currentMessageObject.messageOwner.date, true, true);
currentMessageObject = null;
getNewMessage();
}