mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-11 20:49:27 +01:00
feat: recent accessed chats
This commit is contained in:
parent
bca854c8af
commit
6f1f65d1ac
@ -8767,6 +8767,8 @@ ChatActivity extends BaseFragment implements NotificationCenter.NotificationCent
|
||||
reactionsMentionCount = dialog.unread_reactions_count;
|
||||
updateReactionsMentionButton(false);
|
||||
}
|
||||
BackButtonMenu.addToAccessedDialogs(currentAccount, currentChat, currentUser, dialog_id, dialogFolderId, dialogFilterId);
|
||||
|
||||
return fragmentView;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
@ -29,6 +30,8 @@ import org.telegram.ui.ProfileActivity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class BackButtonMenu {
|
||||
@ -350,4 +353,205 @@ public class BackButtonMenu {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NekoX: History Chats
|
||||
|
||||
public static ActionBarPopupWindow showHistory(BaseFragment thisFragment, View backButton) {
|
||||
if (thisFragment == null) {
|
||||
return null;
|
||||
}
|
||||
final ActionBarLayout parentLayout = thisFragment.getParentLayout();
|
||||
final Context context = thisFragment.getParentActivity();
|
||||
final View fragmentView = thisFragment.getFragmentView();
|
||||
if (parentLayout == null || context == null || fragmentView == null) {
|
||||
return null;
|
||||
}
|
||||
List<PulledDialog> dialogs = getRecentDialogs(thisFragment.getCurrentAccount());
|
||||
if (dialogs.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ActionBarPopupWindow.ActionBarPopupWindowLayout layout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(context, null);
|
||||
android.graphics.Rect backgroundPaddings = new Rect();
|
||||
Drawable shadowDrawable = thisFragment.getParentActivity().getResources().getDrawable(R.drawable.popup_fixed_alert).mutate();
|
||||
shadowDrawable.getPadding(backgroundPaddings);
|
||||
layout.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuBackground));
|
||||
|
||||
AtomicReference<ActionBarPopupWindow> scrimPopupWindowRef = new AtomicReference<>();
|
||||
|
||||
for (PulledDialog pDialog: dialogs) {
|
||||
final TLRPC.Chat chat = pDialog.chat;
|
||||
final TLRPC.User user = pDialog.user;
|
||||
FrameLayout cell = new FrameLayout(context);
|
||||
cell.setMinimumWidth(AndroidUtilities.dp(200));
|
||||
|
||||
BackupImageView imageView = new BackupImageView(context);
|
||||
imageView.setRoundRadius(AndroidUtilities.dp(32));
|
||||
cell.addView(imageView, LayoutHelper.createFrameRelatively(32, 32, Gravity.START | Gravity.CENTER_VERTICAL, 13, 0, 0, 0));
|
||||
|
||||
TextView titleView = new TextView(context);
|
||||
titleView.setLines(1);
|
||||
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||
titleView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
|
||||
titleView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
cell.addView(titleView, LayoutHelper.createFrameRelatively(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 59, 0, 12, 0));
|
||||
|
||||
AvatarDrawable avatarDrawable = new AvatarDrawable();
|
||||
avatarDrawable.setSmallSize(true);
|
||||
Drawable thumb = avatarDrawable;
|
||||
if (chat != null) {
|
||||
avatarDrawable.setInfo(chat);
|
||||
if (chat.photo != null && chat.photo.strippedBitmap != null) {
|
||||
thumb = chat.photo.strippedBitmap;
|
||||
}
|
||||
imageView.setImage(ImageLocation.getForChat(chat, ImageLocation.TYPE_SMALL), "50_50", thumb, chat);
|
||||
titleView.setText(chat.title);
|
||||
} else if (user != null) {
|
||||
String name;
|
||||
if (user.photo != null && user.photo.strippedBitmap != null) {
|
||||
thumb = user.photo.strippedBitmap;
|
||||
}
|
||||
if (pDialog.activity == ChatActivity.class && UserObject.isUserSelf(user)) {
|
||||
name = LocaleController.getString("SavedMessages", R.string.SavedMessages);
|
||||
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
|
||||
imageView.setImageDrawable(avatarDrawable);
|
||||
} else if (UserObject.isReplyUser(user)) {
|
||||
name = LocaleController.getString("RepliesTitle", R.string.RepliesTitle);
|
||||
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
|
||||
imageView.setImageDrawable(avatarDrawable);
|
||||
} else if (UserObject.isDeleted(user)) {
|
||||
name = LocaleController.getString("HiddenName", R.string.HiddenName);
|
||||
avatarDrawable.setInfo(user);
|
||||
imageView.setImage(ImageLocation.getForUser(user, ImageLocation.TYPE_SMALL), "50_50", avatarDrawable, user);
|
||||
} else {
|
||||
name = UserObject.getUserName(user);
|
||||
avatarDrawable.setInfo(user);
|
||||
imageView.setImage(ImageLocation.getForUser(user, ImageLocation.TYPE_SMALL), "50_50", thumb, user);
|
||||
}
|
||||
titleView.setText(name);
|
||||
}
|
||||
|
||||
cell.setBackground(Theme.getSelectorDrawable(Theme.getColor(Theme.key_listSelector), false));
|
||||
cell.setOnClickListener(e2 -> {
|
||||
if (scrimPopupWindowRef.get() != null) {
|
||||
scrimPopupWindowRef.getAndSet(null).dismiss();
|
||||
}
|
||||
if (pDialog.stackIndex >= 0) {
|
||||
Long nextFragmentDialogId = null;
|
||||
if (parentLayout == null || parentLayout.fragmentsStack == null || pDialog.stackIndex >= parentLayout.fragmentsStack.size()) {
|
||||
nextFragmentDialogId = null;
|
||||
} else {
|
||||
BaseFragment nextFragment = parentLayout.fragmentsStack.get(pDialog.stackIndex);
|
||||
if (nextFragment instanceof ChatActivity) {
|
||||
nextFragmentDialogId = ((ChatActivity) nextFragment).getDialogId();
|
||||
} else if (nextFragment instanceof ProfileActivity) {
|
||||
nextFragmentDialogId = ((ProfileActivity) nextFragment).getDialogId();
|
||||
}
|
||||
}
|
||||
if (nextFragmentDialogId != null && nextFragmentDialogId != pDialog.dialogId) {
|
||||
for (int j = parentLayout.fragmentsStack.size() - 2; j > pDialog.stackIndex; --j) {
|
||||
parentLayout.removeFragmentFromStack(j);
|
||||
}
|
||||
} else {
|
||||
if (parentLayout != null && parentLayout.fragmentsStack != null) {
|
||||
for (int j = parentLayout.fragmentsStack.size() - 2; j > pDialog.stackIndex; --j) {
|
||||
if (j >= 0 && j < parentLayout.fragmentsStack.size()) {
|
||||
parentLayout.removeFragmentFromStack(j);
|
||||
}
|
||||
}
|
||||
if (pDialog.stackIndex < parentLayout.fragmentsStack.size()) {
|
||||
parentLayout.showFragment(pDialog.stackIndex);
|
||||
parentLayout.closeLastFragment(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
goToPulledDialogWithoutRemove(thisFragment, pDialog);
|
||||
});
|
||||
layout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
|
||||
}
|
||||
|
||||
ActionBarPopupWindow scrimPopupWindow = new ActionBarPopupWindow(layout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
|
||||
scrimPopupWindowRef.set(scrimPopupWindow);
|
||||
scrimPopupWindow.setPauseNotifications(true);
|
||||
scrimPopupWindow.setDismissAnimationDuration(220);
|
||||
scrimPopupWindow.setOutsideTouchable(true);
|
||||
scrimPopupWindow.setClippingEnabled(true);
|
||||
scrimPopupWindow.setAnimationStyle(R.style.PopupContextAnimation);
|
||||
scrimPopupWindow.setFocusable(true);
|
||||
layout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
|
||||
scrimPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
|
||||
scrimPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
|
||||
scrimPopupWindow.getContentView().setFocusableInTouchMode(true);
|
||||
layout.setFitItems(true);
|
||||
|
||||
int popupX = AndroidUtilities.dp(8) - backgroundPaddings.left;
|
||||
if (AndroidUtilities.isTablet()) {
|
||||
int[] location = new int[2];
|
||||
fragmentView.getLocationInWindow(location);
|
||||
popupX += location[0];
|
||||
}
|
||||
int popupY = (int) (backButton.getBottom() - backgroundPaddings.top - AndroidUtilities.dp(8));
|
||||
scrimPopupWindow.showAtLocation(fragmentView, Gravity.LEFT | Gravity.TOP, popupX, popupY);
|
||||
|
||||
return scrimPopupWindow;
|
||||
}
|
||||
|
||||
private static LinkedList<PulledDialog> getRecentDialogs(int currentAccount) {
|
||||
LinkedList<PulledDialog> ret = recentDialogs.get(currentAccount);
|
||||
if (ret == null) {
|
||||
ret = new LinkedList<>();
|
||||
recentDialogs.put(currentAccount, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static final int maxLastAccessedDialogs = 20;
|
||||
private static final SparseArray<LinkedList<PulledDialog>> recentDialogs = new SparseArray<>();
|
||||
|
||||
public static void addToAccessedDialogs(int currentAccount, TLRPC.Chat chat, TLRPC.User user, long dialogId, int folderId, int filterId) {
|
||||
LinkedList<PulledDialog> recents = getRecentDialogs(currentAccount);
|
||||
for(int i = 0; i < recents.size(); i++) {
|
||||
if (recents.get(i).dialogId == dialogId) {
|
||||
recents.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
PulledDialog d = new PulledDialog();
|
||||
d.activity = ChatActivity.class;
|
||||
d.stackIndex = 0;
|
||||
d.dialogId = dialogId;
|
||||
d.filterId = filterId;
|
||||
d.folderId = folderId;
|
||||
d.chat = chat;
|
||||
d.user = user;
|
||||
recents.add(0, d);
|
||||
if (recents.size() > maxLastAccessedDialogs)
|
||||
recents.removeLast();
|
||||
for (int i = 1; i < recents.size(); i++) {
|
||||
recents.get(i).stackIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
private static void goToPulledDialogWithoutRemove(BaseFragment fragment, PulledDialog dialog) {
|
||||
if (dialog == null) {
|
||||
return;
|
||||
}
|
||||
if (dialog.activity == ChatActivity.class) {
|
||||
Bundle bundle = new Bundle();
|
||||
if (dialog.chat != null) {
|
||||
bundle.putLong("chat_id", dialog.chat.id);
|
||||
} else if (dialog.user != null) {
|
||||
bundle.putLong("user_id", dialog.user.id);
|
||||
}
|
||||
bundle.putInt("dialog_folder_id", dialog.folderId);
|
||||
bundle.putInt("dialog_filter_id", dialog.filterId);
|
||||
fragment.presentFragment(new ChatActivity(bundle), false);
|
||||
} else if (dialog.activity == ProfileActivity.class) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong("dialog_id", dialog.dialogId);
|
||||
fragment.presentFragment(new ProfileActivity(bundle), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,6 +148,7 @@ import org.telegram.ui.Cells.UserCell;
|
||||
import org.telegram.ui.Components.AlertsCreator;
|
||||
import org.telegram.ui.Components.AnimationProperties;
|
||||
import org.telegram.ui.Components.AvatarDrawable;
|
||||
import org.telegram.ui.Components.BackButtonMenu;
|
||||
import org.telegram.ui.Components.BackupImageView;
|
||||
import org.telegram.ui.Components.BlurredRecyclerView;
|
||||
import org.telegram.ui.Components.Bulletin;
|
||||
@ -3874,6 +3875,58 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
} else {
|
||||
showSearch(false, false, false);
|
||||
}
|
||||
View backButton = actionBar.getBackButton();
|
||||
backButton.setOnLongClickListener(e -> {
|
||||
scrimPopupWindow = BackButtonMenu.showHistory(this, backButton);
|
||||
final ActionBarPopupWindow scrimPopupWindowBack = scrimPopupWindow;
|
||||
if (scrimPopupWindow != null) {
|
||||
scrimPopupWindow.setOnDismissListener(() -> {
|
||||
if (scrimPopupWindow != scrimPopupWindowBack) {
|
||||
return;
|
||||
}
|
||||
if (scrimAnimatorSet != null) {
|
||||
scrimAnimatorSet.cancel();
|
||||
scrimAnimatorSet = null;
|
||||
}
|
||||
scrimAnimatorSet = new AnimatorSet();
|
||||
scrimViewAppearing = false;
|
||||
ArrayList<Animator> animators = new ArrayList<>();
|
||||
animators.add(ObjectAnimator.ofInt(scrimPaint, AnimationProperties.PAINT_ALPHA, 0));
|
||||
scrimAnimatorSet.playTogether(animators);
|
||||
scrimAnimatorSet.setDuration(220);
|
||||
scrimAnimatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (scrimView != null) {
|
||||
scrimView.setBackground(null);
|
||||
scrimView = null;
|
||||
}
|
||||
if (fragmentView != null) {
|
||||
fragmentView.invalidate();
|
||||
}
|
||||
}
|
||||
});
|
||||
scrimAnimatorSet.start();
|
||||
scrimPopupWindow = null;
|
||||
scrimPopupWindowItems = null;
|
||||
});
|
||||
if (scrimAnimatorSet != null) {
|
||||
scrimAnimatorSet.cancel();
|
||||
} else {
|
||||
scrimAnimatorSet = new AnimatorSet();
|
||||
}
|
||||
fragmentView.invalidate();
|
||||
scrimViewAppearing = true;
|
||||
ArrayList<Animator> animators = new ArrayList<>();
|
||||
animators.add(ObjectAnimator.ofInt(scrimPaint, AnimationProperties.PAINT_ALPHA, 0, 50));
|
||||
scrimAnimatorSet.playTogether(animators);
|
||||
scrimAnimatorSet.setDuration(150);
|
||||
scrimAnimatorSet.start();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
updateMenuButton(false);
|
||||
actionBar.setDrawBlurBackground(contentView);
|
||||
|
Loading…
Reference in New Issue
Block a user