NekoX/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java

8879 lines
450 KiB
Java
Raw Normal View History

2013-10-25 17:19:00 +02:00
/*
2015-10-29 18:10:07 +01:00
* This is the source code of Telegram for Android v. 3.x.x.
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-2016.
2013-10-25 17:19:00 +02:00
*/
package org.telegram.ui;
2015-10-29 18:10:07 +01:00
import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
2013-10-25 17:19:00 +02:00
import android.app.Activity;
import android.app.AlertDialog;
2015-09-24 22:52:02 +02:00
import android.app.Dialog;
2013-10-25 17:19:00 +02:00
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
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;
2016-04-22 15:49:00 +02:00
import android.graphics.Canvas;
2013-10-25 17:19:00 +02:00
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
2013-10-25 17:19:00 +02:00
import android.net.Uri;
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;
2016-10-11 13:57:01 +02:00
import android.support.v4.content.FileProvider;
2016-05-25 23:49:47 +02:00
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
2016-05-25 23:49:47 +02:00
import android.text.Spanned;
import android.text.TextUtils;
2015-09-02 00:14:21 +02:00
import android.text.style.ClickableSpan;
2016-03-06 02:49:31 +01:00
import android.text.style.URLSpan;
2014-10-10 19:16:39 +02:00
import android.util.SparseArray;
2015-09-24 22:52:02 +02:00
import android.util.SparseIntArray;
2014-11-14 16:40:15 +01:00
import android.util.TypedValue;
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;
2016-03-16 13:26:32 +01:00
import android.view.WindowManager;
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;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
2013-10-25 17:19:00 +02:00
import android.widget.TextView;
import android.widget.Toast;
2013-10-25 17:19:00 +02:00
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2013-10-25 17:19:00 +02:00
import org.telegram.PhoneFormat.PhoneFormat;
2016-10-11 13:57:01 +02:00
import org.telegram.messenger.BuildConfig;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.ChatObject;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MediaController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.messenger.NotificationsController;
import org.telegram.messenger.SecretChatHelper;
import org.telegram.messenger.SendMessagesHelper;
import org.telegram.messenger.UserObject;
2015-11-26 22:04:02 +01:00
import org.telegram.messenger.Utilities;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.VideoEditedInfo;
2016-04-22 15:49:00 +02:00
import org.telegram.messenger.browser.Browser;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.query.BotQuery;
import org.telegram.messenger.query.DraftQuery;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.query.MessagesSearchQuery;
2016-03-16 13:26:32 +01:00
import org.telegram.messenger.query.MessagesQuery;
2016-05-25 23:49:47 +02:00
import org.telegram.messenger.query.SearchQuery;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.query.StickersQuery;
2016-05-25 23:49:47 +02:00
import org.telegram.messenger.support.widget.GridLayoutManager;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.support.widget.LinearLayoutManager;
import org.telegram.messenger.support.widget.RecyclerView;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLoader;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.ContactsController;
2013-12-20 20:25:49 +01:00
import org.telegram.messenger.FileLog;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.MessageObject;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
2013-10-25 17:19:00 +02:00
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.ActionBar.ActionBarLayout;
2015-10-29 18:10:07 +01:00
import org.telegram.ui.ActionBar.BackDrawable;
2015-05-21 23:27:27 +02:00
import org.telegram.ui.ActionBar.BottomSheet;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.ActionBar.SimpleTextView;
import org.telegram.ui.Adapters.MentionsAdapter;
2015-01-02 23:15:07 +01:00
import org.telegram.ui.Adapters.StickersAdapter;
import org.telegram.messenger.AnimatorListenerAdapterProxy;
2014-10-14 22:36:15 +02:00
import org.telegram.ui.Cells.ChatActionCell;
2015-06-29 19:12:11 +02:00
import org.telegram.ui.Cells.ChatLoadingCell;
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;
import org.telegram.ui.Cells.ChatMessageCell;
2015-06-29 19:12:11 +02:00
import org.telegram.ui.Cells.ChatUnreadCell;
2016-03-16 13:26:32 +01:00
import org.telegram.ui.Cells.CheckBoxCell;
2016-10-11 13:57:01 +02:00
import org.telegram.ui.Cells.ContextLinkCell;
2015-06-29 19:12:11 +02:00
import org.telegram.ui.Components.AlertsCreator;
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;
import org.telegram.ui.Components.ChatActivityEnterView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.ImageReceiver;
2016-05-25 23:49:47 +02:00
import org.telegram.ui.Components.ChatAttachAlert;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.Components.ChatAvatarContainer;
2016-10-11 13:57:01 +02:00
import org.telegram.ui.Components.ChatBigEmptyView;
2016-05-25 23:49:47 +02:00
import org.telegram.ui.Components.ContextProgressView;
import org.telegram.ui.Components.ExtendedGridLayoutManager;
2015-10-29 18:10:07 +01:00
import org.telegram.ui.Components.PlayerView;
import org.telegram.ui.Components.LayoutHelper;
2015-10-29 18:10:07 +01:00
import org.telegram.ui.Components.NumberTextView;
2015-01-02 23:15:07 +01:00
import org.telegram.ui.Components.RecyclerListView;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.Components.ShareAlert;
2016-05-25 23:49:47 +02:00
import org.telegram.ui.Components.Size;
2015-05-21 23:27:27 +02:00
import org.telegram.ui.Components.SizeNotifierFrameLayout;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.Components.StickersAlert;
import org.telegram.ui.ActionBar.Theme;
2015-10-29 18:10:07 +01:00
import org.telegram.ui.Components.URLSpanBotCommand;
2015-09-02 00:14:21 +02:00
import org.telegram.ui.Components.URLSpanNoUnderline;
import org.telegram.ui.Components.URLSpanReplacement;
2016-05-25 23:49:47 +02:00
import org.telegram.ui.Components.URLSpanUserMention;
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;
import java.util.concurrent.Semaphore;
2015-11-26 22:04:02 +01:00
import java.util.regex.Matcher;
2013-10-25 17:19:00 +02:00
2015-11-26 22:04:02 +01:00
@SuppressWarnings("unchecked")
2016-04-22 15:49:00 +02:00
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate,
2014-10-15 20:43:52 +02:00
PhotoViewer.PhotoViewerProvider {
protected TLRPC.Chat currentChat;
protected TLRPC.User currentUser;
protected TLRPC.EncryptedChat currentEncryptedChat;
private boolean userBlocked = false;
private ArrayList<ChatMessageCell> chatMessageCellsCache = new ArrayList<>();
2015-09-24 22:52:02 +02:00
private Dialog closeChatDialog;
private FrameLayout progressView;
private FrameLayout bottomOverlay;
2015-11-26 22:04:02 +01:00
protected ChatActivityEnterView chatActivityEnterView;
2014-11-19 16:17:24 +01:00
private View timeItem2;
2014-11-17 03:44:57 +01:00
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;
2016-05-25 23:49:47 +02:00
private ActionBarMenuItem editDoneItem;
private ContextProgressView editDoneItemProgress;
private AnimatorSet editDoneItemAnimation;
2014-11-17 03:44:57 +01:00
private TextView addContactItem;
2015-05-21 23:27:27 +02:00
private RecyclerListView chatListView;
private LinearLayoutManager chatLayoutManager;
private ChatActivityAdapter chatAdapter;
private TextView bottomOverlayChatText;
private FrameLayout bottomOverlayChat;
private FrameLayout emptyViewContainer;
2016-10-11 13:57:01 +02:00
private ChatBigEmptyView bigEmptyView;
2015-01-02 23:15:07 +01:00
private ArrayList<View> actionModeViews = new ArrayList<>();
2016-04-22 15:49:00 +02:00
private ChatAvatarContainer avatarContainer;
2013-10-25 17:19:00 +02:00
private TextView bottomOverlayText;
2015-10-29 18:10:07 +01:00
private NumberTextView selectedMessagesCountTextView;
2016-05-25 23:49:47 +02:00
private FrameLayout actionModeTitleContainer;
private SimpleTextView actionModeTextView;
private SimpleTextView actionModeSubTextView;
2015-01-02 23:15:07 +01:00
private RecyclerListView stickersListView;
2016-03-06 02:49:31 +01:00
private RecyclerListView.OnItemClickListener stickersOnItemClickListener;
2016-04-22 15:49:00 +02:00
private RecyclerListView.OnItemClickListener mentionsOnItemClickListener;
2015-01-02 23:15:07 +01:00
private StickersAdapter stickersAdapter;
private FrameLayout stickersPanel;
2015-02-01 19:51:02 +01:00
private TextView muteItem;
private FrameLayout pagedownButton;
private boolean pagedownButtonShowedByScroll;
private TextView pagedownButtonCounter;
private BackupImageView replyImageView;
2016-05-25 23:49:47 +02:00
private SimpleTextView replyNameTextView;
private SimpleTextView replyObjectTextView;
private ImageView replyIconImageView;
private MentionsAdapter mentionsAdapter;
2016-04-22 15:49:00 +02:00
private FrameLayout mentionContainer;
private RecyclerListView mentionListView;
private LinearLayoutManager mentionLayoutManager;
2016-05-25 23:49:47 +02:00
private ExtendedGridLayoutManager mentionGridLayoutManager;
private AnimatorSet mentionListAnimation;
2016-05-25 23:49:47 +02:00
private ChatAttachAlert chatAttachAlert;
2015-09-24 22:52:02 +02:00
private LinearLayout reportSpamView;
private AnimatorSet reportSpamViewAnimator;
2015-09-24 22:52:02 +02:00
private TextView addToContactsButton;
private TextView reportSpamButton;
2015-11-26 22:04:02 +01:00
private FrameLayout reportSpamContainer;
2015-10-29 18:10:07 +01:00
private PlayerView playerView;
private TextView gifHintTextView;
private View emojiButtonRed;
2016-03-16 13:26:32 +01:00
private FrameLayout pinnedMessageView;
private AnimatorSet pinnedMessageViewAnimator;
2016-10-11 13:57:01 +02:00
private BackupImageView pinnedMessageImageView;
2016-04-22 15:49:00 +02:00
private SimpleTextView pinnedMessageNameTextView;
private SimpleTextView pinnedMessageTextView;
private FrameLayout alertView;
private Runnable hideAlertViewRunnable;
private TextView alertNameTextView;
private TextView alertTextView;
private AnimatorSet alertViewAnimator;
private FrameLayout searchContainer;
private ImageView searchUpButton;
private ImageView searchDownButton;
private SimpleTextView searchCountText;
2016-04-22 15:49:00 +02:00
private boolean mentionListViewIgnoreLayout;
private int mentionListViewScrollOffsetY;
private int mentionListViewLastViewTop;
private int mentionListViewLastViewPosition;
private boolean mentionListViewIsScrolling;
2016-03-16 13:26:32 +01:00
private MessageObject pinnedMessageObject;
private int loadingPinnedMessage;
2015-10-29 18:10:07 +01:00
private ObjectAnimator pagedownButtonAnimation;
private AnimatorSet replyButtonAnimation;
2015-09-24 22:52:02 +02:00
private boolean openSearchKeyboard;
2016-03-16 13:26:32 +01:00
private boolean waitingForReplyMessageLoad;
2015-01-02 23:15:07 +01:00
private boolean allowStickersPanel;
private boolean allowContextBotPanel;
private boolean allowContextBotPanelSecond = true;
private AnimatorSet runningAnimation;
2013-10-25 17:19:00 +02:00
private MessageObject selectedObject;
private ArrayList<MessageObject> forwardingMessages;
2013-10-25 17:19:00 +02:00
private MessageObject forwaringMessage;
private MessageObject replyingMessageObject;
2016-05-25 23:49:47 +02:00
private int editingMessageObjectReqId;
2013-10-25 17:19:00 +02:00
private boolean paused = true;
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;
2016-10-11 13:57:01 +02:00
private TLRPC.FileLocation pinnedImageLocation;
2015-09-24 22:52:02 +02:00
private int linkSearchRequestId;
2015-04-09 20:00:14 +02:00
private TLRPC.WebPage foundWebPage;
2015-11-26 22:04:02 +01:00
private ArrayList<CharSequence> foundUrls;
2015-04-09 20:00:14 +02:00
private String pendingLinkSearchString;
private Runnable pendingWebPageTimeoutRunnable;
private Runnable waitingForCharaterEnterRunnable;
2015-11-26 22:04:02 +01:00
private boolean openAnimationEnded;
2014-11-18 06:01:04 +01:00
2015-11-26 22:04:02 +01:00
private int readWithDate;
private int readWithMid;
private boolean scrollToTopOnResume;
2016-05-25 23:49:47 +02:00
private boolean forceScrollToTop;
2015-11-26 22:04:02 +01:00
private boolean scrollToTopUnReadOnResume;
2013-10-25 17:19:00 +02:00
private long dialog_id;
2015-11-26 22:04:02 +01:00
private int lastLoadIndex;
private boolean isBroadcast;
private HashMap<Integer, MessageObject>[] selectedMessagesIds = new HashMap[]{new HashMap<>(), new HashMap<>()};
private HashMap<Integer, MessageObject>[] selectedMessagesCanCopyIds = new HashMap[]{new HashMap<>(), new HashMap<>()};
private int cantDeleteMessagesCount;
private ArrayList<Integer> waitingForLoad = new ArrayList<>();
private int newUnreadMessageCount;
2015-11-26 22:04:02 +01:00
private HashMap<Integer, MessageObject>[] messagesDict = new HashMap[]{new HashMap<>(), new HashMap<>()};
2015-01-02 23:15:07 +01:00
private HashMap<String, ArrayList<MessageObject>> messagesByDays = new HashMap<>();
protected ArrayList<MessageObject> messages = new ArrayList<>();
2015-11-26 22:04:02 +01:00
private int maxMessageId[] = new int[] {Integer.MAX_VALUE, Integer.MAX_VALUE};
private int minMessageId[] = new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE};
private int maxDate[] = new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE};
private int minDate[] = new int[2];
private boolean endReached[] = new boolean[2];
private boolean cacheEndReached[] = new boolean[2];
private boolean forwardEndReached[] = new boolean[] {true, true};
private boolean loading;
2014-08-02 01:31:15 +02:00
private boolean firstLoading = true;
2015-11-26 22:04:02 +01:00
private int loadsCount;
private int last_message_id = 0;
private long mergeDialogId;
2014-11-19 02:23:46 +01:00
2015-11-26 22:04:02 +01:00
private int startLoadFromMessageId;
2015-03-26 18:34:47 +01:00
private boolean needSelectFromMessageId;
2015-11-26 22:04:02 +01:00
private int returnToMessageId;
2016-03-16 13:26:32 +01:00
private int returnToLoadIndex;
2014-08-02 01:31:15 +02:00
private boolean first = true;
2015-11-26 22:04:02 +01:00
private int unread_to_load;
private int first_unread_id;
private boolean loadingForward;
private MessageObject unreadMessageObject;
private MessageObject scrollToMessage;
2014-11-18 06:01:04 +01:00
private int highlightMessageId = Integer.MAX_VALUE;
2015-09-24 22:52:02 +02:00
private int scrollToMessagePosition = -10000;
2013-10-25 17:19:00 +02:00
private String currentPicturePath;
2015-09-24 22:52:02 +02:00
protected TLRPC.ChatFull info = null;
2013-10-25 17:19:00 +02:00
2015-06-29 19:12:11 +02:00
private HashMap<Integer, TLRPC.BotInfo> botInfo = new HashMap<>();
private String botUser;
2016-04-22 15:49:00 +02:00
private long inlineReturn;
2015-06-29 19:12:11 +02:00
private MessageObject botButtons;
private MessageObject botReplyButtons;
private int botsCount;
private boolean hasBotsCommands;
private long chatEnterTime = 0;
private long chatLeaveTime = 0;
2014-10-01 00:36:18 +02:00
private String startVideoEdit = null;
private Runnable openSecretPhotoRunnable = null;
2014-10-10 19:16:39 +02:00
private float startX = 0;
private float startY = 0;
2016-10-11 13:57:01 +02:00
private ArrayList<Object> botContextResults;
private PhotoViewer.PhotoViewerProvider botContextProvider = new PhotoViewer.PhotoViewerProvider() {
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
if (index < 0 || index >= botContextResults.size()) {
return null;
}
int count = mentionListView.getChildCount();
Object result = botContextResults.get(index);
for (int a = 0; a < count; a++) {
ImageReceiver imageReceiver = null;
View view = mentionListView.getChildAt(a);
if (view instanceof ContextLinkCell) {
ContextLinkCell cell = (ContextLinkCell) view;
if (cell.getResult() == result) {
imageReceiver = cell.getPhotoImage();
}
}
if (imageReceiver != null) {
int coords[] = new int[2];
view.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight);
object.parentView = mentionListView;
object.imageReceiver = imageReceiver;
object.thumb = imageReceiver.getBitmap();
object.radius = imageReceiver.getRoundRadius();
return object;
}
}
return null;
}
@Override
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
return null;
}
@Override
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
}
@Override
public void willHidePhotoViewer() {
}
@Override
public boolean isPhotoChecked(int index) {
return false;
}
@Override
public void setPhotoChecked(int index) {
}
@Override
public boolean cancelButtonPressed() {
return false;
}
@Override
public void sendButtonPressed(int index) {
if (index < 0 || index >= botContextResults.size()) {
return;
}
sendBotInlineResult((TLRPC.BotInlineResult) botContextResults.get(index));
}
@Override
public int getSelectedCount() {
return 0;
}
@Override
public void updatePhotoAtIndex(int index) {
}
@Override
public boolean scaleToFill() {
return false;
}
@Override
public boolean allowCaption() {
return true;
}
};
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;
2016-03-06 02:49:31 +01:00
private final static int edit_done = 20;
2016-03-16 13:26:32 +01:00
private final static int report = 21;
2015-06-29 19:12:11 +02:00
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 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-10-29 18:10:07 +01:00
public boolean 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-10-29 18:10:07 +01:00
return true;
2014-10-10 19:16:39 +02:00
}
2015-10-29 18:10:07 +01:00
return false;
2014-10-10 19:16:39 +02:00
}
};
2015-05-21 23:27:27 +02:00
RecyclerListView.OnItemClickListener onItemClickListener = new RecyclerListView.OnItemClickListener() {
2014-10-10 19:16:39 +02:00
@Override
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);
}
};
public ChatActivity(Bundle args) {
super(args);
}
2013-10-25 17:19:00 +02:00
@Override
public boolean onFragmentCreate() {
final int chatId = arguments.getInt("chat_id", 0);
final int userId = arguments.getInt("user_id", 0);
final int encId = arguments.getInt("enc_id", 0);
2016-04-22 15:49:00 +02:00
inlineReturn = arguments.getLong("inline_return", 0);
String inlineQuery = arguments.getString("inline_query");
2014-10-31 20:02:29 +01:00
startLoadFromMessageId = arguments.getInt("message_id", 0);
2015-11-26 22:04:02 +01:00
int migrated_to = arguments.getInt("migrated_to", 0);
scrollToTopOnResume = arguments.getBoolean("scrollToTopOnResume", false);
2013-10-25 17:19:00 +02:00
if (chatId != 0) {
currentChat = MessagesController.getInstance().getChat(chatId);
2013-10-25 17:19:00 +02:00
if (currentChat == null) {
final Semaphore semaphore = new Semaphore(0);
2014-10-31 20:02:29 +01:00
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
currentChat = MessagesStorage.getInstance().getChat(chatId);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (currentChat != null) {
MessagesController.getInstance().putChat(currentChat, true);
} else {
return false;
}
2013-10-25 17:19:00 +02:00
}
if (chatId > 0) {
dialog_id = -chatId;
} else {
2014-10-20 13:30:05 +02:00
isBroadcast = true;
dialog_id = AndroidUtilities.makeBroadcastId(chatId);
}
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(currentChat)) {
MessagesController.getInstance().startShortPoll(chatId, false);
2014-08-08 12:17:06 +02:00
}
2013-10-25 17:19:00 +02:00
} else if (userId != 0) {
currentUser = MessagesController.getInstance().getUser(userId);
2013-10-25 17:19:00 +02:00
if (currentUser == null) {
final Semaphore semaphore = new Semaphore(0);
2014-10-31 20:02:29 +01:00
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
currentUser = MessagesStorage.getInstance().getUser(userId);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (currentUser != null) {
MessagesController.getInstance().putUser(currentUser, true);
} 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");
2016-04-22 15:49:00 +02:00
if (inlineQuery != null) {
MessagesController.getInstance().sendBotStart(currentUser, inlineQuery);
}
2013-10-25 17:19:00 +02:00
} else if (encId != 0) {
currentEncryptedChat = MessagesController.getInstance().getEncryptedChat(encId);
2013-10-25 17:19:00 +02:00
if (currentEncryptedChat == null) {
final Semaphore semaphore = new Semaphore(0);
2014-10-31 20:02:29 +01:00
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
currentEncryptedChat = MessagesStorage.getInstance().getEncryptedChat(encId);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (currentEncryptedChat != null) {
MessagesController.getInstance().putEncryptedChat(currentEncryptedChat, true);
} else {
return false;
}
2013-10-25 17:19:00 +02:00
}
currentUser = MessagesController.getInstance().getUser(currentEncryptedChat.user_id);
2013-10-25 17:19:00 +02:00
if (currentUser == null) {
final Semaphore semaphore = new Semaphore(0);
2014-10-31 20:02:29 +01:00
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
currentUser = MessagesStorage.getInstance().getUser(currentEncryptedChat.user_id);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (currentUser != null) {
MessagesController.getInstance().putUser(currentUser, true);
} else {
return false;
}
2013-10-25 17:19:00 +02:00
}
2015-04-09 20:00:14 +02:00
dialog_id = ((long) encId) << 32;
2015-11-26 22:04:02 +01:00
maxMessageId[0] = maxMessageId[1] = Integer.MIN_VALUE;
minMessageId[0] = minMessageId[1] = Integer.MAX_VALUE;
MediaController.getInstance().startMediaObserver();
2013-10-25 17:19:00 +02:00
} else {
return false;
}
2014-11-19 02:23:46 +01: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);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesRead);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDeleted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByServer);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByAck);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageSendError);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatUpdated);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesReadEncrypted);
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);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenshotTook);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded);
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);
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);
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);
2015-09-24 22:52:02 +02:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedMessagesViews);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoCantLoad);
2016-03-16 13:26:32 +01:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didLoadedPinnedMessage);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.peerSettingsDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.newDraftReceived);
super.onFragmentCreate();
2015-06-29 19:12:11 +02:00
if (currentEncryptedChat == null && !isBroadcast) {
BotQuery.loadBotKeyboard(dialog_id);
}
2015-09-24 22:52:02 +02:00
loading = true;
2016-03-16 13:26:32 +01:00
MessagesController.getInstance().loadPeerSettings(dialog_id, currentUser, currentChat);
2016-03-06 02:49:31 +01:00
MessagesController.getInstance().setLastCreatedDialogId(dialog_id, true);
2015-09-24 22:52:02 +02:00
if (startLoadFromMessageId != 0) {
needSelectFromMessageId = true;
2015-11-26 22:04:02 +01:00
waitingForLoad.add(lastLoadIndex);
if (migrated_to != 0) {
mergeDialogId = migrated_to;
MessagesController.getInstance().loadMessages(mergeDialogId, AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, true, 0, classGuid, 3, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-11-26 22:04:02 +01:00
} else {
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, true, 0, classGuid, 3, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-11-26 22:04:02 +01:00
}
2015-09-24 22:52:02 +02:00
} else {
2015-11-26 22:04:02 +01:00
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, 0, true, 0, classGuid, 2, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-09-24 22:52:02 +02:00
}
if (currentChat != null) {
Semaphore semaphore = null;
if (isBroadcast) {
semaphore = new Semaphore(0);
}
MessagesController.getInstance().loadChatInfo(currentChat.id, semaphore, ChatObject.isChannel(currentChat));
if (isBroadcast && semaphore != null) {
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
2015-11-26 22:04:02 +01:00
if (userId != 0 && currentUser.bot) {
2015-06-29 19:12:11 +02:00
BotQuery.loadBotInfo(userId, true, classGuid);
2015-09-24 22:52:02 +02:00
} else if (info instanceof TLRPC.TL_chatFull) {
for (int a = 0; a < info.participants.participants.size(); a++) {
2015-11-26 22:04:02 +01:00
TLRPC.ChatParticipant participant = info.participants.participants.get(a);
2015-06-29 19:12:11 +02:00
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
2015-11-26 22:04:02 +01:00
if (user != null && user.bot) {
2015-06-29 19:12:11 +02:00
BotQuery.loadBotInfo(user.id, true, classGuid);
}
}
}
if (currentUser != null) {
userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
}
2013-12-20 20:25:49 +01:00
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, false);
}
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();
if (chatActivityEnterView != null) {
chatActivityEnterView.onDestroy();
}
2016-04-22 15:49:00 +02:00
if (mentionsAdapter != null) {
mentionsAdapter.onDestroy();
}
2016-03-06 02:49:31 +01:00
MessagesController.getInstance().setLastCreatedDialogId(dialog_id, false);
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);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesRead);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesDeleted);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByServer);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByAck);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageSendError);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatUpdated);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesReadEncrypted);
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);
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);
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);
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-09-24 22:52:02 +02:00
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didUpdatedMessagesViews);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoCantLoad);
2016-03-16 13:26:32 +01:00
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didLoadedPinnedMessage);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.peerSettingsDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.newDraftReceived);
2015-04-09 20:00:14 +02:00
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, true);
}
if (currentEncryptedChat != null) {
MediaController.getInstance().stopMediaObserver();
2016-03-16 13:26:32 +01:00
try {
2016-05-25 23:49:47 +02:00
if (Build.VERSION.SDK_INT >= 23) {
2016-03-16 13:26:32 +01:00
getParentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
} catch (Throwable e) {
FileLog.e("tmessages", e);
}
}
2014-11-19 11:32:27 +01:00
if (currentUser != null) {
MessagesController.getInstance().cancelLoadFullUser(currentUser.id);
}
2015-09-24 22:52:02 +02:00
AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid);
2015-01-02 23:15:07 +01:00
if (stickersAdapter != null) {
2015-06-29 19:12:11 +02:00
stickersAdapter.onDestroy();
}
2016-05-25 23:49:47 +02:00
if (chatAttachAlert != null) {
chatAttachAlert.onDestroy();
2015-01-02 23:15:07 +01:00
}
AndroidUtilities.unlockOrientation(getParentActivity());
2016-03-06 02:49:31 +01:00
/*MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
2015-07-22 20:56:37 +02:00
if (messageObject != null && !messageObject.isMusic()) {
MediaController.getInstance().stopAudio();
2016-03-06 02:49:31 +01:00
}*/
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(currentChat)) {
MessagesController.getInstance().startShortPoll(currentChat.id, true);
}
2013-10-25 17:19:00 +02:00
}
@Override
2015-07-22 20:56:37 +02:00
public View createView(Context context) {
2014-11-17 03:44:57 +01:00
2015-11-26 22:04:02 +01:00
if (chatMessageCellsCache.isEmpty()) {
for (int a = 0; a < 8; a++) {
chatMessageCellsCache.add(new ChatMessageCell(context));
}
}
for (int a = 1; a >= 0; a--) {
selectedMessagesIds[a].clear();
selectedMessagesCanCopyIds[a].clear();
}
2015-11-26 22:04:02 +01:00
cantDeleteMessagesCount = 0;
2015-04-09 20:00:14 +02:00
hasOwnBackground = true;
2016-05-25 23:49:47 +02:00
if (chatAttachAlert != null){
chatAttachAlert.onDestroy();
chatAttachAlert = null;
2016-04-25 21:26:41 +02:00
}
2015-04-09 20:00:14 +02:00
2016-04-22 15:49:00 +02:00
Theme.loadRecources(context);
2016-05-25 23:49:47 +02:00
Theme.loadChatResources(context);
2016-10-11 13:57:01 +02:00
actionBar.setAddToContainer(false);
2015-10-29 18:10:07 +01:00
actionBar.setBackButtonDrawable(new BackDrawable(false));
2015-04-09 20:00:14 +02:00
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(final int id) {
if (id == -1) {
2015-10-29 18:10:07 +01:00
if (actionBar.isActionModeShowed()) {
2015-11-26 22:04:02 +01:00
for (int a = 1; a >= 0; a--) {
selectedMessagesIds[a].clear();
selectedMessagesCanCopyIds[a].clear();
}
2015-10-29 18:10:07 +01:00
cantDeleteMessagesCount = 0;
2016-05-25 23:49:47 +02:00
if (chatActivityEnterView.isEditingMessage()) {
chatActivityEnterView.setEditingMessageObject(null, false);
} else {
actionBar.hideActionMode();
updatePinnedMessageView(true);
}
2015-10-29 18:10:07 +01:00
updateVisibleRows();
} else {
finishFragment();
}
2015-04-09 20:00:14 +02:00
} else if (id == copy) {
String str = "";
2016-05-25 23:49:47 +02:00
int previousUid = 0;
2015-11-26 22:04:02 +01:00
for (int a = 1; a >= 0; a--) {
ArrayList<Integer> ids = new ArrayList<>(selectedMessagesCanCopyIds[a].keySet());
if (currentEncryptedChat == null) {
Collections.sort(ids);
2015-04-09 20:00:14 +02:00
} else {
2015-11-26 22:04:02 +01:00
Collections.sort(ids, Collections.reverseOrder());
}
for (int b = 0; b < ids.size(); b++) {
Integer messageId = ids.get(b);
MessageObject messageObject = selectedMessagesCanCopyIds[a].get(messageId);
if (str.length() != 0) {
2016-05-25 23:49:47 +02:00
str += "\n\n";
2015-11-26 22:04:02 +01:00
}
2016-05-25 23:49:47 +02:00
str += getMessageContent(messageObject, previousUid, true);
previousUid = messageObject.messageOwner.from_id;
2014-11-18 13:37:11 +01:00
}
2015-04-09 20:00:14 +02:00
}
if (str.length() != 0) {
2016-05-25 23:49:47 +02:00
AndroidUtilities.addToClipboard(str);
2015-04-09 20:00:14 +02:00
}
2015-11-26 22:04:02 +01:00
for (int a = 1; a >= 0; a--) {
selectedMessagesIds[a].clear();
selectedMessagesCanCopyIds[a].clear();
}
2015-09-24 22:52:02 +02:00
cantDeleteMessagesCount = 0;
2015-04-09 20:00:14 +02:00
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
2015-04-09 20:00:14 +02:00
updateVisibleRows();
2016-03-06 02:49:31 +01:00
} else if (id == edit_done) {
if (chatActivityEnterView != null && (chatActivityEnterView.isEditingCaption() || chatActivityEnterView.hasText())) {
chatActivityEnterView.doneEditingMessage();
}
2015-04-09 20:00:14 +02:00
} else if (id == delete) {
if (getParentActivity() == null) {
return;
}
2016-03-16 13:26:32 +01:00
createDeleteMessagesAlert(null);
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-09-24 22:52:02 +02:00
if (ChatObject.isNotInChat(currentChat)) {
2015-12-09 19:27:52 +01:00
MessagesController.getInstance().deleteDialog(dialog_id, 0);
2015-05-21 23:27:27 +02:00
} else {
MessagesController.getInstance().deleteUserFromChat((int) -dialog_id, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), null);
}
2015-04-09 20:00:14 +02:00
} else {
2015-12-09 19:27:52 +01:00
MessagesController.getInstance().deleteDialog(dialog_id, 0);
2015-04-09 20:00:14 +02:00
}
finishFragment();
2014-11-17 03:44:57 +01:00
} else {
2015-12-09 19:27:52 +01:00
MessagesController.getInstance().deleteDialog(dialog_id, 1);
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 {
2016-04-22 15:49:00 +02:00
shareMyContact(replyingMessageObject);
2015-04-09 20:00:14 +02:00
}
} else if (id == mute) {
2015-09-24 22:52:02 +02:00
toggleMute(false);
2016-03-16 13:26:32 +01:00
} else if (id == report) {
showDialog(AlertsCreator.createReportAlert(getParentActivity(), dialog_id, ChatActivity.this));
2015-04-09 20:00:14 +02:00
} else if (id == reply) {
2015-11-26 22:04:02 +01:00
MessageObject messageObject = null;
for (int a = 1; a >= 0; a--) {
if (messageObject == null && selectedMessagesIds[a].size() == 1) {
ArrayList<Integer> ids = new ArrayList<>(selectedMessagesIds[a].keySet());
messageObject = messagesDict[a].get(ids.get(0));
2014-11-14 16:40:15 +01:00
}
2015-11-26 22:04:02 +01:00
selectedMessagesIds[a].clear();
selectedMessagesCanCopyIds[a].clear();
}
2016-03-06 02:49:31 +01:00
if (messageObject != null && (messageObject.messageOwner.id > 0 || messageObject.messageOwner.id < 0 && currentEncryptedChat != null)) {
2015-11-26 22:04:02 +01:00
showReplyPanel(true, messageObject, null, null, false, true);
2014-11-14 16:40:15 +01:00
}
2015-09-24 22:52:02 +02:00
cantDeleteMessagesCount = 0;
2015-04-09 20:00:14 +02:00
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
2015-04-09 20:00:14 +02:00
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
2016-04-22 15:49:00 +02:00
createChatAttachView();
2016-05-25 23:49:47 +02:00
chatAttachAlert.loadGalleryPhotos();
2015-11-26 22:04:02 +01:00
if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) {
chatActivityEnterView.closeKeyboard();
}
2016-10-11 13:57:01 +02:00
chatAttachAlert.init();
2016-05-25 23:49:47 +02:00
showDialog(chatAttachAlert);
2015-09-24 22:52:02 +02:00
} else if (id == bot_help) {
SendMessagesHelper.getInstance().sendMessage("/help", dialog_id, null, null, false, null, null, null);
2015-06-29 19:12:11 +02:00
} else if (id == bot_settings) {
SendMessagesHelper.getInstance().sendMessage("/settings", dialog_id, null, null, false, null, null, null);
2015-06-29 19:12:11 +02:00
} else if (id == search) {
2015-09-24 22:52:02 +02:00
openSearchWithText(null);
2014-11-17 23:04:31 +01:00
}
}
2015-04-09 20:00:14 +02:00
});
2014-11-17 23:04:31 +01:00
avatarContainer = new ChatAvatarContainer(context, this, currentEncryptedChat != null);
2015-10-29 18:10:07 +01:00
actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));
2014-11-19 16:17:24 +01:00
2015-04-09 20:00:14 +02:00
if (currentChat != null) {
2015-09-24 22:52:02 +02:00
if (!ChatObject.isChannel(currentChat)) {
int count = currentChat.participants_count;
if (info != null) {
count = info.participants.participants.size();
}
2015-11-26 22:04:02 +01:00
if (count == 0 || currentChat.deactivated || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden || info != null && info.participants instanceof TLRPC.TL_chatParticipantsForbidden) {
2015-09-24 22:52:02 +02:00
avatarContainer.setEnabled(false);
}
}
2015-04-09 20:00:14 +02:00
}
2015-04-09 20:00:14 +02:00
ActionBarMenu menu = actionBar.createMenu();
2015-06-29 19:12:11 +02:00
if (currentEncryptedChat == null && !isBroadcast) {
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).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);
2015-09-24 22:52:02 +02:00
highlightMessageId = Integer.MAX_VALUE;
updateVisibleRows();
2015-10-29 18:10:07 +01:00
scrollToLastMessage(false);
updateBottomOverlay();
2015-06-29 19:12:11 +02:00
}
@Override
public void onSearchExpand() {
2015-09-24 22:52:02 +02:00
if (!openSearchKeyboard) {
return;
}
2015-06-29 19:12:11 +02:00
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
searchItem.getSearchField().requestFocus();
AndroidUtilities.showKeyboard(searchItem.getSearchField());
}
2016-03-16 13:26:32 +01:00
}, 300);
2015-06-29 19:12:11 +02:00
}
@Override
public void onSearchPressed(EditText editText) {
updateSearchButtons(0, 0, 0);
2015-11-26 22:04:02 +01:00
MessagesSearchQuery.searchMessagesInChat(editText.getText().toString(), dialog_id, mergeDialogId, classGuid, 0);
2015-06-29 19:12:11 +02:00
}
});
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searchItem.setVisibility(View.GONE);
}
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);
}
2016-03-16 13:26:32 +01:00
if (ChatObject.isChannel(currentChat) && !currentChat.creator && (!currentChat.megagroup || currentChat.username != null && currentChat.username.length() > 0)) {
headerItem.addSubItem(report, LocaleController.getString("ReportChat", R.string.ReportChat), 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);
}
if (!ChatObject.isChannel(currentChat)) {
2015-09-24 22:52:02 +02:00
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);
}
2015-04-09 20:00:14 +02:00
}
2016-10-11 13:57:01 +02:00
if (currentUser == null || !currentUser.self) {
muteItem = headerItem.addSubItem(mute, null, 0);
}
2015-11-26 22:04:02 +01:00
if (currentUser != null && currentEncryptedChat == null && currentUser.bot) {
2015-06-29 19:12:11 +02:00
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();
2016-04-22 15:49:00 +02:00
avatarContainer.updateOnlineCount();
avatarContainer.updateSubtitle();
2015-04-09 20:00:14 +02:00
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();
2015-10-29 18:10:07 +01:00
selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
2015-04-09 20:00:14 +02:00
selectedMessagesCountTextView.setTextSize(18);
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2016-04-22 15:49:00 +02:00
selectedMessagesCountTextView.setTextColor(Theme.ACTION_BAR_ACTION_MODE_TEXT_COLOR);
2015-10-29 18:10:07 +01:00
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
2015-04-09 20:00:14 +02:00
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
2015-04-09 20:00:14 +02:00
});
2016-05-25 23:49:47 +02:00
actionModeTitleContainer = new FrameLayout(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
actionModeTextView.setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 18 : 20);
actionModeTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.AT_MOST));
if (actionModeSubTextView.getVisibility() != GONE) {
actionModeSubTextView.setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 14 : 16);
actionModeSubTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(20), MeasureSpec.AT_MOST));
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int height = bottom - top;
int textTop;
if (actionModeSubTextView.getVisibility() != GONE) {
textTop = (height / 2 - actionModeTextView.getTextHeight()) / 2 + AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 2 : 3);
} else {
textTop = (height - actionModeTextView.getTextHeight()) / 2;
}
actionModeTextView.layout(0, textTop, actionModeTextView.getMeasuredWidth(), textTop + actionModeTextView.getTextHeight());
if (actionModeSubTextView.getVisibility() != GONE) {
textTop = height / 2 + (height / 2 - actionModeSubTextView.getTextHeight()) / 2 - AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 1);
actionModeSubTextView.layout(0, textTop, actionModeSubTextView.getMeasuredWidth(), textTop + actionModeSubTextView.getTextHeight());
}
}
};
actionMode.addView(actionModeTitleContainer, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
actionModeTitleContainer.setOnTouchListener(new View.OnTouchListener() {
2016-03-06 02:49:31 +01:00
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
2016-05-25 23:49:47 +02:00
actionModeTitleContainer.setVisibility(View.GONE);
actionModeTextView = new SimpleTextView(context);
actionModeTextView.setTextSize(18);
actionModeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
actionModeTextView.setTextColor(Theme.ACTION_BAR_ACTION_MODE_TEXT_COLOR);
actionModeTextView.setText(LocaleController.getString("Edit", R.string.Edit));
actionModeTitleContainer.addView(actionModeTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
actionModeSubTextView = new SimpleTextView(context);
actionModeSubTextView.setGravity(Gravity.LEFT);
actionModeSubTextView.setTextColor(Theme.ACTION_BAR_ACTION_MODE_TEXT_COLOR);
actionModeTitleContainer.addView(actionModeSubTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2016-03-06 02:49:31 +01:00
2015-04-09 20:00:14 +02:00
if (currentEncryptedChat == null) {
if (!isBroadcast) {
2016-04-22 15:49:00 +02:00
actionModeViews.add(actionMode.addItem(reply, R.drawable.ic_ab_reply, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
}
2016-04-22 15:49:00 +02:00
actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
actionModeViews.add(actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
2016-05-25 23:49:47 +02:00
actionModeViews.add(editDoneItem = actionMode.addItem(edit_done, R.drawable.check_blue, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
editDoneItem.setVisibility(View.GONE);
2016-10-11 13:57:01 +02:00
editDoneItemProgress = new ContextProgressView(context, 0);
2016-05-25 23:49:47 +02:00
editDoneItem.addView(editDoneItemProgress, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
editDoneItemProgress.setVisibility(View.INVISIBLE);
2015-04-09 20:00:14 +02:00
} else {
2016-04-22 15:49:00 +02:00
actionModeViews.add(actionMode.addItem(reply, R.drawable.ic_ab_reply, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
2015-04-09 20:00:14 +02:00
}
2015-11-26 22:04:02 +01:00
actionMode.getItem(copy).setVisibility(selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() != 0 ? View.VISIBLE : View.GONE);
2015-09-24 22:52:02 +02:00
actionMode.getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
2015-04-09 20:00:14 +02:00
checkActionBarMenu();
2015-05-21 23:27:27 +02:00
fragmentView = new SizeNotifierFrameLayout(context) {
2015-06-29 19:12:11 +02:00
int inputFieldHeight = 0;
2016-10-11 13:57:01 +02:00
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (child == actionBar) {
parentLayout.drawHeaderShadow(canvas, actionBar.getMeasuredHeight());
}
return result;
}
@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-10-29 18:10:07 +01:00
heightSize -= getPaddingTop();
2015-05-21 23:27:27 +02:00
2016-10-11 13:57:01 +02:00
measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
int actionBarHeight = actionBar.getMeasuredHeight();
heightSize -= actionBarHeight;
2015-06-29 19:12:11 +02:00
int keyboardSize = getKeyboardHeight();
2016-10-11 13:57:01 +02:00
if (keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow) {
2015-06-29 19:12:11 +02:00
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);
2016-10-11 13:57:01 +02:00
if (child == null || child.getVisibility() == GONE || child == chatActivityEnterView || child == actionBar) {
2015-05-21 23:27:27 +02:00
continue;
}
if (child == chatListView || child == progressView) {
int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
int contentHeightSpec = MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), heightSize - inputFieldHeight + AndroidUtilities.dp(2 + (chatActivityEnterView.isTopViewVisible() ? 48 : 0))), MeasureSpec.EXACTLY);
child.measure(contentWidthSpec, contentHeightSpec);
} 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)) {
2016-10-11 13:57:01 +02:00
if (AndroidUtilities.isInMultiwindow) {
if (AndroidUtilities.isTablet()) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(320), heightSize - inputFieldHeight + actionBarHeight - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - inputFieldHeight + actionBarHeight - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
}
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
}
} else if (child == mentionContainer) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mentionContainer.getLayoutParams();
int height;
mentionListViewIgnoreLayout = true;
if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) {
int size = mentionGridLayoutManager.getRowsCount(widthSize);
int maxHeight = size * 102;
if (mentionsAdapter.isBotContext()) {
if (mentionsAdapter.getBotContextSwitch() != null) {
maxHeight += 34;
2016-05-25 23:49:47 +02:00
}
}
height = heightSize - chatActivityEnterView.getMeasuredHeight() + (maxHeight != 0 ? AndroidUtilities.dp(2) : 0);
mentionListView.setPadding(0, Math.max(0, height - AndroidUtilities.dp(Math.min(maxHeight, 68 * 1.8f))), 0, 0);
} else {
int size = mentionsAdapter.getItemCount();
int maxHeight = 0;
if (mentionsAdapter.isBotContext()) {
if (mentionsAdapter.getBotContextSwitch() != null) {
maxHeight += 36;
size -= 1;
2016-04-22 15:49:00 +02:00
}
maxHeight += size * 68;
} else {
maxHeight += size * 36;
2016-04-22 15:49:00 +02:00
}
height = heightSize - chatActivityEnterView.getMeasuredHeight() + (maxHeight != 0 ? AndroidUtilities.dp(2) : 0);
mentionListView.setPadding(0, Math.max(0, height - AndroidUtilities.dp(Math.min(maxHeight, 68 * 1.8f))), 0, 0);
}
2016-05-25 23:49:47 +02:00
layoutParams.height = height;
layoutParams.topMargin = 0;
2016-05-25 23:49:47 +02:00
mentionListViewIgnoreLayout = false;
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY));
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
2015-05-21 23:27:27 +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();
2016-10-11 13:57:01 +02:00
int paddingBottom = getKeyboardHeight() <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow ? chatActivityEnterView.getEmojiPadding() : 0;
2015-06-29 19:12:11 +02:00
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:
2015-10-29 18:10:07 +01:00
childTop = lp.topMargin + getPaddingTop();
2016-10-11 13:57:01 +02:00
if (child != actionBar) {
childTop += actionBar.getMeasuredHeight();
}
2015-05-21 23:27:27 +02:00
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;
}
2016-04-22 15:49:00 +02:00
if (child == mentionContainer) {
2015-05-21 23:27:27 +02:00
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) {
2016-10-11 13:57:01 +02:00
childTop -= inputFieldHeight / 2 - actionBar.getMeasuredHeight() / 2;
2015-06-29 19:12:11 +02:00
} else if (chatActivityEnterView.isPopupView(child)) {
2016-10-11 13:57:01 +02:00
if (AndroidUtilities.isInMultiwindow) {
childTop = chatActivityEnterView.getTop() - child.getMeasuredHeight() + AndroidUtilities.dp(1);
} else {
childTop = chatActivityEnterView.getBottom();
}
} else if (child == gifHintTextView) {
childTop -= inputFieldHeight;
} else if (child == chatListView || child == progressView) {
if (chatActivityEnterView.isTopViewVisible()) {
childTop -= AndroidUtilities.dp(48);
}
2016-10-11 13:57:01 +02:00
} else if (child == actionBar) {
childTop -= getPaddingTop();
2015-05-21 23:27:27 +02:00
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
2016-04-22 15:49:00 +02:00
updateMessagesVisisblePart();
2015-05-21 23:27:27 +02:00
notifyHeightChanged();
}
};
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-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;
}
});
2015-04-09 20:00:14 +02:00
if (currentEncryptedChat == null) {
2016-10-11 13:57:01 +02:00
if (currentUser != null && currentUser.self) {
bigEmptyView = new ChatBigEmptyView(context, false);
emptyViewContainer.addView(bigEmptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
2013-12-20 20:25:49 +01:00
} else {
2016-10-11 13:57:01 +02:00
TextView emptyView = new TextView(context);
if (currentUser != null && currentUser.id != 777000 && currentUser.id != 429000 && (currentUser.id / 1000 == 333 || currentUser.id % 1000 == 0)) {
emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion));
} else {
emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages));
}
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
emptyView.setGravity(Gravity.CENTER);
emptyView.setTextColor(Theme.CHAT_EMPTY_VIEW_TEXT_COLOR);
emptyView.setBackgroundResource(R.drawable.system);
emptyView.getBackground().setColorFilter(Theme.colorFilter);
emptyView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
emptyView.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(2), AndroidUtilities.dp(10), AndroidUtilities.dp(3));
emptyViewContainer.addView(emptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
}
2015-04-09 20:00:14 +02:00
} else {
2016-10-11 13:57:01 +02:00
bigEmptyView = new ChatBigEmptyView(context, true);
2015-04-09 20:00:14 +02:00
if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) {
2016-10-11 13:57:01 +02:00
bigEmptyView.setSecretText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, UserObject.getFirstName(currentUser)));
2015-04-09 20:00:14 +02:00
} else {
2016-10-11 13:57:01 +02:00
bigEmptyView.setSecretText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, UserObject.getFirstName(currentUser)));
2015-04-09 20:00:14 +02:00
}
2016-10-11 13:57:01 +02:00
emptyViewContainer.addView(bigEmptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
2015-04-09 20:00:14 +02:00
}
2015-05-21 23:27:27 +02:00
if (chatActivityEnterView != null) {
chatActivityEnterView.onDestroy();
}
2016-04-22 15:49:00 +02:00
if (mentionsAdapter != null) {
mentionsAdapter.onDestroy();
}
2015-05-21 23:27:27 +02:00
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);
2016-05-25 23:49:47 +02:00
forceScrollToTop = false;
if (chatAdapter.isBot) {
2015-06-29 19:12:11 +02:00
int childCount = getChildCount();
for (int a = 0; a < childCount; a++) {
View child = getChildAt(a);
2016-05-25 23:49:47 +02:00
if (child instanceof BotHelpCell) {
2015-06-29 19:12:11 +02:00
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;
}
}
}
}
};
chatListView.setTag(1);
2015-05-21 23:27:27 +02:00
chatListView.setVerticalScrollBarEnabled(true);
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));
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);
chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
private float totalDy = 0;
private final int scrollValue = AndroidUtilities.dp(100);
2015-04-09 20:00:14 +02:00
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
2015-09-24 22:52:02 +02:00
if (newState == RecyclerView.SCROLL_STATE_DRAGGING && highlightMessageId != Integer.MAX_VALUE) {
highlightMessageId = Integer.MAX_VALUE;
updateVisibleRows();
2015-04-09 20:00:14 +02:00
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
2016-04-22 15:49:00 +02:00
checkScrollForLoad(true);
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;
if (visibleItemCount > 0) {
int totalItemCount = chatAdapter.getItemCount();
2015-11-26 22:04:02 +01:00
if (firstVisibleItem + visibleItemCount == totalItemCount && forwardEndReached[0]) {
showPagedownButton(false, true);
} else {
if (dy > 0) {
if (pagedownButton.getTag() == null) {
totalDy += dy;
if (totalDy > scrollValue) {
totalDy = 0;
showPagedownButton(true, true);
pagedownButtonShowedByScroll = true;
}
}
} else {
if (pagedownButtonShowedByScroll && pagedownButton.getTag() != null) {
totalDy += dy;
if (totalDy < -scrollValue) {
showPagedownButton(false, true);
totalDy = 0;
}
}
}
2015-04-09 20:00:14 +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)) {
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-10-29 18:10:07 +01:00
chatListView.setOnItemClickListener(onItemClickListener);
chatListView.setOnItemLongClickListener(onItemLongClickListener);
chatListView.setLongClickable(true);
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
public boolean onInterceptTouchEvent(MotionEvent event) {
2016-03-06 02:49:31 +01:00
if (chatActivityEnterView != null && chatActivityEnterView.isEditingMessage()) {
return true;
}
if (actionBar.isActionModeShowed()) {
return false;
2015-04-09 20:00:14 +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
}
2016-03-16 13:26:32 +01:00
if (!(view instanceof ChatMessageCell)) {
break;
2015-04-09 20:00:14 +02:00
}
2016-03-16 13:26:32 +01:00
final ChatMessageCell cell = (ChatMessageCell) 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)) {
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
}
}
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));
View view = new View(context);
2016-04-22 15:49:00 +02:00
view.setBackgroundResource(R.drawable.system_loader);
view.getBackground().setColorFilter(Theme.colorFilter);
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);
progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));
2015-04-09 20:00:14 +02:00
2016-03-16 13:26:32 +01:00
if (ChatObject.isChannel(currentChat)) {
pinnedMessageView = new FrameLayout(context);
2016-03-16 13:26:32 +01:00
pinnedMessageView.setTag(1);
pinnedMessageView.setTranslationY(-AndroidUtilities.dp(50));
2016-03-16 13:26:32 +01:00
pinnedMessageView.setVisibility(View.GONE);
pinnedMessageView.setBackgroundResource(R.drawable.blockpanel);
contentView.addView(pinnedMessageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.TOP | Gravity.LEFT));
pinnedMessageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollToMessageId(info.pinned_msg_id, 0, true, 0);
}
});
View lineView = new View(context);
lineView.setBackgroundColor(0xff6c9fd2);
pinnedMessageView.addView(lineView, LayoutHelper.createFrame(2, 32, Gravity.LEFT | Gravity.TOP, 8, 8, 0, 0));
2016-10-11 13:57:01 +02:00
pinnedMessageImageView = new BackupImageView(context);
pinnedMessageView.addView(pinnedMessageImageView, LayoutHelper.createFrame(32, 32, Gravity.TOP | Gravity.LEFT, 17, 8, 0, 0));
2016-04-22 15:49:00 +02:00
pinnedMessageNameTextView = new SimpleTextView(context);
pinnedMessageNameTextView.setTextSize(14);
pinnedMessageNameTextView.setTextColor(Theme.PINNED_PANEL_NAME_TEXT_COLOR);
2016-03-16 13:26:32 +01:00
pinnedMessageNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2016-04-22 15:49:00 +02:00
pinnedMessageView.addView(pinnedMessageNameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, AndroidUtilities.dp(18), Gravity.TOP | Gravity.LEFT, 18, 7.3f, 52, 0));
pinnedMessageTextView = new SimpleTextView(context);
pinnedMessageTextView.setTextSize(14);
pinnedMessageTextView.setTextColor(Theme.PINNED_PANEL_MESSAGE_TEXT_COLOR);
pinnedMessageView.addView(pinnedMessageTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, AndroidUtilities.dp(18), Gravity.TOP | Gravity.LEFT, 18, 25.3f, 52, 0));
2016-03-16 13:26:32 +01:00
ImageView closePinned = new ImageView(context);
closePinned.setImageResource(R.drawable.miniplayer_close);
closePinned.setScaleType(ImageView.ScaleType.CENTER);
pinnedMessageView.addView(closePinned, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
closePinned.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
if (currentChat.creator || currentChat.editor) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("UnpinMessageAlert", R.string.UnpinMessageAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MessagesController.getInstance().pinChannelMessage(currentChat, 0, false);
}
});
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
preferences.edit().putInt("pin_" + dialog_id, info.pinned_msg_id).commit();
updatePinnedMessageView(true);
}
}
});
}
2015-09-24 22:52:02 +02:00
reportSpamView = new LinearLayout(context);
2016-03-16 13:26:32 +01:00
reportSpamView.setTag(1);
reportSpamView.setTranslationY(-AndroidUtilities.dp(50));
2015-09-24 22:52:02 +02:00
reportSpamView.setVisibility(View.GONE);
reportSpamView.setBackgroundResource(R.drawable.blockpanel);
contentView.addView(reportSpamView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.TOP | Gravity.LEFT));
2015-11-26 22:04:02 +01:00
addToContactsButton = new TextView(context);
2016-04-22 15:49:00 +02:00
addToContactsButton.setTextColor(Theme.CHAT_ADD_CONTACT_TEXT_COLOR);
2016-03-16 13:26:32 +01:00
addToContactsButton.setVisibility(View.GONE);
2015-11-26 22:04:02 +01:00
addToContactsButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
addToContactsButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
addToContactsButton.setSingleLine(true);
addToContactsButton.setMaxLines(1);
2015-12-09 19:27:52 +01:00
addToContactsButton.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
2015-11-26 22:04:02 +01:00
addToContactsButton.setGravity(Gravity.CENTER);
addToContactsButton.setText(LocaleController.getString("AddContactChat", R.string.AddContactChat));
2015-12-09 19:27:52 +01:00
reportSpamView.addView(addToContactsButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f, Gravity.LEFT | Gravity.TOP, 0, 0, 0, AndroidUtilities.dp(1)));
2015-11-26 22:04:02 +01:00
addToContactsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putInt("user_id", currentUser.id);
args.putBoolean("addContact", true);
presentFragment(new ContactAddActivity(args));
}
});
reportSpamContainer = new FrameLayout(context);
2016-03-16 13:26:32 +01:00
reportSpamView.addView(reportSpamContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 1.0f, Gravity.LEFT | Gravity.TOP, 0, 0, 0, AndroidUtilities.dp(1)));
2015-11-26 22:04:02 +01:00
2015-09-24 22:52:02 +02:00
reportSpamButton = new TextView(context);
2016-04-22 15:49:00 +02:00
reportSpamButton.setTextColor(Theme.CHAT_REPORT_SPAM_TEXT_COLOR);
2015-09-24 22:52:02 +02:00
reportSpamButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
reportSpamButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
reportSpamButton.setSingleLine(true);
reportSpamButton.setMaxLines(1);
2016-03-16 13:26:32 +01:00
if (currentChat != null) {
reportSpamButton.setText(LocaleController.getString("ReportSpamAndLeave", R.string.ReportSpamAndLeave));
} else {
reportSpamButton.setText(LocaleController.getString("ReportSpam", R.string.ReportSpam));
}
2015-11-26 22:04:02 +01:00
reportSpamButton.setGravity(Gravity.CENTER);
2016-03-16 13:26:32 +01:00
reportSpamButton.setPadding(AndroidUtilities.dp(50), 0, AndroidUtilities.dp(50), 0);
2015-11-26 22:04:02 +01:00
reportSpamContainer.addView(reportSpamButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
2015-09-24 22:52:02 +02:00
reportSpamButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2016-03-16 13:26:32 +01:00
if (getParentActivity() == null) {
2015-09-24 22:52:02 +02:00
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2016-03-16 13:26:32 +01:00
if (ChatObject.isChannel(currentChat) && !currentChat.megagroup) {
builder.setMessage(LocaleController.getString("ReportSpamAlertChannel", R.string.ReportSpamAlertChannel));
} else if (currentChat != null) {
2015-09-24 22:52:02 +02:00
builder.setMessage(LocaleController.getString("ReportSpamAlertGroup", R.string.ReportSpamAlertGroup));
} else {
builder.setMessage(LocaleController.getString("ReportSpamAlert", R.string.ReportSpamAlert));
}
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) {
2016-03-16 13:26:32 +01:00
if (currentUser != null) {
MessagesController.getInstance().blockUser(currentUser.id);
2015-10-29 18:10:07 +01:00
}
2016-03-16 13:26:32 +01:00
MessagesController.getInstance().reportSpam(dialog_id, currentUser, currentChat);
updateSpamView();
2016-03-06 02:49:31 +01:00
if (currentChat != null) {
2016-03-16 13:26:32 +01:00
if (ChatObject.isNotInChat(currentChat)) {
MessagesController.getInstance().deleteDialog(dialog_id, 0);
} else {
MessagesController.getInstance().deleteUserFromChat((int) -dialog_id, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), null);
2015-09-24 22:52:02 +02:00
}
2016-04-22 15:49:00 +02:00
} else {
MessagesController.getInstance().deleteDialog(dialog_id, 0);
2016-03-16 13:26:32 +01:00
}
2016-04-22 15:49:00 +02:00
finishFragment();
2015-09-24 22:52:02 +02:00
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
});
2015-11-26 22:04:02 +01:00
ImageView closeReportSpam = new ImageView(context);
2016-03-16 13:26:32 +01:00
closeReportSpam.setImageResource(R.drawable.miniplayer_close);
2015-11-26 22:04:02 +01:00
closeReportSpam.setScaleType(ImageView.ScaleType.CENTER);
reportSpamContainer.addView(closeReportSpam, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
closeReportSpam.setOnClickListener(new View.OnClickListener() {
2015-09-24 22:52:02 +02:00
@Override
public void onClick(View v) {
2016-03-16 13:26:32 +01:00
MessagesController.getInstance().hideReportSpam(dialog_id, currentUser, currentChat);
2015-11-26 22:04:02 +01:00
updateSpamView();
2015-09-24 22:52:02 +02:00
}
});
alertView = new FrameLayout(context);
2016-04-22 15:49:00 +02:00
alertView.setTag(1);
alertView.setTranslationY(-AndroidUtilities.dp(50));
2016-04-22 15:49:00 +02:00
alertView.setVisibility(View.GONE);
alertView.setBackgroundResource(R.drawable.blockpanel);
contentView.addView(alertView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.TOP | Gravity.LEFT));
alertNameTextView = new TextView(context);
alertNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
alertNameTextView.setTextColor(Theme.ALERT_PANEL_NAME_TEXT_COLOR);
alertNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
alertNameTextView.setSingleLine(true);
alertNameTextView.setEllipsize(TextUtils.TruncateAt.END);
alertNameTextView.setMaxLines(1);
alertView.addView(alertNameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 8, 5, 8, 0));
alertTextView = new TextView(context);
alertTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
alertTextView.setTextColor(Theme.ALERT_PANEL_MESSAGE_TEXT_COLOR);
alertTextView.setSingleLine(true);
alertTextView.setEllipsize(TextUtils.TruncateAt.END);
alertTextView.setMaxLines(1);
alertView.addView(alertTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 8, 23, 8, 0));
2016-03-06 02:49:31 +01:00
if (!isBroadcast) {
mentionContainer = new FrameLayout(context) {
2016-04-22 15:49:00 +02:00
private Drawable background;
@Override
public void onDraw(Canvas canvas) {
2016-05-25 23:49:47 +02:00
if (mentionListView.getChildCount() <= 0) {
return;
}
if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout() && mentionsAdapter.getBotContextSwitch() == null) {
background.setBounds(0, mentionListViewScrollOffsetY - AndroidUtilities.dp(4), getMeasuredWidth(), getMeasuredHeight());
2016-04-22 15:49:00 +02:00
} else {
2016-05-25 23:49:47 +02:00
background.setBounds(0, mentionListViewScrollOffsetY - AndroidUtilities.dp(2), getMeasuredWidth(), getMeasuredHeight());
2016-04-22 15:49:00 +02:00
}
background.draw(canvas);
}
@Override
public void setBackgroundResource(int resid) {
background = getContext().getResources().getDrawable(resid);
}
@Override
public void requestLayout() {
if (mentionListViewIgnoreLayout) {
return;
}
super.requestLayout();
}
};
mentionContainer.setBackgroundResource(R.drawable.compose_panel);
mentionContainer.setVisibility(View.GONE);
mentionContainer.setWillNotDraw(false);
contentView.addView(mentionContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM));
mentionListView = new RecyclerListView(context) {
private int lastWidth;
private int lastHeight;
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
2016-05-25 23:49:47 +02:00
if (!mentionListViewIsScrolling && mentionListViewScrollOffsetY != 0 && event.getY() < mentionListViewScrollOffsetY) {
2016-04-22 15:49:00 +02:00
return false;
}
boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, mentionListView, 0);
return super.onInterceptTouchEvent(event) || result;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
2016-05-25 23:49:47 +02:00
if (!mentionListViewIsScrolling && mentionListViewScrollOffsetY != 0 && event.getY() < mentionListViewScrollOffsetY) {
2016-04-22 15:49:00 +02:00
return false;
}
//supress warning
return super.onTouchEvent(event);
}
@Override
public void requestLayout() {
if (mentionListViewIgnoreLayout) {
return;
}
super.requestLayout();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int width = r - l;
int height = b - t;
int newPosition = -1;
int newTop = 0;
if (mentionListView != null && mentionListViewLastViewPosition >= 0 && width == lastWidth && height - lastHeight != 0) {
newPosition = mentionListViewLastViewPosition;
newTop = mentionListViewLastViewTop + height - lastHeight - getPaddingTop();
}
super.onLayout(changed, l, t, r, b);
if (newPosition != -1) {
mentionListViewIgnoreLayout = true;
2016-05-25 23:49:47 +02:00
if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) {
mentionGridLayoutManager.scrollToPositionWithOffset(newPosition, newTop);
} else {
mentionLayoutManager.scrollToPositionWithOffset(newPosition, newTop);
}
2016-04-22 15:49:00 +02:00
super.onLayout(false, l, t, r, b);
mentionListViewIgnoreLayout = false;
}
lastHeight = height;
lastWidth = width;
mentionListViewUpdateLayout();
}
};
mentionListView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return StickerPreviewViewer.getInstance().onTouch(event, mentionListView, 0, mentionsOnItemClickListener);
}
});
mentionListView.setTag(2);
mentionLayoutManager = new LinearLayoutManager(context) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
};
2016-05-25 23:49:47 +02:00
mentionLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mentionGridLayoutManager = new ExtendedGridLayoutManager(context, 100) {
private Size size = new Size();
@Override
protected Size getSizeForItem(int i) {
if (mentionsAdapter.getBotContextSwitch() != null) {
i++;
}
Object object = mentionsAdapter.getItem(i);
if (object instanceof TLRPC.BotInlineResult) {
TLRPC.BotInlineResult inlineResult = (TLRPC.BotInlineResult) object;
if (inlineResult.document != null) {
size.width = inlineResult.document.thumb != null ? inlineResult.document.thumb.w : 100;
size.height = inlineResult.document.thumb != null ? inlineResult.document.thumb.h : 100;
for (int b = 0; b < inlineResult.document.attributes.size(); b++) {
TLRPC.DocumentAttribute attribute = inlineResult.document.attributes.get(b);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) {
size.width = attribute.w;
size.height = attribute.h;
break;
}
}
} else {
size.width = inlineResult.w;
size.height = inlineResult.h;
}
}
return size;
}
@Override
protected int getFlowItemCount() {
if (mentionsAdapter.getBotContextSwitch() != null) {
return getItemCount() - 1;
}
return super.getFlowItemCount();
}
};
mentionGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
Object object = mentionsAdapter.getItem(position);
if (object instanceof TLRPC.TL_inlineBotSwitchPM) {
return 100;
} else {
if (mentionsAdapter.getBotContextSwitch() != null) {
position--;
}
return mentionGridLayoutManager.getSpanSizeForItem(position);
}
}
});
mentionListView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = 0;
outRect.right = 0;
outRect.top = 0;
outRect.bottom = 0;
if (parent.getLayoutManager() == mentionGridLayoutManager) {
int position = parent.getChildAdapterPosition(view);
if (mentionsAdapter.getBotContextSwitch() != null) {
if (position == 0) {
return;
}
position--;
if (!mentionGridLayoutManager.isFirstRow(position)) {
outRect.top = AndroidUtilities.dp(2);
}
} else {
outRect.top = AndroidUtilities.dp(2);
}
outRect.right = mentionGridLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2);
}
}
});
2016-04-22 15:49:00 +02:00
mentionListView.setItemAnimator(null);
mentionListView.setLayoutAnimation(null);
2016-05-25 23:49:47 +02:00
mentionListView.setClipToPadding(false);
mentionListView.setLayoutManager(mentionLayoutManager);
2016-04-22 15:49:00 +02:00
mentionListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
mentionContainer.addView(mentionListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2016-04-22 15:49:00 +02:00
mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(context, false, dialog_id, 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) {
2016-05-25 23:49:47 +02:00
if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) {
mentionListView.setLayoutManager(mentionGridLayoutManager);
} else {
mentionListView.setLayoutManager(mentionLayoutManager);
}
2015-04-09 20:00:14 +02:00
if (show) {
if (mentionListAnimation != null) {
mentionListAnimation.cancel();
mentionListAnimation = null;
}
2016-04-22 15:49:00 +02:00
if (mentionContainer.getVisibility() == View.VISIBLE) {
mentionContainer.setAlpha(1.0f);
2015-04-09 20:00:14 +02:00
return;
2016-05-25 23:49:47 +02:00
}
if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) {
mentionGridLayoutManager.scrollToPositionWithOffset(0, 10000);
} else {
mentionLayoutManager.scrollToPositionWithOffset(0, 10000);
2015-04-09 20:00:14 +02:00
}
if (allowStickersPanel && (!mentionsAdapter.isBotContext() || (allowContextBotPanel || allowContextBotPanelSecond))) {
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat != null && mentionsAdapter.isBotContext()) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (!preferences.getBoolean("secretbot", false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("SecretChatContextBotAlert", R.string.SecretChatContextBotAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
preferences.edit().putBoolean("secretbot", true).commit();
}
}
2016-04-22 15:49:00 +02:00
mentionContainer.setVisibility(View.VISIBLE);
mentionContainer.setTag(null);
mentionListAnimation = new AnimatorSet();
2015-04-09 20:00:14 +02:00
mentionListAnimation.playTogether(
ObjectAnimator.ofFloat(mentionContainer, "alpha", 0.0f, 1.0f)
2015-04-09 20:00:14 +02:00
);
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2015-04-09 20:00:14 +02:00
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
2016-04-22 15:49:00 +02:00
mentionListAnimation = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
2015-04-09 20:00:14 +02:00
mentionListAnimation = null;
}
2013-10-25 17:19:00 +02:00
}
2015-04-09 20:00:14 +02:00
});
mentionListAnimation.setDuration(200);
mentionListAnimation.start();
} else {
mentionContainer.setAlpha(1.0f);
2016-04-22 15:49:00 +02:00
mentionContainer.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
2016-04-22 15:49:00 +02:00
if (mentionContainer.getVisibility() == View.GONE) {
2015-04-09 20:00:14 +02:00
return;
}
if (allowStickersPanel) {
mentionListAnimation = new AnimatorSet();
2015-04-09 20:00:14 +02:00
mentionListAnimation.playTogether(
ObjectAnimator.ofFloat(mentionContainer, "alpha", 0.0f)
2015-04-09 20:00:14 +02:00
);
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2015-04-09 20:00:14 +02:00
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
2016-04-22 15:49:00 +02:00
mentionContainer.setVisibility(View.GONE);
mentionContainer.setTag(null);
mentionListAnimation = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
2015-04-09 20:00:14 +02:00
mentionListAnimation = null;
}
}
});
mentionListAnimation.setDuration(200);
mentionListAnimation.start();
} else {
2016-04-22 15:49:00 +02:00
mentionContainer.setTag(null);
mentionContainer.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
}
@Override
public void onContextSearch(boolean searching) {
if (chatActivityEnterView != null) {
chatActivityEnterView.setCaption(mentionsAdapter.getBotCaption());
chatActivityEnterView.showContextProgress(searching);
}
}
@Override
public void onContextClick(TLRPC.BotInlineResult result) {
if (getParentActivity() == null || result.content_url == null) {
return;
}
if (result.type.equals("video") || result.type.equals("web_player_video")) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
2016-04-22 15:49:00 +02:00
builder.setCustomView(new WebFrameLayout(getParentActivity(), builder.create(), result.title != null ? result.title : "", result.description, result.content_url, result.content_url, result.w, result.h));
builder.setUseFullWidth(true);
showDialog(builder.create());
} else {
2016-04-22 15:49:00 +02:00
Browser.openUrl(getParentActivity(), result.content_url);
}
}
2015-04-09 20:00:14 +02:00
}));
2016-03-06 02:49:31 +01:00
if (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup) {
mentionsAdapter.setBotInfo(botInfo);
}
2016-04-22 15:49:00 +02:00
mentionsAdapter.setParentFragment(this);
2015-04-09 20:00:14 +02:00
mentionsAdapter.setChatInfo(info);
mentionsAdapter.setNeedUsernames(currentChat != null);
2016-03-06 02:49:31 +01:00
mentionsAdapter.setNeedBotContext(currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46);
2015-06-29 19:12:11 +02:00
mentionsAdapter.setBotsCount(currentChat != null ? botsCount : 1);
2016-04-22 15:49:00 +02:00
mentionListView.setOnItemClickListener(mentionsOnItemClickListener = new RecyclerListView.OnItemClickListener() {
2015-04-09 20:00:14 +02:00
@Override
public void onItemClick(View view, int position) {
2015-04-09 20:00:14 +02:00
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) {
2016-05-25 23:49:47 +02:00
if (user.username != null) {
chatActivityEnterView.replaceWithText(start, len, "@" + user.username + " ");
} else {
String name = user.first_name;
if (name == null || name.length() == 0) {
name = user.last_name;
}
Spannable spannable = new SpannableString(name + " ");
spannable.setSpan(new URLSpanUserMention("" + user.id), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
chatActivityEnterView.replaceWithText(start, len, spannable);
}
}
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, null, null, null);
2015-06-29 19:12:11 +02:00
chatActivityEnterView.setFieldText("");
} else {
chatActivityEnterView.replaceWithText(start, len, object + " ");
}
} else if (object instanceof TLRPC.BotInlineResult) {
if (chatActivityEnterView.getFieldText() == null) {
return;
}
TLRPC.BotInlineResult result = (TLRPC.BotInlineResult) object;
2016-10-11 13:57:01 +02:00
if (Build.VERSION.SDK_INT >= 16 &&
(result.type.equals("photo") && (result.photo != null || result.content_url != null) ||
result.type.equals("gif") && (result.document != null || result.content_url != null) ||
result.type.equals("video") && (result.document != null/* || result.content_url != null*/))) {
ArrayList<Object> arrayList = botContextResults = new ArrayList<Object>(mentionsAdapter.getSearchResultBotContext());
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhotoForSelect(arrayList, mentionsAdapter.getItemPosition(position), 3, botContextProvider, null);
} else {
sendBotInlineResult(result);
}
2016-04-22 15:49:00 +02:00
} else if (object instanceof TLRPC.TL_inlineBotSwitchPM) {
processInlineBotContextPM((TLRPC.TL_inlineBotSwitchPM) object);
}
2013-10-25 17:19:00 +02:00
}
});
mentionListView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
2015-04-09 20:00:14 +02:00
@Override
public boolean onItemClick(View view, int position) {
if (getParentActivity() == null || !mentionsAdapter.isLongClickEnabled()) {
2015-06-29 19:12:11 +02:00
return false;
}
2015-04-09 20:00:14 +02:00
Object object = mentionsAdapter.getItem(position);
if (object instanceof String) {
2016-03-06 02:49:31 +01:00
if (mentionsAdapter.isBotCommands()) {
if (URLSpanBotCommand.enabled) {
chatActivityEnterView.setFieldText("");
chatActivityEnterView.setCommand(null, (String) object, true, currentChat != null && currentChat.megagroup);
return true;
}
2016-03-06 02:49:31 +01:00
return false;
} else {
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();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
return true;
}
2015-04-09 20:00:14 +02:00
}
return false;
}
});
mentionListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
2016-04-22 15:49:00 +02:00
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
mentionListViewIsScrolling = newState == RecyclerView.SCROLL_STATE_DRAGGING;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
2016-05-25 23:49:47 +02:00
int lastVisibleItem;
if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) {
lastVisibleItem = mentionGridLayoutManager.findLastVisibleItemPosition();
} else {
lastVisibleItem = mentionLayoutManager.findLastVisibleItemPosition();
}
2016-03-06 02:49:31 +01:00
int visibleItemCount = lastVisibleItem == RecyclerView.NO_POSITION ? 0 : lastVisibleItem;
if (visibleItemCount > 0 && lastVisibleItem > mentionsAdapter.getItemCount() - 5) {
mentionsAdapter.searchForContextBotForNextOffset();
}
2016-04-22 15:49:00 +02:00
mentionListViewUpdateLayout();
}
});
2015-04-09 20:00:14 +02:00
}
pagedownButton = new FrameLayout(context);
2015-10-29 18:10:07 +01:00
pagedownButton.setVisibility(View.INVISIBLE);
contentView.addView(pagedownButton, LayoutHelper.createFrame(46, 59, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 7, 5));
2015-10-29 18:10:07 +01:00
pagedownButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (returnToMessageId > 0) {
2016-03-16 13:26:32 +01:00
scrollToMessageId(returnToMessageId, 0, true, returnToLoadIndex);
2015-10-29 18:10:07 +01:00
} else {
scrollToLastMessage(true);
}
}
});
ImageView pagedownButtonImage = new ImageView(context);
pagedownButtonImage.setImageResource(R.drawable.pagedown);
pagedownButton.addView(pagedownButtonImage, LayoutHelper.createFrame(46, 46, Gravity.LEFT | Gravity.BOTTOM));
pagedownButtonCounter = new TextView(context);
pagedownButtonCounter.setVisibility(View.INVISIBLE);
pagedownButtonCounter.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
pagedownButtonCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
pagedownButtonCounter.setTextColor(0xffffffff);
pagedownButtonCounter.setGravity(Gravity.CENTER);
pagedownButtonCounter.setBackgroundResource(R.drawable.chat_badge);
pagedownButtonCounter.setMinWidth(AndroidUtilities.dp(23));
pagedownButtonCounter.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1));
pagedownButton.addView(pagedownButtonCounter, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 23, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
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);
2016-03-06 02:49:31 +01:00
chatActivityEnterView.setAllowStickersAndGifs(currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 23, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46);
2015-10-29 18:10:07 +01:00
contentView.addView(chatActivityEnterView, contentView.getChildCount() - 1, 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
2016-05-25 23:49:47 +02:00
public void onMessageSend(CharSequence message) {
2015-04-09 20:00:14 +02:00
moveScrollToLastMessage();
showReplyPanel(false, null, null, null, false, true);
if (mentionsAdapter != null) {
mentionsAdapter.addHashtagsFromMessage(message);
}
}
2015-04-09 20:00:14 +02:00
@Override
public void onTextChanged(final CharSequence text, boolean bigChange) {
2016-03-06 02:49:31 +01:00
MediaController.getInstance().setInputFieldHasText(text != null && text.length() != 0 || chatActivityEnterView.isEditingMessage());
if (stickersAdapter != null && !chatActivityEnterView.isEditingMessage()) {
2015-04-09 20:00:14 +02:00
stickersAdapter.loadStikersForEmoji(text);
}
if (mentionsAdapter != null) {
mentionsAdapter.searchUsernameOrHashtag(text.toString(), chatActivityEnterView.getCursorPosition(), messages);
}
if (waitingForCharaterEnterRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(waitingForCharaterEnterRunnable);
waitingForCharaterEnterRunnable = null;
}
2016-03-06 02:49:31 +01:00
if (chatActivityEnterView.isMessageWebPageSearchEnabled() && (!chatActivityEnterView.isEditingMessage() || !chatActivityEnterView.isEditingCaption())) {
if (bigChange) {
searchLinks(text, true);
} else {
waitingForCharaterEnterRunnable = new Runnable() {
@Override
public void run() {
if (this == waitingForCharaterEnterRunnable) {
searchLinks(text, false);
waitingForCharaterEnterRunnable = null;
}
}
};
2015-11-26 22:04:02 +01:00
AndroidUtilities.runOnUIThread(waitingForCharaterEnterRunnable, AndroidUtilities.WEB_URL == null ? 3000 : 1000);
}
2015-04-09 20:00:14 +02:00
}
}
2015-04-09 20:00:14 +02:00
@Override
public void needSendTyping() {
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-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-04-09 20:00:14 +02:00
2016-03-06 02:49:31 +01:00
@Override
2016-05-25 23:49:47 +02:00
public void onMessageEditEnd(boolean loading) {
if (loading) {
showEditDoneProgress(true, true);
} else {
mentionsAdapter.setNeedBotContext(currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46);
chatListView.setOnItemLongClickListener(onItemLongClickListener);
chatListView.setOnItemClickListener(onItemClickListener);
chatListView.setClickable(true);
chatListView.setLongClickable(true);
mentionsAdapter.setAllowNewMentions(true);
actionModeTitleContainer.setVisibility(View.GONE);
selectedMessagesCountTextView.setVisibility(View.VISIBLE);
chatActivityEnterView.setAllowStickersAndGifs(currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 23, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46);
if (editingMessageObjectReqId != 0) {
ConnectionsManager.getInstance().cancelRequest(editingMessageObjectReqId, true);
editingMessageObjectReqId = 0;
}
actionBar.hideActionMode();
updatePinnedMessageView(true);
updateVisibleRows();
}
2016-03-06 02:49:31 +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.setVisibility(View.INVISIBLE);
2015-03-26 18:34:47 +01:00
}
2016-04-22 15:49:00 +02:00
if (mentionContainer != null && mentionContainer.getVisibility() == View.VISIBLE) {
mentionContainer.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.setVisibility(View.VISIBLE);
}
2016-04-22 15:49:00 +02:00
if (mentionContainer != null && mentionContainer.getVisibility() == View.INVISIBLE && (!mentionsAdapter.isBotContext() || (allowContextBotPanel || allowContextBotPanelSecond))) {
mentionContainer.setVisibility(View.VISIBLE);
mentionContainer.setTag(null);
}
}
2016-04-22 15:49:00 +02:00
allowContextBotPanel = !chatActivityEnterView.isPopupShowing();
checkContextBotPanel();
2015-04-09 20:00:14 +02:00
}
@Override
public void onStickersTab(boolean opened) {
if (emojiButtonRed != null) {
emojiButtonRed.setVisibility(View.GONE);
}
allowContextBotPanelSecond = !opened;
checkContextBotPanel();
}
2015-04-09 20:00:14 +02:00
});
FrameLayout replyLayout = new FrameLayout(context) {
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
if (chatActivityEnterView != null) {
chatActivityEnterView.invalidate();
}
if (getVisibility() != GONE) {
int height = getLayoutParams().height;
if (chatListView != null) {
chatListView.setTranslationY(translationY);
}
if (progressView != null) {
progressView.setTranslationY(translationY);
}
if (mentionContainer != null) {
mentionContainer.setTranslationY(translationY);
}
if (pagedownButton != null) {
pagedownButton.setTranslationY(translationY);
}
}
}
@Override
public boolean hasOverlappingRendering() {
return false;
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
if (visibility == GONE) {
if (chatListView != null) {
chatListView.setTranslationY(0);
}
if (progressView != null) {
progressView.setTranslationY(0);
}
if (mentionContainer != null) {
mentionContainer.setTranslationY(0);
}
if (pagedownButton != null) {
pagedownButton.setTranslationY(pagedownButton.getTag() == null ? AndroidUtilities.dp(100) : 0);
}
}
}
};
2015-04-09 20:00:14 +02:00
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);
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);
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);
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-04-09 20:00:14 +02:00
showReplyPanel(false, null, null, foundWebPage, true, true);
}
});
2016-05-25 23:49:47 +02:00
replyNameTextView = new SimpleTextView(context);
replyNameTextView.setTextSize(14);
2016-04-22 15:49:00 +02:00
replyNameTextView.setTextColor(Theme.REPLY_PANEL_NAME_TEXT_COLOR);
2015-04-09 20:00:14 +02:00
replyNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2016-05-25 23:49:47 +02:00
replyLayout.addView(replyNameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 18, Gravity.TOP | Gravity.LEFT, 52, 6, 52, 0));
2015-04-09 20:00:14 +02:00
2016-05-25 23:49:47 +02:00
replyObjectTextView = new SimpleTextView(context);
replyObjectTextView.setTextSize(14);
2016-04-22 15:49:00 +02:00
replyObjectTextView.setTextColor(Theme.REPLY_PANEL_MESSAGE_TEXT_COLOR);
2016-05-25 23:49:47 +02:00
replyLayout.addView(replyObjectTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 18, Gravity.TOP | Gravity.LEFT, 52, 24, 52, 0));
2015-04-09 20:00:14 +02:00
replyImageView = new BackupImageView(context);
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
2016-03-06 02:49:31 +01:00
stickersListView = new RecyclerListView(context) {
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersListView, 0);
return super.onInterceptTouchEvent(event) || result;
}
};
stickersListView.setTag(3);
2016-03-06 02:49:31 +01:00
stickersListView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return StickerPreviewViewer.getInstance().onTouch(event, stickersListView, 0, stickersOnItemClickListener);
}
});
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);
stickersListView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
stickersPanel.addView(stickersListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 78));
2016-03-06 02:49:31 +01:00
initStickers();
2015-04-09 20:00:14 +02:00
imageView = new ImageView(context);
imageView.setImageResource(R.drawable.stickers_back_arrow);
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
searchContainer = new FrameLayout(context);
searchContainer.setBackgroundResource(R.drawable.compose_panel);
searchContainer.setVisibility(View.INVISIBLE);
searchContainer.setFocusable(true);
searchContainer.setFocusableInTouchMode(true);
searchContainer.setClickable(true);
searchContainer.setBackgroundResource(R.drawable.compose_panel);
searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0);
contentView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
searchUpButton = new ImageView(context);
searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
searchUpButton.setImageResource(R.drawable.search_up);
searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48));
searchUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1);
}
});
searchDownButton = new ImageView(context);
searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
searchDownButton.setImageResource(R.drawable.search_down);
searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0));
searchDownButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2);
}
});
searchCountText = new SimpleTextView(context);
searchCountText.setTextColor(Theme.CHAT_SEARCH_COUNT_TEXT_COLOR);
searchCountText.setTextSize(15);
searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0));
2015-04-09 20:00:14 +02:00
bottomOverlay = new FrameLayout(context);
bottomOverlay.setVisibility(View.INVISIBLE);
bottomOverlay.setFocusable(true);
bottomOverlay.setFocusableInTouchMode(true);
bottomOverlay.setClickable(true);
2016-04-22 15:49:00 +02:00
bottomOverlay.setBackgroundResource(R.drawable.compose_panel);
bottomOverlay.setPadding(0, AndroidUtilities.dp(3), 0, 0);
contentView.addView(bottomOverlay, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
2015-04-09 20:00:14 +02:00
bottomOverlayText = new TextView(context);
bottomOverlayText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
2016-04-22 15:49:00 +02:00
bottomOverlayText.setTextColor(Theme.CHAT_BOTTOM_OVERLAY_TEXT_COLOR);
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);
2016-04-22 15:49:00 +02:00
bottomOverlayChat.setBackgroundResource(R.drawable.compose_panel);
bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0);
2015-04-09 20:00:14 +02:00
bottomOverlayChat.setVisibility(View.INVISIBLE);
2016-04-22 15:49:00 +02:00
contentView.addView(bottomOverlayChat, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, 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-11-26 22:04:02 +01:00
if (currentUser.bot) {
2015-09-02 00:14:21 +02:00
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, null, null, null);
}
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-11-26 22:04:02 +01:00
} else if (currentUser != null && currentUser.bot && botUser != null) {
2015-09-24 22:52:02 +02:00
if (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, null, null, null);
2015-06-29 19:12:11 +02:00
}
botUser = null;
updateBottomOverlay();
2015-04-09 20:00:14 +02:00
} else {
2016-03-16 13:26:32 +01:00
if (ChatObject.isChannel(currentChat) && !(currentChat instanceof TLRPC.TL_channelForbidden)) {
2015-09-24 22:52:02 +02:00
if (ChatObject.isNotInChat(currentChat)) {
MessagesController.getInstance().addUserToChat(currentChat.id, UserConfig.getCurrentUser(), null, 0, null, null);
} else {
toggleMute(true);
}
2015-09-24 22:52:02 +02:00
} else {
builder = new AlertDialog.Builder(getParentActivity());
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) {
2015-12-09 19:27:52 +01:00
MessagesController.getInstance().deleteDialog(dialog_id, 0);
2015-09-24 22:52:02 +02:00
finishFragment();
}
});
}
}
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-04-09 20:00:14 +02:00
bottomOverlayChatText = new TextView(context);
2016-04-22 15:49:00 +02:00
bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
bottomOverlayChatText.setTextColor(Theme.CHAT_BOTTOM_CHAT_OVERLAY_TEXT_COLOR);
bottomOverlayChat.addView(bottomOverlayChatText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
2015-04-09 20:00:14 +02:00
2015-11-26 22:04:02 +01:00
chatAdapter.updateRows();
2015-04-09 20:00:14 +02:00
if (loading && messages.isEmpty()) {
2015-11-26 22:04:02 +01:00
progressView.setVisibility(chatAdapter.botInfoRow == -1 ? View.VISIBLE : View.INVISIBLE);
2015-04-09 20:00:14 +02:00
chatListView.setEmptyView(null);
} else {
progressView.setVisibility(View.INVISIBLE);
chatListView.setEmptyView(emptyViewContainer);
}
2015-11-26 22:04:02 +01:00
chatActivityEnterView.setButtons(userBlocked ? null : botButtons);
2015-06-29 19:12:11 +02:00
2015-10-29 18:10:07 +01:00
if (!AndroidUtilities.isTablet() || AndroidUtilities.isSmallTablet()) {
contentView.addView(playerView = new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
}
2015-04-09 20:00:14 +02:00
updateContactStatus();
updateBottomOverlay();
updateSecretStatus();
2015-09-24 22:52:02 +02:00
updateSpamView();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
try {
2016-04-22 15:49:00 +02:00
if (currentEncryptedChat != null && Build.VERSION.SDK_INT >= 23) {
2016-03-16 13:26:32 +01:00
getParentActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
} catch (Throwable e) {
FileLog.e("tmessages", e);
}
2016-04-22 15:49:00 +02:00
fixLayoutInternal();
2015-04-09 20:00:14 +02:00
2016-10-11 13:57:01 +02:00
contentView.addView(actionBar);
2015-04-09 20:00:14 +02:00
return fragmentView;
}
2016-10-11 13:57:01 +02:00
private void sendBotInlineResult(TLRPC.BotInlineResult result) {
int uid = mentionsAdapter.getContextBotId();
HashMap<String, String> params = new HashMap<>();
params.put("id", result.id);
params.put("query_id", "" + result.query_id);
params.put("bot", "" + uid);
params.put("bot_name", mentionsAdapter.getContextBotName());
SendMessagesHelper.prepareSendingBotContextResult(result, params, dialog_id, replyingMessageObject);
chatActivityEnterView.setFieldText("");
showReplyPanel(false, null, null, null, false, true);
SearchQuery.increaseInlineRaiting(uid);
}
2016-04-22 15:49:00 +02:00
private void mentionListViewUpdateLayout() {
2016-05-25 23:49:47 +02:00
if (mentionListView.getChildCount() <= 0) {
2016-04-22 15:49:00 +02:00
mentionListViewScrollOffsetY = 0;
mentionListViewLastViewPosition = -1;
return;
}
View child = mentionListView.getChildAt(mentionListView.getChildCount() - 1);
MentionsAdapter.Holder holder = (MentionsAdapter.Holder) mentionListView.findContainingViewHolder(child);
if (holder != null) {
mentionListViewLastViewPosition = holder.getAdapterPosition();
mentionListViewLastViewTop = child.getTop();
} else {
mentionListViewLastViewPosition = -1;
}
child = mentionListView.getChildAt(0);
holder = (MentionsAdapter.Holder) mentionListView.findContainingViewHolder(child);
int newOffset = child.getTop() > 0 && holder != null && holder.getAdapterPosition() == 0 ? child.getTop() : 0;
if (mentionListViewScrollOffsetY != newOffset) {
mentionListView.setTopGlowOffset(mentionListViewScrollOffsetY = newOffset);
mentionListView.invalidate();
mentionContainer.invalidate();
}
}
2016-05-25 23:49:47 +02:00
private void checkBotCommands() {
URLSpanBotCommand.enabled = false;
if (currentUser != null && currentUser.bot) {
URLSpanBotCommand.enabled = true;
} else if (info instanceof TLRPC.TL_chatFull) {
for (int a = 0; a < info.participants.participants.size(); a++) {
TLRPC.ChatParticipant participant = info.participants.participants.get(a);
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
if (user != null && user.bot) {
URLSpanBotCommand.enabled = true;
break;
}
}
} else if (info instanceof TLRPC.TL_channelFull) {
URLSpanBotCommand.enabled = !info.bot_info.isEmpty();
}
}
2016-04-22 15:49:00 +02:00
public void processInlineBotContextPM(TLRPC.TL_inlineBotSwitchPM object) {
if (object == null) {
return;
}
TLRPC.User user = mentionsAdapter.getContextBotUser();
if (user == null) {
return;
}
chatActivityEnterView.setFieldText("");
if (dialog_id == user.id) {
inlineReturn = dialog_id;
MessagesController.getInstance().sendBotStart(currentUser, object.start_param);
} else {
Bundle args = new Bundle();
args.putInt("user_id", user.id);
args.putString("inline_query", object.start_param);
args.putLong("inline_return", dialog_id);
if (!MessagesController.checkCanOpenChat(args, ChatActivity.this)) {
return;
}
presentFragment(new ChatActivity(args));
}
}
private void createChatAttachView() {
2016-05-25 23:49:47 +02:00
if (getParentActivity() == null) {
return;
}
if (chatAttachAlert == null) {
2016-10-11 13:57:01 +02:00
chatAttachAlert = new ChatAttachAlert(getParentActivity(), this);
2016-05-25 23:49:47 +02:00
chatAttachAlert.setDelegate(new ChatAttachAlert.ChatAttachViewDelegate() {
2016-04-22 15:49:00 +02:00
@Override
public void didPressedButton(int button) {
if (getParentActivity() == null) {
return;
}
2016-04-22 15:49:00 +02:00
if (button == 7) {
2016-05-25 23:49:47 +02:00
chatAttachAlert.dismiss();
HashMap<Integer, MediaController.PhotoEntry> selectedPhotos = chatAttachAlert.getSelectedPhotos();
2016-04-22 15:49:00 +02:00
if (!selectedPhotos.isEmpty()) {
ArrayList<String> photos = new ArrayList<>();
ArrayList<String> captions = new ArrayList<>();
2016-10-11 13:57:01 +02:00
ArrayList<ArrayList<TLRPC.InputDocument>> masks = new ArrayList<>();
2016-04-22 15:49:00 +02:00
for (HashMap.Entry<Integer, MediaController.PhotoEntry> entry : selectedPhotos.entrySet()) {
MediaController.PhotoEntry photoEntry = entry.getValue();
if (photoEntry.imagePath != null) {
photos.add(photoEntry.imagePath);
captions.add(photoEntry.caption != null ? photoEntry.caption.toString() : null);
2016-10-11 13:57:01 +02:00
masks.add(!photoEntry.stickers.isEmpty() ? new ArrayList<>(photoEntry.stickers) : null);
2016-04-22 15:49:00 +02:00
} else if (photoEntry.path != null) {
photos.add(photoEntry.path);
captions.add(photoEntry.caption != null ? photoEntry.caption.toString() : null);
2016-10-11 13:57:01 +02:00
masks.add(!photoEntry.stickers.isEmpty() ? new ArrayList<>(photoEntry.stickers) : null);
2016-04-22 15:49:00 +02:00
}
photoEntry.imagePath = null;
photoEntry.thumbPath = null;
photoEntry.caption = null;
2016-10-11 13:57:01 +02:00
photoEntry.stickers.clear();
2016-04-22 15:49:00 +02:00
}
2016-10-11 13:57:01 +02:00
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject, captions, masks);
2016-04-22 15:49:00 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2016-04-22 15:49:00 +02:00
}
return;
2016-05-25 23:49:47 +02:00
} else if (chatAttachAlert != null) {
chatAttachAlert.dismissWithButtonClick(button);
2016-04-22 15:49:00 +02:00
}
processSelectedAttach(button);
}
@Override
2016-05-25 23:49:47 +02:00
public View getRevealView() {
return menuItem;
2016-04-22 15:49:00 +02:00
}
@Override
2016-05-25 23:49:47 +02:00
public void didSelectBot(TLRPC.User user) {
if (chatActivityEnterView == null || user.username == null || user.username.length() == 0) {
return;
2016-04-22 15:49:00 +02:00
}
2016-05-25 23:49:47 +02:00
chatActivityEnterView.setFieldText("@" + user.username + " ");
chatActivityEnterView.openKeyboard();
2016-04-22 15:49:00 +02:00
}
});
}
}
2016-03-06 02:49:31 +01:00
public long getDialogId() {
return dialog_id;
}
2016-04-22 15:49:00 +02:00
public void setBotUser(String value) {
if (inlineReturn != 0) {
MessagesController.getInstance().sendBotStart(currentUser, value);
} else {
botUser = value;
updateBottomOverlay();
}
}
2016-03-06 02:49:31 +01:00
public boolean playFirstUnreadVoiceMessage() {
for (int a = messages.size() - 1; a >= 0; a--) {
MessageObject messageObject = messages.get(a);
if (messageObject.isVoice() && messageObject.isContentUnread() && !messageObject.isOut() && messageObject.messageOwner.to_id.channel_id == 0) {
MediaController.getInstance().setVoiceMessagesPlaylist(MediaController.getInstance().playAudio(messageObject) ? createVoiceMessagesPlaylist(messageObject, true) : null, true);
return true;
}
}
if (Build.VERSION.SDK_INT >= 23 && getParentActivity() != null) {
if (getParentActivity().checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 3);
return true;
}
}
return false;
}
private void initStickers() {
if (chatActivityEnterView == null || getParentActivity() == null || stickersAdapter != null || currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 23) {
return;
}
if (stickersAdapter != null) {
stickersAdapter.onDestroy();
}
stickersListView.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0);
stickersListView.setAdapter(stickersAdapter = new StickersAdapter(getParentActivity(), new StickersAdapter.StickersAdapterDelegate() {
@Override
public void needChangePanelVisibility(final boolean show) {
if (show && stickersPanel.getVisibility() == View.VISIBLE || !show && stickersPanel.getVisibility() == View.GONE) {
return;
}
if (show) {
stickersListView.scrollToPosition(0);
stickersPanel.setVisibility(allowStickersPanel ? View.VISIBLE : View.INVISIBLE);
}
if (runningAnimation != null) {
runningAnimation.cancel();
runningAnimation = null;
}
if (stickersPanel.getVisibility() != View.INVISIBLE) {
runningAnimation = new AnimatorSet();
2016-03-06 02:49:31 +01:00
runningAnimation.playTogether(
ObjectAnimator.ofFloat(stickersPanel, "alpha", show ? 0.0f : 1.0f, show ? 1.0f : 0.0f)
2016-03-06 02:49:31 +01:00
);
runningAnimation.setDuration(150);
runningAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2016-03-06 02:49:31 +01:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
if (!show) {
stickersAdapter.clearStickers();
stickersPanel.setVisibility(View.GONE);
if (StickerPreviewViewer.getInstance().isVisible()) {
StickerPreviewViewer.getInstance().close();
}
StickerPreviewViewer.getInstance().reset();
}
runningAnimation = null;
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
runningAnimation = null;
}
}
2016-03-06 02:49:31 +01:00
});
runningAnimation.start();
} else if (!show) {
stickersPanel.setVisibility(View.GONE);
}
}
}));
stickersListView.setOnItemClickListener(stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
TLRPC.Document document = stickersAdapter.getItem(position);
if (document instanceof TLRPC.TL_document) {
SendMessagesHelper.getInstance().sendSticker(document, dialog_id, replyingMessageObject);
2016-03-06 02:49:31 +01:00
showReplyPanel(false, null, null, null, false, true);
2016-05-25 23:49:47 +02:00
chatActivityEnterView.addStickerToRecent(document);
2016-03-06 02:49:31 +01:00
}
chatActivityEnterView.setFieldText("");
}
});
}
2016-04-22 15:49:00 +02:00
public void shareMyContact(final MessageObject messageObject) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ShareYouPhoneNumberTitle", R.string.ShareYouPhoneNumberTitle));
if (currentUser != null) {
if (currentUser.bot) {
builder.setMessage(LocaleController.getString("AreYouSureShareMyContactInfoBot", R.string.AreYouSureShareMyContactInfoBot));
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureShareMyContactInfoUser", R.string.AreYouSureShareMyContactInfoUser, PhoneFormat.getInstance().format("+" + UserConfig.getCurrentUser().phone), ContactsController.formatName(currentUser.first_name, currentUser.last_name))));
}
} else {
builder.setMessage(LocaleController.getString("AreYouSureShareMyContactInfo", R.string.AreYouSureShareMyContactInfo));
}
2016-04-22 15:49:00 +02:00
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
SendMessagesHelper.getInstance().sendMessage(UserConfig.getCurrentUser(), dialog_id, messageObject, null, null);
2016-04-22 15:49:00 +02:00
moveScrollToLastMessage();
showReplyPanel(false, null, null, null, false, true);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
private void showGifHint() {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (preferences.getBoolean("gifhint", false)) {
return;
}
preferences.edit().putBoolean("gifhint", true).commit();
if (getParentActivity() == null || fragmentView == null || gifHintTextView != null) {
return;
}
if (!allowContextBotPanelSecond) {
if (chatActivityEnterView != null) {
chatActivityEnterView.setOpenGifsTabFirst();
}
return;
}
SizeNotifierFrameLayout frameLayout = (SizeNotifierFrameLayout) fragmentView;
int index = frameLayout.indexOfChild(chatActivityEnterView);
if (index == -1) {
return;
}
chatActivityEnterView.setOpenGifsTabFirst();
emojiButtonRed = new View(getParentActivity());
emojiButtonRed.setBackgroundResource(R.drawable.redcircle);
frameLayout.addView(emojiButtonRed, index + 1, LayoutHelper.createFrame(10, 10, Gravity.BOTTOM | Gravity.LEFT, 30, 0, 0, 27));
gifHintTextView = new TextView(getParentActivity());
gifHintTextView.setBackgroundResource(R.drawable.tooltip);
2016-04-22 15:49:00 +02:00
gifHintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR);
gifHintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
gifHintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
gifHintTextView.setText(LocaleController.getString("TapHereGifs", R.string.TapHereGifs));
gifHintTextView.setGravity(Gravity.CENTER_VERTICAL);
frameLayout.addView(gifHintTextView, index + 1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.LEFT | Gravity.BOTTOM, 5, 0, 0, 3));
AnimatorSet AnimatorSet = new AnimatorSet();
AnimatorSet.playTogether(
ObjectAnimator.ofFloat(gifHintTextView, "alpha", 0.0f, 1.0f),
ObjectAnimator.ofFloat(emojiButtonRed, "alpha", 0.0f, 1.0f)
);
AnimatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (gifHintTextView == null) {
return;
}
AnimatorSet AnimatorSet = new AnimatorSet();
AnimatorSet.playTogether(
ObjectAnimator.ofFloat(gifHintTextView, "alpha", 0.0f)
);
AnimatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (gifHintTextView != null) {
gifHintTextView.setVisibility(View.GONE);
}
}
});
AnimatorSet.setDuration(300);
AnimatorSet.start();
}
}, 2000);
}
});
AnimatorSet.setDuration(300);
AnimatorSet.start();
}
private void checkContextBotPanel() {
if (allowStickersPanel && mentionsAdapter != null && mentionsAdapter.isBotContext()) {
if (!allowContextBotPanel && !allowContextBotPanelSecond) {
2016-04-22 15:49:00 +02:00
if (mentionContainer.getVisibility() == View.VISIBLE && mentionContainer.getTag() == null) {
if (mentionListAnimation != null) {
mentionListAnimation.cancel();
}
2016-04-22 15:49:00 +02:00
mentionContainer.setTag(1);
mentionListAnimation = new AnimatorSet();
mentionListAnimation.playTogether(
ObjectAnimator.ofFloat(mentionContainer, "alpha", 0.0f)
);
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
2016-04-22 15:49:00 +02:00
mentionContainer.setVisibility(View.INVISIBLE);
mentionListAnimation = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
mentionListAnimation = null;
}
}
});
mentionListAnimation.setDuration(200);
mentionListAnimation.start();
}
} else {
2016-04-22 15:49:00 +02:00
if (mentionContainer.getVisibility() == View.INVISIBLE || mentionContainer.getTag() != null) {
if (mentionListAnimation != null) {
mentionListAnimation.cancel();
}
2016-04-22 15:49:00 +02:00
mentionContainer.setTag(null);
mentionContainer.setVisibility(View.VISIBLE);
mentionListAnimation = new AnimatorSet();
mentionListAnimation.playTogether(
ObjectAnimator.ofFloat(mentionContainer, "alpha", 0.0f, 1.0f)
);
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
2016-04-22 15:49:00 +02:00
mentionListAnimation = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
mentionListAnimation = null;
}
}
});
mentionListAnimation.setDuration(200);
mentionListAnimation.start();
}
}
}
}
2016-04-22 15:49:00 +02:00
private void checkScrollForLoad(boolean scroll) {
2015-12-09 19:27:52 +01:00
if (chatLayoutManager == null || paused) {
2015-11-26 22:04:02 +01:00
return;
}
int firstVisibleItem = chatLayoutManager.findFirstVisibleItemPosition();
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(chatLayoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
if (visibleItemCount > 0) {
int totalItemCount = chatAdapter.getItemCount();
2016-04-22 15:49:00 +02:00
int checkLoadCount;
if (scroll) {
2016-04-25 21:26:41 +02:00
checkLoadCount = 25;
2016-04-22 15:49:00 +02:00
} else {
checkLoadCount = 5;
}
if (firstVisibleItem <= checkLoadCount && !loading) {
2015-11-26 22:04:02 +01:00
if (!endReached[0]) {
loading = true;
waitingForLoad.add(lastLoadIndex);
if (messagesByDays.size() != 0) {
MessagesController.getInstance().loadMessages(dialog_id, 50, maxMessageId[0], !cacheEndReached[0], minDate[0], classGuid, 0, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-11-26 22:04:02 +01:00
} else {
MessagesController.getInstance().loadMessages(dialog_id, 50, 0, !cacheEndReached[0], minDate[0], classGuid, 0, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-11-26 22:04:02 +01:00
}
} else if (mergeDialogId != 0 && !endReached[1]) {
loading = true;
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(mergeDialogId, 50, maxMessageId[1], !cacheEndReached[1], minDate[1], classGuid, 0, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-11-26 22:04:02 +01:00
}
}
if (!loadingForward && firstVisibleItem + visibleItemCount >= totalItemCount - 10) {
if (mergeDialogId != 0 && !forwardEndReached[1]) {
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(mergeDialogId, 50, minMessageId[1], true, maxDate[1], classGuid, 1, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-11-26 22:04:02 +01:00
loadingForward = true;
} else if (!forwardEndReached[0]) {
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(dialog_id, 50, minMessageId[0], true, maxDate[0], classGuid, 1, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-11-26 22:04:02 +01:00
loadingForward = true;
2015-05-21 23:27:27 +02:00
}
}
}
}
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";
}
}
2015-09-24 22:52:02 +02:00
if (!MessagesController.isFeatureEnabled(action, ChatActivity.this)) {
2015-06-29 19:12:11 +02:00
return;
}
}
if (which == attach_photo) {
2016-10-11 13:57:01 +02:00
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.CAMERA}, 19);
return;
}
2015-06-29 19:12:11 +02:00
try {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = AndroidUtilities.generatePicturePath();
if (image != null) {
2016-10-11 13:57:01 +02:00
if (Build.VERSION.SDK_INT >= 24) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image));
takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
}
2015-06-29 19:12:11 +02:00
currentPicturePath = image.getAbsolutePath();
}
startActivityForResult(takePictureIntent, 0);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (which == attach_gallery) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4);
return;
}
2016-10-11 13:57:01 +02:00
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(false, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46, true, ChatActivity.this);
2015-06-29 19:12:11 +02:00
fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
@Override
2016-10-11 13:57:01 +02:00
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<ArrayList<TLRPC.InputDocument>> masks, ArrayList<MediaController.SearchImage> webPhotos) {
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject, captions, masks);
SendMessagesHelper.prepareSendingPhotosSearch(webPhotos, dialog_id, replyingMessageObject);
2015-06-29 19:12:11 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2015-06-29 19:12:11 +02:00
}
@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 {
2016-10-11 13:57:01 +02:00
SendMessagesHelper.prepareSendingVideo(path, 0, 0, 0, 0, null, dialog_id, replyingMessageObject, null);
2015-06-29 19:12:11 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2015-06-29 19:12:11 +02:00
return true;
}
}
});
presentFragment(fragment);
} else if (which == attach_video) {
2016-10-11 13:57:01 +02:00
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.CAMERA}, 20);
return;
}
2015-06-29 19:12:11 +02:00
try {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File video = AndroidUtilities.generateVideoPath();
if (video != null) {
2016-10-11 13:57:01 +02:00
if (Build.VERSION.SDK_INT >= 24) {
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", video));
takeVideoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else if (Build.VERSION.SDK_INT >= 18) {
2015-06-29 19:12:11 +02:00
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) {
2016-04-22 15:49:00 +02:00
if (!AndroidUtilities.isGoogleMapsInstalled(ChatActivity.this)) {
2015-06-29 19:12:11 +02:00
return;
}
LocationActivity fragment = new LocationActivity();
fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
@Override
public void didSelectLocation(TLRPC.MessageMedia location) {
SendMessagesHelper.getInstance().sendMessage(location, dialog_id, replyingMessageObject, null, null);
2015-06-29 19:12:11 +02:00
moveScrollToLastMessage();
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2015-06-29 19:12:11 +02:00
if (paused) {
scrollToTopOnResume = true;
}
}
});
presentFragment(fragment);
} else if (which == attach_document) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4);
return;
}
2015-06-29 19:12:11 +02:00
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);
2015-06-29 19:12:11 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2015-06-29 19:12:11 +02:00
}
@Override
public void startDocumentSelectActivity() {
try {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("*/*");
startActivityForResult(photoPickerIntent, 21);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
presentFragment(fragment);
} else if (which == attach_audio) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4);
return;
}
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);
2015-07-22 20:56:37 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2015-07-22 20:56:37 +02:00
}
});
presentFragment(fragment);
2015-06-29 19:12:11 +02:00
} else if (which == attach_contact) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT >= 23) {
if (getParentActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 5);
return;
}
}
2015-06-29 19:12:11 +02:00
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-10-29 18:10:07 +01:00
@Override
public boolean dismissDialogOnPause(Dialog dialog) {
2016-10-11 13:57:01 +02:00
return dialog != chatAttachAlert && super.dismissDialogOnPause(dialog);
2015-10-29 18:10:07 +01:00
}
2016-03-06 02:49:31 +01:00
private void searchLinks(final CharSequence charSequence, final boolean force) {
if (currentEncryptedChat != null && (MessagesController.getInstance().secretWebpagePreview == 0 || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 46)) {
2015-04-09 20:00:14 +02:00
return;
}
if (force && foundWebPage != null) {
if (foundWebPage.url != null) {
int index = TextUtils.indexOf(charSequence, foundWebPage.url);
2016-03-06 02:49:31 +01:00
char lastChar = 0;
boolean lenEqual = false;
2015-04-09 20:00:14 +02:00
if (index == -1) {
2016-03-06 02:49:31 +01:00
if (foundWebPage.display_url != null) {
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;
}
2015-04-09 20:00:14 +02:00
} else {
2015-09-24 22:52:02 +02:00
lenEqual = index + foundWebPage.url.length() == charSequence.length();
lastChar = !lenEqual ? charSequence.charAt(index + foundWebPage.url.length()) : 0;
}
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-11-26 22:04:02 +01:00
Utilities.searchQueue.postRunnable(new Runnable() {
2015-04-09 20:00:14 +02:00
@Override
2015-11-26 22:04:02 +01:00
public void run() {
if (linkSearchRequestId != 0) {
ConnectionsManager.getInstance().cancelRequest(linkSearchRequestId, true);
linkSearchRequestId = 0;
}
ArrayList<CharSequence> urls = null;
CharSequence textToCheck;
try {
Matcher m = AndroidUtilities.WEB_URL.matcher(charSequence);
while (m.find()) {
2016-03-06 02:49:31 +01:00
if (m.start() > 0) {
if (charSequence.charAt(m.start() - 1) == '@') {
continue;
}
}
2015-11-26 22:04:02 +01:00
if (urls == null) {
urls = new ArrayList<>();
}
urls.add(charSequence.subSequence(m.start(), m.end()));
}
if (urls != null && foundUrls != null && urls.size() == foundUrls.size()) {
boolean clear = true;
for (int a = 0; a < urls.size(); a++) {
if (!TextUtils.equals(urls.get(a), foundUrls.get(a))) {
clear = false;
}
}
if (clear) {
return;
}
}
foundUrls = urls;
if (urls == null) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (foundWebPage != null) {
showReplyPanel(false, null, null, foundWebPage, false, true);
foundWebPage = null;
2015-01-09 13:50:15 +01:00
}
2015-11-26 22:04:02 +01:00
}
});
return;
}
textToCheck = TextUtils.join(" ", urls);
} catch (Exception e) {
FileLog.e("tmessages", e);
String text = charSequence.toString().toLowerCase();
if (charSequence.length() < 13 || !text.contains("http://") && !text.contains("https://")) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
2015-04-09 20:00:14 +02:00
if (foundWebPage != null) {
showReplyPanel(false, null, null, foundWebPage, false, true);
foundWebPage = null;
2015-03-27 11:32:33 +01:00
}
}
2015-11-26 22:04:02 +01:00
});
return;
}
textToCheck = charSequence;
}
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat != null && MessagesController.getInstance().secretWebpagePreview == 2) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MessagesController.getInstance().secretWebpagePreview = 1;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit().putInt("secretWebpage2", MessagesController.getInstance().secretWebpagePreview).commit();
foundUrls = null;
searchLinks(charSequence, force);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setMessage(LocaleController.getString("SecretLinkPreviewAlert", R.string.SecretLinkPreviewAlert));
showDialog(builder.create());
MessagesController.getInstance().secretWebpagePreview = 0;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit().putInt("secretWebpage2", MessagesController.getInstance().secretWebpagePreview).commit();
}
});
return;
}
2015-11-26 22:04:02 +01:00
final TLRPC.TL_messages_getWebPagePreview req = new TLRPC.TL_messages_getWebPagePreview();
if (textToCheck instanceof String) {
req.message = (String) textToCheck;
} else {
req.message = textToCheck.toString();
}
linkSearchRequestId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
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;
}
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat != null && foundWebPage instanceof TLRPC.TL_webPagePending) {
foundWebPage.url = req.message;
}
2015-11-26 22:04:02 +01:00
showReplyPanel(true, null, null, foundWebPage, false, true);
} else {
if (foundWebPage != null) {
showReplyPanel(false, null, null, foundWebPage, false, true);
foundWebPage = null;
}
}
} else {
if (foundWebPage != null) {
showReplyPanel(false, null, null, foundWebPage, false, true);
foundWebPage = null;
}
}
}
}
});
2015-03-26 18:34:47 +01:00
}
2015-04-09 20:00:14 +02:00
});
2015-11-26 22:04:02 +01:00
ConnectionsManager.getInstance().bindRequestToGuid(linkSearchRequestId, classGuid);
2013-10-25 17:19:00 +02:00
}
2015-04-09 20:00:14 +02:00
});
2013-10-25 17:19:00 +02: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);
2015-03-20 00:03:19 +01:00
} else {
for (MessageObject object : arrayList) {
SendMessagesHelper.getInstance().processForwardFromMyName(object, dialog_id);
}
}
}
2016-05-25 23:49:47 +02:00
public void showReplyPanel(boolean show, MessageObject messageObjectToReply, ArrayList<MessageObject> messageObjectsToForward, TLRPC.WebPage webPage, boolean cancel, boolean animated) {
2015-11-26 22:04:02 +01:00
if (chatActivityEnterView == null) {
return;
}
if (show) {
2016-05-25 23:49:47 +02:00
if (messageObjectToReply == null && messageObjectsToForward == null && webPage == null) {
return;
}
if (searchItem != null && actionBar.isSearchFieldVisible()) {
actionBar.closeSearchField();
chatActivityEnterView.setFieldFocused();
}
2015-11-26 22:04:02 +01:00
boolean openKeyboard = false;
2016-05-25 23:49:47 +02:00
if (messageObjectToReply != null && messageObjectToReply.getDialogId() != dialog_id) {
messageObjectsToForward = new ArrayList<>();
messageObjectsToForward.add(messageObjectToReply);
messageObjectToReply = null;
2015-11-26 22:04:02 +01:00
openKeyboard = true;
}
2016-05-25 23:49:47 +02:00
if (messageObjectToReply != null) {
forwardingMessages = null;
replyingMessageObject = messageObjectToReply;
chatActivityEnterView.setReplyingMessageObject(messageObjectToReply);
if (foundWebPage != null) {
return;
}
2015-09-24 22:52:02 +02:00
String name;
2016-05-25 23:49:47 +02:00
if (messageObjectToReply.isFromUser()) {
TLRPC.User user = MessagesController.getInstance().getUser(messageObjectToReply.messageOwner.from_id);
2015-09-24 22:52:02 +02:00
if (user == null) {
return;
}
name = UserObject.getUserName(user);
} else {
2016-05-25 23:49:47 +02:00
TLRPC.Chat chat = MessagesController.getInstance().getChat(messageObjectToReply.messageOwner.to_id.channel_id);
2015-09-24 22:52:02 +02:00
if (chat == null) {
return;
}
name = chat.title;
}
2015-04-09 20:00:14 +02:00
replyIconImageView.setImageResource(R.drawable.reply);
2015-09-24 22:52:02 +02:00
replyNameTextView.setText(name);
2016-05-25 23:49:47 +02:00
2016-10-11 13:57:01 +02:00
if (messageObjectToReply.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
replyObjectTextView.setText(Emoji.replaceEmoji(messageObjectToReply.messageOwner.media.game.title, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
} else if (messageObjectToReply.messageText != null) {
2016-05-25 23:49:47 +02:00
String mess = messageObjectToReply.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
2016-04-22 15:49:00 +02:00
mess = mess.replace('\n', ' ');
2015-07-22 20:56:37 +02:00
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
}
2016-05-25 23:49:47 +02:00
} else if (messageObjectsToForward != null) {
if (messageObjectsToForward.isEmpty()) {
return;
}
replyingMessageObject = null;
2015-04-09 20:00:14 +02:00
chatActivityEnterView.setReplyingMessageObject(null);
2016-05-25 23:49:47 +02:00
forwardingMessages = messageObjectsToForward;
2015-04-09 20:00:14 +02:00
if (foundWebPage != null) {
return;
}
chatActivityEnterView.setForceShowSendButton(true, animated);
ArrayList<Integer> uids = new ArrayList<>();
replyIconImageView.setImageResource(R.drawable.forward_blue);
2016-05-25 23:49:47 +02:00
MessageObject object = messageObjectsToForward.get(0);
2016-03-06 02:49:31 +01:00
if (object.isFromUser()) {
uids.add(object.messageOwner.from_id);
} else {
uids.add(-object.messageOwner.to_id.channel_id);
}
2016-05-25 23:49:47 +02:00
int type = messageObjectsToForward.get(0).type;
for (int a = 1; a < messageObjectsToForward.size(); a++) {
object = messageObjectsToForward.get(a);
2016-03-06 02:49:31 +01:00
Integer uid;
if (object.isFromUser()) {
uid = object.messageOwner.from_id;
} else {
uid = -object.messageOwner.to_id.channel_id;
}
if (!uids.contains(uid)) {
uids.add(uid);
}
2016-05-25 23:49:47 +02:00
if (messageObjectsToForward.get(a).type != type) {
type = -1;
}
}
StringBuilder userNames = new StringBuilder();
for (int a = 0; a < uids.size(); a++) {
Integer uid = uids.get(a);
2015-09-24 22:52:02 +02:00
TLRPC.Chat chat = null;
TLRPC.User user = null;
if (uid > 0) {
user = MessagesController.getInstance().getUser(uid);
} else {
chat = MessagesController.getInstance().getChat(-uid);
}
if (user == null && chat == null) {
continue;
}
if (uids.size() == 1) {
2015-09-24 22:52:02 +02:00
if (user != null) {
userNames.append(UserObject.getUserName(user));
} else {
userNames.append(chat.title);
}
} else if (uids.size() == 2 || userNames.length() == 0) {
if (userNames.length() > 0) {
userNames.append(", ");
}
2015-09-24 22:52:02 +02:00
if (user != null) {
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 {
2015-09-24 22:52:02 +02:00
userNames.append(chat.title);
}
} else {
userNames.append(" ");
userNames.append(LocaleController.formatPluralString("AndOther", uids.size() - 1));
break;
}
}
replyNameTextView.setText(userNames);
2015-11-26 22:04:02 +01:00
if (type == -1 || type == 0 || type == 10 || type == 11) {
2016-05-25 23:49:47 +02:00
if (messageObjectsToForward.size() == 1 && messageObjectsToForward.get(0).messageText != null) {
2016-10-11 13:57:01 +02:00
MessageObject messageObject = messageObjectsToForward.get(0);
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
replyObjectTextView.setText(Emoji.replaceEmoji(messageObject.messageOwner.media.game.title, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
} else {
String mess = messageObject.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
mess = mess.replace('\n', ' ');
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
}
} else {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedMessage", messageObjectsToForward.size()));
}
} else {
if (type == 1) {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedPhoto", messageObjectsToForward.size()));
if (messageObjectsToForward.size() == 1) {
messageObjectToReply = messageObjectsToForward.get(0);
}
} else if (type == 4) {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedLocation", messageObjectsToForward.size()));
} else if (type == 3) {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedVideo", messageObjectsToForward.size()));
if (messageObjectsToForward.size() == 1) {
messageObjectToReply = messageObjectsToForward.get(0);
}
} else if (type == 12) {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedContact", messageObjectsToForward.size()));
2016-03-06 02:49:31 +01:00
} else if (type == 2) {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedAudio", messageObjectsToForward.size()));
2016-03-06 02:49:31 +01:00
} else if (type == 14) {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedMusic", messageObjectsToForward.size()));
} else if (type == 13) {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedSticker", messageObjectsToForward.size()));
} else if (type == 8 || type == 9) {
2016-05-25 23:49:47 +02:00
if (messageObjectsToForward.size() == 1) {
if (type == 8) {
replyObjectTextView.setText(LocaleController.getString("AttachGif", R.string.AttachGif));
} else {
String name;
2016-05-25 23:49:47 +02:00
if ((name = FileLoader.getDocumentFileName(messageObjectsToForward.get(0).getDocument())).length() != 0) {
replyObjectTextView.setText(name);
}
2016-05-25 23:49:47 +02:00
messageObjectToReply = messageObjectsToForward.get(0);
}
} else {
2016-05-25 23:49:47 +02:00
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedFile", messageObjectsToForward.size()));
}
}
}
2015-09-24 22:52:02 +02:00
} else {
2015-04-09 20:00:14 +02:00
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);
2015-11-26 22:04:02 +01:00
} else {
replyNameTextView.setText(LocaleController.getString("LinkPreview", R.string.LinkPreview));
2015-04-09 20:00:14 +02:00
}
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);
}
}
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) replyNameTextView.getLayoutParams();
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) replyObjectTextView.getLayoutParams();
2016-10-11 13:57:01 +02:00
TLRPC.PhotoSize photoSize = null;
if (messageObjectToReply != null) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObjectToReply.photoThumbs2, 80);
if (photoSize == null) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObjectToReply.photoThumbs, 80);
}
}
2016-05-25 23:49:47 +02:00
if (photoSize == null || photoSize instanceof TLRPC.TL_photoSizeEmpty || photoSize.location instanceof TLRPC.TL_fileLocationUnavailable || messageObjectToReply.type == 13 || messageObjectToReply != null && messageObjectToReply.isSecretMedia()) {
replyImageView.setImageBitmap(null);
2015-04-09 20:00:14 +02:00
replyImageLocation = null;
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);
replyImageView.setVisibility(View.VISIBLE);
layoutParams1.leftMargin = layoutParams2.leftMargin = AndroidUtilities.dp(96);
}
replyNameTextView.setLayoutParams(layoutParams1);
replyObjectTextView.setLayoutParams(layoutParams2);
2015-11-26 22:04:02 +01:00
chatActivityEnterView.showTopView(animated, openKeyboard);
} else {
2015-04-09 20:00:14 +02:00
if (replyingMessageObject == null && forwardingMessages == null && foundWebPage == null) {
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;
}
}
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;
}
}
private void moveScrollToLastMessage() {
2016-05-25 23:49:47 +02:00
if (chatListView != null && !messages.isEmpty()) {
chatLayoutManager.scrollToPositionWithOffset(messages.size() - 1, -100000 - chatListView.getPaddingTop());
}
}
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;
}
2015-09-24 22:52:02 +02:00
private void clearChatData() {
messages.clear();
messagesByDays.clear();
2015-11-26 22:04:02 +01:00
waitingForLoad.clear();
progressView.setVisibility(chatAdapter.botInfoRow == -1 ? View.VISIBLE : View.INVISIBLE);
2015-09-24 22:52:02 +02:00
chatListView.setEmptyView(null);
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
messagesDict[a].clear();
if (currentEncryptedChat == null) {
maxMessageId[a] = Integer.MAX_VALUE;
minMessageId[a] = Integer.MIN_VALUE;
} else {
maxMessageId[a] = Integer.MIN_VALUE;
minMessageId[a] = Integer.MAX_VALUE;
}
maxDate[a] = Integer.MIN_VALUE;
minDate[a] = 0;
endReached[a] = false;
cacheEndReached[a] = false;
forwardEndReached[a] = true;
2015-09-24 22:52:02 +02:00
}
first = true;
firstLoading = true;
loading = true;
loadingForward = false;
2016-03-16 13:26:32 +01:00
waitingForReplyMessageLoad = false;
2015-09-24 22:52:02 +02:00
startLoadFromMessageId = 0;
2015-11-26 22:04:02 +01:00
last_message_id = 0;
2015-09-24 22:52:02 +02:00
needSelectFromMessageId = false;
chatAdapter.notifyDataSetChanged();
}
2015-10-29 18:10:07 +01:00
private void scrollToLastMessage(boolean pagedown) {
2015-11-26 22:04:02 +01:00
if (forwardEndReached[0] && first_unread_id == 0 && startLoadFromMessageId == 0) {
2015-10-29 18:10:07 +01:00
if (pagedown && chatLayoutManager.findLastCompletelyVisibleItemPosition() == chatAdapter.getItemCount() - 1) {
showPagedownButton(false, true);
highlightMessageId = Integer.MAX_VALUE;
updateVisibleRows();
} else {
chatLayoutManager.scrollToPositionWithOffset(messages.size() - 1, -100000 - chatListView.getPaddingTop());
}
} else {
2015-09-24 22:52:02 +02:00
clearChatData();
2015-11-26 22:04:02 +01:00
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, true, 0, classGuid, 0, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
}
}
private void updateMessagesVisisblePart() {
if (chatListView == null) {
return;
}
int count = chatListView.getChildCount();
int additionalTop = chatActivityEnterView.isTopViewVisible() ? AndroidUtilities.dp(48) : 0;
int height = chatListView.getMeasuredHeight();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell messageCell = (ChatMessageCell) view;
int top = messageCell.getTop();
int bottom = messageCell.getBottom();
int viewTop = top >= 0 ? 0 : -top;
int viewBottom = messageCell.getMeasuredHeight();
if (viewBottom > height) {
viewBottom = viewTop + height;
}
messageCell.setVisiblePart(viewTop, viewBottom - viewTop);
}
}
}
2015-09-24 22:52:02 +02:00
private void toggleMute(boolean instant) {
boolean muted = MessagesController.getInstance().isDialogMuted(dialog_id);
if (!muted) {
if (instant) {
long flags;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("notify2_" + dialog_id, 2);
flags = 1;
MessagesStorage.getInstance().setDialogFlags(dialog_id, flags);
editor.commit();
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
2015-09-24 22:52:02 +02:00
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
2015-11-26 22:04:02 +01:00
NotificationsController.getInstance().removeNotificationsForDialog(dialog_id);
2015-09-24 22:52:02 +02:00
} else {
showDialog(AlertsCreator.createMuteAlert(getParentActivity(), dialog_id));
}
} 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);
2015-09-24 22:52:02 +02:00
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
}
}
2015-11-26 22:04:02 +01:00
private void scrollToMessageId(int id, int fromMessageId, boolean select, int loadIndex) {
MessageObject object = messagesDict[loadIndex].get(id);
2015-03-26 18:34:47 +01:00
boolean query = false;
if (object != null) {
int index = messages.indexOf(object);
if (index != -1) {
2015-11-26 22:04:02 +01:00
if (select) {
2015-03-26 18:34:47 +01:00
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-09-24 22:52:02 +02:00
chatLayoutManager.scrollToPositionWithOffset(0, -chatListView.getPaddingTop() - AndroidUtilities.dp(7) + yOffset);
2015-03-26 18:34:47 +01:00
} else {
2015-11-26 22:04:02 +01:00
chatLayoutManager.scrollToPositionWithOffset(chatAdapter.messagesStartRow + messages.size() - messages.indexOf(object) - 1, -chatListView.getPaddingTop() - AndroidUtilities.dp(7) + yOffset);
2015-03-26 18:34:47 +01:00
}
updateVisibleRows();
2015-10-29 18:10:07 +01:00
boolean found = false;
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
2016-05-25 23:49:47 +02:00
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && messageObject.getId() == object.getId()) {
2015-10-29 18:10:07 +01:00
found = true;
break;
}
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
2016-05-25 23:49:47 +02:00
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && messageObject.getId() == object.getId()) {
2015-10-29 18:10:07 +01:00
found = true;
break;
}
}
}
if (!found) {
showPagedownButton(true, true);
}
2015-03-26 18:34:47 +01:00
} else {
query = true;
}
} else {
query = true;
}
if (query) {
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat != null && !MessagesStorage.getInstance().checkMessageId(dialog_id, startLoadFromMessageId)) {
return;
}
2016-03-16 13:26:32 +01:00
/*clearChatData();
2015-03-26 18:34:47 +01:00
loadsCount = 0;
unread_to_load = 0;
first_unread_id = 0;
loadingForward = false;
unreadMessageObject = null;
2016-03-16 13:26:32 +01:00
scrollToMessage = null;*/
waitingForLoad.clear();
2016-03-16 13:26:32 +01:00
waitingForReplyMessageLoad = true;
2015-03-26 18:34:47 +01:00
highlightMessageId = Integer.MAX_VALUE;
2015-09-24 22:52:02 +02:00
scrollToMessagePosition = -10000;
2015-03-26 18:34:47 +01:00
startLoadFromMessageId = id;
2015-11-26 22:04:02 +01:00
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(loadIndex == 0 ? dialog_id : mergeDialogId, AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, true, 0, classGuid, 3, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2016-03-16 13:26:32 +01:00
//emptyViewContainer.setVisibility(View.INVISIBLE);
2015-03-26 18:34:47 +01:00
}
2015-11-26 22:04:02 +01:00
returnToMessageId = fromMessageId;
2016-03-16 13:26:32 +01:00
returnToLoadIndex = loadIndex;
2015-11-26 22:04:02 +01:00
needSelectFromMessageId = select;
2015-03-26 18:34:47 +01:00
}
2013-12-20 20:25:49 +01:00
private void showPagedownButton(boolean show, boolean animated) {
if (pagedownButton == null) {
return;
}
if (show) {
pagedownButtonShowedByScroll = false;
2015-10-29 18:10:07 +01:00
if (pagedownButton.getTag() == null) {
if (pagedownButtonAnimation != null) {
pagedownButtonAnimation.cancel();
pagedownButtonAnimation = null;
}
2014-11-17 03:44:57 +01:00
if (animated) {
if (pagedownButton.getTranslationY() == 0) {
pagedownButton.setTranslationY(AndroidUtilities.dp(100));
2015-10-29 18:10:07 +01:00
}
2013-12-20 20:25:49 +01:00
pagedownButton.setVisibility(View.VISIBLE);
2015-10-29 18:10:07 +01:00
pagedownButton.setTag(1);
pagedownButtonAnimation = ObjectAnimator.ofFloat(pagedownButton, "translationY", 0).setDuration(200);
pagedownButtonAnimation.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;
newUnreadMessageCount = 0;
2015-10-29 18:10:07 +01:00
if (pagedownButton.getTag() != null) {
pagedownButton.setTag(null);
if (pagedownButtonAnimation != null) {
pagedownButtonAnimation.cancel();
pagedownButtonAnimation = null;
}
2014-11-17 03:44:57 +01:00
if (animated) {
pagedownButtonAnimation = ObjectAnimator.ofFloat(pagedownButton, "translationY", AndroidUtilities.dp(100)).setDuration(200);
pagedownButtonAnimation.addListener(new AnimatorListenerAdapterProxy() {
2013-12-20 20:25:49 +01:00
@Override
public void onAnimationEnd(Animator animation) {
pagedownButtonCounter.setVisibility(View.INVISIBLE);
pagedownButton.setVisibility(View.INVISIBLE);
2013-12-20 20:25:49 +01:00
}
});
pagedownButtonAnimation.start();
2013-12-20 20:25:49 +01:00
} else {
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;
}
2016-10-11 13:57:01 +02:00
if (currentEncryptedChat == null || bigEmptyView == null) {
bottomOverlay.setVisibility(View.INVISIBLE);
2013-10-25 17:19:00 +02:00
return;
}
boolean hideKeyboard = false;
if (currentEncryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
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) {
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("");
DraftQuery.cleanDraft(dialog_id, false);
2013-10-25 17:19:00 +02:00
hideKeyboard = true;
} else if (currentEncryptedChat instanceof TLRPC.TL_encryptedChat) {
bottomOverlay.setVisibility(View.INVISIBLE);
2013-10-25 17:19:00 +02:00
}
2016-03-06 02:49:31 +01:00
checkRaiseSensors();
2013-10-25 17:19:00 +02:00
if (hideKeyboard) {
2015-09-02 00:14:21 +02:00
chatActivityEnterView.hidePopup(false);
if (getParentActivity() != null) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
checkActionBarMenu();
}
2016-04-22 15:49:00 +02:00
@Override
public void onRequestPermissionsResultFragment(int requestCode, String[] permissions, int[] grantResults) {
if (chatActivityEnterView != null) {
chatActivityEnterView.onRequestPermissionsResultFragment(requestCode, permissions, grantResults);
}
if (mentionsAdapter != null) {
mentionsAdapter.onRequestPermissionsResultFragment(requestCode, permissions, grantResults);
}
2016-10-11 13:57:01 +02:00
if (requestCode == 17 && chatAttachAlert != null) {
chatAttachAlert.checkCamera(false);
} else if (requestCode == 19 && grantResults != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
processSelectedAttach(attach_photo);
} else if (requestCode == 20 && grantResults != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
processSelectedAttach(attach_video);
}
2016-04-22 15:49:00 +02:00
}
private void checkActionBarMenu() {
if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat) ||
2015-09-24 22:52:02 +02:00
currentChat != null && ChatObject.isNotInChat(currentChat) ||
2015-06-29 19:12:11 +02:00
currentUser != null && UserObject.isDeleted(currentUser)) {
if (menuItem != null) {
menuItem.setVisibility(View.GONE);
}
2014-11-19 16:17:24 +01:00
if (timeItem2 != null) {
timeItem2.setVisibility(View.GONE);
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null) {
avatarContainer.hideTimeItem();
}
} else {
if (menuItem != null) {
menuItem.setVisibility(View.VISIBLE);
}
2014-11-19 16:17:24 +01:00
if (timeItem2 != null) {
timeItem2.setVisibility(View.VISIBLE);
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null) {
avatarContainer.showTimeItem();
}
2013-10-25 17:19:00 +02:00
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null && currentEncryptedChat != null) {
avatarContainer.setTime(currentEncryptedChat.ttl);
}
checkAndUpdateAvatar();
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) {
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) {
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 {
2016-04-22 15:49:00 +02:00
if (messageObject.isVoice()) {
return 2;
} else if (messageObject.isSticker()) {
TLRPC.InputStickerSet inputStickerSet = messageObject.getInputStickerSet();
if (inputStickerSet instanceof TLRPC.TL_inputStickerSetID) {
if (!StickersQuery.isStickerPackInstalled(inputStickerSet.id)) {
return 7;
2015-05-21 23:27:27 +02:00
}
2016-04-22 15:49:00 +02:00
} else if (inputStickerSet instanceof TLRPC.TL_inputStickerSetShortName) {
if (!StickersQuery.isStickerPackInstalled(inputStickerSet.short_name)) {
return 7;
}
2016-04-22 15:49:00 +02:00
}
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto || messageObject.getDocument() != null || messageObject.isMusic() || messageObject.isVideo()) {
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;
}
2016-04-22 15:49:00 +02:00
}
if (!canSave) {
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
if (f.exists()) {
canSave = true;
}
}
if (canSave) {
if (messageObject.getDocument() != null) {
String mime = messageObject.getDocument().mime_type;
if (mime != null) {
if (mime.endsWith("/xml")) {
return 5;
} else if (mime.endsWith("/png") || mime.endsWith("/jpg") || mime.endsWith("/jpeg")) {
return 6;
}
}
}
2016-04-22 15:49:00 +02:00
return 4;
}
2016-04-22 15:49:00 +02:00
} else if (messageObject.type == 12) {
return 8;
} else if (messageObject.isMediaEmpty()) {
2013-10-25 17:19:00 +02:00
return 3;
}
2016-04-22 15:49:00 +02:00
return 2;
2013-10-25 17:19:00 +02:00
}
}
} 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) {
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 {
2016-04-22 15:49:00 +02:00
if (messageObject.isVoice()) {
return 2;
} else if (messageObject.isSticker()) {
TLRPC.InputStickerSet inputStickerSet = messageObject.getInputStickerSet();
if (inputStickerSet instanceof TLRPC.TL_inputStickerSetShortName) {
if (!StickersQuery.isStickerPackInstalled(inputStickerSet.short_name)) {
return 7;
2015-05-21 23:27:27 +02:00
}
2016-04-22 15:49:00 +02:00
}
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto || messageObject.getDocument() != null || messageObject.isMusic() || messageObject.isVideo()) {
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;
}
2016-04-22 15:49:00 +02:00
}
if (!canSave) {
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
if (f.exists()) {
canSave = true;
}
2016-04-22 15:49:00 +02:00
}
if (canSave) {
if (messageObject.getDocument() != null) {
String mime = messageObject.getDocument().mime_type;
if (mime != null && mime.endsWith("text/xml")) {
return 5;
2014-10-30 22:27:41 +01:00
}
}
2016-04-22 15:49:00 +02:00
if (messageObject.messageOwner.ttl <= 0) {
return 4;
}
}
2016-04-22 15:49:00 +02:00
} else if (messageObject.type == 12) {
return 8;
} else if (messageObject.isMediaEmpty()) {
2013-10-25 17:19:00 +02:00
return 3;
}
2016-04-22 15:49:00 +02:00
return 2;
2013-10-25 17:19:00 +02:00
}
}
}
private void addToSelectedMessages(MessageObject messageObject) {
2015-11-26 22:04:02 +01:00
int index = messageObject.getDialogId() == dialog_id ? 0 : 1;
if (selectedMessagesIds[index].containsKey(messageObject.getId())) {
selectedMessagesIds[index].remove(messageObject.getId());
2016-03-16 13:26:32 +01:00
if (messageObject.type == 0 || messageObject.caption != null) {
2015-11-26 22:04:02 +01:00
selectedMessagesCanCopyIds[index].remove(messageObject.getId());
2013-10-25 17:19:00 +02:00
}
2015-09-24 22:52:02 +02:00
if (!messageObject.canDeleteMessage(currentChat)) {
cantDeleteMessagesCount--;
}
2013-10-25 17:19:00 +02:00
} else {
2015-11-26 22:04:02 +01:00
selectedMessagesIds[index].put(messageObject.getId(), messageObject);
2016-03-16 13:26:32 +01:00
if (messageObject.type == 0 || messageObject.caption != null) {
2015-11-26 22:04:02 +01:00
selectedMessagesCanCopyIds[index].put(messageObject.getId(), messageObject);
2013-10-25 17:19:00 +02:00
}
2015-09-24 22:52:02 +02:00
if (!messageObject.canDeleteMessage(currentChat)) {
cantDeleteMessagesCount++;
}
}
2014-11-11 23:16:17 +01:00
if (actionBar.isActionModeShowed()) {
2015-11-26 22:04:02 +01:00
if (selectedMessagesIds[0].isEmpty() && selectedMessagesIds[1].isEmpty()) {
2014-11-11 23:16:17 +01:00
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
2015-10-29 18:10:07 +01:00
} else {
2015-11-26 22:04:02 +01:00
int copyVisible = actionBar.createActionMode().getItem(copy).getVisibility();
actionBar.createActionMode().getItem(copy).setVisibility(selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() != 0 ? View.VISIBLE : View.GONE);
int newCopyVisible = actionBar.createActionMode().getItem(copy).getVisibility();
2015-10-29 18:10:07 +01:00
actionBar.createActionMode().getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
2015-11-26 22:04:02 +01:00
final ActionBarMenuItem replyItem = actionBar.createActionMode().getItem(reply);
if (replyItem != null) {
2015-10-29 18:10:07 +01:00
boolean allowChatActions = true;
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 46 || isBroadcast || currentChat != null && (ChatObject.isNotInChat(currentChat) || ChatObject.isChannel(currentChat) && !currentChat.creator && !currentChat.editor && !currentChat.megagroup)) {
2015-10-29 18:10:07 +01:00
allowChatActions = false;
}
2015-11-26 22:04:02 +01:00
final int newVisibility = allowChatActions && selectedMessagesIds[0].size() + selectedMessagesIds[1].size() == 1 ? View.VISIBLE : View.GONE;
if (replyItem.getVisibility() != newVisibility) {
if (replyButtonAnimation != null) {
replyButtonAnimation.cancel();
}
if (copyVisible != newCopyVisible) {
if (newVisibility == View.VISIBLE) {
replyItem.setAlpha(1.0f);
replyItem.setScaleX(1.0f);
2015-11-26 22:04:02 +01:00
} else {
replyItem.setAlpha(0.0f);
replyItem.setScaleX(0.0f);
2015-11-26 22:04:02 +01:00
}
replyItem.setVisibility(newVisibility);
} else {
replyButtonAnimation = new AnimatorSet();
replyItem.setPivotX(AndroidUtilities.dp(54));
2015-11-26 22:04:02 +01:00
if (newVisibility == View.VISIBLE) {
replyItem.setVisibility(newVisibility);
replyButtonAnimation.playTogether(
ObjectAnimator.ofFloat(replyItem, "alpha", 1.0f),
ObjectAnimator.ofFloat(replyItem, "scaleX", 1.0f)
2015-11-26 22:04:02 +01:00
);
} else {
replyButtonAnimation.playTogether(
ObjectAnimator.ofFloat(replyItem, "alpha", 0.0f),
ObjectAnimator.ofFloat(replyItem, "scaleX", 0.0f)
2015-11-26 22:04:02 +01:00
);
}
replyButtonAnimation.setDuration(100);
replyButtonAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2016-04-22 15:49:00 +02:00
if (replyButtonAnimation != null && replyButtonAnimation.equals(animation)) {
2015-11-26 22:04:02 +01:00
if (newVisibility == View.GONE) {
replyItem.setVisibility(View.GONE);
}
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (replyButtonAnimation != null && replyButtonAnimation.equals(animation)) {
replyButtonAnimation = null;
}
}
2015-11-26 22:04:02 +01:00
});
replyButtonAnimation.start();
}
}
2015-09-24 22:52:02 +02:00
}
}
2013-10-25 17:19:00 +02:00
}
}
private void processRowSelect(View view) {
MessageObject message = null;
2016-05-25 23:49:47 +02:00
if (view instanceof ChatMessageCell) {
message = ((ChatMessageCell) 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();
}
2013-10-25 17:19:00 +02:00
2014-07-15 21:57:09 +02:00
int type = getMessageType(message);
2015-09-24 22:52:02 +02:00
if (type < 2 || type == 20) {
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;
}
2015-11-26 22:04:02 +01:00
if (!selectedMessagesIds[0].isEmpty() || !selectedMessagesIds[1].isEmpty()) {
selectedMessagesCountTextView.setNumber(selectedMessagesIds[0].size() + selectedMessagesIds[1].size(), true);
2013-10-25 17:19:00 +02:00
}
}
2014-11-11 23:16:17 +01:00
private void updateTitle() {
2016-04-22 15:49:00 +02:00
if (avatarContainer == null) {
2014-11-17 03:44:57 +01:00
return;
}
2013-10-25 17:19:00 +02:00
if (currentChat != null) {
2016-04-22 15:49:00 +02:00
avatarContainer.setTitle(currentChat.title);
2013-10-25 17:19:00 +02:00
} else if (currentUser != null) {
2016-10-11 13:57:01 +02:00
if (currentUser.self) {
avatarContainer.setTitle(LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName));
} else 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) {
2016-04-22 15:49:00 +02:00
avatarContainer.setTitle(PhoneFormat.getInstance().format("+" + currentUser.phone));
2013-10-25 17:19:00 +02:00
} else {
2016-04-22 15:49:00 +02:00
avatarContainer.setTitle(UserObject.getUserName(currentUser));
2013-10-25 17:19:00 +02:00
}
} else {
2016-04-22 15:49:00 +02:00
avatarContainer.setTitle(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() {
2015-11-26 22:04:02 +01:00
if (headerItem == null || currentUser == null || currentEncryptedChat != null || !currentUser.bot) {
2015-06-29 19:12:11 +02:00
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() {
2016-04-22 15:49:00 +02:00
if (avatarContainer == null) {
2015-09-24 22:52:02 +02:00
return;
}
2015-02-01 19:51:02 +01:00
int rightIcon = MessagesController.getInstance().isDialogMuted(dialog_id) ? R.drawable.mute_fixed : 0;
2016-04-22 15:49:00 +02:00
avatarContainer.setTitleIcons(currentEncryptedChat != null ? R.drawable.ic_lock_header : 0, rightIcon);
2016-10-11 13:57:01 +02:00
if (muteItem != null) {
if (rightIcon != 0) {
muteItem.setText(LocaleController.getString("UnmuteNotifications", R.string.UnmuteNotifications));
} else {
muteItem.setText(LocaleController.getString("MuteNotifications", R.string.MuteNotifications));
}
2015-02-01 19:51:02 +01:00
}
2014-11-11 23:16:17 +01:00
}
2013-10-25 17:19:00 +02:00
private void checkAndUpdateAvatar() {
if (currentUser != null) {
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
} else if (currentChat != null) {
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
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null) {
avatarContainer.checkAndUpdateAvatar();
2013-10-25 17:19:00 +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
2016-10-11 13:57:01 +02:00
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, String caption) {
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;
2016-10-11 13:57:01 +02:00
SendMessagesHelper.prepareSendingVideo(videoPath, estimatedSize, estimatedDuration, resultWidth, resultHeight, videoEditedInfo, dialog_id, replyingMessageObject, caption);
2015-04-09 20:00:14 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2014-10-15 20:43:52 +02:00
}
});
2014-10-22 22:01:07 +02:00
if (parentLayout == null || !fragment.onFragmentCreate()) {
2016-10-11 13:57:01 +02:00
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject, null);
2015-04-09 20:00:14 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2014-10-15 20:43:52 +02:00
return false;
}
2016-10-11 13:57:01 +02:00
if (parentLayout.presentFragment(fragment, removeLast, !animated, true)) {
fragment.setParentChatActivity(this);
}
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
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) {
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) {
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);
}
arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false));
PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() {
@Override
public void sendButtonPressed(int index) {
2016-10-11 13:57:01 +02:00
sendMedia((MediaController.PhotoEntry) arrayList.get(0), false);
}
}, 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) {
showAttachmentError();
return;
}
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);
} 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 {
2016-10-11 13:57:01 +02:00
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject, null);
}
} else {
2016-10-11 13:57:01 +02:00
SendMessagesHelper.prepareSendingPhoto(null, uri, dialog_id, replyingMessageObject, null, null);
}
2015-04-09 20:00:14 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2013-10-25 17:19:00 +02:00
} else if (requestCode == 2) {
String videoPath = null;
2016-03-16 13:26:32 +01:00
FileLog.d("tmessages", "pic path " + currentPicturePath);
if (data != null && currentPicturePath != null) {
if (new File(currentPicturePath).exists()) {
data = null;
}
}
2013-10-25 17:19:00 +02:00
if (data != null) {
Uri uri = data.getData();
if (uri != null) {
2016-03-16 13:26:32 +01:00
FileLog.d("tmessages", "video record uri " + uri.toString());
videoPath = AndroidUtilities.getPath(uri);
FileLog.d("tmessages", "resolved path = " + videoPath);
if (!(new File(videoPath).exists())) {
videoPath = currentPicturePath;
}
2013-10-25 17:19:00 +02:00
} else {
videoPath = currentPicturePath;
2013-10-25 17:19:00 +02:00
}
2015-05-21 23:27:27 +02:00
AndroidUtilities.addMediaToGallery(currentPicturePath);
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 {
openVideoEditor(videoPath, false, false);
2014-10-01 00:36:18 +02:00
}
} else {
2016-10-11 13:57:01 +02:00
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject, null);
2015-04-09 20:00:14 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
}
} 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);
String originalPath = tempPath;
if (tempPath == null) {
originalPath = data.toString();
2016-03-16 13:26:32 +01:00
tempPath = MediaController.copyFileToCache(data.getData(), "file");
}
if (tempPath == null) {
showAttachmentError();
return;
}
SendMessagesHelper.prepareSendingDocument(tempPath, originalPath, null, null, dialog_id, replyingMessageObject);
2015-04-09 20:00:14 +02:00
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, 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, null, null);
2015-06-29 19:12:11 +02:00
}
if (sent) {
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
2015-06-29 19:12:11 +02:00
}
}
} finally {
try {
if (c != null && !c.isClosed()) {
c.close();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
2013-10-25 17:19:00 +02:00
}
}
}
@Override
public void saveSelfArgs(Bundle args) {
if (currentPicturePath != null) {
args.putString("path", currentPicturePath);
}
}
@Override
public void restoreSelfArgs(Bundle args) {
currentPicturePath = args.getString("path");
}
private void removeUnreadPlane() {
2014-10-15 20:43:52 +02:00
if (unreadMessageObject != null) {
2015-11-26 22:04:02 +01:00
forwardEndReached[0] = forwardEndReached[1] = 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;
2016-05-25 23:49:47 +02:00
removeMessageObject(unreadMessageObject);
unreadMessageObject = null;
2014-10-15 20:43:52 +02:00
}
}
2013-10-25 17:19:00 +02:00
public boolean processSendingText(String text) {
return chatActivityEnterView.processSendingText(text);
2013-10-25 17:19:00 +02:00
}
@Override
public void didReceivedNotification(int id, final Object... args) {
if (id == NotificationCenter.messagesDidLoaded) {
int guid = (Integer) args[10];
2015-11-26 22:04:02 +01:00
if (guid == classGuid) {
2016-04-22 15:49:00 +02:00
if (!openAnimationEnded) {
NotificationCenter.getInstance().setAllowedNotificationsDutingAnimation(new int[]{NotificationCenter.chatInfoDidLoaded, NotificationCenter.dialogsNeedReload,
NotificationCenter.closeChats, NotificationCenter.botKeyboardDidLoaded/*, NotificationCenter.botInfoDidLoaded*/});
}
int queryLoadIndex = (Integer) args[11];
2015-11-26 22:04:02 +01:00
int index = waitingForLoad.indexOf(queryLoadIndex);
if (index == -1) {
return;
} else {
waitingForLoad.remove(index);
}
2016-03-16 13:26:32 +01:00
ArrayList<MessageObject> messArr = (ArrayList<MessageObject>) args[2];
if (waitingForReplyMessageLoad) {
boolean found = false;
for (int a = 0; a < messArr.size(); a++) {
if (messArr.get(a).getId() == startLoadFromMessageId) {
found = true;
break;
2016-03-16 13:26:32 +01:00
}
}
if (!found) {
startLoadFromMessageId = 0;
return;
}
2015-09-24 22:52:02 +02:00
int startLoadFrom = startLoadFromMessageId;
2016-03-16 13:26:32 +01:00
boolean needSelect = needSelectFromMessageId;
2015-09-24 22:52:02 +02:00
clearChatData();
startLoadFromMessageId = startLoadFrom;
2016-03-16 13:26:32 +01:00
needSelectFromMessageId = needSelect;
2015-09-24 22:52:02 +02:00
}
loadsCount++;
2015-11-26 22:04:02 +01:00
long did = (Long) args[0];
int loadIndex = did == dialog_id ? 0 : 1;
2015-04-09 20:00:14 +02:00
int count = (Integer) args[1];
boolean isCache = (Boolean) args[3];
int fnid = (Integer) args[4];
2015-09-24 22:52:02 +02:00
int last_unread_date = (Integer) args[7];
int load_type = (Integer) args[8];
2013-10-25 17:19:00 +02:00
boolean wasUnread = false;
2013-12-20 20:25:49 +01:00
if (fnid != 0) {
2014-08-02 01:31:15 +02:00
first_unread_id = fnid;
2015-04-09 20:00:14 +02:00
last_message_id = (Integer) args[5];
2015-09-24 22:52:02 +02:00
unread_to_load = (Integer) args[6];
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];
2013-12-20 20:25:49 +01:00
}
2013-10-25 17:19:00 +02:00
int newRowsCount = 0;
2014-10-31 20:02:29 +01:00
2015-11-26 22:04:02 +01:00
forwardEndReached[loadIndex] = startLoadFromMessageId == 0 && last_message_id == 0;
if ((load_type == 1 || load_type == 3) && loadIndex == 1) {
endReached[0] = cacheEndReached[0] = true;
forwardEndReached[0] = false;
minMessageId[0] = 0;
}
2014-08-02 01:31:15 +02:00
if (loadsCount == 1 && messArr.size() > 20) {
loadsCount++;
}
2014-08-02 01:31:15 +02:00
if (firstLoading) {
2015-11-26 22:04:02 +01:00
if (!forwardEndReached[loadIndex]) {
2014-08-02 01:31:15 +02:00
messages.clear();
messagesByDays.clear();
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
messagesDict[a].clear();
if (currentEncryptedChat == null) {
maxMessageId[a] = Integer.MAX_VALUE;
minMessageId[a] = Integer.MIN_VALUE;
} else {
maxMessageId[a] = Integer.MIN_VALUE;
minMessageId[a] = Integer.MAX_VALUE;
}
maxDate[a] = Integer.MIN_VALUE;
minDate[a] = 0;
2014-08-02 01:31:15 +02:00
}
}
firstLoading = false;
2016-05-25 23:49:47 +02:00
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (parentLayout != null) {
parentLayout.resumeDelayedFragmentAnimation();
}
}
});
2014-08-02 01:31:15 +02:00
}
2014-11-19 02:23:46 +01:00
if (load_type == 1) {
Collections.reverse(messArr);
}
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat == null) {
2016-03-16 13:26:32 +01:00
MessagesQuery.loadReplyMessagesForMessages(messArr, dialog_id);
2016-03-06 02:49:31 +01:00
}
2016-04-22 15:49:00 +02:00
int approximateHeightSum = 0;
2013-12-20 20:25:49 +01:00
for (int a = 0; a < messArr.size(); a++) {
MessageObject obj = messArr.get(a);
2016-04-22 15:49:00 +02:00
approximateHeightSum += obj.getApproximateHeight();
2016-10-11 13:57:01 +02:00
if (currentUser != null) {
if (currentUser.self) {
obj.messageOwner.out = true;
}
if (currentUser.bot && obj.isOut()) {
obj.setIsRead();
}
2016-03-06 02:49:31 +01:00
}
2015-11-26 22:04:02 +01:00
if (messagesDict[loadIndex].containsKey(obj.getId())) {
2013-12-20 20:25:49 +01:00
continue;
}
2015-11-26 22:04:02 +01:00
if (loadIndex == 1) {
obj.setIsRead();
}
if (loadIndex == 0 && ChatObject.isChannel(currentChat) && obj.getId() == 1) {
2015-11-26 22:04:02 +01:00
endReached[loadIndex] = true;
cacheEndReached[loadIndex] = true;
}
if (obj.getId() > 0) {
2015-11-26 22:04:02 +01:00
maxMessageId[loadIndex] = Math.min(obj.getId(), maxMessageId[loadIndex]);
minMessageId[loadIndex] = Math.max(obj.getId(), minMessageId[loadIndex]);
2013-12-20 20:25:49 +01:00
} else if (currentEncryptedChat != null) {
2015-11-26 22:04:02 +01:00
maxMessageId[loadIndex] = Math.max(obj.getId(), maxMessageId[loadIndex]);
minMessageId[loadIndex] = Math.min(obj.getId(), minMessageId[loadIndex]);
2013-10-25 17:19:00 +02:00
}
2014-10-28 18:07:44 +01:00
if (obj.messageOwner.date != 0) {
2015-11-26 22:04:02 +01:00
maxDate[loadIndex] = Math.max(maxDate[loadIndex], obj.messageOwner.date);
if (minDate[loadIndex] == 0 || obj.messageOwner.date < minDate[loadIndex]) {
minDate[loadIndex] = obj.messageOwner.date;
2014-10-28 18:07:44 +01:00
}
2013-10-25 17:19:00 +02:00
}
2014-10-22 22:01:07 +02:00
2015-11-26 22:04:02 +01:00
if (obj.type < 0 || loadIndex == 1 && obj.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
2014-10-22 22:01:07 +02:00
continue;
}
if (!obj.isOut() && obj.isUnread()) {
2013-10-25 17:19:00 +02:00
wasUnread = true;
}
2015-11-26 22:04:02 +01:00
messagesDict[loadIndex].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;
dateMsg.date = obj.messageOwner.date;
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;
2016-04-22 15:49:00 +02:00
dateObj.contentType = 1;
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++;
2014-10-31 20:02:29 +01:00
if (load_type == 1) {
2015-09-24 22:52:02 +02:00
dayArray.add(obj);
2013-12-20 20:25:49 +01:00
messages.add(0, obj);
2015-09-24 22:52:02 +02:00
}
if (load_type != 1) {
dayArray.add(obj);
2013-12-20 20:25:49 +01:00
messages.add(messages.size() - 1, obj);
}
2016-04-22 15:49:00 +02:00
if (obj.getId() == last_message_id) {
forwardEndReached[loadIndex] = true;
}
if (load_type == 2 && obj.getId() == first_unread_id) {
2016-04-22 15:49:00 +02:00
if (approximateHeightSum > AndroidUtilities.displaySize.y / 2 || !forwardEndReached[0]) {
TLRPC.Message dateMsg = new TLRPC.Message();
dateMsg.message = "";
dateMsg.id = 0;
MessageObject dateObj = new MessageObject(dateMsg, null, false);
dateObj.type = 6;
dateObj.contentType = 2;
messages.add(messages.size() - 1, dateObj);
unreadMessageObject = dateObj;
scrollToMessage = unreadMessageObject;
scrollToMessagePosition = -10000;
newRowsCount++;
}
} 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
startLoadFromMessageId = 0;
2015-09-24 22:52:02 +02:00
if (scrollToMessagePosition == -10000) {
scrollToMessagePosition = -9000;
}
2013-10-25 17:19:00 +02:00
}
}
2016-05-25 23:49:47 +02:00
if (load_type == 0 && newRowsCount == 0) {
loadsCount--;
}
2013-10-25 17:19:00 +02:00
2015-11-26 22:04:02 +01:00
if (forwardEndReached[loadIndex] && loadIndex != 1) {
2013-12-20 20:25:49 +01:00
first_unread_id = 0;
2014-10-31 20:02:29 +01:00
last_message_id = 0;
2013-12-20 20:25:49 +01:00
}
2013-10-25 17:19:00 +02:00
2015-09-24 22:52:02 +02:00
if (loadsCount <= 2) {
2016-03-16 13:26:32 +01:00
if (!isCache) {
2015-09-24 22:52:02 +02:00
updateSpamView();
}
}
2014-10-31 20:02:29 +01:00
if (load_type == 1) {
2015-09-24 22:52:02 +02:00
if (messArr.size() != count && !isCache) {
2015-11-26 22:04:02 +01:00
forwardEndReached[loadIndex] = true;
if (loadIndex != 1) {
first_unread_id = 0;
last_message_id = 0;
chatAdapter.notifyItemRemoved(chatAdapter.getItemCount() - 1);
newRowsCount--;
}
2014-11-19 02:23:46 +01:00
startLoadFromMessageId = 0;
}
2016-03-16 13:26:32 +01:00
if (newRowsCount > 0) {
2015-10-29 18:10:07 +01:00
int firstVisPos = chatLayoutManager.findLastVisibleItemPosition();
int top = 0;
if (firstVisPos != chatLayoutManager.getItemCount() - 1) {
firstVisPos = RecyclerView.NO_POSITION;
} else {
2016-03-16 13:26:32 +01:00
View firstVisView = chatLayoutManager.findViewByPosition(firstVisPos);
2015-10-29 18:10:07 +01:00
top = ((firstVisView == null) ? 0 : firstVisView.getTop()) - chatListView.getPaddingTop();
}
2015-06-29 19:12:11 +02:00
chatAdapter.notifyItemRangeInserted(chatAdapter.getItemCount() - 1, newRowsCount);
2015-10-29 18:10:07 +01:00
if (firstVisPos != RecyclerView.NO_POSITION) {
chatLayoutManager.scrollToPositionWithOffset(firstVisPos, top);
}
2013-10-25 17:19:00 +02:00
}
2013-12-20 20:25:49 +01:00
loadingForward = false;
} else {
2015-10-29 18:10:07 +01:00
if (messArr.size() < count && load_type != 3) {
2013-12-20 20:25:49 +01:00
if (isCache) {
2014-10-20 13:30:05 +02:00
if (currentEncryptedChat != null || isBroadcast) {
2015-11-26 22:04:02 +01:00
endReached[loadIndex] = true;
2013-12-20 20:25:49 +01:00
}
2016-05-25 23:49:47 +02:00
if (load_type != 2) {
cacheEndReached[loadIndex] = true;
}
} else if (load_type != 2) {
2016-10-11 13:57:01 +02:00
endReached[loadIndex] = true;// =TODO if < 7 from unread
2013-12-20 20:25:49 +01:00
}
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) {
2016-05-25 23:49:47 +02:00
if (first || scrollToTopOnResume || forceScrollToTop) {
forceScrollToTop = false;
2013-12-20 20:25:49 +01:00
chatAdapter.notifyDataSetChanged();
2014-10-31 20:02:29 +01:00
if (scrollToMessage != null) {
2015-09-24 22:52:02 +02:00
int yOffset;
if (scrollToMessagePosition == -9000) {
yOffset = Math.max(0, (chatListView.getHeight() - scrollToMessage.getApproximateHeight()) / 2);
} else if (scrollToMessagePosition == -10000) {
yOffset = 0;
} else {
yOffset = scrollToMessagePosition;
}
if (!messages.isEmpty()) {
2015-09-24 22:52:02 +02:00
if (messages.get(messages.size() - 1) == scrollToMessage || messages.get(messages.size() - 2) == scrollToMessage) {
chatLayoutManager.scrollToPositionWithOffset((chatAdapter.isBot ? 1 : 0), -chatListView.getPaddingTop() - AndroidUtilities.dp(7) + yOffset);
} else {
2015-11-26 22:04:02 +01:00
chatLayoutManager.scrollToPositionWithOffset(chatAdapter.messagesStartRow + messages.size() - messages.indexOf(scrollToMessage) - 1, -chatListView.getPaddingTop() - AndroidUtilities.dp(7) + yOffset);
}
}
2013-12-20 20:25:49 +01:00
chatListView.invalidate();
2015-09-24 22:52:02 +02:00
if (scrollToMessagePosition == -10000 || scrollToMessagePosition == -9000) {
showPagedownButton(true, true);
}
scrollToMessagePosition = -10000;
2015-11-26 22:04:02 +01:00
scrollToMessage = null;
2013-10-25 17:19:00 +02:00
} else {
moveScrollToLastMessage();
2013-12-20 20:25:49 +01:00
}
} else {
if (newRowsCount != 0) {
2015-11-26 22:04:02 +01:00
boolean end = false;
if (endReached[loadIndex] && (loadIndex == 0 && mergeDialogId == 0 || loadIndex == 1)) {
end = true;
2015-09-24 22:52:02 +02:00
chatAdapter.notifyItemRangeChanged(chatAdapter.isBot ? 1 : 0, 2);
}
int firstVisPos = chatLayoutManager.findLastVisibleItemPosition();
2016-03-16 13:26:32 +01:00
View firstVisView = chatLayoutManager.findViewByPosition(firstVisPos);
int top = ((firstVisView == null) ? 0 : firstVisView.getTop()) - chatListView.getPaddingTop();
2015-11-26 22:04:02 +01:00
if (newRowsCount - (end ? 1 : 0) > 0) {
chatAdapter.notifyItemRangeInserted((chatAdapter.isBot ? 2 : 1) + (end ? 0 : 1), newRowsCount - (end ? 1 : 0));
2015-09-24 22:52:02 +02:00
}
2015-11-26 22:04:02 +01:00
if (firstVisPos != -1) {
chatLayoutManager.scrollToPositionWithOffset(firstVisPos + newRowsCount - (end ? 1 : 0), top);
}
} else if (endReached[loadIndex] && (loadIndex == 0 && mergeDialogId == 0 || loadIndex == 1)) {
2015-09-24 22:52:02 +02:00
chatAdapter.notifyItemRemoved(chatAdapter.isBot ? 1 : 0);
}
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-11-26 22:04:02 +01:00
if (chatListView != null) {
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) {
2015-11-26 22:04:02 +01:00
if (loadIndex == 0) {
final boolean wasUnreadFinal = wasUnread;
final int last_unread_date_final = last_unread_date;
final int lastid = messages.get(0).getId();
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (last_message_id != 0) {
MessagesController.getInstance().markDialogAsRead(dialog_id, lastid, last_message_id, last_unread_date_final, wasUnreadFinal, false);
} else {
MessagesController.getInstance().markDialogAsRead(dialog_id, lastid, minMessageId[0], maxDate[0], wasUnreadFinal, false);
}
2014-11-11 23:16:17 +01:00
}
2015-11-26 22:04:02 +01:00
}, 700);
}
2013-10-25 17:19:00 +02:00
first = false;
}
2015-11-26 22:04:02 +01:00
if (messages.isEmpty() && currentEncryptedChat == null && currentUser != null && currentUser.bot && botUser == null) {
2015-06-29 19:12:11 +02:00
botUser = "";
updateBottomOverlay();
}
2013-10-25 17:19:00 +02:00
2015-11-26 22:04:02 +01:00
if (newRowsCount == 0 && currentEncryptedChat != null && !endReached[0]) {
2015-10-29 18:10:07 +01:00
first = true;
2015-11-26 22:04:02 +01:00
if (chatListView != null) {
chatListView.setEmptyView(null);
2015-10-29 18:10:07 +01:00
}
2015-12-09 19:27:52 +01:00
if (emptyViewContainer != null) {
emptyViewContainer.setVisibility(View.INVISIBLE);
}
2015-10-29 18:10:07 +01:00
} else {
if (progressView != null) {
progressView.setVisibility(View.INVISIBLE);
}
2013-10-25 17:19:00 +02:00
}
2016-04-22 15:49:00 +02:00
checkScrollForLoad(false);
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.emojiDidLoaded) {
if (chatListView != null) {
chatListView.invalidateViews();
2013-10-25 17:19:00 +02:00
}
if (replyObjectTextView != null) {
replyObjectTextView.invalidate();
}
2016-04-22 15:49:00 +02:00
if (alertTextView != null) {
alertTextView.invalidate();
}
if (pinnedMessageTextView != null) {
pinnedMessageTextView.invalidate();
}
if (mentionListView != null) {
mentionListView.invalidateViews();
}
} 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) {
2016-05-25 23:49:47 +02:00
if (currentChat != null) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(currentChat.id);
if (chat != null) {
currentChat = chat;
}
} else if (currentUser != null) {
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
if (user != null) {
currentUser = user;
}
}
2014-11-11 23:16:17 +01:00
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) {
2016-04-22 15:49:00 +02:00
if (currentChat != null && avatarContainer != null) {
avatarContainer.updateOnlineCount();
2014-11-12 23:16:59 +01:00
}
2016-04-22 15:49:00 +02:00
updateSubtitle = true;
2014-11-11 23:16:17 +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();
updateVisibleRows();
2013-10-25 17:19:00 +02:00
}
if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
2016-04-22 15:49:00 +02:00
updateSubtitle = true;
}
2015-09-24 22:52:02 +02:00
if ((updateMask & MessagesController.UPDATE_MASK_CHANNEL) != 0 && ChatObject.isChannel(currentChat)) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(currentChat.id);
if (chat == null) {
return;
}
currentChat = chat;
updateSubtitle = true;
updateBottomOverlay();
if (chatActivityEnterView != null) {
chatActivityEnterView.setDialogId(dialog_id);
}
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null && updateSubtitle) {
avatarContainer.updateSubtitle();
2014-11-12 23:16:59 +01:00
}
if ((updateMask & MessagesController.UPDATE_MASK_USER_PHONE) != 0) {
updateContactStatus();
}
} 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];
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));
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
}
}
2016-04-22 15:49:00 +02:00
if (currentChat != null || inlineReturn != 0) {
2016-03-16 13:26:32 +01:00
for (int a = 0; a < arr.size(); a++) {
MessageObject messageObject = arr.get(a);
2016-04-22 15:49:00 +02:00
if (currentChat != null) {
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser && messageObject.messageOwner.action.user_id == UserConfig.getClientUserId() ||
messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser && messageObject.messageOwner.action.users.contains(UserConfig.getClientUserId())) {
TLRPC.Chat newChat = MessagesController.getInstance().getChat(currentChat.id);
if (newChat != null) {
currentChat = newChat;
checkActionBarMenu();
updateBottomOverlay();
if (avatarContainer != null) {
avatarContainer.updateSubtitle();
}
}
} else if (messageObject.messageOwner.reply_to_msg_id != 0 && messageObject.replyMessageObject == null) {
messageObject.replyMessageObject = messagesDict[0].get(messageObject.messageOwner.reply_to_msg_id);
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
messageObject.generatePinMessageText(null, null);
2016-10-11 13:57:01 +02:00
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
messageObject.generateGameMessageText(null);
2016-04-22 15:49:00 +02:00
}
2016-03-16 13:26:32 +01:00
}
2016-04-22 15:49:00 +02:00
} else if (inlineReturn != 0) {
if (messageObject.messageOwner.reply_markup != null) {
for (int b = 0; b < messageObject.messageOwner.reply_markup.rows.size(); b++) {
TLRPC.TL_keyboardButtonRow row = messageObject.messageOwner.reply_markup.rows.get(b);
for (int c = 0; c < row.buttons.size(); c++) {
TLRPC.KeyboardButton button = row.buttons.get(c);
if (button instanceof TLRPC.TL_keyboardButtonSwitchInline) {
processSwitchButton((TLRPC.TL_keyboardButtonSwitchInline) button);
break;
}
}
}
2016-03-16 13:26:32 +01:00
}
}
}
}
2014-10-21 22:35:16 +02:00
2015-11-26 22:04:02 +01:00
boolean reloadMegagroup = false;
if (!forwardEndReached[0]) {
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
2015-11-26 22:04:02 +01:00
for (int a = 0; a < arr.size(); a++) {
MessageObject obj = arr.get(a);
2016-03-06 02:49:31 +01:00
if (currentUser != null && currentUser.bot && obj.isOut()) {
obj.setIsRead();
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null && currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction && obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
avatarContainer.setTime(((TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction).ttl_seconds);
2014-03-10 10:27:49 +01:00
}
2015-11-26 22:04:02 +01:00
if (obj.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
final Bundle bundle = new Bundle();
bundle.putInt("chat_id", obj.messageOwner.action.channel_id);
final BaseFragment lastFragment = parentLayout.fragmentsStack.size() > 0 ? parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 1) : null;
final int channel_id = obj.messageOwner.action.channel_id;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
ActionBarLayout parentLayout = ChatActivity.this.parentLayout;
if (lastFragment != null) {
NotificationCenter.getInstance().removeObserver(lastFragment, NotificationCenter.closeChats);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
parentLayout.presentFragment(new ChatActivity(bundle), true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().loadFullChat(channel_id, 0, true);
}
}, 1000);
}
});
return;
} else if (currentChat != null && currentChat.megagroup && (obj.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser || obj.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser)) {
reloadMegagroup = true;
}
2014-09-28 15:37:26 +02:00
if (obj.isOut() && obj.isSending()) {
2015-10-29 18:10:07 +01:00
scrollToLastMessage(false);
return;
}
if (obj.type < 0 || messagesDict[0].containsKey(obj.getId())) {
2013-12-20 20:25:49 +01:00
continue;
}
2016-03-06 02:49:31 +01:00
obj.checkLayout();
2013-12-20 20:25:49 +01:00
currentMaxDate = Math.max(currentMaxDate, obj.messageOwner.date);
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) {
currentMinMsgId = Math.min(obj.getId(), currentMinMsgId);
last_message_id = Math.min(last_message_id, obj.getId());
2013-12-20 20:25:49 +01: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 {
if (messages.size() > 0) {
2015-11-26 22:04:02 +01:00
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).getId(), currentMinMsgId, currentMaxDate, true, false);
}
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;
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;
2016-03-06 02:49:31 +01:00
HashMap<String, ArrayList<MessageObject>> webpagesToReload = null;
int placeToPaste = -1;
2015-11-26 22:04:02 +01:00
for (int a = 0; a < arr.size(); a++) {
MessageObject obj = arr.get(a);
if (a == 0) {
if (obj.messageOwner.id < 0) {
placeToPaste = 0;
} else {
if (!messages.isEmpty()) {
int size = messages.size();
for (int b = 0; b < size; b++) {
MessageObject lastMessage = messages.get(b);
if (lastMessage.type >= 0 && lastMessage.messageOwner.date > 0) {
if (lastMessage.messageOwner.id > 0 && obj.messageOwner.id > 0) {
if (lastMessage.messageOwner.id < obj.messageOwner.id) {
placeToPaste = b;
break;
}
} else {
if (lastMessage.messageOwner.date < obj.messageOwner.date) {
placeToPaste = b;
break;
}
}
}
}
if (placeToPaste == -1 || placeToPaste > messages.size()) {
placeToPaste = messages.size();
}
} else {
placeToPaste = 0;
}
}
}
2016-03-06 02:49:31 +01:00
if (currentUser != null && currentUser.bot && obj.isOut()) {
obj.setIsRead();
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null && currentEncryptedChat != null && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction && obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
avatarContainer.setTime(((TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction).ttl_seconds);
2014-03-10 10:27:49 +01:00
}
if (obj.type < 0 || messagesDict[0].containsKey(obj.getId())) {
2013-12-20 20:25:49 +01:00
continue;
}
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat != null && obj.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && obj.messageOwner.media.webpage instanceof TLRPC.TL_webPageUrlPending) {
if (webpagesToReload == null) {
webpagesToReload = new HashMap<>();
}
ArrayList<MessageObject> arrayList = webpagesToReload.get(obj.messageOwner.media.webpage.url);
if (arrayList == null) {
arrayList = new ArrayList<>();
webpagesToReload.put(obj.messageOwner.media.webpage.url, arrayList);
}
arrayList.add(obj);
}
obj.checkLayout();
2015-11-26 22:04:02 +01:00
if (obj.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
final Bundle bundle = new Bundle();
bundle.putInt("chat_id", obj.messageOwner.action.channel_id);
final BaseFragment lastFragment = parentLayout.fragmentsStack.size() > 0 ? parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 1) : null;
final int channel_id = obj.messageOwner.action.channel_id;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
ActionBarLayout parentLayout = ChatActivity.this.parentLayout;
if (lastFragment != null) {
NotificationCenter.getInstance().removeObserver(lastFragment, NotificationCenter.closeChats);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
parentLayout.presentFragment(new ChatActivity(bundle), true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().loadFullChat(channel_id, 0, true);
}
}, 1000);
}
});
return;
} else if (currentChat != null && currentChat.megagroup && (obj.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser || obj.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser)) {
reloadMegagroup = true;
}
if (minDate[0] == 0 || obj.messageOwner.date < minDate[0]) {
minDate[0] = obj.messageOwner.date;
2013-12-20 20:25:49 +01:00
}
if (obj.isOut()) {
removeUnreadPlane();
2014-10-16 22:02:44 +02:00
hasFromMe = true;
2013-12-20 20:25:49 +01:00
}
if (obj.getId() > 0) {
2015-11-26 22:04:02 +01:00
maxMessageId[0] = Math.min(obj.getId(), maxMessageId[0]);
minMessageId[0] = Math.max(obj.getId(), minMessageId[0]);
2013-12-20 20:25:49 +01:00
} else if (currentEncryptedChat != null) {
2015-11-26 22:04:02 +01:00
maxMessageId[0] = Math.max(obj.getId(), maxMessageId[0]);
minMessageId[0] = Math.min(obj.getId(), minMessageId[0]);
2013-12-20 20:25:49 +01:00
}
2015-11-26 22:04:02 +01:00
maxDate[0] = Math.max(maxDate[0], obj.messageOwner.date);
messagesDict[0].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;
dateMsg.date = obj.messageOwner.date;
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;
2016-04-22 15:49:00 +02:00
dateObj.contentType = 1;
messages.add(placeToPaste, dateObj);
2015-06-29 19:12:11 +02:00
addedCount++;
2013-12-20 20:25:49 +01:00
}
if (!obj.isOut()) {
if (paused && placeToPaste == 0) {
if (!scrollToTopUnReadOnResume && unreadMessageObject != null) {
2016-05-25 23:49:47 +02:00
removeMessageObject(unreadMessageObject);
2016-10-11 13:57:01 +02:00
if (placeToPaste > 0) {
placeToPaste--;
}
unreadMessageObject = null;
}
if (unreadMessageObject == null) {
TLRPC.Message dateMsg = new TLRPC.Message();
dateMsg.message = "";
dateMsg.id = 0;
MessageObject dateObj = new MessageObject(dateMsg, null, false);
2016-04-22 15:49:00 +02:00
dateObj.type = 6;
dateObj.contentType = 2;
messages.add(0, dateObj);
unreadMessageObject = dateObj;
scrollToMessage = unreadMessageObject;
2015-09-24 22:52:02 +02:00
scrollToMessagePosition = -10000;
unreadUpdated = false;
unread_to_load = 0;
scrollToTopUnReadOnResume = true;
2015-06-29 19:12:11 +02:00
addedCount++;
}
}
if (unreadMessageObject != null) {
unread_to_load++;
unreadUpdated = true;
}
if (obj.isUnread()) {
if (!paused) {
obj.setIsRead();
}
markAsRead = true;
}
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);
2016-10-11 13:57:01 +02:00
if (placeToPaste > messages.size()) {
placeToPaste = messages.size();
}
messages.add(placeToPaste, obj);
2015-06-29 19:12:11 +02:00
addedCount++;
newUnreadMessageCount++;
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
}
2016-03-06 02:49:31 +01:00
if (webpagesToReload != null) {
MessagesController.getInstance().reloadWebPages(dialog_id, webpagesToReload);
}
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) {
if (unreadUpdated) {
chatAdapter.updateRowWithMessageObject(unreadMessageObject);
}
2015-06-29 19:12:11 +02:00
if (addedCount != 0) {
chatAdapter.notifyItemRangeInserted(chatAdapter.getItemCount() - placeToPaste, addedCount);
}
2013-10-25 17:19:00 +02:00
} else {
2013-12-20 20:25:49 +01:00
scrollToTopOnResume = true;
2013-10-25 17:19:00 +02:00
}
2013-12-20 20:25:49 +01:00
if (chatListView != null && chatAdapter != null) {
int lastVisible = chatLayoutManager.findLastVisibleItemPosition();
2015-06-29 19:12:11 +02:00
if (lastVisible == RecyclerView.NO_POSITION) {
lastVisible = 0;
}
2015-11-26 22:04:02 +01:00
if (endReached[0]) {
2013-12-20 20:25:49 +01:00
lastVisible++;
}
2015-06-29 19:12:11 +02:00
if (chatAdapter.isBot) {
oldCount++;
}
2015-11-26 22:04:02 +01:00
if (lastVisible >= oldCount || hasFromMe) {
newUnreadMessageCount = 0;
2014-08-02 01:31:15 +02:00
if (!firstLoading) {
if (paused) {
scrollToTopOnResume = true;
} else {
2016-05-25 23:49:47 +02:00
forceScrollToTop = true;
moveScrollToLastMessage();
2014-08-02 01:31:15 +02:00
}
2013-12-20 20:25:49 +01:00
}
} else {
if (newUnreadMessageCount != 0 && pagedownButtonCounter != null) {
pagedownButtonCounter.setVisibility(View.VISIBLE);
pagedownButtonCounter.setText(String.format("%d", newUnreadMessageCount));
}
2013-12-20 20:25:49 +01:00
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;
2015-11-26 22:04:02 +01:00
readWithDate = maxDate[0];
readWithMid = minMessageId[0];
2013-12-20 20:25:49 +01:00
} else {
2015-11-26 22:04:02 +01:00
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).getId(), minMessageId[0], maxDate[0], 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
}
2015-11-26 22:04:02 +01:00
if (reloadMegagroup) {
MessagesController.getInstance().loadFullChat(currentChat.id, 0, true);
}
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.closeChats) {
if (args != null && args.length > 0) {
2015-04-09 20:00:14 +02:00
long did = (Long) args[0];
if (did == dialog_id) {
finishFragment();
}
} else {
removeSelfFromStack();
}
} else if (id == NotificationCenter.messagesRead) {
2015-09-24 22:52:02 +02:00
SparseArray<Long> inbox = (SparseArray<Long>) args[0];
SparseArray<Long> outbox = (SparseArray<Long>) args[1];
2013-10-25 17:19:00 +02:00
boolean updated = false;
2015-09-24 22:52:02 +02:00
for (int b = 0; b < inbox.size(); b++) {
int key = inbox.keyAt(b);
long messageId = inbox.get(key);
if (key != dialog_id) {
continue;
}
for (int a = 0; a < messages.size(); a++) {
MessageObject obj = messages.get(a);
2015-09-24 22:52:02 +02:00
if (!obj.isOut() && obj.getId() > 0 && obj.getId() <= (int) messageId) {
if (!obj.isUnread()) {
break;
}
obj.setIsRead();
updated = true;
}
}
break;
}
2015-09-24 22:52:02 +02:00
for (int b = 0; b < outbox.size(); b++) {
int key = outbox.keyAt(b);
int messageId = (int) ((long) outbox.get(key));
2015-09-24 22:52:02 +02:00
if (key != dialog_id) {
continue;
}
for (int a = 0; a < messages.size(); a++) {
MessageObject obj = messages.get(a);
2015-09-24 22:52:02 +02:00
if (obj.isOut() && obj.getId() > 0 && obj.getId() <= messageId) {
if (!obj.isUnread()) {
break;
}
obj.setIsRead();
updated = true;
}
2013-10-25 17:19:00 +02:00
}
break;
2013-10-25 17:19:00 +02:00
}
if (updated) {
updateVisibleRows();
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.messagesDeleted) {
2015-04-09 20:00:14 +02:00
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>) args[0];
2015-09-24 22:52:02 +02:00
int channelId = (Integer) args[1];
2015-11-26 22:04:02 +01:00
int loadIndex = 0;
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(currentChat)) {
2015-11-26 22:04:02 +01:00
if (channelId == 0 && mergeDialogId != 0) {
loadIndex = 1;
} else if (channelId == currentChat.id) {
loadIndex = 0;
} else {
2015-09-24 22:52:02 +02:00
return;
}
} else if (channelId != 0) {
return;
}
2013-10-25 17:19:00 +02:00
boolean updated = false;
2015-11-26 22:04:02 +01:00
for (int a = 0; a < markAsDeletedMessages.size(); a++) {
Integer ids = markAsDeletedMessages.get(a);
MessageObject obj = messagesDict[loadIndex].get(ids);
2016-03-16 13:26:32 +01:00
if (loadIndex == 0 && info != null && info.pinned_msg_id == ids) {
pinnedMessageObject = null;
info.pinned_msg_id = 0;
MessagesStorage.getInstance().updateChannelPinnedMessage(channelId, 0);
updatePinnedMessageView(true);
}
2013-10-25 17:19:00 +02:00
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);
2015-11-26 22:04:02 +01:00
messagesDict[loadIndex].remove(ids);
2013-12-20 20:25:49 +01:00
ArrayList<MessageObject> dayArr = messagesByDays.get(obj.dateKey);
2015-12-09 19:27:52 +01:00
if (dayArr != null) {
dayArr.remove(obj);
if (dayArr.isEmpty()) {
messagesByDays.remove(obj.dateKey);
if (index >= 0 && index < messages.size()) {
messages.remove(index);
}
2014-12-04 21:27:06 +01:00
}
2013-12-20 20:25:49 +01:00
}
2016-05-25 23:49:47 +02:00
updated = true;
2013-10-25 17:19:00 +02:00
}
2013-12-20 20:25:49 +01:00
}
}
if (messages.isEmpty()) {
2015-11-26 22:04:02 +01:00
if (!endReached[0] && !loading) {
2015-06-29 19:12:11 +02:00
if (progressView != null) {
progressView.setVisibility(View.INVISIBLE);
}
if (chatListView != null) {
chatListView.setEmptyView(null);
}
if (currentEncryptedChat == null) {
2015-11-26 22:04:02 +01:00
maxMessageId[0] = maxMessageId[1] = Integer.MAX_VALUE;
minMessageId[0] = minMessageId[1] = Integer.MIN_VALUE;
} else {
2015-11-26 22:04:02 +01:00
maxMessageId[0] = maxMessageId[1] = Integer.MIN_VALUE;
minMessageId[0] = minMessageId[1] = Integer.MAX_VALUE;
}
2015-11-26 22:04:02 +01:00
maxDate[0] = maxDate[1] = Integer.MIN_VALUE;
minDate[0] = minDate[1] = 0;
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(dialog_id, 30, 0, !cacheEndReached[0], minDate[0], classGuid, 0, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
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);
}
}
2015-11-26 22:04:02 +01:00
if (currentEncryptedChat == null && currentUser != null && currentUser.bot && botUser == null) {
2015-06-29 19:12:11 +02:00
botUser = "";
updateBottomOverlay();
}
2013-10-25 17:19:00 +02:00
}
}
if (updated && chatAdapter != null) {
removeUnreadPlane();
2013-10-25 17:19:00 +02:00
chatAdapter.notifyDataSetChanged();
}
} else if (id == NotificationCenter.messageReceivedByServer) {
2015-04-09 20:00:14 +02:00
Integer msgId = (Integer) args[0];
2015-11-26 22:04:02 +01:00
MessageObject obj = messagesDict[0].get(msgId);
2013-10-25 17:19:00 +02:00
if (obj != null) {
2015-04-09 20:00:14 +02:00
Integer newMsgId = (Integer) args[1];
2015-11-26 22:04:02 +01:00
if (!newMsgId.equals(msgId) && messagesDict[0].containsKey(newMsgId)) {
MessageObject removed = messagesDict[0].remove(msgId);
2015-10-29 18:10:07 +01:00
if (removed != null) {
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);
}
}
2016-05-25 23:49:47 +02:00
if (chatAdapter != null) {
chatAdapter.notifyDataSetChanged();
}
2015-10-29 18:10:07 +01:00
}
return;
}
2015-04-09 20:00:14 +02:00
TLRPC.Message newMsgObj = (TLRPC.Message) args[2];
2015-09-24 22:52:02 +02:00
boolean mediaUpdated = false;
2016-10-11 13:57:01 +02:00
boolean updatedForward = false;
if (newMsgObj != null) {
2016-10-11 13:57:01 +02:00
try {
updatedForward = obj.isForwarded() && (obj.messageOwner.reply_markup == null && newMsgObj.reply_markup != null || !obj.messageOwner.message.equals(newMsgObj.message));
mediaUpdated = updatedForward ||
obj.messageOwner.params != null && obj.messageOwner.params.containsKey("query_id") ||
newMsgObj.media != null && obj.messageOwner.media != null && !newMsgObj.media.getClass().equals(obj.messageOwner.media.getClass());
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2016-04-22 15:49:00 +02:00
obj.messageOwner = newMsgObj;
2015-02-01 19:51:02 +01:00
obj.generateThumbs(true);
2016-04-22 15:49:00 +02:00
obj.setType();
2016-10-11 13:57:01 +02:00
if (newMsgObj.media instanceof TLRPC.TL_messageMediaGame) {
obj.applyNewText();
}
}
if (updatedForward) {
obj.measureInlineBotButtons();
}
2015-11-26 22:04:02 +01:00
messagesDict[0].remove(msgId);
messagesDict[0].put(newMsgId, obj);
2013-10-25 17:19:00 +02:00
obj.messageOwner.id = newMsgId;
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
2016-04-22 15:49:00 +02:00
obj.forceUpdate = mediaUpdated;
2015-06-29 19:12:11 +02:00
ArrayList<MessageObject> messArr = new ArrayList<>();
messArr.add(obj);
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat == null) {
2016-03-16 13:26:32 +01:00
MessagesQuery.loadReplyMessagesForMessages(messArr, dialog_id);
2016-03-06 02:49:31 +01:00
}
2015-10-29 18:10:07 +01:00
if (chatAdapter != null) {
chatAdapter.updateRowWithMessageObject(obj);
2015-06-29 19:12:11 +02:00
}
if (chatLayoutManager != null) {
if (mediaUpdated && chatLayoutManager.findLastVisibleItemPosition() >= messages.size() - 1) {
moveScrollToLastMessage();
}
2015-04-09 20:00:14 +02:00
}
2015-05-21 23:27:27 +02:00
NotificationsController.getInstance().playOutChatSound();
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.messageReceivedByAck) {
2015-04-09 20:00:14 +02:00
Integer msgId = (Integer) args[0];
2015-11-26 22:04:02 +01:00
MessageObject obj = messagesDict[0].get(msgId);
2013-10-25 17:19:00 +02:00
if (obj != null) {
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
2015-10-29 18:10:07 +01:00
if (chatAdapter != null) {
chatAdapter.updateRowWithMessageObject(obj);
}
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.messageSendError) {
2015-04-09 20:00:14 +02:00
Integer msgId = (Integer) args[0];
2015-11-26 22:04:02 +01:00
MessageObject obj = messagesDict[0].get(msgId);
2013-10-25 17:19:00 +02:00
if (obj != null) {
obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
updateVisibleRows();
2013-10-25 17:19:00 +02:00
}
} else if (id == NotificationCenter.chatInfoDidLoaded) {
2015-09-24 22:52:02 +02:00
TLRPC.ChatFull chatFull = (TLRPC.ChatFull) args[0];
if (currentChat != null && chatFull.id == currentChat.id) {
2015-11-26 22:04:02 +01:00
if (chatFull instanceof TLRPC.TL_channelFull) {
if (currentChat.megagroup) {
int lastDate = 0;
if (chatFull.participants != null) {
for (int a = 0; a < chatFull.participants.participants.size(); a++) {
lastDate = Math.max(chatFull.participants.participants.get(a).date, lastDate);
}
}
if (lastDate == 0 || Math.abs(System.currentTimeMillis() / 1000 - lastDate) > 60 * 60) {
MessagesController.getInstance().loadChannelParticipants(currentChat.id);
}
}
if (chatFull.participants == null && info != null) {
chatFull.participants = info.participants;
}
}
2015-09-24 22:52:02 +02:00
info = chatFull;
if (mentionsAdapter != null) {
mentionsAdapter.setChatInfo(info);
}
2016-03-16 13:26:32 +01:00
if (args[3] instanceof MessageObject) {
pinnedMessageObject = (MessageObject) args[3];
updatePinnedMessageView(false);
} else {
updatePinnedMessageView(true);
}
2016-04-22 15:49:00 +02:00
if (avatarContainer != null) {
avatarContainer.updateOnlineCount();
avatarContainer.updateSubtitle();
}
2014-10-20 13:30:05 +02:00
if (isBroadcast) {
SendMessagesHelper.getInstance().setCurrentChatInfo(info);
}
2015-09-24 22:52:02 +02:00
if (info instanceof TLRPC.TL_chatFull) {
2015-06-29 19:12:11 +02:00
hasBotsCommands = false;
botInfo.clear();
botsCount = 0;
2015-10-29 18:10:07 +01:00
URLSpanBotCommand.enabled = false;
2015-09-24 22:52:02 +02:00
for (int a = 0; a < info.participants.participants.size(); a++) {
2015-11-26 22:04:02 +01:00
TLRPC.ChatParticipant participant = info.participants.participants.get(a);
2015-06-29 19:12:11 +02:00
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
2015-11-26 22:04:02 +01:00
if (user != null && user.bot) {
2015-10-29 18:10:07 +01:00
URLSpanBotCommand.enabled = true;
2015-06-29 19:12:11 +02:00
botsCount++;
BotQuery.loadBotInfo(user.id, true, classGuid);
}
}
2015-10-29 18:10:07 +01:00
if (chatListView != null) {
chatListView.invalidateViews();
}
2015-11-26 22:04:02 +01:00
} else if (info instanceof TLRPC.TL_channelFull) {
hasBotsCommands = false;
botInfo.clear();
botsCount = 0;
URLSpanBotCommand.enabled = !info.bot_info.isEmpty();
botsCount = info.bot_info.size();
for (int a = 0; a < info.bot_info.size(); a++) {
TLRPC.BotInfo bot = info.bot_info.get(a);
2016-03-06 02:49:31 +01:00
if (!bot.commands.isEmpty() && (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup)) {
2015-11-26 22:04:02 +01:00
hasBotsCommands = true;
}
botInfo.put(bot.user_id, bot);
}
if (chatListView != null) {
chatListView.invalidateViews();
}
2016-03-06 02:49:31 +01:00
if (mentionsAdapter != null && (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup)) {
2015-11-26 22:04:02 +01:00
mentionsAdapter.setBotInfo(botInfo);
}
2015-06-29 19:12:11 +02:00
}
if (chatActivityEnterView != null) {
chatActivityEnterView.setBotsCount(botsCount, hasBotsCommands);
}
if (mentionsAdapter != null) {
mentionsAdapter.setBotsCount(botsCount);
}
2015-11-26 22:04:02 +01:00
if (ChatObject.isChannel(currentChat) && mergeDialogId == 0 && info.migrated_from_chat_id != 0) {
mergeDialogId = -info.migrated_from_chat_id;
maxMessageId[1] = info.migrated_from_max_id;
if (chatAdapter != null) {
chatAdapter.notifyDataSetChanged();
}
}
2013-10-25 17:19:00 +02:00
}
2015-09-24 22:52:02 +02:00
} else if (id == NotificationCenter.chatInfoCantLoad) {
int chatId = (Integer) args[0];
if (currentChat != null && currentChat.id == chatId) {
2016-03-16 13:26:32 +01:00
int reason = (Integer) args[1];
2015-09-24 22:52:02 +02:00
if (getParentActivity() == null || closeChatDialog != null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
2016-03-16 13:26:32 +01:00
if (reason == 0) {
builder.setMessage(LocaleController.getString("ChannelCantOpenPrivate", R.string.ChannelCantOpenPrivate));
} else if (reason == 1) {
builder.setMessage(LocaleController.getString("ChannelCantOpenNa", R.string.ChannelCantOpenNa));
} else if (reason == 2) {
builder.setMessage(LocaleController.getString("ChannelCantOpenBanned", R.string.ChannelCantOpenBanned));
}
2015-09-24 22:52:02 +02:00
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(closeChatDialog = builder.create());
loading = false;
if (progressView != null) {
progressView.setVisibility(View.INVISIBLE);
}
if (chatAdapter != null) {
chatAdapter.notifyDataSetChanged();
}
}
} else if (id == NotificationCenter.contactsDidLoaded) {
2013-10-25 17:19:00 +02:00
updateContactStatus();
2016-04-22 15:49:00 +02:00
if (avatarContainer != null) {
avatarContainer.updateSubtitle();
}
} 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();
2016-03-06 02:49:31 +01:00
initStickers();
if (chatActivityEnterView != null) {
chatActivityEnterView.setAllowStickersAndGifs(currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 23, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46);
}
if (mentionsAdapter != null) {
mentionsAdapter.setNeedBotContext(!chatActivityEnterView.isEditingMessage() && (currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46));
}
2013-10-25 17:19:00 +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) {
if (!obj.isOut()) {
2013-12-20 20:25:49 +01:00
continue;
} else if (obj.isOut() && !obj.isUnread()) {
2013-12-20 20:25:49 +01:00
break;
}
if (obj.messageOwner.date - 1 <= date) {
obj.setIsRead();
2013-10-25 17:19:00 +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) {
if (chatListView != null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
2016-04-22 15:49:00 +02:00
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && (messageObject.isVoice() || messageObject.isMusic())) {
2015-07-22 20:56:37 +02:00
cell.updateButtonState(false);
}
}
}
2016-10-11 13:57:01 +02:00
count = mentionListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = mentionListView.getChildAt(a);
if (view instanceof ContextLinkCell) {
ContextLinkCell cell = (ContextLinkCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && (messageObject.isVoice() || messageObject.isMusic())) {
cell.updateButtonState(false);
}
}
}
}
} else if (id == NotificationCenter.audioProgressDidChanged) {
2015-04-09 20:00:14 +02:00
Integer mid = (Integer) args[0];
if (chatListView != null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
2016-04-22 15:49:00 +02:00
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
2015-07-22 20:56:37 +02:00
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;
2016-04-22 15:49:00 +02:00
cell.updateAudioProgress();
2015-08-13 11:23:31 +02:00
}
2015-07-22 20:56:37 +02:00
break;
}
}
}
}
} 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();
2015-11-26 22:04:02 +01:00
waitingForLoad.clear();
2014-10-21 22:35:16 +02:00
messagesByDays.clear();
2015-11-26 22:04:02 +01:00
for (int a = 1; a >= 0; a--) {
messagesDict[a].clear();
if (currentEncryptedChat == null) {
maxMessageId[a] = Integer.MAX_VALUE;
minMessageId[a] = Integer.MIN_VALUE;
} else {
maxMessageId[a] = Integer.MIN_VALUE;
minMessageId[a] = Integer.MAX_VALUE;
}
maxDate[a] = Integer.MIN_VALUE;
minDate[a] = 0;
selectedMessagesIds[a].clear();
selectedMessagesCanCopyIds[a].clear();
2014-10-21 22:35:16 +02:00
}
2015-09-24 22:52:02 +02:00
cantDeleteMessagesCount = 0;
2014-11-11 23:16:17 +01:00
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
2015-06-29 19:12:11 +02:00
2015-09-24 22:52:02 +02:00
if (botButtons != null) {
botButtons = null;
if (chatActivityEnterView != null) {
chatActivityEnterView.setButtons(null, false);
}
2015-09-24 22:52:02 +02:00
}
2015-11-26 22:04:02 +01:00
if (currentEncryptedChat == null && currentUser != null && currentUser.bot && botUser == null) {
2015-09-24 22:52:02 +02:00
botUser = "";
updateBottomOverlay();
}
2015-11-26 22:04:02 +01:00
if ((Boolean) args[1]) {
if (chatAdapter != null) {
progressView.setVisibility(chatAdapter.botInfoRow == -1 ? View.VISIBLE : View.INVISIBLE);
chatListView.setEmptyView(null);
}
2015-11-26 22:04:02 +01:00
for (int a = 0; a < 2; a++) {
endReached[a] = false;
cacheEndReached[a] = false;
forwardEndReached[a] = true;
2015-06-29 19:12:11 +02:00
}
2015-09-24 22:52:02 +02:00
first = true;
firstLoading = true;
loading = true;
startLoadFromMessageId = 0;
needSelectFromMessageId = false;
2015-11-26 22:04:02 +01:00
waitingForLoad.add(lastLoadIndex);
MessagesController.getInstance().loadMessages(dialog_id, AndroidUtilities.isTablet() ? 30 : 20, 0, true, 0, classGuid, 2, 0, ChatObject.isChannel(currentChat), lastLoadIndex++);
2015-09-24 22:52:02 +02:00
} else {
if (progressView != null) {
progressView.setVisibility(View.INVISIBLE);
chatListView.setEmptyView(emptyViewContainer);
2015-06-29 19:12:11 +02:00
}
}
2015-09-24 22:52:02 +02:00
if (chatAdapter != null) {
chatAdapter.notifyDataSetChanged();
}
}
} else if (id == NotificationCenter.screenshotTook) {
updateInformationForScreenshotDetector();
} else if (id == NotificationCenter.blockedUsersDidLoaded) {
if (currentUser != null) {
boolean oldValue = userBlocked;
userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
if (oldValue != userBlocked) {
updateBottomOverlay();
}
}
} else if (id == NotificationCenter.FileNewChunkAvailable) {
2015-04-09 20:00:14 +02:00
MessageObject messageObject = (MessageObject) args[0];
long finalSize = (Long) args[2];
if (finalSize != 0 && dialog_id == messageObject.getDialogId()) {
2015-11-26 22:04:02 +01:00
MessageObject currentObject = messagesDict[0].get(messageObject.getId());
if (currentObject != null) {
2016-03-06 02:49:31 +01:00
currentObject.messageOwner.media.document.size = (int) finalSize;
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) {
2015-11-26 22:04:02 +01:00
MessageObject messageObject = messagesDict[0].get(mid);
2014-10-10 19:16:39 +02:00
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
if (chatListView != null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
2016-04-22 15:49:00 +02:00
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject messageObject1 = cell.getMessageObject();
if (messageObject1 != null && (messageObject1.isVoice() || messageObject1.isMusic())) {
2015-07-22 20:56:37 +02:00
cell.updateButtonState(false);
}
}
}
}
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-11-26 22:04:02 +01:00
MessageObject existMessageObject = messagesDict[0].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) {
2015-11-26 22:04:02 +01:00
long did = (long) args[0];
if (did != dialog_id && did != mergeDialogId) {
return;
}
int loadIndex = did == dialog_id ? 0 : 1;
boolean changed = false;
boolean mediaUpdated = false;
ArrayList<MessageObject> messageObjects = (ArrayList<MessageObject>) args[1];
2016-03-06 02:49:31 +01:00
for (int a = 0; a < messageObjects.size(); a++) {
MessageObject messageObject = messageObjects.get(a);
2015-11-26 22:04:02 +01:00
MessageObject old = messagesDict[loadIndex].get(messageObject.getId());
2016-03-16 13:26:32 +01:00
if (pinnedMessageObject != null && pinnedMessageObject.getId() == messageObject.getId()) {
pinnedMessageObject = messageObject;
updatePinnedMessageView(true);
}
2015-11-26 22:04:02 +01:00
if (old != null) {
2016-10-11 13:57:01 +02:00
if (messageObject.type >= 0) {
if (!mediaUpdated && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
mediaUpdated = true;
}
if (old.replyMessageObject != null) {
messageObject.replyMessageObject = old.replyMessageObject;
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
messageObject.generateGameMessageText(null);
}
}
messageObject.messageOwner.attachPath = old.messageOwner.attachPath;
messageObject.attachPathExists = old.attachPathExists;
messageObject.mediaExists = old.mediaExists;
messagesDict[loadIndex].put(old.getId(), messageObject);
} else {
messagesDict[loadIndex].remove(old.getId());
2016-03-06 02:49:31 +01:00
}
2015-11-26 22:04:02 +01:00
int index = messages.indexOf(old);
if (index >= 0) {
2016-10-11 13:57:01 +02:00
ArrayList<MessageObject> dayArr = messagesByDays.get(old.dateKey);
int index2 = -1;
if (dayArr != null) {
index2 = dayArr.indexOf(old);
}
if (messageObject.type >= 0) {
messages.set(index, messageObject);
if (chatAdapter != null) {
chatAdapter.notifyItemChanged(chatAdapter.messagesStartRow + messages.size() - index - 1);
}
if (index2 >= 0) {
dayArr.set(index2, messageObject);
}
} else {
messages.remove(index);
if (chatAdapter != null) {
chatAdapter.notifyItemRemoved(chatAdapter.messagesStartRow + messages.size() - index - 1);
}
if (index2 >= 0) {
dayArr.remove(index2);
if (dayArr.isEmpty()) {
messagesByDays.remove(old.dateKey);
messages.remove(index);
chatAdapter.notifyItemRemoved(chatAdapter.messagesStartRow + messages.size());
}
}
2015-01-09 13:50:15 +01:00
}
2015-11-26 22:04:02 +01:00
changed = true;
2015-01-09 13:50:15 +01:00
}
}
2015-11-26 22:04:02 +01:00
}
if (changed && chatLayoutManager != null) {
if (mediaUpdated && chatLayoutManager.findLastVisibleItemPosition() >= messages.size() - (chatAdapter.isBot ? 2 : 1)) {
moveScrollToLastMessage();
2015-01-09 13:50:15 +01:00
}
}
2015-02-01 19:51:02 +01:00
} else if (id == NotificationCenter.notificationsSettingsUpdated) {
updateTitleIcons();
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(currentChat)) {
updateBottomOverlay();
}
} else if (id == NotificationCenter.didLoadedReplyMessages) {
long did = (Long) args[0];
if (did == dialog_id) {
updateVisibleRows();
}
2016-03-16 13:26:32 +01:00
} else if (id == NotificationCenter.didLoadedPinnedMessage) {
MessageObject message = (MessageObject) args[0];
if (message.getDialogId() == dialog_id && info != null && info.pinned_msg_id == message.getId()) {
pinnedMessageObject = message;
loadingPinnedMessage = 0;
updatePinnedMessageView(true);
}
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;
2015-11-26 22:04:02 +01:00
for (int a = 0; a < arrayList.size(); a++) {
TLRPC.Message message = arrayList.get(a);
long did = MessageObject.getDialogId(message);
if (did != dialog_id && did != mergeDialogId) {
continue;
}
MessageObject currentMessage = messagesDict[did == dialog_id ? 0 : 1].get(message.id);
2015-04-09 20:00:14 +02:00
if (currentMessage != null) {
2015-09-24 22:52:02 +02:00
currentMessage.messageOwner.media = new TLRPC.TL_messageMediaWebPage();
2015-04-09 20:00:14 +02:00
currentMessage.messageOwner.media.webpage = message.media.webpage;
currentMessage.generateThumbs(true);
updated = true;
}
}
if (updated) {
updateVisibleRows();
2016-04-22 15:49:00 +02:00
if (chatLayoutManager != null && 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;
}
}
}
} else if (id == NotificationCenter.messagesReadContent) {
2015-09-24 22:52:02 +02:00
ArrayList<Long> arrayList = (ArrayList<Long>) args[0];
boolean updated = false;
2015-11-26 22:04:02 +01:00
for (int a = 0; a < arrayList.size(); a++) {
long mid = arrayList.get(a);
2016-03-16 13:26:32 +01:00
MessageObject currentMessage = messagesDict[mergeDialogId == 0 ? 0 : 1].get((int) 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) {
2016-03-06 02:49:31 +01:00
if (!info.commands.isEmpty() && !ChatObject.isChannel(currentChat)) {
2015-06-29 19:12:11 +02:00
hasBotsCommands = true;
}
botInfo.put(info.user_id, info);
if (chatAdapter != null) {
chatAdapter.notifyItemChanged(0);
}
2016-03-06 02:49:31 +01:00
if (mentionsAdapter != null && (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup)) {
2015-06-29 19:12:11 +02:00
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];
2015-11-26 22:04:02 +01:00
if (message != null && !userBlocked) {
2015-06-29 19:12:11 +02:00
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];
2015-11-26 22:04:02 +01:00
long did = (Long) args[3];
2015-06-29 19:12:11 +02:00
if (messageId != 0) {
2015-11-26 22:04:02 +01:00
scrollToMessageId(messageId, 0, true, did == dialog_id ? 0 : 1);
2015-06-29 19:12:11 +02:00
}
updateSearchButtons((Integer) args[2], (Integer) args[4], (Integer) args[5]);
2015-06-29 19:12:11 +02:00
}
2015-09-24 22:52:02 +02:00
} else if (id == NotificationCenter.didUpdatedMessagesViews) {
SparseArray<SparseIntArray> channelViews = (SparseArray<SparseIntArray>) args[0];
SparseIntArray array = channelViews.get((int) dialog_id);
if (array != null) {
boolean updated = false;
for (int a = 0; a < array.size(); a++) {
int messageId = array.keyAt(a);
2015-11-26 22:04:02 +01:00
MessageObject messageObject = messagesDict[0].get(messageId);
2015-09-24 22:52:02 +02:00
if (messageObject != null) {
int newValue = array.get(messageId);
if (newValue > messageObject.messageOwner.views) {
messageObject.messageOwner.views = newValue;
updated = true;
}
}
}
if (updated) {
updateVisibleRows();
}
}
2016-03-16 13:26:32 +01:00
} else if (id == NotificationCenter.peerSettingsDidLoaded) {
long did = (Long) args[0];
if (did == dialog_id) {
updateSpamView();
}
} else if (id == NotificationCenter.newDraftReceived) {
long did = (Long) args[0];
if (did == dialog_id) {
2016-10-11 13:57:01 +02:00
applyDraftMaybe(true);
}
2015-06-29 19:12:11 +02:00
}
}
2016-04-22 15:49:00 +02:00
public boolean processSwitchButton(TLRPC.TL_keyboardButtonSwitchInline button) {
2016-10-11 13:57:01 +02:00
if (inlineReturn == 0 || button.same_peer) {
2016-04-22 15:49:00 +02:00
return false;
2015-10-29 18:10:07 +01:00
}
2016-04-22 15:49:00 +02:00
String query = "@" + currentUser.username + " " + button.query;
if (inlineReturn == dialog_id) {
inlineReturn = 0;
chatActivityEnterView.setFieldText(query);
} else {
DraftQuery.saveDraft(inlineReturn, query, null, null, false);
2016-04-22 15:49:00 +02:00
if (parentLayout.fragmentsStack.size() > 1) {
BaseFragment prevFragment = parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2);
if (prevFragment instanceof ChatActivity && ((ChatActivity) prevFragment).dialog_id == inlineReturn) {
finishFragment();
} else {
Bundle bundle = new Bundle();
int lower_part = (int) inlineReturn;
int high_part = (int) (inlineReturn >> 32);
if (lower_part != 0) {
if (lower_part > 0) {
bundle.putInt("user_id", lower_part);
} else if (lower_part < 0) {
bundle.putInt("chat_id", -lower_part);
}
} else {
bundle.putInt("enc_id", high_part);
}
/*ActionBarLayout parentLayout = ChatActivity.this.parentLayout;
if (lastFragment != null) {
NotificationCenter.getInstance().removeObserver(lastFragment, NotificationCenter.closeChats);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);*/
presentFragment(new ChatActivity(bundle), true);
}
}
}
return true;
}
private void updateSearchButtons(int mask, int num, int count) {
if (searchUpButton != null) {
searchUpButton.setEnabled((mask & 1) != 0);
searchDownButton.setEnabled((mask & 2) != 0);
searchUpButton.setAlpha(searchUpButton.isEnabled() ? 1.0f : 0.5f);
searchDownButton.setAlpha(searchDownButton.isEnabled() ? 1.0f : 0.5f);
if (count == 0) {
searchCountText.setText("");
} else {
searchCountText.setText(LocaleController.formatString("Of", R.string.Of, num + 1, count));
}
2016-04-22 15:49:00 +02:00
}
}
2016-05-25 23:49:47 +02:00
@Override
public boolean needDelayOpenAnimation() {
return firstLoading;
}
2016-04-22 15:49:00 +02:00
@Override
public void onTransitionAnimationStart(boolean isOpen, boolean backward) {
NotificationCenter.getInstance().setAllowedNotificationsDutingAnimation(new int[]{NotificationCenter.chatInfoDidLoaded, NotificationCenter.dialogsNeedReload,
NotificationCenter.closeChats, NotificationCenter.messagesDidLoaded, NotificationCenter.botKeyboardDidLoaded/*, NotificationCenter.botInfoDidLoaded*/});
NotificationCenter.getInstance().setAnimationInProgress(true);
if (isOpen) {
openAnimationEnded = false;
}
}
2015-05-21 23:27:27 +02:00
@Override
2015-10-29 18:10:07 +01:00
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
2016-04-22 15:49:00 +02:00
NotificationCenter.getInstance().setAnimationInProgress(false);
2015-10-29 18:10:07 +01:00
if (isOpen) {
openAnimationEnded = true;
if (currentUser != null) {
2016-03-16 13:26:32 +01:00
MessagesController.getInstance().loadFullUser(currentUser, classGuid, false);
2015-10-29 18:10:07 +01:00
}
2016-04-22 15:49:00 +02:00
if (Build.VERSION.SDK_INT >= 21) {
createChatAttachView();
}
2014-11-19 11:32:27 +01:00
}
2014-11-18 06:01:04 +01:00
}
2015-09-24 22:52:02 +02:00
@Override
protected void onDialogDismiss(Dialog dialog) {
if (closeChatDialog != null && dialog == closeChatDialog) {
2015-12-09 19:27:52 +01:00
MessagesController.getInstance().deleteDialog(dialog_id, 0);
2016-03-16 13:26:32 +01:00
if (parentLayout != null && !parentLayout.fragmentsStack.isEmpty() && parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 1) != this) {
BaseFragment fragment = parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 1);
removeSelfFromStack();
fragment.finishFragment();
} else {
finishFragment();
}
2015-09-24 22:52:02 +02:00
}
}
private void updateBottomOverlay() {
2015-06-29 19:12:11 +02:00
if (bottomOverlayChatText == null) {
return;
}
2015-09-24 22:52:02 +02:00
if (currentChat != null) {
2016-03-16 13:26:32 +01:00
if (ChatObject.isChannel(currentChat) && !(currentChat instanceof TLRPC.TL_channelForbidden)) {
2015-09-24 22:52:02 +02:00
if (ChatObject.isNotInChat(currentChat)) {
bottomOverlayChatText.setText(LocaleController.getString("ChannelJoin", R.string.ChannelJoin));
} else {
if (!MessagesController.getInstance().isDialogMuted(dialog_id)) {
bottomOverlayChatText.setText(LocaleController.getString("ChannelMute", R.string.ChannelMute));
} else {
bottomOverlayChatText.setText(LocaleController.getString("ChannelUnmute", R.string.ChannelUnmute));
}
}
} else {
bottomOverlayChatText.setText(LocaleController.getString("DeleteThisGroup", R.string.DeleteThisGroup));
}
} else {
if (userBlocked) {
2015-11-26 22:04:02 +01:00
if (currentUser.bot) {
2015-09-02 00:14:21 +02:00
bottomOverlayChatText.setText(LocaleController.getString("BotUnblock", R.string.BotUnblock));
} else {
bottomOverlayChatText.setText(LocaleController.getString("Unblock", R.string.Unblock));
}
2015-11-26 22:04:02 +01:00
if (botButtons != null) {
botButtons = null;
if (chatActivityEnterView != null) {
if (replyingMessageObject != null && botReplyButtons == replyingMessageObject) {
botReplyButtons = null;
showReplyPanel(false, null, null, null, false, true);
}
chatActivityEnterView.setButtons(botButtons, false);
}
}
} else if (botUser != null && currentUser.bot) {
2015-06-29 19:12:11 +02:00
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());
}
} else {
bottomOverlayChatText.setText(LocaleController.getString("DeleteThisChat", R.string.DeleteThisChat));
}
}
if (searchItem != null && searchItem.getVisibility() == View.VISIBLE) {
searchContainer.setVisibility(View.VISIBLE);
bottomOverlayChat.setVisibility(View.INVISIBLE);
chatActivityEnterView.setFieldFocused(false);
2015-06-29 19:12:11 +02:00
chatActivityEnterView.setVisibility(View.INVISIBLE);
} else {
searchContainer.setVisibility(View.INVISIBLE);
if (currentChat != null && (ChatObject.isNotInChat(currentChat) || !ChatObject.canWriteToChat(currentChat)) ||
currentUser != null && (UserObject.isDeleted(currentUser) || userBlocked)) {
2015-06-29 19:12:11 +02:00
bottomOverlayChat.setVisibility(View.VISIBLE);
2016-10-11 13:57:01 +02:00
if (muteItem != null) {
muteItem.setVisibility(View.GONE);
}
chatActivityEnterView.setFieldFocused(false);
2015-06-29 19:12:11 +02:00
chatActivityEnterView.setVisibility(View.INVISIBLE);
2016-10-11 13:57:01 +02:00
attachItem.setVisibility(View.GONE);
headerItem.setVisibility(View.VISIBLE);
2015-06-29 19:12:11 +02:00
} else {
if (botUser != null && currentUser.bot) {
bottomOverlayChat.setVisibility(View.VISIBLE);
chatActivityEnterView.setVisibility(View.INVISIBLE);
} else {
chatActivityEnterView.setVisibility(View.VISIBLE);
bottomOverlayChat.setVisibility(View.INVISIBLE);
}
2016-10-11 13:57:01 +02:00
if (muteItem != null) {
muteItem.setVisibility(View.VISIBLE);
}
2015-06-29 19:12:11 +02:00
}
2013-10-25 17:19:00 +02:00
}
2016-03-06 02:49:31 +01:00
checkRaiseSensors();
2013-10-25 17:19:00 +02:00
}
2016-10-11 13:57:01 +02:00
public void showAlert(String name, String message) {
if (alertView == null || name == null || message == null) {
2016-04-22 15:49:00 +02:00
return;
}
if (alertView.getTag() != null) {
alertView.setTag(null);
if (alertViewAnimator != null) {
alertViewAnimator.cancel();
alertViewAnimator = null;
}
alertView.setVisibility(View.VISIBLE);
alertViewAnimator = new AnimatorSet();
alertViewAnimator.playTogether(ObjectAnimator.ofFloat(alertView, "translationY", 0));
alertViewAnimator.setDuration(200);
alertViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertViewAnimator = null;
2016-04-22 15:49:00 +02:00
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertViewAnimator = null;
2016-04-22 15:49:00 +02:00
}
}
});
alertViewAnimator.start();
2016-04-22 15:49:00 +02:00
}
2016-10-11 13:57:01 +02:00
alertNameTextView.setText(name);
2016-04-22 15:49:00 +02:00
alertTextView.setText(Emoji.replaceEmoji(message.replace('\n', ' '), alertTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
if (hideAlertViewRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(hideAlertViewRunnable);
}
AndroidUtilities.runOnUIThread(hideAlertViewRunnable = new Runnable() {
@Override
public void run() {
if (hideAlertViewRunnable != this) {
return;
}
if (alertView.getTag() == null) {
alertView.setTag(1);
if (alertViewAnimator != null) {
alertViewAnimator.cancel();
alertViewAnimator = null;
}
alertViewAnimator = new AnimatorSet();
alertViewAnimator.playTogether(ObjectAnimator.ofFloat(alertView, "translationY", -AndroidUtilities.dp(50)));
alertViewAnimator.setDuration(200);
alertViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertView.setVisibility(View.GONE);
alertViewAnimator = null;
2016-04-22 15:49:00 +02:00
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertViewAnimator = null;
2016-04-22 15:49:00 +02:00
}
}
});
alertViewAnimator.start();
2016-04-22 15:49:00 +02:00
}
}
}, 3000);
}
2016-03-16 13:26:32 +01:00
private void hidePinnedMessageView(boolean animated) {
if (pinnedMessageView.getTag() == null) {
pinnedMessageView.setTag(1);
if (pinnedMessageViewAnimator != null) {
pinnedMessageViewAnimator.cancel();
pinnedMessageViewAnimator = null;
}
if (animated) {
pinnedMessageViewAnimator = new AnimatorSet();
pinnedMessageViewAnimator.playTogether(ObjectAnimator.ofFloat(pinnedMessageView, "translationY", -AndroidUtilities.dp(50)));
2016-03-16 13:26:32 +01:00
pinnedMessageViewAnimator.setDuration(200);
pinnedMessageViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2016-03-16 13:26:32 +01:00
if (pinnedMessageViewAnimator != null && pinnedMessageViewAnimator.equals(animation)) {
pinnedMessageView.setVisibility(View.GONE);
pinnedMessageViewAnimator = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
2016-03-16 13:26:32 +01:00
if (pinnedMessageViewAnimator != null && pinnedMessageViewAnimator.equals(animation)) {
pinnedMessageViewAnimator = null;
}
}
});
pinnedMessageViewAnimator.start();
} else {
pinnedMessageView.setTranslationY(-AndroidUtilities.dp(50));
2016-03-16 13:26:32 +01:00
pinnedMessageView.setVisibility(View.GONE);
}
}
}
private void updatePinnedMessageView(boolean animated) {
if (pinnedMessageView == null) {
return;
}
if (info != null) {
if (pinnedMessageObject != null && info.pinned_msg_id != pinnedMessageObject.getId()) {
pinnedMessageObject = null;
}
if (info.pinned_msg_id != 0 && pinnedMessageObject == null) {
pinnedMessageObject = messagesDict[0].get(info.pinned_msg_id);
}
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (info == null || info.pinned_msg_id == 0 || info.pinned_msg_id == preferences.getInt("pin_" + dialog_id, 0) || actionBar != null && actionBar.isActionModeShowed()) {
hidePinnedMessageView(animated);
} else {
if (pinnedMessageObject != null) {
if (pinnedMessageView.getTag() != null) {
pinnedMessageView.setTag(null);
if (pinnedMessageViewAnimator != null) {
pinnedMessageViewAnimator.cancel();
pinnedMessageViewAnimator = null;
}
if (animated) {
2016-03-16 13:26:32 +01:00
pinnedMessageView.setVisibility(View.VISIBLE);
pinnedMessageViewAnimator = new AnimatorSet();
pinnedMessageViewAnimator.playTogether(ObjectAnimator.ofFloat(pinnedMessageView, "translationY", 0));
2016-03-16 13:26:32 +01:00
pinnedMessageViewAnimator.setDuration(200);
pinnedMessageViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2016-03-16 13:26:32 +01:00
if (pinnedMessageViewAnimator != null && pinnedMessageViewAnimator.equals(animation)) {
pinnedMessageViewAnimator = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
2016-03-16 13:26:32 +01:00
if (pinnedMessageViewAnimator != null && pinnedMessageViewAnimator.equals(animation)) {
pinnedMessageViewAnimator = null;
}
}
});
pinnedMessageViewAnimator.start();
} else {
pinnedMessageView.setTranslationY(0);
2016-03-16 13:26:32 +01:00
pinnedMessageView.setVisibility(View.VISIBLE);
}
}
2016-10-11 13:57:01 +02:00
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) pinnedMessageNameTextView.getLayoutParams();
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) pinnedMessageTextView.getLayoutParams();
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(pinnedMessageObject.photoThumbs2, AndroidUtilities.dp(50));
if (photoSize == null) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(pinnedMessageObject.photoThumbs, AndroidUtilities.dp(50));
}
if (photoSize == null || photoSize instanceof TLRPC.TL_photoSizeEmpty || photoSize.location instanceof TLRPC.TL_fileLocationUnavailable || pinnedMessageObject.type == 13) {
pinnedMessageImageView.setImageBitmap(null);
pinnedImageLocation = null;
pinnedMessageImageView.setVisibility(View.INVISIBLE);
layoutParams1.leftMargin = layoutParams2.leftMargin = AndroidUtilities.dp(18);
} else {
pinnedImageLocation = photoSize.location;
pinnedMessageImageView.setImage(pinnedImageLocation, "50_50", (Drawable) null);
pinnedMessageImageView.setVisibility(View.VISIBLE);
layoutParams1.leftMargin = layoutParams2.leftMargin = AndroidUtilities.dp(55);
}
pinnedMessageNameTextView.setLayoutParams(layoutParams1);
pinnedMessageTextView.setLayoutParams(layoutParams2);
2016-03-16 13:26:32 +01:00
pinnedMessageNameTextView.setText(LocaleController.getString("PinnedMessage", R.string.PinnedMessage));
2016-10-11 13:57:01 +02:00
if (pinnedMessageObject.type == 14) {
pinnedMessageTextView.setText(String.format("%s - %s", pinnedMessageObject.getMusicAuthor(), pinnedMessageObject.getMusicTitle()));
} else if (pinnedMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
pinnedMessageTextView.setText(Emoji.replaceEmoji(pinnedMessageObject.messageOwner.media.game.title, pinnedMessageTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
} else if (pinnedMessageObject.messageText != null) {
2016-03-16 13:26:32 +01:00
String mess = pinnedMessageObject.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
2016-04-22 15:49:00 +02:00
mess = mess.replace('\n', ' ');
2016-03-16 13:26:32 +01:00
pinnedMessageTextView.setText(Emoji.replaceEmoji(mess, pinnedMessageTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
}
} else {
2016-10-11 13:57:01 +02:00
pinnedImageLocation = null;
2016-03-16 13:26:32 +01:00
hidePinnedMessageView(animated);
if (loadingPinnedMessage != info.pinned_msg_id) {
loadingPinnedMessage = info.pinned_msg_id;
MessagesQuery.loadPinnedMessage(currentChat.id, info.pinned_msg_id, true);
}
}
}
checkListViewPaddings();
}
2015-09-24 22:52:02 +02:00
private void updateSpamView() {
if (reportSpamView == null) {
return;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
2016-03-16 13:26:32 +01:00
boolean show = preferences.getInt("spam3_" + dialog_id, 0) == 2;
if (show) {
if (messages.isEmpty()) {
show = false;
} else {
2015-09-24 22:52:02 +02:00
int count = messages.size() - 1;
for (int a = count; a >= Math.max(count - 50, 0); a--) {
MessageObject messageObject = messages.get(a);
if (messageObject.isOut()) {
2016-03-16 13:26:32 +01:00
show = false;
break;
2015-09-24 22:52:02 +02:00
}
}
2016-03-16 13:26:32 +01:00
}
}
if (!show) {
if (reportSpamView.getTag() == null) {
reportSpamView.setTag(1);
if (reportSpamViewAnimator != null) {
reportSpamViewAnimator.cancel();
}
reportSpamViewAnimator = new AnimatorSet();
reportSpamViewAnimator.playTogether(ObjectAnimator.ofFloat(reportSpamView, "translationY", -AndroidUtilities.dp(50)));
reportSpamViewAnimator.setDuration(200);
reportSpamViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (reportSpamViewAnimator != null && reportSpamViewAnimator.equals(animation)) {
reportSpamView.setVisibility(View.GONE);
reportSpamViewAnimator = null;
2015-09-24 22:52:02 +02:00
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
if (reportSpamViewAnimator != null && reportSpamViewAnimator.equals(animation)) {
reportSpamViewAnimator = null;
2016-04-22 15:49:00 +02:00
}
}
});
reportSpamViewAnimator.start();
2016-03-16 13:26:32 +01:00
}
} else {
if (reportSpamView.getTag() != null) {
reportSpamView.setTag(null);
reportSpamView.setVisibility(View.VISIBLE);
if (reportSpamViewAnimator != null) {
reportSpamViewAnimator.cancel();
}
reportSpamViewAnimator = new AnimatorSet();
reportSpamViewAnimator.playTogether(ObjectAnimator.ofFloat(reportSpamView, "translationY", 0));
reportSpamViewAnimator.setDuration(200);
reportSpamViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (reportSpamViewAnimator != null && reportSpamViewAnimator.equals(animation)) {
reportSpamViewAnimator = null;
2016-03-16 13:26:32 +01:00
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
if (reportSpamViewAnimator != null && reportSpamViewAnimator.equals(animation)) {
reportSpamViewAnimator = null;
2016-04-22 15:49:00 +02:00
}
}
});
reportSpamViewAnimator.start();
2015-09-24 22:52:02 +02:00
}
}
2016-03-16 13:26:32 +01:00
checkListViewPaddings();
2015-09-24 22:52:02 +02:00
}
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 {
TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
if (user != null) {
currentUser = user;
}
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));
2016-03-16 13:26:32 +01:00
reportSpamButton.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(50), 0);
2015-09-24 22:52:02 +02:00
addToContactsButton.setVisibility(View.VISIBLE);
2015-11-26 22:04:02 +01:00
reportSpamContainer.setLayoutParams(LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f, Gravity.LEFT | Gravity.TOP, 0, 0, 0, AndroidUtilities.dp(1)));
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));
2015-09-24 22:52:02 +02:00
addToContactsButton.setVisibility(View.GONE);
2016-03-16 13:26:32 +01:00
reportSpamButton.setPadding(AndroidUtilities.dp(50), 0, AndroidUtilities.dp(50), 0);
2015-11-26 22:04:02 +01:00
reportSpamContainer.setLayoutParams(LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 1.0f, Gravity.LEFT | Gravity.TOP, 0, 0, 0, AndroidUtilities.dp(1)));
2013-10-25 17:19:00 +02:00
}
}
}
2016-03-16 13:26:32 +01:00
checkListViewPaddings();
}
private void checkListViewPaddings() {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
try {
int firstVisPos = chatLayoutManager.findLastVisibleItemPosition();
int top = 0;
if (firstVisPos != RecyclerView.NO_POSITION) {
View firstVisView = chatLayoutManager.findViewByPosition(firstVisPos);
top = ((firstVisView == null) ? 0 : firstVisView.getTop()) - chatListView.getPaddingTop();
}
if (chatListView.getPaddingTop() != AndroidUtilities.dp(52) && (pinnedMessageView != null && pinnedMessageView.getTag() == null || reportSpamView != null && reportSpamView.getTag() == null)) {
chatListView.setPadding(0, AndroidUtilities.dp(52), 0, AndroidUtilities.dp(3));
chatListView.setTopGlowOffset(AndroidUtilities.dp(48));
top -= AndroidUtilities.dp(48);
} else if (chatListView.getPaddingTop() != AndroidUtilities.dp(4) && (pinnedMessageView == null || pinnedMessageView.getTag() != null) && (reportSpamView == null || reportSpamView.getTag() != null)) {
chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3));
chatListView.setTopGlowOffset(0);
top += AndroidUtilities.dp(48);
} else {
firstVisPos = RecyclerView.NO_POSITION;
}
if (firstVisPos != RecyclerView.NO_POSITION) {
chatLayoutManager.scrollToPositionWithOffset(firstVisPos, top);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
2013-10-25 17:19:00 +02:00
}
2016-03-06 02:49:31 +01:00
private void checkRaiseSensors() {
if (!ApplicationLoader.mainInterfacePaused && (bottomOverlayChat == null || bottomOverlayChat.getVisibility() != View.VISIBLE) && (bottomOverlay == null || bottomOverlay.getVisibility() != View.VISIBLE) && (searchContainer == null || searchContainer.getVisibility() != View.VISIBLE)) {
2016-03-06 02:49:31 +01:00
MediaController.getInstance().setAllowStartRecord(true);
} else {
MediaController.getInstance().setAllowStartRecord(false);
}
}
2016-10-11 13:57:01 +02:00
@Override
public void dismissCurrentDialig() {
if (chatAttachAlert != null && visibleDialog == chatAttachAlert) {
chatAttachAlert.closeCamera(false);
chatAttachAlert.dismissInternal();
chatAttachAlert.hideCamera(true);
return;
}
super.dismissCurrentDialig();
}
2013-10-25 17:19:00 +02:00
@Override
public void onResume() {
super.onResume();
2015-09-24 22:52:02 +02:00
AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid);
2016-03-06 02:49:31 +01:00
MediaController.getInstance().startRaiseToEarSensors(this);
checkRaiseSensors();
checkActionBarMenu();
2015-04-09 20:00:14 +02:00
if (replyImageLocation != null && replyImageView != null) {
replyImageView.setImage(replyImageLocation, "50_50", (Drawable) null);
}
2016-10-11 13:57:01 +02:00
if (pinnedImageLocation != null && pinnedMessageImageView != null) {
pinnedMessageImageView.setImage(pinnedImageLocation, "50_50", (Drawable) null);
}
2014-11-11 23:16:17 +01:00
2016-03-16 13:26:32 +01:00
NotificationsController.getInstance().setOpenedDialogId(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-09-24 22:52:02 +02:00
int yOffset;
if (scrollToMessagePosition == -9000) {
yOffset = Math.max(0, (chatListView.getHeight() - scrollToMessage.getApproximateHeight()) / 2);
} else if (scrollToMessagePosition == -10000) {
yOffset = 0;
} else {
yOffset = scrollToMessagePosition;
}
chatLayoutManager.scrollToPositionWithOffset(messages.size() - messages.indexOf(scrollToMessage), -chatListView.getPaddingTop() - AndroidUtilities.dp(7) + yOffset);
2013-12-20 20:25:49 +01:00
}
} else {
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()) {
for (MessageObject messageObject : messages) {
2015-03-26 18:34:47 +01:00
if (!messageObject.isUnread() && !messageObject.isOut()) {
break;
}
if (!messageObject.isOut()) {
messageObject.setIsRead();
}
}
2013-10-25 17:19:00 +02:00
readWhenResume = false;
2015-11-26 22:04:02 +01:00
MessagesController.getInstance().markDialogAsRead(dialog_id, messages.get(0).getId(), readWithMid, readWithDate, true, false);
2013-10-25 17:19:00 +02:00
}
2016-04-22 15:49:00 +02:00
checkScrollForLoad(false);
if (wasPaused) {
wasPaused = false;
if (chatAdapter != null) {
chatAdapter.notifyDataSetChanged();
}
}
2016-04-22 15:49:00 +02:00
fixLayout();
2016-10-11 13:57:01 +02:00
applyDraftMaybe(false);
if (bottomOverlayChat != null && bottomOverlayChat.getVisibility() != View.VISIBLE) {
chatActivityEnterView.setFieldFocused(true);
}
2016-10-11 13:57:01 +02:00
if (chatActivityEnterView != null) {
chatActivityEnterView.onResume();
}
if (currentEncryptedChat != null) {
chatEnterTime = System.currentTimeMillis();
chatLeaveTime = 0;
}
2014-10-01 00:36:18 +02:00
if (startVideoEdit != null) {
AndroidUtilities.runOnUIThread(new Runnable() {
2014-10-01 00:36:18 +02:00
@Override
public void run() {
openVideoEditor(startVideoEdit, false, false);
2014-10-01 00:36:18 +02:00
startVideoEdit = null;
}
});
}
2014-10-10 19:16:39 +02:00
2016-10-11 13:57:01 +02:00
if (chatListView != null && (chatActivityEnterView == null || !chatActivityEnterView.isEditingMessage())) {
2016-03-06 02:49:31 +01:00
chatListView.setOnItemLongClickListener(onItemLongClickListener);
chatListView.setOnItemClickListener(onItemClickListener);
chatListView.setLongClickable(true);
}
2016-05-25 23:49:47 +02:00
checkBotCommands();
2013-10-25 17:19:00 +02:00
}
@Override
public void onPause() {
super.onPause();
2016-03-06 02:49:31 +01:00
MediaController.getInstance().stopRaiseToEarSensors(this);
2014-12-04 21:27:06 +01:00
if (menuItem != null) {
menuItem.closeSubMenu();
}
2016-10-11 13:57:01 +02:00
if (chatAttachAlert != null) {
chatAttachAlert.onPause();
}
2013-10-25 17:19:00 +02:00
paused = true;
wasPaused = true;
2016-03-16 13:26:32 +01:00
NotificationsController.getInstance().setOpenedDialogId(0);
CharSequence draftMessage = null;
boolean searchWebpage = true;
if (chatActivityEnterView != null) {
2015-06-29 19:12:11 +02:00
chatActivityEnterView.onPause();
2016-03-06 02:49:31 +01:00
if (!chatActivityEnterView.isEditingMessage()) {
CharSequence text = AndroidUtilities.getTrimmedString(chatActivityEnterView.getFieldText());
if (!TextUtils.isEmpty(text) && !TextUtils.equals(text, "@gif")) {
draftMessage = text;
2016-03-06 02:49:31 +01:00
}
}
searchWebpage = chatActivityEnterView.isMessageWebPageSearchEnabled();
chatActivityEnterView.setFieldFocused(false);
2013-10-25 17:19:00 +02:00
}
2016-10-11 13:57:01 +02:00
CharSequence[] message = new CharSequence[] {draftMessage};
ArrayList<TLRPC.MessageEntity> entities = MessagesQuery.getEntities(message);
DraftQuery.saveDraft(dialog_id, message[0], entities, replyingMessageObject != null ? replyingMessageObject.messageOwner : null, !searchWebpage);
MessagesController.getInstance().cancelTyping(0, dialog_id);
2014-10-20 20:11:47 +02:00
if (currentEncryptedChat != null) {
chatLeaveTime = System.currentTimeMillis();
updateInformationForScreenshotDetector();
2014-10-20 20:11:47 +02:00
}
}
2016-10-11 13:57:01 +02:00
private void applyDraftMaybe(boolean canClear) {
if (chatActivityEnterView == null) {
return;
}
TLRPC.DraftMessage draftMessage = DraftQuery.getDraft(dialog_id);
TLRPC.Message draftReplyMessage = draftMessage != null && draftMessage.reply_to_msg_id != 0 ? DraftQuery.getDraftMessage(dialog_id) : null;
if (chatActivityEnterView.getFieldText() == null) {
if (draftMessage != null) {
chatActivityEnterView.setWebPage(null, !draftMessage.no_webpage);
CharSequence message;
if (!draftMessage.entities.isEmpty()) {
SpannableStringBuilder stringBuilder = SpannableStringBuilder.valueOf(draftMessage.message);
2016-10-11 13:57:01 +02:00
MessagesQuery.sortEntities(draftMessage.entities);
int addToOffset = 0;
for (int a = 0; a < draftMessage.entities.size(); a++) {
TLRPC.MessageEntity entity = draftMessage.entities.get(a);
if (entity instanceof TLRPC.TL_inputMessageEntityMentionName || entity instanceof TLRPC.TL_messageEntityMentionName) {
int user_id;
if (entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
user_id = ((TLRPC.TL_inputMessageEntityMentionName) entity).user_id.user_id;
} else {
user_id = ((TLRPC.TL_messageEntityMentionName) entity).user_id;
}
2016-10-11 13:57:01 +02:00
if (entity.offset + addToOffset + entity.length < stringBuilder.length() && stringBuilder.charAt(entity.offset + addToOffset + entity.length) == ' ') {
entity.length++;
}
2016-10-11 13:57:01 +02:00
stringBuilder.setSpan(new URLSpanUserMention("" + user_id), entity.offset + addToOffset, entity.offset + addToOffset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntityCode) {
stringBuilder.insert(entity.offset + entity.length + addToOffset, "`");
stringBuilder.insert(entity.offset + addToOffset, "`");
addToOffset += 2;
} else if (entity instanceof TLRPC.TL_messageEntityPre) {
stringBuilder.insert(entity.offset + entity.length + addToOffset, "```");
stringBuilder.insert(entity.offset + addToOffset, "```");
addToOffset += 6;
}
}
message = stringBuilder;
} else {
message = draftMessage.message;
}
chatActivityEnterView.setFieldText(message);
if (getArguments().getBoolean("hasUrl", false)) {
chatActivityEnterView.setSelection(draftMessage.message.indexOf('\n') + 1);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (chatActivityEnterView != null) {
chatActivityEnterView.setFieldFocused(true);
chatActivityEnterView.openKeyboard();
}
}
}, 700);
}
}
2016-10-11 13:57:01 +02:00
} else if (canClear && draftMessage == null) {
chatActivityEnterView.setFieldText("");
showReplyPanel(false, null, null, null, false, true);
}
if (replyingMessageObject == null && draftReplyMessage != null) {
replyingMessageObject = new MessageObject(draftReplyMessage, MessagesController.getInstance().getUsers(), false);
showReplyPanel(true, replyingMessageObject, null, null, false, false);
}
}
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<>();
if (chatListView != null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
MessageObject object = null;
2016-05-25 23:49:47 +02:00
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
object = cell.getMessageObject();
}
if (object != null && object.getId() < 0 && object.messageOwner.random_id != 0) {
visibleMessages.add(object.messageOwner.random_id);
}
}
}
MediaController.getInstance().setLastEncryptedChatParams(chatEnterTime, chatLeaveTime, currentEncryptedChat, visibleMessages);
2013-10-25 17:19:00 +02:00
}
2016-04-22 15:49:00 +02:00
private boolean fixLayoutInternal() {
if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
selectedMessagesCountTextView.setTextSize(18);
} else {
selectedMessagesCountTextView.setTextSize(20);
}
if (AndroidUtilities.isTablet()) {
if (AndroidUtilities.isSmallTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
actionBar.setBackButtonDrawable(new BackDrawable(false));
if (playerView != null && playerView.getParent() == null) {
((ViewGroup) fragmentView).addView(playerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
}
} else {
actionBar.setBackButtonDrawable(new BackDrawable(parentLayout == null || parentLayout.fragmentsStack.isEmpty() || parentLayout.fragmentsStack.get(0) == ChatActivity.this || parentLayout.fragmentsStack.size() == 1));
if (playerView != null && playerView.getParent() != null) {
fragmentView.setPadding(0, 0, 0, 0);
((ViewGroup) fragmentView).removeView(playerView);
}
}
return false;
}
return true;
}
private void fixLayout() {
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
}
2016-04-22 15:49:00 +02:00
return fixLayoutInternal();
2013-10-25 17:19:00 +02:00
}
2014-11-11 23:16:17 +01:00
});
}
}
2013-10-25 17:19:00 +02:00
@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
2016-04-22 15:49:00 +02:00
fixLayout();
2013-10-25 17:19:00 +02:00
}
2016-03-16 13:26:32 +01:00
private void createDeleteMessagesAlert(final MessageObject finalSelectedObject) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("messages", finalSelectedObject != null ? 1 : selectedMessagesIds[0].size() + selectedMessagesIds[1].size())));
builder.setTitle(LocaleController.getString("Message", R.string.Message));
final boolean[] checks = new boolean[3];
TLRPC.User user = null;
if (currentChat != null && currentChat.megagroup) {
if (finalSelectedObject != null) {
if (finalSelectedObject.messageOwner.action == null || finalSelectedObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) {
user = MessagesController.getInstance().getUser(finalSelectedObject.messageOwner.from_id);
}
} else {
int from_id = -1;
for (int a = 1; a >= 0; a--) {
int channelId = 0;
for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a].entrySet()) {
MessageObject msg = entry.getValue();
if (from_id == -1) {
from_id = msg.messageOwner.from_id;
}
if (from_id < 0 || from_id != msg.messageOwner.from_id) {
from_id = -2;
break;
}
}
if (from_id == -2) {
break;
}
}
if (from_id != -1) {
user = MessagesController.getInstance().getUser(from_id);
}
}
if (user != null && user.id != UserConfig.getClientUserId()) {
FrameLayout frameLayout = new FrameLayout(getParentActivity());
2016-03-16 13:26:32 +01:00
if (Build.VERSION.SDK_INT >= 21) {
frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0);
}
for (int a = 0; a < 3; a++) {
CheckBoxCell cell = new CheckBoxCell(getParentActivity());
cell.setBackgroundResource(R.drawable.list_selector);
cell.setTag(a);
if (a == 0) {
cell.setText(LocaleController.getString("DeleteBanUser", R.string.DeleteBanUser), "", false, false);
} else if (a == 1) {
cell.setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", false, false);
} else if (a == 2) {
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, ContactsController.formatName(user.first_name, user.last_name)), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 48 * a, 8, 0));
cell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBoxCell cell = (CheckBoxCell) v;
Integer num = (Integer) cell.getTag();
checks[num] = !checks[num];
cell.setChecked(checks[num], true);
}
});
}
builder.setView(frameLayout);
} else {
user = null;
}
}
final TLRPC.User userFinal = user;
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ArrayList<Integer> ids = null;
if (finalSelectedObject != null) {
ids = new ArrayList<>();
ids.add(finalSelectedObject.getId());
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, finalSelectedObject.messageOwner.to_id.channel_id);
} else {
for (int a = 1; a >= 0; a--) {
ids = new ArrayList<>(selectedMessagesIds[a].keySet());
ArrayList<Long> random_ids = null;
int channelId = 0;
if (!ids.isEmpty()) {
MessageObject msg = selectedMessagesIds[a].get(ids.get(0));
if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) {
channelId = msg.messageOwner.to_id.channel_id;
}
}
if (currentEncryptedChat != null) {
random_ids = new ArrayList<>();
for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a].entrySet()) {
MessageObject msg = entry.getValue();
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
random_ids.add(msg.messageOwner.random_id);
}
}
}
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId);
}
actionBar.hideActionMode();
updatePinnedMessageView(true);
}
if (userFinal != null) {
if (checks[0]) {
MessagesController.getInstance().deleteUserFromChat(currentChat.id, userFinal, info);
}
if (checks[1]) {
TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam();
req.channel = MessagesController.getInputChannel(currentChat);
req.user_id = MessagesController.getInputUser(userFinal);
req.id = ids;
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
}
});
}
if (checks[2]) {
MessagesController.getInstance().deleteUserChannelHistory(currentChat, userFinal, 0);
}
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
2015-09-24 22:52:02 +02:00
private 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;
}
MessageObject message = null;
2016-05-25 23:49:47 +02:00
if (v instanceof ChatMessageCell) {
message = ((ChatMessageCell) v).getMessageObject();
2014-10-15 20:43:52 +02:00
} else if (v instanceof ChatActionCell) {
message = ((ChatActionCell) v).getMessageObject();
}
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);
2016-03-16 13:26:32 +01:00
if (single && message.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
scrollToMessageId(message.messageOwner.reply_to_msg_id, 0, true, 0);
return;
}
2014-06-13 17:03:06 +02:00
selectedObject = null;
forwaringMessage = null;
2015-11-26 22:04:02 +01:00
for (int a = 1; a >= 0; a--) {
selectedMessagesCanCopyIds[a].clear();
selectedMessagesIds[a].clear();
}
2015-09-24 22:52:02 +02:00
cantDeleteMessagesCount = 0;
2014-11-17 23:04:31 +01:00
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
2014-06-13 17:03:06 +02:00
2015-09-24 22:52:02 +02:00
boolean allowChatActions = true;
2016-03-16 13:26:32 +01:00
boolean allowPin = message.getDialogId() != mergeDialogId && message.getId() > 0 && ChatObject.isChannel(currentChat) && currentChat.megagroup && (currentChat.creator || currentChat.editor) && (message.messageOwner.action == null || message.messageOwner.action instanceof TLRPC.TL_messageActionEmpty);
boolean allowUnpin = message.getDialogId() != mergeDialogId && info != null && info.pinned_msg_id == message.getId() && (currentChat.creator || currentChat.editor);
2016-05-25 23:49:47 +02:00
boolean allowEdit = message.canEditMessage(currentChat) && !chatActivityEnterView.hasAudioToSend() && message.getDialogId() != mergeDialogId;
2016-03-06 02:49:31 +01:00
if (currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 46 || type == 1 && message.getDialogId() == mergeDialogId || currentEncryptedChat == null && message.getId() < 0 || isBroadcast || currentChat != null && (ChatObject.isNotInChat(currentChat) || ChatObject.isChannel(currentChat) && !currentChat.creator && !currentChat.editor && !currentChat.megagroup)) {
2015-09-24 22:52:02 +02:00
allowChatActions = false;
}
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;
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2013-10-25 17:19:00 +02:00
2015-09-24 22:52:02 +02:00
ArrayList<CharSequence> items = new ArrayList<>();
final ArrayList<Integer> options = new ArrayList<>();
2013-10-25 17:19:00 +02:00
2014-07-15 21:57:09 +02:00
if (type == 0) {
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("Retry", R.string.Retry));
options.add(0);
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
2014-07-15 21:57:09 +02:00
} else if (type == 1) {
if (currentChat != null && !isBroadcast) {
2015-09-24 22:52:02 +02:00
if (allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(8);
}
2016-03-16 13:26:32 +01:00
if (allowUnpin) {
items.add(LocaleController.getString("UnpinMessage", R.string.UnpinMessage));
options.add(14);
} else if (allowPin) {
items.add(LocaleController.getString("PinMessage", R.string.PinMessage));
options.add(13);
}
if (allowEdit) {
2016-03-06 02:49:31 +01:00
items.add(LocaleController.getString("Edit", R.string.Edit));
options.add(12);
}
2015-09-24 22:52:02 +02:00
if (message.canDeleteMessage(currentChat)) {
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
}
} else {
2016-10-11 13:57:01 +02:00
if (single && selectedObject.getId() > 0 && allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(8);
}
2015-09-24 22:52:02 +02:00
if (message.canDeleteMessage(currentChat)) {
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
}
}
2015-05-21 23:27:27 +02:00
} else if (type == 20) {
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("Retry", R.string.Retry));
options.add(0);
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(3);
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
2013-10-25 17:19:00 +02:00
} else {
2014-07-15 21:57:09 +02:00
if (currentEncryptedChat == null) {
2015-09-24 22:52:02 +02:00
if (allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(8);
}
2016-03-16 13:26:32 +01:00
if (selectedObject.type == 0 || selectedObject.caption != null) {
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(3);
2016-03-16 13:26:32 +01:00
}
if (type == 3) {
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && MessageObject.isNewGifDocument(selectedObject.messageOwner.media.webpage.document)) {
items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
options.add(11);
}
2015-09-24 22:52:02 +02:00
} else if (type == 4) {
2016-03-06 02:49:31 +01:00
if (selectedObject.isVideo()) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
2016-04-22 15:49:00 +02:00
} else if (selectedObject.isMusic()) {
items.add(LocaleController.getString("SaveToMusic", R.string.SaveToMusic));
options.add(10);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
} else if (selectedObject.getDocument() != null) {
if (MessageObject.isNewGifDocument(selectedObject.getDocument())) {
items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
options.add(11);
}
2016-04-22 15:49:00 +02:00
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
2015-09-24 22:52:02 +02:00
options.add(10);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
2016-03-06 02:49:31 +01:00
options.add(6);
2015-09-24 22:52:02 +02:00
} else {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
}
2015-09-24 22:52:02 +02:00
} else if (type == 5) {
items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile));
options.add(5);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
2016-03-06 02:49:31 +01:00
options.add(6);
2015-09-24 22:52:02 +02:00
} else if (type == 6) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(7);
2016-04-22 15:49:00 +02:00
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
2015-09-24 22:52:02 +02:00
options.add(10);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
} else if (type == 7) {
2016-10-11 13:57:01 +02:00
if (selectedObject.isMask()) {
items.add(LocaleController.getString("AddToMasks", R.string.AddToMasks));
} else {
items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
}
2015-09-24 22:52:02 +02:00
options.add(9);
2016-04-22 15:49:00 +02:00
} else if (type == 8) {
TLRPC.User user = MessagesController.getInstance().getUser(selectedObject.messageOwner.media.user_id);
if (user != null && user.id != UserConfig.getClientUserId() && ContactsController.getInstance().contactsDict.get(user.id) == null) {
items.add(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
options.add(15);
}
if (selectedObject.messageOwner.media.phone_number != null || selectedObject.messageOwner.media.phone_number.length() != 0) {
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(16);
items.add(LocaleController.getString("Call", R.string.Call));
options.add(17);
}
2015-09-24 22:52:02 +02:00
}
items.add(LocaleController.getString("Forward", R.string.Forward));
options.add(2);
2016-03-16 13:26:32 +01:00
if (allowUnpin) {
items.add(LocaleController.getString("UnpinMessage", R.string.UnpinMessage));
options.add(14);
} else if (allowPin) {
items.add(LocaleController.getString("PinMessage", R.string.PinMessage));
options.add(13);
}
if (allowEdit) {
2016-03-06 02:49:31 +01:00
items.add(LocaleController.getString("Edit", R.string.Edit));
options.add(12);
}
2015-09-24 22:52:02 +02:00
if (message.canDeleteMessage(currentChat)) {
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
2014-07-15 21:57:09 +02:00
}
} else {
2016-03-06 02:49:31 +01:00
if (allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(8);
}
2016-03-16 13:26:32 +01:00
if (selectedObject.type == 0 || selectedObject.caption != null) {
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(3);
2016-03-16 13:26:32 +01:00
}
if (type == 4) {
2016-03-06 02:49:31 +01:00
if (selectedObject.isVideo()) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
2016-04-22 15:49:00 +02:00
} else if (selectedObject.isMusic()) {
items.add(LocaleController.getString("SaveToMusic", R.string.SaveToMusic));
options.add(10);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
} else if (!selectedObject.isVideo() && selectedObject.getDocument() != null) {
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
2015-09-24 22:52:02 +02:00
options.add(10);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
2016-03-06 02:49:31 +01:00
options.add(6);
} else {
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
}
2014-07-15 21:57:09 +02:00
} else if (type == 5) {
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile));
options.add(5);
2015-05-21 23:27:27 +02:00
} else if (type == 7) {
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
options.add(9);
}
2015-09-24 22:52:02 +02:00
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
2013-10-25 17:19:00 +02:00
}
}
2015-09-24 22:52:02 +02:00
if (options.isEmpty()) {
return;
}
final CharSequence[] finalItems = items.toArray(new CharSequence[items.size()]);
builder.setItems(finalItems, new DialogInterface.OnClickListener() {
2013-10-25 17:19:00 +02:00
@Override
public void onClick(DialogInterface dialogInterface, int i) {
2015-09-24 22:52:02 +02:00
if (selectedObject == null || i < 0 || i >= options.size()) {
2014-06-13 17:03:06 +02:00
return;
}
2015-09-24 22:52:02 +02:00
processSelectedOption(options.get(i));
2013-10-25 17:19:00 +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;
}
2016-03-06 02:49:31 +01:00
final ActionBarMenu actionMode = actionBar.createActionMode();
View item = actionMode.getItem(forward);
if (item != null) {
item.setVisibility(View.VISIBLE);
}
item = actionMode.getItem(delete);
if (item != null) {
item.setVisibility(View.VISIBLE);
}
2016-05-25 23:49:47 +02:00
if (editDoneItem != null) {
editDoneItem.setVisibility(View.GONE);
2016-03-06 02:49:31 +01:00
}
2014-11-11 23:16:17 +01:00
actionBar.showActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
2014-11-17 03:44:57 +01:00
AnimatorSet animatorSet = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
for (int a = 0; a < actionModeViews.size(); a++) {
View view = actionModeViews.get(a);
AndroidUtilities.clearDrawableAnimation(view);
animators.add(ObjectAnimator.ofFloat(view, "scaleY", 0.1f, 1.0f));
2014-10-07 22:14:27 +02:00
}
animatorSet.playTogether(animators);
animatorSet.setDuration(250);
animatorSet.start();
2014-11-17 03:44:57 +01:00
2013-10-25 17:19:00 +02:00
addToSelectedMessages(message);
2015-10-29 18:10:07 +01:00
selectedMessagesCountTextView.setNumber(1, false);
2013-10-25 17:19:00 +02:00
updateVisibleRows();
}
2016-05-25 23:49:47 +02:00
private void showEditDoneProgress(final boolean show, boolean animated) {
if (editDoneItemAnimation != null) {
editDoneItemAnimation.cancel();
}
if (!animated) {
if (show) {
editDoneItem.getImageView().setScaleX(0.1f);
editDoneItem.getImageView().setScaleY(0.1f);
editDoneItem.getImageView().setAlpha(0.0f);
editDoneItemProgress.setScaleX(1.0f);
editDoneItemProgress.setScaleY(1.0f);
editDoneItemProgress.setAlpha(1.0f);
2016-05-25 23:49:47 +02:00
editDoneItem.getImageView().setVisibility(View.INVISIBLE);
editDoneItemProgress.setVisibility(View.VISIBLE);
editDoneItem.setEnabled(false);
} else {
editDoneItemProgress.setScaleX(0.1f);
editDoneItemProgress.setScaleY(0.1f);
editDoneItemProgress.setAlpha(0.0f);
editDoneItem.getImageView().setScaleX(1.0f);
editDoneItem.getImageView().setScaleY(1.0f);
editDoneItem.getImageView().setAlpha(1.0f);
2016-05-25 23:49:47 +02:00
editDoneItem.getImageView().setVisibility(View.VISIBLE);
editDoneItemProgress.setVisibility(View.INVISIBLE);
editDoneItem.setEnabled(true);
}
} else {
editDoneItemAnimation = new AnimatorSet();
2016-05-25 23:49:47 +02:00
if (show) {
editDoneItemProgress.setVisibility(View.VISIBLE);
editDoneItem.setEnabled(false);
editDoneItemAnimation.playTogether(
ObjectAnimator.ofFloat(editDoneItem.getImageView(), "scaleX", 0.1f),
ObjectAnimator.ofFloat(editDoneItem.getImageView(), "scaleY", 0.1f),
ObjectAnimator.ofFloat(editDoneItem.getImageView(), "alpha", 0.0f),
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleX", 1.0f),
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleY", 1.0f),
ObjectAnimator.ofFloat(editDoneItemProgress, "alpha", 1.0f));
2016-05-25 23:49:47 +02:00
} else {
editDoneItem.getImageView().setVisibility(View.VISIBLE);
editDoneItem.setEnabled(true);
editDoneItemAnimation.playTogether(
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleX", 0.1f),
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleY", 0.1f),
ObjectAnimator.ofFloat(editDoneItemProgress, "alpha", 0.0f),
ObjectAnimator.ofFloat(editDoneItem.getImageView(), "scaleX", 1.0f),
ObjectAnimator.ofFloat(editDoneItem.getImageView(), "scaleY", 1.0f),
ObjectAnimator.ofFloat(editDoneItem.getImageView(), "alpha", 1.0f));
2016-05-25 23:49:47 +02:00
}
editDoneItemAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
2016-05-25 23:49:47 +02:00
if (editDoneItemAnimation != null && editDoneItemAnimation.equals(animation)) {
if (!show) {
editDoneItemProgress.setVisibility(View.INVISIBLE);
} else {
editDoneItem.getImageView().setVisibility(View.INVISIBLE);
}
}
}
@Override
public void onAnimationCancel(Animator animation) {
2016-05-25 23:49:47 +02:00
if (editDoneItemAnimation != null && editDoneItemAnimation.equals(animation)) {
editDoneItemAnimation = null;
}
}
});
editDoneItemAnimation.setDuration(150);
editDoneItemAnimation.start();
}
}
private String getMessageContent(MessageObject messageObject, int previousUid, boolean name) {
String str = "";
if (name) {
if (previousUid != messageObject.messageOwner.from_id) {
if (messageObject.messageOwner.from_id > 0) {
TLRPC.User user = MessagesController.getInstance().getUser(messageObject.messageOwner.from_id);
if (user != null) {
str = ContactsController.formatName(user.first_name, user.last_name) + ":\n";
}
} else if (messageObject.messageOwner.from_id < 0) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(-messageObject.messageOwner.from_id);
if (chat != null) {
str = chat.title + ":\n";
}
}
}
}
if (messageObject.type == 0 && messageObject.messageOwner.message != null) {
str += messageObject.messageOwner.message;
} else if (messageObject.messageOwner.media != null && messageObject.messageOwner.media.caption != null) {
str += messageObject.messageOwner.media.caption;
} else {
str += messageObject.messageText;
}
return str;
}
2013-10-25 17:19:00 +02:00
private void processSelectedOption(int option) {
2014-07-15 21:57:09 +02:00
if (selectedObject == null) {
return;
}
2016-04-22 15:49:00 +02:00
switch (option) {
case 0: {
if (SendMessagesHelper.getInstance().retrySendMessage(selectedObject, false)) {
moveScrollToLastMessage();
2014-10-30 22:27:41 +01:00
}
2016-04-22 15:49:00 +02:00
break;
2014-10-30 22:27:41 +01:00
}
2016-04-22 15:49:00 +02:00
case 1: {
if (getParentActivity() == null) {
2016-03-06 02:49:31 +01:00
selectedObject = null;
2015-10-29 18:10:07 +01:00
return;
}
2016-04-22 15:49:00 +02:00
createDeleteMessagesAlert(selectedObject);
break;
2014-07-15 21:57:09 +02:00
}
2016-04-22 15:49:00 +02:00
case 2: {
forwaringMessage = selectedObject;
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 1);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate(this);
presentFragment(fragment);
break;
2014-07-15 21:57:09 +02:00
}
2016-04-22 15:49:00 +02:00
case 3: {
2016-05-25 23:49:47 +02:00
AndroidUtilities.addToClipboard(getMessageContent(selectedObject, 0, false));
2016-04-22 15:49:00 +02:00
break;
2014-07-15 21:57:09 +02:00
}
2016-04-22 15:49:00 +02:00
case 4: {
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();
}
if (selectedObject.type == 3 || selectedObject.type == 1) {
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
2016-03-06 02:49:31 +01:00
selectedObject = null;
2014-07-15 21:57:09 +02:00
return;
}
2016-04-22 15:49:00 +02:00
MediaController.saveFile(path, getParentActivity(), selectedObject.type == 3 ? 1 : 0, null, null);
2013-10-25 17:19:00 +02:00
}
2016-04-22 15:49:00 +02:00
break;
2013-10-25 17:19:00 +02:00
}
2016-04-22 15:49:00 +02:00
case 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;
}
}
2016-04-22 15:49:00 +02:00
if (locFile == null) {
File f = FileLoader.getPathToMessage(selectedObject.messageOwner);
if (f.exists()) {
locFile = f;
}
}
if (locFile != null) {
if (LocaleController.getInstance().applyLanguageFile(locFile)) {
presentFragment(new LanguageSelectActivity());
} else {
if (getParentActivity() == null) {
selectedObject = 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);
showDialog(builder.create());
}
}
2016-04-22 15:49:00 +02:00
break;
}
2016-04-22 15:49:00 +02:00
case 6: {
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();
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(selectedObject.getDocument().mime_type);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
break;
2016-03-06 02:49:31 +01:00
}
2016-04-22 15:49:00 +02:00
case 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();
}
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
selectedObject = null;
return;
}
MediaController.saveFile(path, getParentActivity(), 0, null, null);
break;
2016-03-06 02:49:31 +01:00
}
2016-04-22 15:49:00 +02:00
case 8: {
showReplyPanel(true, selectedObject, null, null, false, true);
break;
2015-10-29 18:10:07 +01:00
}
2016-04-22 15:49:00 +02:00
case 9: {
2016-10-11 13:57:01 +02:00
showDialog(new StickersAlert(getParentActivity(), this, selectedObject.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE ? chatActivityEnterView : null));
2016-04-22 15:49:00 +02:00
break;
}
2016-04-22 15:49:00 +02:00
case 10: {
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
getParentActivity().requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
selectedObject = null;
return;
}
2016-04-22 15:49:00 +02:00
String fileName = FileLoader.getDocumentFileName(selectedObject.getDocument());
if (fileName == null || fileName.length() == 0) {
fileName = selectedObject.getFileName();
}
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();
}
MediaController.saveFile(path, getParentActivity(), selectedObject.isMusic() ? 3 : 2, fileName, selectedObject.getDocument() != null ? selectedObject.getDocument().mime_type : "");
break;
2015-05-21 23:27:27 +02:00
}
2016-04-22 15:49:00 +02:00
case 11: {
2016-10-11 13:57:01 +02:00
TLRPC.Document document = selectedObject.getDocument();
MessagesController.getInstance().saveGif(document);
2016-04-22 15:49:00 +02:00
showGifHint();
2016-10-11 13:57:01 +02:00
chatActivityEnterView.addRecentGif(document);
2016-04-22 15:49:00 +02:00
break;
2016-03-06 02:49:31 +01:00
}
2016-04-22 15:49:00 +02:00
case 12: {
if (getParentActivity() == null) {
selectedObject = null;
return;
}
if (searchItem != null && actionBar.isSearchFieldVisible()) {
actionBar.closeSearchField();
chatActivityEnterView.setFieldFocused();
}
2016-05-25 23:49:47 +02:00
mentionsAdapter.setNeedBotContext(false);
chatListView.setOnItemLongClickListener(null);
chatListView.setOnItemClickListener(null);
chatListView.setClickable(false);
chatListView.setLongClickable(false);
chatActivityEnterView.setEditingMessageObject(selectedObject, !selectedObject.isMediaEmpty());
if (chatActivityEnterView.isEditingCaption()) {
mentionsAdapter.setAllowNewMentions(false);
}
actionModeTitleContainer.setVisibility(View.VISIBLE);
selectedMessagesCountTextView.setVisibility(View.GONE);
checkEditTimer();
chatActivityEnterView.setAllowStickersAndGifs(false, false);
final ActionBarMenu actionMode = actionBar.createActionMode();
actionMode.getItem(reply).setVisibility(View.GONE);
actionMode.getItem(copy).setVisibility(View.GONE);
actionMode.getItem(forward).setVisibility(View.GONE);
actionMode.getItem(delete).setVisibility(View.GONE);
if (editDoneItemAnimation != null) {
editDoneItemAnimation.cancel();
editDoneItemAnimation = null;
}
editDoneItem.setVisibility(View.VISIBLE);
showEditDoneProgress(true, false);
actionBar.showActionMode();
updatePinnedMessageView(true);
updateVisibleRows();
2016-03-06 02:49:31 +01:00
2016-04-22 15:49:00 +02:00
TLRPC.TL_messages_getMessageEditData req = new TLRPC.TL_messages_getMessageEditData();
req.peer = MessagesController.getInputPeer((int) dialog_id);
req.id = selectedObject.getId();
2016-05-25 23:49:47 +02:00
editingMessageObjectReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
2016-04-22 15:49:00 +02:00
@Override
public void run(final TLObject response, TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
2016-05-25 23:49:47 +02:00
editingMessageObjectReqId = 0;
if (response == null) {
2016-04-22 15:49:00 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("EditMessageError", R.string.EditMessageError));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
2016-05-25 23:49:47 +02:00
if (chatActivityEnterView != null) {
chatActivityEnterView.setEditingMessageObject(null, false);
}
} else {
showEditDoneProgress(false, true);
2016-03-06 02:49:31 +01:00
}
}
2016-04-22 15:49:00 +02:00
});
}
});
break;
2016-03-06 02:49:31 +01:00
}
2016-04-22 15:49:00 +02:00
case 13: {
final int mid = selectedObject.getId();
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("PinMessageAlert", R.string.PinMessageAlert));
2016-03-16 13:26:32 +01:00
2016-04-22 15:49:00 +02:00
final boolean[] checks = new boolean[]{true};
FrameLayout frameLayout = new FrameLayout(getParentActivity());
if (Build.VERSION.SDK_INT >= 21) {
frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0);
}
CheckBoxCell cell = new CheckBoxCell(getParentActivity());
cell.setBackgroundResource(R.drawable.list_selector);
cell.setText(LocaleController.getString("PinNotify", R.string.PinNotify), "", true, false);
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0));
cell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBoxCell cell = (CheckBoxCell) v;
checks[0] = !checks[0];
cell.setChecked(checks[0], true);
}
});
builder.setView(frameLayout);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MessagesController.getInstance().pinChannelMessage(currentChat, mid, checks[0]);
}
});
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
break;
2016-03-16 13:26:32 +01:00
}
2016-04-22 15:49:00 +02:00
case 14: {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("UnpinMessageAlert", R.string.UnpinMessageAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MessagesController.getInstance().pinChannelMessage(currentChat, 0, false);
}
});
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
break;
2016-03-16 13:26:32 +01:00
}
2016-04-22 15:49:00 +02:00
case 15: {
Bundle args = new Bundle();
args.putInt("user_id", selectedObject.messageOwner.media.user_id);
args.putString("phone", selectedObject.messageOwner.media.phone_number);
args.putBoolean("addContact", true);
presentFragment(new ContactAddActivity(args));
break;
}
case 16: {
2016-05-25 23:49:47 +02:00
AndroidUtilities.addToClipboard(selectedObject.messageOwner.media.phone_number);
2016-04-22 15:49:00 +02:00
break;
}
case 17: {
try {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + selectedObject.messageOwner.media.phone_number));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
2016-03-16 13:26:32 +01:00
}
2016-04-22 15:49:00 +02:00
break;
}
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) {
2015-11-26 22:04:02 +01:00
if (dialog_id != 0 && (forwaringMessage != null || !selectedMessagesIds[0].isEmpty() || !selectedMessagesIds[1].isEmpty())) {
ArrayList<MessageObject> fmessages = new ArrayList<>();
if (forwaringMessage != null) {
fmessages.add(forwaringMessage);
forwaringMessage = null;
} else {
2015-11-26 22:04:02 +01:00
for (int a = 1; a >= 0; a--) {
ArrayList<Integer> ids = new ArrayList<>(selectedMessagesIds[a].keySet());
Collections.sort(ids);
for (int b = 0; b < ids.size(); b++) {
Integer id = ids.get(b);
MessageObject message = selectedMessagesIds[a].get(id);
if (message != null && id > 0) {
fmessages.add(message);
}
}
2015-11-26 22:04:02 +01:00
selectedMessagesCanCopyIds[a].clear();
selectedMessagesIds[a].clear();
}
2015-09-24 22:52:02 +02:00
cantDeleteMessagesCount = 0;
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
}
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) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", scrollToTopOnResume);
2013-10-25 17:19:00 +02:00
if (lower_part > 0) {
args.putInt("user_id", lower_part);
2013-10-25 17:19:00 +02:00
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
2013-10-25 17:19:00 +02:00
}
2016-03-16 13:26:32 +01:00
if (!MessagesController.checkCanOpenChat(args, activity)) {
return;
}
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();
2014-11-20 15:45:33 +01:00
}
2015-03-19 10:27:46 +01:00
} else {
activity.finishFragment();
}
2013-10-25 17:19:00 +02:00
} else {
activity.finishFragment();
}
} else {
activity.finishFragment();
moveScrollToLastMessage();
2015-04-09 20:00:14 +02:00
showReplyPanel(true, null, fmessages, null, false, AndroidUtilities.isTablet());
if (AndroidUtilities.isTablet()) {
2014-11-11 23:16:17 +01:00
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
}
updateVisibleRows();
2013-10-25 17:19:00 +02:00
}
}
}
@Override
public boolean onBackPressed() {
2016-10-11 13:57:01 +02:00
if (actionBar != null && actionBar.isActionModeShowed()) {
2015-11-26 22:04:02 +01:00
for (int a = 1; a >= 0; a--) {
selectedMessagesIds[a].clear();
selectedMessagesCanCopyIds[a].clear();
}
2016-05-25 23:49:47 +02:00
chatActivityEnterView.setEditingMessageObject(null, false);
2014-11-11 23:16:17 +01:00
actionBar.hideActionMode();
2016-03-16 13:26:32 +01:00
updatePinnedMessageView(true);
2015-09-24 22:52:02 +02:00
cantDeleteMessagesCount = 0;
updateVisibleRows();
return false;
2016-10-11 13:57:01 +02:00
} else if (chatActivityEnterView != null && 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;
}
private void updateVisibleRows() {
if (chatListView == null) {
return;
}
int count = chatListView.getChildCount();
2016-05-25 23:49:47 +02:00
MessageObject editingMessageObject = chatActivityEnterView != null ? chatActivityEnterView.getEditingMessageObject() : null;
2013-10-25 17:19:00 +02:00
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
2016-05-25 23:49:47 +02:00
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
boolean disableSelection = false;
boolean selected = false;
2014-11-11 23:16:17 +01:00
if (actionBar.isActionModeShowed()) {
2015-11-26 22:04:02 +01:00
MessageObject messageObject = cell.getMessageObject();
2016-05-25 23:49:47 +02:00
if (messageObject == editingMessageObject || selectedMessagesIds[messageObject.getDialogId() == dialog_id ? 0 : 1].containsKey(messageObject.getId())) {
view.setBackgroundColor(Theme.MSG_SELECTED_BACKGROUND_COLOR);
selected = true;
} else {
view.setBackgroundColor(0);
}
disableSelection = true;
} else {
view.setBackgroundColor(0);
}
2014-03-02 10:23:06 +01:00
cell.setMessageObject(cell.getMessageObject());
cell.setCheckPressed(!disableSelection, disableSelection && selected);
cell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && cell.getMessageObject() != null && cell.getMessageObject().getId() == highlightMessageId);
if (searchContainer != null && searchContainer.getVisibility() == View.VISIBLE && MessagesSearchQuery.getLastSearchQuery() != null) {
cell.setHighlightedText(MessagesSearchQuery.getLastSearchQuery());
} else {
cell.setHighlightedText(null);
}
2016-03-16 13:26:32 +01:00
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
cell.setMessageObject(cell.getMessageObject());
}
}
}
2016-05-25 23:49:47 +02:00
private void checkEditTimer() {
if (chatActivityEnterView == null) {
return;
}
MessageObject messageObject = chatActivityEnterView.getEditingMessageObject();
if (messageObject == null) {
return;
}
2016-10-11 13:57:01 +02:00
if (currentUser != null && currentUser.self) {
if (actionModeSubTextView.getVisibility() != View.GONE) {
actionModeSubTextView.setVisibility(View.GONE);
}
return;
}
2016-05-25 23:49:47 +02:00
int dt = MessagesController.getInstance().maxEditTime + 5 * 60 - Math.abs(ConnectionsManager.getInstance().getCurrentTime() - messageObject.messageOwner.date);
if (dt > 0) {
if (dt > 5 * 60) {
if (actionModeSubTextView.getVisibility() != View.GONE) {
actionModeSubTextView.setVisibility(View.GONE);
}
} else {
if (actionModeSubTextView.getVisibility() != View.VISIBLE) {
actionModeSubTextView.setVisibility(View.VISIBLE);
}
actionModeSubTextView.setText(LocaleController.formatString("TimeToEdit", R.string.TimeToEdit, String.format("%d:%02d", dt / 60, dt % 60)));
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
checkEditTimer();
}
}, 1000);
} else {
editDoneItem.setVisibility(View.GONE);
actionModeSubTextView.setText(LocaleController.formatString("TimeToEditExpired", R.string.TimeToEditExpired));
}
}
2016-03-06 02:49:31 +01:00
private ArrayList<MessageObject> createVoiceMessagesPlaylist(MessageObject startMessageObject, boolean playingUnreadMedia) {
ArrayList<MessageObject> messageObjects = new ArrayList<>();
messageObjects.add(startMessageObject);
int messageId = startMessageObject.getId();
if (messageId != 0) {
boolean started = false;
for (int a = messages.size() - 1; a >= 0; a--) {
MessageObject messageObject = messages.get(a);
if ((currentEncryptedChat == null && messageObject.getId() > messageId || currentEncryptedChat != null && messageObject.getId() < messageId) && messageObject.isVoice() && (!playingUnreadMedia || messageObject.isContentUnread() && !messageObject.isOut())) {
messageObjects.add(messageObject);
}
}
}
return messageObjects;
}
private void alertUserOpenError(MessageObject message) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
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);
if (message.type == 3) {
2014-10-21 22:35:16 +02:00
builder.setMessage(LocaleController.getString("NoPlayerInstalled", R.string.NoPlayerInstalled));
} else {
2016-04-22 15:49:00 +02:00
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.getDocument().mime_type));
}
2015-05-21 23:27:27 +02:00
showDialog(builder.create());
}
2015-09-24 22:52:02 +02:00
private void openSearchWithText(String text) {
avatarContainer.setVisibility(View.GONE);
headerItem.setVisibility(View.GONE);
attachItem.setVisibility(View.GONE);
searchItem.setVisibility(View.VISIBLE);
updateSearchButtons(0, 0, 0);
updateBottomOverlay();
2015-09-24 22:52:02 +02:00
openSearchKeyboard = text == null;
searchItem.openSearch(openSearchKeyboard);
if (text != null) {
searchItem.getSearchField().setText(text);
searchItem.getSearchField().setSelection(searchItem.getSearchField().length());
2015-11-26 22:04:02 +01:00
MessagesSearchQuery.searchMessagesInChat(text, dialog_id, mergeDialogId, classGuid, 0);
2015-09-24 22:52:02 +02:00
}
}
@Override
public void updatePhotoAtIndex(int index) {
}
2016-03-16 13:26:32 +01:00
public boolean isSecretChat() {
return currentEncryptedChat != null;
}
2016-04-22 15:49:00 +02:00
public TLRPC.User getCurrentUser() {
return currentUser;
}
public TLRPC.Chat getCurrentChat() {
return currentChat;
}
public TLRPC.EncryptedChat getCurrentEncryptedChat() {
return currentEncryptedChat;
}
public TLRPC.ChatFull getCurrentChatInfo() {
return info;
}
2016-10-11 13:57:01 +02:00
@Override
public boolean allowCaption() {
return true;
}
@Override
public boolean scaleToFill() {
return false;
}
@Override
2014-06-12 03:13:15 +02:00
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
ImageReceiver imageReceiver = null;
View view = chatListView.getChildAt(a);
2016-05-25 23:49:47 +02:00
if (view instanceof ChatMessageCell) {
if (messageObject != null) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject message = cell.getMessageObject();
if (message != null && message.getId() == messageObject.getId()) {
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();
if (message != null) {
if (messageObject != null) {
if (message.getId() == messageObject.getId()) {
imageReceiver = cell.getPhotoImage();
}
} else if (fileLocation != null && message.photoThumbs != null) {
for (int b = 0; b < message.photoThumbs.size(); b++) {
TLRPC.PhotoSize photoSize = message.photoThumbs.get(b);
if (photoSize.location.volume_id == fileLocation.volume_id && photoSize.location.local_id == fileLocation.local_id) {
imageReceiver = cell.getPhotoImage();
break;
}
}
}
}
}
if (imageReceiver != null) {
int coords[] = new int[2];
view.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
2016-10-11 13:57:01 +02:00
object.viewY = coords[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight);
object.parentView = chatListView;
object.imageReceiver = imageReceiver;
2014-11-17 03:44:57 +01:00
object.thumb = imageReceiver.getBitmap();
object.radius = imageReceiver.getRoundRadius();
if (view instanceof ChatActionCell && currentChat != null) {
object.dialogId = -currentChat.id;
}
2016-03-16 13:26:32 +01:00
if (pinnedMessageView != null && pinnedMessageView.getTag() == null || reportSpamView != null && reportSpamView.getTag() == null) {
object.clipTopAddition = AndroidUtilities.dp(48);
}
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-10-29 18:10:07 +01:00
public boolean cancelButtonPressed() {
return true;
2015-04-09 20:00:14 +02:00
}
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
2016-10-11 13:57:01 +02:00
public void sendMedia(MediaController.PhotoEntry photoEntry, boolean mutedVideo) {
if (photoEntry.isVideo) {
VideoEditedInfo videoEditedInfo = null;
long size = 0;
if (mutedVideo) {
videoEditedInfo = new VideoEditedInfo();
videoEditedInfo.bitrate = -1;
videoEditedInfo.originalPath = photoEntry.path;
videoEditedInfo.startTime = videoEditedInfo.endTime = -1;
size = new File(photoEntry.path).length();
}
SendMessagesHelper.prepareSendingVideo(photoEntry.path, size, 0, 0, 0, videoEditedInfo, dialog_id, replyingMessageObject, photoEntry.caption != null ? photoEntry.caption.toString() : null);
} else {
if (photoEntry.imagePath != null) {
SendMessagesHelper.prepareSendingPhoto(photoEntry.imagePath, null, dialog_id, replyingMessageObject, photoEntry.caption, photoEntry.stickers);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
} else if (photoEntry.path != null) {
SendMessagesHelper.prepareSendingPhoto(photoEntry.path, null, dialog_id, replyingMessageObject, photoEntry.caption, photoEntry.stickers);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id, true);
}
2016-05-25 23:49:47 +02:00
}
}
2016-10-11 13:57:01 +02:00
public void showOpenGameAlert(final TLRPC.TL_game game, final MessageObject messageObject, final String urlStr, boolean ask, final int uid) {
TLRPC.User user = MessagesController.getInstance().getUser(uid);
if (ask) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
String name;
if (user != null) {
name = ContactsController.formatName(user.first_name, user.last_name);
} else {
name = "";
}
builder.setMessage(LocaleController.formatString("BotPermissionGameAlert", R.string.BotPermissionGameAlert, name));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
showOpenGameAlert(game, messageObject, urlStr, false, uid);
ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE).edit().putBoolean("askgame_" + uid, false).commit();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else {
if (Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet() && WebviewActivity.supportWebview()) {
if (parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 1) == this) {
presentFragment(new WebviewActivity(urlStr, user != null && !TextUtils.isEmpty(user.username) ? user.username : "", game.title, game.short_name, messageObject));
}
} else {
WebviewActivity.openGameInBrowser(urlStr, messageObject, getParentActivity(), game.short_name, user != null && user.username != null ? user.username : "");
}
}
}
public void showOpenUrlAlert(final String url, boolean ask) {
if (Browser.isInternalUrl(url) || !ask) {
2016-04-22 15:49:00 +02:00
Browser.openUrl(getParentActivity(), url, inlineReturn == 0);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
2016-10-11 13:57:01 +02:00
builder.setMessage(LocaleController.formatString("OpenUrlAlert", R.string.OpenUrlAlert, url));
2016-04-22 15:49:00 +02:00
builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Browser.openUrl(getParentActivity(), url, inlineReturn == 0);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
}
2016-05-25 23:49:47 +02:00
private void removeMessageObject(MessageObject messageObject) {
int index = messages.indexOf(messageObject);
if (index == -1) {
return;
}
messages.remove(index);
if (chatAdapter != null) {
chatAdapter.notifyItemRemoved(chatAdapter.messagesStartRow + messages.size() - index - 1);
}
}
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;
2015-11-26 22:04:02 +01:00
private int botInfoRow = -1;
2015-06-29 19:12:11 +02:00
private int loadingUpRow;
private int loadingDownRow;
private int messagesStartRow;
private int messagesEndRow;
2013-10-25 17:19:00 +02:00
public ChatActivityAdapter(Context context) {
2013-10-25 17:19:00 +02:00
mContext = context;
2015-11-26 22:04:02 +01:00
isBot = currentUser != null && currentUser.bot;
2015-06-29 19:12:11 +02:00
}
public void updateRows() {
rowCount = 0;
2015-11-26 22:04:02 +01:00
if (currentUser != null && currentUser.bot) {
2015-06-29 19:12:11 +02:00
botInfoRow = rowCount++;
} else {
botInfoRow = -1;
}
if (!messages.isEmpty()) {
2015-11-26 22:04:02 +01:00
if (!endReached[0] || mergeDialogId != 0 && !endReached[1]) {
2015-06-29 19:12:11 +02:00
loadingUpRow = rowCount++;
} else {
loadingUpRow = -1;
}
messagesStartRow = rowCount;
rowCount += messages.size();
messagesEndRow = rowCount;
2015-11-26 22:04:02 +01:00
if (!forwardEndReached[0] || mergeDialogId != 0 && !forwardEndReached[1]) {
2015-06-29 19:12:11 +02:00
loadingDownRow = rowCount++;
} else {
loadingDownRow = -1;
}
} else {
loadingUpRow = -1;
loadingDownRow = -1;
messagesStartRow = -1;
messagesEndRow = -1;
}
2013-10-25 17:19:00 +02:00
}
private class Holder extends RecyclerView.ViewHolder {
2013-10-25 17:19:00 +02:00
public Holder(View itemView) {
super(itemView);
}
2013-10-25 17:19:00 +02:00
}
@Override
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
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 {
view = new ChatMessageCell(mContext);
2015-04-09 20:00:14 +02:00
}
2016-04-22 15:49:00 +02:00
ChatMessageCell chatMessageCell = (ChatMessageCell) view;
2016-05-25 23:49:47 +02:00
chatMessageCell.setDelegate(new ChatMessageCell.ChatMessageCellDelegate() {
2015-11-26 22:04:02 +01:00
@Override
2016-05-25 23:49:47 +02:00
public void didPressedShare(ChatMessageCell cell) {
2015-11-26 22:04:02 +01:00
if (getParentActivity() == null) {
return;
}
if (chatActivityEnterView != null) {
chatActivityEnterView.closeKeyboard();
}
2016-10-11 13:57:01 +02:00
showDialog(new ShareAlert(mContext, cell.getMessageObject(), null, ChatObject.isChannel(currentChat) && !currentChat.megagroup && currentChat.username != null && currentChat.username.length() > 0, null));
2016-04-22 15:49:00 +02:00
}
@Override
public boolean needPlayAudio(MessageObject messageObject) {
if (messageObject.isVoice()) {
boolean result = MediaController.getInstance().playAudio(messageObject);
MediaController.getInstance().setVoiceMessagesPlaylist(result ? createVoiceMessagesPlaylist(messageObject, false) : null, false);
return result;
} else if (messageObject.isMusic()) {
return MediaController.getInstance().setPlaylist(messages, messageObject);
}
return false;
2015-11-26 22:04:02 +01:00
}
2015-09-24 22:52:02 +02:00
@Override
2016-05-25 23:49:47 +02:00
public void didPressedChannelAvatar(ChatMessageCell cell, TLRPC.Chat chat, int postId) {
2015-09-24 22:52:02 +02:00
if (actionBar.isActionModeShowed()) {
processRowSelect(cell);
return;
}
if (chat != null && chat != currentChat) {
Bundle args = new Bundle();
args.putInt("chat_id", chat.id);
2016-03-06 02:49:31 +01:00
if (postId != 0) {
args.putInt("message_id", postId);
}
2016-03-16 13:26:32 +01:00
if (MessagesController.checkCanOpenChat(args, ChatActivity.this)) {
presentFragment(new ChatActivity(args), true);
}
2015-09-24 22:52:02 +02:00
}
}
2016-03-16 13:26:32 +01:00
@Override
2016-05-25 23:49:47 +02:00
public void didPressedOther(ChatMessageCell cell) {
2016-03-16 13:26:32 +01:00
createMenu(cell, true);
}
@Override
2016-05-25 23:49:47 +02:00
public void didPressedUserAvatar(ChatMessageCell cell, TLRPC.User user) {
if (actionBar.isActionModeShowed()) {
processRowSelect(cell);
return;
}
if (user != null && user.id != UserConfig.getClientUserId()) {
Bundle args = new Bundle();
args.putInt("user_id", user.id);
2015-10-29 18:10:07 +01:00
ProfileActivity fragment = new ProfileActivity(args);
fragment.setPlayProfileAnimation(currentUser != null && currentUser.id == user.id);
presentFragment(fragment);
}
}
2016-04-22 15:49:00 +02:00
@Override
2016-05-25 23:49:47 +02:00
public void didPressedBotButton(ChatMessageCell cell, TLRPC.KeyboardButton button) {
2016-10-11 13:57:01 +02:00
if (getParentActivity() == null || bottomOverlayChat.getVisibility() == View.VISIBLE &&
!(button instanceof TLRPC.TL_keyboardButtonSwitchInline) && !(button instanceof TLRPC.TL_keyboardButtonCallback) &&
!(button instanceof TLRPC.TL_keyboardButtonGame) && !(button instanceof TLRPC.TL_keyboardButtonUrl)) {
2016-04-22 15:49:00 +02:00
return;
}
chatActivityEnterView.didPressedBotButton(button, cell.getMessageObject(), cell.getMessageObject());
}
@Override
2016-05-25 23:49:47 +02:00
public void didPressedCancelSendButton(ChatMessageCell cell) {
MessageObject message = cell.getMessageObject();
if (message.messageOwner.send_state != 0) {
SendMessagesHelper.getInstance().cancelSendingMessage(message);
2014-10-15 20:43:52 +02:00
}
}
@Override
2016-05-25 23:49:47 +02:00
public void didLongPressed(ChatMessageCell cell) {
createMenu(cell, false);
}
@Override
public boolean canPerformActions() {
return actionBar != null && !actionBar.isActionModeShowed();
}
@Override
2016-03-16 13:26:32 +01:00
public void didPressedUrl(MessageObject messageObject, final ClickableSpan url, boolean longPress) {
if (url == null) {
return;
}
2016-05-25 23:49:47 +02:00
if (url instanceof URLSpanUserMention) {
TLRPC.User user = MessagesController.getInstance().getUser(Utilities.parseInt(((URLSpanUserMention) url).getURL()));
if (user != null) {
2016-10-11 13:57:01 +02:00
MessagesController.openChatOrProfileWith(user, null, ChatActivity.this, 0, false);
2016-05-25 23:49:47 +02:00
}
} else if (url instanceof URLSpanNoUnderline) {
2015-09-02 00:14:21 +02:00
String str = ((URLSpanNoUnderline) url).getURL();
if (str.startsWith("@")) {
MessagesController.openByUserName(str.substring(1), ChatActivity.this, 0);
} else if (str.startsWith("#")) {
2015-09-24 22:52:02 +02:00
if (ChatObject.isChannel(currentChat)) {
openSearchWithText(str);
} else {
DialogsActivity fragment = new DialogsActivity(null);
fragment.setSearchString(str);
presentFragment(fragment);
}
2015-09-02 00:14:21 +02:00
} else if (str.startsWith("/")) {
2015-10-29 18:10:07 +01:00
if (URLSpanBotCommand.enabled) {
2015-11-26 22:04:02 +01:00
chatActivityEnterView.setCommand(messageObject, str, longPress, currentChat != null && currentChat.megagroup);
2015-10-29 18:10:07 +01:00
}
2015-09-02 00:14:21 +02:00
}
2016-03-06 02:49:31 +01:00
} else {
final String urlFinal = ((URLSpan) url).getURL();
if (longPress) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
builder.setTitle(urlFinal);
builder.setItems(new CharSequence[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, final int which) {
if (which == 0) {
2016-04-22 15:49:00 +02:00
Browser.openUrl(getParentActivity(), urlFinal, inlineReturn == 0);
2016-03-06 02:49:31 +01:00
} else if (which == 1) {
2016-10-11 13:57:01 +02:00
String url = urlFinal;
if (url.startsWith("mailto:")) {
url = url.substring(7);
} else if (url.startsWith("tel:")) {
url = url.substring(4);
}
AndroidUtilities.addToClipboard(url);
2016-03-06 02:49:31 +01:00
}
2015-09-02 00:14:21 +02:00
}
2016-03-06 02:49:31 +01:00
});
showDialog(builder.create());
} else {
2016-10-11 13:57:01 +02:00
if (((URLSpan) url).getURL().contains(""))
2016-03-06 02:49:31 +01:00
if (url instanceof URLSpanReplacement) {
2016-10-11 13:57:01 +02:00
showOpenUrlAlert(((URLSpanReplacement) url).getURL(), true);
2016-03-06 02:49:31 +01:00
} else if (url instanceof URLSpan) {
2016-04-22 15:49:00 +02:00
Browser.openUrl(getParentActivity(), urlFinal, inlineReturn == 0);
2016-03-06 02:49:31 +01:00
} else {
url.onClick(fragmentView);
2015-09-02 00:14:21 +02:00
}
2016-03-06 02:49:31 +01:00
}
}
}
2015-05-21 23:27:27 +02:00
@Override
2016-04-22 15:49:00 +02:00
public void needOpenWebView(String url, String title, String description, String originalUrl, int w, int h) {
2015-05-21 23:27:27 +02:00
BottomSheet.Builder builder = new BottomSheet.Builder(mContext);
2016-04-22 15:49:00 +02:00
builder.setCustomView(new WebFrameLayout(mContext, builder.create(), title, description, 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());
}
@Override
2016-05-25 23:49:47 +02:00
public void didPressedReplyMessage(ChatMessageCell cell, int id) {
2015-09-24 22:52:02 +02:00
MessageObject messageObject = cell.getMessageObject();
2015-11-26 22:04:02 +01:00
scrollToMessageId(id, messageObject.getId(), true, messageObject.getDialogId() == mergeDialogId ? 1 : 0);
}
2015-08-13 11:23:31 +02:00
@Override
2016-05-25 23:49:47 +02:00
public void didPressedViaBot(ChatMessageCell cell, String username) {
2016-03-06 02:49:31 +01:00
if (bottomOverlayChat != null && bottomOverlayChat.getVisibility() == View.VISIBLE || bottomOverlay != null && bottomOverlay.getVisibility() == View.VISIBLE) {
return;
}
if (chatActivityEnterView != null && username != null && username.length() > 0) {
chatActivityEnterView.setFieldText("@" + username + " ");
chatActivityEnterView.openKeyboard();
}
}
2015-08-13 11:23:31 +02:00
@Override
2016-05-25 23:49:47 +02:00
public void didPressedImage(ChatMessageCell cell) {
2015-08-13 11:23:31 +02:00
MessageObject message = cell.getMessageObject();
if (message.isSendError()) {
createMenu(cell, false);
return;
} else if (message.isSending()) {
return;
}
2016-04-22 15:49:00 +02:00
if (message.type == 13) {
2016-10-11 13:57:01 +02:00
showDialog(new StickersAlert(getParentActivity(), ChatActivity.this, message.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE ? chatActivityEnterView : null));
} else if (Build.VERSION.SDK_INT >= 16 && message.isVideo() || message.type == 1 || message.type == 0 && !message.isWebpageDocument() || message.isGif()) {
2015-08-13 11:23:31 +02:00
PhotoViewer.getInstance().setParentActivity(getParentActivity());
2016-10-11 13:57:01 +02:00
if (PhotoViewer.getInstance().openPhoto(message, message.type != 0 ? dialog_id : 0, message.type != 0 ? mergeDialogId : 0, ChatActivity.this)) {
PhotoViewer.getInstance().setParentChatActivity(ChatActivity.this);
}
2015-08-13 11:23:31 +02:00
} else if (message.type == 3) {
sendSecretMessageRead(message);
try {
File f = null;
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
f = new File(message.messageOwner.attachPath);
}
2015-09-24 22:52:02 +02:00
if (f == null || !f.exists()) {
f = FileLoader.getPathToMessage(message.messageOwner);
}
2015-08-13 11:23:31 +02:00
Intent intent = new Intent(Intent.ACTION_VIEW);
2016-10-11 13:57:01 +02:00
if (Build.VERSION.SDK_INT >= 24) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), "video/mp4");
} else {
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
}
2015-08-13 11:23:31 +02:00
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
alertUserOpenError(message);
}
} else if (message.type == 4) {
2016-04-22 15:49:00 +02:00
if (!AndroidUtilities.isGoogleMapsInstalled(ChatActivity.this)) {
2015-08-13 11:23:31 +02:00
return;
}
LocationActivity fragment = new LocationActivity();
fragment.setMessageObject(message);
presentFragment(fragment);
2016-03-16 13:26:32 +01:00
} else if (message.type == 9 || message.type == 0) {
try {
AndroidUtilities.openForView(message, getParentActivity());
} catch (Exception e) {
alertUserOpenError(message);
}
}
2015-08-13 11:23:31 +02:00
}
});
2016-04-22 15:49:00 +02:00
if (currentEncryptedChat == null) {
chatMessageCell.setAllowAssistant(true);
2014-10-15 20:43:52 +02:00
}
2016-04-22 15:49:00 +02:00
} else if (viewType == 1) {
view = new ChatActionCell(mContext);
((ChatActionCell) view).setDelegate(new ChatActionCell.ChatActionCellDelegate() {
@Override
public void didClickedImage(ChatActionCell cell) {
MessageObject message = cell.getMessageObject();
PhotoViewer.getInstance().setParentActivity(getParentActivity());
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, 640);
if (photoSize != null) {
PhotoViewer.getInstance().openPhoto(photoSize.location, ChatActivity.this);
} else {
PhotoViewer.getInstance().openPhoto(message, 0, 0, ChatActivity.this);
}
}
@Override
public void didLongPressed(ChatActionCell cell) {
createMenu(cell, false);
}
@Override
public void needOpenUserProfile(int uid) {
2015-11-26 22:04:02 +01:00
if (uid < 0) {
Bundle args = new Bundle();
args.putInt("chat_id", -uid);
2016-03-16 13:26:32 +01:00
if (MessagesController.checkCanOpenChat(args, ChatActivity.this)) {
presentFragment(new ChatActivity(args), true);
}
2015-11-26 22:04:02 +01:00
} else if (uid != UserConfig.getClientUserId()) {
Bundle args = new Bundle();
args.putInt("user_id", uid);
2015-10-29 18:10:07 +01:00
if (currentEncryptedChat != null && uid == currentUser.id) {
args.putLong("dialog_id", dialog_id);
}
ProfileActivity fragment = new ProfileActivity(args);
fragment.setPlayProfileAnimation(currentUser != null && currentUser.id == uid);
presentFragment(fragment);
}
}
2016-10-11 13:57:01 +02:00
@Override
public void didPressedReplyMessage(ChatActionCell cell, int id) {
MessageObject messageObject = cell.getMessageObject();
scrollToMessageId(id, messageObject.getId(), true, messageObject.getDialogId() == mergeDialogId ? 1 : 0);
}
@Override
public void didPressedBotButton(MessageObject messageObject, TLRPC.KeyboardButton button) {
if (getParentActivity() == null || bottomOverlayChat.getVisibility() == View.VISIBLE &&
!(button instanceof TLRPC.TL_keyboardButtonSwitchInline) && !(button instanceof TLRPC.TL_keyboardButtonCallback) &&
!(button instanceof TLRPC.TL_keyboardButtonGame) && !(button instanceof TLRPC.TL_keyboardButtonUrl)) {
return;
}
chatActivityEnterView.didPressedBotButton(button, messageObject, messageObject);
}
});
2016-04-22 15:49:00 +02:00
} else if (viewType == 2) {
view = new ChatUnreadCell(mContext);
} else if (viewType == 3) {
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("#")) {
DialogsActivity fragment = new DialogsActivity(null);
fragment.setSearchString(url);
presentFragment(fragment);
} else if (url.startsWith("/")) {
chatActivityEnterView.setCommand(null, url, false, false);
}
}
});
} else if (viewType == 4) {
view = new ChatLoadingCell(mContext);
2014-10-15 20:43:52 +02:00
}
2016-03-16 13:26:32 +01:00
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
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-06-29 19:12:11 +02:00
boolean selected = false;
boolean disableSelection = false;
if (actionBar.isActionModeShowed()) {
2016-05-25 23:49:47 +02:00
MessageObject messageObject = chatActivityEnterView != null ? chatActivityEnterView.getEditingMessageObject() : null;
if (messageObject == message || selectedMessagesIds[message.getDialogId() == dialog_id ? 0 : 1].containsKey(message.getId())) {
view.setBackgroundColor(Theme.MSG_SELECTED_BACKGROUND_COLOR);
2015-06-29 19:12:11 +02:00
selected = true;
} else {
view.setBackgroundColor(0);
}
disableSelection = true;
2014-10-15 20:43:52 +02:00
} else {
view.setBackgroundColor(0);
}
2016-04-22 15:49:00 +02:00
if (view instanceof ChatMessageCell) {
ChatMessageCell messageCell = (ChatMessageCell) view;
messageCell.isChat = currentChat != null;
messageCell.setMessageObject(message);
messageCell.setCheckPressed(!disableSelection, disableSelection && selected);
if (view instanceof ChatMessageCell && MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_AUDIO)) {
((ChatMessageCell) view).downloadAudioIfNeed();
}
messageCell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && message.getId() == highlightMessageId);
if (searchContainer != null && searchContainer.getVisibility() == View.VISIBLE && MessagesSearchQuery.getLastSearchQuery() != null) {
messageCell.setHighlightedText(MessagesSearchQuery.getLastSearchQuery());
} else {
messageCell.setHighlightedText(null);
}
2015-06-29 19:12:11 +02:00
} 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));
}
}
2013-10-25 17:19:00 +02:00
}
@Override
public int getItemViewType(int position) {
2016-04-22 15:49:00 +02:00
if (position >= messagesStartRow && position < messagesEndRow) {
2015-06-29 19:12:11 +02:00
return messages.get(messages.size() - (position - messagesStartRow) - 1).contentType;
2016-04-22 15:49:00 +02:00
} else if (position == botInfoRow) {
return 3;
2013-12-20 20:25:49 +01:00
}
2016-04-22 15:49:00 +02:00
return 4;
2013-10-25 17:19:00 +02:00
}
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
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);
int height = chatListView.getMeasuredHeight();
int top = messageCell.getTop();
int bottom = messageCell.getBottom();
int viewTop = top >= 0 ? 0 : -top;
int viewBottom = messageCell.getMeasuredHeight();
if (viewBottom > height) {
viewBottom = viewTop + height;
}
messageCell.setVisiblePart(viewTop, viewBottom - viewTop);
return true;
}
});
2016-04-22 15:49:00 +02:00
messageCell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && messageCell.getMessageObject().getId() == highlightMessageId);
}
2013-10-25 17:19:00 +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-06-29 19:12:11 +02:00
@Override
public void notifyDataSetChanged() {
updateRows();
2015-11-26 22:04:02 +01:00
try {
super.notifyDataSetChanged();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-06-29 19:12:11 +02:00
}
@Override
public void notifyItemChanged(int position) {
updateRows();
2015-11-26 22:04:02 +01:00
try {
super.notifyItemChanged(position);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-06-29 19:12:11 +02:00
}
@Override
public void notifyItemRangeChanged(int positionStart, int itemCount) {
updateRows();
2015-11-26 22:04:02 +01:00
try {
2016-03-16 13:26:32 +01:00
super.notifyItemRangeChanged(positionStart, itemCount);
2015-11-26 22:04:02 +01:00
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-06-29 19:12:11 +02:00
}
@Override
public void notifyItemInserted(int position) {
updateRows();
2015-11-26 22:04:02 +01:00
try {
super.notifyItemInserted(position);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-06-29 19:12:11 +02:00
}
@Override
public void notifyItemMoved(int fromPosition, int toPosition) {
updateRows();
2015-11-26 22:04:02 +01:00
try {
super.notifyItemMoved(fromPosition, toPosition);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-06-29 19:12:11 +02:00
}
@Override
public void notifyItemRangeInserted(int positionStart, int itemCount) {
updateRows();
2015-11-26 22:04:02 +01:00
try {
super.notifyItemRangeInserted(positionStart, itemCount);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-06-29 19:12:11 +02:00
}
@Override
public void notifyItemRemoved(int position) {
updateRows();
2015-11-26 22:04:02 +01:00
try {
super.notifyItemRemoved(position);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2015-06-29 19:12:11 +02:00
}
@Override
public void notifyItemRangeRemoved(int positionStart, int itemCount) {
updateRows();
2015-11-26 22:04:02 +01:00
try {
super.notifyItemRangeRemoved(positionStart, itemCount);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2013-10-25 17:19:00 +02:00
}
}
}