2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2013-12-20 20:25:49 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 17:19:00 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
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.PackageManager;
|
2014-03-22 23:31:55 +01:00
|
|
|
import android.content.res.Configuration;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.database.Cursor;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.graphics.Bitmap;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.graphics.Rect;
|
2015-03-19 00:09:45 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2015-02-26 02:32:51 +01:00
|
|
|
import android.media.ExifInterface;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.net.Uri;
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.os.Build;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.os.Bundle;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.provider.ContactsContract;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.provider.MediaStore;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.text.TextUtils;
|
2015-09-02 00:14:21 +02:00
|
|
|
import android.text.style.ClickableSpan;
|
2015-03-19 00:09:45 +01:00
|
|
|
import android.util.Base64;
|
2014-10-10 19:16:39 +02:00
|
|
|
import android.util.SparseArray;
|
2014-11-14 16:40:15 +01:00
|
|
|
import android.util.TypedValue;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.Gravity;
|
2014-07-10 02:15:58 +02:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
2014-11-06 22:34:47 +01:00
|
|
|
import android.view.WindowManager;
|
2013-12-26 12:43:37 +01:00
|
|
|
import android.webkit.MimeTypeMap;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.AdapterView;
|
2015-07-22 20:56:37 +02:00
|
|
|
import android.widget.EditText;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.FrameLayout;
|
2014-11-19 16:17:24 +01:00
|
|
|
import android.widget.ImageView;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.widget.LinearLayout;
|
2015-03-19 00:09:45 +01:00
|
|
|
import android.widget.ListView;
|
2015-02-26 02:32:51 +01:00
|
|
|
import android.widget.ProgressBar;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.TextView;
|
2014-06-14 10:36:01 +02:00
|
|
|
import android.widget.Toast;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2015-03-19 00:09:45 +01:00
|
|
|
import org.telegram.android.Emoji;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.LocaleController;
|
|
|
|
import org.telegram.android.MediaController;
|
|
|
|
import org.telegram.android.MessagesStorage;
|
2014-07-10 02:15:58 +02:00
|
|
|
import org.telegram.android.NotificationsController;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.android.SecretChatHelper;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.SendMessagesHelper;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.android.UserObject;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.android.VideoEditedInfo;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.android.query.BotQuery;
|
|
|
|
import org.telegram.android.query.MessagesSearchQuery;
|
2015-03-19 00:09:45 +01:00
|
|
|
import org.telegram.android.query.ReplyMessageQuery;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.android.query.StickersQuery;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.android.support.widget.LinearLayoutManager;
|
|
|
|
import org.telegram.android.support.widget.RecyclerView;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-09-14 01:40:36 +02:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2015-03-19 00:09:45 +01:00
|
|
|
import org.telegram.messenger.RPCRequest;
|
|
|
|
import org.telegram.messenger.SerializedData;
|
|
|
|
import org.telegram.messenger.TLObject;
|
2014-02-28 23:28:25 +01:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.ContactsController;
|
2013-12-20 20:25:49 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.MessageObject;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.MessagesController;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
2015-03-19 00:09:45 +01:00
|
|
|
import org.telegram.ui.Adapters.MentionsAdapter;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.Adapters.StickersAdapter;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.android.AnimationCompat.AnimatorListenerAdapterProxy;
|
|
|
|
import org.telegram.android.AnimationCompat.AnimatorSetProxy;
|
|
|
|
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
|
|
|
|
import org.telegram.android.AnimationCompat.ViewProxy;
|
2014-10-14 22:36:15 +02:00
|
|
|
import org.telegram.ui.Cells.ChatActionCell;
|
2014-02-28 23:28:25 +01:00
|
|
|
import org.telegram.ui.Cells.ChatAudioCell;
|
|
|
|
import org.telegram.ui.Cells.ChatBaseCell;
|
2014-10-15 20:43:52 +02:00
|
|
|
import org.telegram.ui.Cells.ChatContactCell;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.Cells.ChatLoadingCell;
|
2014-03-31 16:14:49 +02:00
|
|
|
import org.telegram.ui.Cells.ChatMediaCell;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Cells.ChatMessageCell;
|
2015-07-22 20:56:37 +02:00
|
|
|
import org.telegram.ui.Cells.ChatMusicCell;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.Cells.ChatUnreadCell;
|
|
|
|
import org.telegram.ui.Components.AlertsCreator;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.Cells.BotHelpCell;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.ChatActivityEnterView;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.ImageReceiver;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.Components.ChatAttachView;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.FrameLayoutFixed;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
import org.telegram.ui.Components.RecordStatusDrawable;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.ResourceLoader;
|
|
|
|
import org.telegram.ui.Components.SendingFileExDrawable;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.SizeNotifierFrameLayout;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.TimerDrawable;
|
|
|
|
import org.telegram.ui.Components.TypingDotsDrawable;
|
2015-09-02 00:14:21 +02:00
|
|
|
import org.telegram.ui.Components.URLSpanNoUnderline;
|
|
|
|
import org.telegram.ui.Components.URLSpanReplacement;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.WebFrameLayout;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
2015-06-29 19:12:11 +02:00
|
|
|
import java.net.URLDecoder;
|
2013-10-25 17:19:00 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
2014-03-26 21:16:28 +01:00
|
|
|
import java.util.concurrent.Semaphore;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.MessagesActivityDelegate,
|
2014-10-15 20:43:52 +02:00
|
|
|
PhotoViewer.PhotoViewerProvider {
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
protected TLRPC.Chat currentChat;
|
|
|
|
protected TLRPC.User currentUser;
|
|
|
|
protected TLRPC.EncryptedChat currentEncryptedChat;
|
2014-08-22 16:24:33 +02:00
|
|
|
private boolean userBlocked = false;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private ArrayList<ChatMessageCell> chatMessageCellsCache = new ArrayList<>();
|
|
|
|
private ArrayList<ChatMediaCell> chatMediaCellsCache = new ArrayList<>();
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private FrameLayout progressView;
|
|
|
|
private FrameLayout bottomOverlay;
|
2014-08-22 16:24:33 +02:00
|
|
|
private ChatActivityEnterView chatActivityEnterView;
|
2014-11-19 16:17:24 +01:00
|
|
|
private ImageView timeItem;
|
|
|
|
private View timeItem2;
|
2014-11-17 03:44:57 +01:00
|
|
|
private TimerDrawable timerDrawable;
|
|
|
|
private ActionBarMenuItem menuItem;
|
2014-11-19 16:17:24 +01:00
|
|
|
private ActionBarMenuItem attachItem;
|
|
|
|
private ActionBarMenuItem headerItem;
|
2015-06-29 19:12:11 +02:00
|
|
|
private ActionBarMenuItem searchItem;
|
|
|
|
private ActionBarMenuItem searchUpItem;
|
|
|
|
private ActionBarMenuItem searchDownItem;
|
2014-11-17 03:44:57 +01:00
|
|
|
private TextView addContactItem;
|
2015-05-21 23:27:27 +02:00
|
|
|
private RecyclerListView chatListView;
|
2015-05-03 13:48:36 +02:00
|
|
|
private LinearLayoutManager chatLayoutManager;
|
|
|
|
private ChatActivityAdapter chatAdapter;
|
2014-08-22 16:24:33 +02:00
|
|
|
private BackupImageView avatarImageView;
|
|
|
|
private TextView bottomOverlayChatText;
|
2015-02-26 02:32:51 +01:00
|
|
|
private FrameLayout bottomOverlayChat;
|
2014-09-24 04:17:27 +02:00
|
|
|
private TypingDotsDrawable typingDotsDrawable;
|
2015-05-03 13:48:36 +02:00
|
|
|
private RecordStatusDrawable recordStatusDrawable;
|
|
|
|
private SendingFileExDrawable sendingFileDrawable;
|
2015-02-26 02:32:51 +01:00
|
|
|
private FrameLayout emptyViewContainer;
|
2015-01-02 23:15:07 +01:00
|
|
|
private ArrayList<View> actionModeViews = new ArrayList<>();
|
2014-11-14 16:40:15 +01:00
|
|
|
private TextView nameTextView;
|
|
|
|
private TextView onlineTextView;
|
|
|
|
private FrameLayout avatarContainer;
|
2013-10-25 17:19:00 +02:00
|
|
|
private TextView bottomOverlayText;
|
2014-11-17 03:44:57 +01:00
|
|
|
private TextView secretViewStatusTextView;
|
|
|
|
private TextView selectedMessagesCountTextView;
|
2015-01-02 23:15:07 +01:00
|
|
|
private RecyclerListView stickersListView;
|
|
|
|
private StickersAdapter stickersAdapter;
|
2015-02-26 02:32:51 +01:00
|
|
|
private FrameLayout stickersPanel;
|
2015-02-01 19:51:02 +01:00
|
|
|
private TextView muteItem;
|
2015-02-26 02:32:51 +01:00
|
|
|
private ImageView pagedownButton;
|
2015-03-19 00:09:45 +01:00
|
|
|
private BackupImageView replyImageView;
|
|
|
|
private TextView replyNameTextView;
|
|
|
|
private TextView replyObjectTextView;
|
|
|
|
private ImageView replyIconImageView;
|
|
|
|
private MentionsAdapter mentionsAdapter;
|
|
|
|
private ListView mentionListView;
|
|
|
|
private AnimatorSetProxy mentionListAnimation;
|
2015-06-29 19:12:11 +02:00
|
|
|
private ChatAttachView chatAttachView;
|
2015-07-22 20:56:37 +02:00
|
|
|
private BottomSheet chatAttachViewSheet;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
private boolean allowStickersPanel;
|
|
|
|
private AnimatorSetProxy runningAnimation;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private MessageObject selectedObject;
|
2015-03-19 00:09:45 +01:00
|
|
|
private ArrayList<MessageObject> forwardingMessages;
|
2013-10-25 17:19:00 +02:00
|
|
|
private MessageObject forwaringMessage;
|
2015-03-19 00:09:45 +01:00
|
|
|
private MessageObject replyingMessageObject;
|
2013-10-25 17:19:00 +02:00
|
|
|
private boolean paused = true;
|
2015-05-03 13:48:36 +02:00
|
|
|
private boolean wasPaused = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
private boolean readWhenResume = false;
|
2015-04-09 20:00:14 +02:00
|
|
|
private TLRPC.FileLocation replyImageLocation;
|
|
|
|
private long linkSearchRequestId;
|
|
|
|
private TLRPC.WebPage foundWebPage;
|
|
|
|
private String pendingLinkSearchString;
|
|
|
|
private Runnable pendingWebPageTimeoutRunnable;
|
|
|
|
private Runnable waitingForCharaterEnterRunnable;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2014-11-18 06:01:04 +01:00
|
|
|
private boolean openAnimationEnded = false;
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
private int readWithDate = 0;
|
|
|
|
private int readWithMid = 0;
|
2014-06-04 01:31:48 +02:00
|
|
|
private boolean scrollToTopOnResume = false;
|
2013-12-20 20:25:49 +01:00
|
|
|
private boolean scrollToTopUnReadOnResume = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
private long dialog_id;
|
2014-10-20 13:30:05 +02:00
|
|
|
private boolean isBroadcast = false;
|
2015-01-02 23:15:07 +01:00
|
|
|
private HashMap<Integer, MessageObject> selectedMessagesIds = new HashMap<>();
|
|
|
|
private HashMap<Integer, MessageObject> selectedMessagesCanCopyIds = new HashMap<>();
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private HashMap<Integer, MessageObject> messagesDict = new HashMap<>();
|
|
|
|
private HashMap<String, ArrayList<MessageObject>> messagesByDays = new HashMap<>();
|
2015-05-03 13:48:36 +02:00
|
|
|
protected ArrayList<MessageObject> messages = new ArrayList<>();
|
2013-10-25 17:19:00 +02:00
|
|
|
private int maxMessageId = Integer.MAX_VALUE;
|
2013-12-20 20:25:49 +01:00
|
|
|
private int minMessageId = Integer.MIN_VALUE;
|
2013-10-25 17:19:00 +02:00
|
|
|
private int maxDate = Integer.MIN_VALUE;
|
|
|
|
private boolean endReached = false;
|
|
|
|
private boolean loading = false;
|
|
|
|
private boolean cacheEndReaced = false;
|
2014-08-02 01:31:15 +02:00
|
|
|
private boolean firstLoading = true;
|
2014-09-24 04:17:27 +02:00
|
|
|
private int loadsCount = 0;
|
2014-11-19 02:23:46 +01:00
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
private int startLoadFromMessageId = 0;
|
2015-03-26 18:34:47 +01:00
|
|
|
private boolean needSelectFromMessageId;
|
|
|
|
private int returnToMessageId = 0;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private int minDate = 0;
|
2014-08-02 01:31:15 +02:00
|
|
|
private boolean first = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
private int unread_to_load = 0;
|
|
|
|
private int first_unread_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
private int last_message_id = 0;
|
2014-11-19 02:23:46 +01:00
|
|
|
private int first_message_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
private boolean forward_end_reached = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
private boolean loadingForward = false;
|
|
|
|
private MessageObject unreadMessageObject = null;
|
2014-10-31 20:02:29 +01:00
|
|
|
private MessageObject scrollToMessage = null;
|
2014-11-18 06:01:04 +01:00
|
|
|
private int highlightMessageId = Integer.MAX_VALUE;
|
|
|
|
private boolean scrollToMessageMiddleScreen = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
private String currentPicturePath;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private Rect scrollRect = new Rect();
|
|
|
|
|
|
|
|
protected TLRPC.ChatParticipants info = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
private int onlineCount = -1;
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private HashMap<Integer, TLRPC.BotInfo> botInfo = new HashMap<>();
|
|
|
|
private String botUser;
|
|
|
|
private MessageObject botButtons;
|
|
|
|
private MessageObject botReplyButtons;
|
|
|
|
private int botsCount;
|
|
|
|
private boolean hasBotsCommands;
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
private CharSequence lastPrintString;
|
2014-11-19 16:17:24 +01:00
|
|
|
private String lastStatus;
|
2015-05-03 13:48:36 +02:00
|
|
|
private int lastStatusDrawable;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-04-04 19:58:33 +02:00
|
|
|
private long chatEnterTime = 0;
|
|
|
|
private long chatLeaveTime = 0;
|
|
|
|
|
2014-10-01 00:36:18 +02:00
|
|
|
private String startVideoEdit = null;
|
|
|
|
|
2014-10-09 17:55:05 +02:00
|
|
|
private Runnable openSecretPhotoRunnable = null;
|
2014-10-10 19:16:39 +02:00
|
|
|
private float startX = 0;
|
|
|
|
private float startY = 0;
|
2014-10-09 17:55:05 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private final static int copy = 10;
|
|
|
|
private final static int forward = 11;
|
|
|
|
private final static int delete = 12;
|
|
|
|
private final static int chat_enc_timer = 13;
|
|
|
|
private final static int chat_menu_attach = 14;
|
|
|
|
private final static int clear_history = 15;
|
|
|
|
private final static int delete_chat = 16;
|
|
|
|
private final static int share_contact = 17;
|
|
|
|
private final static int mute = 18;
|
|
|
|
private final static int reply = 19;
|
|
|
|
|
|
|
|
private final static int bot_help = 30;
|
|
|
|
private final static int bot_settings = 31;
|
|
|
|
|
|
|
|
private final static int attach_photo = 0;
|
|
|
|
private final static int attach_gallery = 1;
|
|
|
|
private final static int attach_video = 2;
|
|
|
|
private final static int attach_audio = 3;
|
|
|
|
private final static int attach_document = 4;
|
|
|
|
private final static int attach_contact = 5;
|
|
|
|
private final static int attach_location = 6;
|
|
|
|
|
|
|
|
private final static int search = 40;
|
|
|
|
private final static int search_up = 41;
|
|
|
|
private final static int search_down = 42;
|
|
|
|
|
2014-04-02 19:36:57 +02:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private final static int id_chat_compose_panel = 1000;
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
RecyclerListView.OnItemLongClickListener onItemLongClickListener = new RecyclerListView.OnItemLongClickListener() {
|
2014-10-10 19:16:39 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onItemClick(View view, int position) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (!actionBar.isActionModeShowed()) {
|
2014-10-10 19:16:39 +02:00
|
|
|
createMenu(view, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
RecyclerListView.OnItemClickListener onItemClickListener = new RecyclerListView.OnItemClickListener() {
|
2014-10-10 19:16:39 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onItemClick(View view, int position) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar.isActionModeShowed()) {
|
2014-10-10 19:16:39 +02:00
|
|
|
processRowSelect(view);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
createMenu(view, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public ChatActivity(Bundle args) {
|
|
|
|
super(args);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2014-06-04 01:31:48 +02:00
|
|
|
final int chatId = arguments.getInt("chat_id", 0);
|
|
|
|
final int userId = arguments.getInt("user_id", 0);
|
|
|
|
final int encId = arguments.getInt("enc_id", 0);
|
2014-10-31 20:02:29 +01:00
|
|
|
startLoadFromMessageId = arguments.getInt("message_id", 0);
|
2014-06-04 01:31:48 +02:00
|
|
|
scrollToTopOnResume = arguments.getBoolean("scrollToTopOnResume", false);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
if (chatId != 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
currentChat = MessagesController.getInstance().getChat(chatId);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentChat == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentChat = MessagesStorage.getInstance().getChat(chatId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentChat != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putChat(currentChat, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-07-27 00:28:33 +02:00
|
|
|
if (chatId > 0) {
|
|
|
|
dialog_id = -chatId;
|
|
|
|
} else {
|
2014-10-20 13:30:05 +02:00
|
|
|
isBroadcast = true;
|
2014-07-27 12:53:00 +02:00
|
|
|
dialog_id = AndroidUtilities.makeBroadcastId(chatId);
|
2014-07-27 00:28:33 +02:00
|
|
|
}
|
2014-08-08 12:17:06 +02:00
|
|
|
Semaphore semaphore = null;
|
2014-10-20 13:30:05 +02:00
|
|
|
if (isBroadcast) {
|
2014-08-08 12:17:06 +02:00
|
|
|
semaphore = new Semaphore(0);
|
|
|
|
}
|
|
|
|
MessagesController.getInstance().loadChatInfo(currentChat.id, semaphore);
|
2014-10-20 13:30:05 +02:00
|
|
|
if (isBroadcast) {
|
2014-08-08 12:17:06 +02:00
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (userId != 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
currentUser = MessagesController.getInstance().getUser(userId);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentUser = MessagesStorage.getInstance().getUser(userId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putUser(currentUser, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
dialog_id = userId;
|
2015-06-29 19:12:11 +02:00
|
|
|
botUser = arguments.getString("botUser");
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (encId != 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
currentEncryptedChat = MessagesController.getInstance().getEncryptedChat(encId);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentEncryptedChat = MessagesStorage.getInstance().getEncryptedChat(encId);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putEncryptedChat(currentEncryptedChat, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
currentUser = MessagesController.getInstance().getUser(currentEncryptedChat.user_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser == null) {
|
2014-03-26 21:16:28 +01:00
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
2014-10-31 20:02:29 +01:00
|
|
|
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
currentUser = MessagesStorage.getInstance().getUser(currentEncryptedChat.user_id);
|
|
|
|
semaphore.release();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
semaphore.acquire();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
MessagesController.getInstance().putUser(currentUser, true);
|
2014-03-26 21:16:28 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
dialog_id = ((long) encId) << 32;
|
2014-03-22 23:31:55 +01:00
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
2013-12-20 20:25:49 +01:00
|
|
|
minMessageId = Integer.MAX_VALUE;
|
2014-04-04 19:58:33 +02:00
|
|
|
MediaController.getInstance().startMediaObserver();
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-19 02:23:46 +01:00
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
|
2014-09-14 01:40:36 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesRead);
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageSendError);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatUpdated);
|
2015-05-03 13:48:36 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesReadEncrypted);
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.removeAllMessagesFromDialog);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
|
2015-07-22 20:56:37 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenshotTook);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded);
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileNewChunkAvailable);
|
2014-10-10 19:16:39 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didCreatedNewDeleteTask);
|
2014-10-21 22:35:16 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidStarted);
|
2015-01-02 23:15:07 +01:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateMessageMedia);
|
2015-01-09 13:50:15 +01:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.replaceMessagesObjects);
|
2015-02-01 19:51:02 +01:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated);
|
2015-03-19 00:09:45 +01:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didLoadedReplyMessages);
|
2015-04-09 20:00:14 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedWebpages);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedWebpagesInUpdates);
|
2015-05-03 13:48:36 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesReadContent);
|
2015-06-29 19:12:11 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.botInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.botKeyboardDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatSearchResultsAvailable);
|
2014-03-22 23:31:55 +01:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
super.onFragmentCreate();
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (currentEncryptedChat == null && !isBroadcast) {
|
|
|
|
BotQuery.loadBotKeyboard(dialog_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userId != 0 && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
BotQuery.loadBotInfo(userId, true, classGuid);
|
|
|
|
} else if (info != null) {
|
|
|
|
for (int a = 0; a < info.participants.size(); a++) {
|
|
|
|
TLRPC.TL_chatParticipant participant = info.participants.get(a);
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
|
|
|
|
if (user != null && (user.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
BotQuery.loadBotInfo(user.id, true, classGuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
loading = true;
|
2014-10-08 22:22:22 +02:00
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (startLoadFromMessageId != 0) {
|
2015-03-26 18:34:47 +01:00
|
|
|
needSelectFromMessageId = true;
|
2014-11-19 02:23:46 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, true, 0, classGuid, 3, 0, 0, false);
|
2014-10-31 20:02:29 +01:00
|
|
|
} else {
|
2014-11-19 02:23:46 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, 0, true, 0, classGuid, 2, 0, 0, true);
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2014-10-08 22:22:22 +02:00
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
if (currentUser != null) {
|
|
|
|
userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
typingDotsDrawable = new TypingDotsDrawable();
|
|
|
|
typingDotsDrawable.setIsChat(currentChat != null);
|
2015-05-03 13:48:36 +02:00
|
|
|
recordStatusDrawable = new RecordStatusDrawable();
|
|
|
|
recordStatusDrawable.setIsChat(currentChat != null);
|
|
|
|
sendingFileDrawable = new SendingFileExDrawable();
|
|
|
|
sendingFileDrawable.setIsChat(currentChat != null);
|
2014-09-24 04:17:27 +02:00
|
|
|
|
2014-12-01 18:56:31 +01:00
|
|
|
if (currentEncryptedChat != null && AndroidUtilities.getMyLayerVersion(currentEncryptedChat.layer) != SecretChatHelper.CURRENT_SECRET_CHAT_LAYER) {
|
|
|
|
SecretChatHelper.getInstance().sendNotifyLayerMessage(currentEncryptedChat, null);
|
2014-10-14 22:36:15 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-07-03 00:39:05 +02:00
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.onDestroy();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
|
2014-09-14 01:40:36 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesRead);
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageSendError);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatUpdated);
|
2015-05-03 13:48:36 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesReadEncrypted);
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.removeAllMessagesFromDialog);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioProgressDidChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidReset);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.screenshotTook);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.blockedUsersDidLoaded);
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileNewChunkAvailable);
|
2014-10-10 19:16:39 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didCreatedNewDeleteTask);
|
2014-10-21 22:35:16 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidStarted);
|
2015-01-02 23:15:07 +01:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateMessageMedia);
|
2015-01-09 13:50:15 +01:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.replaceMessagesObjects);
|
2015-02-01 19:51:02 +01:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.notificationsSettingsUpdated);
|
2015-03-19 00:09:45 +01:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didLoadedReplyMessages);
|
2015-04-09 20:00:14 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedWebpages);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedWebpagesInUpdates);
|
2015-05-03 13:48:36 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesReadContent);
|
2015-06-29 19:12:11 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botInfoDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botKeyboardDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatSearchResultsAvailable);
|
2015-07-22 20:56:37 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioPlayStateChanged);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-09-30 00:48:11 +02:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, true);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-04-04 19:58:33 +02:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
MediaController.getInstance().stopMediaObserver();
|
|
|
|
}
|
2014-11-19 11:32:27 +01:00
|
|
|
if (currentUser != null) {
|
|
|
|
MessagesController.getInstance().cancelLoadFullUser(currentUser.id);
|
|
|
|
}
|
2014-11-20 15:45:33 +01:00
|
|
|
if (!AndroidUtilities.isTablet() && getParentActivity() != null) {
|
2014-11-17 03:44:57 +01:00
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (stickersAdapter != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
stickersAdapter.onDestroy();
|
|
|
|
}
|
|
|
|
if (chatAttachView != null) {
|
|
|
|
chatAttachView.onDestroy();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
AndroidUtilities.unlockOrientation(getParentActivity());
|
2015-07-22 20:56:37 +02:00
|
|
|
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
|
|
|
|
if (messageObject != null && !messageObject.isMusic()) {
|
|
|
|
MediaController.getInstance().stopAudio();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
for (int a = 0; a < 8; a++) {
|
|
|
|
chatMessageCellsCache.add(new ChatMessageCell(context));
|
|
|
|
}
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
chatMediaCellsCache.add(new ChatMediaCell(context));
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
lastPrintString = null;
|
|
|
|
lastStatus = null;
|
|
|
|
hasOwnBackground = true;
|
2015-06-29 19:12:11 +02:00
|
|
|
chatAttachView = null;
|
2015-07-22 20:56:37 +02:00
|
|
|
chatAttachViewSheet = null;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
ResourceLoader.loadRecources(context);
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(final int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
|
|
|
} else if (id == -2) {
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBar.hideActionMode();
|
|
|
|
updateVisibleRows();
|
|
|
|
} else if (id == copy) {
|
|
|
|
String str = "";
|
|
|
|
ArrayList<Integer> ids = new ArrayList<>(selectedMessagesCanCopyIds.keySet());
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
Collections.sort(ids);
|
|
|
|
} else {
|
|
|
|
Collections.sort(ids, Collections.reverseOrder());
|
|
|
|
}
|
|
|
|
for (Integer messageId : ids) {
|
|
|
|
MessageObject messageObject = selectedMessagesCanCopyIds.get(messageId);
|
2014-06-04 01:31:48 +02:00
|
|
|
if (str.length() != 0) {
|
2015-04-09 20:00:14 +02:00
|
|
|
str += "\n";
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (messageObject.messageOwner.message != null) {
|
|
|
|
str += messageObject.messageOwner.message;
|
|
|
|
} else {
|
|
|
|
str += messageObject.messageText;
|
2014-11-18 13:37:11 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
if (str.length() != 0) {
|
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(str);
|
|
|
|
} else {
|
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", str);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBar.hideActionMode();
|
|
|
|
updateVisibleRows();
|
|
|
|
} else if (id == delete) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("messages", selectedMessagesIds.size())));
|
|
|
|
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) {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<>(selectedMessagesIds.keySet());
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
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);
|
2014-11-18 13:37:11 +01:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
|
|
|
|
actionBar.hideActionMode();
|
2014-11-19 02:23:46 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == forward) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
2015-06-29 19:12:11 +02:00
|
|
|
args.putInt("dialogsType", 1);
|
2015-07-22 20:56:37 +02:00
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
2015-04-09 20:00:14 +02:00
|
|
|
fragment.setDelegate(ChatActivity.this);
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (id == chat_enc_timer) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat).create());
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == clear_history || id == delete_chat) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final boolean isChat = (int) dialog_id < 0 && (int) (dialog_id >> 32) != 1;
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
if (id == clear_history) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory));
|
|
|
|
} else {
|
|
|
|
if (isChat) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
|
2014-11-17 03:44:57 +01:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (id != clear_history) {
|
|
|
|
if (isChat) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) {
|
|
|
|
MessagesController.getInstance().deleteDialog(dialog_id, 0, false);
|
|
|
|
} else {
|
|
|
|
MessagesController.getInstance().deleteUserFromChat((int) -dialog_id, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), null);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
MessagesController.getInstance().deleteDialog(dialog_id, 0, false);
|
|
|
|
}
|
|
|
|
finishFragment();
|
2014-11-17 03:44:57 +01:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
MessagesController.getInstance().deleteDialog(dialog_id, 0, true);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == share_contact) {
|
|
|
|
if (currentUser == null || getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentUser.phone != null && currentUser.phone.length() != 0) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", currentUser.id);
|
|
|
|
args.putBoolean("addContact", true);
|
|
|
|
presentFragment(new ContactAddActivity(args));
|
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureShareMyContactInfo", R.string.AreYouSureShareMyContactInfo));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2014-11-17 03:44:57 +01:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2015-04-09 20:00:14 +02:00
|
|
|
SendMessagesHelper.getInstance().sendMessage(UserConfig.getCurrentUser(), dialog_id, replyingMessageObject);
|
|
|
|
moveScrollToLastMessage();
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
} else if (id == mute) {
|
|
|
|
boolean muted = MessagesController.getInstance().isDialogMuted(dialog_id);
|
|
|
|
if (!muted) {
|
2015-06-29 19:12:11 +02:00
|
|
|
showDialog(AlertsCreator.createMuteAlert(getParentActivity(), dialog_id));
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("notify2_" + dialog_id, 0);
|
|
|
|
MessagesStorage.getInstance().setDialogFlags(dialog_id, 0);
|
|
|
|
editor.commit();
|
|
|
|
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
|
|
|
|
if (dialog != null) {
|
|
|
|
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
NotificationsController.updateServerNotificationsSettings(dialog_id);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == reply) {
|
|
|
|
if (selectedMessagesIds.size() == 1) {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<>(selectedMessagesIds.keySet());
|
|
|
|
MessageObject messageObject = messagesDict.get(ids.get(0));
|
|
|
|
if (messageObject != null && messageObject.messageOwner.id > 0) {
|
|
|
|
showReplyPanel(true, messageObject, null, null, false, true);
|
2014-11-14 16:40:15 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
actionBar.hideActionMode();
|
|
|
|
updateVisibleRows();
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (id == chat_menu_attach) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (chatAttachView == null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
|
2015-06-29 19:12:11 +02:00
|
|
|
chatAttachView = new ChatAttachView(getParentActivity());
|
|
|
|
chatAttachView.setDelegate(new ChatAttachView.ChatAttachViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didPressedButton(int button) {
|
|
|
|
if (button == 7) {
|
2015-07-22 20:56:37 +02:00
|
|
|
chatAttachViewSheet.dismiss();
|
2015-06-29 19:12:11 +02:00
|
|
|
HashMap<Integer, MediaController.PhotoEntry> selectedPhotos = chatAttachView.getSelectedPhotos();
|
|
|
|
if (!selectedPhotos.isEmpty()) {
|
|
|
|
ArrayList<String> photos = new ArrayList<>();
|
|
|
|
ArrayList<String> captions = new ArrayList<>();
|
|
|
|
for (HashMap.Entry<Integer, MediaController.PhotoEntry> entry : selectedPhotos.entrySet()) {
|
|
|
|
photos.add(entry.getValue().path);
|
|
|
|
captions.add("");
|
|
|
|
}
|
|
|
|
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject, captions);
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
return;
|
2015-07-22 20:56:37 +02:00
|
|
|
} else {
|
|
|
|
chatAttachViewSheet.dismissWithButtonClick(button);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
processSelectedAttach(button);
|
|
|
|
}
|
|
|
|
});
|
2015-07-22 20:56:37 +02:00
|
|
|
builder.setDelegate(new BottomSheet.BottomSheetDelegate() {
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
@Override
|
|
|
|
public void onRevealAnimationStart(boolean open) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (chatAttachView != null) {
|
|
|
|
chatAttachView.onRevealAnimationStart(open);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRevealAnimationProgress(boolean open, float radius, int x, int y) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (chatAttachView != null) {
|
|
|
|
chatAttachView.onRevealAnimationProgress(open, radius, x, y);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRevealAnimationEnd(boolean open) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (chatAttachView != null) {
|
|
|
|
chatAttachView.onRevealAnimationEnd(open);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOpenAnimationEnd() {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (chatAttachView != null) {
|
|
|
|
chatAttachView.onRevealAnimationEnd(true);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getRevealView() {
|
|
|
|
return menuItem;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setApplyTopPaddings(false);
|
|
|
|
builder.setUseRevealAnimation();
|
|
|
|
builder.setCustomView(chatAttachView);
|
|
|
|
chatAttachViewSheet = builder.create();
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
chatAttachView.init(ChatActivity.this);
|
2015-07-22 20:56:37 +02:00
|
|
|
showDialog(chatAttachViewSheet);
|
|
|
|
}/* else if (id == attach_gallery || id == attach_video || id == attach_document || id == attach_location || id == attach_photo || id == attach_audio || id == attach_contact) {
|
2015-06-29 19:12:11 +02:00
|
|
|
processSelectedAttach(id);
|
2015-07-22 20:56:37 +02:00
|
|
|
} */else if (id == bot_help) {
|
2015-06-29 19:12:11 +02:00
|
|
|
SendMessagesHelper.getInstance().sendMessage("/help", dialog_id, null, null, false);
|
|
|
|
} else if (id == bot_settings) {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage("/settings", dialog_id, null, null, false);
|
|
|
|
} else if (id == search) {
|
|
|
|
avatarContainer.setVisibility(View.GONE);
|
|
|
|
headerItem.setVisibility(View.GONE);
|
|
|
|
attachItem.setVisibility(View.GONE);
|
|
|
|
searchItem.setVisibility(View.VISIBLE);
|
|
|
|
searchUpItem.setVisibility(View.VISIBLE);
|
|
|
|
searchDownItem.setVisibility(View.VISIBLE);
|
|
|
|
updateSearchButtons(0);
|
|
|
|
//chatActivityEnterView.setVisibility(View.GONE);
|
|
|
|
searchItem.openSearch();
|
|
|
|
} else if (id == search_up) {
|
|
|
|
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, classGuid, 1);
|
|
|
|
} else if (id == search_down) {
|
|
|
|
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, classGuid, 2);
|
2014-11-17 23:04:31 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2014-11-17 23:04:31 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
avatarContainer = new FrameLayoutFixed(context);
|
|
|
|
avatarContainer.setBackgroundResource(R.drawable.bar_selector);
|
|
|
|
avatarContainer.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
|
2015-05-03 13:48:36 +02:00
|
|
|
actionBar.addView(avatarContainer, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
avatarContainer.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (currentUser != null) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", currentUser.id);
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
args.putLong("dialog_id", dialog_id);
|
2014-11-19 16:17:24 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
presentFragment(new ProfileActivity(args));
|
|
|
|
} else if (currentChat != null) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("chat_id", currentChat.id);
|
|
|
|
ProfileActivity fragment = new ProfileActivity(args);
|
|
|
|
fragment.setChatInfo(info);
|
|
|
|
presentFragment(fragment);
|
|
|
|
}
|
2014-11-19 16:17:24 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2014-11-19 16:17:24 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentChat != null) {
|
|
|
|
int count = currentChat.participants_count;
|
|
|
|
if (info != null) {
|
|
|
|
count = info.participants.size();
|
2014-11-19 16:17:24 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden || info != null && info instanceof TLRPC.TL_chatParticipantsForbidden) {
|
|
|
|
avatarContainer.setEnabled(false);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
avatarImageView = new BackupImageView(context);
|
|
|
|
avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
|
2015-05-03 13:48:36 +02:00
|
|
|
avatarContainer.addView(avatarImageView, LayoutHelper.createFrame(42, 42, Gravity.TOP | Gravity.LEFT, 0, 3, 0, 0));
|
2014-11-19 02:23:46 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
timeItem = new ImageView(context);
|
|
|
|
timeItem.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(5), AndroidUtilities.dp(5));
|
|
|
|
timeItem.setScaleType(ImageView.ScaleType.CENTER);
|
2015-05-03 13:48:36 +02:00
|
|
|
timeItem.setImageDrawable(timerDrawable = new TimerDrawable(context));
|
|
|
|
avatarContainer.addView(timeItem, LayoutHelper.createFrame(34, 34, Gravity.TOP | Gravity.LEFT, 16, 18, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
timeItem.setOnClickListener(new View.OnClickListener() {
|
2014-07-10 02:15:58 +02:00
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void onClick(View v) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat).create());
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
});
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
nameTextView = new TextView(context);
|
|
|
|
nameTextView.setTextColor(0xffffffff);
|
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
nameTextView.setLines(1);
|
|
|
|
nameTextView.setMaxLines(1);
|
|
|
|
nameTextView.setSingleLine(true);
|
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
nameTextView.setGravity(Gravity.LEFT);
|
|
|
|
nameTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
|
|
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2015-05-03 13:48:36 +02:00
|
|
|
avatarContainer.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM, 54, 0, 0, 22));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
onlineTextView = new TextView(context);
|
|
|
|
onlineTextView.setTextColor(0xffd7e8f7);
|
|
|
|
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
onlineTextView.setLines(1);
|
|
|
|
onlineTextView.setMaxLines(1);
|
|
|
|
onlineTextView.setSingleLine(true);
|
|
|
|
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
onlineTextView.setGravity(Gravity.LEFT);
|
2015-05-03 13:48:36 +02:00
|
|
|
avatarContainer.addView(onlineTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM, 54, 0, 0, 4));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (currentEncryptedChat == null && !isBroadcast) {
|
2015-07-22 20:56:37 +02:00
|
|
|
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true, false).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSearchCollapse() {
|
|
|
|
avatarContainer.setVisibility(View.VISIBLE);
|
2015-07-22 20:56:37 +02:00
|
|
|
if (chatActivityEnterView.hasText()) {
|
|
|
|
if (headerItem != null) {
|
|
|
|
headerItem.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (attachItem != null) {
|
|
|
|
attachItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (headerItem != null) {
|
|
|
|
headerItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
if (attachItem != null) {
|
|
|
|
attachItem.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
searchItem.setVisibility(View.GONE);
|
|
|
|
//chatActivityEnterView.setVisibility(View.VISIBLE);
|
|
|
|
searchUpItem.clearAnimation();
|
|
|
|
searchDownItem.clearAnimation();
|
|
|
|
searchUpItem.setVisibility(View.GONE);
|
|
|
|
searchDownItem.setVisibility(View.GONE);
|
|
|
|
scrollToLastMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSearchExpand() {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
searchItem.getSearchField().requestFocus();
|
|
|
|
AndroidUtilities.showKeyboard(searchItem.getSearchField());
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}, 300); //TODO find a better way to open keyboard
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSearchPressed(EditText editText) {
|
|
|
|
updateSearchButtons(0);
|
|
|
|
MessagesSearchQuery.searchMessagesInChat(editText.getText().toString(), dialog_id, classGuid, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
|
|
|
|
searchItem.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
searchUpItem = menu.addItem(search_up, R.drawable.search_up);
|
|
|
|
searchUpItem.setVisibility(View.GONE);
|
|
|
|
searchDownItem = menu.addItem(search_down, R.drawable.search_down);
|
2015-07-22 20:56:37 +02:00
|
|
|
searchDownItem.setVisibility(View.GONE);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
headerItem = menu.addItem(0, R.drawable.ic_ab_other);
|
2015-06-29 19:12:11 +02:00
|
|
|
if (searchItem != null) {
|
|
|
|
headerItem.addSubItem(search, LocaleController.getString("Search", R.string.Search), 0);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentUser != null) {
|
|
|
|
addContactItem = headerItem.addSubItem(share_contact, "", 0);
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
timeItem2 = headerItem.addSubItem(chat_enc_timer, LocaleController.getString("SetTimer", R.string.SetTimer), 0);
|
|
|
|
}
|
|
|
|
headerItem.addSubItem(clear_history, LocaleController.getString("ClearHistory", R.string.ClearHistory), 0);
|
|
|
|
if (currentChat != null && !isBroadcast) {
|
|
|
|
headerItem.addSubItem(delete_chat, LocaleController.getString("DeleteAndExit", R.string.DeleteAndExit), 0);
|
|
|
|
} else {
|
|
|
|
headerItem.addSubItem(delete_chat, LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser), 0);
|
|
|
|
}
|
|
|
|
muteItem = headerItem.addSubItem(mute, null, 0);
|
2015-06-29 19:12:11 +02:00
|
|
|
if (currentUser != null && currentEncryptedChat == null && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
headerItem.addSubItem(bot_settings, LocaleController.getString("BotSettings", R.string.BotSettings), 0);
|
|
|
|
headerItem.addSubItem(bot_help, LocaleController.getString("BotHelp", R.string.BotHelp), 0);
|
|
|
|
updateBotButtons();
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
updateTitle();
|
|
|
|
updateSubtitle();
|
|
|
|
updateTitleIcons();
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
attachItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_other).setOverrideMenuClick(true).setAllowCloseAnimation(false);
|
2015-06-29 19:12:11 +02:00
|
|
|
attachItem.setVisibility(View.GONE);
|
|
|
|
menuItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach).setAllowCloseAnimation(false);
|
2015-04-09 20:00:14 +02:00
|
|
|
menuItem.setBackgroundDrawable(null);
|
|
|
|
|
|
|
|
actionModeViews.clear();
|
|
|
|
|
|
|
|
final ActionBarMenu actionMode = actionBar.createActionMode();
|
|
|
|
actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_back_grey, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
|
|
|
|
|
|
|
|
selectedMessagesCountTextView = new TextView(actionMode.getContext());
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
|
|
|
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
selectedMessagesCountTextView.setTextColor(0xff737373);
|
|
|
|
selectedMessagesCountTextView.setSingleLine(true);
|
|
|
|
selectedMessagesCountTextView.setLines(1);
|
|
|
|
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, AndroidUtilities.dp(2));
|
|
|
|
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
|
2015-05-03 13:48:36 +02:00
|
|
|
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f));
|
2015-04-09 20:00:14 +02:00
|
|
|
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
|
|
|
|
if (!isBroadcast) {
|
|
|
|
actionModeViews.add(actionMode.addItem(reply, R.drawable.ic_ab_reply, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
actionModeViews.add(actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
|
|
|
|
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
|
|
|
|
} else {
|
|
|
|
actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
|
|
|
|
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
|
|
|
|
}
|
|
|
|
actionMode.getItem(copy).setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE);
|
|
|
|
if (actionMode.getItem(reply) != null) {
|
|
|
|
actionMode.getItem(reply).setVisibility(selectedMessagesIds.size() == 1 ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
checkActionBarMenu();
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
fragmentView = new SizeNotifierFrameLayout(context) {
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
int inputFieldHeight = 0;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2015-05-21 23:27:27 +02:00
|
|
|
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
|
|
|
|
setMeasuredDimension(widthSize, heightSize);
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
int keyboardSize = getKeyboardHeight();
|
|
|
|
|
|
|
|
if (keyboardSize <= AndroidUtilities.dp(20)) {
|
|
|
|
heightSize -= chatActivityEnterView.getEmojiPadding();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
int childCount = getChildCount();
|
2015-07-22 20:56:37 +02:00
|
|
|
|
|
|
|
measureChildWithMargins(chatActivityEnterView, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
inputFieldHeight = chatActivityEnterView.getMeasuredHeight();
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
View child = getChildAt(i);
|
|
|
|
if (child.getVisibility() == GONE || child == chatActivityEnterView) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (child == chatListView || child == progressView) {
|
2015-05-21 23:27:27 +02:00
|
|
|
int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
|
|
|
|
int contentHeightSpec = MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), heightSize - inputFieldHeight + AndroidUtilities.dp(2)), MeasureSpec.EXACTLY);
|
|
|
|
child.measure(contentWidthSpec, contentHeightSpec);
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (child == emptyViewContainer) {
|
|
|
|
int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
|
|
|
|
int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
|
|
|
|
child.measure(contentWidthSpec, contentHeightSpec);
|
|
|
|
} else if (chatActivityEnterView.isPopupView(child)) {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
|
2015-05-21 23:27:27 +02:00
|
|
|
} else {
|
|
|
|
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
final int count = getChildCount();
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
int paddingBottom = getKeyboardHeight() <= AndroidUtilities.dp(20) ? chatActivityEnterView.getEmojiPadding() : 0;
|
|
|
|
setBottomClip(paddingBottom);
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
final View child = getChildAt(i);
|
|
|
|
if (child.getVisibility() == GONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
|
|
|
|
|
|
|
final int width = child.getMeasuredWidth();
|
|
|
|
final int height = child.getMeasuredHeight();
|
|
|
|
|
|
|
|
int childLeft;
|
|
|
|
int childTop;
|
|
|
|
|
|
|
|
int gravity = lp.gravity;
|
|
|
|
if (gravity == -1) {
|
|
|
|
gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
|
|
|
|
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
|
|
|
|
|
|
|
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
|
|
|
|
case Gravity.CENTER_HORIZONTAL:
|
|
|
|
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.RIGHT:
|
|
|
|
childLeft = r - width - lp.rightMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.LEFT:
|
|
|
|
default:
|
|
|
|
childLeft = lp.leftMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (verticalGravity) {
|
|
|
|
case Gravity.TOP:
|
|
|
|
childTop = lp.topMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.CENTER_VERTICAL:
|
2015-06-29 19:12:11 +02:00
|
|
|
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
|
2015-05-21 23:27:27 +02:00
|
|
|
break;
|
|
|
|
case Gravity.BOTTOM:
|
2015-06-29 19:12:11 +02:00
|
|
|
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
|
2015-05-21 23:27:27 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
childTop = lp.topMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child == mentionListView) {
|
|
|
|
childTop -= chatActivityEnterView.getMeasuredHeight() - AndroidUtilities.dp(2);
|
|
|
|
} else if (child == pagedownButton) {
|
|
|
|
childTop -= chatActivityEnterView.getMeasuredHeight();
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (child == emptyViewContainer) {
|
|
|
|
childTop -= inputFieldHeight / 2;
|
|
|
|
} else if (chatActivityEnterView.isPopupView(child)) {
|
|
|
|
childTop = chatActivityEnterView.getBottom();
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
child.layout(childLeft, childTop, childLeft + width, childTop + height);
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyHeightChanged();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
SizeNotifierFrameLayout contentView = (SizeNotifierFrameLayout) fragmentView;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
contentView.setBackgroundImage(ApplicationLoader.getCachedWallpaper());
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
emptyViewContainer = new FrameLayout(context);
|
|
|
|
emptyViewContainer.setVisibility(View.INVISIBLE);
|
2015-06-29 19:12:11 +02:00
|
|
|
contentView.addView(emptyViewContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
2015-04-09 20:00:14 +02:00
|
|
|
emptyViewContainer.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
TextView emptyView = new TextView(context);
|
2015-05-21 23:27:27 +02:00
|
|
|
if (currentUser != null && currentUser.id != 777000 && currentUser.id != 429000 && (currentUser.id / 1000 == 333 || currentUser.id % 1000 == 0)) {
|
2015-04-09 20:00:14 +02:00
|
|
|
emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion));
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages));
|
|
|
|
}
|
|
|
|
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
emptyView.setGravity(Gravity.CENTER);
|
|
|
|
emptyView.setTextColor(0xffffffff);
|
|
|
|
emptyView.setBackgroundResource(ApplicationLoader.isCustomTheme() ? R.drawable.system_black : R.drawable.system_blue);
|
|
|
|
emptyView.setPadding(AndroidUtilities.dp(7), AndroidUtilities.dp(1), AndroidUtilities.dp(7), AndroidUtilities.dp(1));
|
2015-05-03 13:48:36 +02:00
|
|
|
emptyViewContainer.addView(emptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
LinearLayout secretChatPlaceholder = new LinearLayout(context);
|
|
|
|
secretChatPlaceholder.setBackgroundResource(ApplicationLoader.isCustomTheme() ? R.drawable.system_black : R.drawable.system_blue);
|
|
|
|
secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
|
|
|
|
secretChatPlaceholder.setOrientation(LinearLayout.VERTICAL);
|
2015-05-03 13:48:36 +02:00
|
|
|
emptyViewContainer.addView(secretChatPlaceholder, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
secretViewStatusTextView = new TextView(context);
|
|
|
|
secretViewStatusTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
|
|
|
secretViewStatusTextView.setTextColor(0xffffffff);
|
|
|
|
secretViewStatusTextView.setGravity(Gravity.CENTER_HORIZONTAL);
|
|
|
|
secretViewStatusTextView.setMaxWidth(AndroidUtilities.dp(210));
|
|
|
|
if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) {
|
2015-06-29 19:12:11 +02:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, UserObject.getFirstName(currentUser)));
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
secretViewStatusTextView.setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, UserObject.getFirstName(currentUser)));
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
secretChatPlaceholder.addView(secretViewStatusTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescriptionTitle", R.string.EncryptedDescriptionTitle));
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
|
|
|
textView.setTextColor(0xffffffff);
|
|
|
|
textView.setGravity(Gravity.CENTER_HORIZONTAL);
|
|
|
|
textView.setMaxWidth(AndroidUtilities.dp(260));
|
2015-05-03 13:48:36 +02:00
|
|
|
secretChatPlaceholder.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 0, 8, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
2015-05-03 13:48:36 +02:00
|
|
|
secretChatPlaceholder.addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 0, 8, 0, 0));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
ImageView imageView = new ImageView(context);
|
|
|
|
imageView.setImageResource(R.drawable.ic_lock_white);
|
|
|
|
|
|
|
|
textView = new TextView(context);
|
2015-02-26 02:32:51 +01:00
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
|
|
|
textView.setTextColor(0xffffffff);
|
2015-04-09 20:00:14 +02:00
|
|
|
textView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
|
2015-02-26 02:32:51 +01:00
|
|
|
textView.setMaxWidth(AndroidUtilities.dp(260));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
switch (a) {
|
|
|
|
case 0:
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription1", R.string.EncryptedDescription1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription2", R.string.EncryptedDescription2));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription3", R.string.EncryptedDescription3));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
textView.setText(LocaleController.getString("EncryptedDescription4", R.string.EncryptedDescription4));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LocaleController.isRTL) {
|
2015-05-03 13:48:36 +02:00
|
|
|
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
linearLayout.addView(imageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 8, 3, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
linearLayout.addView(imageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 4, 8, 0));
|
|
|
|
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.onDestroy();
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
chatListView = new RecyclerListView(context) {
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
super.onLayout(changed, l, t, r, b);
|
|
|
|
if (chatAdapter.isBot) {
|
|
|
|
int childCount = getChildCount();
|
|
|
|
for (int a = 0; a < childCount; a++) {
|
|
|
|
View child = getChildAt(a);
|
|
|
|
if (child instanceof BotHelpCell) {
|
|
|
|
int height = b - t;
|
|
|
|
int top = height / 2 - child.getMeasuredHeight() / 2;
|
|
|
|
if (child.getTop() > top) {
|
|
|
|
child.layout(0, top, r - l, top + child.getMeasuredHeight());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-05-21 23:27:27 +02:00
|
|
|
chatListView.setVerticalScrollBarEnabled(true);
|
2015-05-03 13:48:36 +02:00
|
|
|
chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context));
|
2015-04-09 20:00:14 +02:00
|
|
|
chatListView.setClipToPadding(false);
|
|
|
|
chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3));
|
2015-05-03 13:48:36 +02:00
|
|
|
chatListView.setItemAnimator(null);
|
|
|
|
chatListView.setLayoutAnimation(null);
|
|
|
|
chatLayoutManager = new LinearLayoutManager(context) {
|
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
chatLayoutManager.setStackFromEnd(true);
|
|
|
|
chatListView.setLayoutManager(chatLayoutManager);
|
2015-05-21 23:27:27 +02:00
|
|
|
contentView.addView(chatListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
chatListView.setOnItemLongClickListener(onItemLongClickListener);
|
|
|
|
chatListView.setOnItemClickListener(onItemClickListener);
|
2015-05-03 13:48:36 +02:00
|
|
|
chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
if (newState != RecyclerView.SCROLL_STATE_DRAGGING && highlightMessageId != Integer.MAX_VALUE) {
|
|
|
|
highlightMessageId = Integer.MAX_VALUE;
|
|
|
|
updateVisibleRows();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
int firstVisibleItem = chatLayoutManager.findFirstVisibleItemPosition();
|
2015-06-29 19:12:11 +02:00
|
|
|
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(chatLayoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (visibleItemCount > 0) {
|
|
|
|
int totalItemCount = chatAdapter.getItemCount();
|
|
|
|
if (firstVisibleItem <= 10) {
|
|
|
|
if (!endReached && !loading) {
|
|
|
|
if (messagesByDays.size() != 0) {
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 20, maxMessageId, !cacheEndReaced && startLoadFromMessageId == 0, minDate, classGuid, 0, 0, 0, startLoadFromMessageId == 0);
|
|
|
|
} else {
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 20, 0, !cacheEndReaced && startLoadFromMessageId == 0, minDate, classGuid, 0, 0, 0, startLoadFromMessageId == 0);
|
|
|
|
}
|
|
|
|
loading = true;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) {
|
|
|
|
if (!forward_end_reached && !loadingForward) {
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 20, minMessageId, startLoadFromMessageId == 0, maxDate, classGuid, 1, 0, 0, startLoadFromMessageId == 0);
|
|
|
|
loadingForward = true;
|
2014-10-10 19:16:39 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (firstVisibleItem + visibleItemCount == totalItemCount && forward_end_reached) {
|
|
|
|
showPagedownButton(false, true);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
updateMessagesVisisblePart();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
chatListView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
if (openSecretPhotoRunnable != null || SecretPhotoViewer.getInstance().isVisible()) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setOnItemClickListener(onItemClickListener);
|
|
|
|
}
|
|
|
|
}, 150);
|
|
|
|
if (openSecretPhotoRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable);
|
|
|
|
openSecretPhotoRunnable = null;
|
|
|
|
try {
|
|
|
|
Toast.makeText(v.getContext(), LocaleController.getString("PhotoTip", R.string.PhotoTip), Toast.LENGTH_SHORT).show();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
} else if (SecretPhotoViewer.getInstance().isVisible()) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
chatListView.setOnItemLongClickListener(onItemLongClickListener);
|
|
|
|
chatListView.setLongClickable(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
SecretPhotoViewer.getInstance().closePhoto();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
} else if (event.getAction() != MotionEvent.ACTION_DOWN) {
|
|
|
|
if (SecretPhotoViewer.getInstance().isVisible()) {
|
|
|
|
return true;
|
|
|
|
} else if (openSecretPhotoRunnable != null) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities.dp(5)) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable);
|
2014-10-10 19:16:39 +02:00
|
|
|
openSecretPhotoRunnable = null;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable);
|
|
|
|
openSecretPhotoRunnable = null;
|
2014-10-10 19:16:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2015-05-21 23:27:27 +02:00
|
|
|
chatListView.setOnInterceptTouchListener(new RecyclerListView.OnInterceptTouchListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
return false;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
int x = (int) event.getX();
|
|
|
|
int y = (int) event.getY();
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
int top = view.getTop();
|
|
|
|
int bottom = view.getBottom();
|
|
|
|
if (top > y || bottom < y) {
|
|
|
|
continue;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!(view instanceof ChatMediaCell)) {
|
|
|
|
break;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
final ChatMediaCell cell = (ChatMediaCell) view;
|
|
|
|
final MessageObject messageObject = cell.getMessageObject();
|
2015-05-21 23:27:27 +02:00
|
|
|
if (messageObject == null || messageObject.isSending() || !messageObject.isSecretPhoto() || !cell.getPhotoImage().isInsideImage(x, y - top)) {
|
2015-05-03 13:48:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
File file = FileLoader.getPathToMessage(messageObject.messageOwner);
|
|
|
|
if (!file.exists()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
startX = x;
|
|
|
|
startY = y;
|
|
|
|
chatListView.setOnItemClickListener(null);
|
|
|
|
openSecretPhotoRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (openSecretPhotoRunnable == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
chatListView.requestDisallowInterceptTouchEvent(true);
|
|
|
|
chatListView.setOnItemLongClickListener(null);
|
|
|
|
chatListView.setLongClickable(false);
|
|
|
|
openSecretPhotoRunnable = null;
|
|
|
|
if (sendSecretMessageRead(messageObject)) {
|
|
|
|
cell.invalidate();
|
|
|
|
}
|
|
|
|
SecretPhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
SecretPhotoViewer.getInstance().openPhoto(messageObject);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
AndroidUtilities.runOnUIThread(openSecretPhotoRunnable, 100);
|
|
|
|
return true;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
return false;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
progressView = new FrameLayout(context);
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
2015-06-29 19:12:11 +02:00
|
|
|
contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
View view = new View(context);
|
|
|
|
view.setBackgroundResource(ApplicationLoader.isCustomTheme() ? R.drawable.system_loader2 : R.drawable.system_loader1);
|
|
|
|
progressView.addView(view, LayoutHelper.createFrame(36, 36, Gravity.CENTER));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
ProgressBar progressBar = new ProgressBar(context);
|
|
|
|
try {
|
|
|
|
progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.loading_animation));
|
|
|
|
} catch (Exception e) {
|
|
|
|
//don't promt
|
|
|
|
}
|
|
|
|
progressBar.setIndeterminate(true);
|
|
|
|
AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500);
|
2015-05-03 13:48:36 +02:00
|
|
|
progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
if (currentEncryptedChat == null && !isBroadcast) {
|
|
|
|
mentionListView = new ListView(context);
|
|
|
|
mentionListView.setBackgroundResource(R.drawable.compose_panel);
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
mentionListView.setPadding(0, AndroidUtilities.dp(2), 0, 0);
|
|
|
|
mentionListView.setClipToPadding(true);
|
|
|
|
mentionListView.setDividerHeight(0);
|
|
|
|
mentionListView.setDivider(null);
|
|
|
|
if (Build.VERSION.SDK_INT > 8) {
|
|
|
|
mentionListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
contentView.addView(mentionListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(context, false, new MentionsAdapter.MentionsAdapterDelegate() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void needChangePanelVisibility(boolean show) {
|
|
|
|
if (show) {
|
2015-05-21 23:27:27 +02:00
|
|
|
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) mentionListView.getLayoutParams();
|
2015-04-09 20:00:14 +02:00
|
|
|
int height = 36 * Math.min(3, mentionsAdapter.getCount()) + (mentionsAdapter.getCount() > 3 ? 18 : 0);
|
|
|
|
layoutParams3.height = AndroidUtilities.dp(2 + height);
|
|
|
|
layoutParams3.topMargin = -AndroidUtilities.dp(height);
|
|
|
|
mentionListView.setLayoutParams(layoutParams3);
|
|
|
|
|
|
|
|
if (mentionListAnimation != null) {
|
|
|
|
mentionListAnimation.cancel();
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mentionListView.getVisibility() == View.VISIBLE) {
|
|
|
|
ViewProxy.setAlpha(mentionListView, 1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (allowStickersPanel) {
|
|
|
|
mentionListView.setVisibility(View.VISIBLE);
|
|
|
|
mentionListAnimation = new AnimatorSetProxy();
|
|
|
|
mentionListAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(mentionListView, "alpha", 0.0f, 1.0f)
|
|
|
|
);
|
|
|
|
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
mentionListAnimation.setDuration(200);
|
|
|
|
mentionListAnimation.start();
|
|
|
|
} else {
|
|
|
|
ViewProxy.setAlpha(mentionListView, 1.0f);
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.INVISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
if (mentionListAnimation != null) {
|
|
|
|
mentionListAnimation.cancel();
|
|
|
|
mentionListAnimation = null;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
if (mentionListView.getVisibility() == View.GONE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (allowStickersPanel) {
|
|
|
|
mentionListAnimation = new AnimatorSetProxy();
|
|
|
|
mentionListAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(mentionListView, "alpha", 0.0f)
|
|
|
|
);
|
|
|
|
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mentionListAnimation.setDuration(200);
|
|
|
|
mentionListAnimation.start();
|
|
|
|
} else {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}));
|
2015-06-29 19:12:11 +02:00
|
|
|
mentionsAdapter.setBotInfo(botInfo);
|
2015-04-09 20:00:14 +02:00
|
|
|
mentionsAdapter.setChatInfo(info);
|
|
|
|
mentionsAdapter.setNeedUsernames(currentChat != null);
|
2015-06-29 19:12:11 +02:00
|
|
|
mentionsAdapter.setBotsCount(currentChat != null ? botsCount : 1);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
mentionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
Object object = mentionsAdapter.getItem(position);
|
|
|
|
int start = mentionsAdapter.getResultStartPosition();
|
|
|
|
int len = mentionsAdapter.getResultLength();
|
|
|
|
if (object instanceof TLRPC.User) {
|
|
|
|
TLRPC.User user = (TLRPC.User) object;
|
|
|
|
if (user != null) {
|
|
|
|
chatActivityEnterView.replaceWithText(start, len, "@" + user.username + " ");
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (object instanceof String) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (mentionsAdapter.isBotCommands()) {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage((String) object, dialog_id, null, null, false);
|
|
|
|
chatActivityEnterView.setFieldText("");
|
|
|
|
} else {
|
|
|
|
chatActivityEnterView.replaceWithText(start, len, object + " ");
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
mentionListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (!mentionsAdapter.isLongClickEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
Object object = mentionsAdapter.getItem(position);
|
|
|
|
if (object instanceof String) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
mentionsAdapter.clearRecentHashtags();
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2015-04-09 20:00:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
chatActivityEnterView = new ChatActivityEnterView(getParentActivity(), contentView, this, true);
|
|
|
|
chatActivityEnterView.setDialogId(dialog_id);
|
|
|
|
chatActivityEnterView.addToAttachLayout(menuItem);
|
|
|
|
chatActivityEnterView.setId(id_chat_compose_panel);
|
2015-06-29 19:12:11 +02:00
|
|
|
chatActivityEnterView.setBotsCount(botsCount, hasBotsCommands);
|
2015-05-21 23:27:27 +02:00
|
|
|
contentView.addView(chatActivityEnterView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM));
|
2015-04-09 20:00:14 +02:00
|
|
|
chatActivityEnterView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onMessageSend(String message) {
|
|
|
|
moveScrollToLastMessage();
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
if (mentionsAdapter != null) {
|
|
|
|
mentionsAdapter.addHashtagsFromMessage(message);
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(final CharSequence text, boolean bigChange) {
|
|
|
|
if (stickersAdapter != null) {
|
|
|
|
stickersAdapter.loadStikersForEmoji(text);
|
|
|
|
}
|
|
|
|
if (mentionsAdapter != null) {
|
|
|
|
mentionsAdapter.searchUsernameOrHashtag(text.toString(), chatActivityEnterView.getCursorPosition(), messages);
|
|
|
|
}
|
|
|
|
if (waitingForCharaterEnterRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(waitingForCharaterEnterRunnable);
|
|
|
|
waitingForCharaterEnterRunnable = null;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (chatActivityEnterView.isMessageWebPageSearchEnabled()) {
|
|
|
|
if (bigChange) {
|
|
|
|
searchLinks(text, true);
|
|
|
|
} else {
|
|
|
|
waitingForCharaterEnterRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (this == waitingForCharaterEnterRunnable) {
|
|
|
|
searchLinks(text, false);
|
|
|
|
waitingForCharaterEnterRunnable = null;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
};
|
|
|
|
AndroidUtilities.runOnUIThread(waitingForCharaterEnterRunnable, 3000);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void needSendTyping() {
|
2015-05-03 13:48:36 +02:00
|
|
|
MessagesController.getInstance().sendTyping(dialog_id, 0, classGuid);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-03-26 18:34:47 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void onAttachButtonHidden() {
|
2015-07-22 20:56:37 +02:00
|
|
|
if (actionBar.isSearchFieldVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (attachItem != null) {
|
|
|
|
attachItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
if (headerItem != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
headerItem.setVisibility(View.GONE);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void onAttachButtonShow() {
|
2015-07-22 20:56:37 +02:00
|
|
|
if (actionBar.isSearchFieldVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (attachItem != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
attachItem.setVisibility(View.GONE);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
if (headerItem != null) {
|
|
|
|
headerItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onWindowSizeChanged(int size) {
|
2015-07-22 20:56:37 +02:00
|
|
|
if (size < AndroidUtilities.dp(72) + ActionBar.getCurrentActionBarHeight()) {
|
2015-04-09 20:00:14 +02:00
|
|
|
allowStickersPanel = false;
|
|
|
|
if (stickersPanel.getVisibility() == View.VISIBLE) {
|
|
|
|
stickersPanel.clearAnimation();
|
|
|
|
stickersPanel.setVisibility(View.INVISIBLE);
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (mentionListView != null && mentionListView.getVisibility() == View.VISIBLE) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.INVISIBLE);
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
allowStickersPanel = true;
|
|
|
|
if (stickersPanel.getVisibility() == View.INVISIBLE) {
|
|
|
|
stickersPanel.clearAnimation();
|
|
|
|
stickersPanel.setVisibility(View.VISIBLE);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (mentionListView != null && mentionListView.getVisibility() == View.INVISIBLE) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.VISIBLE);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
updateMessagesVisisblePart();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
FrameLayout replyLayout = new FrameLayout(context);
|
|
|
|
replyLayout.setClickable(true);
|
2015-06-29 19:12:11 +02:00
|
|
|
chatActivityEnterView.addTopView(replyLayout, 48);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
View lineView = new View(context);
|
|
|
|
lineView.setBackgroundColor(0xffe8e8e8);
|
2015-05-03 13:48:36 +02:00
|
|
|
replyLayout.addView(lineView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 1, Gravity.BOTTOM | Gravity.LEFT));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
replyIconImageView = new ImageView(context);
|
|
|
|
replyIconImageView.setScaleType(ImageView.ScaleType.CENTER);
|
2015-05-03 13:48:36 +02:00
|
|
|
replyLayout.addView(replyIconImageView, LayoutHelper.createFrame(52, 46, Gravity.TOP | Gravity.LEFT));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
ImageView imageView = new ImageView(context);
|
|
|
|
imageView.setImageResource(R.drawable.delete_reply);
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
2015-05-03 13:48:36 +02:00
|
|
|
replyLayout.addView(imageView, LayoutHelper.createFrame(52, 46, Gravity.RIGHT | Gravity.TOP, 0, 0.5f, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
imageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (forwardingMessages != null) {
|
|
|
|
forwardingMessages.clear();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, foundWebPage, true, true);
|
|
|
|
}
|
|
|
|
});
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
replyNameTextView = new TextView(context);
|
|
|
|
replyNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
replyNameTextView.setTextColor(0xff377aae);
|
|
|
|
replyNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
replyNameTextView.setSingleLine(true);
|
|
|
|
replyNameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
replyNameTextView.setMaxLines(1);
|
2015-05-03 13:48:36 +02:00
|
|
|
replyLayout.addView(replyNameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, 4, 52, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
replyObjectTextView = new TextView(context);
|
|
|
|
replyObjectTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
replyObjectTextView.setTextColor(0xff999999);
|
|
|
|
replyObjectTextView.setSingleLine(true);
|
|
|
|
replyObjectTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
replyObjectTextView.setMaxLines(1);
|
2015-05-03 13:48:36 +02:00
|
|
|
replyLayout.addView(replyObjectTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, 22, 52, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
replyImageView = new BackupImageView(context);
|
2015-05-03 13:48:36 +02:00
|
|
|
replyLayout.addView(replyImageView, LayoutHelper.createFrame(34, 34, Gravity.TOP | Gravity.LEFT, 52, 6, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
stickersPanel = new FrameLayout(context);
|
|
|
|
stickersPanel.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
contentView.addView(stickersPanel, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 81.5f, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 38));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
stickersListView = new RecyclerListView(context);
|
2015-05-21 23:27:27 +02:00
|
|
|
stickersListView.setDisallowInterceptTouchEvents(true);
|
2015-04-09 20:00:14 +02:00
|
|
|
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
|
|
|
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
|
stickersListView.setLayoutManager(layoutManager);
|
|
|
|
stickersListView.setClipToPadding(false);
|
|
|
|
if (Build.VERSION.SDK_INT >= 9) {
|
|
|
|
stickersListView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
stickersPanel.addView(stickersListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 78));
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentEncryptedChat == null || currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 23) {
|
2015-05-03 13:48:36 +02:00
|
|
|
chatActivityEnterView.setAllowStickers(true);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (stickersAdapter != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
stickersAdapter.onDestroy();
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
stickersListView.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
|
|
|
|
stickersListView.setAdapter(stickersAdapter = new StickersAdapter(context, new StickersAdapter.StickersAdapterDelegate() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void needChangePanelVisibility(final boolean show) {
|
|
|
|
if (show && stickersPanel.getVisibility() == View.VISIBLE || !show && stickersPanel.getVisibility() == View.GONE) {
|
|
|
|
return;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (show) {
|
|
|
|
stickersListView.scrollToPosition(0);
|
|
|
|
stickersPanel.clearAnimation();
|
|
|
|
stickersPanel.setVisibility(allowStickersPanel ? View.VISIBLE : View.INVISIBLE);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (runningAnimation != null) {
|
|
|
|
runningAnimation.cancel();
|
|
|
|
runningAnimation = null;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (stickersPanel.getVisibility() != View.INVISIBLE) {
|
|
|
|
runningAnimation = new AnimatorSetProxy();
|
|
|
|
runningAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(stickersPanel, "alpha", show ? 0.0f : 1.0f, show ? 1.0f : 0.0f)
|
|
|
|
);
|
|
|
|
runningAnimation.setDuration(150);
|
|
|
|
runningAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (runningAnimation != null && runningAnimation.equals(animation)) {
|
|
|
|
if (!show) {
|
|
|
|
stickersAdapter.clearStickers();
|
|
|
|
stickersPanel.clearAnimation();
|
|
|
|
stickersPanel.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
runningAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
runningAnimation.start();
|
|
|
|
} else if (!show) {
|
|
|
|
stickersPanel.setVisibility(View.GONE);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}));
|
2015-05-21 23:27:27 +02:00
|
|
|
stickersListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
TLRPC.Document document = stickersAdapter.getItem(position);
|
|
|
|
if (document instanceof TLRPC.TL_document) {
|
2015-05-03 13:48:36 +02:00
|
|
|
SendMessagesHelper.getInstance().sendSticker(document, dialog_id, replyingMessageObject);
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
chatActivityEnterView.setFieldText("");
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
});
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
imageView = new ImageView(context);
|
|
|
|
imageView.setImageResource(R.drawable.stickers_back_arrow);
|
2015-05-03 13:48:36 +02:00
|
|
|
stickersPanel.addView(imageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 53, 0, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
bottomOverlay = new FrameLayout(context);
|
|
|
|
bottomOverlay.setBackgroundColor(0xffffffff);
|
|
|
|
bottomOverlay.setVisibility(View.INVISIBLE);
|
|
|
|
bottomOverlay.setFocusable(true);
|
|
|
|
bottomOverlay.setFocusableInTouchMode(true);
|
|
|
|
bottomOverlay.setClickable(true);
|
2015-05-21 23:27:27 +02:00
|
|
|
contentView.addView(bottomOverlay, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
bottomOverlayText = new TextView(context);
|
|
|
|
bottomOverlayText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
bottomOverlayText.setTextColor(0xff7f7f7f);
|
2015-05-03 13:48:36 +02:00
|
|
|
bottomOverlay.addView(bottomOverlayText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
bottomOverlayChat = new FrameLayout(context);
|
|
|
|
bottomOverlayChat.setBackgroundColor(0xfffbfcfd);
|
|
|
|
bottomOverlayChat.setVisibility(View.INVISIBLE);
|
2015-05-21 23:27:27 +02:00
|
|
|
contentView.addView(bottomOverlayChat, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));
|
2015-04-09 20:00:14 +02:00
|
|
|
bottomOverlayChat.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
AlertDialog.Builder builder = null;
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentUser != null && userBlocked) {
|
2015-09-02 00:14:21 +02:00
|
|
|
if ((currentUser.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
String botUserLast = botUser;
|
|
|
|
botUser = null;
|
|
|
|
MessagesController.getInstance().unblockUser(currentUser.id);
|
|
|
|
if (botUserLast != null && botUserLast.length() != 0) {
|
|
|
|
MessagesController.getInstance().sendBotStart(currentUser, botUserLast);
|
|
|
|
} else {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage("/start", dialog_id, null, null, false);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-09-02 00:14:21 +02:00
|
|
|
} else {
|
|
|
|
builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
MessagesController.getInstance().unblockUser(currentUser.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (currentUser != null && botUser != null) {
|
2015-09-02 00:14:21 +02:00
|
|
|
if (botUser != null && botUser.length() != 0) {
|
2015-06-29 19:12:11 +02:00
|
|
|
MessagesController.getInstance().sendBotStart(currentUser, botUser);
|
|
|
|
} else {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage("/start", dialog_id, null, null, false);
|
|
|
|
}
|
|
|
|
botUser = null;
|
|
|
|
updateBottomOverlay();
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
builder = new AlertDialog.Builder(getParentActivity());
|
2015-04-09 20:00:14 +02:00
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
MessagesController.getInstance().deleteDialog(dialog_id, 0, false);
|
|
|
|
finishFragment();
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (builder != null) {
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showDialog(builder.create());
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
bottomOverlayChatText = new TextView(context);
|
|
|
|
bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
bottomOverlayChatText.setTextColor(0xff3e6fa1);
|
2015-05-03 13:48:36 +02:00
|
|
|
bottomOverlayChat.addView(bottomOverlayChatText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
pagedownButton = new ImageView(context);
|
|
|
|
pagedownButton.setVisibility(View.INVISIBLE);
|
|
|
|
pagedownButton.setImageResource(R.drawable.pagedown);
|
2015-05-21 23:27:27 +02:00
|
|
|
contentView.addView(pagedownButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 6, 4));
|
2015-04-09 20:00:14 +02:00
|
|
|
pagedownButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (returnToMessageId > 0) {
|
|
|
|
scrollToMessageId(returnToMessageId, 0, true);
|
|
|
|
} else {
|
|
|
|
scrollToLastMessage();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (loading && messages.isEmpty()) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
chatListView.setEmptyView(null);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
chatListView.setEmptyView(emptyViewContainer);
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
chatActivityEnterView.setButtons(botButtons);
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
updateContactStatus();
|
|
|
|
updateBottomOverlay();
|
|
|
|
updateSecretStatus();
|
|
|
|
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private boolean searchForHttpInText(CharSequence string) {
|
|
|
|
int len = string.length();
|
|
|
|
int seqLen = 0;
|
|
|
|
for (int a = 0; a < len; a++) {
|
|
|
|
char ch = string.charAt(a);
|
|
|
|
if (seqLen == 0 && (ch == 'h' || ch == 'H')) {
|
|
|
|
seqLen++;
|
|
|
|
} else if ((seqLen == 1 || seqLen == 2) && (ch == 't' || ch == 'T')) {
|
|
|
|
seqLen++;
|
|
|
|
} else if (seqLen == 3 && (ch == 'p' || ch == 'P')) {
|
|
|
|
seqLen++;
|
|
|
|
} else if (seqLen == 4 && (ch == 's' || ch == 'S')) {
|
|
|
|
seqLen++;
|
|
|
|
} else if ((seqLen == 4 || seqLen == 5) && ch == ':') {
|
|
|
|
seqLen++;
|
|
|
|
} else if ((seqLen == 5 || seqLen == 6 || seqLen == 7) && ch == '/') {
|
|
|
|
if (seqLen == 6 || seqLen == 7) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
seqLen++;
|
|
|
|
} else if (seqLen != 0) {
|
|
|
|
seqLen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void processSelectedAttach(int which) {
|
|
|
|
if (which == attach_photo || which == attach_gallery || which == attach_document || which == attach_video) {
|
|
|
|
String action;
|
|
|
|
if (currentChat != null) {
|
|
|
|
if (currentChat.participants_count > MessagesController.getInstance().groupBigSize) {
|
|
|
|
if (which == attach_photo || which == attach_gallery) {
|
|
|
|
action = "bigchat_upload_photo";
|
|
|
|
} else {
|
|
|
|
action = "bigchat_upload_document";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (which == attach_photo || which == attach_gallery) {
|
|
|
|
action = "chat_upload_photo";
|
|
|
|
} else {
|
|
|
|
action = "chat_upload_document";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (which == attach_photo || which == attach_gallery) {
|
|
|
|
action = "pm_upload_photo";
|
|
|
|
} else {
|
|
|
|
action = "pm_upload_document";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (action != null && !MessagesController.isFeatureEnabled(action, ChatActivity.this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (which == attach_photo) {
|
|
|
|
try {
|
|
|
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
File image = AndroidUtilities.generatePicturePath();
|
|
|
|
if (image != null) {
|
|
|
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
|
|
|
|
currentPicturePath = image.getAbsolutePath();
|
|
|
|
}
|
|
|
|
startActivityForResult(takePictureIntent, 0);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (which == attach_gallery) {
|
|
|
|
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(false, ChatActivity.this);
|
|
|
|
fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<MediaController.SearchImage> webPhotos) {
|
|
|
|
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject, captions);
|
|
|
|
SendMessagesHelper.prepareSendingPhotosSearch(webPhotos, dialog_id, replyingMessageObject);
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startPhotoSelectActivity() {
|
|
|
|
try {
|
|
|
|
Intent videoPickerIntent = new Intent();
|
|
|
|
videoPickerIntent.setType("video/*");
|
|
|
|
videoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
|
videoPickerIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536));
|
|
|
|
|
|
|
|
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
photoPickerIntent.setType("image/*");
|
|
|
|
Intent chooserIntent = Intent.createChooser(photoPickerIntent, null);
|
|
|
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{videoPickerIntent});
|
|
|
|
|
|
|
|
startActivityForResult(chooserIntent, 1);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean didSelectVideo(String path) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
|
|
return !openVideoEditor(path, true, true);
|
|
|
|
} else {
|
|
|
|
SendMessagesHelper.prepareSendingVideo(path, 0, 0, 0, 0, null, dialog_id, replyingMessageObject);
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (which == attach_video) {
|
|
|
|
try {
|
|
|
|
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
|
|
|
|
File video = AndroidUtilities.generateVideoPath();
|
|
|
|
if (video != null) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
|
|
|
|
}
|
|
|
|
takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536));
|
|
|
|
currentPicturePath = video.getAbsolutePath();
|
|
|
|
}
|
|
|
|
startActivityForResult(takeVideoIntent, 2);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (which == attach_location) {
|
|
|
|
if (!isGoogleMapsInstalled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LocationActivity fragment = new LocationActivity();
|
|
|
|
fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectLocation(TLRPC.MessageMedia location) {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage(location, dialog_id, replyingMessageObject);
|
|
|
|
moveScrollToLastMessage();
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (which == attach_document) {
|
|
|
|
DocumentSelectActivity fragment = new DocumentSelectActivity();
|
|
|
|
fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files) {
|
|
|
|
activity.finishFragment();
|
|
|
|
SendMessagesHelper.prepareSendingDocuments(files, files, null, null, dialog_id, replyingMessageObject);
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startDocumentSelectActivity() {
|
|
|
|
try {
|
|
|
|
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
photoPickerIntent.setType("*/*");
|
|
|
|
startActivityForResult(photoPickerIntent, 21);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (which == attach_audio) {
|
2015-07-22 20:56:37 +02:00
|
|
|
AudioSelectActivity fragment = new AudioSelectActivity();
|
|
|
|
fragment.setDelegate(new AudioSelectActivity.AudioSelectActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectAudio(ArrayList<MessageObject> audios) {
|
|
|
|
SendMessagesHelper.prepareSendingAudioDocuments(audios, dialog_id, replyingMessageObject);
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (which == attach_contact) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
|
|
|
|
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
|
|
|
|
startActivityForResult(intent, 31);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
private void searchLinks(CharSequence charSequence, boolean force) {
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (linkSearchRequestId != 0) {
|
|
|
|
ConnectionsManager.getInstance().cancelRpc(linkSearchRequestId, true);
|
|
|
|
linkSearchRequestId = 0;
|
|
|
|
}
|
|
|
|
if (force && foundWebPage != null) {
|
|
|
|
if (foundWebPage.url != null) {
|
|
|
|
int index = TextUtils.indexOf(charSequence, foundWebPage.url);
|
|
|
|
char lastChar;
|
|
|
|
boolean lenEqual;
|
|
|
|
if (index == -1) {
|
|
|
|
index = TextUtils.indexOf(charSequence, foundWebPage.display_url);
|
|
|
|
lenEqual = index != -1 && index + foundWebPage.display_url.length() == charSequence.length();
|
|
|
|
lastChar = index != -1 && !lenEqual ? charSequence.charAt(index + foundWebPage.display_url.length()) : 0;
|
|
|
|
} else {
|
|
|
|
lenEqual = index != -1 && index + foundWebPage.url.length() == charSequence.length();
|
|
|
|
lastChar = index != -1 && !lenEqual ? charSequence.charAt(index + foundWebPage.url.length()) : 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (index != -1 && (lenEqual || lastChar == ' ' || lastChar == ',' || lastChar == '.' || lastChar == '!' || lastChar == '/')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pendingLinkSearchString = null;
|
|
|
|
showReplyPanel(false, null, null, foundWebPage, false, true);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
if (charSequence.length() < 13 || !searchForHttpInText(charSequence)) {
|
2015-04-09 20:00:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
final TLRPC.TL_messages_getWebPagePreview req = new TLRPC.TL_messages_getWebPagePreview();
|
|
|
|
if (charSequence instanceof String) {
|
|
|
|
req.message = (String) charSequence;
|
|
|
|
} else {
|
|
|
|
req.message = charSequence.toString();
|
|
|
|
}
|
|
|
|
linkSearchRequestId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
|
|
|
@Override
|
|
|
|
public void run(final TLObject response, final TLRPC.TL_error error) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2015-01-02 23:15:07 +01:00
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void run() {
|
|
|
|
linkSearchRequestId = 0;
|
|
|
|
if (error == null) {
|
|
|
|
if (response instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
foundWebPage = ((TLRPC.TL_messageMediaWebPage) response).webpage;
|
|
|
|
if (foundWebPage instanceof TLRPC.TL_webPage || foundWebPage instanceof TLRPC.TL_webPagePending) {
|
|
|
|
if (foundWebPage instanceof TLRPC.TL_webPagePending) {
|
|
|
|
pendingLinkSearchString = req.message;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(true, null, null, foundWebPage, false, true);
|
|
|
|
} else {
|
|
|
|
if (foundWebPage != null) {
|
|
|
|
showReplyPanel(false, null, null, foundWebPage, false, true);
|
|
|
|
foundWebPage = null;
|
2015-01-09 13:50:15 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
if (foundWebPage != null) {
|
|
|
|
showReplyPanel(false, null, null, foundWebPage, false, true);
|
|
|
|
foundWebPage = null;
|
2015-03-27 11:32:33 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
ConnectionsManager.getInstance().bindRequestToGuid(linkSearchRequestId, classGuid);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
private void forwardMessages(ArrayList<MessageObject> arrayList, boolean fromMyName) {
|
|
|
|
if (arrayList == null || arrayList.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-20 00:03:19 +01:00
|
|
|
if (!fromMyName) {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage(arrayList, dialog_id);
|
|
|
|
} else {
|
|
|
|
for (MessageObject object : arrayList) {
|
2015-03-19 00:09:45 +01:00
|
|
|
SendMessagesHelper.getInstance().processForwardFromMyName(object, dialog_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
public void showReplyPanel(boolean show, MessageObject messageObject, ArrayList<MessageObject> messageObjects, TLRPC.WebPage webPage, boolean cancel, boolean animated) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (show) {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (messageObject == null && messageObjects == null && webPage == null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (messageObject != null) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(messageObject.messageOwner.from_id);
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
forwardingMessages = null;
|
|
|
|
replyingMessageObject = messageObject;
|
|
|
|
chatActivityEnterView.setReplyingMessageObject(messageObject);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
if (foundWebPage != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
replyIconImageView.setImageResource(R.drawable.reply);
|
2015-06-29 19:12:11 +02:00
|
|
|
replyNameTextView.setText(UserObject.getUserName(user));
|
2015-03-19 00:09:45 +01:00
|
|
|
if (messageObject.messageText != null) {
|
|
|
|
String mess = messageObject.messageText.toString();
|
|
|
|
if (mess.length() > 150) {
|
|
|
|
mess = mess.substring(0, 150);
|
|
|
|
}
|
|
|
|
mess = mess.replace("\n", " ");
|
2015-07-22 20:56:37 +02:00
|
|
|
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
} else if (messageObjects != null) {
|
|
|
|
if (messageObjects.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
replyingMessageObject = null;
|
2015-04-09 20:00:14 +02:00
|
|
|
chatActivityEnterView.setReplyingMessageObject(null);
|
|
|
|
forwardingMessages = messageObjects;
|
|
|
|
|
|
|
|
if (foundWebPage != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
chatActivityEnterView.setForceShowSendButton(true, animated);
|
2015-03-19 00:09:45 +01:00
|
|
|
ArrayList<Integer> uids = new ArrayList<>();
|
|
|
|
replyIconImageView.setImageResource(R.drawable.forward_blue);
|
|
|
|
uids.add(messageObjects.get(0).messageOwner.from_id);
|
|
|
|
int type = messageObjects.get(0).type;
|
|
|
|
for (int a = 1; a < messageObjects.size(); a++) {
|
|
|
|
Integer uid = messageObjects.get(a).messageOwner.from_id;
|
|
|
|
if (!uids.contains(uid)) {
|
|
|
|
uids.add(uid);
|
|
|
|
}
|
|
|
|
if (messageObjects.get(a).type != type) {
|
|
|
|
type = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringBuilder userNames = new StringBuilder();
|
|
|
|
for (int a = 0; a < uids.size(); a++) {
|
|
|
|
Integer uid = uids.get(a);
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(uid);
|
|
|
|
if (user == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (uids.size() == 1) {
|
2015-06-29 19:12:11 +02:00
|
|
|
userNames.append(UserObject.getUserName(user));
|
2015-03-19 00:09:45 +01:00
|
|
|
} else if (uids.size() == 2 || userNames.length() == 0) {
|
|
|
|
if (userNames.length() > 0) {
|
|
|
|
userNames.append(", ");
|
|
|
|
}
|
|
|
|
if (user.first_name != null && user.first_name.length() > 0) {
|
|
|
|
userNames.append(user.first_name);
|
|
|
|
} else if (user.last_name != null && user.last_name.length() > 0) {
|
|
|
|
userNames.append(user.last_name);
|
|
|
|
} else {
|
|
|
|
userNames.append(" ");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
userNames.append(" ");
|
|
|
|
userNames.append(LocaleController.formatPluralString("AndOther", uids.size() - 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
replyNameTextView.setText(userNames);
|
|
|
|
if (type == -1 || type == 0) {
|
|
|
|
if (messageObjects.size() == 1 && messageObjects.get(0).messageText != null) {
|
|
|
|
String mess = messageObjects.get(0).messageText.toString();
|
|
|
|
if (mess.length() > 150) {
|
|
|
|
mess = mess.substring(0, 150);
|
|
|
|
}
|
|
|
|
mess = mess.replace("\n", " ");
|
2015-07-22 20:56:37 +02:00
|
|
|
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
|
2015-03-19 00:09:45 +01:00
|
|
|
} else {
|
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedMessage", messageObjects.size()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (type == 1) {
|
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedPhoto", messageObjects.size()));
|
|
|
|
if (messageObjects.size() == 1) {
|
|
|
|
messageObject = messageObjects.get(0);
|
|
|
|
}
|
|
|
|
} else if (type == 4) {
|
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedLocation", messageObjects.size()));
|
|
|
|
} else if (type == 3) {
|
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedVideo", messageObjects.size()));
|
|
|
|
if (messageObjects.size() == 1) {
|
|
|
|
messageObject = messageObjects.get(0);
|
|
|
|
}
|
|
|
|
} else if (type == 12) {
|
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedContact", messageObjects.size()));
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (type == 2 || type == 14) {
|
2015-03-19 00:09:45 +01:00
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedAudio", messageObjects.size()));
|
|
|
|
} else if (type == 13) {
|
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedSticker", messageObjects.size()));
|
|
|
|
} else if (type == 8 || type == 9) {
|
|
|
|
if (messageObjects.size() == 1) {
|
2015-05-21 23:27:27 +02:00
|
|
|
String name;
|
2015-03-19 00:09:45 +01:00
|
|
|
if ((name = FileLoader.getDocumentFileName(messageObjects.get(0).messageOwner.media.document)).length() != 0) {
|
|
|
|
replyObjectTextView.setText(name);
|
|
|
|
}
|
|
|
|
messageObject = messageObjects.get(0);
|
|
|
|
} else {
|
|
|
|
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedFile", messageObjects.size()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (webPage != null) {
|
|
|
|
replyIconImageView.setImageResource(R.drawable.link);
|
|
|
|
if (webPage instanceof TLRPC.TL_webPagePending) {
|
|
|
|
replyNameTextView.setText(LocaleController.getString("GettingLinkInfo", R.string.GettingLinkInfo));
|
|
|
|
replyObjectTextView.setText(pendingLinkSearchString);
|
|
|
|
} else {
|
|
|
|
if (webPage.site_name != null) {
|
|
|
|
replyNameTextView.setText(webPage.site_name);
|
|
|
|
} else if (webPage.title != null) {
|
|
|
|
replyNameTextView.setText(webPage.title);
|
|
|
|
}
|
|
|
|
if (webPage.description != null) {
|
|
|
|
replyObjectTextView.setText(webPage.description);
|
|
|
|
} else if (webPage.title != null && webPage.site_name != null) {
|
|
|
|
replyObjectTextView.setText(webPage.title);
|
|
|
|
} else if (webPage.author != null) {
|
|
|
|
replyObjectTextView.setText(webPage.author);
|
|
|
|
} else {
|
|
|
|
replyObjectTextView.setText(webPage.display_url);
|
|
|
|
}
|
|
|
|
chatActivityEnterView.setWebPage(webPage, true);
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) replyNameTextView.getLayoutParams();
|
|
|
|
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) replyObjectTextView.getLayoutParams();
|
|
|
|
TLRPC.PhotoSize photoSize = messageObject != null ? FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80) : null;
|
2015-04-09 20:00:14 +02:00
|
|
|
if (photoSize == null || messageObject != null && messageObject.type == 13) {
|
2015-03-19 00:09:45 +01:00
|
|
|
replyImageView.setImageBitmap(null);
|
2015-04-09 20:00:14 +02:00
|
|
|
replyImageLocation = null;
|
2015-03-19 00:09:45 +01:00
|
|
|
replyImageView.setVisibility(View.INVISIBLE);
|
|
|
|
layoutParams1.leftMargin = layoutParams2.leftMargin = AndroidUtilities.dp(52);
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
replyImageLocation = photoSize.location;
|
|
|
|
replyImageView.setImage(replyImageLocation, "50_50", (Drawable) null);
|
2015-03-19 00:09:45 +01:00
|
|
|
replyImageView.setVisibility(View.VISIBLE);
|
|
|
|
layoutParams1.leftMargin = layoutParams2.leftMargin = AndroidUtilities.dp(96);
|
|
|
|
}
|
|
|
|
replyNameTextView.setLayoutParams(layoutParams1);
|
|
|
|
replyObjectTextView.setLayoutParams(layoutParams2);
|
|
|
|
chatActivityEnterView.showTopView(animated);
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (replyingMessageObject == null && forwardingMessages == null && foundWebPage == null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (replyingMessageObject != null && replyingMessageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyKeyboardForceReply) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
preferences.edit().putInt("answered_" + dialog_id, replyingMessageObject.getId()).commit();
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (foundWebPage != null) {
|
|
|
|
foundWebPage = null;
|
|
|
|
chatActivityEnterView.setWebPage(null, !cancel);
|
|
|
|
if (webPage != null && (replyingMessageObject != null || forwardingMessages != null)) {
|
|
|
|
showReplyPanel(true, replyingMessageObject, forwardingMessages, null, false, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
if (forwardingMessages != null) {
|
|
|
|
forwardMessages(forwardingMessages, false);
|
|
|
|
}
|
|
|
|
chatActivityEnterView.setForceShowSendButton(false, animated);
|
|
|
|
chatActivityEnterView.hideTopView(animated);
|
|
|
|
chatActivityEnterView.setReplyingMessageObject(null);
|
|
|
|
replyingMessageObject = null;
|
|
|
|
forwardingMessages = null;
|
2015-04-09 20:00:14 +02:00
|
|
|
replyImageLocation = null;
|
2015-03-19 00:09:45 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
preferences.edit().remove("reply_" + dialog_id).commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void moveScrollToLastMessage() {
|
|
|
|
if (chatListView != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
chatLayoutManager.scrollToPositionWithOffset(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
private boolean sendSecretMessageRead(MessageObject messageObject) {
|
2014-10-23 17:30:35 +02:00
|
|
|
if (messageObject == null || messageObject.isOut() || !messageObject.isSecretMedia() || messageObject.messageOwner.destroyTime != 0 || messageObject.messageOwner.ttl <= 0) {
|
2014-10-21 22:35:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
MessagesController.getInstance().markMessageAsRead(dialog_id, messageObject.messageOwner.random_id, messageObject.messageOwner.ttl);
|
2014-10-21 22:35:16 +02:00
|
|
|
messageObject.messageOwner.destroyTime = messageObject.messageOwner.ttl + ConnectionsManager.getInstance().getCurrentTime();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:31:55 +01:00
|
|
|
private void scrollToLastMessage() {
|
2014-11-20 15:45:33 +01:00
|
|
|
if (forward_end_reached && first_unread_id == 0 && startLoadFromMessageId == 0) {
|
2015-05-03 13:48:36 +02:00
|
|
|
chatLayoutManager.scrollToPositionWithOffset(messages.size() - 1, -100000 - chatListView.getPaddingTop());
|
2014-03-22 23:31:55 +01:00
|
|
|
} else {
|
|
|
|
messages.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messagesDict.clear();
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
chatListView.setEmptyView(null);
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
forward_end_reached = true;
|
2015-06-29 19:12:11 +02:00
|
|
|
first = true;
|
|
|
|
firstLoading = true;
|
2014-03-22 23:31:55 +01:00
|
|
|
loading = true;
|
2014-11-19 02:23:46 +01:00
|
|
|
startLoadFromMessageId = 0;
|
2015-03-26 18:34:47 +01:00
|
|
|
needSelectFromMessageId = false;
|
2014-03-22 23:31:55 +01:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
2014-11-19 02:23:46 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, true, 0, classGuid, 0, 0, 0, true);
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void updateMessagesVisisblePart() {
|
|
|
|
if (chatListView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatMessageCell) {
|
|
|
|
ChatMessageCell messageCell = (ChatMessageCell) view;
|
|
|
|
messageCell.getLocalVisibleRect(scrollRect);
|
|
|
|
messageCell.setVisiblePart(scrollRect.top, scrollRect.bottom - scrollRect.top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:34:47 +01:00
|
|
|
private void scrollToMessageId(int id, int fromMessageId, boolean select) {
|
|
|
|
returnToMessageId = fromMessageId;
|
|
|
|
needSelectFromMessageId = select;
|
|
|
|
|
|
|
|
MessageObject object = messagesDict.get(id);
|
|
|
|
boolean query = false;
|
|
|
|
if (object != null) {
|
|
|
|
int index = messages.indexOf(object);
|
|
|
|
if (index != -1) {
|
|
|
|
if (needSelectFromMessageId) {
|
|
|
|
highlightMessageId = id;
|
|
|
|
} else {
|
|
|
|
highlightMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
final int yOffset = Math.max(0, (chatListView.getHeight() - object.getApproximateHeight()) / 2);
|
|
|
|
if (messages.get(messages.size() - 1) == object) {
|
2015-05-03 13:48:36 +02:00
|
|
|
chatLayoutManager.scrollToPositionWithOffset(0, AndroidUtilities.dp(-11) + yOffset);
|
2015-03-26 18:34:47 +01:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
chatLayoutManager.scrollToPositionWithOffset(messages.size() - messages.indexOf(object), AndroidUtilities.dp(-11) + yOffset);
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
|
|
|
updateVisibleRows();
|
|
|
|
showPagedownButton(true, true);
|
|
|
|
} else {
|
|
|
|
query = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
query = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query) {
|
|
|
|
messagesDict.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messages.clear();
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
endReached = false;
|
|
|
|
loading = false;
|
|
|
|
cacheEndReaced = false;
|
|
|
|
firstLoading = true;
|
|
|
|
loadsCount = 0;
|
|
|
|
minDate = 0;
|
|
|
|
first = true;
|
|
|
|
unread_to_load = 0;
|
|
|
|
first_unread_id = 0;
|
|
|
|
last_message_id = 0;
|
|
|
|
first_message_id = 0;
|
|
|
|
forward_end_reached = true;
|
|
|
|
loadingForward = false;
|
|
|
|
unreadMessageObject = null;
|
|
|
|
scrollToMessage = null;
|
|
|
|
highlightMessageId = Integer.MAX_VALUE;
|
|
|
|
scrollToMessageMiddleScreen = false;
|
|
|
|
loading = true;
|
|
|
|
startLoadFromMessageId = id;
|
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, true, 0, classGuid, 3, 0, 0, false);
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
chatListView.setEmptyView(null);
|
|
|
|
emptyViewContainer.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
private void showPagedownButton(boolean show, boolean animated) {
|
|
|
|
if (pagedownButton == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (show) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (pagedownButton.getVisibility() == View.INVISIBLE) {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (animated) {
|
2013-12-20 20:25:49 +01:00
|
|
|
pagedownButton.setVisibility(View.VISIBLE);
|
2014-11-17 03:44:57 +01:00
|
|
|
ViewProxy.setAlpha(pagedownButton, 0);
|
|
|
|
ObjectAnimatorProxy.ofFloatProxy(pagedownButton, "alpha", 1.0f).setDuration(200).start();
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
|
|
|
pagedownButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-26 18:34:47 +01:00
|
|
|
returnToMessageId = 0;
|
2013-12-20 20:25:49 +01:00
|
|
|
if (pagedownButton.getVisibility() == View.VISIBLE) {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (animated) {
|
|
|
|
ObjectAnimatorProxy.ofFloatProxy(pagedownButton, "alpha", 0.0f).setDuration(200).addListener(new AnimatorListenerAdapterProxy() {
|
2013-12-20 20:25:49 +01:00
|
|
|
@Override
|
2014-11-17 03:44:57 +01:00
|
|
|
public void onAnimationEnd(Object animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
pagedownButton.setVisibility(View.INVISIBLE);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2014-07-30 09:49:39 +02:00
|
|
|
}).start();
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
pagedownButton.setVisibility(View.INVISIBLE);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private void updateSecretStatus() {
|
|
|
|
if (bottomOverlay == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat == null || secretViewStatusTextView == null) {
|
2015-02-26 02:32:51 +01:00
|
|
|
bottomOverlay.setVisibility(View.INVISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean hideKeyboard = false;
|
|
|
|
if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
|
2014-03-22 23:31:55 +01:00
|
|
|
bottomOverlayText.setText(LocaleController.getString("EncryptionProcessing", R.string.EncryptionProcessing));
|
2013-10-25 17:19:00 +02:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
|
2015-04-09 20:00:14 +02:00
|
|
|
bottomOverlayText.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, "<b>" + currentUser.first_name + "</b>")));
|
2013-10-25 17:19:00 +02:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
|
2014-03-22 23:31:55 +01:00
|
|
|
bottomOverlayText.setText(LocaleController.getString("EncryptionRejected", R.string.EncryptionRejected));
|
2013-10-25 17:19:00 +02:00
|
|
|
bottomOverlay.setVisibility(View.VISIBLE);
|
2014-11-19 02:23:46 +01:00
|
|
|
chatActivityEnterView.setFieldText("");
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
preferences.edit().remove("dialog_" + dialog_id).commit();
|
2013-10-25 17:19:00 +02:00
|
|
|
hideKeyboard = true;
|
|
|
|
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChat) {
|
2015-02-26 02:32:51 +01:00
|
|
|
bottomOverlay.setVisibility(View.INVISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
if (hideKeyboard) {
|
2015-09-02 00:14:21 +02:00
|
|
|
chatActivityEnterView.hidePopup(false);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (getParentActivity() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
checkActionBarMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkActionBarMenu() {
|
|
|
|
if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat) ||
|
|
|
|
currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) ||
|
2015-06-29 19:12:11 +02:00
|
|
|
currentUser != null && UserObject.isDeleted(currentUser)) {
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
if (menuItem != null) {
|
|
|
|
menuItem.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (timeItem != null) {
|
|
|
|
timeItem.setVisibility(View.GONE);
|
|
|
|
}
|
2014-11-19 16:17:24 +01:00
|
|
|
if (timeItem2 != null) {
|
|
|
|
timeItem2.setVisibility(View.GONE);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
|
|
|
if (menuItem != null) {
|
|
|
|
menuItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
if (timeItem != null) {
|
|
|
|
timeItem.setVisibility(View.VISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-11-19 16:17:24 +01:00
|
|
|
if (timeItem2 != null) {
|
|
|
|
timeItem2.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-11-19 16:17:24 +01:00
|
|
|
if (timerDrawable != null) {
|
2014-11-17 03:44:57 +01:00
|
|
|
timerDrawable.setTime(currentEncryptedChat.ttl);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
checkAndUpdateAvatar();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
private int updateOnlineCount() {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (info == null) {
|
2014-11-12 23:16:59 +01:00
|
|
|
return 0;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
onlineCount = 0;
|
2014-03-22 23:31:55 +01:00
|
|
|
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
|
2013-10-25 17:19:00 +02:00
|
|
|
for (TLRPC.TL_chatParticipant participant : info.participants) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
|
2014-06-13 12:42:21 +02:00
|
|
|
if (user != null && user.status != null && (user.status.expires > currentTime || user.id == UserConfig.getClientUserId()) && user.status.expires > 10000) {
|
2013-10-25 17:19:00 +02:00
|
|
|
onlineCount++;
|
|
|
|
}
|
|
|
|
}
|
2014-11-12 23:16:59 +01:00
|
|
|
return onlineCount;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int getMessageType(MessageObject messageObject) {
|
2014-10-20 13:30:05 +02:00
|
|
|
if (messageObject == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
boolean isBroadcastError = isBroadcast && messageObject.getId() <= 0 && messageObject.isSendError();
|
|
|
|
if (!isBroadcast && messageObject.getId() <= 0 && messageObject.isOut() || isBroadcastError) {
|
2014-09-28 15:37:26 +02:00
|
|
|
if (messageObject.isSendError()) {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!messageObject.isMediaEmpty()) {
|
2014-07-15 21:57:09 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
2015-05-21 23:27:27 +02:00
|
|
|
return 20;
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-29 23:06:04 +02:00
|
|
|
if (messageObject.type == 6) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return -1;
|
|
|
|
} else if (messageObject.type == 10 || messageObject.type == 11) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (messageObject.getId() == 0) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
return 1;
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!messageObject.isMediaEmpty()) {
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (messageObject.isSticker()) {
|
|
|
|
TLRPC.InputStickerSet inputStickerSet = messageObject.getInputStickerSet();
|
|
|
|
if (inputStickerSet != null && !StickersQuery.isStickerPackInstalled(inputStickerSet.id)) {
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
boolean canSave = false;
|
|
|
|
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
File f = new File(messageObject.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!canSave) {
|
2014-09-25 05:54:35 +02:00
|
|
|
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
|
2014-03-31 16:14:49 +02:00
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (canSave) {
|
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
String mime = messageObject.messageOwner.media.document.mime_type;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (mime != null) {
|
|
|
|
if (mime.endsWith("/xml")) {
|
|
|
|
return 5;
|
|
|
|
} else if (mime.endsWith("/png") || mime.endsWith("/jpg") || mime.endsWith("/jpeg")) {
|
|
|
|
return 6;
|
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (messageObject.isSending()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-08-29 23:06:04 +02:00
|
|
|
if (messageObject.type == 6) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return -1;
|
2014-09-28 15:37:26 +02:00
|
|
|
} else if (messageObject.isSendError()) {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!messageObject.isMediaEmpty()) {
|
2014-07-15 21:57:09 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
2015-05-21 23:27:27 +02:00
|
|
|
return 20;
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
} else if (messageObject.type == 10 || messageObject.type == 11) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (messageObject.getId() == 0 || messageObject.isSending()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
return -1;
|
2014-10-22 22:01:07 +02:00
|
|
|
} else {
|
|
|
|
return 1;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!messageObject.isMediaEmpty()) {
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto ||
|
|
|
|
messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (messageObject.isSticker()) {
|
|
|
|
TLRPC.InputStickerSet inputStickerSet = messageObject.getInputStickerSet();
|
|
|
|
if (inputStickerSet != null && !StickersQuery.isStickerPackInstalled(inputStickerSet.id)) {
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
boolean canSave = false;
|
|
|
|
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
File f = new File(messageObject.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!canSave) {
|
2014-09-25 05:54:35 +02:00
|
|
|
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
|
2014-03-31 16:14:49 +02:00
|
|
|
if (f.exists()) {
|
|
|
|
canSave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (canSave) {
|
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
String mime = messageObject.messageOwner.media.document.mime_type;
|
2014-04-04 19:58:33 +02:00
|
|
|
if (mime != null && mime.endsWith("text/xml")) {
|
2014-04-02 19:36:57 +02:00
|
|
|
return 5;
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-30 22:27:41 +01:00
|
|
|
if (messageObject.messageOwner.ttl <= 0) {
|
|
|
|
return 4;
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addToSelectedMessages(MessageObject messageObject) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (selectedMessagesIds.containsKey(messageObject.getId())) {
|
|
|
|
selectedMessagesIds.remove(messageObject.getId());
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.type == 0) {
|
2015-03-19 00:09:45 +01:00
|
|
|
selectedMessagesCanCopyIds.remove(messageObject.getId());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
selectedMessagesIds.put(messageObject.getId(), messageObject);
|
2014-03-31 16:14:49 +02:00
|
|
|
if (messageObject.type == 0) {
|
2015-03-19 00:09:45 +01:00
|
|
|
selectedMessagesCanCopyIds.put(messageObject.getId(), messageObject);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar.isActionModeShowed()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (selectedMessagesIds.isEmpty()) {
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.hideActionMode();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.createActionMode().getItem(copy).setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE);
|
2015-03-19 00:09:45 +01:00
|
|
|
if (actionBar.createActionMode().getItem(reply) != null) {
|
|
|
|
actionBar.createActionMode().getItem(reply).setVisibility(selectedMessagesIds.size() == 1 ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processRowSelect(View view) {
|
2014-02-28 23:28:25 +01:00
|
|
|
MessageObject message = null;
|
|
|
|
if (view instanceof ChatBaseCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
message = ((ChatBaseCell) view).getMessageObject();
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (view instanceof ChatActionCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
message = ((ChatActionCell) view).getMessageObject();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-15 21:57:09 +02:00
|
|
|
int type = getMessageType(message);
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (type < 2 || type == 8) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
addToSelectedMessages(message);
|
|
|
|
updateActionModeTitle();
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateActionModeTitle() {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (!actionBar.isActionModeShowed()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
if (!selectedMessagesIds.isEmpty()) {
|
2014-11-17 03:44:57 +01:00
|
|
|
selectedMessagesCountTextView.setText(String.format("%d", selectedMessagesIds.size()));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
private void updateTitle() {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (nameTextView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentChat != null) {
|
2014-11-14 16:40:15 +01:00
|
|
|
nameTextView.setText(currentChat.title);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (currentUser != null) {
|
2014-06-22 11:49:25 +02:00
|
|
|
if (currentUser.id / 1000 != 777 && currentUser.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(currentUser.id) == null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts())) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser.phone != null && currentUser.phone.length() != 0) {
|
2014-11-14 16:40:15 +01:00
|
|
|
nameTextView.setText(PhoneFormat.getInstance().format("+" + currentUser.phone));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
nameTextView.setText(UserObject.getUserName(currentUser));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
nameTextView.setText(UserObject.getUserName(currentUser));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void updateBotButtons() {
|
|
|
|
if (headerItem == null || currentUser == null || currentEncryptedChat != null || (currentUser.flags & TLRPC.USER_FLAG_BOT) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean hasHelp = false;
|
|
|
|
boolean hasSettings = false;
|
|
|
|
if (!botInfo.isEmpty()) {
|
|
|
|
for (HashMap.Entry<Integer, TLRPC.BotInfo> entry : botInfo.entrySet()) {
|
|
|
|
TLRPC.BotInfo info = entry.getValue();
|
|
|
|
for (int a = 0; a < info.commands.size(); a++) {
|
|
|
|
TLRPC.TL_botCommand command = info.commands.get(a);
|
|
|
|
if (command.command.toLowerCase().equals("help")) {
|
|
|
|
hasHelp = true;
|
|
|
|
} else if (command.command.toLowerCase().equals("settings")) {
|
|
|
|
hasSettings = true;
|
|
|
|
}
|
|
|
|
if (hasSettings && hasHelp) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasHelp) {
|
|
|
|
headerItem.showSubItem(bot_help);
|
|
|
|
} else {
|
|
|
|
headerItem.hideSubItem(bot_help);
|
|
|
|
}
|
|
|
|
if (hasSettings) {
|
|
|
|
headerItem.showSubItem(bot_settings);
|
|
|
|
} else {
|
|
|
|
headerItem.hideSubItem(bot_settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
private void updateTitleIcons() {
|
|
|
|
int leftIcon = currentEncryptedChat != null ? R.drawable.ic_lock_header : 0;
|
|
|
|
int rightIcon = MessagesController.getInstance().isDialogMuted(dialog_id) ? R.drawable.mute_fixed : 0;
|
|
|
|
nameTextView.setCompoundDrawablesWithIntrinsicBounds(leftIcon, 0, rightIcon, 0);
|
|
|
|
|
|
|
|
if (rightIcon != 0) {
|
|
|
|
muteItem.setText(LocaleController.getString("UnmuteNotifications", R.string.UnmuteNotifications));
|
|
|
|
} else {
|
|
|
|
muteItem.setText(LocaleController.getString("MuteNotifications", R.string.MuteNotifications));
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
private void updateSubtitle() {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (onlineTextView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
|
2014-09-28 15:37:26 +02:00
|
|
|
if (printString != null) {
|
|
|
|
printString = TextUtils.replace(printString, new String[]{"..."}, new String[]{""});
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (printString == null || printString.length() == 0) {
|
|
|
|
setTypingAnimation(false);
|
|
|
|
if (currentChat != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (currentChat instanceof TLRPC.TL_chatForbidden) {
|
2014-11-14 16:40:15 +01:00
|
|
|
onlineTextView.setText(LocaleController.getString("YouWereKicked", R.string.YouWereKicked));
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (currentChat.left) {
|
2014-11-14 16:40:15 +01:00
|
|
|
onlineTextView.setText(LocaleController.getString("YouLeft", R.string.YouLeft));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-07-31 02:50:12 +02:00
|
|
|
int count = currentChat.participants_count;
|
|
|
|
if (info != null) {
|
|
|
|
count = info.participants.size();
|
|
|
|
}
|
2014-10-05 23:23:57 +02:00
|
|
|
if (onlineCount > 1 && count != 0) {
|
2014-11-14 16:40:15 +01:00
|
|
|
onlineTextView.setText(String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("Online", onlineCount)));
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2014-11-14 16:40:15 +01:00
|
|
|
onlineTextView.setText(LocaleController.formatPluralString("Members", count));
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-05-17 01:05:49 +02:00
|
|
|
if (user != null) {
|
|
|
|
currentUser = user;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
String newStatus;
|
2015-01-02 23:15:07 +01:00
|
|
|
if (currentUser.id == 333000 || currentUser.id == 777000) {
|
|
|
|
newStatus = LocaleController.getString("ServiceNotifications", R.string.ServiceNotifications);
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if ((currentUser.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
newStatus = LocaleController.getString("Bot", R.string.Bot);
|
|
|
|
} else {
|
|
|
|
newStatus = LocaleController.formatUserStatus(currentUser);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-11-19 16:17:24 +01:00
|
|
|
if (lastStatus == null || lastPrintString != null || lastStatus != null && !lastStatus.equals(newStatus)) {
|
|
|
|
lastStatus = newStatus;
|
|
|
|
onlineTextView.setText(newStatus);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-11-12 11:41:46 +01:00
|
|
|
lastPrintString = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-02-04 19:36:55 +01:00
|
|
|
lastPrintString = printString;
|
2014-11-14 16:40:15 +01:00
|
|
|
onlineTextView.setText(printString);
|
2013-10-25 17:19:00 +02:00
|
|
|
setTypingAnimation(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
private void setTypingAnimation(boolean start) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar == null) {
|
2014-10-15 20:43:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (start) {
|
|
|
|
try {
|
2015-05-03 13:48:36 +02:00
|
|
|
Integer type = MessagesController.getInstance().printingStringsTypes.get(dialog_id);
|
|
|
|
if (type == 0) {
|
|
|
|
if (lastStatusDrawable == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastStatusDrawable = 1;
|
|
|
|
if (onlineTextView != null) {
|
|
|
|
onlineTextView.setCompoundDrawablesWithIntrinsicBounds(typingDotsDrawable, null, null, null);
|
|
|
|
onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
|
|
|
|
|
|
|
typingDotsDrawable.start();
|
|
|
|
recordStatusDrawable.stop();
|
|
|
|
sendingFileDrawable.stop();
|
|
|
|
}
|
|
|
|
} else if (type == 1) {
|
|
|
|
if (lastStatusDrawable == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastStatusDrawable = 2;
|
|
|
|
if (onlineTextView != null) {
|
|
|
|
onlineTextView.setCompoundDrawablesWithIntrinsicBounds(recordStatusDrawable, null, null, null);
|
|
|
|
onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
|
|
|
|
|
|
|
recordStatusDrawable.start();
|
|
|
|
typingDotsDrawable.stop();
|
|
|
|
sendingFileDrawable.stop();
|
|
|
|
}
|
|
|
|
} else if (type == 2) {
|
|
|
|
if (lastStatusDrawable == 3) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastStatusDrawable = 3;
|
|
|
|
if (onlineTextView != null) {
|
|
|
|
onlineTextView.setCompoundDrawablesWithIntrinsicBounds(sendingFileDrawable, null, null, null);
|
|
|
|
onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
|
|
|
|
|
|
|
sendingFileDrawable.start();
|
|
|
|
typingDotsDrawable.stop();
|
|
|
|
recordStatusDrawable.stop();
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (lastStatusDrawable == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastStatusDrawable = 0;
|
2014-11-17 03:44:57 +01:00
|
|
|
if (onlineTextView != null) {
|
|
|
|
onlineTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
|
|
|
onlineTextView.setCompoundDrawablePadding(0);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2014-10-15 20:43:52 +02:00
|
|
|
typingDotsDrawable.stop();
|
2015-05-03 13:48:36 +02:00
|
|
|
recordStatusDrawable.stop();
|
|
|
|
sendingFileDrawable.stop();
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private void checkAndUpdateAvatar() {
|
|
|
|
TLRPC.FileLocation newPhoto = null;
|
2014-11-06 22:34:47 +01:00
|
|
|
AvatarDrawable avatarDrawable = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-04-05 07:55:51 +02:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentUser = user;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser.photo != null) {
|
|
|
|
newPhoto = currentUser.photo.photo_small;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarDrawable = new AvatarDrawable(currentUser);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (currentChat != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(currentChat.id);
|
2014-04-05 07:55:51 +02:00
|
|
|
if (chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentChat = chat;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentChat.photo != null) {
|
|
|
|
newPhoto = currentChat.photo.photo_small;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarDrawable = new AvatarDrawable(currentChat);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
if (avatarImageView != null) {
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarImageView.setImage(newPhoto, "50_50", avatarDrawable);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public boolean openVideoEditor(String videoPath, boolean removeLast, boolean animated) {
|
2014-10-15 20:43:52 +02:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putString("videoPath", videoPath);
|
|
|
|
VideoEditorActivity fragment = new VideoEditorActivity(args);
|
|
|
|
fragment.setDelegate(new VideoEditorActivity.VideoEditorActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didFinishEditVideo(String videoPath, long startTime, long endTime, int resultWidth, int resultHeight, int rotationValue, int originalWidth, int originalHeight, int bitrate, long estimatedSize, long estimatedDuration) {
|
2015-05-21 23:27:27 +02:00
|
|
|
VideoEditedInfo videoEditedInfo = new VideoEditedInfo();
|
2014-10-15 20:43:52 +02:00
|
|
|
videoEditedInfo.startTime = startTime;
|
|
|
|
videoEditedInfo.endTime = endTime;
|
|
|
|
videoEditedInfo.rotationValue = rotationValue;
|
|
|
|
videoEditedInfo.originalWidth = originalWidth;
|
|
|
|
videoEditedInfo.originalHeight = originalHeight;
|
|
|
|
videoEditedInfo.bitrate = bitrate;
|
|
|
|
videoEditedInfo.resultWidth = resultWidth;
|
|
|
|
videoEditedInfo.resultHeight = resultHeight;
|
|
|
|
videoEditedInfo.originalPath = videoPath;
|
2015-03-19 00:09:45 +01:00
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, estimatedSize, estimatedDuration, resultWidth, resultHeight, videoEditedInfo, dialog_id, replyingMessageObject);
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
});
|
2014-10-22 22:01:07 +02:00
|
|
|
|
|
|
|
if (parentLayout == null || !fragment.onFragmentCreate()) {
|
2015-03-19 00:09:45 +01:00
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject);
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2014-10-15 20:43:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
parentLayout.presentFragment(fragment, removeLast, !animated, true);
|
2014-10-15 20:43:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showAttachmentError() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnsupportedAttachment", R.string.UnsupportedAttachment), Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2014-03-26 21:16:28 +01:00
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
if (requestCode == 0) {
|
2015-02-26 02:32:51 +01:00
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
final ArrayList<Object> arrayList = new ArrayList<>();
|
|
|
|
int orientation = 0;
|
|
|
|
try {
|
|
|
|
ExifInterface ei = new ExifInterface(currentPicturePath);
|
|
|
|
int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
2015-04-09 20:00:14 +02:00
|
|
|
switch (exif) {
|
2015-02-26 02:32:51 +01:00
|
|
|
case ExifInterface.ORIENTATION_ROTATE_90:
|
|
|
|
orientation = 90;
|
|
|
|
break;
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_180:
|
|
|
|
orientation = 180;
|
|
|
|
break;
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_270:
|
|
|
|
orientation = 270;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() {
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
|
|
|
|
if (photoEntry.imagePath != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
SendMessagesHelper.prepareSendingPhoto(photoEntry.imagePath, null, dialog_id, replyingMessageObject, photoEntry.caption);
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (photoEntry.path != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
SendMessagesHelper.prepareSendingPhoto(photoEntry.path, null, dialog_id, replyingMessageObject, photoEntry.caption);
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}, this);
|
2015-05-21 23:27:27 +02:00
|
|
|
AndroidUtilities.addMediaToGallery(currentPicturePath);
|
2013-10-25 17:19:00 +02:00
|
|
|
currentPicturePath = null;
|
|
|
|
} else if (requestCode == 1) {
|
2014-04-03 23:56:42 +02:00
|
|
|
if (data == null || data.getData() == null) {
|
2014-06-14 10:36:01 +02:00
|
|
|
showAttachmentError();
|
2014-02-04 19:36:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
Uri uri = data.getData();
|
|
|
|
if (uri.toString().contains("video")) {
|
|
|
|
String videoPath = null;
|
|
|
|
try {
|
2015-05-21 23:27:27 +02:00
|
|
|
videoPath = AndroidUtilities.getPath(uri);
|
2015-05-03 13:48:36 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
if (videoPath == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
|
|
if (paused) {
|
|
|
|
startVideoEdit = videoPath;
|
|
|
|
} else {
|
|
|
|
openVideoEditor(videoPath, false, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject);
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SendMessagesHelper.prepareSendingPhoto(null, uri, dialog_id, replyingMessageObject, null);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (requestCode == 2) {
|
|
|
|
String videoPath = null;
|
|
|
|
if (data != null) {
|
|
|
|
Uri uri = data.getData();
|
2015-05-03 13:48:36 +02:00
|
|
|
if (uri != null) {
|
|
|
|
videoPath = uri.getPath();
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
videoPath = currentPicturePath;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
AndroidUtilities.addMediaToGallery(currentPicturePath);
|
2015-05-03 13:48:36 +02:00
|
|
|
currentPicturePath = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
if (videoPath == null && currentPicturePath != null) {
|
|
|
|
File f = new File(currentPicturePath);
|
|
|
|
if (f.exists()) {
|
|
|
|
videoPath = currentPicturePath;
|
|
|
|
}
|
|
|
|
currentPicturePath = null;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
2014-10-01 00:36:18 +02:00
|
|
|
if (paused) {
|
|
|
|
startVideoEdit = videoPath;
|
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
openVideoEditor(videoPath, false, false);
|
2014-10-01 00:36:18 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject);
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-06-14 10:36:01 +02:00
|
|
|
} else if (requestCode == 21) {
|
|
|
|
if (data == null || data.getData() == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
Uri uri = data.getData();
|
|
|
|
|
|
|
|
String extractUriFrom = uri.toString();
|
|
|
|
if (extractUriFrom.contains("com.google.android.apps.photos.contentprovider")) {
|
|
|
|
try {
|
|
|
|
String firstExtraction = extractUriFrom.split("/1/")[1];
|
2015-08-13 11:23:31 +02:00
|
|
|
int index = firstExtraction.indexOf("/ACTUAL");
|
|
|
|
if (index != -1) {
|
|
|
|
firstExtraction = firstExtraction.substring(0, index);
|
2015-06-29 19:12:11 +02:00
|
|
|
String secondExtraction = URLDecoder.decode(firstExtraction, "UTF-8");
|
|
|
|
uri = Uri.parse(secondExtraction);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String tempPath = AndroidUtilities.getPath(uri);
|
2014-06-20 02:18:13 +02:00
|
|
|
String originalPath = tempPath;
|
2014-06-14 10:36:01 +02:00
|
|
|
if (tempPath == null) {
|
2014-06-16 14:36:54 +02:00
|
|
|
originalPath = data.toString();
|
2014-06-14 10:36:01 +02:00
|
|
|
tempPath = MediaController.copyDocumentToCache(data.getData(), "file");
|
|
|
|
}
|
|
|
|
if (tempPath == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
return;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
SendMessagesHelper.prepareSendingDocument(tempPath, originalPath, null, null, dialog_id, replyingMessageObject);
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (requestCode == 31) {
|
|
|
|
if (data == null || data.getData() == null) {
|
|
|
|
showAttachmentError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Uri uri = data.getData();
|
|
|
|
Cursor c = null;
|
|
|
|
try {
|
|
|
|
c = getParentActivity().getContentResolver().query(uri, new String[]{ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}, null, null, null);
|
|
|
|
if (c != null) {
|
|
|
|
boolean sent = false;
|
|
|
|
while (c.moveToNext()) {
|
|
|
|
sent = true;
|
|
|
|
String name = c.getString(0);
|
|
|
|
String number = c.getString(1);
|
|
|
|
TLRPC.User user = new TLRPC.User();
|
|
|
|
user.first_name = name;
|
|
|
|
user.last_name = "";
|
|
|
|
user.phone = number;
|
|
|
|
SendMessagesHelper.getInstance().sendMessage(user, dialog_id, replyingMessageObject);
|
|
|
|
}
|
|
|
|
if (sent) {
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (c != null && !c.isClosed()) {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void saveSelfArgs(Bundle args) {
|
|
|
|
if (currentPicturePath != null) {
|
|
|
|
args.putString("path", currentPicturePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restoreSelfArgs(Bundle args) {
|
|
|
|
currentPicturePath = args.getString("path");
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void removeUnreadPlane() {
|
2014-10-15 20:43:52 +02:00
|
|
|
if (unreadMessageObject != null) {
|
2014-10-31 20:02:29 +01:00
|
|
|
forward_end_reached = true;
|
2014-10-15 20:43:52 +02:00
|
|
|
first_unread_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = 0;
|
2014-10-15 20:43:52 +02:00
|
|
|
unread_to_load = 0;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (chatAdapter != null) {
|
|
|
|
chatAdapter.removeMessageObject(unreadMessageObject);
|
|
|
|
} else {
|
|
|
|
messages.remove(unreadMessageObject);
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
unreadMessageObject = null;
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
public boolean processSendingText(String text) {
|
2014-07-03 00:39:05 +02:00
|
|
|
return chatActivityEnterView.processSendingText(text);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, final Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.messagesDidLoaded) {
|
2015-04-09 20:00:14 +02:00
|
|
|
long did = (Long) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
if (did == dialog_id) {
|
2014-09-24 04:17:27 +02:00
|
|
|
loadsCount++;
|
2015-04-09 20:00:14 +02:00
|
|
|
int count = (Integer) args[1];
|
|
|
|
boolean isCache = (Boolean) args[3];
|
|
|
|
int fnid = (Integer) args[4];
|
|
|
|
int last_unread_date = (Integer) args[8];
|
|
|
|
int load_type = (Integer) args[9];
|
2013-10-25 17:19:00 +02:00
|
|
|
boolean wasUnread = false;
|
2013-12-20 20:25:49 +01:00
|
|
|
if (fnid != 0) {
|
2014-08-02 01:31:15 +02:00
|
|
|
first_unread_id = fnid;
|
2015-04-09 20:00:14 +02:00
|
|
|
last_message_id = (Integer) args[5];
|
|
|
|
unread_to_load = (Integer) args[7];
|
2014-11-19 02:23:46 +01:00
|
|
|
} else if (startLoadFromMessageId != 0 && load_type == 3) {
|
2015-04-09 20:00:14 +02:00
|
|
|
last_message_id = (Integer) args[5];
|
|
|
|
first_message_id = (Integer) args[6];
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
ArrayList<MessageObject> messArr = (ArrayList<MessageObject>) args[2];
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
int newRowsCount = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
|
|
|
|
forward_end_reached = startLoadFromMessageId == 0 && last_message_id == 0;
|
2014-08-02 01:31:15 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (loadsCount == 1 && messArr.size() > 20) {
|
|
|
|
loadsCount++;
|
|
|
|
}
|
|
|
|
|
2014-08-02 01:31:15 +02:00
|
|
|
if (firstLoading) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached) {
|
2014-08-02 01:31:15 +02:00
|
|
|
messages.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messagesDict.clear();
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
|
|
|
}
|
|
|
|
firstLoading = false;
|
|
|
|
}
|
|
|
|
|
2014-11-19 02:23:46 +01:00
|
|
|
if (load_type == 1) {
|
|
|
|
Collections.reverse(messArr);
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
ReplyMessageQuery.loadReplyMessagesForMessages(messArr, dialog_id);
|
2014-11-19 02:23:46 +01:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
for (int a = 0; a < messArr.size(); a++) {
|
|
|
|
MessageObject obj = messArr.get(a);
|
2015-03-19 00:09:45 +01:00
|
|
|
if (messagesDict.containsKey(obj.getId())) {
|
2013-12-20 20:25:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
if (obj.getId() > 0) {
|
|
|
|
maxMessageId = Math.min(obj.getId(), maxMessageId);
|
|
|
|
minMessageId = Math.max(obj.getId(), minMessageId);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (currentEncryptedChat != null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
maxMessageId = Math.max(obj.getId(), maxMessageId);
|
|
|
|
minMessageId = Math.min(obj.getId(), minMessageId);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
if (obj.messageOwner.date != 0) {
|
|
|
|
maxDate = Math.max(maxDate, obj.messageOwner.date);
|
|
|
|
if (minDate == 0 || obj.messageOwner.date < minDate) {
|
|
|
|
minDate = obj.messageOwner.date;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
|
|
|
|
if (obj.type < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-09-14 01:40:36 +02:00
|
|
|
if (!obj.isOut() && obj.isUnread()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
wasUnread = true;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
messagesDict.put(obj.getId(), obj);
|
2013-10-25 17:19:00 +02:00
|
|
|
ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (dayArray == null) {
|
2015-01-02 23:15:07 +01:00
|
|
|
dayArray = new ArrayList<>();
|
2013-10-25 17:19:00 +02:00
|
|
|
messagesByDays.put(obj.dateKey, dayArray);
|
|
|
|
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
2014-03-25 01:25:32 +01:00
|
|
|
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
|
2013-10-25 17:19:00 +02:00
|
|
|
dateMsg.id = 0;
|
2015-02-01 19:51:02 +01:00
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null, false);
|
2014-08-29 23:06:04 +02:00
|
|
|
dateObj.type = 10;
|
2014-10-15 20:43:52 +02:00
|
|
|
dateObj.contentType = 4;
|
2014-10-31 20:02:29 +01:00
|
|
|
if (load_type == 1) {
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(0, dateObj);
|
|
|
|
} else {
|
|
|
|
messages.add(dateObj);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
newRowsCount++;
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
newRowsCount++;
|
|
|
|
dayArray.add(obj);
|
2014-10-31 20:02:29 +01:00
|
|
|
if (load_type == 1) {
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(0, obj);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(messages.size() - 1, obj);
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
if (load_type == 2 && obj.getId() == first_unread_id) {
|
2014-10-31 20:02:29 +01:00
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
|
|
|
dateMsg.message = "";
|
|
|
|
dateMsg.id = 0;
|
2015-02-01 19:51:02 +01:00
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null, false);
|
2014-10-31 20:02:29 +01:00
|
|
|
dateObj.contentType = dateObj.type = 6;
|
|
|
|
boolean dateAdded = true;
|
|
|
|
if (a != messArr.size() - 1) {
|
|
|
|
MessageObject next = messArr.get(a + 1);
|
|
|
|
dateAdded = !next.dateKey.equals(obj.dateKey);
|
|
|
|
}
|
|
|
|
messages.add(messages.size() - (dateAdded ? 0 : 1), dateObj);
|
|
|
|
unreadMessageObject = dateObj;
|
|
|
|
scrollToMessage = unreadMessageObject;
|
2014-11-18 06:01:04 +01:00
|
|
|
scrollToMessageMiddleScreen = false;
|
2014-10-31 20:02:29 +01:00
|
|
|
newRowsCount++;
|
2015-03-19 00:09:45 +01:00
|
|
|
} else if (load_type == 3 && obj.getId() == startLoadFromMessageId) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (needSelectFromMessageId) {
|
|
|
|
highlightMessageId = obj.getId();
|
|
|
|
} else {
|
|
|
|
highlightMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
scrollToMessage = obj;
|
2014-11-19 02:23:46 +01:00
|
|
|
if (isCache) {
|
|
|
|
startLoadFromMessageId = 0;
|
|
|
|
}
|
2014-11-18 06:01:04 +01:00
|
|
|
scrollToMessageMiddleScreen = true;
|
2015-03-19 00:09:45 +01:00
|
|
|
} else if (load_type == 1 && startLoadFromMessageId != 0 && first_message_id != 0 && obj.getId() >= first_message_id) {
|
2014-11-19 02:23:46 +01:00
|
|
|
startLoadFromMessageId = 0;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
if (obj.getId() == last_message_id) {
|
2014-10-31 20:02:29 +01:00
|
|
|
forward_end_reached = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (forward_end_reached) {
|
2013-12-20 20:25:49 +01:00
|
|
|
first_unread_id = 0;
|
2014-11-19 02:23:46 +01:00
|
|
|
first_message_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = 0;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
if (load_type == 1) {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (messArr.size() != count) {
|
2014-10-31 20:02:29 +01:00
|
|
|
forward_end_reached = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
first_unread_id = 0;
|
2014-10-31 20:02:29 +01:00
|
|
|
last_message_id = 0;
|
2014-11-19 02:23:46 +01:00
|
|
|
first_message_id = 0;
|
|
|
|
startLoadFromMessageId = 0;
|
2015-06-29 19:12:11 +02:00
|
|
|
chatAdapter.notifyItemRemoved(chatAdapter.getItemCount() - 1);
|
2015-05-03 13:48:36 +02:00
|
|
|
newRowsCount--;
|
|
|
|
}
|
|
|
|
if (newRowsCount != 0) {
|
2015-06-29 19:12:11 +02:00
|
|
|
int firstVisPos = chatLayoutManager.findLastVisibleItemPosition();
|
|
|
|
if (firstVisPos == RecyclerView.NO_POSITION) {
|
|
|
|
firstVisPos = 0;
|
|
|
|
}
|
|
|
|
View firstVisView = chatListView.getChildAt(chatListView.getChildCount() - 1);
|
|
|
|
int top = ((firstVisView == null) ? 0 : firstVisView.getTop()) - chatListView.getPaddingTop();
|
|
|
|
chatAdapter.notifyItemRangeInserted(chatAdapter.getItemCount() - 1, newRowsCount);
|
|
|
|
chatLayoutManager.scrollToPositionWithOffset(firstVisPos, top);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
loadingForward = false;
|
|
|
|
} else {
|
|
|
|
if (messArr.size() != count) {
|
|
|
|
if (isCache) {
|
|
|
|
cacheEndReaced = true;
|
2014-10-20 13:30:05 +02:00
|
|
|
if (currentEncryptedChat != null || isBroadcast) {
|
2013-12-20 20:25:49 +01:00
|
|
|
endReached = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cacheEndReaced = true;
|
|
|
|
endReached = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
loading = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (chatListView != null) {
|
|
|
|
if (first || scrollToTopOnResume) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToMessage != null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
final int yOffset = scrollToMessageMiddleScreen ? Math.max(0, (chatListView.getHeight() - scrollToMessage.getApproximateHeight()) / 2) : 0;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!messages.isEmpty()) {
|
|
|
|
if (messages.get(messages.size() - 1) == scrollToMessage) {
|
|
|
|
chatLayoutManager.scrollToPositionWithOffset(0, AndroidUtilities.dp(-11) + yOffset);
|
|
|
|
} else {
|
|
|
|
chatLayoutManager.scrollToPositionWithOffset(messages.size() - messages.indexOf(scrollToMessage), AndroidUtilities.dp(-11) + yOffset);
|
|
|
|
}
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
chatListView.invalidate();
|
|
|
|
showPagedownButton(true, true);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
moveScrollToLastMessage();
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (endReached) {
|
2015-06-29 19:12:11 +02:00
|
|
|
chatAdapter.notifyItemRemoved(chatAdapter.isBot ? 1 : 0);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (newRowsCount != 0) {
|
|
|
|
int firstVisPos = chatLayoutManager.findLastVisibleItemPosition();
|
2015-06-29 19:12:11 +02:00
|
|
|
if (firstVisPos == RecyclerView.NO_POSITION) {
|
|
|
|
firstVisPos = 0;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
View firstVisView = chatListView.getChildAt(chatListView.getChildCount() - 1);
|
|
|
|
int top = ((firstVisView == null) ? 0 : firstVisView.getTop()) - chatListView.getPaddingTop();
|
2015-06-29 19:12:11 +02:00
|
|
|
chatAdapter.notifyItemRangeInserted(chatAdapter.isBot ? 2 : 1, newRowsCount);
|
2015-05-03 13:48:36 +02:00
|
|
|
chatLayoutManager.scrollToPositionWithOffset(firstVisPos + newRowsCount - (endReached ? 1 : 0), top);
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToMessage != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopUnReadOnResume = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
|
|
|
if (first) {
|
2015-05-03 13:48:36 +02:00
|
|
|
chatListView.setEmptyView(emptyViewContainer);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scrollToTopOnResume = true;
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToMessage != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopUnReadOnResume = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (first && messages.size() > 0) {
|
2014-11-11 23:16:17 +01:00
|
|
|
final boolean wasUnreadFinal = wasUnread;
|
|
|
|
final int last_unread_date_final = last_unread_date;
|
2015-03-19 00:09:45 +01:00
|
|
|
final int lastid = messages.get(0).getId();
|
2014-11-11 23:16:17 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (last_message_id != 0) {
|
2014-11-19 02:23:46 +01:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, lastid, last_message_id, 0, last_unread_date_final, wasUnreadFinal, false);
|
2014-11-11 23:16:17 +01:00
|
|
|
} else {
|
2014-11-19 02:23:46 +01:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, lastid, minMessageId, 0, maxDate, wasUnreadFinal, false);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 700);
|
2013-10-25 17:19:00 +02:00
|
|
|
first = false;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (messages.isEmpty() && currentEncryptedChat == null && currentUser != null && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0 && botUser == null) {
|
|
|
|
botUser = "";
|
|
|
|
updateBottomOverlay();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
if (progressView != null) {
|
2014-11-11 23:16:17 +01:00
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.emojiDidLoaded) {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.invalidateViews();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
if (replyObjectTextView != null) {
|
|
|
|
replyObjectTextView.invalidate();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.updateInterfaces) {
|
2015-04-09 20:00:14 +02:00
|
|
|
int updateMask = (Integer) args[0];
|
2014-11-11 23:16:17 +01:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0) {
|
|
|
|
updateTitle();
|
|
|
|
}
|
|
|
|
boolean updateSubtitle = false;
|
2014-11-12 23:16:59 +01:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0 || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
|
|
|
if (currentChat != null) {
|
|
|
|
int lastCount = onlineCount;
|
|
|
|
if (lastCount != updateOnlineCount()) {
|
|
|
|
updateSubtitle = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
updateSubtitle = true;
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
2013-10-25 17:19:00 +02:00
|
|
|
checkAndUpdateAvatar();
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
2014-03-22 23:31:55 +01:00
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
|
2014-02-04 19:36:55 +01:00
|
|
|
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
2014-11-12 23:16:59 +01:00
|
|
|
updateSubtitle = true;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-12 23:16:59 +01:00
|
|
|
if (updateSubtitle) {
|
|
|
|
updateSubtitle();
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if ((updateMask & MessagesController.UPDATE_MASK_USER_PHONE) != 0) {
|
|
|
|
updateContactStatus();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.didReceivedNewMessages) {
|
2015-04-09 20:00:14 +02:00
|
|
|
long did = (Long) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
if (did == dialog_id) {
|
|
|
|
|
|
|
|
boolean updateChat = false;
|
2014-10-16 22:02:44 +02:00
|
|
|
boolean hasFromMe = false;
|
2015-04-09 20:00:14 +02:00
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[1];
|
2013-12-20 20:25:49 +01:00
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
if (currentEncryptedChat != null && arr.size() == 1) {
|
2014-10-22 22:01:07 +02:00
|
|
|
MessageObject obj = arr.get(0);
|
|
|
|
|
|
|
|
if (currentEncryptedChat != null && obj.isOut() && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
|
|
|
|
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && getParentActivity() != null) {
|
|
|
|
if (AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 17 && currentEncryptedChat.ttl > 0 && currentEncryptedChat.ttl <= 60) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2015-03-19 00:09:45 +01:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2014-10-22 22:01:07 +02:00
|
|
|
builder.setMessage(LocaleController.formatString("CompatibilityChat", R.string.CompatibilityChat, currentUser.first_name, currentUser.first_name));
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2014-10-22 22:01:07 +02:00
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
ReplyMessageQuery.loadReplyMessagesForMessages(arr, dialog_id);
|
2014-10-31 20:02:29 +01:00
|
|
|
if (!forward_end_reached) {
|
2013-12-20 20:25:49 +01:00
|
|
|
int currentMaxDate = Integer.MIN_VALUE;
|
|
|
|
int currentMinMsgId = Integer.MIN_VALUE;
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
currentMinMsgId = Integer.MAX_VALUE;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
boolean currentMarkAsRead = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
for (MessageObject obj : arr) {
|
2014-10-22 22:01:07 +02:00
|
|
|
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
|
2014-11-17 03:44:57 +01:00
|
|
|
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && timerDrawable != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction;
|
2014-11-17 03:44:57 +01:00
|
|
|
timerDrawable.setTime(action.ttl_seconds);
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
2014-09-28 15:37:26 +02:00
|
|
|
if (obj.isOut() && obj.isSending()) {
|
2014-03-22 23:31:55 +01:00
|
|
|
scrollToLastMessage();
|
|
|
|
return;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
if (messagesDict.containsKey(obj.getId())) {
|
2013-12-20 20:25:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
currentMaxDate = Math.max(currentMaxDate, obj.messageOwner.date);
|
2015-03-19 00:09:45 +01:00
|
|
|
if (obj.getId() > 0) {
|
|
|
|
currentMinMsgId = Math.max(obj.getId(), currentMinMsgId);
|
|
|
|
last_message_id = Math.max(last_message_id, obj.getId());
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (currentEncryptedChat != null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
currentMinMsgId = Math.min(obj.getId(), currentMinMsgId);
|
|
|
|
last_message_id = Math.min(last_message_id, obj.getId());
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
|
2014-09-14 01:40:36 +02:00
|
|
|
if (!obj.isOut() && obj.isUnread()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
unread_to_load++;
|
|
|
|
currentMarkAsRead = true;
|
|
|
|
}
|
|
|
|
if (obj.type == 10 || obj.type == 11) {
|
|
|
|
updateChat = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (currentMarkAsRead) {
|
|
|
|
if (paused) {
|
|
|
|
readWhenResume = true;
|
|
|
|
readWithDate = currentMaxDate;
|
|
|
|
readWithMid = currentMinMsgId;
|
|
|
|
} else {
|
2014-02-04 19:36:55 +01:00
|
|
|
if (messages.size() > 0) {
|
2015-03-19 00:09:45 +01:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).getId(), currentMinMsgId, 0, currentMaxDate, true, false);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
updateVisibleRows();
|
|
|
|
} else {
|
|
|
|
boolean markAsRead = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
boolean unreadUpdated = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
int oldCount = messages.size();
|
2015-06-29 19:12:11 +02:00
|
|
|
int addedCount = 0;
|
2013-12-20 20:25:49 +01:00
|
|
|
for (MessageObject obj : arr) {
|
2014-10-22 22:01:07 +02:00
|
|
|
if (currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
|
2014-11-17 03:44:57 +01:00
|
|
|
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && timerDrawable != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction;
|
2014-11-17 03:44:57 +01:00
|
|
|
timerDrawable.setTime(action.ttl_seconds);
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
if (messagesDict.containsKey(obj.getId())) {
|
2013-12-20 20:25:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (minDate == 0 || obj.messageOwner.date < minDate) {
|
|
|
|
minDate = obj.messageOwner.date;
|
|
|
|
}
|
|
|
|
|
2014-04-03 23:18:54 +02:00
|
|
|
if (obj.isOut()) {
|
2015-05-03 13:48:36 +02:00
|
|
|
removeUnreadPlane();
|
2014-10-16 22:02:44 +02:00
|
|
|
hasFromMe = true;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
if (obj.getId() > 0) {
|
|
|
|
maxMessageId = Math.min(obj.getId(), maxMessageId);
|
|
|
|
minMessageId = Math.max(obj.getId(), minMessageId);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (currentEncryptedChat != null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
maxMessageId = Math.max(obj.getId(), maxMessageId);
|
|
|
|
minMessageId = Math.min(obj.getId(), minMessageId);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
maxDate = Math.max(maxDate, obj.messageOwner.date);
|
2015-03-19 00:09:45 +01:00
|
|
|
messagesDict.put(obj.getId(), obj);
|
2013-12-20 20:25:49 +01:00
|
|
|
ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);
|
|
|
|
if (dayArray == null) {
|
2015-01-02 23:15:07 +01:00
|
|
|
dayArray = new ArrayList<>();
|
2013-12-20 20:25:49 +01:00
|
|
|
messagesByDays.put(obj.dateKey, dayArray);
|
|
|
|
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
2014-03-25 01:25:32 +01:00
|
|
|
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
|
2013-12-20 20:25:49 +01:00
|
|
|
dateMsg.id = 0;
|
2015-02-01 19:51:02 +01:00
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null, false);
|
2014-08-29 23:06:04 +02:00
|
|
|
dateObj.type = 10;
|
2014-10-15 20:43:52 +02:00
|
|
|
dateObj.contentType = 4;
|
2013-12-20 20:25:49 +01:00
|
|
|
messages.add(0, dateObj);
|
2015-06-29 19:12:11 +02:00
|
|
|
addedCount++;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!obj.isOut()) {
|
|
|
|
if (paused) {
|
|
|
|
if (!scrollToTopUnReadOnResume && unreadMessageObject != null) {
|
|
|
|
if (chatAdapter != null) {
|
|
|
|
chatAdapter.removeMessageObject(unreadMessageObject);
|
|
|
|
} else {
|
|
|
|
messages.remove(unreadMessageObject);
|
|
|
|
}
|
|
|
|
unreadMessageObject = null;
|
|
|
|
}
|
|
|
|
if (unreadMessageObject == null) {
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
|
|
|
dateMsg.message = "";
|
|
|
|
dateMsg.id = 0;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null, false);
|
|
|
|
dateObj.contentType = dateObj.type = 6;
|
|
|
|
messages.add(0, dateObj);
|
|
|
|
unreadMessageObject = dateObj;
|
|
|
|
scrollToMessage = unreadMessageObject;
|
|
|
|
scrollToMessageMiddleScreen = false;
|
|
|
|
unreadUpdated = false;
|
|
|
|
unread_to_load = 0;
|
|
|
|
scrollToTopUnReadOnResume = true;
|
2015-06-29 19:12:11 +02:00
|
|
|
addedCount++;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (unreadMessageObject != null) {
|
|
|
|
unread_to_load++;
|
|
|
|
unreadUpdated = true;
|
|
|
|
}
|
|
|
|
if (obj.isUnread()) {
|
|
|
|
if (!paused) {
|
|
|
|
obj.setIsRead();
|
|
|
|
}
|
|
|
|
markAsRead = true;
|
2014-07-20 23:49:33 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
dayArray.add(0, obj);
|
|
|
|
messages.add(0, obj);
|
2015-06-29 19:12:11 +02:00
|
|
|
addedCount++;
|
2013-12-20 20:25:49 +01:00
|
|
|
if (obj.type == 10 || obj.type == 11) {
|
|
|
|
updateChat = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (progressView != null) {
|
2014-11-11 23:16:17 +01:00
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (chatAdapter != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (unreadUpdated) {
|
|
|
|
chatAdapter.updateRowWithMessageObject(unreadMessageObject);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (addedCount != 0) {
|
|
|
|
chatAdapter.notifyItemRangeInserted(chatAdapter.getItemCount(), addedCount);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopOnResume = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
|
|
|
|
if (chatListView != null && chatAdapter != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
int lastVisible = chatLayoutManager.findLastVisibleItemPosition();
|
2015-06-29 19:12:11 +02:00
|
|
|
if (lastVisible == RecyclerView.NO_POSITION) {
|
|
|
|
lastVisible = 0;
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (endReached) {
|
|
|
|
lastVisible++;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (chatAdapter.isBot) {
|
|
|
|
oldCount++;
|
|
|
|
}
|
2014-10-16 22:02:44 +02:00
|
|
|
if (lastVisible == oldCount || hasFromMe) {
|
2014-08-02 01:31:15 +02:00
|
|
|
if (!firstLoading) {
|
|
|
|
if (paused) {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
moveScrollToLastMessage();
|
2014-08-02 01:31:15 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showPagedownButton(true, true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scrollToTopOnResume = true;
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (markAsRead) {
|
|
|
|
if (paused) {
|
|
|
|
readWhenResume = true;
|
|
|
|
readWithDate = maxDate;
|
|
|
|
readWithMid = minMessageId;
|
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).getId(), minMessageId, 0, maxDate, true, false);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (!messages.isEmpty() && botUser != null && botUser.length() == 0) {
|
|
|
|
botUser = null;
|
|
|
|
updateBottomOverlay();
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
if (updateChat) {
|
2014-11-11 23:16:17 +01:00
|
|
|
updateTitle();
|
2013-12-20 20:25:49 +01:00
|
|
|
checkAndUpdateAvatar();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.closeChats) {
|
2014-09-30 00:48:11 +02:00
|
|
|
if (args != null && args.length > 0) {
|
2015-04-09 20:00:14 +02:00
|
|
|
long did = (Long) args[0];
|
2014-09-30 00:48:11 +02:00
|
|
|
if (did == dialog_id) {
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
removeSelfFromStack();
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
} else if (id == NotificationCenter.messagesRead) {
|
2015-03-19 00:09:45 +01:00
|
|
|
HashMap<Integer, Integer> inbox = (HashMap<Integer, Integer>) args[0];
|
|
|
|
HashMap<Integer, Integer> outbox = (HashMap<Integer, Integer>) args[1];
|
2013-10-25 17:19:00 +02:00
|
|
|
boolean updated = false;
|
2015-03-19 00:09:45 +01:00
|
|
|
for (HashMap.Entry<Integer, Integer> entry : inbox.entrySet()) {
|
|
|
|
if (entry.getKey() != dialog_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int a = 0; a < messages.size(); a++) {
|
|
|
|
MessageObject obj = messages.get(a);
|
|
|
|
if (!obj.isOut() && obj.getId() > 0 && obj.getId() <= entry.getValue()) {
|
|
|
|
if (!obj.isUnread()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
obj.setIsRead();
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (HashMap.Entry<Integer, Integer> entry : outbox.entrySet()) {
|
|
|
|
if (entry.getKey() != dialog_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int a = 0; a < messages.size(); a++) {
|
|
|
|
MessageObject obj = messages.get(a);
|
|
|
|
if (obj.isOut() && obj.getId() > 0 && obj.getId() <= entry.getValue()) {
|
|
|
|
if (!obj.isUnread()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
obj.setIsRead();
|
|
|
|
updated = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
break;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
if (updated) {
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messagesDeleted) {
|
2015-04-09 20:00:14 +02:00
|
|
|
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
boolean updated = false;
|
|
|
|
for (Integer ids : markAsDeletedMessages) {
|
|
|
|
MessageObject obj = messagesDict.get(ids);
|
|
|
|
if (obj != null) {
|
|
|
|
int index = messages.indexOf(obj);
|
2013-12-20 20:25:49 +01:00
|
|
|
if (index != -1) {
|
2013-10-25 17:19:00 +02:00
|
|
|
messages.remove(index);
|
2013-12-20 20:25:49 +01:00
|
|
|
messagesDict.remove(ids);
|
|
|
|
ArrayList<MessageObject> dayArr = messagesByDays.get(obj.dateKey);
|
|
|
|
dayArr.remove(obj);
|
|
|
|
if (dayArr.isEmpty()) {
|
|
|
|
messagesByDays.remove(obj.dateKey);
|
2014-12-04 21:27:06 +01:00
|
|
|
if (index >= 0 && index < messages.size()) { //TODO fix it
|
|
|
|
messages.remove(index);
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
updated = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (messages.isEmpty()) {
|
|
|
|
if (!endReached && !loading) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
if (chatListView != null) {
|
|
|
|
chatListView.setEmptyView(null);
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
2014-11-19 02:23:46 +01:00
|
|
|
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, !cacheEndReaced, minDate, classGuid, 0, 0, 0, true);
|
2013-12-20 20:25:49 +01:00
|
|
|
loading = true;
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
|
|
|
if (botButtons != null) {
|
|
|
|
botButtons = null;
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.setButtons(null, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat == null && currentUser != null && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0 && botUser == null) {
|
|
|
|
botUser = "";
|
|
|
|
updateBottomOverlay();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated && chatAdapter != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
removeUnreadPlane();
|
2013-10-25 17:19:00 +02:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messageReceivedByServer) {
|
2015-04-09 20:00:14 +02:00
|
|
|
Integer msgId = (Integer) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
Integer newMsgId = (Integer) args[1];
|
|
|
|
TLRPC.Message newMsgObj = (TLRPC.Message) args[2];
|
|
|
|
boolean mediaUpdated = (Boolean) args[3];
|
2014-03-22 23:31:55 +01:00
|
|
|
if (newMsgObj != null) {
|
2014-10-22 22:01:07 +02:00
|
|
|
obj.messageOwner.media = newMsgObj.media;
|
2015-02-01 19:51:02 +01:00
|
|
|
obj.generateThumbs(true);
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
int oldCount = messagesDict.size();
|
|
|
|
MessageObject removed = messagesDict.remove(msgId);
|
2013-10-25 17:19:00 +02:00
|
|
|
messagesDict.put(newMsgId, obj);
|
|
|
|
obj.messageOwner.id = newMsgId;
|
2014-08-22 16:24:33 +02:00
|
|
|
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
|
2015-06-29 19:12:11 +02:00
|
|
|
ArrayList<MessageObject> messArr = new ArrayList<>();
|
|
|
|
messArr.add(obj);
|
|
|
|
ReplyMessageQuery.loadReplyMessagesForMessages(messArr, dialog_id);
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2015-06-29 19:12:11 +02:00
|
|
|
if (oldCount != messagesDict.size()) {
|
|
|
|
int index = messages.indexOf(removed);
|
|
|
|
messages.remove(index);
|
|
|
|
ArrayList<MessageObject> dayArr = messagesByDays.get(removed.dateKey);
|
|
|
|
dayArr.remove(obj);
|
|
|
|
if (dayArr.isEmpty()) {
|
|
|
|
messagesByDays.remove(obj.dateKey);
|
|
|
|
if (index >= 0 && index < messages.size()) {
|
|
|
|
messages.remove(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (mediaUpdated && chatLayoutManager.findLastVisibleItemPosition() >= messages.size() - 1) {
|
2015-04-09 20:00:14 +02:00
|
|
|
moveScrollToLastMessage();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
NotificationsController.getInstance().playOutChatSound();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messageReceivedByAck) {
|
2015-04-09 20:00:14 +02:00
|
|
|
Integer msgId = (Integer) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.messageSendError) {
|
2015-04-09 20:00:14 +02:00
|
|
|
Integer msgId = (Integer) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.chatInfoDidLoaded) {
|
2015-04-09 20:00:14 +02:00
|
|
|
int chatId = (Integer) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentChat != null && chatId == currentChat.id) {
|
2015-04-09 20:00:14 +02:00
|
|
|
info = (TLRPC.ChatParticipants) args[1];
|
2015-03-19 00:09:45 +01:00
|
|
|
if (mentionsAdapter != null) {
|
|
|
|
mentionsAdapter.setChatInfo(info);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
updateOnlineCount();
|
2014-11-11 23:16:17 +01:00
|
|
|
updateSubtitle();
|
2014-10-20 13:30:05 +02:00
|
|
|
if (isBroadcast) {
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().setCurrentChatInfo(info);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (info != null) {
|
|
|
|
hasBotsCommands = false;
|
|
|
|
botInfo.clear();
|
|
|
|
botsCount = 0;
|
|
|
|
for (int a = 0; a < info.participants.size(); a++) {
|
|
|
|
TLRPC.TL_chatParticipant participant = info.participants.get(a);
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
|
|
|
|
if (user != null && (user.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
botsCount++;
|
|
|
|
BotQuery.loadBotInfo(user.id, true, classGuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.setBotsCount(botsCount, hasBotsCommands);
|
|
|
|
}
|
|
|
|
if (mentionsAdapter != null) {
|
|
|
|
mentionsAdapter.setBotsCount(botsCount);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.contactsDidLoaded) {
|
2013-10-25 17:19:00 +02:00
|
|
|
updateContactStatus();
|
2013-12-20 20:25:49 +01:00
|
|
|
updateSubtitle();
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.encryptedChatUpdated) {
|
2015-04-09 20:00:14 +02:00
|
|
|
TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentEncryptedChat != null && chat.id == currentEncryptedChat.id) {
|
|
|
|
currentEncryptedChat = chat;
|
2013-12-20 20:25:49 +01:00
|
|
|
updateContactStatus();
|
2013-10-25 17:19:00 +02:00
|
|
|
updateSecretStatus();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (id == NotificationCenter.messagesReadEncrypted) {
|
2015-04-09 20:00:14 +02:00
|
|
|
int encId = (Integer) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentEncryptedChat != null && currentEncryptedChat.id == encId) {
|
2015-04-09 20:00:14 +02:00
|
|
|
int date = (Integer) args[1];
|
2013-10-25 17:19:00 +02:00
|
|
|
for (MessageObject obj : messages) {
|
2014-04-03 23:18:54 +02:00
|
|
|
if (!obj.isOut()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
continue;
|
2014-10-09 17:55:05 +02:00
|
|
|
} else if (obj.isOut() && !obj.isUnread()) {
|
2013-12-20 20:25:49 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
if (obj.messageOwner.date - 1 <= date) {
|
2014-10-09 17:55:05 +02:00
|
|
|
obj.setIsRead();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (id == NotificationCenter.audioDidReset || id == NotificationCenter.audioPlayStateChanged) {
|
2015-04-09 20:00:14 +02:00
|
|
|
Integer mid = (Integer) args[0];
|
2014-02-28 23:28:25 +01:00
|
|
|
if (chatListView != null) {
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatAudioCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
ChatAudioCell cell = (ChatAudioCell) view;
|
2015-03-19 00:09:45 +01:00
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
|
2015-07-22 20:56:37 +02:00
|
|
|
cell.updateButtonState(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (view instanceof ChatMusicCell) {
|
|
|
|
ChatMusicCell cell = (ChatMusicCell) view;
|
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
|
|
|
|
cell.updateButtonState(false);
|
2014-02-28 23:28:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.audioProgressDidChanged) {
|
2015-04-09 20:00:14 +02:00
|
|
|
Integer mid = (Integer) args[0];
|
2014-02-28 23:28:25 +01:00
|
|
|
if (chatListView != null) {
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatAudioCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
ChatAudioCell cell = (ChatAudioCell) view;
|
2015-03-19 00:09:45 +01:00
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
|
2014-02-28 23:28:25 +01:00
|
|
|
cell.updateProgress();
|
|
|
|
break;
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (view instanceof ChatMusicCell) {
|
|
|
|
ChatMusicCell cell = (ChatMusicCell) view;
|
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
|
|
|
|
MessageObject playing = cell.getMessageObject();
|
|
|
|
MessageObject player = MediaController.getInstance().getPlayingMessageObject();
|
2015-08-13 11:23:31 +02:00
|
|
|
if (player != null) {
|
|
|
|
playing.audioProgress = player.audioProgress;
|
|
|
|
playing.audioProgressSec = player.audioProgressSec;
|
|
|
|
cell.updateProgress();
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.removeAllMessagesFromDialog) {
|
2015-04-09 20:00:14 +02:00
|
|
|
long did = (Long) args[0];
|
2014-10-21 22:35:16 +02:00
|
|
|
if (dialog_id == did) {
|
|
|
|
messages.clear();
|
|
|
|
messagesByDays.clear();
|
|
|
|
messagesDict.clear();
|
2014-11-11 23:16:17 +01:00
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
2014-10-21 22:35:16 +02:00
|
|
|
chatListView.setEmptyView(emptyViewContainer);
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
maxMessageId = Integer.MAX_VALUE;
|
|
|
|
minMessageId = Integer.MIN_VALUE;
|
|
|
|
} else {
|
|
|
|
maxMessageId = Integer.MIN_VALUE;
|
|
|
|
minMessageId = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
maxDate = Integer.MIN_VALUE;
|
|
|
|
minDate = 0;
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.hideActionMode();
|
2014-10-21 22:35:16 +02:00
|
|
|
chatAdapter.notifyDataSetChanged();
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
if (messages.isEmpty()) {
|
|
|
|
if (botButtons != null) {
|
|
|
|
botButtons = null;
|
|
|
|
chatActivityEnterView.setButtons(null, false);
|
|
|
|
}
|
|
|
|
if (currentEncryptedChat == null && currentUser != null && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0 && botUser == null) {
|
|
|
|
botUser = "";
|
|
|
|
updateBottomOverlay();
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.screenshotTook) {
|
2014-04-04 19:58:33 +02:00
|
|
|
updateInformationForScreenshotDetector();
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.blockedUsersDidLoaded) {
|
|
|
|
if (currentUser != null) {
|
|
|
|
boolean oldValue = userBlocked;
|
|
|
|
userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
|
|
|
|
if (oldValue != userBlocked) {
|
|
|
|
updateBottomOverlay();
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
} else if (id == NotificationCenter.FileNewChunkAvailable) {
|
2015-04-09 20:00:14 +02:00
|
|
|
MessageObject messageObject = (MessageObject) args[0];
|
|
|
|
long finalSize = (Long) args[2];
|
2014-09-30 00:48:11 +02:00
|
|
|
if (finalSize != 0 && dialog_id == messageObject.getDialogId()) {
|
2015-03-19 00:09:45 +01:00
|
|
|
MessageObject currentObject = messagesDict.get(messageObject.getId());
|
2014-09-30 00:48:11 +02:00
|
|
|
if (currentObject != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
currentObject.messageOwner.media.video.size = (int) finalSize;
|
2014-09-30 00:48:11 +02:00
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
}
|
2014-10-10 19:16:39 +02:00
|
|
|
} else if (id == NotificationCenter.didCreatedNewDeleteTask) {
|
2015-04-09 20:00:14 +02:00
|
|
|
SparseArray<ArrayList<Integer>> mids = (SparseArray<ArrayList<Integer>>) args[0];
|
2014-10-10 19:16:39 +02:00
|
|
|
boolean changed = false;
|
2015-04-09 20:00:14 +02:00
|
|
|
for (int i = 0; i < mids.size(); i++) {
|
2014-10-10 19:16:39 +02:00
|
|
|
int key = mids.keyAt(i);
|
|
|
|
ArrayList<Integer> arr = mids.get(key);
|
|
|
|
for (Integer mid : arr) {
|
|
|
|
MessageObject messageObject = messagesDict.get(mid);
|
|
|
|
if (messageObject != null) {
|
|
|
|
messageObject.messageOwner.destroyTime = key;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
} else if (id == NotificationCenter.audioDidStarted) {
|
2015-04-09 20:00:14 +02:00
|
|
|
MessageObject messageObject = (MessageObject) args[0];
|
2014-10-21 22:35:16 +02:00
|
|
|
sendSecretMessageRead(messageObject);
|
2015-07-22 20:56:37 +02:00
|
|
|
|
|
|
|
int mid = messageObject.getId();
|
|
|
|
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().getId() == mid) {
|
|
|
|
cell.updateButtonState(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (view instanceof ChatMusicCell) {
|
|
|
|
ChatMusicCell cell = (ChatMusicCell) view;
|
|
|
|
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
|
|
|
|
cell.updateButtonState(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
} else if (id == NotificationCenter.updateMessageMedia) {
|
2015-04-09 20:00:14 +02:00
|
|
|
MessageObject messageObject = (MessageObject) args[0];
|
2015-03-19 00:09:45 +01:00
|
|
|
MessageObject existMessageObject = messagesDict.get(messageObject.getId());
|
2015-01-02 23:15:07 +01:00
|
|
|
if (existMessageObject != null) {
|
|
|
|
existMessageObject.messageOwner.media = messageObject.messageOwner.media;
|
|
|
|
existMessageObject.messageOwner.attachPath = messageObject.messageOwner.attachPath;
|
2015-02-01 19:51:02 +01:00
|
|
|
existMessageObject.generateThumbs(false);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
updateVisibleRows();
|
2015-01-09 13:50:15 +01:00
|
|
|
} else if (id == NotificationCenter.replaceMessagesObjects) {
|
|
|
|
if (dialog_id == (long) args[0]) {
|
|
|
|
boolean changed = false;
|
2015-04-09 20:00:14 +02:00
|
|
|
boolean mediaUpdated = false;
|
2015-01-09 13:50:15 +01:00
|
|
|
ArrayList<MessageObject> messageObjects = (ArrayList<MessageObject>) args[1];
|
|
|
|
for (MessageObject messageObject : messageObjects) {
|
2015-03-19 00:09:45 +01:00
|
|
|
MessageObject old = messagesDict.get(messageObject.getId());
|
2015-01-09 13:50:15 +01:00
|
|
|
if (old != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!mediaUpdated && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
mediaUpdated = true;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
messagesDict.put(old.getId(), messageObject);
|
2015-06-29 19:12:11 +02:00
|
|
|
int index = messages.indexOf(old);
|
|
|
|
if (index >= 0) {
|
|
|
|
messages.set(index, messageObject);
|
|
|
|
chatAdapter.notifyItemChanged(chatAdapter.messagesStartRow + messages.size() - index - 1);
|
2015-01-09 13:50:15 +01:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (mediaUpdated && chatLayoutManager.findLastVisibleItemPosition() >= messages.size() - (chatAdapter.isBot ? 2 : 1)) {
|
2015-04-09 20:00:14 +02:00
|
|
|
moveScrollToLastMessage();
|
|
|
|
}
|
2015-01-09 13:50:15 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
} else if (id == NotificationCenter.notificationsSettingsUpdated) {
|
|
|
|
updateTitleIcons();
|
2015-03-19 00:09:45 +01:00
|
|
|
} else if (id == NotificationCenter.didLoadedReplyMessages) {
|
|
|
|
long did = (Long) args[0];
|
|
|
|
if (did == dialog_id) {
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == NotificationCenter.didReceivedWebpages) {
|
|
|
|
ArrayList<TLRPC.Message> arrayList = (ArrayList<TLRPC.Message>) args[0];
|
|
|
|
boolean updated = false;
|
|
|
|
for (TLRPC.Message message : arrayList) {
|
|
|
|
MessageObject currentMessage = messagesDict.get(message.id);
|
|
|
|
if (currentMessage != null) {
|
|
|
|
currentMessage.messageOwner.media.webpage = message.media.webpage;
|
|
|
|
currentMessage.generateThumbs(true);
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated) {
|
|
|
|
updateVisibleRows();
|
2015-05-03 13:48:36 +02:00
|
|
|
if (chatLayoutManager.findLastVisibleItemPosition() >= messages.size() - 1) {
|
2015-04-09 20:00:14 +02:00
|
|
|
moveScrollToLastMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.didReceivedWebpagesInUpdates) {
|
|
|
|
if (foundWebPage != null) {
|
|
|
|
HashMap<Long, TLRPC.WebPage> hashMap = (HashMap<Long, TLRPC.WebPage>) args[0];
|
|
|
|
for (TLRPC.WebPage webPage : hashMap.values()) {
|
|
|
|
if (webPage.id == foundWebPage.id) {
|
|
|
|
showReplyPanel(!(webPage instanceof TLRPC.TL_webPageEmpty), null, null, webPage, false, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (id == NotificationCenter.messagesReadContent) {
|
|
|
|
ArrayList<Integer> arrayList = (ArrayList<Integer>) args[0];
|
|
|
|
boolean updated = false;
|
|
|
|
for (Integer mid : arrayList) {
|
|
|
|
MessageObject currentMessage = messagesDict.get(mid);
|
|
|
|
if (currentMessage != null) {
|
|
|
|
currentMessage.setContentIsRead();
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated) {
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (id == NotificationCenter.botInfoDidLoaded) {
|
|
|
|
int guid = (Integer) args[1];
|
|
|
|
if (classGuid == guid) {
|
|
|
|
TLRPC.BotInfo info = (TLRPC.BotInfo) args[0];
|
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
if (!info.commands.isEmpty()) {
|
|
|
|
hasBotsCommands = true;
|
|
|
|
}
|
|
|
|
botInfo.put(info.user_id, info);
|
|
|
|
if (chatAdapter != null) {
|
|
|
|
chatAdapter.notifyItemChanged(0);
|
|
|
|
}
|
|
|
|
if (mentionsAdapter != null) {
|
|
|
|
mentionsAdapter.setBotInfo(botInfo);
|
|
|
|
}
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
chatActivityEnterView.setBotsCount(botsCount, hasBotsCommands);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateBotButtons();
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.botKeyboardDidLoaded) {
|
|
|
|
if (dialog_id == (Long) args[1]) {
|
|
|
|
TLRPC.Message message = (TLRPC.Message) args[0];
|
|
|
|
if (message != null) {
|
|
|
|
botButtons = new MessageObject(message, null, false);
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
if (botButtons.messageOwner.reply_markup instanceof TLRPC.TL_replyKeyboardForceReply) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
if (preferences.getInt("answered_" + dialog_id, 0) != botButtons.getId() && (replyingMessageObject == null || chatActivityEnterView.getFieldText() == null)) {
|
|
|
|
botReplyButtons = botButtons;
|
|
|
|
chatActivityEnterView.setButtons(botButtons);
|
|
|
|
showReplyPanel(true, botButtons, null, null, false, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (replyingMessageObject != null && botReplyButtons == replyingMessageObject) {
|
|
|
|
botReplyButtons = null;
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
chatActivityEnterView.setButtons(botButtons);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
botButtons = null;
|
|
|
|
if (chatActivityEnterView != null) {
|
|
|
|
if (replyingMessageObject != null && botReplyButtons == replyingMessageObject) {
|
|
|
|
botReplyButtons = null;
|
|
|
|
showReplyPanel(false, null, null, null, false, true);
|
|
|
|
}
|
|
|
|
chatActivityEnterView.setButtons(botButtons);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.chatSearchResultsAvailable) {
|
|
|
|
if (classGuid == (Integer) args[0]) {
|
|
|
|
int messageId = (Integer) args[1];
|
|
|
|
if (messageId != 0) {
|
|
|
|
scrollToMessageId(messageId, 0, true);
|
|
|
|
}
|
|
|
|
updateSearchButtons((Integer) args[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSearchButtons(int mask) {
|
|
|
|
if (searchUpItem != null) {
|
|
|
|
searchUpItem.setEnabled((mask & 1) != 0);
|
|
|
|
searchDownItem.setEnabled((mask & 2) != 0);
|
|
|
|
ViewProxy.setAlpha(searchUpItem, searchUpItem.isEnabled() ? 1.0f : 0.6f);
|
|
|
|
ViewProxy.setAlpha(searchDownItem, searchDownItem.isEnabled() ? 1.0f : 0.6f);
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 06:01:04 +01:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
protected void onOpenAnimationStart() {
|
|
|
|
NotificationCenter.getInstance().setAnimationInProgress(true);
|
2015-06-29 19:12:11 +02:00
|
|
|
openAnimationEnded = false;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onOpenAnimationEnd() {
|
|
|
|
NotificationCenter.getInstance().setAnimationInProgress(false);
|
2014-11-18 06:01:04 +01:00
|
|
|
openAnimationEnded = true;
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
|
|
|
if (view instanceof ChatMediaCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
ChatMediaCell cell = (ChatMediaCell) view;
|
2014-11-18 06:01:04 +01:00
|
|
|
cell.setAllowedToSetPhoto(true);
|
|
|
|
}
|
|
|
|
}
|
2014-11-19 11:32:27 +01:00
|
|
|
|
|
|
|
if (currentUser != null) {
|
|
|
|
MessagesController.getInstance().loadFullUser(MessagesController.getInstance().getUser(currentUser.id), classGuid);
|
|
|
|
}
|
2014-11-18 06:01:04 +01:00
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
private void updateBottomOverlay() {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (bottomOverlayChatText == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
if (currentUser == null) {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("DeleteThisGroup", R.string.DeleteThisGroup));
|
|
|
|
} else {
|
|
|
|
if (userBlocked) {
|
2015-09-02 00:14:21 +02:00
|
|
|
if ((currentUser.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("BotUnblock", R.string.BotUnblock));
|
|
|
|
} else {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("Unblock", R.string.Unblock));
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (botUser != null) {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("BotStart", R.string.BotStart));
|
2015-09-02 00:14:21 +02:00
|
|
|
chatActivityEnterView.hidePopup(false);
|
2015-06-29 19:12:11 +02:00
|
|
|
if (getParentActivity() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else {
|
|
|
|
bottomOverlayChatText.setText(LocaleController.getString("DeleteThisChat", R.string.DeleteThisChat));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) ||
|
2015-06-29 19:12:11 +02:00
|
|
|
currentUser != null && (UserObject.isDeleted(currentUser) || userBlocked)) {
|
2014-08-22 16:24:33 +02:00
|
|
|
bottomOverlayChat.setVisibility(View.VISIBLE);
|
2015-02-01 19:51:02 +01:00
|
|
|
muteItem.setVisibility(View.GONE);
|
2014-08-22 16:24:33 +02:00
|
|
|
chatActivityEnterView.setFieldFocused(false);
|
2015-06-29 19:12:11 +02:00
|
|
|
chatActivityEnterView.setVisibility(View.INVISIBLE);
|
2014-08-22 16:24:33 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (botUser != null) {
|
|
|
|
bottomOverlayChat.setVisibility(View.VISIBLE);
|
|
|
|
chatActivityEnterView.setVisibility(View.INVISIBLE);
|
|
|
|
} else {
|
|
|
|
chatActivityEnterView.setVisibility(View.VISIBLE);
|
|
|
|
bottomOverlayChat.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
muteItem.setVisibility(View.VISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateContactStatus() {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (addContactItem == null) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentUser == null) {
|
2014-11-17 03:44:57 +01:00
|
|
|
addContactItem.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
|
2014-05-17 01:05:49 +02:00
|
|
|
if (user != null) {
|
|
|
|
currentUser = user;
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat)
|
2014-08-29 23:06:04 +02:00
|
|
|
|| currentUser.id / 1000 == 333 || currentUser.id / 1000 == 777
|
2015-06-29 19:12:11 +02:00
|
|
|
|| UserObject.isDeleted(currentUser)
|
2014-08-29 23:06:04 +02:00
|
|
|
|| ContactsController.getInstance().isLoadingContacts()
|
|
|
|
|| (currentUser.phone != null && currentUser.phone.length() != 0 && ContactsController.getInstance().contactsDict.get(currentUser.id) != null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts()))) {
|
2014-11-17 03:44:57 +01:00
|
|
|
addContactItem.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-11-17 03:44:57 +01:00
|
|
|
addContactItem.setVisibility(View.VISIBLE);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (currentUser.phone != null && currentUser.phone.length() != 0) {
|
2014-11-17 03:44:57 +01:00
|
|
|
addContactItem.setText(LocaleController.getString("AddToContacts", R.string.AddToContacts));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-11-17 03:44:57 +01:00
|
|
|
addContactItem.setText(LocaleController.getString("ShareMyContactInfo", R.string.ShareMyContactInfo));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onResume();
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
checkActionBarMenu();
|
2015-04-09 20:00:14 +02:00
|
|
|
if (replyImageLocation != null && replyImageView != null) {
|
|
|
|
replyImageView.setImage(replyImageLocation, "50_50", (Drawable) null);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
|
2014-07-10 02:15:58 +02:00
|
|
|
NotificationsController.getInstance().setOpennedDialogId(dialog_id);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (scrollToTopOnResume) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (scrollToTopUnReadOnResume && scrollToMessage != null) {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (chatListView != null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
final int yOffset = scrollToMessageMiddleScreen ? Math.max(0, (chatListView.getHeight() - scrollToMessage.getApproximateHeight()) / 2) : 0;
|
2015-05-03 13:48:36 +02:00
|
|
|
chatLayoutManager.scrollToPositionWithOffset(messages.size() - messages.indexOf(scrollToMessage), -chatListView.getPaddingTop() - AndroidUtilities.dp(7) + yOffset);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
moveScrollToLastMessage();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
scrollToTopUnReadOnResume = false;
|
2013-10-25 17:19:00 +02:00
|
|
|
scrollToTopOnResume = false;
|
2014-10-31 20:02:29 +01:00
|
|
|
scrollToMessage = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
paused = false;
|
|
|
|
if (readWhenResume && !messages.isEmpty()) {
|
2014-07-20 23:49:33 +02:00
|
|
|
for (MessageObject messageObject : messages) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (!messageObject.isUnread() && !messageObject.isOut()) {
|
2014-07-20 23:49:33 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
if (!messageObject.isOut()) {
|
2014-10-09 17:55:05 +02:00
|
|
|
messageObject.setIsRead();
|
2014-09-14 01:40:36 +02:00
|
|
|
}
|
2014-07-20 23:49:33 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
readWhenResume = false;
|
2015-03-19 00:09:45 +01:00
|
|
|
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).getId(), readWithMid, 0, readWithDate, true, false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (wasPaused) {
|
|
|
|
wasPaused = false;
|
|
|
|
if (chatAdapter != null) {
|
|
|
|
chatAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-06-20 02:18:13 +02:00
|
|
|
fixLayout(true);
|
2014-02-04 19:36:55 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2015-06-29 19:12:11 +02:00
|
|
|
if (chatActivityEnterView.getFieldText() == null) {
|
|
|
|
String lastMessageText = preferences.getString("dialog_" + dialog_id, null);
|
|
|
|
if (lastMessageText != null) {
|
|
|
|
preferences.edit().remove("dialog_" + dialog_id).commit();
|
|
|
|
chatActivityEnterView.setFieldText(lastMessageText);
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-19 02:23:46 +01:00
|
|
|
preferences.edit().remove("dialog_" + dialog_id).commit();
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (replyingMessageObject == null) {
|
|
|
|
String lastReplyMessage = preferences.getString("reply_" + dialog_id, null);
|
|
|
|
if (lastReplyMessage != null && lastReplyMessage.length() != 0) {
|
|
|
|
preferences.edit().remove("reply_" + dialog_id).commit();
|
|
|
|
try {
|
|
|
|
byte[] bytes = Base64.decode(lastReplyMessage, Base64.DEFAULT);
|
|
|
|
if (bytes != null) {
|
|
|
|
SerializedData data = new SerializedData(bytes);
|
|
|
|
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
|
|
|
|
if (message != null) {
|
|
|
|
replyingMessageObject = new MessageObject(message, MessagesController.getInstance().getUsers(), false);
|
|
|
|
showReplyPanel(true, replyingMessageObject, null, null, false, false);
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
|
|
|
preferences.edit().remove("reply_" + dialog_id).commit();
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
if (bottomOverlayChat.getVisibility() != View.VISIBLE) {
|
|
|
|
chatActivityEnterView.setFieldFocused(true);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
chatActivityEnterView.onResume();
|
2014-04-04 19:58:33 +02:00
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
chatEnterTime = System.currentTimeMillis();
|
|
|
|
chatLeaveTime = 0;
|
|
|
|
}
|
2014-10-01 00:36:18 +02:00
|
|
|
|
|
|
|
if (startVideoEdit != null) {
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-10-01 00:36:18 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-03 13:48:36 +02:00
|
|
|
openVideoEditor(startVideoEdit, false, false);
|
2014-10-01 00:36:18 +02:00
|
|
|
startVideoEdit = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-10-10 19:16:39 +02:00
|
|
|
|
|
|
|
chatListView.setOnItemLongClickListener(onItemLongClickListener);
|
|
|
|
chatListView.setOnItemClickListener(onItemClickListener);
|
|
|
|
chatListView.setLongClickable(true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onPause();
|
2014-12-04 21:27:06 +01:00
|
|
|
if (menuItem != null) {
|
|
|
|
menuItem.closeSubMenu();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
paused = true;
|
2015-05-03 13:48:36 +02:00
|
|
|
wasPaused = true;
|
2014-07-10 02:15:58 +02:00
|
|
|
NotificationsController.getInstance().setOpennedDialogId(0);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (chatActivityEnterView != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
chatActivityEnterView.onPause();
|
2015-02-26 02:32:51 +01:00
|
|
|
String text = chatActivityEnterView.getFieldText();
|
|
|
|
if (text != null) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putString("dialog_" + dialog_id, text);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
chatActivityEnterView.setFieldFocused(false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
if (replyingMessageObject != null) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
try {
|
|
|
|
SerializedData data = new SerializedData();
|
|
|
|
replyingMessageObject.messageOwner.serializeToStream(data);
|
|
|
|
String string = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
|
|
|
|
if (string != null && string.length() != 0) {
|
|
|
|
editor.putString("reply_" + dialog_id, string);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
editor.remove("reply_" + dialog_id);
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
MessagesController.getInstance().cancelTyping(0, dialog_id);
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2014-10-20 20:11:47 +02:00
|
|
|
if (currentEncryptedChat != null) {
|
2014-04-04 19:58:33 +02:00
|
|
|
chatLeaveTime = System.currentTimeMillis();
|
|
|
|
updateInformationForScreenshotDetector();
|
2014-10-20 20:11:47 +02:00
|
|
|
}
|
2014-04-04 19:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateInformationForScreenshotDetector() {
|
2014-10-21 22:35:16 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
ArrayList<Long> visibleMessages = new ArrayList<>();
|
2014-04-04 19:58:33 +02:00
|
|
|
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();
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
if (object != null && object.getId() < 0 && object.messageOwner.random_id != 0) {
|
2014-04-04 19:58:33 +02:00
|
|
|
visibleMessages.add(object.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MediaController.getInstance().setLastEncryptedChatParams(chatEnterTime, chatLeaveTime, currentEncryptedChat, visibleMessages);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-06-20 02:18:13 +02:00
|
|
|
private void fixLayout(final boolean resume) {
|
2014-11-14 16:40:15 +01:00
|
|
|
if (avatarContainer != null) {
|
|
|
|
avatarContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
2014-11-11 23:16:17 +01:00
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
2014-11-14 16:40:15 +01:00
|
|
|
if (avatarContainer != null) {
|
|
|
|
avatarContainer.getViewTreeObserver().removeOnPreDrawListener(this);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
2014-11-11 23:16:17 +01:00
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
2014-11-17 03:44:57 +01:00
|
|
|
} else {
|
|
|
|
selectedMessagesCountTextView.setTextSize(20);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (AndroidUtilities.isSmallTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
2015-02-01 19:51:02 +01:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
} else {
|
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_close_white);
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
int padding = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(48)) / 2;
|
2014-11-17 03:44:57 +01:00
|
|
|
avatarContainer.setPadding(avatarContainer.getPaddingLeft(), padding, avatarContainer.getPaddingRight(), padding);
|
2015-03-19 00:09:45 +01:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) avatarContainer.getLayoutParams();
|
2014-11-17 03:44:57 +01:00
|
|
|
layoutParams.topMargin = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
2014-11-14 16:40:15 +01:00
|
|
|
avatarContainer.setLayoutParams(layoutParams);
|
2015-06-29 19:12:11 +02:00
|
|
|
return true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
});
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
2014-06-20 02:18:13 +02:00
|
|
|
fixLayout(false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void createMenu(View v, boolean single) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar.isActionModeShowed()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
MessageObject message = null;
|
|
|
|
if (v instanceof ChatBaseCell) {
|
2015-03-19 00:09:45 +01:00
|
|
|
message = ((ChatBaseCell) v).getMessageObject();
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (v instanceof ChatActionCell) {
|
2015-03-19 00:09:45 +01:00
|
|
|
message = ((ChatActionCell) v).getMessageObject();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2014-10-20 13:30:05 +02:00
|
|
|
if (message == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
final int type = getMessageType(message);
|
2014-06-13 17:03:06 +02:00
|
|
|
|
|
|
|
selectedObject = null;
|
|
|
|
forwaringMessage = null;
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
selectedMessagesIds.clear();
|
2014-11-17 23:04:31 +01:00
|
|
|
actionBar.hideActionMode();
|
2014-06-13 17:03:06 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (single || type < 2 || type == 20) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (type >= 0) {
|
|
|
|
selectedObject = message;
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
CharSequence[] items = null;
|
2015-03-19 00:09:45 +01:00
|
|
|
int[] options = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-15 21:57:09 +02:00
|
|
|
if (type == 0) {
|
2015-03-19 00:09:45 +01:00
|
|
|
items = new CharSequence[]{LocaleController.getString("Retry", R.string.Retry), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{0, 1};
|
2014-07-15 21:57:09 +02:00
|
|
|
} else if (type == 1) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (currentChat != null && !isBroadcast) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{8, 1};
|
|
|
|
} else {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{1};
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
} else if (type == 20) {
|
2015-03-19 00:09:45 +01:00
|
|
|
items = new CharSequence[]{LocaleController.getString("Retry", R.string.Retry), LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{0, 3, 1};
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (currentEncryptedChat == null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (!isBroadcast && !(currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left))) {
|
|
|
|
if (type == 2) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{8, 2, 1};
|
|
|
|
} else if (type == 3) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{8, 2, 3, 1};
|
|
|
|
} else if (type == 4) {
|
|
|
|
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-07-22 20:56:37 +02:00
|
|
|
String saveString;
|
|
|
|
if (selectedObject.isMusic()) {
|
|
|
|
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
|
|
|
|
} else {
|
|
|
|
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
|
|
|
|
}
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{8, 10, 4, 2, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
} else {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{8, 4, 2, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
} else if (type == 5) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{8, 5, 4, 2, 1};
|
|
|
|
} else if (type == 6) {
|
2015-07-22 20:56:37 +02:00
|
|
|
String saveString;
|
|
|
|
if (selectedObject.isMusic()) {
|
|
|
|
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
|
|
|
|
} else {
|
|
|
|
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
|
|
|
|
}
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("SaveToGallery", R.string.SaveToGallery), saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{8, 7, 10, 6, 2, 1};
|
|
|
|
} else if (type == 7) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("AddToStickers", R.string.AddToStickers), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{8, 2, 9, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (type == 2) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{2, 1};
|
|
|
|
} else if (type == 3) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{2, 3, 1};
|
|
|
|
} else if (type == 4) {
|
|
|
|
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-07-22 20:56:37 +02:00
|
|
|
String saveString;
|
|
|
|
if (selectedObject.isMusic()) {
|
|
|
|
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
|
|
|
|
} else {
|
|
|
|
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
|
|
|
|
}
|
|
|
|
items = new CharSequence[]{saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{10, 4, 2, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
} else {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{4, 2, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
} else if (type == 5) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{5, 4, 2, 1};
|
|
|
|
} else if (type == 6) {
|
2015-07-22 20:56:37 +02:00
|
|
|
String saveString;
|
|
|
|
if (selectedObject.isMusic()) {
|
|
|
|
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
|
|
|
|
} else {
|
|
|
|
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
|
|
|
|
}
|
|
|
|
items = new CharSequence[]{LocaleController.getString("SaveToGallery", R.string.SaveToGallery), saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{7, 10, 6, 2, 1};
|
|
|
|
} else if (type == 7) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("AddToStickers", R.string.AddToStickers), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{8, 2, 9, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (type == 2) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Delete", R.string.Delete)};
|
2015-03-19 00:09:45 +01:00
|
|
|
options = new int[]{1};
|
2014-07-15 21:57:09 +02:00
|
|
|
} else if (type == 3) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
|
2015-03-19 00:09:45 +01:00
|
|
|
options = new int[]{3, 1};
|
2014-07-15 21:57:09 +02:00
|
|
|
} else if (type == 4) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-07-22 20:56:37 +02:00
|
|
|
String saveString;
|
|
|
|
if (selectedObject.isMusic()) {
|
|
|
|
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
|
|
|
|
} else {
|
|
|
|
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
|
|
|
|
}
|
|
|
|
items = new CharSequence[]{saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{10, 4, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
} else {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("Delete", R.string.Delete)};
|
2015-05-21 23:27:27 +02:00
|
|
|
options = new int[]{4, 1};
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
} else if (type == 5) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("Delete", R.string.Delete)};
|
2015-03-19 00:09:45 +01:00
|
|
|
options = new int[]{5, 1};
|
2015-05-21 23:27:27 +02:00
|
|
|
} else if (type == 7) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("AddToStickers", R.string.AddToStickers), LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
options = new int[]{8, 2, 9, 1};
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
final int[] finalOptions = options;
|
2013-10-25 17:19:00 +02:00
|
|
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (finalOptions == null || selectedObject == null || i < 0 || i >= finalOptions.length) {
|
2014-06-13 17:03:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
processSelectedOption(finalOptions[i]);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-02 19:36:57 +02:00
|
|
|
builder.setTitle(LocaleController.getString("Message", R.string.Message));
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.showActionMode();
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2014-11-19 16:17:24 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
|
2015-01-02 23:15:07 +01:00
|
|
|
ArrayList<Object> animators = new ArrayList<>();
|
2014-11-19 16:17:24 +01:00
|
|
|
for (int a = 0; a < actionModeViews.size(); a++) {
|
|
|
|
View view = actionModeViews.get(a);
|
|
|
|
AndroidUtilities.clearDrawableAnimation(view);
|
|
|
|
if (a < 1) {
|
|
|
|
animators.add(ObjectAnimatorProxy.ofFloat(view, "translationX", -AndroidUtilities.dp(56), 0));
|
|
|
|
} else {
|
|
|
|
animators.add(ObjectAnimatorProxy.ofFloat(view, "scaleY", 0.1f, 1.0f));
|
|
|
|
}
|
2014-10-07 22:14:27 +02:00
|
|
|
}
|
2014-11-19 16:17:24 +01:00
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.setDuration(250);
|
|
|
|
animatorSet.start();
|
2014-10-07 22:14:27 +02:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
addToSelectedMessages(message);
|
|
|
|
updateActionModeTitle();
|
|
|
|
updateVisibleRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processSelectedOption(int option) {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (selectedObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (option == 0) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (SendMessagesHelper.getInstance().retrySendMessage(selectedObject, false)) {
|
2015-03-19 00:09:45 +01:00
|
|
|
moveScrollToLastMessage();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else if (option == 1) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-09 13:50:15 +01:00
|
|
|
final MessageObject finalSelectedObject = selectedObject;
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("messages", 1)));
|
|
|
|
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) {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<>();
|
2015-03-19 00:09:45 +01:00
|
|
|
ids.add(finalSelectedObject.getId());
|
2015-05-03 13:48:36 +02:00
|
|
|
removeUnreadPlane();
|
2015-01-09 13:50:15 +01:00
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
if (currentEncryptedChat != null && finalSelectedObject.messageOwner.random_id != 0 && finalSelectedObject.type != 10) {
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
random_ids.add(finalSelectedObject.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (option == 2) {
|
2014-07-15 21:57:09 +02:00
|
|
|
forwaringMessage = selectedObject;
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
2015-06-29 19:12:11 +02:00
|
|
|
args.putInt("dialogsType", 1);
|
2015-07-22 20:56:37 +02:00
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
2014-07-15 21:57:09 +02:00
|
|
|
fragment.setDelegate(this);
|
|
|
|
presentFragment(fragment);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (option == 3) {
|
2015-06-29 19:12:11 +02:00
|
|
|
try {
|
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(selectedObject.messageText);
|
|
|
|
} else {
|
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedObject.messageText);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
|
|
|
} else if (option == 4) {
|
2014-09-30 00:48:11 +02:00
|
|
|
String path = selectedObject.messageOwner.attachPath;
|
2014-10-30 22:27:41 +01:00
|
|
|
if (path != null && path.length() > 0) {
|
|
|
|
File temp = new File(path);
|
|
|
|
if (!temp.exists()) {
|
|
|
|
path = null;
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
if (path == null || path.length() == 0) {
|
|
|
|
path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
|
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
if (selectedObject.type == 3) {
|
2014-09-30 00:48:11 +02:00
|
|
|
MediaController.saveFile(path, getParentActivity(), 1, null);
|
2014-07-15 21:57:09 +02:00
|
|
|
} else if (selectedObject.type == 1) {
|
2014-09-30 00:48:11 +02:00
|
|
|
MediaController.saveFile(path, getParentActivity(), 0, null);
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (selectedObject.type == 8 || selectedObject.type == 9 || selectedObject.type == 14) {
|
2015-02-01 19:51:02 +01:00
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setType(selectedObject.messageOwner.media.document.mime_type);
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
|
2015-02-26 02:32:51 +01:00
|
|
|
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
|
|
|
} else if (option == 5) {
|
|
|
|
File locFile = null;
|
|
|
|
if (selectedObject.messageOwner.attachPath != null && selectedObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
File f = new File(selectedObject.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
|
|
|
locFile = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (locFile == null) {
|
2014-09-25 05:54:35 +02:00
|
|
|
File f = FileLoader.getPathToMessage(selectedObject.messageOwner);
|
2014-07-15 21:57:09 +02:00
|
|
|
if (f.exists()) {
|
|
|
|
locFile = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (locFile != null) {
|
|
|
|
if (LocaleController.getInstance().applyLanguageFile(locFile)) {
|
|
|
|
presentFragment(new LanguageSelectActivity());
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-07-15 21:57:09 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (option == 6 || option == 7) {
|
|
|
|
String path = selectedObject.messageOwner.attachPath;
|
|
|
|
if (path != null && path.length() > 0) {
|
|
|
|
File temp = new File(path);
|
|
|
|
if (!temp.exists()) {
|
|
|
|
path = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (path == null || path.length() == 0) {
|
|
|
|
path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
if (selectedObject.type == 8 || selectedObject.type == 9 || selectedObject.type == 14) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (option == 6) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setType(selectedObject.messageOwner.media.document.mime_type);
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
|
|
|
|
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
|
|
|
|
} else if (option == 7) {
|
|
|
|
MediaController.saveFile(path, getParentActivity(), 0, null);
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
} else if (option == 8) {
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(true, selectedObject, null, null, false, true);
|
2015-05-21 23:27:27 +02:00
|
|
|
} else if (option == 9) {
|
|
|
|
StickersQuery.loadStickers(this, selectedObject.getInputStickerSet());
|
|
|
|
} else if (option == 10) {
|
|
|
|
String fileName = FileLoader.getDocumentFileName(selectedObject.messageOwner.media.document);
|
|
|
|
if (fileName == null || fileName.length() == 0) {
|
|
|
|
fileName = selectedObject.getFileName();
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
String path = selectedObject.messageOwner.attachPath;
|
|
|
|
if (path != null && path.length() > 0) {
|
|
|
|
File temp = new File(path);
|
|
|
|
if (!temp.exists()) {
|
|
|
|
path = null;
|
2014-07-10 23:15:39 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
if (path == null || path.length() == 0) {
|
|
|
|
path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
MediaController.saveFile(path, getParentActivity(), selectedObject.isMusic() ? 3 : 2, fileName);
|
2014-07-13 01:02:21 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
selectedObject = null;
|
2014-07-13 01:02:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public void didSelectDialog(DialogsActivity activity, long did, boolean param) {
|
2014-07-13 01:02:21 +02:00
|
|
|
if (dialog_id != 0 && (forwaringMessage != null || !selectedMessagesIds.isEmpty())) {
|
2015-03-19 00:09:45 +01:00
|
|
|
ArrayList<MessageObject> fmessages = new ArrayList<>();
|
|
|
|
if (forwaringMessage != null) {
|
|
|
|
fmessages.add(forwaringMessage);
|
|
|
|
forwaringMessage = null;
|
|
|
|
} else {
|
|
|
|
ArrayList<Integer> ids = new ArrayList<>(selectedMessagesIds.keySet());
|
|
|
|
Collections.sort(ids);
|
|
|
|
for (Integer id : ids) {
|
|
|
|
MessageObject message = selectedMessagesIds.get(id);
|
|
|
|
if (message != null && id > 0) {
|
|
|
|
fmessages.add(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
|
|
|
selectedMessagesIds.clear();
|
|
|
|
actionBar.hideActionMode();
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (did != dialog_id) {
|
2015-04-09 20:00:14 +02:00
|
|
|
int lower_part = (int) did;
|
2013-10-25 17:19:00 +02:00
|
|
|
if (lower_part != 0) {
|
2014-06-04 01:31:48 +02:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("scrollToTopOnResume", scrollToTopOnResume);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (lower_part > 0) {
|
2014-06-04 01:31:48 +02:00
|
|
|
args.putInt("user_id", lower_part);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (lower_part < 0) {
|
2014-06-04 01:31:48 +02:00
|
|
|
args.putInt("chat_id", -lower_part);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
ChatActivity chatActivity = new ChatActivity(args);
|
2015-03-19 10:27:46 +01:00
|
|
|
if (presentFragment(chatActivity, true)) {
|
2015-04-09 20:00:14 +02:00
|
|
|
chatActivity.showReplyPanel(true, null, fmessages, null, false, false);
|
2015-03-19 10:27:46 +01:00
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
removeSelfFromStack();
|
|
|
|
Activity parentActivity = getParentActivity();
|
|
|
|
if (parentActivity == null) {
|
|
|
|
parentActivity = chatActivity.getParentActivity();
|
|
|
|
}
|
|
|
|
if (parentActivity != null) {
|
|
|
|
parentActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
}
|
2014-11-20 15:45:33 +01:00
|
|
|
}
|
2015-03-19 10:27:46 +01:00
|
|
|
} else {
|
|
|
|
activity.finishFragment();
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
activity.finishFragment();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.finishFragment();
|
2015-03-19 00:09:45 +01:00
|
|
|
moveScrollToLastMessage();
|
2015-04-09 20:00:14 +02:00
|
|
|
showReplyPanel(true, null, fmessages, null, false, AndroidUtilities.isTablet());
|
2014-09-30 00:48:11 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.hideActionMode();
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
updateVisibleRows();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBackPressed() {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar.isActionModeShowed()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
selectedMessagesIds.clear();
|
|
|
|
selectedMessagesCanCopyIds.clear();
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.hideActionMode();
|
2014-06-04 01:31:48 +02:00
|
|
|
updateVisibleRows();
|
|
|
|
return false;
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (chatActivityEnterView.isPopupShowing()) {
|
2015-09-02 00:14:21 +02:00
|
|
|
chatActivityEnterView.hidePopup(true);
|
2013-10-25 17:19:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGoogleMapsInstalled() {
|
|
|
|
try {
|
2015-07-22 20:56:37 +02:00
|
|
|
ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
|
2013-10-25 17:19:00 +02:00
|
|
|
return true;
|
2015-04-09 20:00:14 +02:00
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 17:19:00 +02:00
|
|
|
builder.setMessage("Install Google Maps?");
|
|
|
|
builder.setCancelable(true);
|
2014-03-22 23:31:55 +01:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
|
2015-02-26 02:32:51 +01:00
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
2013-10-25 17:19:00 +02:00
|
|
|
} catch (Exception e) {
|
2013-12-20 20:25:49 +01:00
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-03-19 00:09:45 +01:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2013-10-25 17:19:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVisibleRows() {
|
|
|
|
if (chatListView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = chatListView.getChildAt(a);
|
2014-10-15 20:43:52 +02:00
|
|
|
if (view instanceof ChatBaseCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
ChatBaseCell cell = (ChatBaseCell) view;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
|
|
|
boolean disableSelection = false;
|
|
|
|
boolean selected = false;
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar.isActionModeShowed()) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (selectedMessagesIds.containsKey(cell.getMessageObject().getId())) {
|
2014-02-28 23:28:25 +01:00
|
|
|
view.setBackgroundColor(0x6633b5e5);
|
|
|
|
selected = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
disableSelection = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
|
2014-03-02 10:23:06 +01:00
|
|
|
cell.setMessageObject(cell.getMessageObject());
|
2014-02-28 23:28:25 +01:00
|
|
|
cell.setCheckPressed(!disableSelection, disableSelection && selected);
|
2015-03-19 00:09:45 +01:00
|
|
|
cell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && cell.getMessageObject() != null && cell.getMessageObject().getId() == highlightMessageId);
|
2014-02-11 15:32:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 23:18:54 +02:00
|
|
|
private void alertUserOpenError(MessageObject message) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-04-03 23:18:54 +02:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2014-10-21 22:35:16 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2014-04-03 23:18:54 +02:00
|
|
|
if (message.type == 3) {
|
2014-10-21 22:35:16 +02:00
|
|
|
builder.setMessage(LocaleController.getString("NoPlayerInstalled", R.string.NoPlayerInstalled));
|
2014-04-03 23:18:54 +02:00
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.messageOwner.media.document.mime_type));
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2014-04-03 23:18:54 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
|
|
|
public void updatePhotoAtIndex(int index) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
@Override
|
2014-06-12 03:13:15 +02:00
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (messageObject == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
int count = chatListView.getChildCount();
|
|
|
|
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
MessageObject messageToOpen = null;
|
|
|
|
ImageReceiver imageReceiver = null;
|
|
|
|
View view = chatListView.getChildAt(a);
|
2015-08-13 11:23:31 +02:00
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
ChatBaseCell cell = (ChatBaseCell) view;
|
2014-06-11 01:05:54 +02:00
|
|
|
MessageObject message = cell.getMessageObject();
|
2015-03-19 00:09:45 +01:00
|
|
|
if (message != null && message.getId() == messageObject.getId()) {
|
2014-06-11 01:05:54 +02:00
|
|
|
messageToOpen = message;
|
|
|
|
imageReceiver = cell.getPhotoImage();
|
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
} else if (view instanceof ChatActionCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
ChatActionCell cell = (ChatActionCell) view;
|
2014-10-15 20:43:52 +02:00
|
|
|
MessageObject message = cell.getMessageObject();
|
2015-03-19 00:09:45 +01:00
|
|
|
if (message != null && message.getId() == messageObject.getId()) {
|
2014-10-15 20:43:52 +02:00
|
|
|
messageToOpen = message;
|
|
|
|
imageReceiver = cell.getPhotoImage();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageToOpen != null) {
|
|
|
|
int coords[] = new int[2];
|
|
|
|
view.getLocationInWindow(coords);
|
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
2014-07-03 00:39:05 +02:00
|
|
|
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
|
2014-06-11 01:05:54 +02:00
|
|
|
object.parentView = chatListView;
|
|
|
|
object.imageReceiver = imageReceiver;
|
2014-11-17 03:44:57 +01:00
|
|
|
object.thumb = imageReceiver.getBitmap();
|
|
|
|
object.radius = imageReceiver.getRoundRadius();
|
2014-06-11 01:05:54 +02:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
@Override
|
|
|
|
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-11 02:22:42 +02:00
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void willHidePhotoViewer() {
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public boolean isPhotoChecked(int index) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void setPhotoChecked(int index) {
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void cancelButtonPressed() {
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void sendButtonPressed(int index) {
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public int getSelectedCount() {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-11 02:22:42 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public class ChatActivityAdapter extends RecyclerView.Adapter {
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
private Context mContext;
|
2015-06-29 19:12:11 +02:00
|
|
|
private boolean isBot;
|
|
|
|
private int rowCount;
|
|
|
|
private int botInfoRow;
|
|
|
|
private int loadingUpRow;
|
|
|
|
private int loadingDownRow;
|
|
|
|
private int messagesStartRow;
|
|
|
|
private int messagesEndRow;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public ChatActivityAdapter(Context context) {
|
2013-10-25 17:19:00 +02:00
|
|
|
mContext = context;
|
2015-06-29 19:12:11 +02:00
|
|
|
isBot = currentUser != null && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateRows() {
|
|
|
|
rowCount = 0;
|
|
|
|
if (currentUser != null && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0) {
|
|
|
|
botInfoRow = rowCount++;
|
|
|
|
} else {
|
|
|
|
botInfoRow = -1;
|
|
|
|
}
|
|
|
|
if (!messages.isEmpty()) {
|
|
|
|
if (!endReached) {
|
|
|
|
loadingUpRow = rowCount++;
|
|
|
|
} else {
|
|
|
|
loadingUpRow = -1;
|
|
|
|
}
|
|
|
|
messagesStartRow = rowCount;
|
|
|
|
rowCount += messages.size();
|
|
|
|
messagesEndRow = rowCount;
|
|
|
|
if (!forward_end_reached) {
|
|
|
|
loadingDownRow = rowCount++;
|
|
|
|
} else {
|
|
|
|
loadingDownRow = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
loadingUpRow = -1;
|
|
|
|
loadingDownRow = -1;
|
|
|
|
messagesStartRow = -1;
|
|
|
|
messagesEndRow = -1;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private class Holder extends RecyclerView.ViewHolder {
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public Holder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public int getItemCount() {
|
2015-06-29 19:12:11 +02:00
|
|
|
return rowCount;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
2015-05-21 23:27:27 +02:00
|
|
|
return RecyclerListView.NO_ID;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view = null;
|
|
|
|
if (viewType == 0) {
|
|
|
|
if (!chatMessageCellsCache.isEmpty()) {
|
|
|
|
view = chatMessageCellsCache.get(0);
|
|
|
|
chatMessageCellsCache.remove(0);
|
|
|
|
} else {
|
2014-03-31 16:14:49 +02:00
|
|
|
view = new ChatMessageCell(mContext);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (viewType == 1) {
|
|
|
|
if (!chatMediaCellsCache.isEmpty()) {
|
|
|
|
view = chatMediaCellsCache.get(0);
|
|
|
|
chatMediaCellsCache.remove(0);
|
|
|
|
} else {
|
2014-03-31 16:14:49 +02:00
|
|
|
view = new ChatMediaCell(mContext);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (viewType == 2) {
|
|
|
|
view = new ChatAudioCell(mContext);
|
|
|
|
} else if (viewType == 3) {
|
|
|
|
view = new ChatContactCell(mContext);
|
|
|
|
} else if (viewType == 4) {
|
|
|
|
view = new ChatActionCell(mContext);
|
|
|
|
} else if (viewType == 5) {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = new ChatLoadingCell(mContext);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (viewType == 6) {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = new ChatUnreadCell(mContext);
|
|
|
|
} else if (viewType == 7) {
|
|
|
|
view = new BotHelpCell(mContext);
|
|
|
|
((BotHelpCell) view).setDelegate(new BotHelpCell.BotHelpCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didPressUrl(String url) {
|
|
|
|
if (url.startsWith("@")) {
|
|
|
|
MessagesController.openByUserName(url.substring(1), ChatActivity.this, 0);
|
|
|
|
} else if (url.startsWith("#")) {
|
2015-07-22 20:56:37 +02:00
|
|
|
DialogsActivity fragment = new DialogsActivity(null);
|
2015-06-29 19:12:11 +02:00
|
|
|
fragment.setSearchString(url);
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (url.startsWith("/")) {
|
|
|
|
chatActivityEnterView.setCommand(null, url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (viewType == 8) {
|
|
|
|
view = new ChatMusicCell(mContext);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
((ChatBaseCell) view).setDelegate(new ChatBaseCell.ChatBaseCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user) {
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
processRowSelect(cell);
|
|
|
|
return;
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (user != null && user.id != UserConfig.getClientUserId()) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", user.id);
|
|
|
|
presentFragment(new ProfileActivity(args));
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2014-04-01 03:00:35 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void didPressedCancelSendButton(ChatBaseCell cell) {
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message.messageOwner.send_state != 0) {
|
|
|
|
SendMessagesHelper.getInstance().cancelSendingMessage(message);
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2014-04-01 03:00:35 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void didLongPressed(ChatBaseCell cell) {
|
|
|
|
createMenu(cell, false);
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public boolean canPerformActions() {
|
|
|
|
return actionBar != null && !actionBar.isActionModeShowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-02 00:14:21 +02:00
|
|
|
public void didPressUrl(MessageObject messageObject, final ClickableSpan url) {
|
|
|
|
if (url instanceof URLSpanNoUnderline) {
|
|
|
|
String str = ((URLSpanNoUnderline) url).getURL();
|
|
|
|
if (str.startsWith("@")) {
|
|
|
|
MessagesController.openByUserName(str.substring(1), ChatActivity.this, 0);
|
|
|
|
} else if (str.startsWith("#")) {
|
|
|
|
DialogsActivity fragment = new DialogsActivity(null);
|
|
|
|
fragment.setSearchString(str);
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (str.startsWith("/")) {
|
|
|
|
chatActivityEnterView.setCommand(messageObject, str);
|
|
|
|
}
|
|
|
|
} else if (url instanceof URLSpanReplacement) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setMessage(LocaleController.formatString("OpenUrlAlert", R.string.OpenUrlAlert, ((URLSpanReplacement) url).getURL()));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
try {
|
|
|
|
url.onClick(fragmentView);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showDialog(builder.create());
|
|
|
|
} else {
|
|
|
|
url.onClick(fragmentView);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
|
|
|
public void needOpenWebView(String url, String title, String originalUrl, int w, int h) {
|
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(mContext);
|
|
|
|
builder.setCustomView(new WebFrameLayout(mContext, builder.create(), title, originalUrl, url, w, h));
|
2015-07-22 20:56:37 +02:00
|
|
|
builder.setUseFullWidth(true);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void didPressReplyMessage(ChatBaseCell cell, int id) {
|
|
|
|
scrollToMessageId(id, cell.getMessageObject().getId(), true);
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didClickedImage(ChatBaseCell cell) {
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
if (message.isSendError()) {
|
|
|
|
createMenu(cell, false);
|
|
|
|
return;
|
|
|
|
} else if (message.isSending()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (message.type == 1 || message.type == 0) {
|
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
PhotoViewer.getInstance().openPhoto(message, ChatActivity.this);
|
|
|
|
} else if (message.type == 3) {
|
|
|
|
sendSecretMessageRead(message);
|
|
|
|
try {
|
2015-05-03 13:48:36 +02:00
|
|
|
File f = null;
|
|
|
|
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
|
|
|
|
f = new File(message.messageOwner.attachPath);
|
|
|
|
}
|
|
|
|
if (f == null || f != null && !f.exists()) {
|
|
|
|
f = FileLoader.getPathToMessage(message.messageOwner);
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
|
|
|
} catch (Exception e) {
|
|
|
|
alertUserOpenError(message);
|
|
|
|
}
|
|
|
|
} else if (message.type == 4) {
|
|
|
|
if (!isGoogleMapsInstalled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LocationActivity fragment = new LocationActivity();
|
|
|
|
fragment.setMessageObject(message);
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else if (message.type == 9) {
|
|
|
|
File f = null;
|
|
|
|
String fileName = message.getFileName();
|
|
|
|
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
|
|
|
|
f = new File(message.messageOwner.attachPath);
|
|
|
|
}
|
|
|
|
if (f == null || f != null && !f.exists()) {
|
|
|
|
f = FileLoader.getPathToMessage(message.messageOwner);
|
|
|
|
}
|
|
|
|
if (f != null && f.exists()) {
|
|
|
|
String realMimeType = null;
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
if (message.type == 8 || message.type == 9) {
|
|
|
|
MimeTypeMap myMime = MimeTypeMap.getSingleton();
|
|
|
|
int idx = fileName.lastIndexOf(".");
|
|
|
|
if (idx != -1) {
|
|
|
|
String ext = fileName.substring(idx + 1);
|
|
|
|
realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
|
|
|
|
if (realMimeType == null) {
|
|
|
|
realMimeType = message.messageOwner.media.document.mime_type;
|
|
|
|
if (realMimeType == null || realMimeType.length() == 0) {
|
|
|
|
realMimeType = null;
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
if (realMimeType != null) {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), realMimeType);
|
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
2014-08-29 23:06:04 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2015-08-13 11:23:31 +02:00
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (realMimeType != null) {
|
|
|
|
try {
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
|
|
|
} catch (Exception e) {
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
2015-05-03 13:48:36 +02:00
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
2014-08-29 23:06:04 +02:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
} else {
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
2014-08-29 23:06:04 +02:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
alertUserOpenError(message);
|
2014-08-29 23:06:04 +02:00
|
|
|
}
|
2014-04-03 23:18:54 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
if (view instanceof ChatMediaCell) {
|
|
|
|
((ChatMediaCell) view).setAllowedToSetPhoto(openAnimationEnded);
|
|
|
|
((ChatMediaCell) view).setMediaDelegate(new ChatMediaCell.ChatMediaCellDelegate() {
|
2014-10-15 20:43:52 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void didPressedOther(ChatMediaCell cell) {
|
|
|
|
createMenu(cell, true);
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
});
|
|
|
|
} else if (view instanceof ChatContactCell) {
|
|
|
|
((ChatContactCell) view).setContactDelegate(new ChatContactCell.ChatContactCellDelegate() {
|
2014-09-25 16:57:17 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void didClickAddButton(ChatContactCell cell, TLRPC.User user) {
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
processRowSelect(cell);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MessageObject messageObject = cell.getMessageObject();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", messageObject.messageOwner.media.user_id);
|
|
|
|
args.putString("phone", messageObject.messageOwner.media.phone_number);
|
|
|
|
args.putBoolean("addContact", true);
|
|
|
|
presentFragment(new ContactAddActivity(args));
|
2014-09-25 16:57:17 +02:00
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
|
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void didClickPhone(ChatContactCell cell) {
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
processRowSelect(cell);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final MessageObject messageObject = cell.getMessageObject();
|
|
|
|
if (getParentActivity() == null || messageObject.messageOwner.media.phone_number == null || messageObject.messageOwner.media.phone_number.length() == 0) {
|
|
|
|
return;
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setItems(new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (i == 1) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + messageObject.messageOwner.media.phone_number));
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else if (i == 0) {
|
2015-06-29 19:12:11 +02:00
|
|
|
try {
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(messageObject.messageOwner.media.phone_number);
|
|
|
|
} else {
|
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", messageObject.messageOwner.media.phone_number);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
});
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (view instanceof ChatMusicCell) {
|
|
|
|
((ChatMusicCell) view).setMusicDelegate(new ChatMusicCell.ChatMusicCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public boolean needPlayMusic(MessageObject messageObject) {
|
|
|
|
return MediaController.getInstance().setPlaylist(messages, messageObject);
|
|
|
|
}
|
|
|
|
});
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (view instanceof ChatActionCell) {
|
|
|
|
((ChatActionCell) view).setDelegate(new ChatActionCell.ChatActionCellDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didClickedImage(ChatActionCell cell) {
|
|
|
|
MessageObject message = cell.getMessageObject();
|
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
PhotoViewer.getInstance().openPhoto(message, ChatActivity.this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didLongPressed(ChatActionCell cell) {
|
|
|
|
createMenu(cell, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void needOpenUserProfile(int uid) {
|
|
|
|
if (uid != UserConfig.getClientUserId()) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", uid);
|
|
|
|
presentFragment(new ProfileActivity(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
return new Holder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (position == botInfoRow) {
|
|
|
|
BotHelpCell helpView = (BotHelpCell) holder.itemView;
|
|
|
|
helpView.setText(!botInfo.isEmpty() ? botInfo.get(currentUser.id).description : null);
|
|
|
|
} else if (position == loadingDownRow || position == loadingUpRow) {
|
|
|
|
ChatLoadingCell loadingCell = (ChatLoadingCell) holder.itemView;
|
|
|
|
loadingCell.setProgressVisible(loadsCount > 1);
|
|
|
|
} else if (position >= messagesStartRow && position < messagesEndRow) {
|
|
|
|
MessageObject message = messages.get(messages.size() - (position - messagesStartRow) - 1);
|
|
|
|
View view = holder.itemView;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
boolean selected = false;
|
|
|
|
boolean disableSelection = false;
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
if (selectedMessagesIds.containsKey(message.getId())) {
|
|
|
|
view.setBackgroundColor(0x6633b5e5);
|
|
|
|
selected = true;
|
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
disableSelection = true;
|
2014-10-15 20:43:52 +02:00
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(0);
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (view instanceof ChatBaseCell) {
|
|
|
|
ChatBaseCell baseCell = (ChatBaseCell) view;
|
|
|
|
baseCell.isChat = currentChat != null;
|
|
|
|
baseCell.setMessageObject(message);
|
|
|
|
baseCell.setCheckPressed(!disableSelection, disableSelection && selected);
|
|
|
|
if (view instanceof ChatAudioCell && MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_AUDIO)) {
|
|
|
|
((ChatAudioCell) view).downloadAudioIfNeed();
|
|
|
|
}
|
|
|
|
baseCell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && message.getId() == highlightMessageId);
|
|
|
|
} else if (view instanceof ChatActionCell) {
|
|
|
|
ChatActionCell actionCell = (ChatActionCell) view;
|
|
|
|
actionCell.setMessageObject(message);
|
|
|
|
} else if (view instanceof ChatUnreadCell) {
|
|
|
|
ChatUnreadCell unreadCell = (ChatUnreadCell) view;
|
|
|
|
unreadCell.setText(LocaleController.formatPluralString("NewMessages", unread_to_load));
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public int getItemViewType(int position) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (position == loadingUpRow || position == loadingDownRow) {
|
2014-08-29 23:06:04 +02:00
|
|
|
return 5;
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (position == botInfoRow) {
|
|
|
|
return 7;
|
|
|
|
} else if (position >= messagesStartRow && position < messagesEndRow) {
|
|
|
|
return messages.get(messages.size() - (position - messagesStartRow) - 1).contentType;
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return 5;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
|
|
|
|
if (holder.itemView instanceof ChatBaseCell) {
|
|
|
|
ChatBaseCell baseCell = (ChatBaseCell) holder.itemView;
|
|
|
|
baseCell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && baseCell.getMessageObject().getId() == highlightMessageId);
|
|
|
|
}
|
|
|
|
if (holder.itemView instanceof ChatMessageCell) {
|
|
|
|
final ChatMessageCell messageCell = (ChatMessageCell) holder.itemView;
|
|
|
|
messageCell.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
messageCell.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
messageCell.getLocalVisibleRect(scrollRect);
|
|
|
|
messageCell.setVisiblePart(scrollRect.top, scrollRect.bottom - scrollRect.top);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public void updateRowWithMessageObject(MessageObject messageObject) {
|
|
|
|
int index = messages.indexOf(messageObject);
|
|
|
|
if (index == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
notifyItemChanged(messagesStartRow + messages.size() - index - 1);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeMessageObject(MessageObject messageObject) {
|
|
|
|
int index = messages.indexOf(messageObject);
|
|
|
|
if (index == -1) {
|
|
|
|
return;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
messages.remove(index);
|
2015-06-29 19:12:11 +02:00
|
|
|
notifyItemRemoved(messagesStartRow + messages.size() - index - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyDataSetChanged() {
|
|
|
|
updateRows();
|
|
|
|
super.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemChanged(int position) {
|
|
|
|
updateRows();
|
|
|
|
super.notifyItemChanged(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemRangeChanged(int positionStart, int itemCount) {
|
|
|
|
updateRows();
|
|
|
|
super.notifyItemRangeChanged(positionStart, itemCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemInserted(int position) {
|
|
|
|
updateRows();
|
|
|
|
super.notifyItemInserted(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemMoved(int fromPosition, int toPosition) {
|
|
|
|
updateRows();
|
|
|
|
super.notifyItemMoved(fromPosition, toPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemRangeInserted(int positionStart, int itemCount) {
|
|
|
|
updateRows();
|
|
|
|
super.notifyItemRangeInserted(positionStart, itemCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemRemoved(int position) {
|
|
|
|
updateRows();
|
|
|
|
super.notifyItemRemoved(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
|
|
|
updateRows();
|
|
|
|
super.notifyItemRangeRemoved(positionStart, itemCount);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|