2013-10-25 15:19:00 +00:00
|
|
|
/*
|
2013-12-20 19:25:49 +00:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 15:19:00 +00: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-02-28 22:28:25 +00:00
|
|
|
import android.animation.Animator;
|
2013-10-25 15:19:00 +00: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 22:31:55 +00:00
|
|
|
import android.content.res.Configuration;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.graphics.drawable.AnimationDrawable;
|
2014-06-14 08:36:01 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.media.MediaPlayer;
|
|
|
|
import android.media.ThumbnailUtils;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2014-03-22 22:31:55 +00:00
|
|
|
import android.os.PowerManager;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Html;
|
2014-06-03 23:31:48 +00:00
|
|
|
import android.text.TextUtils;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.style.ImageSpan;
|
|
|
|
import android.util.TypedValue;
|
2014-06-03 23:31:48 +00:00
|
|
|
import android.view.Gravity;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewParent;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
2014-02-28 22:28:25 +00:00
|
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
2014-02-04 18:36:55 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2013-12-26 11:43:37 +00:00
|
|
|
import android.webkit.MimeTypeMap;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.ImageView;
|
2014-06-03 23:31:48 +00:00
|
|
|
import android.widget.LinearLayout;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.PopupWindow;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
2014-06-14 08:36:01 +00:00
|
|
|
import android.widget.Toast;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-03-22 22:31:55 +00:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.MediaController;
|
2014-03-10 09:27:49 +00:00
|
|
|
import org.telegram.messenger.MessagesStorage;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-02-04 18:36:55 +00:00
|
|
|
import org.telegram.messenger.ContactsController;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.messenger.FileLog;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.objects.MessageObject;
|
|
|
|
import org.telegram.objects.PhotoObject;
|
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
|
|
|
import org.telegram.messenger.Emoji;
|
|
|
|
import org.telegram.messenger.FileLoader;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
import org.telegram.messenger.Utilities;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.ui.Cells.ChatAudioCell;
|
|
|
|
import org.telegram.ui.Cells.ChatBaseCell;
|
2014-03-31 14:14:49 +00:00
|
|
|
import org.telegram.ui.Cells.ChatMediaCell;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.ui.Cells.ChatMessageCell;
|
2014-06-03 23:31:48 +00:00
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.ui.Views.BackupImageView;
|
2014-06-03 23:31:48 +00:00
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.ui.Views.EmojiView;
|
2014-06-06 23:35:21 +00:00
|
|
|
import org.telegram.ui.Views.ImageReceiver;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.ui.Views.LayoutListView;
|
|
|
|
import org.telegram.ui.Views.MessageActionLayout;
|
|
|
|
import org.telegram.ui.Views.SizeNotifierRelativeLayout;
|
2014-03-10 09:27:49 +00:00
|
|
|
import org.telegram.ui.Views.TimerButton;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.HashMap;
|
2014-03-26 20:16:28 +00:00
|
|
|
import java.util.concurrent.Semaphore;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate,
|
|
|
|
NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate,
|
|
|
|
DocumentSelectActivity.DocumentSelectActivityDelegate, PhotoViewer.PhotoViewerProvider,
|
|
|
|
PhotoPickerActivity.PhotoPickerActivityDelegate {
|
2014-06-03 23:31:48 +00:00
|
|
|
|
|
|
|
private View timeItem;
|
|
|
|
private View menuItem;
|
2013-10-25 15:19:00 +00:00
|
|
|
private LayoutListView chatListView;
|
|
|
|
private BackupImageView avatarImageView;
|
|
|
|
private TLRPC.Chat currentChat;
|
|
|
|
private TLRPC.User currentUser;
|
|
|
|
private TLRPC.EncryptedChat currentEncryptedChat;
|
|
|
|
private ChatAdapter chatAdapter;
|
|
|
|
private EditText messsageEditText;
|
|
|
|
private ImageButton sendButton;
|
|
|
|
private PopupWindow emojiPopup;
|
|
|
|
private ImageView emojiButton;
|
|
|
|
private EmojiView emojiView;
|
2014-03-22 22:31:55 +00:00
|
|
|
private View slideText;
|
2013-10-25 15:19:00 +00:00
|
|
|
private boolean keyboardVisible;
|
2013-12-20 19:25:49 +00:00
|
|
|
private int keyboardHeight = 0;
|
|
|
|
private int keyboardHeightLand = 0;
|
2013-10-25 15:19:00 +00:00
|
|
|
private View topPanel;
|
|
|
|
private View secretChatPlaceholder;
|
|
|
|
private View contentView;
|
|
|
|
private View progressView;
|
|
|
|
private boolean ignoreTextChange = false;
|
|
|
|
private TextView emptyView;
|
|
|
|
private View bottomOverlay;
|
2014-02-28 22:28:25 +00:00
|
|
|
private View recordPanel;
|
|
|
|
private TextView recordTimeText;
|
2013-10-25 15:19:00 +00:00
|
|
|
private TextView bottomOverlayText;
|
2014-02-11 14:32:09 +00:00
|
|
|
private ImageButton audioSendButton;
|
2013-10-25 15:19:00 +00:00
|
|
|
private MessageObject selectedObject;
|
|
|
|
private MessageObject forwaringMessage;
|
|
|
|
private TextView secretViewStatusTextView;
|
2014-03-10 09:27:49 +00:00
|
|
|
private TimerButton timerButton;
|
2014-06-03 23:31:48 +00:00
|
|
|
private TextView selectedMessagesCountTextView;
|
2013-10-25 15:19:00 +00:00
|
|
|
private boolean paused = true;
|
|
|
|
private boolean readWhenResume = false;
|
2014-02-04 18:36:55 +00:00
|
|
|
private boolean sendByEnter = false;
|
2013-12-20 19:25:49 +00:00
|
|
|
private int readWithDate = 0;
|
|
|
|
private int readWithMid = 0;
|
2014-06-03 23:31:48 +00:00
|
|
|
private boolean scrollToTopOnResume = false;
|
2013-12-20 19:25:49 +00:00
|
|
|
private boolean scrollToTopUnReadOnResume = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
private boolean isCustomTheme = false;
|
2014-05-24 22:47:05 +00:00
|
|
|
private int downloadPhotos = 0;
|
|
|
|
private int downloadAudios = 0;
|
2013-10-25 15:19:00 +00:00
|
|
|
private ImageView topPlaneClose;
|
2013-12-20 19:25:49 +00:00
|
|
|
private View pagedownButton;
|
2013-10-25 15:19:00 +00:00
|
|
|
private TextView topPanelText;
|
|
|
|
private long dialog_id;
|
|
|
|
private SizeNotifierRelativeLayout sizeNotifierRelativeLayout;
|
|
|
|
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 19:25:49 +00:00
|
|
|
private int minMessageId = Integer.MIN_VALUE;
|
2013-10-25 15:19:00 +00:00
|
|
|
private int maxDate = Integer.MIN_VALUE;
|
|
|
|
private boolean endReached = false;
|
|
|
|
private boolean loading = false;
|
|
|
|
private boolean cacheEndReaced = false;
|
|
|
|
private long lastTypingTimeSend = 0;
|
|
|
|
private int minDate = 0;
|
|
|
|
private int progressTag = 0;
|
|
|
|
boolean first = true;
|
2013-12-20 19:25:49 +00:00
|
|
|
private int unread_to_load = 0;
|
|
|
|
private int first_unread_id = 0;
|
|
|
|
private int last_unread_id = 0;
|
|
|
|
private boolean unread_end_reached = true;
|
|
|
|
private boolean loadingForward = false;
|
|
|
|
private MessageObject unreadMessageObject = null;
|
2014-02-28 22:28:25 +00:00
|
|
|
private boolean recordingAudio = false;
|
|
|
|
private String lastTimeString = null;
|
2014-03-22 22:31:55 +00:00
|
|
|
private float startedDraggingX = -1;
|
|
|
|
private float distCanMove = Utilities.dp(80);
|
|
|
|
private PowerManager.WakeLock mWakeLock = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
private String currentPicturePath;
|
|
|
|
|
|
|
|
private TLRPC.ChatParticipants info = null;
|
|
|
|
private int onlineCount = -1;
|
|
|
|
|
|
|
|
private HashMap<String, ProgressBar> progressBarMap = new HashMap<String, ProgressBar>();
|
|
|
|
private HashMap<String, ArrayList<ProgressBar>> loadingFile = new HashMap<String, ArrayList<ProgressBar>>();
|
|
|
|
private HashMap<Integer, String> progressByTag = new HashMap<Integer, String>();
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
private CharSequence lastPrintString;
|
|
|
|
|
2014-04-04 17:58:33 +00:00
|
|
|
private long chatEnterTime = 0;
|
|
|
|
private long chatLeaveTime = 0;
|
|
|
|
|
2014-04-02 17:36:57 +00: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-06-03 23:31:48 +00:00
|
|
|
public ChatActivity(Bundle args) {
|
|
|
|
super(args);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2014-06-03 23:31:48 +00: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);
|
|
|
|
scrollToTopOnResume = arguments.getBoolean("scrollToTopOnResume", false);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (chatId != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
currentChat = MessagesController.getInstance().chats.get(chatId);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentChat == null) {
|
2014-03-26 20:16:28 +00:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
|
|
|
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentChat = MessagesStorage.getInstance().getChat(chatId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentChat != null) {
|
|
|
|
MessagesController.getInstance().chats.put(currentChat.id, currentChat);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadChatInfo(currentChat.id);
|
2013-10-25 15:19:00 +00:00
|
|
|
dialog_id = -chatId;
|
|
|
|
} else if (userId != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
currentUser = MessagesController.getInstance().users.get(userId);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentUser == null) {
|
2014-03-26 20:16:28 +00:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
|
|
|
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentUser = MessagesStorage.getInstance().getUser(userId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentUser != null) {
|
|
|
|
MessagesController.getInstance().users.putIfAbsent(currentUser.id, currentUser);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
dialog_id = userId;
|
|
|
|
} else if (encId != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
currentEncryptedChat = MessagesController.getInstance().encryptedChats.get(encId);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentEncryptedChat == null) {
|
2014-03-26 20:16:28 +00:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
|
|
|
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentEncryptedChat = MessagesStorage.getInstance().getEncryptedChat(encId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
MessagesController.getInstance().encryptedChats.putIfAbsent(currentEncryptedChat.id, currentEncryptedChat);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
currentUser = MessagesController.getInstance().users.get(currentEncryptedChat.user_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentUser == null) {
|
2014-03-26 20:16:28 +00:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
|
|
|
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
|
|
|
|
@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) {
|
|
|
|
MessagesController.getInstance().users.putIfAbsent(currentUser.id, currentUser);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
dialog_id = ((long)encId) << 32;
|
2014-03-22 22:31:55 +00:00
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
2013-12-20 19:25:49 +00:00
|
|
|
minMessageId = Integer.MAX_VALUE;
|
2014-04-04 17:58:33 +00:00
|
|
|
MediaController.getInstance().startMediaObserver();
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.messagesDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, 999);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.messagesReaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.messageSendError);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.chatInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.encryptedChatUpdated);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.messagesReadedEncrypted);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.removeAllMessagesFromDialog);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, FileLoader.FileUploadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, FileLoader.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, FileLoader.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, FileLoader.FileLoadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MediaController.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MediaController.audioDidReset);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged);
|
2014-03-23 00:09:24 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, MediaController.recordStarted);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, MediaController.recordStartError);
|
2014-03-23 00:24:19 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, MediaController.recordStopped);
|
2014-04-04 17:58:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, MediaController.screenshotTook);
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, 997);
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
super.onFragmentCreate();
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
loading = true;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false);
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
sendByEnter = preferences.getBoolean("send_by_enter", false);
|
|
|
|
|
|
|
|
if (currentChat != null) {
|
2014-05-24 22:47:05 +00:00
|
|
|
downloadPhotos = preferences.getInt("photo_download_chat2", 0);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else {
|
2014-05-24 22:47:05 +00:00
|
|
|
downloadPhotos = preferences.getInt("photo_download_user2", 0);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
if (currentChat != null) {
|
2014-05-24 22:47:05 +00:00
|
|
|
downloadAudios = preferences.getInt("audio_download_chat2", 0);
|
2014-03-22 22:31:55 +00:00
|
|
|
} else {
|
2014-05-24 22:47:05 +00:00
|
|
|
downloadAudios = preferences.getInt("audio_download_user2", 0);
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.messagesDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, 999);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.closeChats);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.messagesReaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.messageSendError);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.chatInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.encryptedChatUpdated);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.messagesReadedEncrypted);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.removeAllMessagesFromDialog);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, FileLoader.FileUploadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, FileLoader.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, FileLoader.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, FileLoader.FileLoadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MediaController.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MediaController.audioDidReset);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged);
|
2014-03-23 00:09:24 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStarted);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStartError);
|
2014-03-23 00:24:19 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStopped);
|
2014-04-04 17:58:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, MediaController.screenshotTook);
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, 997);
|
2014-04-04 17:58:33 +00:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
MediaController.getInstance().stopMediaObserver();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
if (sizeNotifierRelativeLayout != null) {
|
|
|
|
sizeNotifierRelativeLayout.delegate = null;
|
|
|
|
sizeNotifierRelativeLayout = null;
|
|
|
|
}
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
if (mWakeLock != null) {
|
|
|
|
try {
|
|
|
|
mWakeLock.release();
|
2014-03-23 00:24:19 +00:00
|
|
|
mWakeLock = null;
|
2014-03-22 22:31:55 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
Utilities.unlockOrientation(getParentActivity());
|
2014-03-22 22:31:55 +00:00
|
|
|
MediaController.getInstance().stopAudio();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (fragmentView == null) {
|
2014-06-12 01:13:15 +00:00
|
|
|
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
|
2014-06-12 15:53:20 +00:00
|
|
|
actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
|
2014-06-03 23:31:48 +00: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();
|
|
|
|
}
|
|
|
|
getParentActivity().startActivityForResult(takePictureIntent, 0);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (id == attach_gallery) {
|
2014-06-12 01:13:15 +00:00
|
|
|
PhotoPickerActivity fragment = new PhotoPickerActivity();
|
|
|
|
fragment.setDelegate(ChatActivity.this);
|
|
|
|
presentFragment(fragment);
|
2014-06-03 23:31:48 +00:00
|
|
|
} else if (id == attach_video) {
|
|
|
|
try {
|
|
|
|
Intent pickIntent = new Intent();
|
|
|
|
pickIntent.setType("video/*");
|
|
|
|
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
|
2014-06-12 19:55:13 +00:00
|
|
|
pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
|
2014-06-03 23:31:48 +00:00
|
|
|
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
|
|
|
|
File video = Utilities.generateVideoPath();
|
|
|
|
if (video != null) {
|
2014-06-12 19:55:13 +00:00
|
|
|
if (android.os.Build.VERSION.SDK_INT > 16) {
|
2014-06-03 23:31:48 +00:00
|
|
|
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
|
|
|
|
}
|
2014-06-12 19:55:13 +00:00
|
|
|
takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
|
2014-06-03 23:31:48 +00:00
|
|
|
currentPicturePath = video.getAbsolutePath();
|
|
|
|
}
|
|
|
|
Intent chooserIntent = Intent.createChooser(pickIntent, "");
|
2014-06-12 19:55:13 +00:00
|
|
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
|
2014-06-03 23:31:48 +00:00
|
|
|
|
|
|
|
getParentActivity().startActivityForResult(chooserIntent, 2);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (id == attach_location) {
|
|
|
|
if (!isGoogleMapsInstalled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LocationActivity fragment = new LocationActivity();
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (id == attach_document) {
|
|
|
|
DocumentSelectActivity fragment = new DocumentSelectActivity();
|
|
|
|
fragment.setDelegate(ChatActivity.this);
|
|
|
|
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-10 23:05:54 +00:00
|
|
|
if (info != null && info instanceof TLRPC.TL_chatParticipantsForbidden) {
|
|
|
|
return;
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
if (currentChat.participants_count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", currentChat.id);
|
2014-06-10 23:05:54 +00:00
|
|
|
ChatProfileActivity fragment = new ChatProfileActivity(args);
|
|
|
|
fragment.setChatInfo(info);
|
|
|
|
presentFragment(fragment);
|
2014-06-03 23:31:48 +00: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";
|
|
|
|
}
|
|
|
|
str += messageObject.messageOwner.message;
|
|
|
|
}
|
|
|
|
if (str.length() != 0) {
|
2014-06-12 19:55:13 +00:00
|
|
|
if (android.os.Build.VERSION.SDK_INT < 11) {
|
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
2014-06-03 23:31:48 +00:00
|
|
|
clipboard.setText(str);
|
|
|
|
} else {
|
2014-06-12 19:55:13 +00:00
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
2014-06-03 23:31:48 +00:00
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", str);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
2014-06-04 18:57:11 +00:00
|
|
|
actionBarLayer.hideActionMode();
|
2014-06-06 23:35:21 +00:00
|
|
|
updateVisibleRows();
|
2014-06-03 23:31:48 +00: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 18:57:11 +00:00
|
|
|
actionBarLayer.hideActionMode();
|
2014-06-03 23:31:48 +00: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));
|
|
|
|
MessagesActivity fragment = new MessagesActivity(args);
|
|
|
|
fragment.setDelegate(ChatActivity.this);
|
|
|
|
presentFragment(fragment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-12 15:53:20 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
updateSubtitle();
|
|
|
|
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
ActionBarMenu actionMode = actionBarLayer.createActionMode();
|
|
|
|
actionMode.addItem(-2, R.drawable.ic_ab_done_gray);
|
|
|
|
|
|
|
|
FrameLayout layout = new FrameLayout(actionMode.getContext());
|
|
|
|
layout.setBackgroundColor(0xffe5e5e5);
|
|
|
|
actionMode.addView(layout);
|
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)layout.getLayoutParams();
|
|
|
|
layoutParams.width = Utilities.dp(1);
|
|
|
|
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.topMargin = Utilities.dp(12);
|
|
|
|
layoutParams.bottomMargin = Utilities.dp(12);
|
|
|
|
layoutParams.gravity = Gravity.CENTER_VERTICAL;
|
|
|
|
layout.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
selectedMessagesCountTextView = new TextView(actionMode.getContext());
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
|
|
|
selectedMessagesCountTextView.setTextColor(0xff000000);
|
|
|
|
selectedMessagesCountTextView.setSingleLine(true);
|
|
|
|
selectedMessagesCountTextView.setLines(1);
|
|
|
|
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
selectedMessagesCountTextView.setPadding(Utilities.dp(6), 0, 0, 0);
|
|
|
|
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
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) {
|
|
|
|
actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy);
|
|
|
|
actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward);
|
|
|
|
actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete);
|
|
|
|
} else {
|
|
|
|
actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy);
|
|
|
|
actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete);
|
|
|
|
}
|
|
|
|
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 15:19:00 +00:00
|
|
|
fragmentView = inflater.inflate(R.layout.chat_layout, container, false);
|
|
|
|
|
|
|
|
sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout)fragmentView.findViewById(R.id.chat_layout);
|
|
|
|
sizeNotifierRelativeLayout.delegate = this;
|
|
|
|
contentView = sizeNotifierRelativeLayout;
|
|
|
|
|
|
|
|
emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
|
2014-03-22 22:31:55 +00:00
|
|
|
emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages));
|
2013-10-25 15:19:00 +00:00
|
|
|
chatListView = (LayoutListView)fragmentView.findViewById(R.id.chat_list_view);
|
2014-06-03 23:31:48 +00:00
|
|
|
chatListView.setAdapter(chatAdapter = new ChatAdapter(getParentActivity()));
|
2013-10-25 15:19:00 +00: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);
|
2013-12-20 19:25:49 +00:00
|
|
|
View bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat);
|
|
|
|
progressView = fragmentView.findViewById(R.id.progressLayout);
|
|
|
|
pagedownButton = fragmentView.findViewById(R.id.pagedown_button);
|
2014-02-11 14:32:09 +00:00
|
|
|
audioSendButton = (ImageButton)fragmentView.findViewById(R.id.chat_audio_send_button);
|
2014-02-28 22:28:25 +00:00
|
|
|
recordPanel = fragmentView.findViewById(R.id.record_panel);
|
|
|
|
recordTimeText = (TextView)fragmentView.findViewById(R.id.recording_time_text);
|
2013-12-20 19:25:49 +00:00
|
|
|
View progressViewInner = progressView.findViewById(R.id.progressLayoutInner);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
updateContactStatus();
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-12-20 19:25:49 +00:00
|
|
|
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
|
|
|
|
int selectedColor = preferences.getInt("selectedColor", 0);
|
|
|
|
if (selectedColor != 0) {
|
2014-06-14 08:36:01 +00:00
|
|
|
contentView.setBackgroundColor(selectedColor);
|
2013-12-20 19:25:49 +00:00
|
|
|
chatListView.setCacheColorHint(selectedColor);
|
|
|
|
} else {
|
|
|
|
chatListView.setCacheColorHint(0);
|
2014-06-14 08:36:01 +00: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 19:25:49 +00:00
|
|
|
}
|
2014-06-14 08:36:01 +00:00
|
|
|
isCustomTheme = true;
|
|
|
|
} else {
|
|
|
|
((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-14 08:36:01 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
contentView.setBackgroundColor(-2693905);
|
|
|
|
chatListView.setCacheColorHint(-2693905);
|
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder);
|
|
|
|
if (isCustomTheme) {
|
|
|
|
secretChatPlaceholder.setBackgroundResource(R.drawable.system_black);
|
|
|
|
} else {
|
|
|
|
secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue);
|
|
|
|
}
|
|
|
|
secretViewStatusTextView = (TextView)contentView.findViewById(R.id.invite_text);
|
2013-12-26 16:46:13 +00:00
|
|
|
secretChatPlaceholder.setPadding(Utilities.dp(16), Utilities.dp(12), Utilities.dp(16), Utilities.dp(12));
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
View v = contentView.findViewById(R.id.secret_placeholder);
|
|
|
|
v.setVisibility(View.VISIBLE);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-13 10:42:21 +00:00
|
|
|
if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) {
|
2013-12-26 11:43:37 +00:00
|
|
|
if (currentUser.first_name.length() > 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.first_name));
|
2013-12-26 11:43:37 +00:00
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.last_name));
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
2013-12-26 11:43:37 +00:00
|
|
|
if (currentUser.first_name.length() > 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.first_name));
|
2013-12-26 11:43:37 +00:00
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.last_name));
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
updateSecretStatus();
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
if (isCustomTheme) {
|
2013-12-20 19:25:49 +00:00
|
|
|
progressViewInner.setBackgroundResource(R.drawable.system_loader2);
|
|
|
|
emptyView.setBackgroundResource(R.drawable.system_black);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
progressViewInner.setBackgroundResource(R.drawable.system_loader1);
|
|
|
|
emptyView.setBackgroundResource(R.drawable.system_blue);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-26 16:46:13 +00:00
|
|
|
emptyView.setPadding(Utilities.dp(7), Utilities.dp(1), Utilities.dp(7), Utilities.dp(1));
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
if (currentUser != null && currentUser.id / 1000 == 333) {
|
2014-03-22 22:31:55 +00:00
|
|
|
emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chatListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (!actionBarLayer.isActionModeShowed()) {
|
2014-02-11 14:32:09 +00:00
|
|
|
createMenu(view, false);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
final Rect scrollRect = new Rect();
|
|
|
|
|
2013-10-25 15:19:00 +00: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) {
|
|
|
|
if (firstVisibleItem <= 4) {
|
|
|
|
if (!endReached && !loading) {
|
|
|
|
if (messagesByDays.size() != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 0, 20, 0, !cacheEndReaced, minDate, classGuid, false, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
loading = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (!unread_end_reached && !loadingForward) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 0, 20, minMessageId, true, maxDate, classGuid, false, true);
|
2013-12-20 19:25:49 +00:00
|
|
|
loadingForward = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) {
|
2013-12-20 19:25:49 +00:00
|
|
|
showPagedownButton(false, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showPagedownButton(false, false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-02-28 22:28:25 +00: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 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
messsageEditText = (EditText)fragmentView.findViewById(R.id.chat_text_edit);
|
2014-03-22 22:31:55 +00:00
|
|
|
messsageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
|
|
|
|
slideText = fragmentView.findViewById(R.id.slideText);
|
|
|
|
TextView textView = (TextView)fragmentView.findViewById(R.id.slideToCancelTextView);
|
|
|
|
textView.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
|
|
|
|
textView = (TextView)fragmentView.findViewById(R.id.bottom_overlay_chat_text);
|
2014-05-16 23:05:49 +00:00
|
|
|
if (currentUser == null) {
|
|
|
|
textView.setText(LocaleController.getString("DeleteThisGroup", R.string.DeleteThisGroup));
|
|
|
|
} else {
|
|
|
|
textView.setText(LocaleController.getString("DeleteThisChat", R.string.DeleteThisChat));
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
textView = (TextView)fragmentView.findViewById(R.id.secret_title);
|
|
|
|
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 19:25:49 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
sendButton = (ImageButton)fragmentView.findViewById(R.id.chat_send_button);
|
|
|
|
sendButton.setEnabled(false);
|
2014-02-11 14:32:09 +00:00
|
|
|
sendButton.setVisibility(View.INVISIBLE);
|
2013-10-25 15:19:00 +00:00
|
|
|
emojiButton = (ImageView)fragmentView.findViewById(R.id.chat_smile_button);
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
if (loading && messages.isEmpty()) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
chatListView.setEmptyView(null);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
chatListView.setEmptyView(emptyView);
|
|
|
|
} else {
|
|
|
|
chatListView.setEmptyView(secretChatPlaceholder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
emojiButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (emojiPopup == null) {
|
|
|
|
showEmojiPopup(true);
|
|
|
|
} else {
|
|
|
|
showEmojiPopup(!emojiPopup.isShowing());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
messsageEditText.setOnKeyListener(new View.OnKeyListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onKey(View view, int i, KeyEvent keyEvent) {
|
|
|
|
if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) {
|
|
|
|
if (keyEvent.getAction() == 1) {
|
|
|
|
showEmojiPopup(false);
|
|
|
|
}
|
|
|
|
return true;
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-16 23:32:05 +00:00
|
|
|
messsageEditText.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (emojiPopup != null && emojiPopup.isShowing()) {
|
|
|
|
showEmojiPopup(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
|
|
|
if (i == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
} else if (sendByEnter) {
|
|
|
|
if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
sendButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-02-04 18:36:55 +00:00
|
|
|
sendMessage();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-11 14:32:09 +00:00
|
|
|
audioSendButton.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
|
|
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
2014-03-22 22:31:55 +00:00
|
|
|
startedDraggingX = -1;
|
2014-03-23 00:09:24 +00:00
|
|
|
MediaController.getInstance().startRecording(dialog_id);
|
2014-02-28 22:28:25 +00:00
|
|
|
updateAudioRecordIntefrace();
|
|
|
|
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
|
2014-03-22 22:31:55 +00:00
|
|
|
startedDraggingX = -1;
|
2014-03-23 00:24:19 +00:00
|
|
|
MediaController.getInstance().stopRecording(true);
|
|
|
|
recordingAudio = false;
|
|
|
|
updateAudioRecordIntefrace();
|
2014-02-28 22:28:25 +00:00
|
|
|
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) {
|
2014-03-22 22:31:55 +00:00
|
|
|
float x = motionEvent.getX();
|
|
|
|
if (x < -distCanMove) {
|
|
|
|
MediaController.getInstance().stopRecording(false);
|
2014-02-28 22:28:25 +00:00
|
|
|
recordingAudio = false;
|
|
|
|
updateAudioRecordIntefrace();
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
if(android.os.Build.VERSION.SDK_INT > 13) {
|
|
|
|
x = x + audioSendButton.getX();
|
|
|
|
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
|
|
|
|
if (startedDraggingX != -1) {
|
|
|
|
float dist = (x - startedDraggingX);
|
|
|
|
params.leftMargin = Utilities.dp(30) + (int)dist;
|
|
|
|
slideText.setLayoutParams(params);
|
|
|
|
float alpha = 1.0f + dist / distCanMove;
|
|
|
|
if (alpha > 1) {
|
|
|
|
alpha = 1;
|
|
|
|
} else if (alpha < 0) {
|
|
|
|
alpha = 0;
|
|
|
|
}
|
|
|
|
slideText.setAlpha(alpha);
|
|
|
|
}
|
|
|
|
if (x <= slideText.getX() + slideText.getWidth() + Utilities.dp(30)) {
|
|
|
|
if (startedDraggingX == -1) {
|
|
|
|
startedDraggingX = x;
|
|
|
|
distCanMove = (recordPanel.getMeasuredWidth() - slideText.getMeasuredWidth() - Utilities.dp(48)) / 2.0f;
|
|
|
|
if (distCanMove <= 0) {
|
|
|
|
distCanMove = Utilities.dp(80);
|
|
|
|
} else if (distCanMove > Utilities.dp(80)) {
|
|
|
|
distCanMove = Utilities.dp(80);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (params.leftMargin > Utilities.dp(30)) {
|
|
|
|
params.leftMargin = Utilities.dp(30);
|
|
|
|
slideText.setLayoutParams(params);
|
|
|
|
slideText.setAlpha(1);
|
|
|
|
startedDraggingX = -1;
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
view.onTouchEvent(motionEvent);
|
|
|
|
return true;
|
2014-02-11 14:32:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
pagedownButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-03-22 22:31:55 +00:00
|
|
|
scrollToLastMessage();
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-11 14:32:09 +00:00
|
|
|
checkSendButton();
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
messsageEditText.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
2014-05-16 23:05:49 +00:00
|
|
|
String message = getTrimmedString(charSequence.toString());
|
2013-10-25 15:19:00 +00:00
|
|
|
sendButton.setEnabled(message.length() != 0);
|
2014-02-11 14:32:09 +00:00
|
|
|
checkSendButton();
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
|
2014-03-22 22:31:55 +00:00
|
|
|
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
|
2014-02-28 22:28:25 +00:00
|
|
|
if (currentUser != null && currentUser.status != null && currentUser.status.expires < currentTime) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastTypingTimeSend = System.currentTimeMillis();
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendTyping(dialog_id, classGuid);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable editable) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
|
|
|
|
sendMessage();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
int i = 0;
|
|
|
|
ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
|
|
|
|
int j = arrayOfImageSpan.length;
|
|
|
|
while (true) {
|
|
|
|
if (i >= j) {
|
2014-05-16 23:05:49 +00:00
|
|
|
Emoji.replaceEmoji(editable, messsageEditText.getPaint().getFontMetricsInt(), Utilities.dp(20));
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
editable.removeSpan(arrayOfImageSpan[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
bottomOverlayChat.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-05-16 23:05:49 +00:00
|
|
|
builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
chatListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
processRowSelect(view);
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
createMenu(view, true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-16 23:05:49 +00:00
|
|
|
if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) ||
|
|
|
|
currentUser != null && (currentUser instanceof TLRPC.TL_userDeleted || currentUser instanceof TLRPC.TL_userEmpty)) {
|
2013-12-20 19:25:49 +00:00
|
|
|
bottomOverlayChat.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
bottomOverlayChat.setVisibility(View.GONE);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:05:49 +00:00
|
|
|
private String getTrimmedString(String src) {
|
|
|
|
String result = src.trim();
|
2014-06-03 23:57:30 +00:00
|
|
|
if (result.length() == 0) {
|
|
|
|
return result;
|
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
while (src.startsWith("\n")) {
|
|
|
|
src = src.substring(1);
|
|
|
|
}
|
|
|
|
while (src.endsWith("\n")) {
|
|
|
|
src = src.substring(0, src.length() - 1);
|
|
|
|
}
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
2014-02-11 14:32:09 +00:00
|
|
|
private void checkSendButton() {
|
2014-05-16 23:05:49 +00:00
|
|
|
String message = getTrimmedString(messsageEditText.getText().toString());
|
2014-03-22 22:31:55 +00:00
|
|
|
if (message.length() > 0) {
|
2014-02-28 22:28:25 +00:00
|
|
|
sendButton.setVisibility(View.VISIBLE);
|
|
|
|
audioSendButton.setVisibility(View.INVISIBLE);
|
2014-03-22 22:31:55 +00:00
|
|
|
} else {
|
|
|
|
sendButton.setVisibility(View.INVISIBLE);
|
|
|
|
audioSendButton.setVisibility(View.VISIBLE);
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAudioRecordIntefrace() {
|
|
|
|
if (recordingAudio) {
|
2014-03-22 22:31:55 +00:00
|
|
|
try {
|
2014-03-23 00:24:19 +00:00
|
|
|
if (mWakeLock == null) {
|
2014-06-03 23:31:48 +00:00
|
|
|
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
2014-03-23 00:24:19 +00:00
|
|
|
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
|
|
|
|
mWakeLock.acquire();
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
Utilities.lockOrientation(getParentActivity());
|
2014-03-22 22:31:55 +00:00
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
recordPanel.setVisibility(View.VISIBLE);
|
|
|
|
recordTimeText.setText("00:00");
|
|
|
|
lastTimeString = null;
|
2014-03-22 22:31:55 +00:00
|
|
|
if(android.os.Build.VERSION.SDK_INT > 13) {
|
|
|
|
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
|
|
|
|
params.leftMargin = Utilities.dp(30);
|
|
|
|
slideText.setLayoutParams(params);
|
|
|
|
slideText.setAlpha(1);
|
2014-02-28 22:28:25 +00:00
|
|
|
recordPanel.setX(Utilities.displaySize.x);
|
|
|
|
recordPanel.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
recordPanel.setX(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animator) {
|
|
|
|
}
|
|
|
|
}).setDuration(300).translationX(0).start();
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
if (mWakeLock != null) {
|
|
|
|
try {
|
|
|
|
mWakeLock.release();
|
2014-03-23 00:24:19 +00:00
|
|
|
mWakeLock = null;
|
2014-03-22 22:31:55 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
Utilities.unlockOrientation(getParentActivity());
|
2014-03-22 22:31:55 +00:00
|
|
|
if(android.os.Build.VERSION.SDK_INT > 13) {
|
2014-02-28 22:28:25 +00:00
|
|
|
recordPanel.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animator) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
2014-03-22 22:31:55 +00:00
|
|
|
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)slideText.getLayoutParams();
|
|
|
|
params.leftMargin = Utilities.dp(30);
|
|
|
|
slideText.setLayoutParams(params);
|
|
|
|
slideText.setAlpha(1);
|
2014-02-28 22:28:25 +00:00
|
|
|
recordPanel.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animator) {
|
|
|
|
}
|
|
|
|
}).setDuration(300).translationX(Utilities.displaySize.x).start();
|
|
|
|
} else {
|
|
|
|
recordPanel.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 14:32:09 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
private void sendMessage() {
|
2014-05-16 23:05:49 +00:00
|
|
|
if (processSendingText(messsageEditText.getText().toString())) {
|
2014-02-04 18:36:55 +00:00
|
|
|
messsageEditText.setText("");
|
|
|
|
lastTypingTimeSend = 0;
|
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-02-28 22:28:25 +00:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
private void scrollToLastMessage() {
|
|
|
|
if (unread_end_reached || first_unread_id == 0) {
|
|
|
|
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;
|
|
|
|
unread_end_reached = true;
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false);
|
|
|
|
loading = true;
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
private void showPagedownButton(boolean show, boolean animated) {
|
|
|
|
if (pagedownButton == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (show) {
|
|
|
|
if (pagedownButton.getVisibility() == View.GONE) {
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 16 && animated) {
|
|
|
|
pagedownButton.setVisibility(View.VISIBLE);
|
|
|
|
pagedownButton.setAlpha(0);
|
|
|
|
pagedownButton.animate().alpha(1).setDuration(200).start();
|
|
|
|
} else {
|
|
|
|
pagedownButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pagedownButton.getVisibility() == View.VISIBLE) {
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 16 && animated) {
|
|
|
|
pagedownButton.animate().alpha(0).withEndAction(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
pagedownButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}).setDuration(200).start();
|
|
|
|
} else {
|
|
|
|
pagedownButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00: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 22:31:55 +00:00
|
|
|
bottomOverlayText.setText(LocaleController.getString("EncryptionProcessing", R.string.EncryptionProcessing));
|
2013-10-25 15:19:00 +00:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
|
2014-03-22 22:31:55 +00:00
|
|
|
bottomOverlayText.setText(Html.fromHtml(LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, "<b>" + currentUser.first_name + "</b>")));
|
2013-10-25 15:19:00 +00:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
|
2014-03-22 22:31:55 +00:00
|
|
|
bottomOverlayText.setText(LocaleController.getString("EncryptionRejected", R.string.EncryptionRejected));
|
2013-10-25 15:19:00 +00:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChat) {
|
|
|
|
bottomOverlay.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (hideKeyboard) {
|
|
|
|
hideEmojiPopup();
|
2014-06-03 23:31:48 +00:00
|
|
|
Utilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
|
|
|
}
|
|
|
|
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 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-03 23:31:48 +00: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 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
|
|
|
|
builder.setItems(new CharSequence[]{
|
|
|
|
LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever),
|
|
|
|
LocaleController.getString("ShortMessageLifetime2s", R.string.ShortMessageLifetime2s),
|
|
|
|
LocaleController.getString("ShortMessageLifetime5s", R.string.ShortMessageLifetime5s),
|
|
|
|
LocaleController.getString("ShortMessageLifetime1m", R.string.ShortMessageLifetime1m),
|
|
|
|
LocaleController.getString("ShortMessageLifetime1h", R.string.ShortMessageLifetime1h),
|
|
|
|
LocaleController.getString("ShortMessageLifetime1d", R.string.ShortMessageLifetime1d),
|
|
|
|
LocaleController.getString("ShortMessageLifetime1w", R.string.ShortMessageLifetime1w)
|
|
|
|
|
|
|
|
}, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
int oldValue = currentEncryptedChat.ttl;
|
|
|
|
if (which == 0) {
|
|
|
|
currentEncryptedChat.ttl = 0;
|
|
|
|
} else if (which == 1) {
|
|
|
|
currentEncryptedChat.ttl = 2;
|
|
|
|
} else if (which == 2) {
|
|
|
|
currentEncryptedChat.ttl = 5;
|
|
|
|
} else if (which == 3) {
|
|
|
|
currentEncryptedChat.ttl = 60;
|
|
|
|
} else if (which == 4) {
|
|
|
|
currentEncryptedChat.ttl = 60 * 60;
|
|
|
|
} else if (which == 5) {
|
|
|
|
currentEncryptedChat.ttl = 60 * 60 * 24;
|
|
|
|
} else if (which == 6) {
|
|
|
|
currentEncryptedChat.ttl = 60 * 60 * 24 * 7;
|
|
|
|
}
|
|
|
|
if (oldValue != currentEncryptedChat.ttl) {
|
|
|
|
MessagesController.getInstance().sendTTLMessage(currentEncryptedChat);
|
|
|
|
MessagesStorage.getInstance().updateEncryptedChat(currentEncryptedChat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
timerButton.setTime(currentEncryptedChat.ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (avatarImageView != null) {
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
int placeHolderId = 0;
|
|
|
|
if (currentUser != null) {
|
|
|
|
if (currentUser.photo != null) {
|
|
|
|
photo = currentUser.photo.photo_small;
|
|
|
|
}
|
|
|
|
placeHolderId = Utilities.getUserAvatarForId(currentUser.id);
|
|
|
|
} else if (currentChat != null) {
|
|
|
|
if (currentChat.photo != null) {
|
|
|
|
photo = currentChat.photo.photo_small;
|
|
|
|
}
|
|
|
|
placeHolderId = Utilities.getGroupAvatarForId(currentChat.id);
|
|
|
|
}
|
|
|
|
avatarImageView.setImage(photo, "50_50", placeHolderId);
|
2013-11-04 12:31:01 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addToLoadingFile(String path, ProgressBar bar) {
|
|
|
|
ArrayList<ProgressBar> arr = loadingFile.get(path);
|
|
|
|
if (arr == null) {
|
|
|
|
arr = new ArrayList<ProgressBar>();
|
|
|
|
loadingFile.put(path, arr);
|
|
|
|
}
|
|
|
|
arr.add(bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeFromloadingFile(String path, ProgressBar bar) {
|
|
|
|
ArrayList<ProgressBar> arr = loadingFile.get(path);
|
|
|
|
if (arr != null) {
|
|
|
|
arr.remove(bar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateOnlineCount() {
|
|
|
|
if (info == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onlineCount = 0;
|
2014-03-22 22:31:55 +00:00
|
|
|
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
|
2013-10-25 15:19:00 +00:00
|
|
|
for (TLRPC.TL_chatParticipant participant : info.participants) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(participant.user_id);
|
2014-06-13 10:42:21 +00:00
|
|
|
if (user != null && user.status != null && (user.status.expires > currentTime || user.id == UserConfig.getClientUserId()) && user.status.expires > 10000) {
|
2013-10-25 15:19:00 +00:00
|
|
|
onlineCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSubtitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getMessageType(MessageObject messageObject) {
|
|
|
|
if (currentEncryptedChat == null) {
|
2014-04-03 21:18:54 +00:00
|
|
|
if (messageObject.messageOwner.id <= 0 && messageObject.isOut()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-03 21:18:54 +00:00
|
|
|
if (messageObject.type == 7) {
|
2013-12-20 19:25:49 +00:00
|
|
|
return -1;
|
|
|
|
} else if (messageObject.type == 10 || messageObject.type == 11) {
|
|
|
|
if (messageObject.messageOwner.id == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
2014-03-31 14:14:49 +00: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) {
|
|
|
|
File f = new File(Utilities.getCacheDir(), messageObject.getFileName());
|
|
|
|
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 17:58:33 +00:00
|
|
|
if (mime != null && mime.endsWith("/xml")) {
|
2014-04-02 17:36:57 +00:00
|
|
|
return 5;
|
2014-03-31 14:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-03 21:18:54 +00:00
|
|
|
if (messageObject.type == 7) {
|
2013-12-20 19:25:49 +00:00
|
|
|
return -1;
|
|
|
|
} else if (messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 0;
|
|
|
|
} else if (messageObject.type == 10 || messageObject.type == 11 || messageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (messageObject.messageOwner.id == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
2014-03-31 14:14:49 +00: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) {
|
|
|
|
File f = new File(Utilities.getCacheDir(), messageObject.getFileName());
|
|
|
|
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 17:58:33 +00:00
|
|
|
if (mime != null && mime.endsWith("text/xml")) {
|
2014-04-02 17:36:57 +00:00
|
|
|
return 5;
|
2014-03-31 14:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//return 4;
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00: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 14:14:49 +00:00
|
|
|
if (messageObject.type == 0) {
|
2013-10-25 15:19:00 +00:00
|
|
|
selectedMessagesCanCopyIds.remove(messageObject.messageOwner.id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
selectedMessagesIds.put(messageObject.messageOwner.id, messageObject);
|
2014-03-31 14:14:49 +00:00
|
|
|
if (messageObject.type == 0) {
|
2013-10-25 15:19:00 +00:00
|
|
|
selectedMessagesCanCopyIds.put(messageObject.messageOwner.id, messageObject);
|
|
|
|
}
|
2014-03-04 19:29:32 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
if (selectedMessagesIds.isEmpty()) {
|
|
|
|
actionBarLayer.hideActionMode();
|
|
|
|
}
|
|
|
|
actionBarLayer.createActionMode().getItem(copy).setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processRowSelect(View view) {
|
|
|
|
View parentView = getRowParentView(view);
|
|
|
|
if (parentView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
MessageObject message = null;
|
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
message = ((ChatBaseCell)view).getMessageObject();
|
|
|
|
} else {
|
|
|
|
ChatListRowHolderEx holder = (ChatListRowHolderEx)parentView.getTag();
|
|
|
|
message = holder.message;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (getMessageType(message) < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addToSelectedMessages(message);
|
|
|
|
updateActionModeTitle();
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateActionModeTitle() {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (!actionBarLayer.isActionModeShowed()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
if (!selectedMessagesIds.isEmpty()) {
|
|
|
|
selectedMessagesCountTextView.setText(LocaleController.formatString("Selected", R.string.Selected, selectedMessagesIds.size()));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSubtitle() {
|
|
|
|
if (currentChat != null) {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setTitle(currentChat.title);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (currentUser != null) {
|
2014-06-13 10:42:21 +00:00
|
|
|
if (currentUser.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(currentUser.id) == null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts())) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentUser.phone != null && currentUser.phone.length() != 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setTitle(PhoneFormat.getInstance().format("+" + currentUser.phone));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (printString == null || printString.length() == 0) {
|
2014-02-04 18:36:55 +00:00
|
|
|
lastPrintString = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
setTypingAnimation(false);
|
|
|
|
if (currentChat != null) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (currentChat instanceof TLRPC.TL_chatForbidden) {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setSubtitle(LocaleController.getString("YouWereKicked", R.string.YouWereKicked));
|
2013-12-20 19:25:49 +00:00
|
|
|
} else if (currentChat.left) {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setSubtitle(LocaleController.getString("YouLeft", R.string.YouLeft));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (onlineCount > 0 && currentChat.participants_count != 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setSubtitle(String.format("%d %s, %d %s", currentChat.participants_count, LocaleController.getString("Members", R.string.Members), onlineCount, LocaleController.getString("Online", R.string.Online)));
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setSubtitle(String.format("%d %s", currentChat.participants_count, LocaleController.getString("Members", R.string.Members)));
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (currentUser != null) {
|
2014-05-16 23:05:49 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(currentUser.id);
|
|
|
|
if (user != null) {
|
|
|
|
currentUser = user;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setSubtitle(LocaleController.formatUserStatus(currentUser));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-04 18:36:55 +00:00
|
|
|
lastPrintString = printString;
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setSubtitle(printString);
|
2013-10-25 15:19:00 +00:00
|
|
|
setTypingAnimation(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkAndUpdateAvatar() {
|
|
|
|
TLRPC.FileLocation newPhoto = null;
|
|
|
|
int placeHolderId = 0;
|
|
|
|
if (currentUser != null) {
|
2014-04-05 05:55:51 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(currentUser.id);
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentUser = user;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentUser.photo != null) {
|
|
|
|
newPhoto = currentUser.photo.photo_small;
|
|
|
|
}
|
|
|
|
placeHolderId = Utilities.getUserAvatarForId(currentUser.id);
|
|
|
|
} else if (currentChat != null) {
|
2014-04-05 05:55:51 +00:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().chats.get(currentChat.id);
|
|
|
|
if (chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentChat = chat;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentChat.photo != null) {
|
|
|
|
newPhoto = currentChat.photo.photo_small;
|
|
|
|
}
|
|
|
|
placeHolderId = Utilities.getGroupAvatarForId(currentChat.id);
|
|
|
|
}
|
|
|
|
if (avatarImageView != null) {
|
|
|
|
avatarImageView.setImage(newPhoto, "50_50", placeHolderId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-20 19:25:49 +00:00
|
|
|
public void onSizeChanged(int height) {
|
2013-10-25 15:19:00 +00:00
|
|
|
Rect localRect = new Rect();
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
2014-03-10 09:27:49 +00:00
|
|
|
if (manager == null || manager.getDefaultDisplay() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
|
|
|
|
2014-05-16 23:05:49 +00:00
|
|
|
if (height > Utilities.dp(50)) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
|
|
|
keyboardHeightLand = height;
|
2014-06-03 23:31:48 +00:00
|
|
|
ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height_land3", keyboardHeightLand).commit();
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
|
|
|
keyboardHeight = height;
|
2014-06-03 23:31:48 +00:00
|
|
|
ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit();
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emojiPopup != null && emojiPopup.isShowing()) {
|
2014-06-03 23:31:48 +00:00
|
|
|
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
|
2013-12-20 19:25:49 +00:00
|
|
|
final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams)emojiPopup.getContentView().getLayoutParams();
|
|
|
|
layoutParams.width = contentView.getWidth();
|
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
|
|
|
layoutParams.height = keyboardHeightLand;
|
|
|
|
} else {
|
|
|
|
layoutParams.height = keyboardHeight;
|
|
|
|
}
|
|
|
|
wm.updateViewLayout(emojiPopup.getContentView(), layoutParams);
|
|
|
|
if (!keyboardVisible) {
|
|
|
|
contentView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
contentView.setPadding(0, 0, 0, layoutParams.height);
|
2014-02-04 18:36:55 +00:00
|
|
|
contentView.requestLayout();
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean oldValue = keyboardVisible;
|
|
|
|
keyboardVisible = height > 0;
|
|
|
|
if (keyboardVisible && contentView.getPaddingBottom() > 0) {
|
|
|
|
showEmojiPopup(false);
|
|
|
|
} else if (!keyboardVisible && keyboardVisible != oldValue && emojiPopup != null && emojiPopup.isShowing()) {
|
|
|
|
showEmojiPopup(false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-26 20:16:28 +00:00
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
if (requestCode == 0) {
|
|
|
|
Utilities.addMediaToGallery(currentPicturePath);
|
2014-03-04 19:29:32 +00:00
|
|
|
processSendingPhoto(currentPicturePath, null);
|
2013-10-25 15:19:00 +00:00
|
|
|
currentPicturePath = null;
|
|
|
|
} else if (requestCode == 1) {
|
2014-04-03 21:56:42 +00:00
|
|
|
if (data == null || data.getData() == null) {
|
2014-06-14 08:36:01 +00:00
|
|
|
showAttachmentError();
|
2014-02-04 18:36:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-04-03 21:56:42 +00:00
|
|
|
String tempPath = Utilities.getPath(data.getData());
|
2014-04-05 17:11:44 +00:00
|
|
|
|
|
|
|
boolean isGif = false;
|
2014-04-03 21:56:42 +00:00
|
|
|
if (tempPath != null && tempPath.endsWith(".gif")) {
|
2014-04-05 17:11:44 +00:00
|
|
|
isGif = true;
|
|
|
|
} else if (tempPath == null) {
|
|
|
|
isGif = MediaController.isGif(data.getData());
|
|
|
|
if (isGif) {
|
2014-06-14 08:36:01 +00:00
|
|
|
tempPath = MediaController.copyDocumentToCache(data.getData(), "gif");
|
2014-04-05 17:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tempPath != null && isGif) {
|
2014-04-03 21:56:42 +00:00
|
|
|
processSendingDocument(tempPath);
|
|
|
|
} else {
|
|
|
|
processSendingPhoto(null, data.getData());
|
|
|
|
}
|
2013-10-25 15:19:00 +00: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 19:25:49 +00:00
|
|
|
try {
|
2014-02-11 14:32:09 +00:00
|
|
|
videoPath = Utilities.getPath(uri);
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (videoPath == null && currentPicturePath != null) {
|
|
|
|
File f = new File(currentPicturePath);
|
|
|
|
if (f.exists()) {
|
|
|
|
videoPath = currentPicturePath;
|
|
|
|
}
|
|
|
|
currentPicturePath = null;
|
|
|
|
}
|
|
|
|
processSendingVideo(videoPath);
|
2014-06-14 08:36:01 +00:00
|
|
|
} else if (requestCode == 21) {
|
|
|
|
if (data == null || data.getData() == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String tempPath = Utilities.getPath(data.getData());
|
|
|
|
if (tempPath == null) {
|
|
|
|
tempPath = MediaController.copyDocumentToCache(data.getData(), "file");
|
|
|
|
}
|
|
|
|
if (tempPath == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
processSendingDocument(tempPath);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-14 08:36:01 +00:00
|
|
|
private void showAttachmentError() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnsupportedAttachment", R.string.UnsupportedAttachment), Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
2014-03-26 20:16:28 +00:00
|
|
|
@Override
|
|
|
|
public void saveSelfArgs(Bundle args) {
|
|
|
|
if (currentPicturePath != null) {
|
|
|
|
args.putString("path", currentPicturePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restoreSelfArgs(Bundle args) {
|
|
|
|
currentPicturePath = args.getString("path");
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
public boolean processSendingText(String text) {
|
2014-05-16 23:05:49 +00:00
|
|
|
text = getTrimmedString(text);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (text.length() != 0) {
|
|
|
|
int count = (int)Math.ceil(text.length() / 2048.0f);
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
String mess = text.substring(a * 2048, Math.min((a + 1) * 2048, text.length()));
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(mess, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-04 19:29:32 +00:00
|
|
|
public void processSendingPhoto(String imageFilePath, Uri imageUri) {
|
|
|
|
if ((imageFilePath == null || imageFilePath.length() == 0) && imageUri == null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.TL_photo photo = MessagesController.getInstance().generatePhotoSizes(imageFilePath, imageUri);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (photo != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(photo, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.setSelection(messages.size() + 1);
|
|
|
|
}
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-12 19:55:13 +00:00
|
|
|
public void processSendingPhotos(ArrayList<String> paths, ArrayList<Uri> uris) {
|
|
|
|
if (paths == null && uris == null || paths != null && paths.isEmpty() || uris != null && uris.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final ArrayList<String> pathsCopy = new ArrayList<String>();
|
|
|
|
final ArrayList<Uri> urisCopy = new ArrayList<Uri>();
|
|
|
|
if (paths != null) {
|
|
|
|
pathsCopy.addAll(paths);
|
|
|
|
}
|
|
|
|
if (uris != null) {
|
|
|
|
urisCopy.addAll(uris);
|
|
|
|
}
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
int count = !pathsCopy.isEmpty() ? pathsCopy.size() : urisCopy.size();
|
|
|
|
String path = null;
|
|
|
|
Uri uri = null;
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
if (!pathsCopy.isEmpty()) {
|
|
|
|
path = pathsCopy.get(a);
|
|
|
|
} else if (!urisCopy.isEmpty()) {
|
|
|
|
uri = urisCopy.get(a);
|
|
|
|
}
|
2014-06-14 08:36:01 +00:00
|
|
|
|
|
|
|
boolean isGif = false;
|
|
|
|
if (path != null && path.endsWith(".gif")) {
|
|
|
|
final String finalPath = path;
|
|
|
|
Utilities.RunOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
processSendingDocument(finalPath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
final TLRPC.TL_photo photo = MessagesController.getInstance().generatePhotoSizes(path, uri);
|
|
|
|
Utilities.RunOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (photo != null) {
|
|
|
|
MessagesController.getInstance().sendMessage(photo, dialog_id);
|
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.setSelection(messages.size() + 1);
|
|
|
|
}
|
|
|
|
scrollToTopOnResume = true;
|
2014-06-12 19:55:13 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-14 08:36:01 +00:00
|
|
|
});
|
|
|
|
}
|
2014-06-12 19:55:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
public void processSendingDocument(String documentFilePath) {
|
|
|
|
if (documentFilePath == null || documentFilePath.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
File f = new File(documentFilePath);
|
|
|
|
if (!f.exists() || f.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String name = f.getName();
|
|
|
|
if (name == null) {
|
|
|
|
name = "noname";
|
|
|
|
}
|
|
|
|
String ext = "";
|
|
|
|
int idx = documentFilePath.lastIndexOf(".");
|
|
|
|
if (idx != -1) {
|
2014-04-01 01:00:35 +00:00
|
|
|
ext = documentFilePath.substring(idx + 1);
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
TLRPC.TL_document document = new TLRPC.TL_document();
|
|
|
|
document.id = 0;
|
2014-06-13 10:42:21 +00:00
|
|
|
document.user_id = UserConfig.getClientUserId();
|
2014-03-22 22:31:55 +00:00
|
|
|
document.date = ConnectionsManager.getInstance().getCurrentTime();
|
2014-02-28 22:28:25 +00:00
|
|
|
document.file_name = name;
|
|
|
|
document.size = (int)f.length();
|
|
|
|
document.dc_id = 0;
|
|
|
|
document.path = documentFilePath;
|
|
|
|
if (ext.length() != 0) {
|
|
|
|
MimeTypeMap myMime = MimeTypeMap.getSingleton();
|
|
|
|
String mimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
|
|
|
|
if (mimeType != null) {
|
|
|
|
document.mime_type = mimeType;
|
|
|
|
} else {
|
|
|
|
document.mime_type = "application/octet-stream";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.mime_type = "application/octet-stream";
|
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
if (document.mime_type.equals("image/gif")) {
|
|
|
|
try {
|
2014-04-01 01:00:35 +00:00
|
|
|
Bitmap bitmap = FileLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90);
|
2014-03-31 14:14:49 +00:00
|
|
|
if (bitmap != null) {
|
|
|
|
document.thumb = FileLoader.scaleAndSaveImage(bitmap, 90, 90, 55, currentEncryptedChat != null);
|
|
|
|
document.thumb.type = "s";
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (document.thumb == null) {
|
|
|
|
document.thumb = new TLRPC.TL_photoSizeEmpty();
|
|
|
|
document.thumb.type = "s";
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(document, dialog_id);
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
public void processSendingVideo(final String videoPath) {
|
2014-02-28 22:28:25 +00:00
|
|
|
if (videoPath == null || videoPath.length() == 0) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
|
2013-11-04 12:31:01 +00:00
|
|
|
TLRPC.PhotoSize size = FileLoader.scaleAndSaveImage(thumb, 90, 90, 55, currentEncryptedChat != null);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (size == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size.type = "s";
|
|
|
|
TLRPC.TL_video video = new TLRPC.TL_video();
|
|
|
|
video.thumb = size;
|
|
|
|
video.caption = "";
|
2013-12-26 11:43:37 +00:00
|
|
|
video.id = 0;
|
2013-10-25 15:19:00 +00:00
|
|
|
video.path = videoPath;
|
|
|
|
File temp = new File(videoPath);
|
|
|
|
if (temp != null && temp.exists()) {
|
|
|
|
video.size = (int)temp.length();
|
|
|
|
}
|
|
|
|
UserConfig.lastLocalId--;
|
2013-11-04 12:31:01 +00:00
|
|
|
UserConfig.saveConfig(false);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath)));
|
|
|
|
if (mp == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
video.duration = (int)Math.ceil(mp.getDuration() / 1000.0f);
|
|
|
|
video.w = mp.getVideoWidth();
|
|
|
|
video.h = mp.getVideoHeight();
|
|
|
|
mp.release();
|
|
|
|
|
|
|
|
MediaStore.Video.Media media = new MediaStore.Video.Media();
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(video, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.setSelection(messages.size() + 1);
|
|
|
|
}
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
private void removeUnreadPlane(boolean reload) {
|
|
|
|
if (unreadMessageObject != null) {
|
|
|
|
messages.remove(unreadMessageObject);
|
|
|
|
unread_end_reached = true;
|
|
|
|
first_unread_id = 0;
|
|
|
|
last_unread_id = 0;
|
|
|
|
unread_to_load = 0;
|
|
|
|
unreadMessageObject = null;
|
|
|
|
if (reload) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, final Object... args) {
|
|
|
|
if (id == MessagesController.messagesDidLoaded) {
|
|
|
|
long did = (Long)args[0];
|
|
|
|
if (did == dialog_id) {
|
|
|
|
int offset = (Integer)args[1];
|
|
|
|
int count = (Integer)args[2];
|
|
|
|
boolean isCache = (Boolean)args[4];
|
2013-12-20 19:25:49 +00:00
|
|
|
int fnid = (Integer)args[5];
|
|
|
|
int last_unread_date = (Integer)args[8];
|
|
|
|
boolean forwardLoad = (Boolean)args[9];
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean wasUnread = false;
|
2013-12-20 19:25:49 +00:00
|
|
|
boolean positionToUnread = false;
|
|
|
|
if (fnid != 0) {
|
|
|
|
first_unread_id = (Integer)args[5];
|
|
|
|
last_unread_id = (Integer)args[6];
|
|
|
|
unread_to_load = (Integer)args[7];
|
|
|
|
positionToUnread = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
ArrayList<MessageObject> messArr = (ArrayList<MessageObject>)args[3];
|
|
|
|
|
|
|
|
int newRowsCount = 0;
|
2013-12-20 19:25:49 +00:00
|
|
|
unread_end_reached = last_unread_id == 0;
|
|
|
|
for (int a = 0; a < messArr.size(); a++) {
|
|
|
|
MessageObject obj = messArr.get(a);
|
|
|
|
if (messagesDict.containsKey(obj.messageOwner.id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
if (obj.messageOwner.id > 0) {
|
|
|
|
maxMessageId = Math.min(obj.messageOwner.id, maxMessageId);
|
2013-12-20 19:25:49 +00:00
|
|
|
minMessageId = Math.max(obj.messageOwner.id, minMessageId);
|
|
|
|
} else if (currentEncryptedChat != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
maxMessageId = Math.max(obj.messageOwner.id, maxMessageId);
|
2013-12-20 19:25:49 +00:00
|
|
|
minMessageId = Math.min(obj.messageOwner.id, minMessageId);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
maxDate = Math.max(maxDate, obj.messageOwner.date);
|
|
|
|
if (minDate == 0 || obj.messageOwner.date < minDate) {
|
|
|
|
minDate = obj.messageOwner.date;
|
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
if (!obj.isOut() && obj.messageOwner.unread) {
|
2013-10-25 15:19:00 +00:00
|
|
|
wasUnread = true;
|
|
|
|
}
|
|
|
|
messagesDict.put(obj.messageOwner.id, obj);
|
|
|
|
ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
if (dayArray == null) {
|
|
|
|
dayArray = new ArrayList<MessageObject>();
|
|
|
|
messagesByDays.put(obj.dateKey, dayArray);
|
|
|
|
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
2014-03-25 00:25:32 +00:00
|
|
|
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
|
2013-10-25 15:19:00 +00:00
|
|
|
dateMsg.id = 0;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null);
|
2014-03-31 14:14:49 +00:00
|
|
|
dateObj.contentType = dateObj.type = 10;
|
2013-12-20 19:25:49 +00:00
|
|
|
if (forwardLoad) {
|
|
|
|
messages.add(0, dateObj);
|
|
|
|
} else {
|
|
|
|
messages.add(dateObj);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
newRowsCount++;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
newRowsCount++;
|
|
|
|
dayArray.add(obj);
|
2013-12-20 19:25:49 +00:00
|
|
|
if (forwardLoad) {
|
|
|
|
messages.add(0, obj);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
messages.add(messages.size() - 1, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!forwardLoad) {
|
|
|
|
if (obj.messageOwner.id == first_unread_id) {
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
|
|
|
dateMsg.message = "";
|
|
|
|
dateMsg.id = 0;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null);
|
2014-04-03 21:18:54 +00:00
|
|
|
dateObj.contentType = dateObj.type = 7;
|
2013-12-20 19:25:49 +00:00
|
|
|
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;
|
|
|
|
newRowsCount++;
|
|
|
|
}
|
|
|
|
if (obj.messageOwner.id == last_unread_id) {
|
|
|
|
unread_end_reached = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
if (unread_end_reached) {
|
|
|
|
first_unread_id = 0;
|
|
|
|
last_unread_id = 0;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
if (forwardLoad) {
|
|
|
|
if (messArr.size() != count) {
|
|
|
|
unread_end_reached = true;
|
|
|
|
first_unread_id = 0;
|
|
|
|
last_unread_id = 0;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
loadingForward = false;
|
|
|
|
} else {
|
|
|
|
if (messArr.size() != count) {
|
|
|
|
if (isCache) {
|
|
|
|
cacheEndReaced = true;
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
endReached = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cacheEndReaced = true;
|
|
|
|
endReached = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
loading = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
if (chatListView != null) {
|
|
|
|
if (first || scrollToTopOnResume) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
if (positionToUnread && unreadMessageObject != null) {
|
|
|
|
if (messages.get(messages.size() - 1) == unreadMessageObject) {
|
2013-12-26 16:46:13 +00:00
|
|
|
chatListView.setSelectionFromTop(0, Utilities.dp(-11));
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
2013-12-26 16:46:13 +00:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), Utilities.dp(-11));
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
ViewTreeObserver obs = chatListView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
if (messages.get(messages.size() - 1) == unreadMessageObject) {
|
2013-12-26 16:46:13 +00:00
|
|
|
chatListView.setSelectionFromTop(0, Utilities.dp(-11));
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
2013-12-26 16:46:13 +00:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), Utilities.dp(-11));
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
chatListView.invalidate();
|
|
|
|
showPagedownButton(true, true);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-02-28 22:28:25 +00:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2013-12-20 19:25:49 +00: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 01:13:15 +00:00
|
|
|
chatListView.setSelectionFromTop(firstVisPos + newRowsCount - (endReached ? 1 : 0), top);
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
if (positionToUnread && unreadMessageObject != null) {
|
|
|
|
scrollToTopUnReadOnResume = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
if (first) {
|
|
|
|
if (chatListView.getEmptyView() == null) {
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
chatListView.setEmptyView(emptyView);
|
|
|
|
} else {
|
|
|
|
chatListView.setEmptyView(secretChatPlaceholder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
if (positionToUnread && unreadMessageObject != null) {
|
|
|
|
scrollToTopUnReadOnResume = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
if (first && messages.size() > 0) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (last_unread_id != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, last_unread_id, 0, last_unread_date, wasUnread);
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, wasUnread);
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == 999) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.invalidateViews();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
if (emojiView != null) {
|
|
|
|
emojiView.invalidateViews();
|
|
|
|
}
|
|
|
|
} else if (id == MessagesController.updateInterfaces) {
|
|
|
|
int updateMask = (Integer)args[0];
|
2014-02-11 14:32:09 +00: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 15:19:00 +00:00
|
|
|
updateSubtitle();
|
|
|
|
updateOnlineCount();
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
2013-10-25 15:19:00 +00:00
|
|
|
checkAndUpdateAvatar();
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
|
2014-02-04 18:36:55 +00: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();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (id == MessagesController.didReceivedNewMessages) {
|
|
|
|
long did = (Long)args[0];
|
|
|
|
if (did == dialog_id) {
|
|
|
|
|
|
|
|
boolean updateChat = false;
|
2013-12-20 19:25:49 +00:00
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>)args[1];
|
|
|
|
|
|
|
|
if (!unread_end_reached) {
|
|
|
|
int currentMaxDate = Integer.MIN_VALUE;
|
|
|
|
int currentMinMsgId = Integer.MIN_VALUE;
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
currentMinMsgId = Integer.MAX_VALUE;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
boolean currentMarkAsRead = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
for (MessageObject obj : arr) {
|
2014-03-10 09:27:49 +00:00
|
|
|
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageActionTTLChange && timerButton != null) {
|
|
|
|
timerButton.setTime(obj.messageOwner.action.ttl);
|
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
if (obj.isOut() && obj.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
2014-03-22 22:31:55 +00:00
|
|
|
scrollToLastMessage();
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00: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);
|
|
|
|
} else if (currentEncryptedChat != null) {
|
|
|
|
currentMinMsgId = Math.min(obj.messageOwner.id, currentMinMsgId);
|
|
|
|
}
|
|
|
|
|
2014-04-03 21:18:54 +00:00
|
|
|
if (!obj.isOut() && obj.messageOwner.unread) {
|
2013-12-20 19:25:49 +00:00
|
|
|
unread_to_load++;
|
|
|
|
currentMarkAsRead = true;
|
|
|
|
}
|
|
|
|
if (obj.type == 10 || obj.type == 11) {
|
|
|
|
updateChat = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
if (currentMarkAsRead) {
|
|
|
|
if (paused) {
|
|
|
|
readWhenResume = true;
|
|
|
|
readWithDate = currentMaxDate;
|
|
|
|
readWithMid = currentMinMsgId;
|
|
|
|
} else {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (messages.size() > 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, currentMinMsgId, 0, currentMaxDate, true);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
updateVisibleRows();
|
|
|
|
} else {
|
|
|
|
boolean markAsRead = false;
|
|
|
|
int oldCount = messages.size();
|
|
|
|
for (MessageObject obj : arr) {
|
2014-03-10 09:27:49 +00:00
|
|
|
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageActionTTLChange && timerButton != null) {
|
|
|
|
timerButton.setTime(obj.messageOwner.action.ttl);
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (messagesDict.containsKey(obj.messageOwner.id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (minDate == 0 || obj.messageOwner.date < minDate) {
|
|
|
|
minDate = obj.messageOwner.date;
|
|
|
|
}
|
|
|
|
if (obj.messageOwner.attachPath != null && obj.messageOwner.attachPath.length() != 0) {
|
|
|
|
progressBarMap.put(obj.messageOwner.attachPath, null);
|
|
|
|
}
|
|
|
|
|
2014-04-03 21:18:54 +00:00
|
|
|
if (obj.isOut()) {
|
2013-12-20 19:25:49 +00:00
|
|
|
removeUnreadPlane(false);
|
|
|
|
}
|
|
|
|
|
2014-04-03 21:18:54 +00:00
|
|
|
if (!obj.isOut() && unreadMessageObject != null) {
|
2013-12-20 19:25:49 +00: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 22:31:55 +00:00
|
|
|
maxMessageId = Math.max(obj.messageOwner.id, maxMessageId);
|
2013-12-20 19:25:49 +00: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 00:25:32 +00:00
|
|
|
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
|
2013-12-20 19:25:49 +00:00
|
|
|
dateMsg.id = 0;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null);
|
2014-03-31 14:14:49 +00:00
|
|
|
dateObj.contentType = dateObj.type = 10;
|
2013-12-20 19:25:49 +00:00
|
|
|
messages.add(0, dateObj);
|
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
if (!obj.isOut() && obj.messageOwner.unread) {
|
2013-12-20 19:25:49 +00:00
|
|
|
obj.messageOwner.unread = false;
|
|
|
|
markAsRead = true;
|
|
|
|
}
|
|
|
|
dayArray.add(0, obj);
|
|
|
|
messages.add(0, obj);
|
|
|
|
if (obj.type == 10 || obj.type == 11) {
|
|
|
|
updateChat = true;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (chatAdapter != null) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
scrollToTopOnResume = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
if (chatListView != null && chatAdapter != null) {
|
|
|
|
int lastVisible = chatListView.getLastVisiblePosition();
|
|
|
|
if (endReached) {
|
|
|
|
lastVisible++;
|
|
|
|
}
|
|
|
|
if (lastVisible == oldCount) {
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
} else {
|
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-02-28 22:28:25 +00:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showPagedownButton(true, true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
if (markAsRead) {
|
|
|
|
if (paused) {
|
|
|
|
readWhenResume = true;
|
|
|
|
readWithDate = maxDate;
|
|
|
|
readWithMid = minMessageId;
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, minMessageId, 0, maxDate, true);
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updateChat) {
|
|
|
|
updateSubtitle();
|
|
|
|
checkAndUpdateAvatar();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == MessagesController.closeChats) {
|
2013-11-04 12:31:01 +00:00
|
|
|
if (messsageEditText != null && messsageEditText.isFocused()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
Utilities.hideKeyboard(messsageEditText);
|
|
|
|
}
|
|
|
|
removeSelfFromStack();
|
|
|
|
} else if (id == MessagesController.messagesReaded) {
|
|
|
|
ArrayList<Integer> markAsReadMessages = (ArrayList<Integer>)args[0];
|
|
|
|
boolean updated = false;
|
|
|
|
for (Integer ids : markAsReadMessages) {
|
|
|
|
MessageObject obj = messagesDict.get(ids);
|
|
|
|
if (obj != null) {
|
|
|
|
obj.messageOwner.unread = false;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated) {
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (id == MessagesController.messagesDeleted) {
|
|
|
|
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 19:25:49 +00:00
|
|
|
if (index != -1) {
|
2013-10-25 15:19:00 +00:00
|
|
|
messages.remove(index);
|
2013-12-20 19:25:49 +00:00
|
|
|
messagesDict.remove(ids);
|
|
|
|
ArrayList<MessageObject> dayArr = messagesByDays.get(obj.dateKey);
|
|
|
|
dayArr.remove(obj);
|
|
|
|
if (dayArr.isEmpty()) {
|
|
|
|
messagesByDays.remove(obj.dateKey);
|
|
|
|
if (index != -1) {
|
|
|
|
messages.remove(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updated = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (messages.isEmpty()) {
|
|
|
|
if (!endReached && !loading) {
|
2014-03-22 22:31:55 +00:00
|
|
|
progressView.setVisibility(View.GONE);
|
2013-12-20 19:25:49 +00:00
|
|
|
chatListView.setEmptyView(null);
|
2014-03-22 22:31:55 +00:00
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 0, 30, 0, !cacheEndReaced, minDate, classGuid, false, false);
|
2013-12-20 19:25:49 +00:00
|
|
|
loading = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated && chatAdapter != null) {
|
2013-12-20 19:25:49 +00:00
|
|
|
removeUnreadPlane(false);
|
2013-10-25 15:19:00 +00:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
} else if (id == MessagesController.messageReceivedByServer) {
|
|
|
|
Integer msgId = (Integer)args[0];
|
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
|
|
|
Integer newMsgId = (Integer)args[1];
|
2014-03-22 22:31:55 +00:00
|
|
|
MessageObject newMsgObj = (MessageObject)args[2];
|
|
|
|
if (newMsgObj != null) {
|
|
|
|
obj.messageOwner.media = newMsgObj.messageOwner.media;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
messagesDict.remove(msgId);
|
|
|
|
messagesDict.put(newMsgId, obj);
|
|
|
|
obj.messageOwner.id = newMsgId;
|
|
|
|
obj.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SENT;
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
if (obj.messageOwner.attachPath != null && obj.messageOwner.attachPath.length() != 0) {
|
|
|
|
progressBarMap.remove(obj.messageOwner.attachPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == MessagesController.messageReceivedByAck) {
|
|
|
|
Integer msgId = (Integer)args[0];
|
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
|
|
|
if (obj.messageOwner.attachPath != null && obj.messageOwner.attachPath.length() != 0) {
|
|
|
|
progressBarMap.remove(obj.messageOwner.attachPath);
|
|
|
|
}
|
|
|
|
obj.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SENT;
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (id == MessagesController.messageSendError) {
|
|
|
|
Integer msgId = (Integer)args[0];
|
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
|
|
|
obj.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SEND_ERROR;
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
if (obj.messageOwner.attachPath != null && obj.messageOwner.attachPath.length() != 0) {
|
|
|
|
progressBarMap.remove(obj.messageOwner.attachPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == 997) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage((Double) args[0], (Double) args[1], dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.setSelection(messages.size() + 1);
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
} else if (id == MessagesController.chatInfoDidLoaded) {
|
|
|
|
int chatId = (Integer)args[0];
|
|
|
|
if (currentChat != null && chatId == currentChat.id) {
|
|
|
|
info = (TLRPC.ChatParticipants)args[1];
|
|
|
|
updateOnlineCount();
|
|
|
|
}
|
|
|
|
} else if (id == FileLoader.FileUploadProgressChanged) {
|
|
|
|
String location = (String)args[0];
|
2014-02-28 22:28:25 +00:00
|
|
|
boolean enc = (Boolean)args[2];
|
|
|
|
if (enc && currentEncryptedChat == null) {
|
|
|
|
return;
|
|
|
|
} else if (!enc && currentEncryptedChat != null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
ProgressBar bar;
|
|
|
|
if ((bar = progressBarMap.get(location)) != null) {
|
|
|
|
Float progress = (Float)args[1];
|
|
|
|
bar.setProgress((int)(progress * 100));
|
|
|
|
}
|
|
|
|
} else if (id == FileLoader.FileDidFailedLoad) {
|
|
|
|
String location = (String)args[0];
|
|
|
|
if (loadingFile.containsKey(location)) {
|
|
|
|
loadingFile.remove(location);
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (id == FileLoader.FileDidLoaded) {
|
|
|
|
String location = (String)args[0];
|
|
|
|
if (loadingFile.containsKey(location)) {
|
|
|
|
loadingFile.remove(location);
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (id == FileLoader.FileLoadProgressChanged) {
|
|
|
|
String location = (String)args[0];
|
|
|
|
ArrayList<ProgressBar> arr = loadingFile.get(location);
|
|
|
|
if (arr != null) {
|
|
|
|
Float progress = (Float)args[1];
|
|
|
|
for (ProgressBar bar : arr) {
|
|
|
|
bar.setProgress((int)(progress * 100));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == MessagesController.contactsDidLoaded) {
|
|
|
|
updateContactStatus();
|
2013-12-20 19:25:49 +00:00
|
|
|
updateSubtitle();
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (id == MessagesController.encryptedChatUpdated) {
|
|
|
|
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat)args[0];
|
|
|
|
if (currentEncryptedChat != null && chat.id == currentEncryptedChat.id) {
|
|
|
|
currentEncryptedChat = chat;
|
2013-12-20 19:25:49 +00:00
|
|
|
updateContactStatus();
|
2013-10-25 15:19:00 +00:00
|
|
|
updateSecretStatus();
|
|
|
|
}
|
|
|
|
} else if (id == MessagesController.messagesReadedEncrypted) {
|
|
|
|
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 21:18:54 +00:00
|
|
|
if (!obj.isOut()) {
|
2013-12-20 19:25:49 +00:00
|
|
|
continue;
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (obj.isOut() && !obj.messageOwner.unread) {
|
2013-12-20 19:25:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
if (obj.messageOwner.date <= date) {
|
|
|
|
obj.messageOwner.unread = false;
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
updateVisibleRows();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
} else if (id == MediaController.audioDidReset) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == MediaController.audioProgressDidChanged) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == MediaController.recordProgressChanged) {
|
|
|
|
Long time = (Long)args[0] / 1000;
|
|
|
|
String str = String.format("%02d:%02d", time / 60, time % 60);
|
|
|
|
if (lastTimeString == null || !lastPrintString.equals(str)) {
|
|
|
|
if (recordTimeText != null) {
|
|
|
|
recordTimeText.setText(str);
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
} else if (id == MessagesController.removeAllMessagesFromDialog) {
|
|
|
|
messages.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messagesDict.clear();
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
chatListView.setEmptyView(emptyView);
|
|
|
|
} else {
|
|
|
|
chatListView.setEmptyView(secretChatPlaceholder);
|
|
|
|
}
|
|
|
|
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-06-03 23:31:48 +00:00
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBarLayer.hideActionMode();
|
2014-03-22 22:31:55 +00:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
2014-03-23 00:24:19 +00:00
|
|
|
} else if (id == MediaController.recordStartError || id == MediaController.recordStopped) {
|
2014-03-23 00:09:24 +00:00
|
|
|
if (recordingAudio) {
|
|
|
|
recordingAudio = false;
|
|
|
|
updateAudioRecordIntefrace();
|
|
|
|
}
|
|
|
|
} else if (id == MediaController.recordStarted) {
|
|
|
|
if (!recordingAudio) {
|
|
|
|
recordingAudio = true;
|
|
|
|
updateAudioRecordIntefrace();
|
|
|
|
}
|
2014-04-04 17:58:33 +00:00
|
|
|
} else if (id == MediaController.screenshotTook) {
|
|
|
|
updateInformationForScreenshotDetector();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateContactStatus() {
|
|
|
|
if (topPanel == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentUser == null) {
|
|
|
|
topPanel.setVisibility(View.GONE);
|
|
|
|
} else {
|
2014-05-16 23:05:49 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(currentUser.id);
|
|
|
|
if (user != null) {
|
|
|
|
currentUser = user;
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat)
|
2014-02-28 22:28:25 +00:00
|
|
|
|| currentUser.id / 1000 == 333
|
2014-05-16 23:05:49 +00:00
|
|
|
|| currentUser instanceof TLRPC.TL_userEmpty || currentUser instanceof TLRPC.TL_userDeleted
|
2014-02-04 18:36:55 +00:00
|
|
|
|| (currentUser.phone != null && currentUser.phone.length() != 0 &&
|
2014-03-22 22:31:55 +00:00
|
|
|
ContactsController.getInstance().contactsDict.get(currentUser.id) != null &&
|
2014-06-13 10:42:21 +00:00
|
|
|
(ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts()))) {
|
2013-10-25 15:19:00 +00:00
|
|
|
topPanel.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
topPanel.setVisibility(View.VISIBLE);
|
2013-12-26 16:46:13 +00:00
|
|
|
topPanelText.setShadowLayer(1, 0, Utilities.dp(1), 0xff8797a3);
|
2013-10-25 15:19:00 +00: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 22:31:55 +00:00
|
|
|
if (MessagesController.getInstance().hidenAddToContacts.get(currentUser.id) != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
topPanel.setVisibility(View.INVISIBLE);
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
topPanelText.setText(LocaleController.getString("AddToContacts", R.string.AddToContacts));
|
2013-10-25 15:19:00 +00:00
|
|
|
topPlaneClose.setVisibility(View.VISIBLE);
|
|
|
|
topPlaneClose.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().hidenAddToContacts.put(currentUser.id, currentUser);
|
2013-10-25 15:19:00 +00: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-03 23:31:48 +00:00
|
|
|
presentFragment(new ContactAddActivity(args));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
if (MessagesController.getInstance().hidenAddToContacts.get(currentUser.id) != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
topPanel.setVisibility(View.INVISIBLE);
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
topPanelText.setText(LocaleController.getString("ShareMyContactInfo", R.string.ShareMyContactInfo));
|
2013-10-25 15:19:00 +00:00
|
|
|
topPlaneClose.setVisibility(View.GONE);
|
|
|
|
topPanel.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 19:27:43 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
2014-06-04 19:27:43 +00:00
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
MessagesController.getInstance().hidenAddToContacts.put(currentUser.id, currentUser);
|
|
|
|
topPanel.setVisibility(View.GONE);
|
2014-06-13 10:42:21 +00:00
|
|
|
MessagesController.getInstance().sendMessage(UserConfig.getCurrentUser(), dialog_id);
|
2014-06-04 19:27:43 +00:00
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-04 19:27:43 +00:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createEmojiPopup() {
|
2014-06-03 23:31:48 +00:00
|
|
|
emojiView = new EmojiView(getParentActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
emojiView.setListener(new EmojiView.Listener() {
|
|
|
|
public void onBackspace() {
|
|
|
|
messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEmojiSelected(String paramAnonymousString) {
|
|
|
|
int i = messsageEditText.getSelectionEnd();
|
2014-05-16 23:05:49 +00:00
|
|
|
CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString, messsageEditText.getPaint().getFontMetricsInt(), Utilities.dp(20));
|
2013-10-25 15:19:00 +00:00
|
|
|
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
|
|
|
|
int j = i + localCharSequence.length();
|
|
|
|
messsageEditText.setSelection(j, j);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
emojiPopup = new PopupWindow(emojiView);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showEmojiPopup(boolean show) {
|
2014-06-03 23:31:48 +00:00
|
|
|
InputMethodManager localInputMethodManager = (InputMethodManager)ApplicationLoader.applicationContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (show) {
|
|
|
|
if (emojiPopup == null) {
|
|
|
|
createEmojiPopup();
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
int currentHeight;
|
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
2013-10-25 15:19:00 +00:00
|
|
|
if (keyboardHeight <= 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
keyboardHeight = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height", Utilities.dp(200));
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
if (keyboardHeightLand <= 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
keyboardHeightLand = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height_land3", Utilities.dp(200));
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
|
|
|
currentHeight = keyboardHeightLand;
|
|
|
|
} else {
|
|
|
|
currentHeight = keyboardHeight;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY));
|
|
|
|
emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(contentView.getWidth(), View.MeasureSpec.EXACTLY));
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
emojiPopup.showAtLocation(getParentActivity().getWindow().getDecorView(), 83, 0, 0);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (!keyboardVisible) {
|
2013-12-20 19:25:49 +00:00
|
|
|
contentView.setPadding(0, 0, 0, currentHeight);
|
2013-10-25 15:19:00 +00:00
|
|
|
emojiButton.setImageResource(R.drawable.ic_msg_panel_hide);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_msg_panel_kb);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (emojiButton != null) {
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
|
|
|
|
}
|
|
|
|
if (emojiPopup != null) {
|
|
|
|
emojiPopup.dismiss();
|
|
|
|
}
|
|
|
|
if (contentView != null) {
|
|
|
|
contentView.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (contentView != null) {
|
|
|
|
contentView.setPadding(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void hideEmojiPopup() {
|
|
|
|
if (emojiPopup != null && emojiPopup.isShowing()) {
|
|
|
|
showEmojiPopup(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 16:00:42 +00:00
|
|
|
super.onResume();
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
checkActionBarMenu();
|
|
|
|
if (chatAdapter != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().openned_dialog_id = dialog_id;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (scrollToTopOnResume) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (scrollToTopUnReadOnResume && unreadMessageObject != null) {
|
|
|
|
if (chatListView != null) {
|
2013-12-26 16:46:13 +00:00
|
|
|
chatListView.setSelectionFromTop(messages.size() - messages.indexOf(unreadMessageObject), -chatListView.getPaddingTop() - Utilities.dp(7));
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.setSelection(messages.size() + 1);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
scrollToTopUnReadOnResume = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
scrollToTopOnResume = false;
|
|
|
|
}
|
|
|
|
paused = false;
|
|
|
|
if (readWhenResume && !messages.isEmpty()) {
|
|
|
|
readWhenResume = false;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).messageOwner.id, readWithMid, 0, readWithDate, true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
fixLayout();
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
String lastMessageText = preferences.getString("dialog_" + dialog_id, null);
|
|
|
|
if (lastMessageText != null) {
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.remove("dialog_" + dialog_id);
|
|
|
|
editor.commit();
|
|
|
|
ignoreTextChange = true;
|
|
|
|
messsageEditText.setText(lastMessageText);
|
2014-02-04 18:36:55 +00:00
|
|
|
messsageEditText.setSelection(messsageEditText.getText().length());
|
2013-10-25 15:19:00 +00:00
|
|
|
ignoreTextChange = false;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (messsageEditText != null) {
|
|
|
|
messsageEditText.postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (messsageEditText != null) {
|
|
|
|
messsageEditText.requestFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 400);
|
|
|
|
}
|
2014-04-04 17:58:33 +00:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
chatEnterTime = System.currentTimeMillis();
|
|
|
|
chatLeaveTime = 0;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public void didSelectPhotos(ArrayList<String> photos) {
|
2014-06-12 19:55:13 +00:00
|
|
|
processSendingPhotos(photos, null);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startPhotoSelectActivity() {
|
|
|
|
try {
|
|
|
|
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
photoPickerIntent.setType("image/*");
|
|
|
|
getParentActivity().startActivityForResult(photoPickerIntent, 1);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onBeginSlide() {
|
2014-06-06 23:35:21 +00:00
|
|
|
super.onBeginSlide();
|
2014-06-03 23:31:48 +00:00
|
|
|
hideEmojiPopup();
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
private void setTypingAnimation(boolean start) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer == null) {
|
|
|
|
return;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
if (start) {
|
|
|
|
try {
|
|
|
|
if (currentChat != null) {
|
|
|
|
actionBarLayer.setSubTitleIcon(R.drawable.typing_dots_chat, Utilities.dp(4));
|
|
|
|
} else {
|
|
|
|
actionBarLayer.setSubTitleIcon(R.drawable.typing_dots, Utilities.dp(4));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AnimationDrawable mAnim = (AnimationDrawable)actionBarLayer.getSubTitleIcon();
|
|
|
|
mAnim.setAlpha(200);
|
|
|
|
mAnim.start();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
} else {
|
|
|
|
actionBarLayer.setSubTitleIcon(0, 0);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
2014-06-04 16:00:42 +00:00
|
|
|
super.onPause();
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.hideActionMode();
|
2013-10-25 15:19:00 +00:00
|
|
|
hideEmojiPopup();
|
|
|
|
paused = true;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().openned_dialog_id = 0;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (messsageEditText != null && messsageEditText.length() != 0) {
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putString("dialog_" + dialog_id, messsageEditText.getText().toString());
|
|
|
|
editor.commit();
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
|
2014-04-04 17:58:33 +00:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
chatLeaveTime = System.currentTimeMillis();
|
|
|
|
updateInformationForScreenshotDetector();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateInformationForScreenshotDetector() {
|
|
|
|
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();
|
|
|
|
} else {
|
|
|
|
Object tag = view.getTag();
|
|
|
|
if (tag instanceof ChatListRowHolderEx) {
|
|
|
|
ChatListRowHolderEx holder = (ChatListRowHolderEx) tag;
|
|
|
|
object = holder.message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayout() {
|
2014-06-14 08:36:01 +00:00
|
|
|
final int lastPos = chatListView.getLastVisiblePosition();
|
2014-06-03 23:31:48 +00:00
|
|
|
ViewTreeObserver obs = chatListView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public boolean onPreDraw() {
|
2014-06-06 23:35:21 +00:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
}
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
int height = Utilities.dp(48);
|
|
|
|
if (getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
height = Utilities.dp(40);
|
|
|
|
selectedMessagesCountTextView.setTextSize(16);
|
|
|
|
} else {
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
if (avatarImageView != null) {
|
|
|
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) avatarImageView.getLayoutParams();
|
|
|
|
params.width = height;
|
|
|
|
params.height = height;
|
|
|
|
avatarImageView.setLayoutParams(params);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-14 08:36:01 +00:00
|
|
|
if (lastPos >= messages.size() - 1) {
|
|
|
|
chatListView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
return false;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
fixLayout();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private View getRowParentView(View v) {
|
2014-02-28 22:28:25 +00:00
|
|
|
if (v instanceof ChatBaseCell) {
|
|
|
|
return v;
|
|
|
|
} else {
|
|
|
|
while (!(v.getTag() instanceof ChatListRowHolderEx)) {
|
|
|
|
ViewParent parent = v.getParent();
|
|
|
|
if (!(parent instanceof View)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
v = (View)v.getParent();
|
|
|
|
if (v == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
return v;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void createMenu(View v, boolean single) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
View parentView = getRowParentView(v);
|
|
|
|
if (parentView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
MessageObject message = null;
|
|
|
|
if (v instanceof ChatBaseCell) {
|
|
|
|
message = ((ChatBaseCell)v).getMessageObject();
|
|
|
|
} else {
|
|
|
|
ChatListRowHolderEx holder = (ChatListRowHolderEx)parentView.getTag();
|
|
|
|
message = holder.message;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
final int type = getMessageType(message);
|
2014-06-13 15:03:06 +00:00
|
|
|
|
|
|
|
selectedObject = null;
|
|
|
|
forwaringMessage = null;
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
if (single || type < 2) {
|
|
|
|
if (type >= 0) {
|
|
|
|
selectedObject = message;
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
CharSequence[] items = null;
|
|
|
|
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (type == 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("Retry", R.string.Retry), LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 1) {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 2) {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 3) {
|
2014-03-22 22:31:55 +00:00
|
|
|
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)};
|
2014-03-31 14:14:49 +00:00
|
|
|
} 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)};
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (type == 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("Retry", R.string.Retry), LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 1) {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 2) {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 3) {
|
2014-03-22 22:31:55 +00:00
|
|
|
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)};
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (type == 5) {
|
|
|
|
items = new CharSequence[] {LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("Delete", R.string.Delete)};
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2014-06-13 15:03:06 +00:00
|
|
|
if (selectedObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 15:19:00 +00: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 22:31:55 +00:00
|
|
|
} else if (type == 4) {
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (i == 0) {
|
|
|
|
String fileName = selectedObject.getFileName();
|
2014-04-03 21:18:54 +00:00
|
|
|
if (selectedObject.type == 3) {
|
2014-06-03 23:31:48 +00:00
|
|
|
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 1, null);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (selectedObject.type == 1) {
|
2014-06-03 23:31:48 +00:00
|
|
|
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 0, null);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
|
2014-06-03 23:31:48 +00:00
|
|
|
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 2, selectedObject.messageOwner.media.document.file_name);
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(2);
|
|
|
|
} else if (i == 2) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
|
|
} else if (i == 1) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (type == 5) {
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (i == 1) {
|
|
|
|
String fileName = selectedObject.getFileName();
|
2014-04-03 21:18:54 +00:00
|
|
|
if (selectedObject.type == 3) {
|
2014-06-03 23:31:48 +00:00
|
|
|
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 1, null);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (selectedObject.type == 1) {
|
2014-06-03 23:31:48 +00:00
|
|
|
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 0, null);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
|
2014-06-03 23:31:48 +00:00
|
|
|
MediaController.saveFile(fileName, selectedObject.messageOwner.attachPath, getParentActivity(), 2, selectedObject.messageOwner.media.document.file_name);
|
2014-03-31 14:14:49 +00:00
|
|
|
}
|
|
|
|
} else if (i == 2) {
|
|
|
|
processSelectedOption(2);
|
|
|
|
} else if (i == 3) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i == 1) {
|
|
|
|
processSelectedOption(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == 0) {
|
|
|
|
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) {
|
|
|
|
File f = new File(Utilities.getCacheDir(), selectedObject.getFileName());
|
|
|
|
if (f.exists()) {
|
|
|
|
locFile = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (locFile != null) {
|
|
|
|
if (LocaleController.getInstance().applyLanguageFile(locFile)) {
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new LanguageSelectActivity());
|
|
|
|
} else {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-04-02 17:36:57 +00:00
|
|
|
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);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-03-31 14:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-02 17:36:57 +00:00
|
|
|
builder.setTitle(LocaleController.getString("Message", R.string.Message));
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.showActionMode();
|
2013-10-25 15:19:00 +00:00
|
|
|
addToSelectedMessages(message);
|
|
|
|
updateActionModeTitle();
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processSelectedOption(int option) {
|
|
|
|
if (option == 0) {
|
|
|
|
if (selectedObject != null && selectedObject.messageOwner.id < 0) {
|
2014-03-31 14:14:49 +00:00
|
|
|
if (selectedObject.type == 0) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(selectedObject, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(selectedObject.messageOwner.message, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (selectedObject.type == 4) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(selectedObject.messageOwner.media.geo.lat, selectedObject.messageOwner.media.geo._long, dialog_id);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (selectedObject.type == 1) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(selectedObject, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
TLRPC.TL_photo photo = (TLRPC.TL_photo)selectedObject.messageOwner.media.photo;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(photo, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (selectedObject.type == 3) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(selectedObject, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
TLRPC.TL_video video = (TLRPC.TL_video)selectedObject.messageOwner.media.video;
|
|
|
|
video.path = selectedObject.messageOwner.attachPath;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(video, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (selectedObject.type == 12 || selectedObject.type == 13) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(selectedObject.messageOwner.media.user_id);
|
|
|
|
MessagesController.getInstance().sendMessage(user, dialog_id);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
|
2013-12-26 11:43:37 +00:00
|
|
|
TLRPC.TL_document document = (TLRPC.TL_document)selectedObject.messageOwner.media.document;
|
|
|
|
document.path = selectedObject.messageOwner.attachPath;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(document, dialog_id);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (selectedObject.type == 2) {
|
2014-02-11 14:32:09 +00:00
|
|
|
TLRPC.TL_audio audio = (TLRPC.TL_audio)selectedObject.messageOwner.media.audio;
|
|
|
|
audio.path = selectedObject.messageOwner.attachPath;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(audio, dialog_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
ArrayList<Integer> arr = new ArrayList<Integer>();
|
|
|
|
arr.add(selectedObject.messageOwner.id);
|
2014-03-22 22:31:55 +00:00
|
|
|
ArrayList<Long> random_ids = null;
|
2014-04-04 17:58:33 +00:00
|
|
|
if (currentEncryptedChat != null && selectedObject.messageOwner.random_id != 0 && selectedObject.type != 10) {
|
2014-03-22 22:31:55 +00:00
|
|
|
random_ids = new ArrayList<Long>();
|
|
|
|
random_ids.add(selectedObject.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
MessagesController.getInstance().deleteMessages(arr, random_ids, currentEncryptedChat);
|
2013-10-25 15:19:00 +00:00
|
|
|
chatListView.setSelection(messages.size() + 1);
|
|
|
|
}
|
|
|
|
} else if (option == 1) {
|
|
|
|
if (selectedObject != null) {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<Integer>();
|
|
|
|
ids.add(selectedObject.messageOwner.id);
|
2013-12-20 19:25:49 +00:00
|
|
|
removeUnreadPlane(true);
|
2014-03-22 22:31:55 +00:00
|
|
|
ArrayList<Long> random_ids = null;
|
2014-04-04 17:58:33 +00:00
|
|
|
if (currentEncryptedChat != null && selectedObject.messageOwner.random_id != 0 && selectedObject.type != 10) {
|
2014-03-22 22:31:55 +00:00
|
|
|
random_ids = new ArrayList<Long>();
|
|
|
|
random_ids.add(selectedObject.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
|
2013-10-25 15:19:00 +00:00
|
|
|
selectedObject = null;
|
|
|
|
}
|
|
|
|
} else if (option == 2) {
|
|
|
|
if (selectedObject != null) {
|
|
|
|
forwaringMessage = selectedObject;
|
|
|
|
selectedObject = null;
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
2013-12-20 19:25:49 +00:00
|
|
|
args.putBoolean("serverOnly", true);
|
2014-06-03 23:31:48 +00:00
|
|
|
args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo));
|
|
|
|
MessagesActivity fragment = new MessagesActivity(args);
|
|
|
|
fragment.setDelegate(this);
|
|
|
|
presentFragment(fragment);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (option == 3) {
|
|
|
|
if (selectedObject != null) {
|
|
|
|
if(android.os.Build.VERSION.SDK_INT < 11) {
|
2014-06-03 23:31:48 +00:00
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
2013-10-25 15:19:00 +00:00
|
|
|
clipboard.setText(selectedObject.messageText);
|
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
2013-10-25 15:19:00 +00:00
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedObject.messageText);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
selectedObject = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:43:37 +00:00
|
|
|
@Override
|
|
|
|
public void didSelectFile(DocumentSelectActivity activity, String path, String name, String ext, long size) {
|
|
|
|
activity.finishFragment();
|
|
|
|
TLRPC.TL_document document = new TLRPC.TL_document();
|
|
|
|
document.id = 0;
|
2014-06-13 10:42:21 +00:00
|
|
|
document.user_id = UserConfig.getClientUserId();
|
2014-03-22 22:31:55 +00:00
|
|
|
document.date = ConnectionsManager.getInstance().getCurrentTime();
|
2013-12-26 11:43:37 +00:00
|
|
|
document.file_name = name;
|
|
|
|
document.size = (int)size;
|
|
|
|
document.dc_id = 0;
|
|
|
|
document.path = path;
|
|
|
|
if (ext.length() != 0) {
|
|
|
|
MimeTypeMap myMime = MimeTypeMap.getSingleton();
|
|
|
|
String mimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
|
|
|
|
if (mimeType != null) {
|
|
|
|
document.mime_type = mimeType;
|
|
|
|
} else {
|
|
|
|
document.mime_type = "application/octet-stream";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.mime_type = "application/octet-stream";
|
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
if (document.mime_type.equals("image/gif")) {
|
|
|
|
try {
|
2014-04-01 01:00:35 +00:00
|
|
|
Bitmap bitmap = FileLoader.loadBitmap(path, null, 90, 90);
|
2014-03-31 14:14:49 +00:00
|
|
|
if (bitmap != null) {
|
2014-04-01 01:00:35 +00:00
|
|
|
document.thumb = FileLoader.scaleAndSaveImage(bitmap, 90, 90, 80, currentEncryptedChat != null);
|
2014-03-31 14:14:49 +00:00
|
|
|
document.thumb.type = "s";
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (document.thumb == null) {
|
|
|
|
document.thumb = new TLRPC.TL_photoSizeEmpty();
|
|
|
|
document.thumb.type = "s";
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(document, dialog_id);
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 08:36:01 +00:00
|
|
|
@Override
|
|
|
|
public void startDocumentSelectActivity() {
|
|
|
|
try {
|
|
|
|
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
photoPickerIntent.setType("*/*");
|
|
|
|
getParentActivity().startActivityForResult(photoPickerIntent, 21);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void didSelectDialog(MessagesActivity activity, long did) {
|
|
|
|
if (dialog_id != 0 && (forwaringMessage != null || !selectedMessagesIds.isEmpty())) {
|
|
|
|
if (did != dialog_id) {
|
|
|
|
int lower_part = (int)did;
|
|
|
|
if (lower_part != 0) {
|
|
|
|
activity.removeSelfFromStack();
|
2014-06-03 23:31:48 +00:00
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("scrollToTopOnResume", scrollToTopOnResume);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (lower_part > 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
args.putInt("user_id", lower_part);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (lower_part < 0) {
|
2014-06-03 23:31:48 +00:00
|
|
|
args.putInt("chat_id", -lower_part);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new ChatActivity(args));
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
removeSelfFromStack();
|
|
|
|
if (forwaringMessage != null) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (forwaringMessage.messageOwner.id > 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(forwaringMessage, did);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
forwaringMessage = null;
|
|
|
|
} else {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
|
|
|
|
Collections.sort(ids);
|
|
|
|
for (Integer id : ids) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (id > 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(selectedMessagesIds.get(id), did);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
selectedMessagesCanCopyIds.clear();
|
2013-10-25 15:19:00 +00:00
|
|
|
selectedMessagesIds.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.finishFragment();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.finishFragment();
|
|
|
|
if (forwaringMessage != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(forwaringMessage, did);
|
2013-10-25 15:19:00 +00:00
|
|
|
forwaringMessage = null;
|
|
|
|
} else {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
|
|
|
|
Collections.sort(ids, new Comparator<Integer>() {
|
|
|
|
@Override
|
|
|
|
public int compare(Integer lhs, Integer rhs) {
|
|
|
|
return lhs.compareTo(rhs);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
for (Integer id : ids) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().sendMessage(selectedMessagesIds.get(id), did);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
selectedMessagesCanCopyIds.clear();
|
2013-10-25 15:19:00 +00:00
|
|
|
selectedMessagesIds.clear();
|
|
|
|
}
|
|
|
|
chatListView.setSelection(messages.size() + 1);
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBackPressed() {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBarLayer.hideActionMode();
|
|
|
|
updateVisibleRows();
|
|
|
|
return false;
|
|
|
|
} else if (emojiPopup != null && emojiPopup.isShowing()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
hideEmojiPopup();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGoogleMapsInstalled() {
|
|
|
|
try {
|
2014-06-14 08:36:01 +00:00
|
|
|
ApplicationInfo info = ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
} catch(PackageManager.NameNotFoundException e) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
builder.setMessage("Install Google Maps?");
|
|
|
|
builder.setCancelable(true);
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2013-10-25 15:19:00 +00: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-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(intent);
|
2013-10-25 15:19:00 +00:00
|
|
|
} catch (Exception e) {
|
2013-12-20 19:25:49 +00:00
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.Cancel, null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 15:19:00 +00: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();
|
|
|
|
if (tag instanceof ChatListRowHolderEx) {
|
|
|
|
ChatListRowHolderEx holder = (ChatListRowHolderEx)tag;
|
|
|
|
holder.update();
|
|
|
|
|
|
|
|
boolean disableSelection = false;
|
|
|
|
boolean selected = false;
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (selectedMessagesIds.containsKey(holder.message.messageOwner.id)) {
|
|
|
|
view.setBackgroundColor(0x6633b5e5);
|
|
|
|
selected = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
disableSelection = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
2014-02-11 14:32:09 +00:00
|
|
|
updateRowBackground(holder, disableSelection, selected);
|
2014-02-28 22:28:25 +00:00
|
|
|
} else if (view instanceof ChatBaseCell) {
|
|
|
|
ChatBaseCell cell = (ChatBaseCell)view;
|
|
|
|
|
|
|
|
boolean disableSelection = false;
|
|
|
|
boolean selected = false;
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2014-02-28 22:28:25 +00: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 09:23:06 +00:00
|
|
|
cell.setMessageObject(cell.getMessageObject());
|
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
cell.setCheckPressed(!disableSelection, disableSelection && selected);
|
2014-02-11 14:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateRowBackground(ChatListRowHolderEx holder, boolean disableSelection, boolean selected) {
|
|
|
|
int messageType = holder.message.type;
|
|
|
|
if (!disableSelection) {
|
2014-04-03 21:18:54 +00:00
|
|
|
if (messageType == 12) {
|
2014-02-11 14:32:09 +00:00
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_text_states);
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(6), Utilities.dp(6), Utilities.dp(18), 0);
|
|
|
|
} else if (messageType == 13) {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_incoming_text_states);
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(15), Utilities.dp(6), Utilities.dp(9), 0);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (messageType == 8) {
|
2014-02-11 14:32:09 +00:00
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_outgoing_text_states);
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(9), Utilities.dp(9), Utilities.dp(18), 0);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (messageType == 9) {
|
2014-02-11 14:32:09 +00:00
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.chat_incoming_text_states);
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(18), Utilities.dp(9), Utilities.dp(9), 0);
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-03 21:18:54 +00:00
|
|
|
if (messageType == 12) {
|
2014-02-11 14:32:09 +00:00
|
|
|
if (selected) {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_selected);
|
|
|
|
} else {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out);
|
|
|
|
}
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(6), Utilities.dp(6), Utilities.dp(18), 0);
|
|
|
|
} else if (messageType == 13) {
|
|
|
|
if (selected) {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in_selected);
|
|
|
|
} else {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in);
|
|
|
|
}
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(15), Utilities.dp(6), Utilities.dp(9), 0);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (messageType == 8) {
|
2014-02-11 14:32:09 +00:00
|
|
|
if (selected) {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out_selected);
|
|
|
|
} else {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_out);
|
|
|
|
}
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(9), Utilities.dp(9), Utilities.dp(18), 0);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (messageType == 9) {
|
2014-02-11 14:32:09 +00:00
|
|
|
if (selected) {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in_selected);
|
|
|
|
} else {
|
|
|
|
holder.chatBubbleView.setBackgroundResource(R.drawable.msg_in);
|
|
|
|
}
|
|
|
|
holder.chatBubbleView.setPadding(Utilities.dp(18), Utilities.dp(9), Utilities.dp(9), 0);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 21:18:54 +00:00
|
|
|
private void alertUserOpenError(MessageObject message) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-04-03 21:18:54 +00:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(R.string.OK, null);
|
|
|
|
if (message.type == 3) {
|
|
|
|
builder.setMessage(R.string.NoPlayerInstalled);
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.messageOwner.media.document.mime_type));
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-04-03 21:18:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
@Override
|
2014-06-12 01:13:15 +00:00
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2014-06-10 23:05:54 +00: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();
|
|
|
|
}
|
|
|
|
} else if (view.getTag() != null) {
|
|
|
|
Object tag = view.getTag();
|
|
|
|
if (tag instanceof ChatListRowHolderEx) {
|
|
|
|
ChatListRowHolderEx holder = (ChatListRowHolderEx)tag;
|
|
|
|
if (holder.message != null && holder.message.messageOwner.id == messageObject.messageOwner.id) {
|
|
|
|
messageToOpen = holder.message;
|
|
|
|
imageReceiver = holder.photoImage.imageReceiver;
|
|
|
|
view = holder.photoImage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageToOpen != null) {
|
|
|
|
int coords[] = new int[2];
|
|
|
|
view.getLocationInWindow(coords);
|
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
|
|
|
object.viewY = coords[1] - Utilities.statusBarHeight;
|
|
|
|
object.parentView = chatListView;
|
|
|
|
object.imageReceiver = imageReceiver;
|
|
|
|
object.thumb = object.imageReceiver.getBitmap();
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-11 00:22:42 +00:00
|
|
|
@Override
|
2014-06-12 01:13:15 +00: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 00:22:42 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
private class ChatAdapter extends BaseAdapter {
|
|
|
|
|
|
|
|
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 19:25:49 +00:00
|
|
|
if (count != 0) {
|
|
|
|
if (!endReached) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (!unread_end_reached) {
|
|
|
|
count++;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
2013-12-20 19:25:49 +00:00
|
|
|
return null;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
2013-12-20 19:25:49 +00:00
|
|
|
return true;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
int offset = 1;
|
2013-12-20 19:25:49 +00:00
|
|
|
if ((!endReached || !unread_end_reached) && messages.size() != 0) {
|
|
|
|
if (!endReached) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
if (i == 0 && !endReached || !unread_end_reached && i == (messages.size() + 1 - offset)) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
2013-12-20 19:25:49 +00:00
|
|
|
view = li.inflate(R.layout.chat_loading_layout, viewGroup, false);
|
|
|
|
View progressBar = view.findViewById(R.id.progressLayout);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (isCustomTheme) {
|
2013-12-20 19:25:49 +00:00
|
|
|
progressBar.setBackgroundResource(R.drawable.system_loader2);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
progressBar.setBackgroundResource(R.drawable.system_loader1);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MessageObject message = messages.get(messages.size() - i - offset);
|
2014-03-31 14:14:49 +00:00
|
|
|
int type = message.contentType;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
if (type == 0) {
|
2014-03-31 14:14:49 +00:00
|
|
|
view = new ChatMessageCell(mContext);
|
2014-04-03 21:18:54 +00:00
|
|
|
} if (type == 1) {
|
2014-03-31 14:14:49 +00:00
|
|
|
view = new ChatMediaCell(mContext);
|
|
|
|
((ChatMediaCell)view).downloadPhotos = downloadPhotos;
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 10) {
|
|
|
|
view = li.inflate(R.layout.chat_action_message_layout, viewGroup, false);
|
|
|
|
} else if (type == 11) {
|
|
|
|
view = li.inflate(R.layout.chat_action_change_photo_layout, viewGroup, false);
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (type == 4) {
|
2013-10-25 15:19:00 +00:00
|
|
|
view = li.inflate(R.layout.chat_outgoing_contact_layout, viewGroup, false);
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (type == 5) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (currentChat != null) {
|
|
|
|
view = li.inflate(R.layout.chat_group_incoming_contact_layout, viewGroup, false);
|
|
|
|
} else {
|
|
|
|
view = li.inflate(R.layout.chat_incoming_contact_layout, viewGroup, false);
|
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (type == 7) {
|
2013-12-20 19:25:49 +00:00
|
|
|
view = li.inflate(R.layout.chat_unread_layout, viewGroup, false);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (type == 8) {
|
2013-12-26 11:43:37 +00:00
|
|
|
view = li.inflate(R.layout.chat_outgoing_document_layout, viewGroup, false);
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (type == 9) {
|
2013-12-26 11:43:37 +00:00
|
|
|
if (currentChat != null) {
|
|
|
|
view = li.inflate(R.layout.chat_group_incoming_document_layout, viewGroup, false);
|
|
|
|
} else {
|
|
|
|
view = li.inflate(R.layout.chat_incoming_document_layout, viewGroup, false);
|
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (type == 2) {
|
|
|
|
view = new ChatAudioCell(mContext);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean selected = false;
|
|
|
|
boolean disableSelection = false;
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2014-02-28 22:28:25 +00:00
|
|
|
if (selectedMessagesIds.containsKey(message.messageOwner.id)) {
|
2013-10-25 15:19:00 +00:00
|
|
|
view.setBackgroundColor(0x6633b5e5);
|
|
|
|
selected = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
disableSelection = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
|
|
|
|
if (view instanceof ChatBaseCell) {
|
2014-03-31 14:14:49 +00:00
|
|
|
((ChatBaseCell)view).delegate = new ChatBaseCell.ChatBaseCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user) {
|
2014-06-13 10:42:21 +00:00
|
|
|
if (user != null && user.id != UserConfig.getClientUserId()) {
|
2014-03-31 14:14:49 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", user.id);
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new UserProfileActivity(args));
|
2014-03-31 14:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-03 21:18:54 +00:00
|
|
|
public void didPressedCancelSendButton(ChatBaseCell cell) {
|
2014-03-31 14:14:49 +00:00
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message.messageOwner.send_state != 0) {
|
|
|
|
MessagesController.getInstance().cancelSendingMessage(message);
|
|
|
|
}
|
|
|
|
}
|
2014-04-01 01:00:35 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didLongPressed(ChatBaseCell cell) {
|
|
|
|
createMenu(cell, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canPerformActions() {
|
2014-06-03 23:31:48 +00:00
|
|
|
return !actionBarLayer.isActionModeShowed();
|
2014-04-01 01:00:35 +00:00
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
};
|
|
|
|
if (view instanceof ChatMediaCell) {
|
|
|
|
((ChatMediaCell)view).mediaDelegate = new ChatMediaCell.ChatMediaCellDelegate() {
|
|
|
|
@Override
|
2014-06-10 23:05:54 +00:00
|
|
|
public void didPressedImage(ChatMediaCell cell) {
|
2014-04-03 21:18:54 +00:00
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
|
|
|
createMenu(cell, false);
|
|
|
|
return;
|
|
|
|
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (message.type == 1) {
|
2014-06-10 23:05:54 +00:00
|
|
|
PhotoViewer.getInstance().openPhoto(message, ChatActivity.this);
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (message.type == 3) {
|
|
|
|
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 = new File(Utilities.getCacheDir(), message.getFileName());
|
|
|
|
}
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(intent);
|
2014-04-03 21:18:54 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
alertUserOpenError(message);
|
|
|
|
}
|
|
|
|
} else if (message.type == 4) {
|
|
|
|
if (!isGoogleMapsInstalled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
LocationActivity fragment = new LocationActivity();
|
|
|
|
fragment.setMessageObject(message);
|
|
|
|
presentFragment(fragment);
|
2014-04-03 21:18:54 +00:00
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
((ChatBaseCell)view).isChat = currentChat != null;
|
2014-02-28 22:28:25 +00:00
|
|
|
((ChatBaseCell)view).setMessageObject(message);
|
|
|
|
((ChatBaseCell)view).setCheckPressed(!disableSelection, disableSelection && selected);
|
2014-05-24 22:47:05 +00:00
|
|
|
if (view instanceof ChatAudioCell && (downloadAudios == 0 || downloadAudios == 2 && ConnectionsManager.isConnectedToWiFi())) {
|
2014-03-22 22:31:55 +00:00
|
|
|
((ChatAudioCell)view).downloadAudioIfNeed();
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (view instanceof ChatMediaCell) {
|
|
|
|
((ChatMediaCell)view).downloadPhotos = downloadPhotos;
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
} else {
|
|
|
|
ChatListRowHolderEx holder = (ChatListRowHolderEx)view.getTag();
|
|
|
|
if (holder == null) {
|
2014-03-31 14:14:49 +00:00
|
|
|
holder = new ChatListRowHolderEx(view, message.type);
|
2014-02-28 22:28:25 +00:00
|
|
|
view.setTag(holder);
|
|
|
|
}
|
|
|
|
holder.message = message;
|
|
|
|
updateRowBackground(holder, disableSelection, selected);
|
|
|
|
holder.update();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
int offset = 1;
|
|
|
|
if (!endReached && messages.size() != 0) {
|
|
|
|
offset = 0;
|
|
|
|
if (i == 0) {
|
2014-04-03 21:18:54 +00:00
|
|
|
return 6;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (!unread_end_reached && i == (messages.size() + 1 - offset)) {
|
2014-04-03 21:18:54 +00:00
|
|
|
return 6;
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
MessageObject message = messages.get(messages.size() - i - offset);
|
2014-03-31 14:14:49 +00:00
|
|
|
return message.contentType;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
2014-04-03 21:18:54 +00:00
|
|
|
return 12;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
int count = messages.size();
|
2013-12-20 19:25:49 +00:00
|
|
|
if (count != 0) {
|
|
|
|
if (!endReached) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (!unread_end_reached) {
|
|
|
|
count++;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
return count == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ChatListRowHolderEx {
|
|
|
|
public BackupImageView avatarImageView;
|
|
|
|
public TextView nameTextView;
|
|
|
|
public TextView messageTextView;
|
|
|
|
public MessageActionLayout messageLayoutAction;
|
|
|
|
public TextView timeTextView;
|
|
|
|
public BackupImageView photoImage;
|
|
|
|
public ImageView halfCheckImage;
|
|
|
|
public ImageView checkImage;
|
|
|
|
public TextView actionAttachButton;
|
|
|
|
public TextView videoTimeText;
|
|
|
|
public MessageObject message;
|
|
|
|
public TextView phoneTextView;
|
|
|
|
public BackupImageView contactAvatar;
|
|
|
|
public View contactView;
|
|
|
|
public ImageView addContactButton;
|
|
|
|
public View addContactView;
|
|
|
|
public View chatBubbleView;
|
|
|
|
|
|
|
|
public ProgressBar actionProgress;
|
|
|
|
public View actionView;
|
|
|
|
public ImageView actionCancelButton;
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
private PhotoObject photoObjectToSet = null;
|
|
|
|
private File photoFile = null;
|
|
|
|
private String photoFilter = null;
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
public void update() {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User fromUser = MessagesController.getInstance().users.get(message.messageOwner.from_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
int type = message.type;
|
|
|
|
|
|
|
|
if (timeTextView != null) {
|
2014-03-25 00:25:32 +00:00
|
|
|
timeTextView.setText(LocaleController.formatterDay.format((long) (message.messageOwner.date) * 1000));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (avatarImageView != null && fromUser != null) {
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (fromUser.photo != null) {
|
|
|
|
photo = fromUser.photo.photo_small;
|
|
|
|
}
|
|
|
|
int placeHolderId = Utilities.getUserAvatarForId(fromUser.id);
|
|
|
|
avatarImageView.setImage(photo, "50_50", placeHolderId);
|
|
|
|
}
|
|
|
|
|
2014-03-31 14:14:49 +00:00
|
|
|
if (type != 12 && type != 13 && nameTextView != null && fromUser != null && type != 8 && type != 9) {
|
2013-10-25 15:19:00 +00:00
|
|
|
nameTextView.setText(Utilities.formatName(fromUser.first_name, fromUser.last_name));
|
|
|
|
nameTextView.setTextColor(Utilities.getColorForId(message.messageOwner.from_id));
|
|
|
|
}
|
|
|
|
|
2014-04-03 21:18:54 +00:00
|
|
|
if (type == 11 || type == 10) {
|
2014-06-03 23:31:48 +00:00
|
|
|
int width = Utilities.displaySize.x - Utilities.dp(30);
|
2013-10-25 15:19:00 +00:00
|
|
|
messageTextView.setText(message.messageText);
|
|
|
|
messageTextView.setMaxWidth(width);
|
|
|
|
|
|
|
|
if (type == 11) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
|
|
|
photoImage.setImage(message.messageOwner.action.newUserPhoto.photo_small, "50_50", Utilities.getUserAvatarForId(currentUser.id));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-26 16:46:13 +00:00
|
|
|
PhotoObject photo = PhotoObject.getClosestImageWithSize(message.photoThumbs, Utilities.dp(64), Utilities.dp(64));
|
2013-12-20 19:25:49 +00:00
|
|
|
if (photo.image != null) {
|
|
|
|
photoImage.setImageBitmap(photo.image);
|
|
|
|
} else {
|
|
|
|
photoImage.setImage(photo.photoOwner.location, "50_50", Utilities.getGroupAvatarForId(currentChat.id));
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
photoImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (type == 12 || type == 13) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User contactUser = MessagesController.getInstance().users.get(message.messageOwner.media.user_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (contactUser != null) {
|
|
|
|
nameTextView.setText(Utilities.formatName(message.messageOwner.media.first_name, message.messageOwner.media.last_name));
|
|
|
|
nameTextView.setTextColor(Utilities.getColorForId(contactUser.id));
|
|
|
|
String phone = message.messageOwner.media.phone_number;
|
|
|
|
if (phone != null && phone.length() != 0) {
|
|
|
|
if (!phone.startsWith("+")) {
|
|
|
|
phone = "+" + phone;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
phoneTextView.setText(PhoneFormat.getInstance().format(phone));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
phoneTextView.setText("Unknown");
|
|
|
|
}
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (contactUser.photo != null) {
|
|
|
|
photo = contactUser.photo.photo_small;
|
|
|
|
}
|
|
|
|
int placeHolderId = Utilities.getUserAvatarForId(contactUser.id);
|
|
|
|
contactAvatar.setImage(photo, "50_50", placeHolderId);
|
2014-06-13 10:42:21 +00:00
|
|
|
if (contactUser.id != UserConfig.getClientUserId() && ContactsController.getInstance().contactsDict.get(contactUser.id) == null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
addContactView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
addContactView.setVisibility(View.GONE);
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
|
|
|
nameTextView.setText(Utilities.formatName(message.messageOwner.media.first_name, message.messageOwner.media.last_name));
|
|
|
|
nameTextView.setTextColor(Utilities.getColorForId(message.messageOwner.media.user_id));
|
|
|
|
String phone = message.messageOwner.media.phone_number;
|
|
|
|
if (phone != null && phone.length() != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
if (message.messageOwner.media.user_id != 0 && !phone.startsWith("+")) {
|
2013-12-20 19:25:49 +00:00
|
|
|
phone = "+" + phone;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
phoneTextView.setText(PhoneFormat.getInstance().format(phone));
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
|
|
|
phoneTextView.setText("Unknown");
|
|
|
|
}
|
|
|
|
contactAvatar.setImageResource(Utilities.getUserAvatarForId(message.messageOwner.media.user_id));
|
|
|
|
addContactView.setVisibility(View.GONE);
|
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (type == 7) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (unread_to_load == 1) {
|
2014-03-22 22:31:55 +00:00
|
|
|
messageTextView.setText(LocaleController.formatString("OneNewMessage", R.string.OneNewMessage, unread_to_load));
|
2013-12-20 19:25:49 +00:00
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
messageTextView.setText(LocaleController.formatString("FewNewMessages", R.string.FewNewMessages, unread_to_load));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
} else if (type == 8 || type == 9) {
|
2013-12-26 11:43:37 +00:00
|
|
|
TLRPC.Document document = message.messageOwner.media.document;
|
|
|
|
if (document instanceof TLRPC.TL_document || document instanceof TLRPC.TL_documentEncrypted) {
|
|
|
|
nameTextView.setText(message.messageOwner.media.document.file_name);
|
|
|
|
|
|
|
|
String fileName = message.getFileName();
|
|
|
|
int idx = fileName.lastIndexOf(".");
|
|
|
|
String ext = null;
|
|
|
|
if (idx != -1) {
|
|
|
|
ext = fileName.substring(idx + 1);
|
|
|
|
}
|
|
|
|
if (ext == null || ext.length() == 0) {
|
|
|
|
ext = message.messageOwner.media.document.mime_type;
|
|
|
|
}
|
|
|
|
ext = ext.toUpperCase();
|
|
|
|
if (document.size < 1024) {
|
|
|
|
phoneTextView.setText(String.format("%d B %s", document.size, ext));
|
|
|
|
} else if (document.size < 1024 * 1024) {
|
|
|
|
phoneTextView.setText(String.format("%.1f KB %s", document.size / 1024.0f, ext));
|
|
|
|
} else {
|
|
|
|
phoneTextView.setText(String.format("%.1f MB %s", document.size / 1024.0f / 1024.0f, ext));
|
|
|
|
}
|
|
|
|
if (document.thumb instanceof TLRPC.TL_photoSize) {
|
2014-06-10 23:05:54 +00:00
|
|
|
contactAvatar.setImage(document.thumb.location, "50_50", type == 8 ? R.drawable.doc_green : R.drawable.doc_blue);
|
2013-12-26 11:43:37 +00:00
|
|
|
} else if (document.thumb instanceof TLRPC.TL_photoCachedSize) {
|
2014-06-10 23:05:54 +00:00
|
|
|
contactAvatar.setImage(document.thumb.location, "50_50", type == 8 ? R.drawable.doc_green : R.drawable.doc_blue);
|
2013-12-26 11:43:37 +00:00
|
|
|
} else {
|
2014-03-31 14:14:49 +00:00
|
|
|
if (type == 8) {
|
2013-12-26 11:43:37 +00:00
|
|
|
contactAvatar.setImageResource(R.drawable.doc_green);
|
|
|
|
} else {
|
|
|
|
contactAvatar.setImageResource(R.drawable.doc_blue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("Error");
|
|
|
|
phoneTextView.setText("Error");
|
2014-03-31 14:14:49 +00:00
|
|
|
if (type == 8) {
|
2013-12-26 11:43:37 +00:00
|
|
|
contactAvatar.setImageResource(R.drawable.doc_green);
|
|
|
|
} else {
|
|
|
|
contactAvatar.setImageResource(R.drawable.doc_blue);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
if (message.messageOwner.id < 0 && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SEND_ERROR && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENT) {
|
2014-03-22 22:31:55 +00:00
|
|
|
if (MessagesController.getInstance().sendingMessages.get(message.messageOwner.id) == null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
message.messageOwner.send_state = MessagesController.MESSAGE_SEND_STATE_SEND_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.isFromMe()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (halfCheckImage != null) {
|
|
|
|
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
2013-12-20 19:25:49 +00:00
|
|
|
checkImage.setVisibility(View.INVISIBLE);
|
2014-04-03 21:18:54 +00:00
|
|
|
halfCheckImage.setImageResource(R.drawable.msg_clock);
|
2013-10-25 15:19:00 +00:00
|
|
|
halfCheckImage.setVisibility(View.VISIBLE);
|
2014-03-31 14:14:49 +00:00
|
|
|
if (actionView != null) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (actionView != null) {
|
|
|
|
actionView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
Float progress = FileLoader.getInstance().fileProgresses.get(message.messageOwner.attachPath);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (progress != null) {
|
|
|
|
actionProgress.setProgress((int)(progress * 100));
|
|
|
|
} else {
|
|
|
|
actionProgress.setProgress(0);
|
|
|
|
}
|
|
|
|
progressByTag.put((Integer)actionProgress.getTag(), message.messageOwner.attachPath);
|
|
|
|
progressBarMap.put(message.messageOwner.attachPath, actionProgress);
|
|
|
|
}
|
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
|
|
|
halfCheckImage.setVisibility(View.VISIBLE);
|
|
|
|
halfCheckImage.setImageResource(R.drawable.msg_warning);
|
|
|
|
if (checkImage != null) {
|
|
|
|
checkImage.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
if (actionView != null) {
|
|
|
|
actionView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
|
|
|
|
if (!message.messageOwner.unread) {
|
|
|
|
halfCheckImage.setVisibility(View.VISIBLE);
|
2013-12-20 19:25:49 +00:00
|
|
|
checkImage.setVisibility(View.VISIBLE);
|
2014-04-03 21:18:54 +00:00
|
|
|
halfCheckImage.setImageResource(R.drawable.msg_halfcheck);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
halfCheckImage.setVisibility(View.VISIBLE);
|
2013-12-20 19:25:49 +00:00
|
|
|
checkImage.setVisibility(View.INVISIBLE);
|
2014-04-03 21:18:54 +00:00
|
|
|
halfCheckImage.setImageResource(R.drawable.msg_check);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
if (actionView != null) {
|
|
|
|
actionView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2013-10-25 15:19:00 +00:00
|
|
|
Integer tag = (Integer)actionProgress.getTag();
|
|
|
|
String file = progressByTag.get(tag);
|
|
|
|
if (file != null) {
|
|
|
|
removeFromloadingFile(file, actionProgress);
|
|
|
|
}
|
|
|
|
if (message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENDING && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
|
|
|
if (file != null) {
|
|
|
|
progressBarMap.remove(file);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
String fileName = message.getFileName();
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean load = false;
|
2014-02-04 18:36:55 +00:00
|
|
|
if (message.type != 2 && message.type != 3 && message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
|
2013-10-25 15:19:00 +00:00
|
|
|
File f = new File(message.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setVisibility(View.VISIBLE);
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2014-03-22 22:31:55 +00:00
|
|
|
actionAttachButton.setText(LocaleController.getString("Open", R.string.Open));
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (actionView != null) {
|
|
|
|
actionView.setVisibility(View.GONE);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
load = true;
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
if (load && message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0 || !load && (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0)) {
|
2014-02-04 18:36:55 +00:00
|
|
|
File cacheFile = null;
|
2014-03-31 14:14:49 +00:00
|
|
|
if ((cacheFile = new File(Utilities.getCacheDir(), fileName)).exists()) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setVisibility(View.VISIBLE);
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2014-03-22 22:31:55 +00:00
|
|
|
actionAttachButton.setText(LocaleController.getString("Open", R.string.Open));
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (actionView != null) {
|
|
|
|
actionView.setVisibility(View.GONE);
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
load = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
load = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (load) {
|
2014-03-22 22:31:55 +00:00
|
|
|
Float progress = FileLoader.getInstance().fileProgresses.get(fileName);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (loadingFile.containsKey(fileName) || progress != null) {
|
|
|
|
if (progress != null) {
|
|
|
|
actionProgress.setProgress((int)(progress * 100));
|
|
|
|
} else {
|
|
|
|
actionProgress.setProgress(0);
|
|
|
|
}
|
|
|
|
progressByTag.put((Integer)actionProgress.getTag(), fileName);
|
|
|
|
addToLoadingFile(fileName, actionProgress);
|
2014-02-04 18:36:55 +00:00
|
|
|
if (actionView != null) {
|
2014-03-31 14:14:49 +00:00
|
|
|
actionView.setVisibility(View.VISIBLE);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setVisibility(View.GONE);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (actionView != null) {
|
2014-03-31 14:14:49 +00:00
|
|
|
actionView.setVisibility(View.GONE);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setVisibility(View.VISIBLE);
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2014-03-22 22:31:55 +00:00
|
|
|
actionAttachButton.setText(LocaleController.getString("DOWNLOAD", R.string.DOWNLOAD));
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 14:14:49 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2014-02-04 18:36:55 +00:00
|
|
|
int width;
|
2014-03-31 14:14:49 +00:00
|
|
|
if (currentChat != null && type != 8) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (actionView.getVisibility() == View.VISIBLE) {
|
2014-06-03 23:31:48 +00:00
|
|
|
width = Utilities.displaySize.x - Utilities.dp(290);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
width = Utilities.displaySize.x - Utilities.dp(270);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2013-12-26 11:43:37 +00:00
|
|
|
} else {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (actionView.getVisibility() == View.VISIBLE) {
|
2014-06-03 23:31:48 +00:00
|
|
|
width = Utilities.displaySize.x - Utilities.dp(240);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
width = Utilities.displaySize.x - Utilities.dp(220);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
nameTextView.setMaxWidth(width);
|
|
|
|
phoneTextView.setMaxWidth(width);
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
public ChatListRowHolderEx(View view, int type) {
|
2013-10-25 15:19:00 +00:00
|
|
|
avatarImageView = (BackupImageView)view.findViewById(R.id.chat_group_avatar_image);
|
|
|
|
nameTextView = (TextView)view.findViewById(R.id.chat_user_group_name);
|
|
|
|
messageLayoutAction = (MessageActionLayout)view.findViewById(R.id.message_action_layout);
|
|
|
|
timeTextView = (TextView)view.findViewById(R.id.chat_time_text);
|
|
|
|
photoImage = (BackupImageView)view.findViewById(R.id.chat_photo_image);
|
|
|
|
halfCheckImage = (ImageView)view.findViewById(R.id.chat_row_halfcheck);
|
|
|
|
checkImage = (ImageView)view.findViewById(R.id.chat_row_check);
|
|
|
|
actionAttachButton = (TextView)view.findViewById(R.id.chat_view_action_button);
|
|
|
|
messageTextView = (TextView)view.findViewById(R.id.chat_message_text);
|
|
|
|
videoTimeText = (TextView)view.findViewById(R.id.chat_video_time);
|
|
|
|
actionView = view.findViewById(R.id.chat_view_action_layout);
|
|
|
|
actionProgress = (ProgressBar)view.findViewById(R.id.chat_view_action_progress);
|
|
|
|
actionCancelButton = (ImageView)view.findViewById(R.id.chat_view_action_cancel_button);
|
|
|
|
phoneTextView = (TextView)view.findViewById(R.id.phone_text_view);
|
|
|
|
contactAvatar = (BackupImageView)view.findViewById(R.id.contact_avatar);
|
|
|
|
contactView = view.findViewById(R.id.shared_layout);
|
|
|
|
addContactButton = (ImageView)view.findViewById(R.id.add_contact_button);
|
|
|
|
addContactView = view.findViewById(R.id.add_contact_view);
|
|
|
|
chatBubbleView = view.findViewById(R.id.chat_bubble_layout);
|
|
|
|
if (messageTextView != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (actionProgress != null) {
|
|
|
|
actionProgress.setTag(progressTag);
|
|
|
|
progressTag++;
|
|
|
|
}
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
if (type != 2 && type != 3) {
|
|
|
|
if (actionView != null) {
|
|
|
|
if (isCustomTheme) {
|
|
|
|
actionView.setBackgroundResource(R.drawable.system_black);
|
|
|
|
} else {
|
|
|
|
actionView.setBackgroundResource(R.drawable.system_blue);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageLayoutAction != null) {
|
|
|
|
if (isCustomTheme) {
|
2013-12-20 19:25:49 +00:00
|
|
|
messageLayoutAction.setBackgroundResource(R.drawable.system_black);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
messageLayoutAction.setBackgroundResource(R.drawable.system_blue);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addContactButton != null) {
|
|
|
|
addContactButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
processRowSelect(view);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", message.messageOwner.media.user_id);
|
2013-12-20 19:25:49 +00:00
|
|
|
args.putString("phone", message.messageOwner.media.phone_number);
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new ContactAddActivity(args));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
addContactButton.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
createMenu(v, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contactView != null) {
|
|
|
|
contactView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-03-31 14:14:49 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2013-12-26 11:43:37 +00:00
|
|
|
processOnClick(view);
|
|
|
|
} else if (message.type == 12 || message.type == 13) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-12-26 11:43:37 +00:00
|
|
|
processRowSelect(view);
|
|
|
|
return;
|
|
|
|
}
|
2014-06-13 10:42:21 +00:00
|
|
|
if (message.messageOwner.media.user_id != UserConfig.getClientUserId()) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = null;
|
|
|
|
if (message.messageOwner.media.user_id != 0) {
|
|
|
|
user = MessagesController.getInstance().users.get(message.messageOwner.media.user_id);
|
|
|
|
}
|
|
|
|
if (user != null) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", message.messageOwner.media.user_id);
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new UserProfileActivity(args));
|
2014-03-22 22:31:55 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (message.messageOwner.media.phone_number == null || message.messageOwner.media.phone_number.length() == 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() {
|
2014-06-06 23:35:21 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (i == 1) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + message.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) {
|
|
|
|
int sdk = android.os.Build.VERSION.SDK_INT;
|
|
|
|
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(message.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", message.messageOwner.media.phone_number);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
);
|
|
|
|
showAlertDialog(builder);
|
2014-03-22 22:31:55 +00:00
|
|
|
}
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
contactView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
createMenu(v, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
if (contactAvatar != null) {
|
|
|
|
contactAvatar.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-03-31 14:14:49 +00:00
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
if (actionAttachButton != null) {
|
|
|
|
actionAttachButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2013-12-26 11:43:37 +00:00
|
|
|
processOnClick(view);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (avatarImageView != null) {
|
|
|
|
avatarImageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
processRowSelect(view);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (message != null) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", message.messageOwner.from_id);
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new UserProfileActivity(args));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actionCancelButton != null) {
|
|
|
|
actionCancelButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (message != null) {
|
|
|
|
Integer tag = (Integer)actionProgress.getTag();
|
|
|
|
if (message.messageOwner.send_state != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().cancelSendingMessage(message);
|
2013-10-25 15:19:00 +00:00
|
|
|
String file = progressByTag.get(tag);
|
|
|
|
if (file != null) {
|
|
|
|
progressBarMap.remove(file);
|
|
|
|
}
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (message.type == 8 || message.type == 9) {
|
2013-10-25 15:19:00 +00:00
|
|
|
String file = progressByTag.get(tag);
|
|
|
|
if (file != null) {
|
|
|
|
loadingFile.remove(file);
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2014-03-22 22:31:55 +00:00
|
|
|
FileLoader.getInstance().cancelLoadFile(null, null, message.messageOwner.media.document, null);
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (photoImage != null) {
|
|
|
|
photoImage.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2013-12-26 11:43:37 +00:00
|
|
|
processOnClick(view);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
photoImage.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
createMenu(v, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-12-26 11:43:37 +00:00
|
|
|
|
|
|
|
private void processOnClick(View view) {
|
2014-06-03 23:31:48 +00:00
|
|
|
if (actionBarLayer.isActionModeShowed()) {
|
2013-12-26 11:43:37 +00:00
|
|
|
processRowSelect(view);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (message != null) {
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 11) {
|
2014-06-10 23:05:54 +00:00
|
|
|
PhotoViewer.getInstance().openPhoto(message, ChatActivity.this);
|
2014-04-03 21:18:54 +00:00
|
|
|
} else if (message.type == 8 || message.type == 9) {
|
2013-12-26 11:43:37 +00:00
|
|
|
File f = null;
|
|
|
|
String fileName = message.getFileName();
|
|
|
|
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
|
|
|
|
f = new File(message.messageOwner.attachPath);
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
if (f == null || f != null && !f.exists()) {
|
2013-12-26 11:43:37 +00:00
|
|
|
f = new File(Utilities.getCacheDir(), fileName);
|
|
|
|
}
|
|
|
|
if (f != null && f.exists()) {
|
2014-02-04 18:36:55 +00:00
|
|
|
String realMimeType = null;
|
2013-12-26 11:43:37 +00:00
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2013-12-26 11:43:37 +00:00
|
|
|
MimeTypeMap myMime = MimeTypeMap.getSingleton();
|
|
|
|
int idx = fileName.lastIndexOf(".");
|
|
|
|
if (idx != -1) {
|
|
|
|
String ext = fileName.substring(idx + 1);
|
2014-02-04 18:36:55 +00:00
|
|
|
realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
|
|
|
|
if (realMimeType != null) {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), realMimeType);
|
2013-12-26 11:43:37 +00:00
|
|
|
} else {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
if (realMimeType != null) {
|
|
|
|
try {
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(intent);
|
2014-02-04 18:36:55 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(intent);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2013-12-26 11:43:37 +00:00
|
|
|
} else {
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(intent);
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
} catch (Exception e) {
|
2014-04-03 21:18:54 +00:00
|
|
|
alertUserOpenError(message);
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SEND_ERROR && message.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENDING || !message.isOut()) {
|
2013-12-26 11:43:37 +00:00
|
|
|
if (!loadingFile.containsKey(fileName)) {
|
|
|
|
progressByTag.put((Integer)actionProgress.getTag(), fileName);
|
|
|
|
addToLoadingFile(fileName, actionProgress);
|
2014-04-03 21:18:54 +00:00
|
|
|
if (message.type == 8 || message.type == 9) {
|
2014-03-22 22:31:55 +00:00
|
|
|
FileLoader.getInstance().loadFile(null, null, message.messageOwner.media.document, null);
|
2013-12-26 11:43:37 +00:00
|
|
|
}
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
|
|
|
createMenu(view, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|