2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2013-12-20 20:25:49 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 17:19:00 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
import android.animation.StateListAnimator;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.app.AlertDialog;
|
2015-04-09 20:00:14 +02:00
|
|
|
import android.content.Context;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.content.DialogInterface;
|
2014-11-06 22:34:47 +01:00
|
|
|
import android.content.res.Configuration;
|
2015-02-01 19:51:02 +01:00
|
|
|
import android.graphics.Outline;
|
2014-10-31 20:02:29 +01:00
|
|
|
import android.os.Build;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.os.Bundle;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.util.TypedValue;
|
2014-11-06 22:34:47 +01:00
|
|
|
import android.view.Gravity;
|
2014-10-07 22:14:27 +02:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
2015-02-01 19:51:02 +01:00
|
|
|
import android.view.ViewOutlineProvider;
|
2014-11-06 22:34:47 +01:00
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.widget.EditText;
|
2014-11-06 22:34:47 +01:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.widget.LinearLayout;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.ListView;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.widget.ProgressBar;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.ChatObject;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MessageObject;
|
|
|
|
import org.telegram.messenger.UserObject;
|
|
|
|
import org.telegram.messenger.support.widget.LinearLayoutManager;
|
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
2014-11-21 11:59:05 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.messenger.ContactsController;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.Adapters.DialogsAdapter;
|
|
|
|
import org.telegram.ui.Adapters.DialogsSearchAdapter;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AnimationCompat.ObjectAnimatorProxy;
|
|
|
|
import org.telegram.messenger.AnimationCompat.ViewProxy;
|
2015-08-13 11:23:31 +02:00
|
|
|
import org.telegram.ui.Cells.ProfileSearchCell;
|
2014-11-10 12:05:22 +01:00
|
|
|
import org.telegram.ui.Cells.UserCell;
|
2014-02-04 19:36:55 +01:00
|
|
|
import org.telegram.ui.Cells.DialogCell;
|
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.ActionBar.BaseFragment;
|
|
|
|
import org.telegram.ui.ActionBar.MenuDrawable;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.EmptyTextProgressView;
|
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.ResourceLoader;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public class DialogsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
private RecyclerListView listView;
|
|
|
|
private LinearLayoutManager layoutManager;
|
2014-11-13 21:10:14 +01:00
|
|
|
private DialogsAdapter dialogsAdapter;
|
|
|
|
private DialogsSearchAdapter dialogsSearchAdapter;
|
2015-05-21 23:27:27 +02:00
|
|
|
private EmptyTextProgressView searchEmptyView;
|
|
|
|
private ProgressBar progressView;
|
|
|
|
private LinearLayout emptyView;
|
2015-02-26 02:32:51 +01:00
|
|
|
private ActionBarMenuItem passcodeItem;
|
2014-11-06 22:34:47 +01:00
|
|
|
private ImageView floatingButton;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
private int prevPosition;
|
|
|
|
private int prevTop;
|
|
|
|
private boolean scrollUpdated;
|
|
|
|
private boolean floatingHidden;
|
|
|
|
private final AccelerateDecelerateInterpolator floatingInterpolator = new AccelerateDecelerateInterpolator();
|
2014-10-31 20:02:29 +01:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
private String selectAlertString;
|
2014-10-04 17:56:09 +02:00
|
|
|
private String selectAlertStringGroup;
|
2015-06-29 19:12:11 +02:00
|
|
|
private String addToGroupAlertString;
|
|
|
|
private int dialogsType;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private static boolean dialogsLoaded;
|
|
|
|
private boolean searching;
|
|
|
|
private boolean searchWas;
|
|
|
|
private boolean onlySelect;
|
2013-10-25 17:19:00 +02:00
|
|
|
private long selectedDialog;
|
2015-03-19 00:09:45 +01:00
|
|
|
private String searchString;
|
2015-05-21 23:27:27 +02:00
|
|
|
private long openedDialogId;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
private MessagesActivityDelegate delegate;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface MessagesActivityDelegate {
|
2015-07-22 20:56:37 +02:00
|
|
|
void didSelectDialog(DialogsActivity fragment, long dialog_id, boolean param);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public DialogsActivity(Bundle args) {
|
2014-06-04 01:31:48 +02:00
|
|
|
super(args);
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (getArguments() != null) {
|
2014-06-04 01:31:48 +02:00
|
|
|
onlySelect = arguments.getBoolean("onlySelect", false);
|
2015-06-29 19:12:11 +02:00
|
|
|
dialogsType = arguments.getInt("dialogsType", 0);
|
2014-06-04 01:31:48 +02:00
|
|
|
selectAlertString = arguments.getString("selectAlertString");
|
2014-10-04 17:56:09 +02:00
|
|
|
selectAlertStringGroup = arguments.getString("selectAlertStringGroup");
|
2015-06-29 19:12:11 +02:00
|
|
|
addToGroupAlertString = arguments.getString("addToGroupAlertString");
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
|
|
|
if (searchString == null) {
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatUpdated);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.openedChatChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageSendError);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didSetPasscode);
|
2015-09-24 22:52:02 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.needReloadRecentDialogsSearch);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
if (!dialogsLoaded) {
|
2014-03-22 23:31:55 +01:00
|
|
|
MessagesController.getInstance().loadDialogs(0, 0, 100, true);
|
2015-01-02 23:15:07 +01:00
|
|
|
ContactsController.getInstance().checkInviteText();
|
2013-12-20 20:25:49 +01:00
|
|
|
dialogsLoaded = true;
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2015-03-19 00:09:45 +01:00
|
|
|
if (searchString == null) {
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.dialogsNeedReload);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatUpdated);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.openedChatChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.notificationsSettingsUpdated);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByAck);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByServer);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageSendError);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didSetPasscode);
|
2015-09-24 22:52:02 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.needReloadRecentDialogsSearch);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
delegate = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(final Context context) {
|
2015-04-09 20:00:14 +02:00
|
|
|
searching = false;
|
|
|
|
searchWas = false;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
ResourceLoader.loadRecources(context);
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
if (!onlySelect && searchString == null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
passcodeItem = menu.addItem(1, R.drawable.lock_close);
|
2015-04-09 20:00:14 +02:00
|
|
|
updatePasscodeButton();
|
|
|
|
}
|
|
|
|
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
|
|
|
@Override
|
|
|
|
public void onSearchExpand() {
|
|
|
|
searching = true;
|
2015-05-21 23:27:27 +02:00
|
|
|
if (listView != null) {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (searchString != null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(searchEmptyView);
|
2015-06-29 19:12:11 +02:00
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
emptyView.setVisibility(View.GONE);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!onlySelect) {
|
|
|
|
floatingButton.setVisibility(View.GONE);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
updatePasscodeButton();
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-06-29 19:12:11 +02:00
|
|
|
public boolean canCollapseSearch() {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (searchString != null) {
|
|
|
|
finishFragment();
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSearchCollapse() {
|
2015-04-09 20:00:14 +02:00
|
|
|
searching = false;
|
|
|
|
searchWas = false;
|
2015-05-21 23:27:27 +02:00
|
|
|
if (listView != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
searchEmptyView.setVisibility(View.GONE);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
|
2015-06-29 19:12:11 +02:00
|
|
|
emptyView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(progressView);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
progressView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(emptyView);
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!onlySelect) {
|
|
|
|
floatingButton.setVisibility(View.VISIBLE);
|
|
|
|
floatingHidden = true;
|
|
|
|
ViewProxy.setTranslationY(floatingButton, AndroidUtilities.dp(100));
|
|
|
|
hideFloatingButton(false);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
if (listView.getAdapter() != dialogsAdapter) {
|
|
|
|
listView.setAdapter(dialogsAdapter);
|
2015-04-09 20:00:14 +02:00
|
|
|
dialogsAdapter.notifyDataSetChanged();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (dialogsSearchAdapter != null) {
|
2015-08-13 11:23:31 +02:00
|
|
|
dialogsSearchAdapter.searchDialogs(null);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
updatePasscodeButton();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(EditText editText) {
|
|
|
|
String text = editText.getText().toString();
|
2015-08-13 11:23:31 +02:00
|
|
|
if (text.length() != 0 || dialogsSearchAdapter != null && dialogsSearchAdapter.hasRecentRearch()) {
|
2015-04-09 20:00:14 +02:00
|
|
|
searchWas = true;
|
|
|
|
if (dialogsSearchAdapter != null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setAdapter(dialogsSearchAdapter);
|
2015-04-09 20:00:14 +02:00
|
|
|
dialogsSearchAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) {
|
2015-06-29 19:12:11 +02:00
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
progressView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
searchEmptyView.showTextView();
|
|
|
|
listView.setEmptyView(searchEmptyView);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (dialogsSearchAdapter != null) {
|
2015-08-13 11:23:31 +02:00
|
|
|
dialogsSearchAdapter.searchDialogs(text);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
|
|
|
|
if (onlySelect) {
|
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat));
|
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
if (searchString != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
} else {
|
|
|
|
actionBar.setBackButtonDrawable(new MenuDrawable());
|
2014-11-19 11:32:27 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
}
|
|
|
|
actionBar.setAllowOverlayTitle(true);
|
|
|
|
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
if (onlySelect) {
|
|
|
|
finishFragment();
|
|
|
|
} else if (parentLayout != null) {
|
|
|
|
parentLayout.getDrawerLayoutContainer().openDrawer(false);
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
} else if (id == 1) {
|
2015-04-09 20:00:14 +02:00
|
|
|
UserConfig.appLocked = !UserConfig.appLocked;
|
|
|
|
UserConfig.saveConfig(false);
|
|
|
|
updatePasscodeButton();
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
|
|
|
fragmentView = frameLayout;
|
|
|
|
|
|
|
|
listView = new RecyclerListView(context);
|
|
|
|
listView.setVerticalScrollBarEnabled(true);
|
|
|
|
listView.setItemAnimator(null);
|
|
|
|
listView.setInstantClick(true);
|
|
|
|
listView.setLayoutAnimation(null);
|
|
|
|
layoutManager = new LinearLayoutManager(context) {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
};
|
|
|
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
listView.setLayoutManager(layoutManager);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
if (listView == null || listView.getAdapter() == null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
long dialog_id = 0;
|
|
|
|
int message_id = 0;
|
2015-05-21 23:27:27 +02:00
|
|
|
RecyclerView.Adapter adapter = listView.getAdapter();
|
2015-04-09 20:00:14 +02:00
|
|
|
if (adapter == dialogsAdapter) {
|
2015-09-24 22:52:02 +02:00
|
|
|
TLRPC.Dialog dialog = dialogsAdapter.getItem(position);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (dialog == null) {
|
2014-10-21 22:35:16 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
dialog_id = dialog.id;
|
|
|
|
} else if (adapter == dialogsSearchAdapter) {
|
2015-05-21 23:27:27 +02:00
|
|
|
Object obj = dialogsSearchAdapter.getItem(position);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (obj instanceof TLRPC.User) {
|
|
|
|
dialog_id = ((TLRPC.User) obj).id;
|
2015-05-21 23:27:27 +02:00
|
|
|
if (dialogsSearchAdapter.isGlobalSearch(position)) {
|
2015-04-09 20:00:14 +02:00
|
|
|
ArrayList<TLRPC.User> users = new ArrayList<>();
|
|
|
|
users.add((TLRPC.User) obj);
|
|
|
|
MessagesController.getInstance().putUsers(users, false);
|
|
|
|
MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.User) obj);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (obj instanceof TLRPC.Chat) {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (dialogsSearchAdapter.isGlobalSearch(position)) {
|
|
|
|
ArrayList<TLRPC.Chat> chats = new ArrayList<>();
|
|
|
|
chats.add((TLRPC.Chat) obj);
|
|
|
|
MessagesController.getInstance().putChats(chats, false);
|
|
|
|
MessagesStorage.getInstance().putUsersAndChats(null, chats, false, true);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (((TLRPC.Chat) obj).id > 0) {
|
|
|
|
dialog_id = -((TLRPC.Chat) obj).id;
|
|
|
|
} else {
|
|
|
|
dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.Chat) obj);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (obj instanceof TLRPC.EncryptedChat) {
|
|
|
|
dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32;
|
2015-08-13 11:23:31 +02:00
|
|
|
dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.EncryptedChat) obj);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (obj instanceof MessageObject) {
|
|
|
|
MessageObject messageObject = (MessageObject) obj;
|
|
|
|
dialog_id = messageObject.getDialogId();
|
|
|
|
message_id = messageObject.getId();
|
|
|
|
dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString());
|
|
|
|
} else if (obj instanceof String) {
|
|
|
|
actionBar.openSearchField((String) obj);
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (dialog_id == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (onlySelect) {
|
|
|
|
didSelectResult(dialog_id, true, false);
|
|
|
|
} else {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
int lower_part = (int) dialog_id;
|
|
|
|
int high_id = (int) (dialog_id >> 32);
|
|
|
|
if (lower_part != 0) {
|
|
|
|
if (high_id == 1) {
|
|
|
|
args.putInt("chat_id", lower_part);
|
2014-11-24 15:14:40 +01:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (lower_part > 0) {
|
|
|
|
args.putInt("user_id", lower_part);
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
args.putInt("chat_id", -lower_part);
|
2014-11-24 15:14:40 +01:00
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
args.putInt("enc_id", high_id);
|
|
|
|
}
|
|
|
|
if (message_id != 0) {
|
|
|
|
args.putInt("message_id", message_id);
|
|
|
|
} else {
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.closeSearchField();
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (openedDialogId == dialog_id && adapter != dialogsSearchAdapter) {
|
2015-04-09 20:00:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (dialogsAdapter != null) {
|
|
|
|
dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id);
|
|
|
|
updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (searchString != null) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
presentFragment(new ChatActivity(args));
|
|
|
|
} else {
|
|
|
|
presentFragment(new ChatActivity(args));
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public void onItemClick(View view, int position) {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (onlySelect || searching && searchWas || getParentActivity() == null) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (searchWas && searching || dialogsSearchAdapter.isRecentSearchDisplayed()) {
|
2015-05-21 23:27:27 +02:00
|
|
|
RecyclerView.Adapter adapter = listView.getAdapter();
|
2015-04-09 20:00:14 +02:00
|
|
|
if (adapter == dialogsSearchAdapter) {
|
2015-05-21 23:27:27 +02:00
|
|
|
Object item = dialogsSearchAdapter.getItem(position);
|
2015-08-13 11:23:31 +02:00
|
|
|
if (item instanceof String || dialogsSearchAdapter.isRecentSearchDisplayed()) {
|
2015-04-09 20:00:14 +02:00
|
|
|
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) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (dialogsSearchAdapter.isRecentSearchDisplayed()) {
|
|
|
|
dialogsSearchAdapter.clearRecentSearch();
|
|
|
|
} else {
|
|
|
|
dialogsSearchAdapter.clearRecentHashtags();
|
|
|
|
}
|
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());
|
|
|
|
return;
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
return;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
TLRPC.Dialog dialog;
|
|
|
|
ArrayList<TLRPC.Dialog> dialogs = getDialogsArray();
|
2015-06-29 19:12:11 +02:00
|
|
|
if (position < 0 || position >= dialogs.size()) {
|
|
|
|
return;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
dialog = dialogs.get(position);
|
2015-04-09 20:00:14 +02:00
|
|
|
selectedDialog = dialog.id;
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
|
2015-04-09 20:00:14 +02:00
|
|
|
int lower_id = (int) selectedDialog;
|
|
|
|
int high_id = (int) (selectedDialog >> 32);
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
if (dialog instanceof TLRPC.TL_dialogChannel) {
|
|
|
|
final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id);
|
|
|
|
if (chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.setItems(new CharSequence[]{(chat.flags & TLRPC.CHAT_FLAG_ADMIN) == 0 ? LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu) : LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu)}, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, final int which) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
if ((chat.flags & TLRPC.CHAT_FLAG_ADMIN) == 0) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert));
|
2014-11-17 03:44:57 +01:00
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
builder.setMessage(LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
MessagesController.getInstance().deleteUserFromChat((int) -selectedDialog, UserConfig.getCurrentUser(), null);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats, selectedDialog);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showDialog(builder.create());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
showDialog(builder.create());
|
|
|
|
} else {
|
|
|
|
final boolean isChat = lower_id < 0 && high_id != 1;
|
|
|
|
builder.setItems(new CharSequence[]{LocaleController.getString("ClearHistory", R.string.ClearHistory), isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat) : LocaleController.getString("Delete", R.string.Delete)}, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, final int which) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
if (which == 0) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory));
|
|
|
|
} else {
|
|
|
|
if (isChat) {
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat));
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (which != 0) {
|
|
|
|
if (isChat) {
|
|
|
|
TLRPC.Chat currentChat = MessagesController.getInstance().getChat((int) -selectedDialog);
|
|
|
|
if (currentChat != null && ChatObject.isNotInChat(currentChat)) {
|
|
|
|
MessagesController.getInstance().deleteDialog(selectedDialog, 0, false);
|
|
|
|
} else {
|
|
|
|
MessagesController.getInstance().deleteUserFromChat((int) -selectedDialog, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), null);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MessagesController.getInstance().deleteDialog(selectedDialog, 0, false);
|
|
|
|
}
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats, selectedDialog);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MessagesController.getInstance().deleteDialog(selectedDialog, 0, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showDialog(builder.create());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
showDialog(builder.create());
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
searchEmptyView = new EmptyTextProgressView(context);
|
2015-06-29 19:12:11 +02:00
|
|
|
searchEmptyView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
searchEmptyView.setShowAtCenter(true);
|
|
|
|
searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
|
|
|
|
frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
|
|
|
|
emptyView = new LinearLayout(context);
|
|
|
|
emptyView.setOrientation(LinearLayout.VERTICAL);
|
2015-06-29 19:12:11 +02:00
|
|
|
emptyView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
emptyView.setGravity(Gravity.CENTER);
|
|
|
|
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
emptyView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
2015-04-09 20:00:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setText(LocaleController.getString("NoChats", R.string.NoChats));
|
|
|
|
textView.setTextColor(0xff959595);
|
|
|
|
textView.setGravity(Gravity.CENTER);
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
|
|
|
textView = new TextView(context);
|
|
|
|
String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp);
|
|
|
|
if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) {
|
|
|
|
help = help.replace("\n", " ");
|
|
|
|
}
|
|
|
|
textView.setText(help);
|
|
|
|
textView.setTextColor(0xff959595);
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
|
|
|
textView.setGravity(Gravity.CENTER);
|
|
|
|
textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(8), 0);
|
|
|
|
textView.setLineSpacing(AndroidUtilities.dp(2), 1);
|
|
|
|
emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
|
|
|
progressView = new ProgressBar(context);
|
2015-06-29 19:12:11 +02:00
|
|
|
progressView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
|
|
|
|
|
|
|
floatingButton = new ImageView(context);
|
|
|
|
floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE);
|
|
|
|
floatingButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
floatingButton.setBackgroundResource(R.drawable.floating_states);
|
|
|
|
floatingButton.setImageResource(R.drawable.floating_pencil);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
StateListAnimator animator = new StateListAnimator();
|
|
|
|
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
|
|
|
|
animator.addState(new int[]{}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
|
|
|
|
floatingButton.setStateListAnimator(animator);
|
|
|
|
floatingButton.setOutlineProvider(new ViewOutlineProvider() {
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
@Override
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
frameLayout.addView(floatingButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
|
|
|
|
floatingButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("destroyAfterSelect", true);
|
|
|
|
presentFragment(new ContactsActivity(args));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) {
|
2015-04-09 20:00:14 +02:00
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
|
|
|
|
int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
|
|
|
|
int totalItemCount = recyclerView.getAdapter().getItemCount();
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (searching && searchWas) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) {
|
2015-04-09 20:00:14 +02:00
|
|
|
dialogsSearchAdapter.loadMoreSearchMessages();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (visibleItemCount > 0) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (layoutManager.findLastVisibleItemPosition() == getDialogsArray().size()) {
|
2015-09-24 22:52:02 +02:00
|
|
|
MessagesController.getInstance().loadDialogs(MessagesController.getInstance().dialogs.size(), MessagesController.getInstance().currentDialogsCount, 100, true);
|
2014-05-25 00:47:05 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (floatingButton.getVisibility() != View.GONE) {
|
2015-05-21 23:27:27 +02:00
|
|
|
final View topChild = recyclerView.getChildAt(0);
|
2015-04-09 20:00:14 +02:00
|
|
|
int firstViewTop = 0;
|
|
|
|
if (topChild != null) {
|
|
|
|
firstViewTop = topChild.getTop();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
boolean goingDown;
|
|
|
|
boolean changed = true;
|
|
|
|
if (prevPosition == firstVisibleItem) {
|
|
|
|
final int topDelta = prevTop - firstViewTop;
|
|
|
|
goingDown = firstViewTop < prevTop;
|
|
|
|
changed = Math.abs(topDelta) > 1;
|
|
|
|
} else {
|
|
|
|
goingDown = firstVisibleItem > prevPosition;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (changed && scrollUpdated) {
|
|
|
|
hideFloatingButton(goingDown);
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
prevPosition = firstVisibleItem;
|
|
|
|
prevTop = firstViewTop;
|
|
|
|
scrollUpdated = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (searchString == null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
dialogsAdapter = new DialogsAdapter(context, dialogsType);
|
2015-05-21 23:27:27 +02:00
|
|
|
if (AndroidUtilities.isTablet() && openedDialogId != 0) {
|
|
|
|
dialogsAdapter.setOpenedDialogId(openedDialogId);
|
|
|
|
}
|
|
|
|
listView.setAdapter(dialogsAdapter);
|
|
|
|
}
|
|
|
|
int type = 0;
|
|
|
|
if (searchString != null) {
|
|
|
|
type = 2;
|
|
|
|
} else if (!onlySelect) {
|
|
|
|
type = 1;
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
dialogsSearchAdapter = new DialogsSearchAdapter(context, type, dialogsType);
|
2015-05-21 23:27:27 +02:00
|
|
|
dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() {
|
|
|
|
@Override
|
|
|
|
public void searchStateChanged(boolean search) {
|
|
|
|
if (searching && searchWas && searchEmptyView != null) {
|
|
|
|
if (search) {
|
|
|
|
searchEmptyView.showProgress();
|
|
|
|
} else {
|
|
|
|
searchEmptyView.showTextView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
|
2015-06-29 19:12:11 +02:00
|
|
|
searchEmptyView.setVisibility(View.GONE);
|
|
|
|
emptyView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(progressView);
|
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
searchEmptyView.setVisibility(View.GONE);
|
|
|
|
progressView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (searchString != null) {
|
|
|
|
actionBar.openSearchField(searchString);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onResume();
|
2014-11-13 21:10:14 +01:00
|
|
|
if (dialogsAdapter != null) {
|
|
|
|
dialogsAdapter.notifyDataSetChanged();
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2014-11-13 21:10:14 +01:00
|
|
|
if (dialogsSearchAdapter != null) {
|
|
|
|
dialogsSearchAdapter.notifyDataSetChanged();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
if (!onlySelect && floatingButton != null) {
|
|
|
|
floatingButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
|
@Override
|
|
|
|
public void onGlobalLayout() {
|
|
|
|
ViewProxy.setTranslationY(floatingButton, floatingHidden ? AndroidUtilities.dp(100) : 0);
|
2014-11-19 02:23:46 +01:00
|
|
|
floatingButton.setClickable(!floatingHidden);
|
2014-11-06 22:34:47 +01:00
|
|
|
if (floatingButton != null) {
|
|
|
|
if (Build.VERSION.SDK_INT < 16) {
|
|
|
|
floatingButton.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
|
|
|
} else {
|
|
|
|
floatingButton.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.dialogsNeedReload) {
|
2014-11-20 15:45:33 +01:00
|
|
|
if (dialogsAdapter != null) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (dialogsAdapter.isDataSetChanged()) {
|
|
|
|
dialogsAdapter.notifyDataSetChanged();
|
|
|
|
} else {
|
|
|
|
updateVisibleRows(MessagesController.UPDATE_MASK_NEW_MESSAGE);
|
|
|
|
}
|
2014-11-20 15:45:33 +01:00
|
|
|
}
|
|
|
|
if (dialogsSearchAdapter != null) {
|
|
|
|
dialogsSearchAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
if (listView != null) {
|
2014-11-21 11:59:05 +01:00
|
|
|
try {
|
|
|
|
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
|
2015-06-29 19:12:11 +02:00
|
|
|
searchEmptyView.setVisibility(View.GONE);
|
|
|
|
emptyView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(progressView);
|
2014-11-17 03:44:57 +01:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
progressView.setVisibility(View.GONE);
|
2014-11-21 11:59:05 +01:00
|
|
|
if (searching && searchWas) {
|
2015-06-29 19:12:11 +02:00
|
|
|
emptyView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(searchEmptyView);
|
2014-11-21 11:59:05 +01:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
searchEmptyView.setVisibility(View.GONE);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setEmptyView(emptyView);
|
2014-11-21 11:59:05 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-11-21 11:59:05 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e); //TODO fix it in other way?
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.emojiDidLoaded) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (listView != null) {
|
2014-02-04 19:36:55 +01:00
|
|
|
updateVisibleRows(0);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.updateInterfaces) {
|
2015-05-21 23:27:27 +02:00
|
|
|
updateVisibleRows((Integer) args[0]);
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.appDidLogout) {
|
2013-10-25 17:19:00 +02:00
|
|
|
dialogsLoaded = false;
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.encryptedChatUpdated) {
|
2014-02-04 19:36:55 +01:00
|
|
|
updateVisibleRows(0);
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.contactsDidLoaded) {
|
2014-02-04 19:36:55 +01:00
|
|
|
updateVisibleRows(0);
|
2014-09-24 04:17:27 +02:00
|
|
|
} else if (id == NotificationCenter.openedChatChanged) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (dialogsType == 0 && AndroidUtilities.isTablet()) {
|
2015-05-21 23:27:27 +02:00
|
|
|
boolean close = (Boolean) args[1];
|
|
|
|
long dialog_id = (Long) args[0];
|
2014-09-30 00:48:11 +02:00
|
|
|
if (close) {
|
|
|
|
if (dialog_id == openedDialogId) {
|
|
|
|
openedDialogId = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
openedDialogId = dialog_id;
|
|
|
|
}
|
2014-11-19 11:32:27 +01:00
|
|
|
if (dialogsAdapter != null) {
|
|
|
|
dialogsAdapter.setOpenedDialogId(openedDialogId);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
} else if (id == NotificationCenter.notificationsSettingsUpdated) {
|
2015-02-26 02:32:51 +01:00
|
|
|
updateVisibleRows(0);
|
|
|
|
} else if (id == NotificationCenter.messageReceivedByAck || id == NotificationCenter.messageReceivedByServer || id == NotificationCenter.messageSendError) {
|
|
|
|
updateVisibleRows(MessagesController.UPDATE_MASK_SEND_STATE);
|
|
|
|
} else if (id == NotificationCenter.didSetPasscode) {
|
|
|
|
updatePasscodeButton();
|
2015-09-24 22:52:02 +02:00
|
|
|
} if (id == NotificationCenter.needReloadRecentDialogsSearch) {
|
|
|
|
if (dialogsSearchAdapter != null) {
|
|
|
|
dialogsSearchAdapter.loadRecentSearch();
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
private ArrayList<TLRPC.Dialog> getDialogsArray() {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (dialogsType == 0) {
|
|
|
|
return MessagesController.getInstance().dialogs;
|
|
|
|
} else if (dialogsType == 1) {
|
|
|
|
return MessagesController.getInstance().dialogsServerOnly;
|
|
|
|
} else if (dialogsType == 2) {
|
|
|
|
return MessagesController.getInstance().dialogsGroupsOnly;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private void updatePasscodeButton() {
|
|
|
|
if (passcodeItem == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (UserConfig.passcodeHash.length() != 0 && !searching) {
|
|
|
|
passcodeItem.setVisibility(View.VISIBLE);
|
|
|
|
if (UserConfig.appLocked) {
|
|
|
|
passcodeItem.setIcon(R.drawable.lock_close);
|
|
|
|
} else {
|
|
|
|
passcodeItem.setIcon(R.drawable.lock_open);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
|
|
|
passcodeItem.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
private void hideFloatingButton(boolean hide) {
|
|
|
|
if (floatingHidden == hide) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
floatingHidden = hide;
|
|
|
|
ObjectAnimatorProxy animator = ObjectAnimatorProxy.ofFloatProxy(floatingButton, "translationY", floatingHidden ? AndroidUtilities.dp(100) : 0).setDuration(300);
|
|
|
|
animator.setInterpolator(floatingInterpolator);
|
2014-11-19 02:23:46 +01:00
|
|
|
floatingButton.setClickable(!hide);
|
2014-11-06 22:34:47 +01:00
|
|
|
animator.start();
|
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
private void updateVisibleRows(int mask) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (listView == null) {
|
2014-02-04 19:36:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
int count = listView.getChildCount();
|
2014-02-04 19:36:55 +01:00
|
|
|
for (int a = 0; a < count; a++) {
|
2015-05-21 23:27:27 +02:00
|
|
|
View child = listView.getChildAt(a);
|
2014-02-04 19:36:55 +01:00
|
|
|
if (child instanceof DialogCell) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (listView.getAdapter() != dialogsSearchAdapter) {
|
|
|
|
DialogCell cell = (DialogCell) child;
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) != 0) {
|
|
|
|
cell.checkCurrentDialogIndex();
|
|
|
|
if (dialogsType == 0 && AndroidUtilities.isTablet()) {
|
|
|
|
cell.setDialogSelected(cell.getDialogId() == openedDialogId);
|
|
|
|
}
|
|
|
|
} else if ((mask & MessagesController.UPDATE_MASK_SELECT_DIALOG) != 0) {
|
|
|
|
if (dialogsType == 0 && AndroidUtilities.isTablet()) {
|
|
|
|
cell.setDialogSelected(cell.getDialogId() == openedDialogId);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cell.update(mask);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-10 12:05:22 +01:00
|
|
|
} else if (child instanceof UserCell) {
|
|
|
|
((UserCell) child).update(mask);
|
2015-08-13 11:23:31 +02:00
|
|
|
} else if (child instanceof ProfileSearchCell) {
|
|
|
|
((ProfileSearchCell) child).update(mask);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public void setDelegate(MessagesActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public void setSearchString(String string) {
|
|
|
|
searchString = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isMainDialogList() {
|
|
|
|
return delegate == null && searchString == null;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 23:15:39 +02:00
|
|
|
private void didSelectResult(final long dialog_id, boolean useAlert, final boolean param) {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (addToGroupAlertString == null) {
|
|
|
|
if ((int) dialog_id < 0 && ChatObject.isChannel(-(int) dialog_id) && !ChatObject.isCanWriteToChannel(-(int) dialog_id)) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelCantSendMessage", R.string.ChannelCantSendMessage));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
showDialog(builder.create());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (useAlert && (selectAlertString != null && selectAlertStringGroup != null || addToGroupAlertString != null)) {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-04-02 19:36:57 +02:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2015-05-21 23:27:27 +02:00
|
|
|
int lower_part = (int) dialog_id;
|
|
|
|
int high_id = (int) (dialog_id >> 32);
|
2013-10-25 17:19:00 +02:00
|
|
|
if (lower_part != 0) {
|
2014-07-27 12:53:00 +02:00
|
|
|
if (high_id == 1) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(lower_part);
|
2014-02-04 19:36:55 +01:00
|
|
|
if (chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-04 17:56:09 +02:00
|
|
|
builder.setMessage(LocaleController.formatStringSimple(selectAlertStringGroup, chat.title));
|
2014-07-27 00:28:33 +02:00
|
|
|
} else {
|
2014-07-27 12:53:00 +02:00
|
|
|
if (lower_part > 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(lower_part);
|
2014-07-27 12:53:00 +02:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
builder.setMessage(LocaleController.formatStringSimple(selectAlertString, UserObject.getUserName(user)));
|
2014-07-27 12:53:00 +02:00
|
|
|
} else if (lower_part < 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part);
|
2014-07-27 12:53:00 +02:00
|
|
|
if (chat == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (addToGroupAlertString != null) {
|
|
|
|
builder.setMessage(LocaleController.formatStringSimple(addToGroupAlertString, chat.title));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.formatStringSimple(selectAlertStringGroup, chat.title));
|
|
|
|
}
|
2014-07-27 00:28:33 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2014-07-27 12:53:00 +02:00
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
TLRPC.EncryptedChat chat = MessagesController.getInstance().getEncryptedChat(high_id);
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(chat.user_id);
|
2014-07-27 12:53:00 +02:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
builder.setMessage(LocaleController.formatStringSimple(selectAlertString, UserObject.getUserName(user)));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2015-05-21 23:27:27 +02:00
|
|
|
didSelectResult(dialog_id, false, false);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
2015-03-19 00:09:45 +01:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
if (delegate != null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
delegate.didSelectDialog(DialogsActivity.this, dialog_id, param);
|
2013-10-25 17:19:00 +02:00
|
|
|
delegate = null;
|
|
|
|
} else {
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|