2014-10-31 20:02:29 +01:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2014-10-31 20:02:29 +01: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).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2014-10-31 20:02:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Adapters;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.content.SharedPreferences;
|
2021-01-28 15:15:51 +01:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
|
|
|
import android.graphics.Rect;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2019-05-14 14:08:05 +02:00
|
|
|
import android.os.Build;
|
2019-07-18 15:01:39 +02:00
|
|
|
import android.os.SystemClock;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
2014-10-31 20:02:29 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.TextView;
|
2014-10-31 20:02:29 +01:00
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.ContactsController;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.DialogObject;
|
2019-07-18 15:01:39 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.R;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2019-07-18 15:01:39 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.ui.Cells.ArchiveHintCell;
|
2014-10-31 20:02:29 +01:00
|
|
|
import org.telegram.ui.Cells.DialogCell;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Cells.DialogMeUrlCell;
|
|
|
|
import org.telegram.ui.Cells.DialogsEmptyCell;
|
|
|
|
import org.telegram.ui.Cells.HeaderCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Cells.ShadowSectionCell;
|
2021-01-28 15:15:51 +01:00
|
|
|
import org.telegram.ui.Cells.TextCell;
|
|
|
|
import org.telegram.ui.Cells.TextInfoPrivacyCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Cells.UserCell;
|
|
|
|
import org.telegram.ui.Components.CombinedDrawable;
|
2021-01-28 15:15:51 +01:00
|
|
|
import org.telegram.ui.Components.FlickerLoadingView;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2020-12-23 08:48:30 +01:00
|
|
|
import org.telegram.ui.Components.PullForegroundDrawable;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2019-03-03 21:40:48 +01:00
|
|
|
import org.telegram.ui.DialogsActivity;
|
2014-10-31 20:02:29 +01:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
import java.util.ArrayList;
|
2019-05-14 14:08:05 +02:00
|
|
|
import java.util.Collections;
|
2020-12-23 08:48:30 +01:00
|
|
|
import java.util.HashSet;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public class DialogsAdapter extends RecyclerListView.SelectionAdapter {
|
2014-10-31 20:02:29 +01:00
|
|
|
|
|
|
|
private Context mContext;
|
2019-05-14 14:08:05 +02:00
|
|
|
private ArchiveHintCell archiveHintCell;
|
2019-07-18 15:01:39 +02:00
|
|
|
private ArrayList<TLRPC.TL_contact> onlineContacts;
|
2021-01-28 15:15:51 +01:00
|
|
|
private int dialogsCount;
|
2019-07-18 15:01:39 +02:00
|
|
|
private int prevContactsCount;
|
2021-01-28 15:15:51 +01:00
|
|
|
private int prevDialogsCount;
|
2015-06-29 19:12:11 +02:00
|
|
|
private int dialogsType;
|
2019-05-14 14:08:05 +02:00
|
|
|
private int folderId;
|
2014-10-31 20:02:29 +01:00
|
|
|
private long openedDialogId;
|
2015-02-26 02:32:51 +01:00
|
|
|
private int currentCount;
|
2017-12-08 18:35:59 +01:00
|
|
|
private boolean isOnlySelect;
|
|
|
|
private ArrayList<Long> selectedDialogs;
|
|
|
|
private boolean hasHints;
|
2020-09-30 15:48:47 +02:00
|
|
|
private int currentAccount;
|
2019-05-14 14:08:05 +02:00
|
|
|
private boolean dialogsListFrozen;
|
|
|
|
private boolean showArchiveHint;
|
|
|
|
private boolean isReordering;
|
2019-07-18 15:01:39 +02:00
|
|
|
private long lastSortTime;
|
2019-12-31 14:08:08 +01:00
|
|
|
private PullForegroundDrawable pullForegroundDrawable;
|
2014-10-31 20:02:29 +01:00
|
|
|
|
2021-01-28 15:15:51 +01:00
|
|
|
private Drawable arrowDrawable;
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
private DialogsPreloader preloader;
|
2021-01-28 15:15:51 +01:00
|
|
|
private boolean forceShowEmptyCell;
|
2020-12-23 08:48:30 +01:00
|
|
|
|
2021-01-28 15:15:51 +01:00
|
|
|
private DialogsActivity parentFragment;
|
|
|
|
|
|
|
|
public DialogsAdapter(DialogsActivity fragment, Context context, int type, int folder, boolean onlySelect, ArrayList<Long> selected, int account) {
|
2014-10-31 20:02:29 +01:00
|
|
|
mContext = context;
|
2021-01-28 15:15:51 +01:00
|
|
|
parentFragment = fragment;
|
2015-06-29 19:12:11 +02:00
|
|
|
dialogsType = type;
|
2019-05-14 14:08:05 +02:00
|
|
|
folderId = folder;
|
2017-12-08 18:35:59 +01:00
|
|
|
isOnlySelect = onlySelect;
|
2019-05-14 14:08:05 +02:00
|
|
|
hasHints = folder == 0 && type == 0 && !onlySelect;
|
2020-03-30 14:00:09 +02:00
|
|
|
selectedDialogs = selected;
|
2020-09-30 15:48:47 +02:00
|
|
|
currentAccount = account;
|
2019-05-14 14:08:05 +02:00
|
|
|
if (folderId == 1) {
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
showArchiveHint = preferences.getBoolean("archivehint", true);
|
|
|
|
preferences.edit().putBoolean("archivehint", false).commit();
|
|
|
|
if (showArchiveHint) {
|
|
|
|
archiveHintCell = new ArchiveHintCell(context);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
if (folder == 0) {
|
|
|
|
this.preloader = new DialogsPreloader();
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setOpenedDialogId(long id) {
|
|
|
|
openedDialogId = id;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void onReorderStateChanged(boolean reordering) {
|
|
|
|
isReordering = reordering;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int fixPosition(int position) {
|
|
|
|
if (hasHints) {
|
|
|
|
position -= 2 + MessagesController.getInstance(currentAccount).hintDialogs.size();
|
|
|
|
}
|
|
|
|
if (showArchiveHint) {
|
|
|
|
position -= 2;
|
2021-01-28 15:15:51 +01:00
|
|
|
} else if (dialogsType == 11 || dialogsType == 13) {
|
|
|
|
position -= 2;
|
|
|
|
} else if (dialogsType == 12) {
|
|
|
|
position -= 1;
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public boolean isDataSetChanged() {
|
|
|
|
int current = currentCount;
|
2015-11-26 22:04:02 +01:00
|
|
|
return current != getItemCount() || current == 1;
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
public void setDialogsType(int type) {
|
|
|
|
dialogsType = type;
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2021-08-31 21:06:39 +02:00
|
|
|
public int getDialogsType() {
|
|
|
|
return dialogsType;
|
|
|
|
}
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public int getItemCount() {
|
2021-01-28 15:15:51 +01:00
|
|
|
MessagesController messagesController = MessagesController.getInstance(currentAccount);
|
|
|
|
ArrayList<TLRPC.Dialog> array = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
|
|
|
|
dialogsCount = array.size();
|
|
|
|
if (!forceShowEmptyCell && dialogsType != 7 && dialogsType != 8 && dialogsType != 11 && dialogsCount == 0 && (folderId != 0 || messagesController.isLoadingDialogs(folderId) || !MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId))) {
|
2019-07-18 15:01:39 +02:00
|
|
|
onlineContacts = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
if (folderId == 1 && showArchiveHint) {
|
2019-06-04 12:14:50 +02:00
|
|
|
return (currentCount = 2);
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
return (currentCount = 0);
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
int count = dialogsCount;
|
2020-03-30 14:00:09 +02:00
|
|
|
if (dialogsType == 7 || dialogsType == 8) {
|
|
|
|
if (dialogsCount == 0) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} else {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (!messagesController.isDialogsEndReached(folderId) || dialogsCount == 0) {
|
2020-03-30 14:00:09 +02:00
|
|
|
count++;
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
boolean hasContacts = false;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (hasHints) {
|
2021-01-28 15:15:51 +01:00
|
|
|
count += 2 + messagesController.hintDialogs.size();
|
2021-01-30 07:18:23 +01:00
|
|
|
} else if (dialogsType == 0 && messagesController.dialogs_dict.size() <= 10 && folderId == 0 && messagesController.isDialogsEndReached(folderId)) {
|
2021-06-25 02:43:10 +02:00
|
|
|
if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && !ContactsController.getInstance(currentAccount).doneLoadingContacts) {
|
2019-07-18 15:01:39 +02:00
|
|
|
onlineContacts = null;
|
2019-06-04 12:14:50 +02:00
|
|
|
return (currentCount = 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!ContactsController.getInstance(currentAccount).contacts.isEmpty()) {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (onlineContacts == null || prevDialogsCount != messagesController.dialogs_dict.size() || prevContactsCount != ContactsController.getInstance(currentAccount).contacts.size()) {
|
2019-07-18 15:01:39 +02:00
|
|
|
onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
|
|
|
|
prevContactsCount = onlineContacts.size();
|
2021-01-28 15:15:51 +01:00
|
|
|
prevDialogsCount = messagesController.dialogs_dict.size();
|
2021-09-20 07:54:41 +02:00
|
|
|
long selfId = UserConfig.getInstance(currentAccount).clientUserId;
|
2019-07-18 15:01:39 +02:00
|
|
|
for (int a = 0, N = onlineContacts.size(); a < N; a++) {
|
2021-09-20 07:54:41 +02:00
|
|
|
long userId = onlineContacts.get(a).user_id;
|
2021-01-28 15:15:51 +01:00
|
|
|
if (userId == selfId || messagesController.dialogs_dict.get(userId) != null) {
|
2019-07-18 15:01:39 +02:00
|
|
|
onlineContacts.remove(a);
|
2021-01-28 15:15:51 +01:00
|
|
|
a--;
|
|
|
|
N--;
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
if (onlineContacts.isEmpty()) {
|
|
|
|
onlineContacts = null;
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
sortOnlineContacts(false);
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
if (onlineContacts != null) {
|
|
|
|
count += onlineContacts.size() + 2;
|
|
|
|
hasContacts = true;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
if (folderId == 0 && onlineContacts != null) {
|
|
|
|
if (!hasContacts) {
|
|
|
|
onlineContacts = null;
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (folderId == 1 && showArchiveHint) {
|
|
|
|
count += 2;
|
|
|
|
}
|
|
|
|
if (folderId == 0 && dialogsCount != 0) {
|
|
|
|
count++;
|
2021-01-28 15:15:51 +01:00
|
|
|
if (dialogsCount > 10 && dialogsType == 0) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dialogsType == 11 || dialogsType == 13) {
|
|
|
|
count += 2;
|
|
|
|
} else if (dialogsType == 12) {
|
|
|
|
count += 1;
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
currentCount = count;
|
2014-10-31 20:02:29 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public TLObject getItem(int i) {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (onlineContacts != null && (dialogsCount == 0 || i >= dialogsCount)) {
|
|
|
|
if (dialogsCount == 0) {
|
|
|
|
i -= 3;
|
|
|
|
} else {
|
|
|
|
i -= dialogsCount + 2;
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
if (i < 0 || i >= onlineContacts.size()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return null;
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
return MessagesController.getInstance(currentAccount).getUser(onlineContacts.get(i).user_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (showArchiveHint) {
|
|
|
|
i -= 2;
|
2021-01-28 15:15:51 +01:00
|
|
|
} else if (dialogsType == 11 || dialogsType == 13) {
|
|
|
|
i -= 2;
|
|
|
|
} else if (dialogsType == 12) {
|
|
|
|
i -= 1;
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
ArrayList<TLRPC.Dialog> arrayList = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (hasHints) {
|
2018-07-30 04:07:02 +02:00
|
|
|
int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
|
2017-12-08 18:35:59 +01:00
|
|
|
if (i < 2 + count) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return MessagesController.getInstance(currentAccount).hintDialogs.get(i - 1);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
|
|
|
i -= count + 2;
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (i < 0 || i >= arrayList.size()) {
|
|
|
|
return null;
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return arrayList.get(i);
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public void sortOnlineContacts(boolean notify) {
|
2020-01-23 07:15:40 +01:00
|
|
|
if (onlineContacts == null || notify && (SystemClock.elapsedRealtime() - lastSortTime) < 2000) {
|
2019-07-18 15:01:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-01-23 07:15:40 +01:00
|
|
|
lastSortTime = SystemClock.elapsedRealtime();
|
2019-07-18 15:01:39 +02:00
|
|
|
try {
|
|
|
|
int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
|
|
|
|
MessagesController messagesController = MessagesController.getInstance(currentAccount);
|
|
|
|
Collections.sort(onlineContacts, (o1, o2) -> {
|
|
|
|
TLRPC.User user1 = messagesController.getUser(o2.user_id);
|
|
|
|
TLRPC.User user2 = messagesController.getUser(o1.user_id);
|
|
|
|
int status1 = 0;
|
|
|
|
int status2 = 0;
|
|
|
|
if (user1 != null) {
|
|
|
|
if (user1.self) {
|
|
|
|
status1 = currentTime + 50000;
|
|
|
|
} else if (user1.status != null) {
|
|
|
|
status1 = user1.status.expires;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (user2 != null) {
|
|
|
|
if (user2.self) {
|
|
|
|
status2 = currentTime + 50000;
|
|
|
|
} else if (user2.status != null) {
|
|
|
|
status2 = user2.status.expires;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (status1 > 0 && status2 > 0) {
|
|
|
|
if (status1 > status2) {
|
|
|
|
return 1;
|
|
|
|
} else if (status1 < status2) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else if (status1 < 0 && status2 < 0) {
|
|
|
|
if (status1 > status2) {
|
|
|
|
return 1;
|
|
|
|
} else if (status1 < status2) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else if (status1 < 0 && status2 > 0 || status1 == 0 && status2 != 0) {
|
|
|
|
return -1;
|
2021-01-28 15:15:51 +01:00
|
|
|
} else if (status2 < 0 || status1 != 0) {
|
2019-07-18 15:01:39 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
if (notify) {
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void setDialogsListFrozen(boolean frozen) {
|
|
|
|
dialogsListFrozen = frozen;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ViewPager getArchiveHintCellPager() {
|
|
|
|
return archiveHintCell != null ? archiveHintCell.getViewPager() : null;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
@Override
|
|
|
|
public void notifyDataSetChanged() {
|
2019-05-14 14:08:05 +02:00
|
|
|
hasHints = folderId == 0 && dialogsType == 0 && !isOnlySelect && !MessagesController.getInstance(currentAccount).hintDialogs.isEmpty();
|
2017-12-08 18:35:59 +01:00
|
|
|
super.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
@Override
|
|
|
|
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
|
|
|
|
if (holder.itemView instanceof DialogCell) {
|
2019-05-14 14:08:05 +02:00
|
|
|
DialogCell dialogCell = (DialogCell) holder.itemView;
|
|
|
|
dialogCell.onReorderStateChanged(isReordering, false);
|
|
|
|
int position = fixPosition(holder.getAdapterPosition());
|
|
|
|
dialogCell.setDialogIndex(position);
|
|
|
|
dialogCell.checkCurrentDialogIndex(dialogsListFrozen);
|
|
|
|
dialogCell.setChecked(selectedDialogs.contains(dialogCell.getDialogId()), false);
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
2017-12-08 18:35:59 +01:00
|
|
|
int viewType = holder.getItemViewType();
|
2021-01-28 15:15:51 +01:00
|
|
|
return viewType != 1 && viewType != 5 && viewType != 3 && viewType != 8 && viewType != 7 && viewType != 9 && viewType != 10 && viewType != 11;
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
2017-12-08 18:35:59 +01:00
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
2021-09-20 07:54:41 +02:00
|
|
|
DialogCell dialogCell = new DialogCell(parentFragment, mContext, true, false, currentAccount, null);
|
2019-12-31 14:08:08 +01:00
|
|
|
dialogCell.setArchivedPullAnimation(pullForegroundDrawable);
|
2020-12-23 08:48:30 +01:00
|
|
|
dialogCell.setPreloader(preloader);
|
2019-12-31 14:08:08 +01:00
|
|
|
view = dialogCell;
|
2017-12-08 18:35:59 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-01-28 15:15:51 +01:00
|
|
|
FlickerLoadingView flickerLoadingView = new FlickerLoadingView(mContext);
|
|
|
|
flickerLoadingView.setIsSingleCell(true);
|
|
|
|
flickerLoadingView.setViewType(FlickerLoadingView.DIALOG_CELL_TYPE);
|
|
|
|
view = flickerLoadingView;
|
2017-12-08 18:35:59 +01:00
|
|
|
break;
|
2018-07-30 04:07:02 +02:00
|
|
|
case 2: {
|
2017-12-08 18:35:59 +01:00
|
|
|
HeaderCell headerCell = new HeaderCell(mContext);
|
|
|
|
headerCell.setText(LocaleController.getString("RecentlyViewed", R.string.RecentlyViewed));
|
|
|
|
|
|
|
|
TextView textView = new TextView(mContext);
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
|
|
|
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
|
|
|
|
textView.setText(LocaleController.getString("RecentlyViewedHide", R.string.RecentlyViewedHide));
|
|
|
|
textView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL);
|
|
|
|
headerCell.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, 17, 15, 17, 0));
|
2018-08-27 10:33:11 +02:00
|
|
|
textView.setOnClickListener(view1 -> {
|
|
|
|
MessagesController.getInstance(currentAccount).hintDialogs.clear();
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
preferences.edit().remove("installReferer").commit();
|
|
|
|
notifyDataSetChanged();
|
2017-12-08 18:35:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
view = headerCell;
|
|
|
|
break;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
case 3:
|
|
|
|
FrameLayout frameLayout = new FrameLayout(mContext) {
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(12), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
|
|
|
|
View v = new View(mContext);
|
|
|
|
v.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
frameLayout.addView(v, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
view = frameLayout;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
view = new DialogMeUrlCell(mContext);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
view = new DialogsEmptyCell(mContext);
|
|
|
|
break;
|
2018-07-30 04:07:02 +02:00
|
|
|
case 6:
|
|
|
|
view = new UserCell(mContext, 8, 0, false);
|
|
|
|
break;
|
|
|
|
case 7:
|
2021-01-28 15:15:51 +01:00
|
|
|
view = new HeaderCell(mContext);
|
2018-07-30 04:07:02 +02:00
|
|
|
break;
|
2021-01-28 15:15:51 +01:00
|
|
|
case 8: {
|
2018-07-30 04:07:02 +02:00
|
|
|
view = new ShadowSectionCell(mContext);
|
|
|
|
Drawable drawable = Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
|
|
|
|
CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
|
|
|
|
combinedDrawable.setFullsize(true);
|
|
|
|
view.setBackgroundDrawable(combinedDrawable);
|
|
|
|
break;
|
2021-01-28 15:15:51 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
case 9:
|
|
|
|
view = archiveHintCell;
|
|
|
|
if (archiveHintCell.getParent() != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) archiveHintCell.getParent();
|
|
|
|
parent.removeView(archiveHintCell);
|
|
|
|
}
|
|
|
|
break;
|
2021-01-28 15:15:51 +01:00
|
|
|
case 10: {
|
2021-03-19 11:25:58 +01:00
|
|
|
view = new LastEmptyView(mContext);
|
2021-01-28 15:15:51 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 11: {
|
|
|
|
view = new TextInfoPrivacyCell(mContext) {
|
|
|
|
|
|
|
|
private int movement;
|
|
|
|
private float moveProgress;
|
|
|
|
private long lastUpdateTime;
|
2021-07-15 16:24:57 +02:00
|
|
|
private int originalX;
|
|
|
|
private int originalY;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void afterTextDraw() {
|
|
|
|
if (arrowDrawable != null) {
|
|
|
|
Rect bounds = arrowDrawable.getBounds();
|
|
|
|
arrowDrawable.setBounds(originalX, originalY, originalX + bounds.width(), originalY + bounds.height());
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onTextDraw() {
|
|
|
|
if (arrowDrawable != null) {
|
|
|
|
Rect bounds = arrowDrawable.getBounds();
|
|
|
|
int dx = (int) (moveProgress * AndroidUtilities.dp(3));
|
2021-07-15 16:24:57 +02:00
|
|
|
originalX = bounds.left;
|
|
|
|
originalY = bounds.top;
|
|
|
|
arrowDrawable.setBounds(originalX + dx, originalY + AndroidUtilities.dp(1), originalX + dx + bounds.width(), originalY + AndroidUtilities.dp(1) + bounds.height());
|
2021-01-28 15:15:51 +01:00
|
|
|
|
|
|
|
long newUpdateTime = SystemClock.elapsedRealtime();
|
|
|
|
long dt = newUpdateTime - lastUpdateTime;
|
|
|
|
if (dt > 17) {
|
|
|
|
dt = 17;
|
|
|
|
}
|
|
|
|
lastUpdateTime = newUpdateTime;
|
|
|
|
if (movement == 0) {
|
|
|
|
moveProgress += dt / 664.0f;
|
|
|
|
if (moveProgress >= 1.0f) {
|
|
|
|
movement = 1;
|
|
|
|
moveProgress = 1.0f;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
moveProgress -= dt / 664.0f;
|
|
|
|
if (moveProgress <= 0.0f) {
|
|
|
|
movement = 0;
|
|
|
|
moveProgress = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getTextView().invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Drawable drawable = Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
|
|
|
|
CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
|
|
|
|
combinedDrawable.setFullsize(true);
|
|
|
|
view.setBackgroundDrawable(combinedDrawable);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
default: {
|
|
|
|
view = new TextCell(mContext);
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, viewType == 5 ? RecyclerView.LayoutParams.MATCH_PARENT : RecyclerView.LayoutParams.WRAP_CONTENT));
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-12-08 18:35:59 +01:00
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0: {
|
|
|
|
DialogCell cell = (DialogCell) holder.itemView;
|
2019-05-14 14:08:05 +02:00
|
|
|
TLRPC.Dialog dialog = (TLRPC.Dialog) getItem(i);
|
|
|
|
TLRPC.Dialog nextDialog = (TLRPC.Dialog) getItem(i + 1);
|
2021-01-28 15:15:51 +01:00
|
|
|
cell.useSeparator = nextDialog != null;
|
2019-01-23 18:03:33 +01:00
|
|
|
cell.fullSeparator = dialog.pinned && nextDialog != null && !nextDialog.pinned;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (dialogsType == 0) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
cell.setDialogSelected(dialog.id == openedDialogId);
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
cell.setChecked(selectedDialogs.contains(dialog.id), false);
|
|
|
|
cell.setDialog(dialog, dialogsType, folderId);
|
2020-12-23 08:48:30 +01:00
|
|
|
if (preloader != null && i < 10) {
|
|
|
|
preloader.add(dialog.id);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
case 5: {
|
|
|
|
DialogsEmptyCell cell = (DialogsEmptyCell) holder.itemView;
|
2020-03-30 14:00:09 +02:00
|
|
|
if (dialogsType == 7 || dialogsType == 8) {
|
|
|
|
if (MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId)) {
|
|
|
|
cell.setType(2);
|
|
|
|
} else {
|
|
|
|
cell.setType(3);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cell.setType(onlineContacts != null ? 1 : 0);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
case 4: {
|
|
|
|
DialogMeUrlCell cell = (DialogMeUrlCell) holder.itemView;
|
|
|
|
cell.setRecentMeUrl((TLRPC.RecentMeUrl) getItem(i));
|
|
|
|
break;
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
case 6: {
|
|
|
|
UserCell cell = (UserCell) holder.itemView;
|
2021-01-28 15:15:51 +01:00
|
|
|
int position;
|
|
|
|
if (dialogsCount == 0) {
|
|
|
|
position = i - 3;
|
|
|
|
} else {
|
|
|
|
position = i - dialogsCount - 2;
|
|
|
|
}
|
|
|
|
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(onlineContacts.get(position).user_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
cell.setData(user, null, null, 0);
|
|
|
|
break;
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
case 7: {
|
|
|
|
HeaderCell cell = (HeaderCell) holder.itemView;
|
|
|
|
if (dialogsType == 11 || dialogsType == 12 || dialogsType == 13) {
|
|
|
|
if (i == 0) {
|
|
|
|
cell.setText(LocaleController.getString("ImportHeader", R.string.ImportHeader));
|
|
|
|
} else {
|
|
|
|
cell.setText(LocaleController.getString("ImportHeaderContacts", R.string.ImportHeaderContacts));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cell.setText(LocaleController.getString("YourContacts", R.string.YourContacts));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 11: {
|
|
|
|
TextInfoPrivacyCell cell = (TextInfoPrivacyCell) holder.itemView;
|
|
|
|
cell.setText(LocaleController.getString("TapOnThePencil", R.string.TapOnThePencil));
|
|
|
|
if (arrowDrawable == null) {
|
|
|
|
arrowDrawable = mContext.getResources().getDrawable(R.drawable.arrow_newchat);
|
|
|
|
arrowDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4), PorterDuff.Mode.MULTIPLY));
|
|
|
|
}
|
|
|
|
TextView textView = cell.getTextView();
|
|
|
|
textView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
|
|
|
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, arrowDrawable, null);
|
|
|
|
textView.getLayoutParams().width = LayoutHelper.WRAP_CONTENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 12: {
|
|
|
|
TextCell cell = (TextCell) holder.itemView;
|
|
|
|
cell.setColors(Theme.key_windowBackgroundWhiteBlueText4, Theme.key_windowBackgroundWhiteBlueText4);
|
|
|
|
cell.setTextAndIcon(LocaleController.getString("CreateGroupForImport", R.string.CreateGroupForImport), R.drawable.groups_create, dialogsCount != 0);
|
|
|
|
cell.setIsInDialogs();
|
|
|
|
cell.setOffsetFromImage(75);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
2019-07-18 15:01:39 +02:00
|
|
|
if (onlineContacts != null) {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (dialogsCount == 0) {
|
|
|
|
if (i == 0) {
|
|
|
|
return 5;
|
|
|
|
} else if (i == 1) {
|
|
|
|
return 8;
|
|
|
|
} else if (i == 2) {
|
|
|
|
return 7;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (i < dialogsCount) {
|
|
|
|
return 0;
|
|
|
|
} else if (i == dialogsCount) {
|
|
|
|
return 8;
|
|
|
|
} else if (i == dialogsCount + 1) {
|
|
|
|
return 7;
|
|
|
|
} else if (i == currentCount - 1) {
|
|
|
|
return 10;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
return 6;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (hasHints) {
|
|
|
|
int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
|
2017-12-08 18:35:59 +01:00
|
|
|
if (i < 2 + count) {
|
|
|
|
if (i == 0) {
|
|
|
|
return 2;
|
|
|
|
} else if (i == 1 + count) {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
i -= 2 + count;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (showArchiveHint) {
|
|
|
|
if (i == 0) {
|
|
|
|
return 9;
|
|
|
|
} else if (i == 1) {
|
|
|
|
return 8;
|
|
|
|
} else {
|
|
|
|
i -= 2;
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
} else if (dialogsType == 11 || dialogsType == 13) {
|
|
|
|
if (i == 0) {
|
|
|
|
return 7;
|
|
|
|
} else if (i == 1) {
|
|
|
|
return 12;
|
|
|
|
} else {
|
|
|
|
i -= 2;
|
|
|
|
}
|
|
|
|
} else if (dialogsType == 12) {
|
|
|
|
if (i == 0) {
|
|
|
|
return 7;
|
|
|
|
} else {
|
|
|
|
i -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (folderId == 0 && dialogsCount > 10 && i == currentCount - 2 && dialogsType == 0) {
|
|
|
|
return 11;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
int size = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen).size();
|
2019-05-14 14:08:05 +02:00
|
|
|
if (i == size) {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (!forceShowEmptyCell && dialogsType != 7 && dialogsType != 8 && !MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId)) {
|
2017-12-08 18:35:59 +01:00
|
|
|
return 1;
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (size == 0) {
|
2017-12-08 18:35:59 +01:00
|
|
|
return 5;
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
|
|
|
return 10;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (i > size) {
|
|
|
|
return 10;
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyItemMoved(int fromPosition, int toPosition) {
|
2021-01-28 15:15:51 +01:00
|
|
|
ArrayList<TLRPC.Dialog> dialogs = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, false);
|
2019-05-14 14:08:05 +02:00
|
|
|
int fromIndex = fixPosition(fromPosition);
|
|
|
|
int toIndex = fixPosition(toPosition);
|
|
|
|
TLRPC.Dialog fromDialog = dialogs.get(fromIndex);
|
|
|
|
TLRPC.Dialog toDialog = dialogs.get(toIndex);
|
2020-03-30 14:00:09 +02:00
|
|
|
if (dialogsType == 7 || dialogsType == 8) {
|
|
|
|
MessagesController.DialogFilter filter = MessagesController.getInstance(currentAccount).selectedDialogFilter[dialogsType == 8 ? 1 : 0];
|
|
|
|
int idx1 = filter.pinnedDialogs.get(fromDialog.id);
|
|
|
|
int idx2 = filter.pinnedDialogs.get(toDialog.id);
|
|
|
|
filter.pinnedDialogs.put(fromDialog.id, idx2);
|
|
|
|
filter.pinnedDialogs.put(toDialog.id, idx1);
|
|
|
|
} else {
|
|
|
|
int oldNum = fromDialog.pinnedNum;
|
|
|
|
fromDialog.pinnedNum = toDialog.pinnedNum;
|
|
|
|
toDialog.pinnedNum = oldNum;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
Collections.swap(dialogs, fromIndex, toIndex);
|
|
|
|
super.notifyItemMoved(fromPosition, toPosition);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
public void setArchivedPullDrawable(PullForegroundDrawable drawable) {
|
|
|
|
pullForegroundDrawable = drawable;
|
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
|
|
|
|
public void didDatabaseCleared() {
|
|
|
|
if (preloader != null) {
|
|
|
|
preloader.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resume() {
|
|
|
|
if (preloader != null) {
|
|
|
|
preloader.resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pause() {
|
|
|
|
if (preloader != null) {
|
|
|
|
preloader.pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class DialogsPreloader {
|
|
|
|
|
|
|
|
private final int MAX_REQUEST_COUNT = 4;
|
|
|
|
private final int MAX_NETWORK_REQUEST_COUNT = 10 - MAX_REQUEST_COUNT;
|
|
|
|
private final int NETWORK_REQUESTS_RESET_TIME = 60_000;
|
|
|
|
|
|
|
|
HashSet<Long> dialogsReadyMap = new HashSet<>();
|
|
|
|
HashSet<Long> preloadedErrorMap = new HashSet<>();
|
|
|
|
|
|
|
|
HashSet<Long> loadingDialogs = new HashSet<>();
|
|
|
|
ArrayList<Long> preloadDialogsPool = new ArrayList<>();
|
|
|
|
int currentRequestCount;
|
|
|
|
int networkRequestCount;
|
|
|
|
|
|
|
|
boolean resumed;
|
|
|
|
|
|
|
|
Runnable clearNetworkRequestCount = () -> {
|
|
|
|
networkRequestCount = 0;
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
public void add(long dialog_id) {
|
|
|
|
if (isReady(dialog_id) || preloadedErrorMap.contains(dialog_id) || loadingDialogs.contains(dialog_id) || preloadDialogsPool.contains(dialog_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
preloadDialogsPool.add(dialog_id);
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void start() {
|
|
|
|
if (!preloadIsAvilable() || !resumed || preloadDialogsPool.isEmpty() || currentRequestCount >= MAX_REQUEST_COUNT || networkRequestCount > MAX_NETWORK_REQUEST_COUNT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
long dialog_id = preloadDialogsPool.remove(0);
|
|
|
|
currentRequestCount++;
|
|
|
|
loadingDialogs.add(dialog_id);
|
|
|
|
MessagesController.getInstance(UserConfig.selectedAccount).ensureMessagesLoaded(dialog_id, 0, new MessagesController.MessagesLoadedCallback() {
|
|
|
|
@Override
|
|
|
|
public void onMessagesLoaded(boolean fromCache) {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (!fromCache) {
|
|
|
|
networkRequestCount++;
|
|
|
|
if (networkRequestCount >= MAX_NETWORK_REQUEST_COUNT) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(clearNetworkRequestCount);
|
|
|
|
AndroidUtilities.runOnUIThread(clearNetworkRequestCount, NETWORK_REQUESTS_RESET_TIME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (loadingDialogs.remove(dialog_id)) {
|
|
|
|
dialogsReadyMap.add(dialog_id);
|
|
|
|
updateList();
|
|
|
|
currentRequestCount--;
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError() {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (loadingDialogs.remove(dialog_id)) {
|
|
|
|
preloadedErrorMap.add(dialog_id);
|
|
|
|
currentRequestCount--;
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean preloadIsAvilable() {
|
|
|
|
return false;
|
|
|
|
// return DownloadController.getInstance(UserConfig.selectedAccount).getCurrentDownloadMask() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateList() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isReady(long currentDialogId) {
|
|
|
|
return dialogsReadyMap.contains(currentDialogId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean preloadedError(long currendDialogId) {
|
|
|
|
return preloadedErrorMap.contains(currendDialogId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void remove(long currentDialogId) {
|
|
|
|
preloadDialogsPool.remove(currentDialogId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clear() {
|
|
|
|
dialogsReadyMap.clear();
|
|
|
|
preloadedErrorMap.clear();
|
|
|
|
loadingDialogs.clear();
|
|
|
|
preloadDialogsPool.clear();
|
|
|
|
currentRequestCount = 0;
|
|
|
|
networkRequestCount = 0;
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(clearNetworkRequestCount);
|
|
|
|
updateList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resume() {
|
|
|
|
resumed = true;
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pause() {
|
|
|
|
resumed = false;
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
|
|
|
|
public int getCurrentCount() {
|
|
|
|
return currentCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setForceShowEmptyCell(boolean forceShowEmptyCell) {
|
|
|
|
this.forceShowEmptyCell = forceShowEmptyCell;
|
|
|
|
}
|
2021-03-19 11:25:58 +01:00
|
|
|
|
|
|
|
public class LastEmptyView extends View {
|
|
|
|
|
|
|
|
public boolean moving;
|
|
|
|
|
|
|
|
public LastEmptyView(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int size = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen).size();
|
|
|
|
boolean hasArchive = dialogsType == 0 && MessagesController.getInstance(currentAccount).dialogs_dict.get(DialogObject.makeFolderDialogId(1)) != null;
|
|
|
|
View parent = (View) getParent();
|
|
|
|
int height;
|
|
|
|
int paddingTop = parent.getPaddingTop();
|
|
|
|
if (size == 0 || paddingTop == 0 && !hasArchive) {
|
|
|
|
height = 0;
|
|
|
|
} else {
|
|
|
|
height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
if (height == 0) {
|
|
|
|
height = parent.getMeasuredHeight();
|
|
|
|
}
|
|
|
|
if (height == 0) {
|
|
|
|
height = AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
|
|
|
}
|
|
|
|
int cellHeight = AndroidUtilities.dp(SharedConfig.useThreeLinesLayout ? 78 : 72);
|
|
|
|
int dialogsHeight = size * cellHeight + (size - 1);
|
|
|
|
if (onlineContacts != null) {
|
|
|
|
dialogsHeight += onlineContacts.size() * AndroidUtilities.dp(58) + (onlineContacts.size() - 1) + AndroidUtilities.dp(52);
|
|
|
|
}
|
|
|
|
int archiveHeight = (hasArchive ? cellHeight + 1 : 0);
|
|
|
|
if (dialogsHeight < height) {
|
|
|
|
height = height - dialogsHeight + archiveHeight;
|
|
|
|
if (paddingTop != 0) {
|
|
|
|
height -= AndroidUtilities.statusBarHeight;
|
|
|
|
if (height < 0) {
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dialogsHeight - height < archiveHeight) {
|
|
|
|
height = archiveHeight - (dialogsHeight - height);
|
|
|
|
if (paddingTop != 0) {
|
|
|
|
height -= AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
|
|
|
if (height < 0) {
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), height);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-10-31 20:02:29 +01:00
|
|
|
}
|