2014-07-02 22:39:05 +00:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 1.4.x.
|
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013-2014.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.KeyguardManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2014-07-10 00:15:58 +00:00
|
|
|
import android.content.res.Configuration;
|
2015-02-01 18:51:02 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
2014-07-02 22:39:05 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.PowerManager;
|
2014-11-17 02:44:57 +00:00
|
|
|
import android.text.TextUtils;
|
2014-07-10 00:15:58 +00:00
|
|
|
import android.util.AttributeSet;
|
2014-07-02 22:39:05 +00:00
|
|
|
import android.util.TypedValue;
|
2014-07-10 12:14:36 +00:00
|
|
|
import android.view.Gravity;
|
2014-07-10 00:15:58 +00:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.VelocityTracker;
|
2014-07-02 22:39:05 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2014-07-10 00:15:58 +00:00
|
|
|
import android.view.ViewTreeObserver;
|
2014-07-02 22:39:05 +00:00
|
|
|
import android.view.WindowManager;
|
2014-07-10 00:15:58 +00:00
|
|
|
import android.view.animation.TranslateAnimation;
|
|
|
|
import android.widget.FrameLayout;
|
2014-07-02 22:39:05 +00:00
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.telegram.android.AndroidUtilities;
|
|
|
|
import org.telegram.android.ContactsController;
|
|
|
|
import org.telegram.android.LocaleController;
|
2014-07-10 00:15:58 +00:00
|
|
|
import org.telegram.android.MediaController;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.MessagesController;
|
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-07-10 00:15:58 +00:00
|
|
|
import org.telegram.android.NotificationsController;
|
2014-12-01 17:56:31 +00:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.MessageObject;
|
2014-11-13 20:10:14 +00:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
2014-12-01 17:56:31 +00:00
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
|
|
|
import org.telegram.ui.Components.ChatActivityEnterView;
|
|
|
|
import org.telegram.ui.Components.FrameLayoutFixed;
|
|
|
|
import org.telegram.ui.Components.PopupAudioView;
|
2015-02-26 01:32:51 +00:00
|
|
|
import org.telegram.ui.Components.SizeNotifierRelativeLayout;
|
2014-12-01 17:56:31 +00:00
|
|
|
import org.telegram.ui.Components.TypingDotsDrawable;
|
2014-07-10 00:15:58 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
2014-12-01 17:56:31 +00:00
|
|
|
import java.util.Locale;
|
2014-07-02 22:39:05 +00:00
|
|
|
|
|
|
|
public class PopupNotificationActivity extends Activity implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
private ActionBar actionBar;
|
2014-07-02 22:39:05 +00:00
|
|
|
private ChatActivityEnterView chatActivityEnterView;
|
|
|
|
private BackupImageView avatarImageView;
|
2014-11-17 02:44:57 +00:00
|
|
|
private TextView nameTextView;
|
|
|
|
private TextView onlineTextView;
|
|
|
|
private FrameLayout avatarContainer;
|
2014-07-02 22:39:05 +00:00
|
|
|
private TextView countText;
|
2014-07-10 00:15:58 +00:00
|
|
|
private ViewGroup messageContainer;
|
|
|
|
private ViewGroup centerView;
|
|
|
|
private ViewGroup leftView;
|
|
|
|
private ViewGroup rightView;
|
2015-01-02 22:15:07 +00:00
|
|
|
private ArrayList<ViewGroup> textViews = new ArrayList<>();
|
|
|
|
private ArrayList<ViewGroup> imageViews = new ArrayList<>();
|
|
|
|
private ArrayList<ViewGroup> audioViews = new ArrayList<>();
|
2014-07-10 00:15:58 +00:00
|
|
|
private VelocityTracker velocityTracker = null;
|
2014-09-24 02:17:27 +00:00
|
|
|
private TypingDotsDrawable typingDotsDrawable;
|
2014-07-02 22:39:05 +00:00
|
|
|
|
|
|
|
private int classGuid;
|
|
|
|
private TLRPC.User currentUser;
|
|
|
|
private TLRPC.Chat currentChat;
|
|
|
|
private boolean finished = false;
|
|
|
|
private CharSequence lastPrintString;
|
|
|
|
private MessageObject currentMessageObject = null;
|
|
|
|
private int currentMessageNum = 0;
|
|
|
|
private PowerManager.WakeLock wakeLock = null;
|
2014-07-10 00:15:58 +00:00
|
|
|
private boolean animationInProgress = false;
|
|
|
|
private long animationStartTime = 0;
|
|
|
|
private float moveStartX = -1;
|
|
|
|
private boolean startedMoving = false;
|
|
|
|
private Runnable onAnimationEndRunnable = null;
|
|
|
|
|
2014-07-10 12:14:36 +00:00
|
|
|
private class FrameLayoutTouch extends FrameLayoutFixed {
|
2014-07-10 00:15:58 +00:00
|
|
|
public FrameLayoutTouch(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public FrameLayoutTouch(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public FrameLayoutTouch(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
return checkTransitionAnimation() || ((PopupNotificationActivity) getContext()).onTouchEventMy(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
|
|
return checkTransitionAnimation() || ((PopupNotificationActivity) getContext()).onTouchEventMy(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
|
|
|
((PopupNotificationActivity)getContext()).onTouchEventMy(null);
|
|
|
|
super.requestDisallowInterceptTouchEvent(disallowIntercept);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 12:14:36 +00:00
|
|
|
public class FrameLayoutAnimationListener extends FrameLayoutFixed {
|
2014-07-10 00:15:58 +00:00
|
|
|
public FrameLayoutAnimationListener(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public FrameLayoutAnimationListener(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public FrameLayoutAnimationListener(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAnimationEnd() {
|
|
|
|
super.onAnimationEnd();
|
|
|
|
if (onAnimationEndRunnable != null) {
|
|
|
|
onAnimationEndRunnable.run();
|
|
|
|
onAnimationEndRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.pushMessagesUpdated);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
2014-07-02 22:39:05 +00:00
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
typingDotsDrawable = new TypingDotsDrawable();
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
SizeNotifierRelativeLayout contentView = new SizeNotifierRelativeLayout(this);
|
|
|
|
setContentView(contentView);
|
|
|
|
contentView.setBackgroundColor(0x99000000);
|
|
|
|
|
|
|
|
RelativeLayout relativeLayout = new RelativeLayout(this);
|
|
|
|
contentView.addView(relativeLayout);
|
|
|
|
RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();
|
|
|
|
layoutParams3.width = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams3.height = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
relativeLayout.setLayoutParams(layoutParams3);
|
|
|
|
|
|
|
|
RelativeLayout popupContainer = new RelativeLayout(this);
|
|
|
|
popupContainer.setBackgroundColor(0xffffffff);
|
|
|
|
relativeLayout.addView(popupContainer);
|
|
|
|
layoutParams3 = (RelativeLayout.LayoutParams) popupContainer.getLayoutParams();
|
|
|
|
layoutParams3.width = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams3.height = AndroidUtilities.dp(240);
|
|
|
|
layoutParams3.leftMargin = AndroidUtilities.dp(12);
|
|
|
|
layoutParams3.rightMargin = AndroidUtilities.dp(12);
|
|
|
|
layoutParams3.addRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
|
popupContainer.setLayoutParams(layoutParams3);
|
|
|
|
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.onDestroy();
|
|
|
|
}
|
2015-03-18 23:09:45 +00:00
|
|
|
chatActivityEnterView = new ChatActivityEnterView(this, contentView, null, false);
|
2015-02-26 01:32:51 +00:00
|
|
|
popupContainer.addView(chatActivityEnterView);
|
|
|
|
layoutParams3 = (RelativeLayout.LayoutParams) chatActivityEnterView.getLayoutParams();
|
|
|
|
layoutParams3.width = RelativeLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams3.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams3.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
|
|
chatActivityEnterView.setLayoutParams(layoutParams3);
|
2014-07-02 22:39:05 +00:00
|
|
|
chatActivityEnterView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
|
|
|
|
@Override
|
2015-03-26 17:34:47 +00:00
|
|
|
public void onMessageSend(String message) {
|
2014-07-10 00:15:58 +00:00
|
|
|
if (currentMessageObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-13 23:40:36 +00:00
|
|
|
if (currentMessageNum >= 0 && currentMessageNum < NotificationsController.getInstance().popupMessages.size()) {
|
|
|
|
NotificationsController.getInstance().popupMessages.remove(currentMessageNum);
|
|
|
|
}
|
2015-03-18 23:09:45 +00:00
|
|
|
MessagesController.getInstance().markDialogAsRead(currentMessageObject.getDialogId(), currentMessageObject.getId(), Math.max(0, currentMessageObject.getId()), 0, currentMessageObject.messageOwner.date, true, true);
|
2014-07-02 22:39:05 +00:00
|
|
|
currentMessageObject = null;
|
|
|
|
getNewMessage();
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
@Override
|
2015-04-09 18:00:14 +00:00
|
|
|
public void onTextChanged(CharSequence text, boolean big) {
|
2015-01-02 22:15:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
@Override
|
|
|
|
public void needSendTyping() {
|
|
|
|
if (currentMessageObject != null) {
|
|
|
|
MessagesController.getInstance().sendTyping(currentMessageObject.getDialogId(), classGuid);
|
|
|
|
}
|
|
|
|
}
|
2014-11-19 01:23:46 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttachButtonHidden() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttachButtonShow() {
|
|
|
|
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onWindowSizeChanged(int size) {
|
|
|
|
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
});
|
|
|
|
|
2014-07-10 00:15:58 +00:00
|
|
|
messageContainer = new FrameLayoutTouch(this);
|
|
|
|
popupContainer.addView(messageContainer, 0);
|
2014-07-02 22:39:05 +00:00
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar = new ActionBar(this);
|
2014-11-17 02:44:57 +00:00
|
|
|
actionBar.setOccupyStatusBar(false);
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
2015-02-26 01:32:51 +00:00
|
|
|
actionBar.setBackgroundColor(0xff54759e);
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setItemsBackground(R.drawable.bar_selector);
|
2014-07-02 22:39:05 +00:00
|
|
|
popupContainer.addView(actionBar);
|
|
|
|
ViewGroup.LayoutParams layoutParams = actionBar.getLayoutParams();
|
|
|
|
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
actionBar.setLayoutParams(layoutParams);
|
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2014-07-02 22:39:05 +00:00
|
|
|
View view = menu.addItemResource(2, R.layout.popup_count_layout);
|
|
|
|
countText = (TextView) view.findViewById(R.id.count_text);
|
|
|
|
|
2014-11-17 02:44:57 +00:00
|
|
|
avatarContainer = new FrameLayoutFixed(this);
|
|
|
|
avatarContainer.setBackgroundResource(R.drawable.bar_selector);
|
|
|
|
avatarContainer.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
actionBar.addView(avatarContainer);
|
|
|
|
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) avatarContainer.getLayoutParams();
|
|
|
|
layoutParams2.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams2.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams2.rightMargin = AndroidUtilities.dp(48);
|
|
|
|
layoutParams2.leftMargin = AndroidUtilities.dp(60);
|
|
|
|
layoutParams2.gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
avatarContainer.setLayoutParams(layoutParams2);
|
|
|
|
|
|
|
|
avatarImageView = new BackupImageView(this);
|
2015-04-09 18:00:14 +00:00
|
|
|
avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
|
2014-11-17 02:44:57 +00:00
|
|
|
avatarContainer.addView(avatarImageView);
|
|
|
|
layoutParams2 = (FrameLayout.LayoutParams) avatarImageView.getLayoutParams();
|
|
|
|
layoutParams2.width = AndroidUtilities.dp(42);
|
|
|
|
layoutParams2.height = AndroidUtilities.dp(42);
|
|
|
|
layoutParams2.topMargin = AndroidUtilities.dp(3);
|
|
|
|
avatarImageView.setLayoutParams(layoutParams2);
|
|
|
|
|
|
|
|
nameTextView = new TextView(this);
|
|
|
|
nameTextView.setTextColor(0xffffffff);
|
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
nameTextView.setLines(1);
|
|
|
|
nameTextView.setMaxLines(1);
|
|
|
|
nameTextView.setSingleLine(true);
|
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
nameTextView.setGravity(Gravity.LEFT);
|
|
|
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
avatarContainer.addView(nameTextView);
|
|
|
|
layoutParams2 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
|
|
|
|
layoutParams2.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams2.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams2.leftMargin = AndroidUtilities.dp(54);
|
|
|
|
layoutParams2.bottomMargin = AndroidUtilities.dp(22);
|
|
|
|
layoutParams2.gravity = Gravity.BOTTOM;
|
|
|
|
nameTextView.setLayoutParams(layoutParams2);
|
|
|
|
|
|
|
|
onlineTextView = new TextView(this);
|
|
|
|
onlineTextView.setTextColor(0xffd7e8f7);
|
|
|
|
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
onlineTextView.setLines(1);
|
|
|
|
onlineTextView.setMaxLines(1);
|
|
|
|
onlineTextView.setSingleLine(true);
|
|
|
|
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
onlineTextView.setGravity(Gravity.LEFT);
|
|
|
|
avatarContainer.addView(onlineTextView);
|
|
|
|
layoutParams2 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
|
|
|
|
layoutParams2.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams2.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams2.leftMargin = AndroidUtilities.dp(54);
|
|
|
|
layoutParams2.bottomMargin = AndroidUtilities.dp(4);
|
|
|
|
layoutParams2.gravity = Gravity.BOTTOM;
|
|
|
|
onlineTextView.setLayoutParams(layoutParams2);
|
2014-07-02 22:39:05 +00:00
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
2014-07-02 22:39:05 +00:00
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2014-07-10 00:15:58 +00:00
|
|
|
onFinish();
|
2014-07-02 22:39:05 +00:00
|
|
|
finish();
|
|
|
|
} else if (id == 1) {
|
|
|
|
openCurrentMessage();
|
|
|
|
} else if (id == 2) {
|
2014-07-10 00:15:58 +00:00
|
|
|
switchToNextMessage();
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-01 17:56:31 +00:00
|
|
|
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
2014-07-02 22:39:05 +00:00
|
|
|
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
|
2014-07-10 12:14:36 +00:00
|
|
|
wakeLock.setReferenceCounted(false);
|
2014-07-02 22:39:05 +00:00
|
|
|
|
|
|
|
handleIntent(getIntent());
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:15:58 +00:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
AndroidUtilities.checkDisplaySize();
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
handleIntent(intent);
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:15:58 +00:00
|
|
|
private void switchToNextMessage() {
|
|
|
|
if (NotificationsController.getInstance().popupMessages.size() > 1) {
|
|
|
|
if (currentMessageNum < NotificationsController.getInstance().popupMessages.size() - 1) {
|
|
|
|
currentMessageNum++;
|
|
|
|
} else {
|
|
|
|
currentMessageNum = 0;
|
|
|
|
}
|
|
|
|
currentMessageObject = NotificationsController.getInstance().popupMessages.get(currentMessageNum);
|
|
|
|
updateInterfaceForCurrentMessage(2);
|
|
|
|
countText.setText(String.format("%d/%d", currentMessageNum + 1, NotificationsController.getInstance().popupMessages.size()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToPreviousMessage() {
|
|
|
|
if (NotificationsController.getInstance().popupMessages.size() > 1) {
|
|
|
|
if (currentMessageNum > 0) {
|
|
|
|
currentMessageNum--;
|
|
|
|
} else {
|
|
|
|
currentMessageNum = NotificationsController.getInstance().popupMessages.size() - 1;
|
|
|
|
}
|
|
|
|
currentMessageObject = NotificationsController.getInstance().popupMessages.get(currentMessageNum);
|
|
|
|
updateInterfaceForCurrentMessage(1);
|
|
|
|
countText.setText(String.format("%d/%d", currentMessageNum + 1, NotificationsController.getInstance().popupMessages.size()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean checkTransitionAnimation() {
|
|
|
|
if (animationInProgress && animationStartTime < System.currentTimeMillis() - 400) {
|
|
|
|
animationInProgress = false;
|
|
|
|
if (onAnimationEndRunnable != null) {
|
|
|
|
onAnimationEndRunnable.run();
|
|
|
|
onAnimationEndRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return animationInProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onTouchEventMy(MotionEvent motionEvent) {
|
|
|
|
if (checkTransitionAnimation()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (motionEvent != null && motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
moveStartX = motionEvent.getX();
|
|
|
|
} else if (motionEvent != null && motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
float x = motionEvent.getX();
|
|
|
|
int diff = (int)(x - moveStartX);
|
|
|
|
if (moveStartX != -1 && !startedMoving) {
|
|
|
|
if (Math.abs(diff) > AndroidUtilities.dp(10)) {
|
|
|
|
startedMoving = true;
|
|
|
|
moveStartX = x;
|
|
|
|
AndroidUtilities.lockOrientation(this);
|
|
|
|
diff = 0;
|
|
|
|
if (velocityTracker == null) {
|
|
|
|
velocityTracker = VelocityTracker.obtain();
|
|
|
|
} else {
|
|
|
|
velocityTracker.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startedMoving) {
|
|
|
|
if (leftView == null && diff > 0) {
|
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
if (rightView == null && diff < 0) {
|
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.addMovement(motionEvent);
|
|
|
|
}
|
|
|
|
applyViewsLayoutParams(diff);
|
|
|
|
}
|
|
|
|
} else if (motionEvent == null || motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
if (motionEvent != null && startedMoving) {
|
2014-07-10 12:14:36 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) centerView.getLayoutParams();
|
2014-07-10 00:15:58 +00:00
|
|
|
int diff = (int)(motionEvent.getX() - moveStartX);
|
|
|
|
int width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
|
|
|
int moveDiff = 0;
|
|
|
|
int forceMove = 0;
|
|
|
|
View otherView = null;
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.computeCurrentVelocity(1000);
|
|
|
|
if (velocityTracker.getXVelocity() >= 3500) {
|
|
|
|
forceMove = 1;
|
|
|
|
} else if (velocityTracker.getXVelocity() <= -3500) {
|
|
|
|
forceMove = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((forceMove == 1 || diff > width / 3) && leftView != null) {
|
|
|
|
moveDiff = width - layoutParams.leftMargin;
|
|
|
|
otherView = leftView;
|
|
|
|
onAnimationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
animationInProgress = false;
|
|
|
|
switchToPreviousMessage();
|
|
|
|
AndroidUtilities.unlockOrientation(PopupNotificationActivity.this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else if ((forceMove == 2 || diff < -width / 3) && rightView != null) {
|
|
|
|
moveDiff = -width - layoutParams.leftMargin;
|
|
|
|
otherView = rightView;
|
|
|
|
onAnimationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
animationInProgress = false;
|
|
|
|
switchToNextMessage();
|
|
|
|
AndroidUtilities.unlockOrientation(PopupNotificationActivity.this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else if (layoutParams.leftMargin != 0) {
|
|
|
|
moveDiff = -layoutParams.leftMargin;
|
|
|
|
otherView = diff > 0 ? leftView : rightView;
|
|
|
|
onAnimationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
animationInProgress = false;
|
|
|
|
applyViewsLayoutParams(0);
|
|
|
|
AndroidUtilities.unlockOrientation(PopupNotificationActivity.this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (moveDiff != 0) {
|
|
|
|
int time = (int)(Math.abs((float)moveDiff / (float)width) * 200);
|
|
|
|
TranslateAnimation animation = new TranslateAnimation(0, moveDiff, 0, 0);
|
|
|
|
animation.setDuration(time);
|
|
|
|
centerView.startAnimation(animation);
|
|
|
|
if (otherView != null) {
|
|
|
|
animation = new TranslateAnimation(0, moveDiff, 0, 0);
|
|
|
|
animation.setDuration(time);
|
|
|
|
otherView.startAnimation(animation);
|
|
|
|
}
|
|
|
|
animationInProgress = true;
|
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
applyViewsLayoutParams(0);
|
|
|
|
}
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.recycle();
|
|
|
|
velocityTracker = null;
|
|
|
|
}
|
|
|
|
startedMoving = false;
|
|
|
|
moveStartX = -1;
|
|
|
|
}
|
|
|
|
return startedMoving;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyViewsLayoutParams(int xOffset) {
|
2014-07-10 12:14:36 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = null;
|
2014-07-10 00:15:58 +00:00
|
|
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
|
|
|
if (leftView != null) {
|
2014-07-10 12:14:36 +00:00
|
|
|
layoutParams = (FrameLayout.LayoutParams) leftView.getLayoutParams();
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
2014-07-10 00:15:58 +00:00
|
|
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.width = widht;
|
|
|
|
layoutParams.leftMargin = -widht + xOffset;
|
|
|
|
leftView.setLayoutParams(layoutParams);
|
|
|
|
}
|
|
|
|
if (centerView != null) {
|
2014-07-10 12:14:36 +00:00
|
|
|
layoutParams = (FrameLayout.LayoutParams) centerView.getLayoutParams();
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
2014-07-10 00:15:58 +00:00
|
|
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.width = widht;
|
|
|
|
layoutParams.leftMargin = xOffset;
|
|
|
|
centerView.setLayoutParams(layoutParams);
|
|
|
|
}
|
|
|
|
if (rightView != null) {
|
2014-07-10 12:14:36 +00:00
|
|
|
layoutParams = (FrameLayout.LayoutParams) rightView.getLayoutParams();
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
2014-07-10 00:15:58 +00:00
|
|
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.width = widht;
|
|
|
|
layoutParams.leftMargin = widht + xOffset;
|
|
|
|
rightView.setLayoutParams(layoutParams);
|
|
|
|
}
|
|
|
|
messageContainer.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ViewGroup getViewForMessage(int num, boolean applyOffset) {
|
|
|
|
if (NotificationsController.getInstance().popupMessages.size() == 1 && (num < 0 || num >= NotificationsController.getInstance().popupMessages.size())) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (num == -1) {
|
|
|
|
num = NotificationsController.getInstance().popupMessages.size() - 1;
|
|
|
|
} else if (num == NotificationsController.getInstance().popupMessages.size()) {
|
|
|
|
num = 0;
|
|
|
|
}
|
|
|
|
ViewGroup view = null;
|
|
|
|
MessageObject messageObject = NotificationsController.getInstance().popupMessages.get(num);
|
2014-12-01 17:56:31 +00:00
|
|
|
if (messageObject.type == 1 || messageObject.type == 4) {
|
2014-07-10 00:15:58 +00:00
|
|
|
if (imageViews.size() > 0) {
|
|
|
|
view = imageViews.get(0);
|
|
|
|
imageViews.remove(0);
|
|
|
|
} else {
|
|
|
|
view = new FrameLayoutAnimationListener(this);
|
|
|
|
view.addView(getLayoutInflater().inflate(R.layout.popup_image_layout, null));
|
|
|
|
view.setTag(2);
|
|
|
|
|
|
|
|
view.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
openCurrentMessage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TextView messageText = (TextView)view.findViewById(R.id.message_text);
|
|
|
|
BackupImageView imageView = (BackupImageView) view.findViewById(R.id.message_image);
|
2015-04-09 18:00:14 +00:00
|
|
|
imageView.setAspectFit(true);
|
2014-12-01 17:56:31 +00:00
|
|
|
|
|
|
|
if (messageObject.type == 1) {
|
2015-02-01 18:51:02 +00:00
|
|
|
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
|
|
|
|
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
|
2014-12-01 17:56:31 +00:00
|
|
|
boolean photoSet = false;
|
|
|
|
if (currentPhotoObject != null) {
|
|
|
|
boolean photoExist = true;
|
|
|
|
if (messageObject.type == 1) {
|
|
|
|
File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
|
|
|
|
if (!cacheFile.exists()) {
|
|
|
|
photoExist = false;
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
}
|
2014-12-01 17:56:31 +00:00
|
|
|
if (photoExist || MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
|
2015-02-01 18:51:02 +00:00
|
|
|
imageView.setImage(currentPhotoObject.location, "100_100", thumb.location, currentPhotoObject.size);
|
2014-07-10 00:15:58 +00:00
|
|
|
photoSet = true;
|
2014-12-01 17:56:31 +00:00
|
|
|
} else {
|
2015-02-01 18:51:02 +00:00
|
|
|
if (thumb != null) {
|
|
|
|
imageView.setImage(thumb.location, null, (Drawable) null);
|
2014-12-01 17:56:31 +00:00
|
|
|
photoSet = true;
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-01 17:56:31 +00:00
|
|
|
if (!photoSet) {
|
|
|
|
imageView.setVisibility(View.GONE);
|
|
|
|
messageText.setVisibility(View.VISIBLE);
|
|
|
|
messageText.setTextSize(TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
|
|
|
|
messageText.setText(messageObject.messageText);
|
|
|
|
} else {
|
|
|
|
imageView.setVisibility(View.VISIBLE);
|
|
|
|
messageText.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else if (messageObject.type == 4) {
|
|
|
|
messageText.setVisibility(View.GONE);
|
2014-07-10 00:15:58 +00:00
|
|
|
messageText.setText(messageObject.messageText);
|
|
|
|
imageView.setVisibility(View.VISIBLE);
|
2014-12-01 17:56:31 +00:00
|
|
|
double lat = messageObject.messageOwner.media.geo.lat;
|
|
|
|
double lon = messageObject.messageOwner.media.geo._long;
|
|
|
|
String currentUrl = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(AndroidUtilities.density)), lat, lon);
|
|
|
|
imageView.setImage(currentUrl, null, null);
|
2014-07-10 00:15:58 +00:00
|
|
|
}
|
|
|
|
} else if (messageObject.type == 2) {
|
|
|
|
PopupAudioView cell = null;
|
|
|
|
if (audioViews.size() > 0) {
|
|
|
|
view = audioViews.get(0);
|
|
|
|
audioViews.remove(0);
|
|
|
|
cell = (PopupAudioView)view.findViewWithTag(300);
|
|
|
|
} else {
|
|
|
|
view = new FrameLayoutAnimationListener(this);
|
|
|
|
view.addView(getLayoutInflater().inflate(R.layout.popup_audio_layout, null));
|
|
|
|
view.setTag(3);
|
|
|
|
|
|
|
|
view.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
openCurrentMessage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ViewGroup audioContainer = (ViewGroup)view.findViewById(R.id.audio_container);
|
|
|
|
cell = new PopupAudioView(this);
|
|
|
|
cell.setTag(300);
|
|
|
|
audioContainer.addView(cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
cell.setMessageObject(messageObject);
|
2014-08-22 14:24:33 +00:00
|
|
|
if (MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_AUDIO)) {
|
2014-07-10 00:15:58 +00:00
|
|
|
cell.downloadAudioIfNeed();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (textViews.size() > 0) {
|
|
|
|
view = textViews.get(0);
|
|
|
|
textViews.remove(0);
|
|
|
|
} else {
|
|
|
|
view = new FrameLayoutAnimationListener(this);
|
|
|
|
view.addView(getLayoutInflater().inflate(R.layout.popup_text_layout, null));
|
|
|
|
view.setTag(1);
|
|
|
|
|
|
|
|
View textContainer = view.findViewById(R.id.text_container);
|
|
|
|
textContainer.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
openCurrentMessage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
TextView messageText = (TextView)view.findViewById(R.id.message_text);
|
2014-12-01 17:56:31 +00:00
|
|
|
messageText.setTag(301);
|
2014-07-10 00:15:58 +00:00
|
|
|
messageText.setTextSize(TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
|
|
|
|
messageText.setText(messageObject.messageText);
|
|
|
|
}
|
|
|
|
if (view.getParent() == null) {
|
|
|
|
messageContainer.addView(view);
|
|
|
|
}
|
|
|
|
view.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
if (applyOffset) {
|
|
|
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
2014-07-10 12:14:36 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
2014-07-10 00:15:58 +00:00
|
|
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.width = widht;
|
|
|
|
if (num == currentMessageNum) {
|
|
|
|
layoutParams.leftMargin = 0;
|
|
|
|
} else if (num == currentMessageNum - 1) {
|
|
|
|
layoutParams.leftMargin = -widht;
|
|
|
|
} else if (num == currentMessageNum + 1) {
|
|
|
|
layoutParams.leftMargin = widht;
|
|
|
|
}
|
|
|
|
view.setLayoutParams(layoutParams);
|
|
|
|
view.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void reuseView(ViewGroup view) {
|
|
|
|
if (view == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int tag = (Integer)view.getTag();
|
|
|
|
view.setVisibility(View.GONE);
|
|
|
|
if (tag == 1) {
|
|
|
|
textViews.add(view);
|
|
|
|
} else if (tag == 2) {
|
|
|
|
imageViews.add(view);
|
|
|
|
} else if (tag == 3) {
|
|
|
|
audioViews.add(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void prepareLayouts(int move) {
|
|
|
|
if (move == 0) {
|
|
|
|
reuseView(centerView);
|
|
|
|
reuseView(leftView);
|
|
|
|
reuseView(rightView);
|
|
|
|
for (int a = currentMessageNum - 1; a < currentMessageNum + 2; a++) {
|
|
|
|
if (a == currentMessageNum - 1) {
|
|
|
|
leftView = getViewForMessage(a, true);
|
|
|
|
} else if (a == currentMessageNum) {
|
|
|
|
centerView = getViewForMessage(a, true);
|
|
|
|
} else if (a == currentMessageNum + 1) {
|
|
|
|
rightView = getViewForMessage(a, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (move == 1) {
|
|
|
|
reuseView(rightView);
|
|
|
|
rightView = centerView;
|
|
|
|
centerView = leftView;
|
|
|
|
leftView = getViewForMessage(currentMessageNum - 1, true);
|
|
|
|
} else if (move == 2) {
|
|
|
|
reuseView(leftView);
|
|
|
|
leftView = centerView;
|
|
|
|
centerView = rightView;
|
|
|
|
rightView = getViewForMessage(currentMessageNum + 1, true);
|
|
|
|
} else if (move == 3) {
|
|
|
|
if (rightView != null) {
|
2014-07-10 12:14:36 +00:00
|
|
|
int offset = ((FrameLayout.LayoutParams) rightView.getLayoutParams()).leftMargin;
|
2014-07-10 00:15:58 +00:00
|
|
|
reuseView(rightView);
|
|
|
|
rightView = getViewForMessage(currentMessageNum + 1, false);
|
|
|
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
2014-07-10 12:14:36 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) rightView.getLayoutParams();
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
2014-07-10 00:15:58 +00:00
|
|
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.width = widht;
|
|
|
|
layoutParams.leftMargin = offset;
|
|
|
|
rightView.setLayoutParams(layoutParams);
|
|
|
|
rightView.invalidate();
|
|
|
|
}
|
|
|
|
} else if (move == 4) {
|
|
|
|
if (leftView != null) {
|
2014-07-10 12:14:36 +00:00
|
|
|
int offset = ((FrameLayout.LayoutParams) leftView.getLayoutParams()).leftMargin;
|
2014-07-10 00:15:58 +00:00
|
|
|
reuseView(leftView);
|
|
|
|
leftView = getViewForMessage(0, false);
|
|
|
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
2014-07-10 12:14:36 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) leftView.getLayoutParams();
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
2014-07-10 00:15:58 +00:00
|
|
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.width = widht;
|
|
|
|
layoutParams.leftMargin = offset;
|
|
|
|
leftView.setLayoutParams(layoutParams);
|
|
|
|
leftView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayout() {
|
2014-11-17 02:44:57 +00:00
|
|
|
if (avatarContainer != null) {
|
|
|
|
avatarContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
if (avatarContainer != null) {
|
|
|
|
avatarContainer.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
}
|
|
|
|
int padding = (AndroidUtilities.getCurrentActionBarHeight() - AndroidUtilities.dp(48)) / 2;
|
|
|
|
avatarContainer.setPadding(avatarContainer.getPaddingLeft(), padding, avatarContainer.getPaddingRight(), padding);
|
|
|
|
return false;
|
2014-07-10 00:15:58 +00:00
|
|
|
}
|
2014-11-17 02:44:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (messageContainer != null) {
|
|
|
|
messageContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
messageContainer.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
if (!checkTransitionAnimation() && !startedMoving) {
|
|
|
|
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) messageContainer.getLayoutParams();
|
|
|
|
layoutParams.topMargin = AndroidUtilities.getCurrentActionBarHeight();
|
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(48);
|
|
|
|
layoutParams.width = ViewGroup.MarginLayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = ViewGroup.MarginLayoutParams.MATCH_PARENT;
|
|
|
|
messageContainer.setLayoutParams(layoutParams);
|
|
|
|
applyViewsLayoutParams(0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleIntent(Intent intent) {
|
2014-07-02 22:39:05 +00:00
|
|
|
KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
|
|
|
|
if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) {
|
|
|
|
getWindow().addFlags(
|
|
|
|
WindowManager.LayoutParams.FLAG_DIM_BEHIND |
|
|
|
|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
|
|
|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
|
|
|
|
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
|
|
|
} else {
|
|
|
|
getWindow().addFlags(
|
|
|
|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
|
|
|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
|
|
|
|
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentMessageObject == null) {
|
|
|
|
currentMessageNum = 0;
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
getNewMessage();
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void getNewMessage() {
|
2014-07-10 00:15:58 +00:00
|
|
|
if (NotificationsController.getInstance().popupMessages.isEmpty()) {
|
|
|
|
onFinish();
|
2014-07-02 22:39:05 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean found = false;
|
2014-07-10 00:15:58 +00:00
|
|
|
if ((currentMessageNum != 0 || chatActivityEnterView.hasText() || startedMoving) && currentMessageObject != null) {
|
|
|
|
for (int a = 0; a < NotificationsController.getInstance().popupMessages.size(); a++) {
|
2015-03-18 23:09:45 +00:00
|
|
|
if (NotificationsController.getInstance().popupMessages.get(a).getId() == currentMessageObject.getId()) {
|
2014-07-02 22:39:05 +00:00
|
|
|
currentMessageNum = a;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2014-07-10 00:15:58 +00:00
|
|
|
currentMessageNum = 0;
|
|
|
|
currentMessageObject = NotificationsController.getInstance().popupMessages.get(0);
|
|
|
|
updateInterfaceForCurrentMessage(0);
|
|
|
|
} else if (startedMoving) {
|
|
|
|
if (currentMessageNum == NotificationsController.getInstance().popupMessages.size() - 1) {
|
|
|
|
prepareLayouts(3);
|
|
|
|
} else if (currentMessageNum == 1) {
|
|
|
|
prepareLayouts(4);
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
countText.setText(String.format("%d/%d", currentMessageNum + 1, NotificationsController.getInstance().popupMessages.size()));
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void openCurrentMessage() {
|
|
|
|
if (currentMessageObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
|
|
|
|
long dialog_id = currentMessageObject.getDialogId();
|
|
|
|
if ((int)dialog_id != 0) {
|
|
|
|
int lower_id = (int)dialog_id;
|
|
|
|
if (lower_id < 0) {
|
|
|
|
intent.putExtra("chatId", -lower_id);
|
|
|
|
} else {
|
|
|
|
intent.putExtra("userId", lower_id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
intent.putExtra("encId", (int)(dialog_id >> 32));
|
|
|
|
}
|
|
|
|
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
|
|
|
|
intent.setFlags(0x00008000);
|
|
|
|
startActivity(intent);
|
2014-07-10 00:15:58 +00:00
|
|
|
onFinish();
|
|
|
|
finish();
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 00:15:58 +00:00
|
|
|
private void updateInterfaceForCurrentMessage(int move) {
|
2014-11-11 22:16:17 +00:00
|
|
|
if (actionBar == null) {
|
2014-07-02 22:39:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentChat = null;
|
|
|
|
currentUser = null;
|
|
|
|
long dialog_id = currentMessageObject.getDialogId();
|
|
|
|
chatActivityEnterView.setDialogId(dialog_id);
|
|
|
|
if ((int)dialog_id != 0) {
|
|
|
|
int lower_id = (int)dialog_id;
|
|
|
|
if (lower_id > 0) {
|
2014-08-22 14:24:33 +00:00
|
|
|
currentUser = MessagesController.getInstance().getUser(lower_id);
|
2014-07-02 22:39:05 +00:00
|
|
|
} else {
|
2014-08-22 14:24:33 +00:00
|
|
|
currentChat = MessagesController.getInstance().getChat(-lower_id);
|
|
|
|
currentUser = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.from_id);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat((int)(dialog_id >> 32));
|
|
|
|
currentUser = MessagesController.getInstance().getUser(encryptedChat.user_id);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentChat != null && currentUser != null) {
|
2014-11-17 02:44:57 +00:00
|
|
|
nameTextView.setText(currentChat.title);
|
|
|
|
onlineTextView.setText(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
|
|
|
|
nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
nameTextView.setCompoundDrawablePadding(0);
|
2014-07-02 22:39:05 +00:00
|
|
|
} else if (currentUser != null) {
|
2014-11-17 02:44:57 +00:00
|
|
|
nameTextView.setText(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
|
2014-07-02 22:39:05 +00:00
|
|
|
if ((int)dialog_id == 0) {
|
2014-11-17 02:44:57 +00:00
|
|
|
nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0);
|
|
|
|
nameTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
2014-07-02 22:39:05 +00:00
|
|
|
} else {
|
2014-11-17 02:44:57 +00:00
|
|
|
nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
nameTextView.setCompoundDrawablePadding(0);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
|
|
|
|
prepareLayouts(move);
|
2014-07-02 22:39:05 +00:00
|
|
|
updateSubtitle();
|
|
|
|
checkAndUpdateAvatar();
|
2014-07-10 00:15:58 +00:00
|
|
|
applyViewsLayoutParams(0);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSubtitle() {
|
2014-11-11 22:16:17 +00:00
|
|
|
if (actionBar == null) {
|
2014-07-02 22:39:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentChat != null || currentUser == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentUser.id / 1000 != 777 && currentUser.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(currentUser.id) == null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts())) {
|
|
|
|
if (currentUser.phone != null && currentUser.phone.length() != 0) {
|
2014-11-17 02:44:57 +00:00
|
|
|
nameTextView.setText(PhoneFormat.getInstance().format("+" + currentUser.phone));
|
2014-07-02 22:39:05 +00:00
|
|
|
} else {
|
2014-11-17 02:44:57 +00:00
|
|
|
nameTextView.setText(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-11-17 02:44:57 +00:00
|
|
|
nameTextView.setText(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
|
|
|
|
if (printString == null || printString.length() == 0) {
|
|
|
|
lastPrintString = null;
|
|
|
|
setTypingAnimation(false);
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-07-02 22:39:05 +00:00
|
|
|
if (user != null) {
|
|
|
|
currentUser = user;
|
|
|
|
}
|
2014-11-17 02:44:57 +00:00
|
|
|
onlineTextView.setText(LocaleController.formatUserStatus(currentUser));
|
2014-07-02 22:39:05 +00:00
|
|
|
} else {
|
|
|
|
lastPrintString = printString;
|
2014-11-17 02:44:57 +00:00
|
|
|
onlineTextView.setText(printString);
|
2014-07-02 22:39:05 +00:00
|
|
|
setTypingAnimation(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkAndUpdateAvatar() {
|
|
|
|
TLRPC.FileLocation newPhoto = null;
|
2014-11-06 21:34:47 +00:00
|
|
|
AvatarDrawable avatarDrawable = null;
|
2014-07-02 22:39:05 +00:00
|
|
|
if (currentChat != null) {
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(currentChat.id);
|
2014-07-02 22:39:05 +00:00
|
|
|
if (chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentChat = chat;
|
|
|
|
if (currentChat.photo != null) {
|
|
|
|
newPhoto = currentChat.photo.photo_small;
|
|
|
|
}
|
2014-11-06 21:34:47 +00:00
|
|
|
avatarDrawable = new AvatarDrawable(currentChat);
|
2014-07-02 22:39:05 +00:00
|
|
|
} else if (currentUser != null) {
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-07-02 22:39:05 +00:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentUser = user;
|
|
|
|
if (currentUser.photo != null) {
|
|
|
|
newPhoto = currentUser.photo.photo_small;
|
|
|
|
}
|
2014-11-06 21:34:47 +00:00
|
|
|
avatarDrawable = new AvatarDrawable(currentUser);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
if (avatarImageView != null) {
|
2014-11-06 21:34:47 +00:00
|
|
|
avatarImageView.setImage(newPhoto, "50_50", avatarDrawable);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setTypingAnimation(boolean start) {
|
2014-11-11 22:16:17 +00:00
|
|
|
if (actionBar == null) {
|
2014-07-02 22:39:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (start) {
|
|
|
|
try {
|
2014-11-17 02:44:57 +00:00
|
|
|
onlineTextView.setCompoundDrawablesWithIntrinsicBounds(typingDotsDrawable, null, null, null);
|
|
|
|
onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
2014-09-24 02:17:27 +00:00
|
|
|
typingDotsDrawable.start();
|
2014-07-02 22:39:05 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-17 02:44:57 +00:00
|
|
|
onlineTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
|
|
|
onlineTextView.setCompoundDrawablePadding(0);
|
2014-09-24 02:17:27 +00:00
|
|
|
typingDotsDrawable.stop();
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (chatActivityEnterView.isEmojiPopupShowing()) {
|
|
|
|
chatActivityEnterView.hideEmojiPopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.setFieldFocused(true);
|
|
|
|
}
|
|
|
|
ConnectionsManager.getInstance().setAppPaused(false, false);
|
2014-07-10 00:15:58 +00:00
|
|
|
fixLayout();
|
2015-04-09 18:00:14 +00:00
|
|
|
checkAndUpdateAvatar();
|
2014-07-10 12:14:36 +00:00
|
|
|
wakeLock.acquire(7000);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
overridePendingTransition(0, 0);
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.hideEmojiPopup();
|
|
|
|
chatActivityEnterView.setFieldFocused(false);
|
|
|
|
}
|
|
|
|
ConnectionsManager.getInstance().setAppPaused(true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (id == NotificationCenter.appDidLogout) {
|
2014-07-02 22:39:05 +00:00
|
|
|
onFinish();
|
|
|
|
finish();
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.pushMessagesUpdated) {
|
2014-07-02 22:39:05 +00:00
|
|
|
getNewMessage();
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.updateInterfaces) {
|
2014-07-02 22:39:05 +00:00
|
|
|
if (currentMessageObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int updateMask = (Integer)args[0];
|
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
|
|
|
|
updateSubtitle();
|
|
|
|
}
|
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) {
|
|
|
|
checkAndUpdateAvatar();
|
|
|
|
}
|
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
|
|
|
|
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
|
|
|
updateSubtitle();
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.audioDidReset) {
|
2014-07-10 00:15:58 +00:00
|
|
|
Integer mid = (Integer)args[0];
|
|
|
|
if (messageContainer != null) {
|
|
|
|
int count = messageContainer.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = messageContainer.getChildAt(a);
|
|
|
|
if ((Integer)view.getTag() == 3) {
|
|
|
|
PopupAudioView cell = (PopupAudioView)view.findViewWithTag(300);
|
2015-03-18 23:09:45 +00:00
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
|
2014-07-10 00:15:58 +00:00
|
|
|
cell.updateButtonState();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.audioProgressDidChanged) {
|
2014-07-10 00:15:58 +00:00
|
|
|
Integer mid = (Integer)args[0];
|
|
|
|
if (messageContainer != null) {
|
|
|
|
int count = messageContainer.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = messageContainer.getChildAt(a);
|
|
|
|
if ((Integer)view.getTag() == 3) {
|
|
|
|
PopupAudioView cell = (PopupAudioView)view.findViewWithTag(300);
|
2015-03-18 23:09:45 +00:00
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
|
2014-07-10 00:15:58 +00:00
|
|
|
cell.updateProgress();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.emojiDidLoaded) {
|
2014-07-10 00:15:58 +00:00
|
|
|
if (messageContainer != null) {
|
|
|
|
int count = messageContainer.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = messageContainer.getChildAt(a);
|
2014-12-01 17:56:31 +00:00
|
|
|
if ((Integer)view.getTag() == 1) {
|
|
|
|
TextView textView = (TextView)view.findViewWithTag(301);
|
|
|
|
if (textView != null) {
|
|
|
|
textView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 00:15:58 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.contactsDidLoaded) {
|
2014-07-19 23:31:49 +00:00
|
|
|
updateSubtitle();
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
onFinish();
|
|
|
|
if (wakeLock.isHeld()) {
|
|
|
|
wakeLock.release();
|
|
|
|
}
|
2015-03-18 23:09:45 +00:00
|
|
|
if (avatarImageView != null) {
|
|
|
|
avatarImageView.setImageDrawable(null);
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void onFinish() {
|
|
|
|
if (finished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finished = true;
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.pushMessagesUpdated);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidReset);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
2014-07-02 22:39:05 +00:00
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.onDestroy();
|
|
|
|
}
|
|
|
|
if (wakeLock.isHeld()) {
|
|
|
|
wakeLock.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|