NekoX/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java

531 lines
22 KiB
Java
Raw Normal View History

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;
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
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;
2014-11-19 02:23:46 +01:00
import org.telegram.ui.Cells.LoadingCell;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.Cells.ShadowSectionCell;
import org.telegram.ui.Cells.UserCell;
2019-12-31 14:08:08 +01:00
import org.telegram.ui.Components.PullForegroundDrawable;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.Components.CombinedDrawable;
2017-12-08 18:35:59 +01:00
import org.telegram.ui.Components.LayoutHelper;
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;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
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;
private int prevContactsCount;
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;
private int currentCount;
2017-12-08 18:35:59 +01:00
private boolean isOnlySelect;
private ArrayList<Long> selectedDialogs;
private boolean hasHints;
2018-07-30 04:07:02 +02:00
private int currentAccount = UserConfig.selectedAccount;
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
2019-05-14 14:08:05 +02:00
public DialogsAdapter(Context context, int type, int folder, boolean onlySelect) {
2014-10-31 20:02:29 +01:00
mContext = context;
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;
selectedDialogs = new ArrayList<>();
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
}
2014-10-31 20:02:29 +01:00
}
public void setOpenedDialogId(long id) {
openedDialogId = id;
}
2017-12-08 18:35:59 +01:00
public boolean hasSelectedDialogs() {
return selectedDialogs != null && !selectedDialogs.isEmpty();
}
2019-05-14 14:08:05 +02:00
public boolean addOrRemoveSelectedDialog(long did, View cell) {
2017-12-08 18:35:59 +01:00
if (selectedDialogs.contains(did)) {
selectedDialogs.remove(did);
if (cell instanceof DialogCell) {
((DialogCell) cell).setChecked(false, true);
}
2019-05-14 14:08:05 +02:00
return false;
2017-12-08 18:35:59 +01:00
} else {
selectedDialogs.add(did);
if (cell instanceof DialogCell) {
((DialogCell) cell).setChecked(true, true);
}
2019-05-14 14:08:05 +02:00
return true;
2017-12-08 18:35:59 +01:00
}
}
public ArrayList<Long> getSelectedDialogs() {
return selectedDialogs;
}
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;
}
return position;
}
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
}
@Override
2015-05-21 23:27:27 +02:00
public int getItemCount() {
2019-05-14 14:08:05 +02:00
ArrayList<TLRPC.Dialog> array = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
2018-07-30 04:07:02 +02:00
int dialogsCount = array.size();
2019-05-14 14:08:05 +02:00
if (dialogsCount == 0 && (folderId != 0 || MessagesController.getInstance(currentAccount).isLoadingDialogs(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;
2019-05-14 14:08:05 +02:00
if (!MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId) || dialogsCount == 0) {
2014-10-31 20:02:29 +01:00
count++;
}
2019-07-18 15:01:39 +02:00
boolean hasContacts = false;
2017-12-08 18:35:59 +01:00
if (hasHints) {
2018-07-30 04:07:02 +02:00
count += 2 + MessagesController.getInstance(currentAccount).hintDialogs.size();
2019-05-14 14:08:05 +02:00
} else if (dialogsType == 0 && dialogsCount == 0 && folderId == 0) {
2018-07-30 04:07:02 +02:00
if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && ContactsController.getInstance(currentAccount).isLoadingContacts()) {
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()) {
2019-07-18 15:01:39 +02:00
if (onlineContacts == null || prevContactsCount != ContactsController.getInstance(currentAccount).contacts.size()) {
onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
prevContactsCount = onlineContacts.size();
int selfId = UserConfig.getInstance(currentAccount).clientUserId;
for (int a = 0, N = onlineContacts.size(); a < N; a++) {
if (onlineContacts.get(a).user_id == selfId) {
onlineContacts.remove(a);
break;
}
}
sortOnlineContacts(false);
}
count += onlineContacts.size() + 2;
hasContacts = true;
2018-07-30 04:07:02 +02:00
}
2017-12-08 18:35:59 +01:00
}
2019-07-18 15:01:39 +02:00
if (!hasContacts && onlineContacts != null) {
onlineContacts = null;
}
2019-05-14 14:08:05 +02:00
if (folderId == 1 && showArchiveHint) {
count += 2;
}
if (folderId == 0 && dialogsCount != 0) {
count++;
}
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) {
2019-07-18 15:01:39 +02:00
if (onlineContacts != null) {
2018-07-30 04:07:02 +02:00
i -= 3;
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;
}
ArrayList<TLRPC.Dialog> arrayList = DialogsActivity.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;
} else if (status2 < 0 && status1 > 0 || status2 == 0 && status1 != 0) {
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();
2019-05-14 14:08:05 +02:00
return viewType != 1 && viewType != 5 && viewType != 3 && viewType != 8 && viewType != 7 && viewType != 9 && viewType != 10;
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:
2019-12-31 14:08:08 +01:00
DialogCell dialogCell = new DialogCell(mContext, true, false);
dialogCell.setArchivedPullAnimation(pullForegroundDrawable);
view = dialogCell;
2017-12-08 18:35:59 +01:00
break;
case 1:
view = new LoadingCell(mContext);
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:
HeaderCell headerCell = new HeaderCell(mContext);
headerCell.setText(LocaleController.getString("YourContacts", R.string.YourContacts));
view = headerCell;
break;
case 8:
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;
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;
case 10:
default: {
view = new View(mContext) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int size = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen).size();
boolean hasArchive = MessagesController.getInstance(currentAccount).dialogs_dict.get(DialogObject.makeFolderDialogId(1)) != null;
int height;
if (size == 0 || !hasArchive) {
height = 0;
} else {
height = MeasureSpec.getSize(heightMeasureSpec);
if (height == 0) {
View parent = (View) getParent();
if (parent != null) {
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 (dialogsHeight < height) {
height = height - dialogsHeight + cellHeight + 1;
} else if (dialogsHeight - height < cellHeight + 1) {
height = cellHeight + 1 - (dialogsHeight - height);
} else {
height = 0;
}
}
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), height);
}
};
}
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);
if (folderId == 0) {
cell.useSeparator = (i != getItemCount() - 2);
} else {
cell.useSeparator = (i != getItemCount() - 1);
2017-12-08 18:35:59 +01:00
}
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);
2017-12-08 18:35:59 +01:00
break;
}
2018-07-30 04:07:02 +02:00
case 5: {
DialogsEmptyCell cell = (DialogsEmptyCell) holder.itemView;
2019-07-18 15:01:39 +02:00
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;
2019-07-18 15:01:39 +02:00
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(onlineContacts.get(i - 3).user_id);
2018-07-30 04:07:02 +02:00
cell.setData(user, null, null, 0);
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) {
2018-07-30 04:07:02 +02:00
if (i == 0) {
return 5;
} else if (i == 1) {
return 8;
} else if (i == 2) {
return 7;
} else {
return 6;
}
} 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;
}
2017-12-08 18:35:59 +01:00
}
2019-05-14 14:08:05 +02:00
int size = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen).size();
if (i == size) {
if (!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) {
ArrayList<TLRPC.Dialog> dialogs = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, false);
int fromIndex = fixPosition(fromPosition);
int toIndex = fixPosition(toPosition);
TLRPC.Dialog fromDialog = dialogs.get(fromIndex);
TLRPC.Dialog toDialog = dialogs.get(toIndex);
int oldNum = fromDialog.pinnedNum;
fromDialog.pinnedNum = toDialog.pinnedNum;
toDialog.pinnedNum = oldNum;
Collections.swap(dialogs, fromIndex, toIndex);
super.notifyItemMoved(fromPosition, toPosition);
}
2019-12-31 14:08:08 +01:00
public void setArchivedPullDrawable(PullForegroundDrawable drawable) {
pullForegroundDrawable = drawable;
}
2014-10-31 20:02:29 +01:00
}