2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2013-12-20 20:25:49 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 17:19:00 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2014-07-30 09:49:39 +02:00
|
|
|
import android.animation.Animator;
|
2014-10-07 22:14:27 +02:00
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
2014-03-22 23:31:55 +01:00
|
|
|
import android.content.res.Configuration;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.graphics.Rect;
|
2014-06-14 10:36:01 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.net.Uri;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.os.Build;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.text.Html;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.text.TextUtils;
|
2014-10-10 19:16:39 +02:00
|
|
|
import android.util.SparseArray;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.Gravity;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.LayoutInflater;
|
2014-07-10 02:15:58 +02:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
2014-11-06 22:34:47 +01:00
|
|
|
import android.view.WindowManager;
|
2013-12-26 12:43:37 +01:00
|
|
|
import android.webkit.MimeTypeMap;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.widget.LinearLayout;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
2014-06-14 10:36:01 +02:00
|
|
|
import android.widget.Toast;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.LocaleController;
|
|
|
|
import org.telegram.android.MediaController;
|
|
|
|
import org.telegram.android.MessagesStorage;
|
2014-07-10 02:15:58 +02:00
|
|
|
import org.telegram.android.NotificationsController;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.SendMessagesHelper;
|
2014-09-14 01:40:36 +02:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2014-02-28 23:28:25 +01:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.ContactsController;
|
2013-12-20 20:25:49 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.MessageObject;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.MessagesController;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
import org.telegram.messenger.Utilities;
|
2014-06-20 02:18:13 +02:00
|
|
|
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
2014-10-14 22:36:15 +02:00
|
|
|
import org.telegram.ui.Cells.ChatActionCell;
|
2014-02-28 23:28:25 +01:00
|
|
|
import org.telegram.ui.Cells.ChatAudioCell;
|
|
|
|
import org.telegram.ui.Cells.ChatBaseCell;
|
2014-10-15 20:43:52 +02:00
|
|
|
import org.telegram.ui.Cells.ChatContactCell;
|
2014-03-31 16:14:49 +02:00
|
|
|
import org.telegram.ui.Cells.ChatMediaCell;
|
2014-02-28 23:28:25 +01:00
|
|
|
import org.telegram.ui.Cells.ChatMessageCell;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
|
2014-11-06 22:34:47 +01:00
|
|
|
import org.telegram.ui.Views.AvatarDrawable;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.ui.Views.BackupImageView;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.ui.Views.ChatActivityEnterView;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.ImageReceiver;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.ui.Views.LayoutListView;
|
|
|
|
import org.telegram.ui.Views.SizeNotifierRelativeLayout;
|
2014-03-10 10:27:49 +01:00
|
|
|
import org.telegram.ui.Views.TimerButton;
|
2014-09-24 04:17:27 +02:00
|
|
|
import org.telegram.ui.Views.TypingDotsDrawable;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
2014-03-26 21:16:28 +01:00
|
|
|
import java.util.concurrent.Semaphore;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate,
|
2014-10-15 20:43:52 +02:00
|
|
|
PhotoViewer.PhotoViewerProvider {
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private TLRPC.Chat currentChat;
|
|
|
|
private TLRPC.User currentUser;
|
|
|
|
private TLRPC.EncryptedChat currentEncryptedChat;
|
2014-08-22 16:24:33 +02:00
|
|
|
private boolean userBlocked = false;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private View topPanel;
|
|
|
|
private View progressView;
|
|
|
|
private View bottomOverlay;
|
2014-08-22 16:24:33 +02:00
|
|
|
private ChatAdapter chatAdapter;
|
|
|
|
private ChatActivityEnterView chatActivityEnterView;
|
|
|
|
private View timeItem;
|
|
|
|
private View menuItem;
|
|
|
|
private LayoutListView chatListView;
|
|
|
|
private BackupImageView avatarImageView;
|
|
|
|
private TextView bottomOverlayChatText;
|
|
|
|
private View bottomOverlayChat;
|
2014-09-24 04:17:27 +02:00
|
|
|
private TypingDotsDrawable typingDotsDrawable;
|
2014-09-30 00:48:11 +02:00
|
|
|
private View emptyViewContainer;
|
2014-10-07 22:14:27 +02:00
|
|
|
private ArrayList<View> actionModeViews = new ArrayList<View>();
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private TextView bottomOverlayText;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private MessageObject selectedObject;
|
|
|
|
private MessageObject forwaringMessage;
|
|
|
|
private TextView secretViewStatusTextView;
|
2014-03-10 10:27:49 +01:00
|
|
|
private TimerButton timerButton;
|
2014-06-04 01:31:48 +02:00
|
|
|
private TextView selectedMessagesCountTextView;
|
2013-10-25 17:19:00 +02:00
|
|
|
private boolean paused = true;
|
|
|
|
private boolean readWhenResume = false;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
private int readWithDate = 0;
|
|
|
|
private int readWithMid = 0;
|
2014-06-04 01:31:48 +02:00
|
|
|
private boolean scrollToTopOnResume = false;
|
2013-12-20 20:25:49 +01:00
|
|
|
private boolean scrollToTopUnReadOnResume = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
private boolean isCustomTheme = false;
|
|
|
|
private ImageView topPlaneClose;
|
2013-12-20 20:25:49 +01:00
|
|
|
private View pagedownButton;
|
2013-10-25 17:19:00 +02:00
|
|
|
private TextView topPanelText;
|
|
|
|
private long dialog_id;
|
2014-10-20 13:30:05 +02:00
|
|
|
private boolean isBroadcast = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
private HashMap<Integer, MessageObject> selectedMessagesIds = new HashMap<Integer, MessageObject>();
|
|
|
|
private HashMap<Integer, MessageObject> selectedMessagesCanCopyIds = new HashMap<Integer, MessageObject>();
|
|
|
|
|
|
|
|
private HashMap<Integer, MessageObject> messagesDict = new HashMap<Integer, MessageObject>();
|
|
|
|
private HashMap<String, ArrayList<MessageObject>> messagesByDays = new HashMap<String, ArrayList<MessageObject>>();
|
|
|
|
private ArrayList<MessageObject> messages = new ArrayList<MessageObject>();
|
|
|
|
private int maxMessageId = Integer.MAX_VALUE;
|
2013-12-20 20:25:49 +01:00
|
|
|
private int minMessageId = Integer.MIN_VALUE;
|
2013-10-25 17:19:00 +02:00
|
|
|
private int maxDate = Integer.MIN_VALUE;
|
|
|
|
private boolean endReached = false;
|
|
|
|
private boolean loading = false;
|
|
|
|
private boolean cacheEndReaced = false;
|
2014-08-02 01:31:15 +02:00
|
|
|
private boolean firstLoading = true;
|
2014-09-24 04:17:27 +02:00
|
|
|
private int loadsCount = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
private int startLoadFromMessageId = 0;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private int minDate = 0;
|
2014-08-02 01:31:15 +02:00
|
|
|
private boolean first = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
private int unread_to_load = 0;
|
|
|
|
private int first_unread_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
private int last_message_id = 0;
|
|
|
|
private boolean forward_end_reached = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
private boolean loadingForward = false;
|
|
|
|
private MessageObject unreadMessageObject = null;
|
2014-10-31 20:02:29 +01:00
|
|
|
private MessageObject scrollToMessage = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
private String currentPicturePath;
|
|
|
|
|
|
|
|
private TLRPC.ChatParticipants info = null;
|
|
|
|
private int onlineCount = -1;
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
private CharSequence lastPrintString;
|
|
|
|
|
2014-04-04 19:58:33 +02:00
|
|
|
private long chatEnterTime = 0;
|
|
|
|
private long chatLeaveTime = 0;
|
|
|
|
|
2014-10-01 00:36:18 +02:00
|
|
|
private String startVideoEdit = null;
|
|
|
|
|
2014-10-09 17:55:05 +02:00
|
|
|
private Runnable openSecretPhotoRunnable = null;
|
2014-10-10 19:16:39 +02:00
|
|
|
private float startX = 0;
|
|
|
|
private float startY = 0;
|
2014-10-09 17:55:05 +02:00
|
|
|
|
2014-04-02 19:36:57 +02:00
|
|
|
private final static int copy = 1;
|
|
|
|
private final static int forward = 2;
|
|
|
|
private final static int delete = 3;
|
|
|
|
private final static int chat_enc_timer = 4;
|
|
|
|
private final static int chat_menu_attach = 5;
|
|
|
|
private final static int attach_photo = 6;
|
|
|
|
private final static int attach_gallery = 7;
|
|
|
|
private final static int attach_video = 8;
|
|
|
|
private final static int attach_document = 9;
|
|
|
|
private final static int attach_location = 10;
|
|
|
|
private final static int chat_menu_avatar = 11;
|
|
|
|
|
2014-10-10 19:16:39 +02:00
|
|
|
AdapterView.OnItemLongClickListener onItemLongClickListener = new AdapterView.OnItemLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) {
|
|
|
|
if (!actionBarLayer.isActionModeShowed()) {
|
|
|
|
createMenu(view, false);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
processRowSelect(view);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
createMenu(view, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public ChatActivity(Bundle args) {
|
|
|
|
super(args);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2014-06-04 01:31:48 +02:00
|
|
|
final int chatId = arguments.getInt("chat_id", 0);
|
|
|
|
final int userId = arguments.getInt("user_id", 0);
|
|
|
|
final int encId = arguments.getInt("enc_id", 0);
|
2014-10-31 20:02:29 +01:00
|
|
|
startLoadFromMessageId = arguments.getInt("message_id", 0);
|
2014-06-04 01:31:48 +02:00
|
|
|
scrollToTopOnResume = arguments.getBoolean("scrollToTopOnResume", false);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
if (chatId != 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
currentChat = MessagesController.getInstance().getChat(chatId);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentChat == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentChat = MessagesStorage.getInstance().getChat(chatId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentChat != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putChat(currentChat, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-07-27 00:28:33 +02:00
|
|
|
if (chatId > 0) {
|
|
|
|
dialog_id = -chatId;
|
|
|
|
} else {
|
2014-10-20 13:30:05 +02:00
|
|
|
isBroadcast = true;
|
2014-07-27 12:53:00 +02:00
|
|
|
dialog_id = AndroidUtilities.makeBroadcastId(chatId);
|
2014-07-27 00:28:33 +02:00
|
|
|
}
|
2014-08-08 12:17:06 +02:00
|
|
|
Semaphore semaphore = null;
|
2014-10-20 13:30:05 +02:00
|
|
|
if (isBroadcast) {
|
2014-08-08 12:17:06 +02:00
|
|
|
semaphore = new Semaphore(0);
|
|
|
|
}
|
|
|
|
MessagesController.getInstance().loadChatInfo(currentChat.id, semaphore);
|
2014-10-20 13:30:05 +02:00
|
|
|
if (isBroadcast) {
|
2014-08-08 12:17:06 +02:00
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (userId != 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
currentUser = MessagesController.getInstance().getUser(userId);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentUser = MessagesStorage.getInstance().getUser(userId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putUser(currentUser, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
dialog_id = userId;
|
|
|
|
} else if (encId != 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
currentEncryptedChat = MessagesController.getInstance().getEncryptedChat(encId);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentEncryptedChat = MessagesStorage.getInstance().getEncryptedChat(encId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putEncryptedChat(currentEncryptedChat, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
currentUser = MessagesController.getInstance().getUser(currentEncryptedChat.user_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentUser = MessagesStorage.getInstance().getUser(currentEncryptedChat.user_id);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putUser(currentUser, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
dialog_id = ((long)encId) << 32;
|
2014-03-22 23:31:55 +01:00
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
2013-12-20 20:25:49 +01:00
|
|
|
minMessageId = Integer.MAX_VALUE;
|
2014-04-04 19:58:33 +02:00
|
|
|
MediaController.getInstance().startMediaObserver();
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
chatActivityEnterView = new ChatActivityEnterView();
|
|
|
|
chatActivityEnterView.setDialogId(dialog_id);
|
|
|
|
chatActivityEnterView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onMessageSend() {
|
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void needSendTyping() {
|
|
|
|
MessagesController.getInstance().sendTyping(dialog_id, classGuid);
|
|
|
|
}
|
|
|
|
});
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
|
2014-09-14 01:40:36 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesRead);
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageSendError);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatUpdated);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesReadedEncrypted);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.removeAllMessagesFromDialog);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenshotTook);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded);
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileNewChunkAvailable);
|
2014-10-10 19:16:39 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didCreatedNewDeleteTask);
|
2014-10-21 22:35:16 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidStarted);
|
2014-03-22 23:31:55 +01:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
super.onFragmentCreate();
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
loading = true;
|
2014-10-08 22:22:22 +02:00
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (startLoadFromMessageId != 0) {
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, true, 0, classGuid, 3);
|
|
|
|
} else {
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, 0, true, 0, classGuid, 2);
|
|
|
|
}
|
2014-10-08 22:22:22 +02:00
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
if (currentUser != null) {
|
|
|
|
userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
typingDotsDrawable = new TypingDotsDrawable();
|
|
|
|
typingDotsDrawable.setIsChat(currentChat != null);
|
|
|
|
|
2014-10-14 22:36:15 +02:00
|
|
|
if (currentEncryptedChat != null && AndroidUtilities.getMyLayerVersion(currentEncryptedChat.layer) != SendMessagesHelper.CURRENT_SECRET_CHAT_LAYER) {
|
2014-10-22 22:01:07 +02:00
|
|
|
SendMessagesHelper.getInstance().sendNotifyLayerMessage(currentEncryptedChat, null);
|
2014-10-14 22:36:15 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-07-03 00:39:05 +02:00
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.onDestroy();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
|
2014-09-14 01:40:36 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesRead);
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageSendError);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatUpdated);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesReadedEncrypted);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.removeAllMessagesFromDialog);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidReset);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.screenshotTook);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.blockedUsersDidLoaded);
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileNewChunkAvailable);
|
2014-10-10 19:16:39 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didCreatedNewDeleteTask);
|
2014-10-21 22:35:16 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidStarted);
|
2014-09-24 04:17:27 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, true);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-04-04 19:58:33 +02:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
MediaController.getInstance().stopMediaObserver();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
AndroidUtilities.unlockOrientation(getParentActivity());
|
2014-03-22 23:31:55 +01:00
|
|
|
MediaController.getInstance().stopAudio();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (fragmentView == null) {
|
2014-11-06 22:34:47 +01:00
|
|
|
actionBarLayer.setBackButtonImage(R.drawable.ic_ab_back);
|
2014-06-12 17:53:20 +02:00
|
|
|
actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
|
|
|
} else if (id == -2) {
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBarLayer.hideActionMode();
|
|
|
|
updateVisibleRows();
|
|
|
|
} else if (id == attach_photo) {
|
|
|
|
try {
|
|
|
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
File image = Utilities.generatePicturePath();
|
|
|
|
if (image != null) {
|
|
|
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
|
|
|
|
currentPicturePath = image.getAbsolutePath();
|
|
|
|
}
|
2014-10-01 00:36:18 +02:00
|
|
|
startActivityForResult(takePictureIntent, 0);
|
2014-06-04 01:31:48 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (id == attach_gallery) {
|
2014-06-12 03:13:15 +02:00
|
|
|
PhotoPickerActivity fragment = new PhotoPickerActivity();
|
2014-10-15 20:43:52 +02:00
|
|
|
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectPhotos(ArrayList<String> photos) {
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id);
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startPhotoSelectActivity() {
|
|
|
|
try {
|
|
|
|
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
photoPickerIntent.setType("image/*");
|
|
|
|
startActivityForResult(photoPickerIntent, 1);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-12 03:13:15 +02:00
|
|
|
presentFragment(fragment);
|
2014-06-04 01:31:48 +02:00
|
|
|
} else if (id == attach_video) {
|
|
|
|
try {
|
|
|
|
Intent pickIntent = new Intent();
|
|
|
|
pickIntent.setType("video/*");
|
|
|
|
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
|
2014-06-12 21:55:13 +02:00
|
|
|
pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
|
2014-06-04 01:31:48 +02:00
|
|
|
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
|
|
|
|
File video = Utilities.generateVideoPath();
|
|
|
|
if (video != null) {
|
2014-10-01 00:36:18 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
2014-06-04 01:31:48 +02:00
|
|
|
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
|
|
|
|
}
|
2014-06-12 21:55:13 +02:00
|
|
|
takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
|
2014-06-04 01:31:48 +02:00
|
|
|
currentPicturePath = video.getAbsolutePath();
|
|
|
|
}
|
|
|
|
Intent chooserIntent = Intent.createChooser(pickIntent, "");
|
2014-06-12 21:55:13 +02:00
|
|
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-10-01 00:36:18 +02:00
|
|
|
startActivityForResult(chooserIntent, 2);
|
2014-06-04 01:31:48 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (id == attach_location) {
|
|
|
|
if (!isGoogleMapsInstalled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LocationActivity fragment = new LocationActivity();
|
2014-10-15 20:43:52 +02:00
|
|
|
fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectLocation(double latitude, double longitude) {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage(latitude, longitude, dialog_id);
|
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
}
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-04 01:31:48 +02:00
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (id == attach_document) {
|
|
|
|
DocumentSelectActivity fragment = new DocumentSelectActivity();
|
2014-10-15 20:43:52 +02:00
|
|
|
fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectFile(DocumentSelectActivity activity, String path) {
|
|
|
|
activity.finishFragment();
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingDocument(path, path, dialog_id);
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startDocumentSelectActivity() {
|
|
|
|
try {
|
|
|
|
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
photoPickerIntent.setType("*/*");
|
|
|
|
startActivityForResult(photoPickerIntent, 21);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-04 01:31:48 +02:00
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (id == chat_menu_avatar) {
|
|
|
|
if (currentUser != null) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", currentUser.id);
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
args.putLong("dialog_id", dialog_id);
|
|
|
|
}
|
|
|
|
presentFragment(new UserProfileActivity(args));
|
|
|
|
} else if (currentChat != null) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (info != null && info instanceof TLRPC.TL_chatParticipantsForbidden) {
|
|
|
|
return;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-07-31 02:50:12 +02:00
|
|
|
int count = currentChat.participants_count;
|
|
|
|
if (info != null) {
|
|
|
|
count = info.participants.size();
|
|
|
|
}
|
|
|
|
if (count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", currentChat.id);
|
2014-06-11 01:05:54 +02:00
|
|
|
ChatProfileActivity fragment = new ChatProfileActivity(args);
|
|
|
|
fragment.setChatInfo(info);
|
|
|
|
presentFragment(fragment);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
} else if (id == copy) {
|
|
|
|
String str = "";
|
|
|
|
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesCanCopyIds.keySet());
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
Collections.sort(ids);
|
|
|
|
} else {
|
|
|
|
Collections.sort(ids, Collections.reverseOrder());
|
|
|
|
}
|
|
|
|
for (Integer messageId : ids) {
|
|
|
|
MessageObject messageObject = selectedMessagesCanCopyIds.get(messageId);
|
|
|
|
if (str.length() != 0) {
|
|
|
|
str += "\n";
|
|
|
|
}
|
2014-06-22 11:36:52 +02:00
|
|
|
if (messageObject.messageOwner.message != null) {
|
|
|
|
str += messageObject.messageOwner.message;
|
|
|
|
} else {
|
|
|
|
str += messageObject.messageText;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
if (str.length() != 0) {
|
2014-10-01 00:36:18 +02:00
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
2014-06-12 21:55:13 +02:00
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
2014-06-04 01:31:48 +02:00
|
|
|
clipboard.setText(str);
|
|
|
|
} else {
|
2014-06-12 21:55:13 +02:00
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
2014-06-04 01:31:48 +02:00
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", str);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
2014-06-04 20:57:11 +02:00
|
|
|
actionBarLayer.hideActionMode();
|
2014-06-07 01:35:21 +02:00
|
|
|
updateVisibleRows();
|
2014-06-04 01:31:48 +02:00
|
|
|
} else if (id == delete) {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
random_ids = new ArrayList<Long>();
|
|
|
|
for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds.entrySet()) {
|
|
|
|
MessageObject msg = entry.getValue();
|
|
|
|
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
|
|
|
|
random_ids.add(msg.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
|
2014-06-04 20:57:11 +02:00
|
|
|
actionBarLayer.hideActionMode();
|
2014-06-04 01:31:48 +02:00
|
|
|
} else if (id == forward) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
|
|
|
args.putBoolean("serverOnly", true);
|
|
|
|
args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo));
|
2014-10-04 17:56:09 +02:00
|
|
|
args.putString("selectAlertStringGroup", LocaleController.getString("ForwardMessagesToGroup", R.string.ForwardMessagesToGroup));
|
2014-06-04 01:31:48 +02:00
|
|
|
MessagesActivity fragment = new MessagesActivity(args);
|
|
|
|
fragment.setDelegate(ChatActivity.this);
|
|
|
|
presentFragment(fragment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-12 17:53:20 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
updateSubtitle();
|
|
|
|
|
|
|
|
if (currentEncryptedChat != null) {
|
2014-07-03 00:39:05 +02:00
|
|
|
actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4));
|
2014-07-27 00:28:33 +02:00
|
|
|
} else if (currentChat != null && currentChat.id < 0) {
|
|
|
|
actionBarLayer.setTitleIcon(R.drawable.broadcast2, AndroidUtilities.dp(4));
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionBarMenu menu = actionBarLayer.createMenu();
|
|
|
|
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
timeItem = menu.addItemResource(chat_enc_timer, R.layout.chat_header_enc_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionBarMenuItem item = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach);
|
|
|
|
item.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto), R.drawable.ic_attach_photo);
|
|
|
|
item.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery), R.drawable.ic_attach_gallery);
|
|
|
|
item.addSubItem(attach_video, LocaleController.getString("ChatVideo", R.string.ChatVideo), R.drawable.ic_attach_video);
|
|
|
|
item.addSubItem(attach_document, LocaleController.getString("ChatDocument", R.string.ChatDocument), R.drawable.ic_ab_doc);
|
|
|
|
item.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation), R.drawable.ic_attach_location);
|
|
|
|
menuItem = item;
|
|
|
|
|
2014-10-07 22:14:27 +02:00
|
|
|
actionModeViews.clear();
|
|
|
|
|
2014-10-22 22:01:07 +02:00
|
|
|
final ActionBarMenu actionMode = actionBarLayer.createActionMode();
|
2014-10-07 22:14:27 +02:00
|
|
|
actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_done_gray, R.drawable.bar_selector_mode));
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
FrameLayout layout = new FrameLayout(actionMode.getContext());
|
|
|
|
layout.setBackgroundColor(0xffe5e5e5);
|
|
|
|
actionMode.addView(layout);
|
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)layout.getLayoutParams();
|
2014-07-03 00:39:05 +02:00
|
|
|
layoutParams.width = AndroidUtilities.dp(1);
|
2014-06-04 01:31:48 +02:00
|
|
|
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
2014-07-03 00:39:05 +02:00
|
|
|
layoutParams.topMargin = AndroidUtilities.dp(12);
|
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(12);
|
2014-06-04 01:31:48 +02:00
|
|
|
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
|
|
|
layout.setLayoutParams(layoutParams);
|
2014-10-07 22:14:27 +02:00
|
|
|
actionModeViews.add(layout);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
selectedMessagesCountTextView = new TextView(actionMode.getContext());
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
|
|
|
selectedMessagesCountTextView.setTextColor(0xff000000);
|
|
|
|
selectedMessagesCountTextView.setSingleLine(true);
|
|
|
|
selectedMessagesCountTextView.setLines(1);
|
|
|
|
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
|
2014-09-24 04:17:27 +02:00
|
|
|
selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, 0);
|
2014-06-04 01:31:48 +02:00
|
|
|
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
|
2014-07-10 02:15:58 +02:00
|
|
|
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-06-04 01:31:48 +02:00
|
|
|
actionMode.addView(selectedMessagesCountTextView);
|
|
|
|
layoutParams = (LinearLayout.LayoutParams)selectedMessagesCountTextView.getLayoutParams();
|
|
|
|
layoutParams.weight = 1;
|
|
|
|
layoutParams.width = 0;
|
|
|
|
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
selectedMessagesCountTextView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
if (currentEncryptedChat == null) {
|
2014-10-07 22:14:27 +02:00
|
|
|
actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode));
|
|
|
|
actionModeViews.add(actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, R.drawable.bar_selector_mode));
|
|
|
|
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode));
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
2014-10-07 22:14:27 +02:00
|
|
|
actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode));
|
|
|
|
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode));
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
actionMode.getItem(copy).setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
View avatarLayout = menu.addItemResource(chat_menu_avatar, R.layout.chat_header_layout);
|
|
|
|
avatarImageView = (BackupImageView)avatarLayout.findViewById(R.id.chat_avatar_image);
|
|
|
|
avatarImageView.processDetach = false;
|
|
|
|
checkActionBarMenu();
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
fragmentView = inflater.inflate(R.layout.chat_layout, container, false);
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
View contentView = fragmentView.findViewById(R.id.chat_layout);
|
2014-09-30 00:48:11 +02:00
|
|
|
TextView emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
|
|
|
|
emptyViewContainer = fragmentView.findViewById(R.id.empty_view);
|
|
|
|
emptyViewContainer.setVisibility(View.GONE);
|
|
|
|
emptyViewContainer.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-03-22 23:31:55 +01:00
|
|
|
emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages));
|
2013-10-25 17:19:00 +02:00
|
|
|
chatListView = (LayoutListView)fragmentView.findViewById(R.id.chat_list_view);
|
2014-06-04 01:31:48 +02:00
|
|
|
chatListView.setAdapter(chatAdapter = new ChatAdapter(getParentActivity()));
|
2013-10-25 17:19:00 +02:00
|
|
|
topPanel = fragmentView.findViewById(R.id.top_panel);
|
|
|
|
topPlaneClose = (ImageView)fragmentView.findViewById(R.id.top_plane_close);
|
|
|
|
topPanelText = (TextView)fragmentView.findViewById(R.id.top_panel_text);
|
|
|
|
bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay);
|
|
|
|
bottomOverlayText = (TextView)fragmentView.findViewById(R.id.bottom_overlay_text);
|
2014-08-22 16:24:33 +02:00
|
|
|
bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat);
|
2013-12-20 20:25:49 +01:00
|
|
|
progressView = fragmentView.findViewById(R.id.progressLayout);
|
|
|
|
pagedownButton = fragmentView.findViewById(R.id.pagedown_button);
|
2014-07-30 09:49:39 +02:00
|
|
|
pagedownButton.setVisibility(View.GONE);
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
View progressViewInner = progressView.findViewById(R.id.progressLayoutInner);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
updateContactStatus();
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-12-20 20:25:49 +01:00
|
|
|
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
|
|
|
|
int selectedColor = preferences.getInt("selectedColor", 0);
|
|
|
|
if (selectedColor != 0) {
|
2014-06-14 10:36:01 +02:00
|
|
|
contentView.setBackgroundColor(selectedColor);
|
2013-12-20 20:25:49 +01:00
|
|
|
chatListView.setCacheColorHint(selectedColor);
|
|
|
|
} else {
|
|
|
|
chatListView.setCacheColorHint(0);
|
2014-06-14 10:36:01 +02:00
|
|
|
try {
|
|
|
|
if (selectedBackground == 1000001) {
|
|
|
|
((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd);
|
|
|
|
} else {
|
|
|
|
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
|
|
|
|
if (toFile.exists()) {
|
|
|
|
if (ApplicationLoader.cachedWallpaper != null) {
|
|
|
|
((SizeNotifierRelativeLayout) contentView).setBackgroundImage(ApplicationLoader.cachedWallpaper);
|
|
|
|
} else {
|
|
|
|
Drawable drawable = Drawable.createFromPath(toFile.getAbsolutePath());
|
|
|
|
if (drawable != null) {
|
|
|
|
((SizeNotifierRelativeLayout) contentView).setBackgroundImage(drawable);
|
|
|
|
ApplicationLoader.cachedWallpaper = drawable;
|
|
|
|
} else {
|
|
|
|
contentView.setBackgroundColor(-2693905);
|
|
|
|
chatListView.setCacheColorHint(-2693905);
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2014-06-14 10:36:01 +02:00
|
|
|
isCustomTheme = true;
|
|
|
|
} else {
|
|
|
|
((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-14 10:36:01 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
contentView.setBackgroundColor(-2693905);
|
|
|
|
chatListView.setCacheColorHint(-2693905);
|
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (currentEncryptedChat != null) {
|
2014-09-30 00:48:11 +02:00
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
View secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder);
|
|
|
|
secretChatPlaceholder.setVisibility(View.VISIBLE);
|
2013-12-20 20:25:49 +01:00
|
|
|
if (isCustomTheme) {
|
|
|
|
secretChatPlaceholder.setBackgroundResource(R.drawable.system_black);
|
|
|
|
} else {
|
|
|
|
secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue);
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text);
|
|
|
|
secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
|
2013-12-20 20:25:49 +01:00
|
|
|
|
|
|
|
View v = contentView.findViewById(R.id.secret_placeholder);
|
|
|
|
v.setVisibility(View.VISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-13 12:42:21 +02:00
|
|
|
if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) {
|
2013-12-26 12:43:37 +01:00
|
|
|
if (currentUser.first_name.length() > 0) {
|
2014-03-22 23:31:55 +01:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.first_name));
|
2013-12-26 12:43:37 +01:00
|
|
|
} else {
|
2014-03-22 23:31:55 +01:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.last_name));
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2013-12-26 12:43:37 +01:00
|
|
|
if (currentUser.first_name.length() > 0) {
|
2014-03-22 23:31:55 +01:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.first_name));
|
2013-12-26 12:43:37 +01:00
|
|
|
} else {
|
2014-03-22 23:31:55 +01:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.last_name));
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
updateSecretStatus();
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (isCustomTheme) {
|
2013-12-20 20:25:49 +01:00
|
|
|
progressViewInner.setBackgroundResource(R.drawable.system_loader2);
|
|
|
|
emptyView.setBackgroundResource(R.drawable.system_black);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
progressViewInner.setBackgroundResource(R.drawable.system_loader1);
|
|
|
|
emptyView.setBackgroundResource(R.drawable.system_blue);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
emptyView.setPadding(AndroidUtilities.dp(7), AndroidUtilities.dp(1), AndroidUtilities.dp(7), AndroidUtilities.dp(1));
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-08-29 23:06:04 +02:00
|
|
|
if (currentUser != null && (currentUser.id / 1000 == 333 || currentUser.id % 1000 == 0)) {
|
2014-03-22 23:31:55 +01:00
|
|
|
emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 19:16:39 +02:00
|
|
|
chatListView.setOnItemLongClickListener(onItemLongClickListener);
|
|
|
|
chatListView.setOnItemClickListener(onItemClickListener);
|
|
|
|
|
|
|
|
final Rect scrollRect = new Rect();
|
|
|
|
|
|
|
|
chatListView.setOnInterceptTouchEventListener(new LayoutListView.OnInterceptTouchEventListener() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2014-10-10 19:16:39 +02:00
|
|
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
2014-10-22 22:01:07 +02:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-10 19:16:39 +02:00
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
int x = (int)event.getX();
|
|
|
|
int y = (int)event.getY();
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
Rect rect = new Rect();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
int top = view.getTop();
|
|
|
|
int bottom = view.getBottom();
|
|
|
|
view.getLocalVisibleRect(rect);
|
|
|
|
if (top > y || bottom < y) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(view instanceof ChatMediaCell)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
final ChatMediaCell cell = (ChatMediaCell)view;
|
|
|
|
final MessageObject messageObject = cell.getMessageObject();
|
2014-10-21 22:35:16 +02:00
|
|
|
if (messageObject == null || !messageObject.isSecretPhoto() || !cell.getPhotoImage().isInsideImage(x, y - top)) {
|
2014-10-10 19:16:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-10-14 22:36:15 +02:00
|
|
|
File file = FileLoader.getPathToMessage(messageObject.messageOwner);
|
|
|
|
if (!file.exists()) {
|
|
|
|
break;
|
|
|
|
}
|
2014-10-10 19:16:39 +02:00
|
|
|
startX = x;
|
|
|
|
startY = y;
|
2014-10-22 12:11:47 +02:00
|
|
|
chatListView.setOnItemClickListener(null);
|
2014-10-10 19:16:39 +02:00
|
|
|
openSecretPhotoRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (openSecretPhotoRunnable == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
chatListView.requestDisallowInterceptTouchEvent(true);
|
|
|
|
chatListView.setOnItemLongClickListener(null);
|
|
|
|
chatListView.setLongClickable(false);
|
|
|
|
openSecretPhotoRunnable = null;
|
2014-10-21 22:35:16 +02:00
|
|
|
if (sendSecretMessageRead(messageObject)) {
|
2014-10-10 19:16:39 +02:00
|
|
|
cell.invalidate();
|
|
|
|
}
|
|
|
|
SecretPhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
SecretPhotoViewer.getInstance().openPhoto(messageObject);
|
|
|
|
}
|
|
|
|
};
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.runOnUIThread(openSecretPhotoRunnable, 100);
|
2014-10-10 19:16:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-11 15:32:09 +01:00
|
|
|
}
|
2014-10-10 19:16:39 +02:00
|
|
|
return false;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-10-10 19:16:39 +02:00
|
|
|
chatListView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
2014-10-11 13:30:32 +02:00
|
|
|
if (openSecretPhotoRunnable != null || SecretPhotoViewer.getInstance().isVisible()) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-10-22 22:01:07 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setOnItemClickListener(onItemClickListener);
|
|
|
|
}
|
|
|
|
}, 150);
|
2014-10-11 13:30:32 +02:00
|
|
|
if (openSecretPhotoRunnable != null) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable);
|
2014-10-11 13:30:32 +02:00
|
|
|
openSecretPhotoRunnable = null;
|
2014-10-22 12:11:47 +02:00
|
|
|
try {
|
|
|
|
Toast.makeText(v.getContext(), LocaleController.getString("PhotoTip", R.string.PhotoTip), Toast.LENGTH_SHORT).show();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-10-11 13:30:32 +02:00
|
|
|
} else {
|
|
|
|
if (SecretPhotoViewer.getInstance().isVisible()) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-10-11 13:30:32 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-22 12:11:47 +02:00
|
|
|
chatListView.setOnItemLongClickListener(onItemLongClickListener);
|
2014-10-11 13:30:32 +02:00
|
|
|
chatListView.setLongClickable(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
SecretPhotoViewer.getInstance().closePhoto();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (event.getAction() != MotionEvent.ACTION_DOWN) {
|
2014-10-10 19:16:39 +02:00
|
|
|
if (SecretPhotoViewer.getInstance().isVisible()) {
|
2014-10-11 13:30:32 +02:00
|
|
|
return true;
|
|
|
|
} else if (openSecretPhotoRunnable != null) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities.dp(5)) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable);
|
2014-10-11 13:30:32 +02:00
|
|
|
openSecretPhotoRunnable = null;
|
2014-10-10 19:16:39 +02:00
|
|
|
}
|
2014-10-11 13:30:32 +02:00
|
|
|
} else {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable);
|
2014-10-10 19:16:39 +02:00
|
|
|
openSecretPhotoRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
chatListView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView absListView, int i) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
if (visibleItemCount > 0) {
|
2014-10-18 01:06:51 +02:00
|
|
|
if (firstVisibleItem <= 10) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (!endReached && !loading) {
|
|
|
|
if (messagesByDays.size() != 0) {
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, 0);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 20, 0, !cacheEndReaced, minDate, classGuid, 0);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
loading = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached && !loadingForward) {
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 20, minMessageId, true, maxDate, classGuid, 1);
|
2013-12-20 20:25:49 +01:00
|
|
|
loadingForward = true;
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
if (firstVisibleItem + visibleItemCount == totalItemCount && forward_end_reached) {
|
2013-12-20 20:25:49 +01:00
|
|
|
showPagedownButton(false, true);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
for (int a = 0; a < visibleItemCount; a++) {
|
|
|
|
View view = absListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatMessageCell) {
|
|
|
|
ChatMessageCell messageCell = (ChatMessageCell)view;
|
|
|
|
messageCell.getLocalVisibleRect(scrollRect);
|
|
|
|
messageCell.setVisiblePart(scrollRect.top, scrollRect.bottom - scrollRect.top);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
bottomOverlayChatText = (TextView)fragmentView.findViewById(R.id.bottom_overlay_chat_text);
|
|
|
|
TextView textView = (TextView)fragmentView.findViewById(R.id.secret_title);
|
2014-03-22 23:31:55 +01:00
|
|
|
textView.setText(LocaleController.getString("EncryptedDescriptionTitle", R.string.EncryptedDescriptionTitle));
|
|
|
|
textView = (TextView)fragmentView.findViewById(R.id.secret_description1);
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription1", R.string.EncryptedDescription1));
|
|
|
|
textView = (TextView)fragmentView.findViewById(R.id.secret_description2);
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription2", R.string.EncryptedDescription2));
|
|
|
|
textView = (TextView)fragmentView.findViewById(R.id.secret_description3);
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription3", R.string.EncryptedDescription3));
|
|
|
|
textView = (TextView)fragmentView.findViewById(R.id.secret_description4);
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription4", R.string.EncryptedDescription4));
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (loading && messages.isEmpty()) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
chatListView.setEmptyView(null);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.GONE);
|
2014-09-30 00:48:11 +02:00
|
|
|
chatListView.setEmptyView(emptyViewContainer);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
pagedownButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-03-22 23:31:55 +01:00
|
|
|
scrollToLastMessage();
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bottomOverlayChat.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-05-17 01:05:49 +02:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2014-08-22 16:24:33 +02:00
|
|
|
if (currentUser != null && userBlocked) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
MessagesController.getInstance().unblockUser(currentUser.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
MessagesController.getInstance().deleteDialog(dialog_id, 0, false);
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-17 01:05:49 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-07 01:35:21 +02:00
|
|
|
showAlertDialog(builder);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
updateBottomOverlay();
|
2014-07-03 00:39:05 +02:00
|
|
|
|
|
|
|
chatActivityEnterView.setContainerView(getParentActivity(), fragmentView);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
private boolean sendSecretMessageRead(MessageObject messageObject) {
|
2014-10-23 17:30:35 +02:00
|
|
|
if (messageObject == null || messageObject.isOut() || !messageObject.isSecretMedia() || messageObject.messageOwner.destroyTime != 0 || messageObject.messageOwner.ttl <= 0) {
|
2014-10-21 22:35:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
MessagesController.getInstance().markMessageAsRead(dialog_id, messageObject.messageOwner.random_id, messageObject.messageOwner.ttl);
|
2014-10-21 22:35:16 +02:00
|
|
|
messageObject.messageOwner.destroyTime = messageObject.messageOwner.ttl + ConnectionsManager.getInstance().getCurrentTime();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:31:55 +01:00
|
|
|
private void scrollToLastMessage() {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (forward_end_reached || first_unread_id == 0) {
|
2014-03-22 23:31:55 +01:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
} else {
|
|
|
|
messages.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messagesDict.clear();
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
chatListView.setEmptyView(null);
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
forward_end_reached = true;
|
2014-03-22 23:31:55 +01:00
|
|
|
loading = true;
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, true, 0, classGuid, 0);
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
private void showPagedownButton(boolean show, boolean animated) {
|
|
|
|
if (pagedownButton == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (show) {
|
|
|
|
if (pagedownButton.getVisibility() == View.GONE) {
|
2014-10-01 00:36:18 +02:00
|
|
|
if (Build.VERSION.SDK_INT > 13 && animated) {
|
2013-12-20 20:25:49 +01:00
|
|
|
pagedownButton.setVisibility(View.VISIBLE);
|
|
|
|
pagedownButton.setAlpha(0);
|
2014-08-22 16:24:33 +02:00
|
|
|
pagedownButton.animate().alpha(1).setDuration(200).setListener(null).start();
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
|
|
|
pagedownButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pagedownButton.getVisibility() == View.VISIBLE) {
|
2014-10-01 00:36:18 +02:00
|
|
|
if (Build.VERSION.SDK_INT > 13 && animated) {
|
2014-07-30 09:49:39 +02:00
|
|
|
pagedownButton.animate().alpha(0).setDuration(200).setListener(new Animator.AnimatorListener() {
|
2013-12-20 20:25:49 +01:00
|
|
|
@Override
|
2014-07-30 09:49:39 +02:00
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
2013-12-20 20:25:49 +01:00
|
|
|
pagedownButton.setVisibility(View.GONE);
|
|
|
|
}
|
2014-07-30 09:49:39 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animation) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}).start();
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
|
|
|
pagedownButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private void updateSecretStatus() {
|
|
|
|
if (bottomOverlay == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat == null || secretViewStatusTextView == null) {
|
|
|
|
bottomOverlay.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean hideKeyboard = false;
|
|
|
|
if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
|
2014-03-22 23:31:55 +01:00
|
|
|
bottomOverlayText.setText(LocaleController.getString("EncryptionProcessing", R.string.EncryptionProcessing));
|
2013-10-25 17:19:00 +02:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
|
2014-03-22 23:31:55 +01:00
|
|
|
bottomOverlayText.setText(Html.fromHtml(LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, "<b>" + currentUser.first_name + "</b>")));
|
2013-10-25 17:19:00 +02:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
|
2014-03-22 23:31:55 +01:00
|
|
|
bottomOverlayText.setText(LocaleController.getString("EncryptionRejected", R.string.EncryptionRejected));
|
2013-10-25 17:19:00 +02:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChat) {
|
|
|
|
bottomOverlay.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (hideKeyboard) {
|
2014-07-03 00:39:05 +02:00
|
|
|
chatActivityEnterView.hideEmojiPopup();
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
checkActionBarMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkActionBarMenu() {
|
|
|
|
if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat) ||
|
|
|
|
currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) ||
|
|
|
|
currentUser != null && (currentUser instanceof TLRPC.TL_userDeleted || currentUser instanceof TLRPC.TL_userEmpty)) {
|
|
|
|
|
|
|
|
if (menuItem != null) {
|
|
|
|
menuItem.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeItem != null) {
|
|
|
|
timeItem.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (menuItem != null) {
|
|
|
|
menuItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeItem != null) {
|
|
|
|
timeItem.setVisibility(View.VISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
if (timeItem != null) {
|
|
|
|
timerButton = (TimerButton)timeItem.findViewById(R.id.chat_timer);
|
|
|
|
timerButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-14 22:36:15 +02:00
|
|
|
showAlertDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat));
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
timerButton.setTime(currentEncryptedChat.ttl);
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
checkAndUpdateAvatar();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateOnlineCount() {
|
|
|
|
if (info == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onlineCount = 0;
|
2014-03-22 23:31:55 +01:00
|
|
|
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
|
2013-10-25 17:19:00 +02:00
|
|
|
for (TLRPC.TL_chatParticipant participant : info.participants) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
|
2014-06-13 12:42:21 +02:00
|
|
|
if (user != null && user.status != null && (user.status.expires > currentTime || user.id == UserConfig.getClientUserId()) && user.status.expires > 10000) {
|
2013-10-25 17:19:00 +02:00
|
|
|
onlineCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSubtitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getMessageType(MessageObject messageObject) {
|
2014-10-20 13:30:05 +02:00
|
|
|
if (messageObject == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
2014-10-20 13:30:05 +02:00
|
|
|
boolean isBroadcastError = isBroadcast && messageObject.messageOwner.id <= 0 && messageObject.isSendError();
|
|
|
|
if (!isBroadcast && messageObject.messageOwner.id <= 0 && messageObject.isOut() || isBroadcastError) {
|
2014-09-28 15:37:26 +02:00
|
|
|
if (messageObject.isSendError()) {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 6;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-29 23:06:04 +02:00
|
|
|
if (messageObject.type == 6) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return -1;
|
|
|
|
} else if (messageObject.type == 10 || messageObject.type == 11) {
|
|
|
|
if (messageObject.messageOwner.id == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
boolean canSave = false;
|
|
|
|
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
File f = new File(messageObject.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!canSave) {
|
2014-09-25 05:54:35 +02:00
|
|
|
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
|
2014-03-31 16:14:49 +02:00
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (canSave) {
|
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
String mime = messageObject.messageOwner.media.document.mime_type;
|
2014-04-04 19:58:33 +02:00
|
|
|
if (mime != null && mime.endsWith("/xml")) {
|
2014-04-02 19:36:57 +02:00
|
|
|
return 5;
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-29 23:06:04 +02:00
|
|
|
if (messageObject.type == 6) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return -1;
|
2014-09-28 15:37:26 +02:00
|
|
|
} else if (messageObject.isSendError()) {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 6;
|
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
} else if (messageObject.type == 10 || messageObject.type == 11) {
|
|
|
|
if (messageObject.isSending()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return -1;
|
2014-10-22 22:01:07 +02:00
|
|
|
} else {
|
|
|
|
return 1;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
boolean canSave = false;
|
|
|
|
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
File f = new File(messageObject.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!canSave) {
|
2014-09-25 05:54:35 +02:00
|
|
|
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
|
2014-03-31 16:14:49 +02:00
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (canSave) {
|
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
String mime = messageObject.messageOwner.media.document.mime_type;
|
2014-04-04 19:58:33 +02:00
|
|
|
if (mime != null && mime.endsWith("text/xml")) {
|
2014-04-02 19:36:57 +02:00
|
|
|
return 5;
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-30 22:27:41 +01:00
|
|
|
if (messageObject.messageOwner.ttl <= 0) {
|
|
|
|
return 4;
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addToSelectedMessages(MessageObject messageObject) {
|
|
|
|
if (selectedMessagesIds.containsKey(messageObject.messageOwner.id)) {
|
|
|
|
selectedMessagesIds.remove(messageObject.messageOwner.id);
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.type == 0) {
|
2013-10-25 17:19:00 +02:00
|
|
|
selectedMessagesCanCopyIds.remove(messageObject.messageOwner.id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
selectedMessagesIds.put(messageObject.messageOwner.id, messageObject);
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.type == 0) {
|
2013-10-25 17:19:00 +02:00
|
|
|
selectedMessagesCanCopyIds.put(messageObject.messageOwner.id, messageObject);
|
|
|
|
}
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
if (selectedMessagesIds.isEmpty()) {
|
|
|
|
actionBarLayer.hideActionMode();
|
|
|
|
}
|
|
|
|
actionBarLayer.createActionMode().getItem(copy).setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processRowSelect(View view) {
|
2014-02-28 23:28:25 +01:00
|
|
|
MessageObject message = null;
|
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
message = ((ChatBaseCell)view).getMessageObject();
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (view instanceof ChatActionCell) {
|
|
|
|
message = ((ChatActionCell)view).getMessageObject();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-15 21:57:09 +02:00
|
|
|
int type = getMessageType(message);
|
|
|
|
|
|
|
|
if (type < 2 || type == 6) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
addToSelectedMessages(message);
|
|
|
|
updateActionModeTitle();
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateActionModeTitle() {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (!actionBarLayer.isActionModeShowed()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
if (!selectedMessagesIds.isEmpty()) {
|
|
|
|
selectedMessagesCountTextView.setText(LocaleController.formatString("Selected", R.string.Selected, selectedMessagesIds.size()));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSubtitle() {
|
|
|
|
if (currentChat != null) {
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.setTitle(currentChat.title);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (currentUser != null) {
|
2014-06-22 11:49:25 +02:00
|
|
|
if (currentUser.id / 1000 != 777 && currentUser.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(currentUser.id) == null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts())) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser.phone != null && currentUser.phone.length() != 0) {
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.setTitle(PhoneFormat.getInstance().format("+" + currentUser.phone));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayer.setTitle(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBarLayer.setTitle(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:31:55 +01:00
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
|
2014-09-28 15:37:26 +02:00
|
|
|
if (printString != null) {
|
|
|
|
printString = TextUtils.replace(printString, new String[]{"..."}, new String[]{""});
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (printString == null || printString.length() == 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
lastPrintString = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
setTypingAnimation(false);
|
|
|
|
if (currentChat != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (currentChat instanceof TLRPC.TL_chatForbidden) {
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.setSubtitle(LocaleController.getString("YouWereKicked", R.string.YouWereKicked));
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (currentChat.left) {
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.setSubtitle(LocaleController.getString("YouLeft", R.string.YouLeft));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-07-31 02:50:12 +02:00
|
|
|
int count = currentChat.participants_count;
|
|
|
|
if (info != null) {
|
|
|
|
count = info.participants.size();
|
|
|
|
}
|
2014-10-05 23:23:57 +02:00
|
|
|
if (onlineCount > 1 && count != 0) {
|
|
|
|
actionBarLayer.setSubtitle(String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("Online", onlineCount)));
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2014-07-31 02:50:12 +02:00
|
|
|
actionBarLayer.setSubtitle(LocaleController.formatPluralString("Members", count));
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-05-17 01:05:49 +02:00
|
|
|
if (user != null) {
|
|
|
|
currentUser = user;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.setSubtitle(LocaleController.formatUserStatus(currentUser));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-04 19:36:55 +01:00
|
|
|
lastPrintString = printString;
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.setSubtitle(printString);
|
2013-10-25 17:19:00 +02:00
|
|
|
setTypingAnimation(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
private void setTypingAnimation(boolean start) {
|
|
|
|
if (actionBarLayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (start) {
|
|
|
|
try {
|
|
|
|
actionBarLayer.setSubTitleIcon(0, typingDotsDrawable, AndroidUtilities.dp(4));
|
|
|
|
typingDotsDrawable.start();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionBarLayer.setSubTitleIcon(0, null, 0);
|
|
|
|
if (typingDotsDrawable != null) {
|
|
|
|
typingDotsDrawable.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private void checkAndUpdateAvatar() {
|
|
|
|
TLRPC.FileLocation newPhoto = null;
|
2014-11-06 22:34:47 +01:00
|
|
|
AvatarDrawable avatarDrawable = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-04-05 07:55:51 +02:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentUser = user;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser.photo != null) {
|
|
|
|
newPhoto = currentUser.photo.photo_small;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarDrawable = new AvatarDrawable(currentUser);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (currentChat != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(currentChat.id);
|
2014-04-05 07:55:51 +02:00
|
|
|
if (chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentChat = chat;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentChat.photo != null) {
|
|
|
|
newPhoto = currentChat.photo.photo_small;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarDrawable = new AvatarDrawable(currentChat);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
if (avatarImageView != null) {
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarImageView.setImage(newPhoto, "50_50", avatarDrawable);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 13:30:05 +02:00
|
|
|
public boolean openVideoEditor(String videoPath, boolean removeLast) {
|
2014-10-15 20:43:52 +02:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putString("videoPath", videoPath);
|
|
|
|
VideoEditorActivity fragment = new VideoEditorActivity(args);
|
|
|
|
fragment.setDelegate(new VideoEditorActivity.VideoEditorActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didFinishEditVideo(String videoPath, long startTime, long endTime, int resultWidth, int resultHeight, int rotationValue, int originalWidth, int originalHeight, int bitrate, long estimatedSize, long estimatedDuration) {
|
|
|
|
TLRPC.VideoEditedInfo videoEditedInfo = new TLRPC.VideoEditedInfo();
|
|
|
|
videoEditedInfo.startTime = startTime;
|
|
|
|
videoEditedInfo.endTime = endTime;
|
|
|
|
videoEditedInfo.rotationValue = rotationValue;
|
|
|
|
videoEditedInfo.originalWidth = originalWidth;
|
|
|
|
videoEditedInfo.originalHeight = originalHeight;
|
|
|
|
videoEditedInfo.bitrate = bitrate;
|
|
|
|
videoEditedInfo.resultWidth = resultWidth;
|
|
|
|
videoEditedInfo.resultHeight = resultHeight;
|
|
|
|
videoEditedInfo.originalPath = videoPath;
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, estimatedSize, estimatedDuration, resultWidth, resultHeight, videoEditedInfo, dialog_id);
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
});
|
2014-10-22 22:01:07 +02:00
|
|
|
|
|
|
|
if (parentLayout == null || !fragment.onFragmentCreate()) {
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id);
|
2014-10-15 20:43:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
parentLayout.presentFragment(fragment, removeLast, true, true);
|
2014-10-15 20:43:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showAttachmentError() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnsupportedAttachment", R.string.UnsupportedAttachment), Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2014-03-26 21:16:28 +01:00
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
if (requestCode == 0) {
|
|
|
|
Utilities.addMediaToGallery(currentPicturePath);
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingPhoto(currentPicturePath, null, dialog_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
currentPicturePath = null;
|
|
|
|
} else if (requestCode == 1) {
|
2014-04-03 23:56:42 +02:00
|
|
|
if (data == null || data.getData() == null) {
|
2014-06-14 10:36:01 +02:00
|
|
|
showAttachmentError();
|
2014-02-04 19:36:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingPhoto(null, data.getData(), dialog_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (requestCode == 2) {
|
|
|
|
String videoPath = null;
|
|
|
|
if (data != null) {
|
|
|
|
Uri uri = data.getData();
|
|
|
|
boolean fromCamera = false;
|
|
|
|
if (uri != null && uri.getScheme() != null) {
|
|
|
|
fromCamera = uri.getScheme().contains("file");
|
|
|
|
} else if (uri == null) {
|
|
|
|
fromCamera = true;
|
|
|
|
}
|
|
|
|
if (fromCamera) {
|
|
|
|
if (uri != null) {
|
|
|
|
videoPath = uri.getPath();
|
|
|
|
} else {
|
|
|
|
videoPath = currentPicturePath;
|
|
|
|
}
|
|
|
|
Utilities.addMediaToGallery(currentPicturePath);
|
|
|
|
currentPicturePath = null;
|
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
try {
|
2014-02-11 15:32:09 +01:00
|
|
|
videoPath = Utilities.getPath(uri);
|
2013-12-20 20:25:49 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (videoPath == null && currentPicturePath != null) {
|
|
|
|
File f = new File(currentPicturePath);
|
|
|
|
if (f.exists()) {
|
|
|
|
videoPath = currentPicturePath;
|
|
|
|
}
|
|
|
|
currentPicturePath = null;
|
|
|
|
}
|
2014-10-01 00:36:18 +02:00
|
|
|
if(Build.VERSION.SDK_INT >= 16) {
|
|
|
|
if (paused) {
|
|
|
|
startVideoEdit = videoPath;
|
|
|
|
} else {
|
2014-10-20 13:30:05 +02:00
|
|
|
openVideoEditor(videoPath, false);
|
2014-10-01 00:36:18 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
} else {
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-06-14 10:36:01 +02:00
|
|
|
} else if (requestCode == 21) {
|
|
|
|
if (data == null || data.getData() == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String tempPath = Utilities.getPath(data.getData());
|
2014-06-20 02:18:13 +02:00
|
|
|
String originalPath = tempPath;
|
2014-06-14 10:36:01 +02:00
|
|
|
if (tempPath == null) {
|
2014-06-16 14:36:54 +02:00
|
|
|
originalPath = data.toString();
|
2014-06-14 10:36:01 +02:00
|
|
|
tempPath = MediaController.copyDocumentToCache(data.getData(), "file");
|
|
|
|
}
|
|
|
|
if (tempPath == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
return;
|
|
|
|
}
|
2014-10-16 22:02:44 +02:00
|
|
|
SendMessagesHelper.prepareSendingDocument(tempPath, originalPath, dialog_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void saveSelfArgs(Bundle args) {
|
|
|
|
if (currentPicturePath != null) {
|
|
|
|
args.putString("path", currentPicturePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restoreSelfArgs(Bundle args) {
|
|
|
|
currentPicturePath = args.getString("path");
|
|
|
|
}
|
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
private void removeUnreadPlane(boolean reload) {
|
|
|
|
if (unreadMessageObject != null) {
|
|
|
|
messages.remove(unreadMessageObject);
|
2014-10-31 20:02:29 +01:00
|
|
|
forward_end_reached = true;
|
2014-10-15 20:43:52 +02:00
|
|
|
first_unread_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = 0;
|
2014-10-15 20:43:52 +02:00
|
|
|
unread_to_load = 0;
|
|
|
|
unreadMessageObject = null;
|
|
|
|
if (reload) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
public boolean processSendingText(String text) {
|
2014-07-03 00:39:05 +02:00
|
|
|
return chatActivityEnterView.processSendingText(text);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, final Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.messagesDidLoaded) {
|
2013-10-25 17:19:00 +02:00
|
|
|
long did = (Long)args[0];
|
|
|
|
if (did == dialog_id) {
|
2014-09-24 04:17:27 +02:00
|
|
|
loadsCount++;
|
2014-08-02 01:31:15 +02:00
|
|
|
int count = (Integer)args[1];
|
|
|
|
boolean isCache = (Boolean)args[3];
|
|
|
|
int fnid = (Integer)args[4];
|
|
|
|
int last_unread_date = (Integer)args[7];
|
2014-10-31 20:02:29 +01:00
|
|
|
int load_type = (Integer)args[8];
|
2013-10-25 17:19:00 +02:00
|
|
|
boolean wasUnread = false;
|
2013-12-20 20:25:49 +01:00
|
|
|
if (fnid != 0) {
|
2014-08-02 01:31:15 +02:00
|
|
|
first_unread_id = fnid;
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = (Integer)args[5];
|
2014-08-02 01:31:15 +02:00
|
|
|
unread_to_load = (Integer)args[6];
|
2014-10-31 20:02:29 +01:00
|
|
|
} else if (startLoadFromMessageId != 0) {
|
|
|
|
last_message_id = (Integer)args[5];
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2014-08-02 01:31:15 +02:00
|
|
|
ArrayList<MessageObject> messArr = (ArrayList<MessageObject>)args[2];
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
int newRowsCount = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
|
|
|
|
forward_end_reached = startLoadFromMessageId == 0 && last_message_id == 0;
|
2014-08-02 01:31:15 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (loadsCount == 1 && messArr.size() > 20) {
|
|
|
|
loadsCount++;
|
|
|
|
}
|
|
|
|
|
2014-08-02 01:31:15 +02:00
|
|
|
if (firstLoading) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached) {
|
2014-08-02 01:31:15 +02:00
|
|
|
messages.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messagesDict.clear();
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
|
|
|
}
|
|
|
|
firstLoading = false;
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
for (int a = 0; a < messArr.size(); a++) {
|
|
|
|
MessageObject obj = messArr.get(a);
|
|
|
|
if (messagesDict.containsKey(obj.messageOwner.id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (obj.messageOwner.id > 0) {
|
|
|
|
maxMessageId = Math.min(obj.messageOwner.id, maxMessageId);
|
2013-12-20 20:25:49 +01:00
|
|
|
minMessageId = Math.max(obj.messageOwner.id, minMessageId);
|
|
|
|
} else if (currentEncryptedChat != null) {
|
2014-03-22 23:31:55 +01:00
|
|
|
maxMessageId = Math.max(obj.messageOwner.id, maxMessageId);
|
2013-12-20 20:25:49 +01:00
|
|
|
minMessageId = Math.min(obj.messageOwner.id, minMessageId);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
if (obj.messageOwner.date != 0) {
|
|
|
|
maxDate = Math.max(maxDate, obj.messageOwner.date);
|
|
|
|
if (minDate == 0 || obj.messageOwner.date < minDate) {
|
|
|
|
minDate = obj.messageOwner.date;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
|
|
|
|
if (obj.type < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-09-14 01:40:36 +02:00
|
|
|
if (!obj.isOut() && obj.isUnread()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
wasUnread = true;
|
|
|
|
}
|
|
|
|
messagesDict.put(obj.messageOwner.id, obj);
|
|
|
|
ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (dayArray == null) {
|
|
|
|
dayArray = new ArrayList<MessageObject>();
|
|
|
|
messagesByDays.put(obj.dateKey, dayArray);
|
|
|
|
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
2014-03-25 01:25:32 +01:00
|
|
|
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
|
2013-10-25 17:19:00 +02:00
|
|
|
dateMsg.id = 0;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null);
|
2014-08-29 23:06:04 +02:00
|
|
|
dateObj.type = 10;
|
2014-10-15 20:43:52 +02:00
|
|
|
dateObj.contentType = 4;
|
2014-10-31 20:02:29 +01:00
|
|
|
if (load_type == 1) {
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(0, dateObj);
|
|
|
|
} else {
|
|
|
|
messages.add(dateObj);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
newRowsCount++;
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
newRowsCount++;
|
|
|
|
dayArray.add(obj);
|
2014-10-31 20:02:29 +01:00
|
|
|
if (load_type == 1) {
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(0, obj);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(messages.size() - 1, obj);
|
|
|
|
}
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (load_type == 2 && obj.messageOwner.id == first_unread_id) {
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
|
|
|
dateMsg.message = "";
|
|
|
|
dateMsg.id = 0;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null);
|
|
|
|
dateObj.contentType = dateObj.type = 6;
|
|
|
|
boolean dateAdded = true;
|
|
|
|
if (a != messArr.size() - 1) {
|
|
|
|
MessageObject next = messArr.get(a + 1);
|
|
|
|
dateAdded = !next.dateKey.equals(obj.dateKey);
|
|
|
|
}
|
|
|
|
messages.add(messages.size() - (dateAdded ? 0 : 1), dateObj);
|
|
|
|
unreadMessageObject = dateObj;
|
|
|
|
scrollToMessage = unreadMessageObject;
|
|
|
|
newRowsCount++;
|
|
|
|
} else if (load_type == 3 && obj.messageOwner.id == startLoadFromMessageId) {
|
|
|
|
scrollToMessage = obj;
|
|
|
|
startLoadFromMessageId = 0;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (obj.messageOwner.id == last_message_id) {
|
|
|
|
forward_end_reached = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (forward_end_reached) {
|
2013-12-20 20:25:49 +01:00
|
|
|
first_unread_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = 0;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (load_type == 1) {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (messArr.size() != count) {
|
2014-10-31 20:02:29 +01:00
|
|
|
forward_end_reached = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
first_unread_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = 0;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
loadingForward = false;
|
|
|
|
} else {
|
|
|
|
if (messArr.size() != count) {
|
|
|
|
if (isCache) {
|
|
|
|
cacheEndReaced = true;
|
2014-10-20 13:30:05 +02:00
|
|
|
if (currentEncryptedChat != null || isBroadcast) {
|
2013-12-20 20:25:49 +01:00
|
|
|
endReached = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cacheEndReaced = true;
|
|
|
|
endReached = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
loading = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (chatListView != null) {
|
|
|
|
if (first || scrollToTopOnResume) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToMessage != null) {
|
|
|
|
if (messages.get(messages.size() - 1) == scrollToMessage) {
|
2014-07-03 00:39:05 +02:00
|
|
|
chatListView.setSelectionFromTop(0, AndroidUtilities.dp(-11));
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2014-10-31 20:02:29 +01:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - messages.indexOf(scrollToMessage), AndroidUtilities.dp(-11));
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
ViewTreeObserver obs = chatListView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (!messages.isEmpty()) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (messages.get(messages.size() - 1) == scrollToMessage) {
|
2014-07-03 00:39:05 +02:00
|
|
|
chatListView.setSelectionFromTop(0, AndroidUtilities.dp(-11));
|
|
|
|
} else {
|
2014-10-31 20:02:29 +01:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - messages.indexOf(scrollToMessage), AndroidUtilities.dp(-11));
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
chatListView.invalidate();
|
|
|
|
showPagedownButton(true, true);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-02-28 23:28:25 +01:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int firstVisPos = chatListView.getLastVisiblePosition();
|
|
|
|
View firstVisView = chatListView.getChildAt(chatListView.getChildCount() - 1);
|
|
|
|
int top = ((firstVisView == null) ? 0 : firstVisView.getTop()) - chatListView.getPaddingTop();
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
2014-06-12 03:13:15 +02:00
|
|
|
chatListView.setSelectionFromTop(firstVisPos + newRowsCount - (endReached ? 1 : 0), top);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToMessage != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopUnReadOnResume = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
|
|
|
if (first) {
|
|
|
|
if (chatListView.getEmptyView() == null) {
|
2014-09-30 00:48:11 +02:00
|
|
|
chatListView.setEmptyView(emptyViewContainer);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scrollToTopOnResume = true;
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToMessage != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopUnReadOnResume = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (first && messages.size() > 0) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (last_message_id != 0) {
|
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, last_message_id, 0, last_unread_date, wasUnread, false);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2014-08-08 12:17:06 +02:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, wasUnread, false);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.emojiDidLoaded) {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.invalidateViews();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.updateInterfaces) {
|
2013-10-25 17:19:00 +02:00
|
|
|
int updateMask = (Integer)args[0];
|
2014-02-11 15:32:09 +01:00
|
|
|
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) {
|
2013-10-25 17:19:00 +02:00
|
|
|
updateSubtitle();
|
|
|
|
updateOnlineCount();
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
2013-10-25 17:19:00 +02:00
|
|
|
checkAndUpdateAvatar();
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
2014-03-22 23:31:55 +01:00
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
|
2014-02-04 19:36:55 +01:00
|
|
|
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
|
|
|
updateSubtitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_USER_PHONE) != 0) {
|
|
|
|
updateContactStatus();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.didReceivedNewMessages) {
|
2013-10-25 17:19:00 +02:00
|
|
|
long did = (Long)args[0];
|
|
|
|
if (did == dialog_id) {
|
|
|
|
|
|
|
|
boolean updateChat = false;
|
2014-10-16 22:02:44 +02:00
|
|
|
boolean hasFromMe = false;
|
2013-12-20 20:25:49 +01:00
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>)args[1];
|
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
if (currentEncryptedChat != null && arr.size() == 1) {
|
2014-10-22 22:01:07 +02:00
|
|
|
MessageObject obj = arr.get(0);
|
|
|
|
|
|
|
|
if (currentEncryptedChat != null && obj.isOut() && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
|
|
|
|
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && getParentActivity() != null) {
|
|
|
|
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL)obj.messageOwner.action.encryptedAction;
|
|
|
|
if (AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 17 && currentEncryptedChat.ttl > 0 && currentEncryptedChat.ttl <= 60) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(R.string.OK, null);
|
|
|
|
builder.setMessage(LocaleController.formatString("CompatibilityChat", R.string.CompatibilityChat, currentUser.first_name, currentUser.first_name));
|
|
|
|
showAlertDialog(builder);
|
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached) {
|
2013-12-20 20:25:49 +01:00
|
|
|
int currentMaxDate = Integer.MIN_VALUE;
|
|
|
|
int currentMinMsgId = Integer.MIN_VALUE;
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
currentMinMsgId = Integer.MAX_VALUE;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
boolean currentMarkAsRead = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
for (MessageObject obj : arr) {
|
2014-10-22 22:01:07 +02:00
|
|
|
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
|
|
|
|
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && timerButton != null) {
|
|
|
|
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL)obj.messageOwner.action.encryptedAction;
|
|
|
|
timerButton.setTime(action.ttl_seconds);
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
2014-09-28 15:37:26 +02:00
|
|
|
if (obj.isOut() && obj.isSending()) {
|
2014-03-22 23:31:55 +01:00
|
|
|
scrollToLastMessage();
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (messagesDict.containsKey(obj.messageOwner.id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
currentMaxDate = Math.max(currentMaxDate, obj.messageOwner.date);
|
|
|
|
if (obj.messageOwner.id > 0) {
|
|
|
|
currentMinMsgId = Math.max(obj.messageOwner.id, currentMinMsgId);
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = Math.max(last_message_id, obj.messageOwner.id);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (currentEncryptedChat != null) {
|
|
|
|
currentMinMsgId = Math.min(obj.messageOwner.id, currentMinMsgId);
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = Math.min(last_message_id, obj.messageOwner.id);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
|
2014-09-14 01:40:36 +02:00
|
|
|
if (!obj.isOut() && obj.isUnread()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
unread_to_load++;
|
|
|
|
currentMarkAsRead = true;
|
|
|
|
}
|
|
|
|
if (obj.type == 10 || obj.type == 11) {
|
|
|
|
updateChat = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (currentMarkAsRead) {
|
|
|
|
if (paused) {
|
|
|
|
readWhenResume = true;
|
|
|
|
readWithDate = currentMaxDate;
|
|
|
|
readWithMid = currentMinMsgId;
|
|
|
|
} else {
|
2014-02-04 19:36:55 +01:00
|
|
|
if (messages.size() > 0) {
|
2014-08-08 12:17:06 +02:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, currentMinMsgId, 0, currentMaxDate, true, false);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
updateVisibleRows();
|
|
|
|
} else {
|
|
|
|
boolean markAsRead = false;
|
|
|
|
int oldCount = messages.size();
|
|
|
|
for (MessageObject obj : arr) {
|
2014-10-22 22:01:07 +02:00
|
|
|
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
|
|
|
|
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && timerButton != null) {
|
|
|
|
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL)obj.messageOwner.action.encryptedAction;
|
|
|
|
timerButton.setTime(action.ttl_seconds);
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (messagesDict.containsKey(obj.messageOwner.id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (minDate == 0 || obj.messageOwner.date < minDate) {
|
|
|
|
minDate = obj.messageOwner.date;
|
|
|
|
}
|
|
|
|
|
2014-04-03 23:18:54 +02:00
|
|
|
if (obj.isOut()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
removeUnreadPlane(false);
|
2014-10-16 22:02:44 +02:00
|
|
|
hasFromMe = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
|
2014-04-03 23:18:54 +02:00
|
|
|
if (!obj.isOut() && unreadMessageObject != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
unread_to_load++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.messageOwner.id > 0) {
|
|
|
|
maxMessageId = Math.min(obj.messageOwner.id, maxMessageId);
|
|
|
|
minMessageId = Math.max(obj.messageOwner.id, minMessageId);
|
|
|
|
} else if (currentEncryptedChat != null) {
|
2014-03-22 23:31:55 +01:00
|
|
|
maxMessageId = Math.max(obj.messageOwner.id, maxMessageId);
|
2013-12-20 20:25:49 +01:00
|
|
|
minMessageId = Math.min(obj.messageOwner.id, minMessageId);
|
|
|
|
}
|
|
|
|
maxDate = Math.max(maxDate, obj.messageOwner.date);
|
|
|
|
messagesDict.put(obj.messageOwner.id, obj);
|
|
|
|
ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);
|
|
|
|
if (dayArray == null) {
|
|
|
|
dayArray = new ArrayList<MessageObject>();
|
|
|
|
messagesByDays.put(obj.dateKey, dayArray);
|
|
|
|
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
2014-03-25 01:25:32 +01:00
|
|
|
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
|
2013-12-20 20:25:49 +01:00
|
|
|
dateMsg.id = 0;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null);
|
2014-08-29 23:06:04 +02:00
|
|
|
dateObj.type = 10;
|
2014-10-15 20:43:52 +02:00
|
|
|
dateObj.contentType = 4;
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(0, dateObj);
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
if (!obj.isOut() && obj.isUnread()) {
|
2014-07-20 23:49:33 +02:00
|
|
|
if (!paused) {
|
2014-10-09 17:55:05 +02:00
|
|
|
obj.setIsRead();
|
2014-07-20 23:49:33 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
markAsRead = true;
|
|
|
|
}
|
|
|
|
dayArray.add(0, obj);
|
|
|
|
messages.add(0, obj);
|
|
|
|
if (obj.type == 10 || obj.type == 11) {
|
|
|
|
updateChat = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (chatAdapter != null) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopOnResume = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
|
|
|
if (chatListView != null && chatAdapter != null) {
|
|
|
|
int lastVisible = chatListView.getLastVisiblePosition();
|
|
|
|
if (endReached) {
|
|
|
|
lastVisible++;
|
|
|
|
}
|
2014-10-16 22:02:44 +02:00
|
|
|
if (lastVisible == oldCount || hasFromMe) {
|
2014-08-02 01:31:15 +02:00
|
|
|
if (!firstLoading) {
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
} else {
|
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showPagedownButton(true, true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (markAsRead) {
|
|
|
|
if (paused) {
|
|
|
|
readWhenResume = true;
|
|
|
|
readWithDate = maxDate;
|
|
|
|
readWithMid = minMessageId;
|
|
|
|
} else {
|
2014-08-08 12:17:06 +02:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, true, false);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updateChat) {
|
|
|
|
updateSubtitle();
|
|
|
|
checkAndUpdateAvatar();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.closeChats) {
|
2014-09-30 00:48:11 +02:00
|
|
|
if (args != null && args.length > 0) {
|
|
|
|
long did = (Long)args[0];
|
|
|
|
if (did == dialog_id) {
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
removeSelfFromStack();
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
} else if (id == NotificationCenter.messagesRead) {
|
2013-10-25 17:19:00 +02:00
|
|
|
ArrayList<Integer> markAsReadMessages = (ArrayList<Integer>)args[0];
|
|
|
|
boolean updated = false;
|
|
|
|
for (Integer ids : markAsReadMessages) {
|
|
|
|
MessageObject obj = messagesDict.get(ids);
|
|
|
|
if (obj != null) {
|
2014-10-09 17:55:05 +02:00
|
|
|
obj.setIsRead();
|
2013-10-25 17:19:00 +02:00
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated) {
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messagesDeleted) {
|
2013-10-25 17:19:00 +02:00
|
|
|
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>)args[0];
|
|
|
|
boolean updated = false;
|
|
|
|
for (Integer ids : markAsDeletedMessages) {
|
|
|
|
MessageObject obj = messagesDict.get(ids);
|
|
|
|
if (obj != null) {
|
|
|
|
int index = messages.indexOf(obj);
|
2013-12-20 20:25:49 +01:00
|
|
|
if (index != -1) {
|
2013-10-25 17:19:00 +02:00
|
|
|
messages.remove(index);
|
2013-12-20 20:25:49 +01:00
|
|
|
messagesDict.remove(ids);
|
|
|
|
ArrayList<MessageObject> dayArr = messagesByDays.get(obj.dateKey);
|
|
|
|
dayArr.remove(obj);
|
|
|
|
if (dayArr.isEmpty()) {
|
|
|
|
messagesByDays.remove(obj.dateKey);
|
2014-06-15 01:23:36 +02:00
|
|
|
messages.remove(index);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
updated = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (messages.isEmpty()) {
|
|
|
|
if (!endReached && !loading) {
|
2014-03-22 23:31:55 +01:00
|
|
|
progressView.setVisibility(View.GONE);
|
2013-12-20 20:25:49 +01:00
|
|
|
chatListView.setEmptyView(null);
|
2014-03-22 23:31:55 +01:00
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, !cacheEndReaced, minDate, classGuid, 0);
|
2013-12-20 20:25:49 +01:00
|
|
|
loading = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated && chatAdapter != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
removeUnreadPlane(false);
|
2013-10-25 17:19:00 +02:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messageReceivedByServer) {
|
2013-10-25 17:19:00 +02:00
|
|
|
Integer msgId = (Integer)args[0];
|
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
|
|
|
Integer newMsgId = (Integer)args[1];
|
2014-10-22 22:01:07 +02:00
|
|
|
TLRPC.Message newMsgObj = (TLRPC.Message)args[2];
|
2014-03-22 23:31:55 +01:00
|
|
|
if (newMsgObj != null) {
|
2014-10-22 22:01:07 +02:00
|
|
|
obj.messageOwner.media = newMsgObj.media;
|
2014-08-06 01:17:40 +02:00
|
|
|
obj.generateThumbs(true, 1);
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
messagesDict.remove(msgId);
|
|
|
|
messagesDict.put(newMsgId, obj);
|
|
|
|
obj.messageOwner.id = newMsgId;
|
2014-08-22 16:24:33 +02:00
|
|
|
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messageReceivedByAck) {
|
2013-10-25 17:19:00 +02:00
|
|
|
Integer msgId = (Integer)args[0];
|
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messageSendError) {
|
2013-10-25 17:19:00 +02:00
|
|
|
Integer msgId = (Integer)args[0];
|
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.chatInfoDidLoaded) {
|
2013-10-25 17:19:00 +02:00
|
|
|
int chatId = (Integer)args[0];
|
|
|
|
if (currentChat != null && chatId == currentChat.id) {
|
|
|
|
info = (TLRPC.ChatParticipants)args[1];
|
|
|
|
updateOnlineCount();
|
2014-10-20 13:30:05 +02:00
|
|
|
if (isBroadcast) {
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().setCurrentChatInfo(info);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.contactsDidLoaded) {
|
2013-10-25 17:19:00 +02:00
|
|
|
updateContactStatus();
|
2013-12-20 20:25:49 +01:00
|
|
|
updateSubtitle();
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.encryptedChatUpdated) {
|
2013-10-25 17:19:00 +02:00
|
|
|
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)args[0];
|
|
|
|
if (currentEncryptedChat != null && chat.id == currentEncryptedChat.id) {
|
|
|
|
currentEncryptedChat = chat;
|
2013-12-20 20:25:49 +01:00
|
|
|
updateContactStatus();
|
2013-10-25 17:19:00 +02:00
|
|
|
updateSecretStatus();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messagesReadedEncrypted) {
|
2013-10-25 17:19:00 +02:00
|
|
|
int encId = (Integer)args[0];
|
|
|
|
if (currentEncryptedChat != null && currentEncryptedChat.id == encId) {
|
|
|
|
int date = (Integer)args[1];
|
|
|
|
boolean started = false;
|
|
|
|
for (MessageObject obj : messages) {
|
2014-04-03 23:18:54 +02:00
|
|
|
if (!obj.isOut()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
continue;
|
2014-10-09 17:55:05 +02:00
|
|
|
} else if (obj.isOut() && !obj.isUnread()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (obj.messageOwner.date <= date) {
|
2014-10-09 17:55:05 +02:00
|
|
|
obj.setIsRead();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.audioDidReset) {
|
2014-02-28 23:28:25 +01:00
|
|
|
Integer mid = (Integer)args[0];
|
|
|
|
if (chatListView != null) {
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatAudioCell) {
|
|
|
|
ChatAudioCell cell = (ChatAudioCell)view;
|
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().messageOwner.id == mid) {
|
|
|
|
cell.updateButtonState();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.audioProgressDidChanged) {
|
2014-02-28 23:28:25 +01:00
|
|
|
Integer mid = (Integer)args[0];
|
|
|
|
if (chatListView != null) {
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatAudioCell) {
|
|
|
|
ChatAudioCell cell = (ChatAudioCell)view;
|
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().messageOwner.id == mid) {
|
|
|
|
cell.updateProgress();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.removeAllMessagesFromDialog) {
|
2014-10-21 22:35:16 +02:00
|
|
|
long did = (Long)args[0];
|
|
|
|
if (dialog_id == did) {
|
|
|
|
messages.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messagesDict.clear();
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
chatListView.setEmptyView(emptyViewContainer);
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBarLayer.hideActionMode();
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.screenshotTook) {
|
2014-04-04 19:58:33 +02:00
|
|
|
updateInformationForScreenshotDetector();
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.blockedUsersDidLoaded) {
|
|
|
|
if (currentUser != null) {
|
|
|
|
boolean oldValue = userBlocked;
|
|
|
|
userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
|
|
|
|
if (oldValue != userBlocked) {
|
|
|
|
updateBottomOverlay();
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
} else if (id == NotificationCenter.FileNewChunkAvailable) {
|
|
|
|
MessageObject messageObject = (MessageObject)args[0];
|
|
|
|
long finalSize = (Long)args[2];
|
|
|
|
if (finalSize != 0 && dialog_id == messageObject.getDialogId()) {
|
|
|
|
MessageObject currentObject = messagesDict.get(messageObject.messageOwner.id);
|
|
|
|
if (currentObject != null) {
|
|
|
|
currentObject.messageOwner.media.video.size = (int)finalSize;
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
}
|
2014-10-10 19:16:39 +02:00
|
|
|
} else if (id == NotificationCenter.didCreatedNewDeleteTask) {
|
|
|
|
SparseArray<ArrayList<Integer>> mids = (SparseArray<ArrayList<Integer>>)args[0];
|
|
|
|
boolean changed = false;
|
|
|
|
for(int i = 0; i < mids.size(); i++) {
|
|
|
|
int key = mids.keyAt(i);
|
|
|
|
ArrayList<Integer> arr = mids.get(key);
|
|
|
|
for (Integer mid : arr) {
|
|
|
|
MessageObject messageObject = messagesDict.get(mid);
|
|
|
|
if (messageObject != null) {
|
|
|
|
messageObject.messageOwner.destroyTime = key;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
} else if (id == NotificationCenter.audioDidStarted) {
|
|
|
|
MessageObject messageObject = (MessageObject)args[0];
|
|
|
|
sendSecretMessageRead(messageObject);
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateBottomOverlay() {
|
|
|
|
if (currentUser == null) {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("DeleteThisGroup", R.string.DeleteThisGroup));
|
|
|
|
} else {
|
|
|
|
if (userBlocked) {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("Unblock", R.string.Unblock));
|
|
|
|
} else {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("DeleteThisChat", R.string.DeleteThisChat));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) ||
|
|
|
|
currentUser != null && (currentUser instanceof TLRPC.TL_userDeleted || currentUser instanceof TLRPC.TL_userEmpty || userBlocked)) {
|
|
|
|
bottomOverlayChat.setVisibility(View.VISIBLE);
|
|
|
|
chatActivityEnterView.setFieldFocused(false);
|
|
|
|
} else {
|
|
|
|
bottomOverlayChat.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateContactStatus() {
|
|
|
|
if (topPanel == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentUser == null) {
|
|
|
|
topPanel.setVisibility(View.GONE);
|
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-05-17 01:05:49 +02:00
|
|
|
if (user != null) {
|
|
|
|
currentUser = user;
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat)
|
2014-08-29 23:06:04 +02:00
|
|
|
|| currentUser.id / 1000 == 333 || currentUser.id / 1000 == 777
|
2014-05-17 01:05:49 +02:00
|
|
|
|| currentUser instanceof TLRPC.TL_userEmpty || currentUser instanceof TLRPC.TL_userDeleted
|
2014-08-29 23:06:04 +02:00
|
|
|
|| ContactsController.getInstance().isLoadingContacts()
|
|
|
|
|| (currentUser.phone != null && currentUser.phone.length() != 0 && ContactsController.getInstance().contactsDict.get(currentUser.id) != null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts()))) {
|
2013-10-25 17:19:00 +02:00
|
|
|
topPanel.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
topPanel.setVisibility(View.VISIBLE);
|
2014-07-03 00:39:05 +02:00
|
|
|
topPanelText.setShadowLayer(1, 0, AndroidUtilities.dp(1), 0xff8797a3);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (isCustomTheme) {
|
|
|
|
topPlaneClose.setImageResource(R.drawable.ic_msg_btn_cross_custom);
|
|
|
|
topPanel.setBackgroundResource(R.drawable.top_pane_custom);
|
|
|
|
} else {
|
|
|
|
topPlaneClose.setImageResource(R.drawable.ic_msg_btn_cross_custom);
|
|
|
|
topPanel.setBackgroundResource(R.drawable.top_pane);
|
|
|
|
}
|
|
|
|
if (currentUser.phone != null && currentUser.phone.length() != 0) {
|
2014-03-22 23:31:55 +01:00
|
|
|
if (MessagesController.getInstance().hidenAddToContacts.get(currentUser.id) != null) {
|
2013-10-25 17:19:00 +02:00
|
|
|
topPanel.setVisibility(View.INVISIBLE);
|
|
|
|
} else {
|
2014-03-22 23:31:55 +01:00
|
|
|
topPanelText.setText(LocaleController.getString("AddToContacts", R.string.AddToContacts));
|
2013-10-25 17:19:00 +02:00
|
|
|
topPlaneClose.setVisibility(View.VISIBLE);
|
|
|
|
topPlaneClose.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-03-22 23:31:55 +01:00
|
|
|
MessagesController.getInstance().hidenAddToContacts.put(currentUser.id, currentUser);
|
2013-10-25 17:19:00 +02:00
|
|
|
topPanel.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
topPanel.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", currentUser.id);
|
2014-06-04 01:31:48 +02:00
|
|
|
presentFragment(new ContactAddActivity(args));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-22 23:31:55 +01:00
|
|
|
if (MessagesController.getInstance().hidenAddToContacts.get(currentUser.id) != null) {
|
2013-10-25 17:19:00 +02:00
|
|
|
topPanel.setVisibility(View.INVISIBLE);
|
|
|
|
} else {
|
2014-03-22 23:31:55 +01:00
|
|
|
topPanelText.setText(LocaleController.getString("ShareMyContactInfo", R.string.ShareMyContactInfo));
|
2013-10-25 17:19:00 +02:00
|
|
|
topPlaneClose.setVisibility(View.GONE);
|
|
|
|
topPanel.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 21:27:43 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-07-10 23:15:39 +02:00
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureShareMyContactInfo", R.string.AreYouSureShareMyContactInfo));
|
2014-06-04 21:27:43 +02:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2014-06-04 21:27:43 +02:00
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
MessagesController.getInstance().hidenAddToContacts.put(currentUser.id, currentUser);
|
|
|
|
topPanel.setVisibility(View.GONE);
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().sendMessage(UserConfig.getCurrentUser(), dialog_id);
|
2014-06-04 21:27:43 +02:00
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
2014-06-04 21:27:43 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-07 01:35:21 +02:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onResume();
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
checkActionBarMenu();
|
|
|
|
if (chatAdapter != null) {
|
2013-10-25 17:19:00 +02:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
NotificationsController.getInstance().setOpennedDialogId(dialog_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (scrollToTopOnResume) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToTopUnReadOnResume && scrollToMessage != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (chatListView != null) {
|
2014-10-31 20:02:29 +01:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - messages.indexOf(scrollToMessage), -chatListView.getPaddingTop() - AndroidUtilities.dp(7));
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (chatListView != null) {
|
2014-07-11 23:47:50 +02:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopUnReadOnResume = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
scrollToTopOnResume = false;
|
2014-10-31 20:02:29 +01:00
|
|
|
scrollToMessage = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
paused = false;
|
|
|
|
if (readWhenResume && !messages.isEmpty()) {
|
2014-07-20 23:49:33 +02:00
|
|
|
for (MessageObject messageObject : messages) {
|
|
|
|
if (!messageObject.isUnread() && !messageObject.isFromMe()) {
|
|
|
|
break;
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
if (!messageObject.isOut()) {
|
2014-10-09 17:55:05 +02:00
|
|
|
messageObject.setIsRead();
|
2014-09-14 01:40:36 +02:00
|
|
|
}
|
2014-07-20 23:49:33 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
readWhenResume = false;
|
2014-08-08 12:17:06 +02:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, readWithMid, 0, readWithDate, true, false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-06-20 02:18:13 +02:00
|
|
|
fixLayout(true);
|
2014-02-04 19:36:55 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 17:19:00 +02:00
|
|
|
String lastMessageText = preferences.getString("dialog_" + dialog_id, null);
|
|
|
|
if (lastMessageText != null) {
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.remove("dialog_" + dialog_id);
|
|
|
|
editor.commit();
|
2014-07-03 00:39:05 +02:00
|
|
|
chatActivityEnterView.setFieldText(lastMessageText);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
if (bottomOverlayChat.getVisibility() != View.VISIBLE) {
|
|
|
|
chatActivityEnterView.setFieldFocused(true);
|
|
|
|
}
|
2014-04-04 19:58:33 +02:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
chatEnterTime = System.currentTimeMillis();
|
|
|
|
chatLeaveTime = 0;
|
|
|
|
}
|
2014-10-01 00:36:18 +02:00
|
|
|
|
|
|
|
if (startVideoEdit != null) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-10-01 00:36:18 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-20 13:30:05 +02:00
|
|
|
openVideoEditor(startVideoEdit, false);
|
2014-10-01 00:36:18 +02:00
|
|
|
startVideoEdit = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-10-10 19:16:39 +02:00
|
|
|
|
|
|
|
chatListView.setOnItemLongClickListener(onItemLongClickListener);
|
|
|
|
chatListView.setOnItemClickListener(onItemClickListener);
|
|
|
|
chatListView.setLongClickable(true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
@Override
|
|
|
|
public void onBeginSlide() {
|
2014-06-07 01:35:21 +02:00
|
|
|
super.onBeginSlide();
|
2014-07-03 00:39:05 +02:00
|
|
|
chatActivityEnterView.hideEmojiPopup();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onPause();
|
2014-11-06 22:34:47 +01:00
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.hideActionMode();
|
2014-07-03 00:39:05 +02:00
|
|
|
chatActivityEnterView.hideEmojiPopup();
|
2013-10-25 17:19:00 +02:00
|
|
|
paused = true;
|
2014-07-10 02:15:58 +02:00
|
|
|
NotificationsController.getInstance().setOpennedDialogId(0);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
String text = chatActivityEnterView.getFieldText();
|
|
|
|
if (text != null) {
|
2014-02-04 19:36:55 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 17:19:00 +02:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
2014-07-03 00:39:05 +02:00
|
|
|
editor.putString("dialog_" + dialog_id, text);
|
2013-10-25 17:19:00 +02:00
|
|
|
editor.commit();
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
chatActivityEnterView.setFieldFocused(false);
|
2014-08-23 01:22:33 +02:00
|
|
|
MessagesController.getInstance().cancelTyping(dialog_id);
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2014-10-20 20:11:47 +02:00
|
|
|
if (currentEncryptedChat != null) {
|
2014-04-04 19:58:33 +02:00
|
|
|
chatLeaveTime = System.currentTimeMillis();
|
|
|
|
updateInformationForScreenshotDetector();
|
2014-10-20 20:11:47 +02:00
|
|
|
}
|
2014-04-04 19:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateInformationForScreenshotDetector() {
|
2014-10-21 22:35:16 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 19:58:33 +02:00
|
|
|
ArrayList<Long> visibleMessages = new ArrayList<Long>();
|
|
|
|
if (chatListView != null) {
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
MessageObject object = null;
|
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
ChatBaseCell cell = (ChatBaseCell) view;
|
|
|
|
object = cell.getMessageObject();
|
|
|
|
}
|
|
|
|
if (object != null && object.messageOwner.id < 0 && object.messageOwner.random_id != 0) {
|
|
|
|
visibleMessages.add(object.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MediaController.getInstance().setLastEncryptedChatParams(chatEnterTime, chatLeaveTime, currentEncryptedChat, visibleMessages);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-06-20 02:18:13 +02:00
|
|
|
private void fixLayout(final boolean resume) {
|
2014-06-14 10:36:01 +02:00
|
|
|
final int lastPos = chatListView.getLastVisiblePosition();
|
2014-06-04 01:31:48 +02:00
|
|
|
ViewTreeObserver obs = chatListView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public boolean onPreDraw() {
|
2014-06-07 01:35:21 +02:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
}
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
int height = AndroidUtilities.getCurrentActionBarHeight();
|
2014-09-24 04:17:27 +02:00
|
|
|
if (!AndroidUtilities.isTablet() && getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
2014-06-04 01:31:48 +02:00
|
|
|
selectedMessagesCountTextView.setTextSize(16);
|
|
|
|
} else {
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
if (avatarImageView != null) {
|
|
|
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) avatarImageView.getLayoutParams();
|
|
|
|
params.width = height;
|
|
|
|
params.height = height;
|
|
|
|
avatarImageView.setLayoutParams(params);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-20 02:18:13 +02:00
|
|
|
if (!resume && lastPos >= messages.size() - 1) {
|
2014-06-14 10:36:01 +02:00
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
return false;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
2014-06-20 02:18:13 +02:00
|
|
|
fixLayout(false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void createMenu(View v, boolean single) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
MessageObject message = null;
|
|
|
|
if (v instanceof ChatBaseCell) {
|
|
|
|
message = ((ChatBaseCell)v).getMessageObject();
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (v instanceof ChatActionCell) {
|
|
|
|
message = ((ChatActionCell)v).getMessageObject();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2014-10-20 13:30:05 +02:00
|
|
|
if (message == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
final int type = getMessageType(message);
|
2014-06-13 17:03:06 +02:00
|
|
|
|
|
|
|
selectedObject = null;
|
|
|
|
forwaringMessage = null;
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
|
2014-07-15 21:57:09 +02:00
|
|
|
if (single || type < 2 || type == 6) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (type >= 0) {
|
|
|
|
selectedObject = message;
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
CharSequence[] items = null;
|
|
|
|
|
2014-07-15 21:57:09 +02:00
|
|
|
if (type == 0) {
|
|
|
|
items = new CharSequence[] {LocaleController.getString("Retry", R.string.Retry), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 1) {
|
|
|
|
items = new CharSequence[] {LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 6) {
|
|
|
|
items = new CharSequence[] {LocaleController.getString("Retry", R.string.Retry), LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (type == 2) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 3) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 4) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString(selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? "SaveToDownloads" : "SaveToGallery",
|
|
|
|
selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? R.string.SaveToDownloads : R.string.SaveToGallery), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 5) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (type == 2) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 3) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 4) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString(selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? "SaveToDownloads" : "SaveToGallery",
|
|
|
|
selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? R.string.SaveToDownloads : R.string.SaveToGallery), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
} else if (type == 5) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2014-06-13 17:03:06 +02:00
|
|
|
if (selectedObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (type == 0) {
|
|
|
|
if (i == 0) {
|
|
|
|
processSelectedOption(0);
|
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
} else if (type == 1) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
} else if (type == 2) {
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (i == 0) {
|
|
|
|
processSelectedOption(2);
|
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
} else if (type == 3) {
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (i == 0) {
|
|
|
|
processSelectedOption(2);
|
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(3);
|
|
|
|
} else if (i == 2) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i == 0) {
|
|
|
|
processSelectedOption(3);
|
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
} else if (type == 4) {
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (i == 0) {
|
2014-07-15 21:57:09 +02:00
|
|
|
processSelectedOption(4);
|
2014-03-22 23:31:55 +01:00
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(2);
|
|
|
|
} else if (i == 2) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i == 0) {
|
2014-10-30 22:27:41 +01:00
|
|
|
processSelectedOption(4);
|
2014-03-22 23:31:55 +01:00
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
} else if (type == 5) {
|
|
|
|
if (i == 0) {
|
2014-07-15 21:57:09 +02:00
|
|
|
processSelectedOption(5);
|
|
|
|
} else {
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (i == 1) {
|
|
|
|
processSelectedOption(4);
|
|
|
|
} else if (i == 2) {
|
|
|
|
processSelectedOption(2);
|
|
|
|
} else if (i == 3) {
|
|
|
|
processSelectedOption(1);
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
} else {
|
|
|
|
if (i == 1) {
|
|
|
|
processSelectedOption(1);
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
} else if (type == 6) {
|
|
|
|
if (i == 0) {
|
|
|
|
processSelectedOption(0);
|
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(3);
|
|
|
|
} else if (i == 2) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-02 19:36:57 +02:00
|
|
|
builder.setTitle(LocaleController.getString("Message", R.string.Message));
|
2014-06-07 01:35:21 +02:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
actionBarLayer.showActionMode();
|
2014-10-07 22:14:27 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
ArrayList<Animator> animators = new ArrayList<Animator>();
|
|
|
|
for (int a = 0; a < actionModeViews.size(); a++) {
|
|
|
|
View view = actionModeViews.get(a);
|
|
|
|
if (a < 2) {
|
|
|
|
animators.add(ObjectAnimator.ofFloat(view, "translationX", -AndroidUtilities.dp(56), 0));
|
|
|
|
} else {
|
|
|
|
animators.add(ObjectAnimator.ofFloat(view, "scaleY", 0.1f, 1.0f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.setDuration(250);
|
|
|
|
animatorSet.start();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
addToSelectedMessages(message);
|
|
|
|
updateActionModeTitle();
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processSelectedOption(int option) {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (selectedObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (option == 0) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (SendMessagesHelper.getInstance().retrySendMessage(selectedObject, false)) {
|
2014-07-11 23:47:50 +02:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else if (option == 1) {
|
2014-07-15 21:57:09 +02:00
|
|
|
ArrayList<Integer> ids = new ArrayList<Integer>();
|
|
|
|
ids.add(selectedObject.messageOwner.id);
|
|
|
|
removeUnreadPlane(true);
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
if (currentEncryptedChat != null && selectedObject.messageOwner.random_id != 0 && selectedObject.type != 10) {
|
|
|
|
random_ids = new ArrayList<Long>();
|
|
|
|
random_ids.add(selectedObject.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (option == 2) {
|
2014-07-15 21:57:09 +02:00
|
|
|
forwaringMessage = selectedObject;
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
|
|
|
args.putBoolean("serverOnly", true);
|
|
|
|
args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo));
|
2014-10-04 17:56:09 +02:00
|
|
|
args.putString("selectAlertStringGroup", LocaleController.getString("ForwardMessagesToGroup", R.string.ForwardMessagesToGroup));
|
2014-07-15 21:57:09 +02:00
|
|
|
MessagesActivity fragment = new MessagesActivity(args);
|
|
|
|
fragment.setDelegate(this);
|
|
|
|
presentFragment(fragment);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (option == 3) {
|
2014-10-01 00:36:18 +02:00
|
|
|
if(Build.VERSION.SDK_INT < 11) {
|
2014-07-15 21:57:09 +02:00
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(selectedObject.messageText);
|
|
|
|
} else {
|
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedObject.messageText);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
} else if (option == 4) {
|
|
|
|
String fileName = selectedObject.getFileName();
|
2014-09-30 00:48:11 +02:00
|
|
|
String path = selectedObject.messageOwner.attachPath;
|
2014-10-30 22:27:41 +01:00
|
|
|
if (path != null && path.length() > 0) {
|
|
|
|
File temp = new File(path);
|
|
|
|
if (!temp.exists()) {
|
|
|
|
path = null;
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
if (path == null || path.length() == 0) {
|
|
|
|
path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
|
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
if (selectedObject.type == 3) {
|
2014-09-30 00:48:11 +02:00
|
|
|
MediaController.saveFile(path, getParentActivity(), 1, null);
|
2014-07-15 21:57:09 +02:00
|
|
|
} else if (selectedObject.type == 1) {
|
2014-09-30 00:48:11 +02:00
|
|
|
MediaController.saveFile(path, getParentActivity(), 0, null);
|
2014-08-31 11:02:28 +02:00
|
|
|
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
|
2014-09-30 00:48:11 +02:00
|
|
|
MediaController.saveFile(path, getParentActivity(), 2, selectedObject.messageOwner.media.document.file_name);
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
|
|
|
} else if (option == 5) {
|
|
|
|
File locFile = null;
|
|
|
|
if (selectedObject.messageOwner.attachPath != null && selectedObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
File f = new File(selectedObject.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
|
|
|
locFile = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (locFile == null) {
|
2014-09-25 05:54:35 +02:00
|
|
|
File f = FileLoader.getPathToMessage(selectedObject.messageOwner);
|
2014-07-15 21:57:09 +02:00
|
|
|
if (f.exists()) {
|
|
|
|
locFile = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (locFile != null) {
|
|
|
|
if (LocaleController.getInstance().applyLanguageFile(locFile)) {
|
|
|
|
presentFragment(new LanguageSelectActivity());
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
showAlertDialog(builder);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
selectedObject = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-07-13 01:02:21 +02:00
|
|
|
private void forwardSelectedMessages(long did, boolean fromMyName) {
|
|
|
|
if (forwaringMessage != null) {
|
2014-07-27 00:28:33 +02:00
|
|
|
if (!fromMyName) {
|
|
|
|
if (forwaringMessage.messageOwner.id > 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().sendMessage(forwaringMessage, did);
|
2014-07-10 23:15:39 +02:00
|
|
|
}
|
2014-07-27 00:28:33 +02:00
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().processForwardFromMyName(forwaringMessage, did);
|
2014-07-13 01:02:21 +02:00
|
|
|
}
|
|
|
|
forwaringMessage = null;
|
|
|
|
} else {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
|
|
|
|
Collections.sort(ids);
|
|
|
|
for (Integer id : ids) {
|
2014-07-27 00:28:33 +02:00
|
|
|
if (!fromMyName) {
|
|
|
|
if (id > 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().sendMessage(selectedMessagesIds.get(id), did);
|
2014-07-10 23:15:39 +02:00
|
|
|
}
|
2014-07-27 00:28:33 +02:00
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().processForwardFromMyName(selectedMessagesIds.get(id), did);
|
2014-07-10 23:15:39 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-13 01:02:21 +02:00
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didSelectDialog(MessagesActivity activity, long did, boolean param) {
|
|
|
|
if (dialog_id != 0 && (forwaringMessage != null || !selectedMessagesIds.isEmpty())) {
|
2014-10-20 13:30:05 +02:00
|
|
|
if (isBroadcast) {
|
2014-07-27 00:28:33 +02:00
|
|
|
param = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (did != dialog_id) {
|
|
|
|
int lower_part = (int)did;
|
|
|
|
if (lower_part != 0) {
|
2014-06-04 01:31:48 +02:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("scrollToTopOnResume", scrollToTopOnResume);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (lower_part > 0) {
|
2014-06-04 01:31:48 +02:00
|
|
|
args.putInt("user_id", lower_part);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (lower_part < 0) {
|
2014-06-04 01:31:48 +02:00
|
|
|
args.putInt("chat_id", -lower_part);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-07-13 01:02:21 +02:00
|
|
|
presentFragment(new ChatActivity(args), true);
|
2014-08-02 01:31:15 +02:00
|
|
|
forwardSelectedMessages(did, param);
|
2014-09-30 00:48:11 +02:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
removeSelfFromStack();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
activity.finishFragment();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.finishFragment();
|
2014-07-13 01:02:21 +02:00
|
|
|
forwardSelectedMessages(did, param);
|
2014-07-11 23:47:50 +02:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2013-10-25 17:19:00 +02:00
|
|
|
scrollToTopOnResume = true;
|
2014-09-30 00:48:11 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBarLayer.hideActionMode();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBackPressed() {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBarLayer.hideActionMode();
|
|
|
|
updateVisibleRows();
|
|
|
|
return false;
|
2014-07-03 00:39:05 +02:00
|
|
|
} else if (chatActivityEnterView.isEmojiPopupShowing()) {
|
|
|
|
chatActivityEnterView.hideEmojiPopup();
|
2013-10-25 17:19:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGoogleMapsInstalled() {
|
|
|
|
try {
|
2014-06-14 10:36:01 +02:00
|
|
|
ApplicationInfo info = ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
|
2013-10-25 17:19:00 +02:00
|
|
|
return true;
|
|
|
|
} catch(PackageManager.NameNotFoundException e) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 17:19:00 +02:00
|
|
|
builder.setMessage("Install Google Maps?");
|
|
|
|
builder.setCancelable(true);
|
2014-03-22 23:31:55 +01:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
|
2014-06-04 01:31:48 +02:00
|
|
|
getParentActivity().startActivity(intent);
|
2013-10-25 17:19:00 +02:00
|
|
|
} catch (Exception e) {
|
2013-12-20 20:25:49 +01:00
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.Cancel, null);
|
2014-06-07 01:35:21 +02:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 17:19:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVisibleRows() {
|
|
|
|
if (chatListView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
Object tag = view.getTag();
|
2014-10-15 20:43:52 +02:00
|
|
|
if (view instanceof ChatBaseCell) {
|
2014-02-28 23:28:25 +01:00
|
|
|
ChatBaseCell cell = (ChatBaseCell)view;
|
|
|
|
|
|
|
|
boolean disableSelection = false;
|
|
|
|
boolean selected = false;
|
2014-06-04 01:31:48 +02:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2014-02-28 23:28:25 +01:00
|
|
|
if (selectedMessagesIds.containsKey(cell.getMessageObject().messageOwner.id)) {
|
|
|
|
view.setBackgroundColor(0x6633b5e5);
|
|
|
|
selected = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
disableSelection = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
|
2014-03-02 10:23:06 +01:00
|
|
|
cell.setMessageObject(cell.getMessageObject());
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
cell.setCheckPressed(!disableSelection, disableSelection && selected);
|
2014-02-11 15:32:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 23:18:54 +02:00
|
|
|
private void alertUserOpenError(MessageObject message) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-04-03 23:18:54 +02:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2014-10-21 22:35:16 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2014-04-03 23:18:54 +02:00
|
|
|
if (message.type == 3) {
|
2014-10-21 22:35:16 +02:00
|
|
|
builder.setMessage(LocaleController.getString("NoPlayerInstalled", R.string.NoPlayerInstalled));
|
2014-04-03 23:18:54 +02:00
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.messageOwner.media.document.mime_type));
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
showAlertDialog(builder);
|
2014-04-03 23:18:54 +02:00
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
@Override
|
2014-06-12 03:13:15 +02:00
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (messageObject == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
MessageObject messageToOpen = null;
|
|
|
|
ImageReceiver imageReceiver = null;
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatMediaCell) {
|
|
|
|
ChatMediaCell cell = (ChatMediaCell)view;
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message != null && message.messageOwner.id == messageObject.messageOwner.id) {
|
|
|
|
messageToOpen = message;
|
|
|
|
imageReceiver = cell.getPhotoImage();
|
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (view instanceof ChatActionCell) {
|
|
|
|
ChatActionCell cell = (ChatActionCell)view;
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message != null && message.messageOwner.id == messageObject.messageOwner.id) {
|
|
|
|
messageToOpen = message;
|
|
|
|
imageReceiver = cell.getPhotoImage();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageToOpen != null) {
|
|
|
|
int coords[] = new int[2];
|
|
|
|
view.getLocationInWindow(coords);
|
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
2014-07-03 00:39:05 +02:00
|
|
|
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
|
2014-06-11 01:05:54 +02:00
|
|
|
object.parentView = chatListView;
|
|
|
|
object.imageReceiver = imageReceiver;
|
|
|
|
object.thumb = object.imageReceiver.getBitmap();
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-11 02:22:42 +02:00
|
|
|
@Override
|
2014-06-12 03:13:15 +02:00
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) { return false; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPhotoChecked(int index) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cancelButtonPressed() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() { return 0; }
|
2014-06-11 02:22:42 +02:00
|
|
|
|
2014-06-20 02:18:13 +02:00
|
|
|
private class ChatAdapter extends BaseFragmentAdapter {
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ChatAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int i) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
int count = messages.size();
|
2013-12-20 20:25:49 +01:00
|
|
|
if (count != 0) {
|
|
|
|
if (!endReached) {
|
|
|
|
count++;
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached) {
|
2013-12-20 20:25:49 +01:00
|
|
|
count++;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return null;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
2013-12-20 20:25:49 +01:00
|
|
|
return true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
int offset = 1;
|
2014-10-31 20:02:29 +01:00
|
|
|
if ((!endReached || !forward_end_reached) && messages.size() != 0) {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (!endReached) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
if (i == 0 && !endReached || !forward_end_reached && i == (messages.size() + 1 - offset)) {
|
2014-10-14 22:36:15 +02:00
|
|
|
View progressBar = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
2013-12-20 20:25:49 +01:00
|
|
|
view = li.inflate(R.layout.chat_loading_layout, viewGroup, false);
|
2014-10-14 22:36:15 +02:00
|
|
|
progressBar = view.findViewById(R.id.progressLayout);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (isCustomTheme) {
|
2013-12-20 20:25:49 +01:00
|
|
|
progressBar.setBackgroundResource(R.drawable.system_loader2);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
progressBar.setBackgroundResource(R.drawable.system_loader1);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-10-14 22:36:15 +02:00
|
|
|
} else {
|
|
|
|
progressBar = view.findViewById(R.id.progressLayout);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-10-14 22:36:15 +02:00
|
|
|
progressBar.setVisibility(loadsCount > 1 ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
2014-10-09 17:55:05 +02:00
|
|
|
final MessageObject message = messages.get(messages.size() - i - offset);
|
2014-03-31 16:14:49 +02:00
|
|
|
int type = message.contentType;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (view == null) {
|
|
|
|
if (type == 0) {
|
2014-03-31 16:14:49 +02:00
|
|
|
view = new ChatMessageCell(mContext);
|
2014-04-03 23:18:54 +02:00
|
|
|
} if (type == 1) {
|
2014-03-31 16:14:49 +02:00
|
|
|
view = new ChatMediaCell(mContext);
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (type == 2) {
|
|
|
|
view = new ChatAudioCell(mContext);
|
2014-08-29 23:06:04 +02:00
|
|
|
} else if (type == 3) {
|
2014-10-15 20:43:52 +02:00
|
|
|
view = new ChatContactCell(mContext);
|
2014-08-29 23:06:04 +02:00
|
|
|
} else if (type == 6) {
|
2014-10-14 22:36:15 +02:00
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
2013-12-20 20:25:49 +01:00
|
|
|
view = li.inflate(R.layout.chat_unread_layout, viewGroup, false);
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (type == 4) {
|
|
|
|
view = new ChatActionCell(mContext);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
((ChatBaseCell)view).setDelegate(new ChatBaseCell.ChatBaseCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user) {
|
2014-10-16 22:02:44 +02:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
processRowSelect(cell);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
if (user != null && user.id != UserConfig.getClientUserId()) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", user.id);
|
|
|
|
presentFragment(new UserProfileActivity(args));
|
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
@Override
|
|
|
|
public void didPressedCancelSendButton(ChatBaseCell cell) {
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message.messageOwner.send_state != 0) {
|
|
|
|
SendMessagesHelper.getInstance().cancelSendingMessage(message);
|
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2014-04-01 03:00:35 +02:00
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
@Override
|
|
|
|
public void didLongPressed(ChatBaseCell cell) {
|
|
|
|
createMenu(cell, false);
|
|
|
|
}
|
2014-04-01 03:00:35 +02:00
|
|
|
|
2014-03-31 16:14:49 +02:00
|
|
|
@Override
|
2014-10-15 20:43:52 +02:00
|
|
|
public boolean canPerformActions() {
|
|
|
|
return actionBarLayer != null && !actionBarLayer.isActionModeShowed();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (view instanceof ChatMediaCell) {
|
|
|
|
((ChatMediaCell) view).setMediaDelegate(new ChatMediaCell.ChatMediaCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didClickedImage(ChatMediaCell cell) {
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message.isSendError()) {
|
|
|
|
createMenu(cell, false);
|
|
|
|
return;
|
|
|
|
} else if (message.isSending()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (message.type == 1) {
|
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
PhotoViewer.getInstance().openPhoto(message, ChatActivity.this);
|
|
|
|
} else if (message.type == 3) {
|
2014-10-21 22:35:16 +02:00
|
|
|
sendSecretMessageRead(message);
|
2014-10-15 20:43:52 +02:00
|
|
|
try {
|
|
|
|
File f = null;
|
|
|
|
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
|
|
|
|
f = new File(message.messageOwner.attachPath);
|
|
|
|
}
|
|
|
|
if (f == null || f != null && !f.exists()) {
|
|
|
|
f = FileLoader.getPathToMessage(message.messageOwner);
|
|
|
|
}
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
|
|
|
|
getParentActivity().startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
alertUserOpenError(message);
|
|
|
|
}
|
|
|
|
} else if (message.type == 4) {
|
|
|
|
if (!isGoogleMapsInstalled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LocationActivity fragment = new LocationActivity();
|
|
|
|
fragment.setMessageObject(message);
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (message.type == 9) {
|
2014-04-03 23:18:54 +02:00
|
|
|
File f = null;
|
2014-10-15 20:43:52 +02:00
|
|
|
String fileName = message.getFileName();
|
2014-04-03 23:18:54 +02:00
|
|
|
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
|
|
|
|
f = new File(message.messageOwner.attachPath);
|
|
|
|
}
|
|
|
|
if (f == null || f != null && !f.exists()) {
|
2014-09-25 05:54:35 +02:00
|
|
|
f = FileLoader.getPathToMessage(message.messageOwner);
|
2014-04-03 23:18:54 +02:00
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
if (f != null && f.exists()) {
|
|
|
|
String realMimeType = null;
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
if (message.type == 8 || message.type == 9) {
|
|
|
|
MimeTypeMap myMime = MimeTypeMap.getSingleton();
|
|
|
|
int idx = fileName.lastIndexOf(".");
|
|
|
|
if (idx != -1) {
|
|
|
|
String ext = fileName.substring(idx + 1);
|
|
|
|
realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
|
2014-11-06 22:34:47 +01:00
|
|
|
if (realMimeType == null) {
|
|
|
|
realMimeType = message.messageOwner.media.document.mime_type;
|
|
|
|
if (realMimeType == null || realMimeType.length() == 0) {
|
|
|
|
realMimeType = null;
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
if (realMimeType != null) {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), realMimeType);
|
|
|
|
} else {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
|
|
|
}
|
2014-08-29 23:06:04 +02:00
|
|
|
} else {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
if (realMimeType != null) {
|
|
|
|
try {
|
|
|
|
getParentActivity().startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
|
|
|
getParentActivity().startActivity(intent);
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-29 23:06:04 +02:00
|
|
|
getParentActivity().startActivity(intent);
|
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
alertUserOpenError(message);
|
2014-08-29 23:06:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-03 23:18:54 +02:00
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didPressedOther(ChatMediaCell cell) {
|
|
|
|
createMenu(cell, true);
|
|
|
|
}
|
|
|
|
});
|
2014-10-16 22:02:44 +02:00
|
|
|
} else if (view instanceof ChatContactCell) {
|
|
|
|
((ChatContactCell)view).setContactDelegate(new ChatContactCell.ChatContactCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didClickAddButton(ChatContactCell cell, TLRPC.User user) {
|
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
processRowSelect(cell);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-20 13:30:05 +02:00
|
|
|
MessageObject messageObject = cell.getMessageObject();
|
2014-10-16 22:02:44 +02:00
|
|
|
Bundle args = new Bundle();
|
2014-10-20 13:30:05 +02:00
|
|
|
args.putInt("user_id", messageObject.messageOwner.media.user_id);
|
|
|
|
args.putString("phone", messageObject.messageOwner.media.phone_number);
|
2014-10-16 22:02:44 +02:00
|
|
|
presentFragment(new ContactAddActivity(args));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didClickPhone(ChatContactCell cell) {
|
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
processRowSelect(cell);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final MessageObject messageObject = cell.getMessageObject();
|
|
|
|
if (getParentActivity() == null || messageObject.messageOwner.media.phone_number == null || messageObject.messageOwner.media.phone_number.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-10-21 22:35:16 +02:00
|
|
|
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() {
|
2014-10-16 22:02:44 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (i == 1) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + messageObject.messageOwner.media.phone_number));
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
getParentActivity().startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (i == 0) {
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(messageObject.messageOwner.media.phone_number);
|
|
|
|
} else {
|
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", messageObject.messageOwner.media.phone_number);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
showAlertDialog(builder);
|
|
|
|
}
|
|
|
|
});
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
} else if (view instanceof ChatActionCell) {
|
|
|
|
((ChatActionCell)view).setDelegate(new ChatActionCell.ChatActionCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didClickedImage(ChatActionCell cell) {
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
PhotoViewer.getInstance().openPhoto(message, ChatActivity.this);
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2014-09-25 16:57:17 +02:00
|
|
|
|
|
|
|
@Override
|
2014-10-15 20:43:52 +02:00
|
|
|
public void didLongPressed(ChatActionCell cell) {
|
|
|
|
createMenu(cell, false);
|
2014-09-25 16:57:17 +02:00
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void needOpenUserProfile(int uid) {
|
|
|
|
if (uid != UserConfig.getClientUserId()) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", uid);
|
|
|
|
presentFragment(new UserProfileActivity(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean selected = false;
|
|
|
|
boolean disableSelection = false;
|
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
if (selectedMessagesIds.containsKey(message.messageOwner.id)) {
|
|
|
|
view.setBackgroundColor(0x6633b5e5);
|
|
|
|
selected = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
disableSelection = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
ChatBaseCell baseCell = (ChatBaseCell)view;
|
|
|
|
baseCell.isChat = currentChat != null;
|
|
|
|
baseCell.setMessageObject(message);
|
|
|
|
baseCell.setCheckPressed(!disableSelection, disableSelection && selected);
|
2014-08-22 16:24:33 +02:00
|
|
|
if (view instanceof ChatAudioCell && MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_AUDIO)) {
|
2014-08-23 01:22:33 +02:00
|
|
|
((ChatAudioCell)view).downloadAudioIfNeed();
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2014-10-14 22:36:15 +02:00
|
|
|
} else if (view instanceof ChatActionCell) {
|
2014-10-15 20:43:52 +02:00
|
|
|
ChatActionCell actionCell = (ChatActionCell)view;
|
|
|
|
actionCell.setMessageObject(message);
|
|
|
|
actionCell.setUseBlackBackground(isCustomTheme);
|
|
|
|
}
|
|
|
|
if (type == 6) {
|
|
|
|
TextView messageTextView = (TextView)view.findViewById(R.id.chat_message_text);
|
|
|
|
messageTextView.setText(LocaleController.formatPluralString("NewMessages", unread_to_load));
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
int offset = 1;
|
|
|
|
if (!endReached && messages.size() != 0) {
|
|
|
|
offset = 0;
|
|
|
|
if (i == 0) {
|
2014-08-29 23:06:04 +02:00
|
|
|
return 5;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached && i == (messages.size() + 1 - offset)) {
|
2014-08-29 23:06:04 +02:00
|
|
|
return 5;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
MessageObject message = messages.get(messages.size() - i - offset);
|
2014-03-31 16:14:49 +02:00
|
|
|
return message.contentType;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
2014-10-15 20:43:52 +02:00
|
|
|
return 7;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
int count = messages.size();
|
2013-12-20 20:25:49 +01:00
|
|
|
if (count != 0) {
|
|
|
|
if (!endReached) {
|
|
|
|
count++;
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached) {
|
2013-12-20 20:25:49 +01:00
|
|
|
count++;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
return count == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|