feat: 'add to folder' menu entry in chat profile

Thanks to @nekox_broken

Co-authored-by: dic1911 <d69873@gmail.com>
This commit is contained in:
xtaodada 2024-10-23 23:19:54 +08:00
parent 7fab9933af
commit b8f93a2fa0
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 77 additions and 2 deletions

View File

@ -61,9 +61,9 @@ public class FiltersListBottomSheet extends BottomSheet implements NotificationC
} }
private final ArrayList<Long> selectedDialogs; private final ArrayList<Long> selectedDialogs;
private final DialogsActivity fragment; private final BaseFragment fragment;
public FiltersListBottomSheet(DialogsActivity baseFragment, ArrayList<Long> selectedDialogs) { public FiltersListBottomSheet(BaseFragment baseFragment, ArrayList<Long> selectedDialogs) {
super(baseFragment.getParentActivity(), false); super(baseFragment.getParentActivity(), false);
this.selectedDialogs = selectedDialogs; this.selectedDialogs = selectedDialogs;
this.fragment = baseFragment; this.fragment = baseFragment;
@ -330,6 +330,12 @@ public class FiltersListBottomSheet extends BottomSheet implements NotificationC
delegate = filtersListBottomSheetDelegate; delegate = filtersListBottomSheetDelegate;
} }
public static ArrayList<MessagesController.DialogFilter> getCanAddDialogFilters(BaseFragment fragment, Long dialogId) {
var arrays = new ArrayList<Long>(1);
arrays.add(dialogId);
return getCanAddDialogFilters(fragment, arrays);
}
public static ArrayList<MessagesController.DialogFilter> getCanAddDialogFilters(BaseFragment fragment, ArrayList<Long> selectedDialogs) { public static ArrayList<MessagesController.DialogFilter> getCanAddDialogFilters(BaseFragment fragment, ArrayList<Long> selectedDialogs) {
ArrayList<MessagesController.DialogFilter> result = new ArrayList<>(); ArrayList<MessagesController.DialogFilter> result = new ArrayList<>();
ArrayList<MessagesController.DialogFilter> filters = fragment.getMessagesController().dialogFilters; ArrayList<MessagesController.DialogFilter> filters = fragment.getMessagesController().dialogFilters;

View File

@ -230,6 +230,7 @@ import org.telegram.ui.Components.DotDividerSpan;
import org.telegram.ui.Components.EditTextBoldCursor; import org.telegram.ui.Components.EditTextBoldCursor;
import org.telegram.ui.Components.EmojiPacksAlert; import org.telegram.ui.Components.EmojiPacksAlert;
import org.telegram.ui.Components.EmptyStubSpan; import org.telegram.ui.Components.EmptyStubSpan;
import org.telegram.ui.Components.FiltersListBottomSheet;
import org.telegram.ui.Components.FloatingDebug.FloatingDebugController; import org.telegram.ui.Components.FloatingDebug.FloatingDebugController;
import org.telegram.ui.Components.Forum.ForumUtilities; import org.telegram.ui.Components.Forum.ForumUtilities;
import org.telegram.ui.Components.FragmentContextView; import org.telegram.ui.Components.FragmentContextView;
@ -580,6 +581,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
private final static int event_log = 102; private final static int event_log = 102;
private final static int message_filter = 103; private final static int message_filter = 103;
private final static int clear_cache = 104; private final static int clear_cache = 104;
private final static int add_to_folder = 105;
private Rect rect = new Rect(); private Rect rect = new Rect();
@ -2803,6 +2805,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
args.putLong("dialog_id", userId != 0 ? dialogId : -chatId); args.putLong("dialog_id", userId != 0 ? dialogId : -chatId);
CacheControlActivity fragment = new CacheControlActivity(args); CacheControlActivity fragment = new CacheControlActivity(args);
presentFragment(fragment); presentFragment(fragment);
} else if (id == add_to_folder) {
showAddCurrentChatToFolderSheet();
} }
} }
}); });
@ -10701,6 +10705,9 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
if (selfUser && !myProfile) { if (selfUser && !myProfile) {
otherItem.addSubItem(logout, R.drawable.msg_leave, LocaleController.getString(R.string.LogOut)); otherItem.addSubItem(logout, R.drawable.msg_leave, LocaleController.getString(R.string.LogOut));
} else { } else {
if (getDialogId() != 0 && !FiltersListBottomSheet.getCanAddDialogFilters(this, getDialogId()).isEmpty()) {
otherItem.addSubItem(add_to_folder, R.drawable.msg_folders, LocaleController.getString(R.string.FilterAddTo));
}
otherItem.addSubItem(clear_cache, R.drawable.msg_delete, LocaleController.getString(R.string.ClearCache)); otherItem.addSubItem(clear_cache, R.drawable.msg_delete, LocaleController.getString(R.string.ClearCache));
} }
if (!isPulledDown) { if (!isPulledDown) {
@ -14502,6 +14509,68 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
return true; return true;
} }
private void showAddCurrentChatToFolderSheet() {
ArrayList<Long> selectedDialogs = new ArrayList<>(1);
selectedDialogs.add(getDialogId());
FiltersListBottomSheet sheet = new FiltersListBottomSheet(ProfileActivity.this, selectedDialogs);
sheet.setDelegate((filter, checked) -> {
ArrayList<Long> alwaysShow = FiltersListBottomSheet.getDialogsCount(ProfileActivity.this, filter, selectedDialogs, true, false);
if (!checked) {
int currentCount;
if (filter != null) {
currentCount = filter.alwaysShow.size();
} else {
currentCount = 0;
}
int totalCount = currentCount + alwaysShow.size();
if ((totalCount > getMessagesController().dialogFiltersChatsLimitDefault && !getUserConfig().isPremium()) || totalCount > getMessagesController().dialogFiltersChatsLimitPremium) {
showDialog(new LimitReachedBottomSheet(ProfileActivity.this, fragmentView.getContext(), LimitReachedBottomSheet.TYPE_CHATS_IN_FOLDER, currentAccount, null));
return;
}
}
if (filter != null) {
if (checked) {
for (int a = 0; a < selectedDialogs.size(); a++) {
filter.neverShow.add(selectedDialogs.get(a));
filter.alwaysShow.remove(selectedDialogs.get(a));
}
FilterCreateActivity.saveFilterToServer(filter, filter.flags, filter.emoticon, filter.name, filter.color, filter.alwaysShow, filter.neverShow, filter.pinnedDialogs, false, false, true, true, false, ProfileActivity.this, null);
long did;
if (selectedDialogs.size() == 1) {
did = selectedDialogs.get(0);
} else {
did = 0;
}
final UndoView undoView = getUndoView();
if (undoView != null) {
undoView.showWithAction(did, UndoView.ACTION_REMOVED_FROM_FOLDER, selectedDialogs.size(), filter, null, null);
}
} else {
if (!alwaysShow.isEmpty()) {
for (int a = 0; a < alwaysShow.size(); a++) {
filter.neverShow.remove(alwaysShow.get(a));
}
filter.alwaysShow.addAll(alwaysShow);
FilterCreateActivity.saveFilterToServer(filter, filter.flags, filter.emoticon, filter.name, filter.color, filter.alwaysShow, filter.neverShow, filter.pinnedDialogs, false, false, true, true, false, ProfileActivity.this, null);
}
long did;
if (alwaysShow.size() == 1) {
did = alwaysShow.get(0);
} else {
did = 0;
}
final UndoView undoView = getUndoView();
if (undoView != null) {
undoView.showWithAction(did, UndoView.ACTION_ADDED_TO_FOLDER, alwaysShow.size(), filter, null, null);
}
}
} else {
presentFragment(new FilterCreateActivity(null, alwaysShow));
}
});
showDialog(sheet);
}
private void updateItemsUsername() { private void updateItemsUsername() {
if (!myProfile) return; if (!myProfile) return;
TLRPC.User user = getMessagesController().getUser(userId); TLRPC.User user = getMessagesController().getUser(userId);