Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Apr 25, 2016
1 parent fe9e23e commit 1c74ed4
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,8 @@ public void run() {
AndroidUtilities.addMediaToGallery(finalFile.toString());
}
}
ImageLoader.this.fileDidLoaded(location, finalFile, type);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.FileDidLoaded, location);
ImageLoader.this.fileDidLoaded(location, finalFile, type);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,8 @@ public String getForwardedName() {

public void checkMediaExistance() {
File cacheFile = null;
attachPathExists = false;
mediaExists = false;
if (type == 1) {
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize());
if (currentPhotoObject != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,34 +268,34 @@ public void didReceivedNotification(int id, final Object... args) {
if (file != null && media != null) {
if (message.type == 0) {
media.file = file;
performSendMessageRequest(message.sendRequest, message.obj.messageOwner, message.originalPath);
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
} else if (message.type == 1) {
if (media.file == null) {
media.file = file;
if (media.thumb == null && message.location != null) {
performSendDelayedMessage(message);
} else {
performSendMessageRequest(message.sendRequest, message.obj.messageOwner, message.originalPath);
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else {
media.thumb = file;
performSendMessageRequest(message.sendRequest, message.obj.messageOwner, message.originalPath);
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else if (message.type == 2) {
if (media.file == null) {
media.file = file;
if (media.thumb == null && message.location != null) {
performSendDelayedMessage(message);
} else {
performSendMessageRequest(message.sendRequest, message.obj.messageOwner, message.originalPath);
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else {
media.thumb = file;
performSendMessageRequest(message.sendRequest, message.obj.messageOwner, message.originalPath);
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else if (message.type == 3) {
media.file = file;
performSendMessageRequest(message.sendRequest, message.obj.messageOwner, message.originalPath);
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
arr.remove(a);
a--;
Expand Down Expand Up @@ -838,6 +838,7 @@ public void sendMessage(ArrayList<MessageObject> messages, final long peer, bool
}

final ArrayList<TLRPC.Message> newMsgObjArr = arr;
final ArrayList<MessageObject> newMsgArr = objArr;
final HashMap<Long, TLRPC.Message> messagesByRandomIdsFinal = messagesByRandomIds;
final boolean isMegagroupFinal = isMegagroup;
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
Expand Down Expand Up @@ -875,12 +876,13 @@ public void run(TLObject response, final TLRPC.TL_error error) {
if (newMsgObj == null) {
continue;
}
MessageObject msgObj = newMsgArr.get(newMsgObjArr.indexOf(newMsgObj));
newMsgObjArr.remove(newMsgObj);
final int oldId = newMsgObj.id;
final ArrayList<TLRPC.Message> sentMessages = new ArrayList<>();
sentMessages.add(message);
newMsgObj.id = message.id;
processSentMessage(newMsgObj, message, null, true);
updateMediaPaths(msgObj, message, null, true);
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -1479,7 +1481,7 @@ private void sendMessage(String message, TLRPC.MessageMedia location, TLRPC.TL_p
reqSend.contacts = sendToPeers;
reqSend.media = new TLRPC.TL_inputMediaEmpty();
reqSend.random_id = random_ids;
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
} else {
TLRPC.TL_messages_sendMessage reqSend = new TLRPC.TL_messages_sendMessage();
reqSend.message = message;
Expand All @@ -1498,7 +1500,7 @@ private void sendMessage(String message, TLRPC.MessageMedia location, TLRPC.TL_p
if (!searchLinks) {
reqSend.no_webpage = true;
}
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
}
} else {
TLRPC.TL_decryptedMessage reqSend;
Expand Down Expand Up @@ -1694,32 +1696,32 @@ private void sendMessage(String message, TLRPC.MessageMedia location, TLRPC.TL_p
reqSend = request;
}
if (type == 1) {
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
} else if (type == 2) {
if (photo.access_hash == 0) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
}
} else if (type == 3) {
if (document.access_hash == 0) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
}
} else if (type == 6) {
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
} else if (type == 7) {
if (document.access_hash == 0 && delayedMessage != null) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj.messageOwner, originalPath);
performSendMessageRequest(reqSend, newMsgObj, originalPath);
}
} else if (type == 8) {
if (document.access_hash == 0) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
}
}
} else {
Expand Down Expand Up @@ -2010,7 +2012,7 @@ private void sendMessage(String message, TLRPC.MessageMedia location, TLRPC.TL_p
if (asAdmin && reqSend.to_peer.channel_id != 0) {
reqSend.broadcast = true;
}
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
} else if (type == 9) {
TLRPC.TL_messages_sendInlineBotResult reqSend = new TLRPC.TL_messages_sendInlineBotResult();
reqSend.peer = sendToPeer;
Expand All @@ -2027,7 +2029,7 @@ private void sendMessage(String message, TLRPC.MessageMedia location, TLRPC.TL_p
}
reqSend.query_id = Utilities.parseLong(params.get("query_id"));
reqSend.id = params.get("id");
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
performSendMessageRequest(reqSend, newMsgObj, null);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
Expand Down Expand Up @@ -2185,7 +2187,8 @@ public boolean isSendingMessage(int mid) {
return sendingMessages.containsKey(mid);
}

private void performSendMessageRequest(final TLObject req, final TLRPC.Message newMsgObj, final String originalPath) {
private void performSendMessageRequest(final TLObject req, final MessageObject msgObj, final String originalPath) {
final TLRPC.Message newMsgObj = msgObj.messageOwner;
putToSendingMessages(newMsgObj);
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
Expand Down Expand Up @@ -2252,7 +2255,7 @@ public void run() {
}
if (message != null) {
newMsgObj.id = message.id;
processSentMessage(newMsgObj, message, originalPath, false);
updateMediaPaths(msgObj, message, originalPath, false);
} else {
isSentError = true;
}
Expand Down Expand Up @@ -2329,7 +2332,8 @@ public void run() {
}, ConnectionsManager.RequestFlagCanCompress | ConnectionsManager.RequestFlagInvokeAfter | (req instanceof TLRPC.TL_messages_sendMessage ? ConnectionsManager.RequestFlagNeedQuickAck : 0));
}

private void processSentMessage(TLRPC.Message newMsg, TLRPC.Message sentMessage, String originalPath, boolean post) {
private void updateMediaPaths(MessageObject newMsgObj, TLRPC.Message sentMessage, String originalPath, boolean post) {
TLRPC.Message newMsg = newMsgObj.messageOwner;
if (sentMessage == null) {
return;
}
Expand Down Expand Up @@ -2436,6 +2440,8 @@ private void processSentMessage(TLRPC.Message newMsg, TLRPC.Message sentMessage,
sentMessage.attachPath = newMsg.attachPath;
sentMessage.message = newMsg.message;
} else if (!MessageObject.isVideoMessage(sentMessage)) {
newMsgObj.mediaExists = newMsgObj.attachPathExists;
newMsgObj.attachPathExists = false;
newMsg.attachPath = "";
if (originalPath != null && originalPath.startsWith("http")) {
MessagesStorage.getInstance().addRecentLocalFile(originalPath, cacheFile2.toString(), newMsg.media.document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
Expand All @@ -28,6 +29,7 @@
import android.widget.LinearLayout;

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.AnimationCompat.AnimatorListenerAdapterProxy;
Expand All @@ -50,6 +52,9 @@ public interface ActionBarLayoutDelegate {

public class LinearLayoutContainer extends LinearLayout {

private Rect rect = new Rect();
private boolean isKeyboardVisible;

public LinearLayoutContainer(Context context) {
super(context);
setOrientation(VERTICAL);
Expand Down Expand Up @@ -87,12 +92,32 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
public boolean hasOverlappingRendering() {
return false;
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);

View rootView = getRootView();
getWindowVisibleDisplayFrame(rect);
int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
isKeyboardVisible = usableViewHeight - (rect.bottom - rect.top) > 0;
if (BuildVars.DEBUG_VERSION) {
FileLog.e("tmessages", "keyboard visible = " + isKeyboardVisible + " for " + this);
}
if (waitingForKeyboardCloseRunnable != null && !containerView.isKeyboardVisible && !containerViewBack.isKeyboardVisible) {
AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
waitingForKeyboardCloseRunnable.run();
waitingForKeyboardCloseRunnable = null;
}
}
}

private static Drawable headerShadowDrawable;
private static Drawable layerShadowDrawable;
private static Paint scrimPaint;

private Runnable waitingForKeyboardCloseRunnable;

private LinearLayoutContainer containerView;
private LinearLayoutContainer containerViewBack;
private DrawerLayoutContainer drawerLayoutContainer;
Expand Down Expand Up @@ -494,6 +519,10 @@ public void onLowMemory() {
private void onAnimationEndCheck(boolean byCheck) {
onCloseAnimationEnd(false);
onOpenAnimationEnd(false);
if (waitingForKeyboardCloseRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
waitingForKeyboardCloseRunnable = null;
}
if (currentAnimation != null) {
if (byCheck) {
currentAnimation.cancel();
Expand All @@ -514,7 +543,7 @@ private void onAnimationEndCheck(boolean byCheck) {
}

public boolean checkTransitionAnimation() {
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 1000) {
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 1500) {
onAnimationEndCheck(true);
}
return transitionAnimationInProgress;
Expand Down Expand Up @@ -718,7 +747,21 @@ public void run() {
if (animation == null) {
ViewProxy.setAlpha(containerView, 0.0f);
ViewProxy.setTranslationX(containerView, 48.0f);
startLayoutAnimation(true, true);
if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) {
waitingForKeyboardCloseRunnable = new Runnable() {
@Override
public void run() {
FileLog.e("tmessages", "start delayed by keyboard open animation");
if (waitingForKeyboardCloseRunnable != this) {
return;
}
startLayoutAnimation(true, true);
}
};
AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 200);
} else {
startLayoutAnimation(true, true);
}
} else {
if (Build.VERSION.SDK_INT > 15) {
//containerView.setLayerType(LAYER_TYPE_HARDWARE, null);
Expand Down Expand Up @@ -868,7 +911,21 @@ public void run() {
}
});
if (animation == null) {
startLayoutAnimation(false, true);
if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) {
waitingForKeyboardCloseRunnable = new Runnable() {
@Override
public void run() {
if (waitingForKeyboardCloseRunnable != this) {
return;
}
FileLog.e("tmessages", "start delayed by keyboard close animation");
startLayoutAnimation(false, true);
}
};
AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 200);
} else {
startLayoutAnimation(false, true);
}
} else {
if (Build.VERSION.SDK_INT > 15) {
//containerView.setLayerType(LAYER_TYPE_HARDWARE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ public void onItemClick(int id) {
}

public void clearItems() {
while(getChildCount() > 0) {
View view = getChildAt(0);
removeView(view);
}
removeAllViews();
}

public void onMenuButtonPressed() {
Expand Down
Loading

0 comments on commit 1c74ed4

Please sign in to comment.