diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/FiltersListBottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/FiltersListBottomSheet.java index 0ff2685f4..160aa07e2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/FiltersListBottomSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/FiltersListBottomSheet.java @@ -61,9 +61,9 @@ public class FiltersListBottomSheet extends BottomSheet implements NotificationC } private final ArrayList selectedDialogs; - private final DialogsActivity fragment; + private final BaseFragment fragment; - public FiltersListBottomSheet(DialogsActivity baseFragment, ArrayList selectedDialogs) { + public FiltersListBottomSheet(BaseFragment baseFragment, ArrayList selectedDialogs) { super(baseFragment.getParentActivity(), false); this.selectedDialogs = selectedDialogs; this.fragment = baseFragment; @@ -330,6 +330,12 @@ public class FiltersListBottomSheet extends BottomSheet implements NotificationC delegate = filtersListBottomSheetDelegate; } + public static ArrayList getCanAddDialogFilters(BaseFragment fragment, Long dialogId) { + var arrays = new ArrayList(1); + arrays.add(dialogId); + return getCanAddDialogFilters(fragment, arrays); + } + public static ArrayList getCanAddDialogFilters(BaseFragment fragment, ArrayList selectedDialogs) { ArrayList result = new ArrayList<>(); ArrayList filters = fragment.getMessagesController().dialogFilters; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index b2da2e990..cc4dae9c3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -230,6 +230,7 @@ import org.telegram.ui.Components.DotDividerSpan; import org.telegram.ui.Components.EditTextBoldCursor; import org.telegram.ui.Components.EmojiPacksAlert; import org.telegram.ui.Components.EmptyStubSpan; +import org.telegram.ui.Components.FiltersListBottomSheet; import org.telegram.ui.Components.FloatingDebug.FloatingDebugController; import org.telegram.ui.Components.Forum.ForumUtilities; 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 message_filter = 103; private final static int clear_cache = 104; + private final static int add_to_folder = 105; private Rect rect = new Rect(); @@ -2803,6 +2805,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. args.putLong("dialog_id", userId != 0 ? dialogId : -chatId); CacheControlActivity fragment = new CacheControlActivity(args); presentFragment(fragment); + } else if (id == add_to_folder) { + showAddCurrentChatToFolderSheet(); } } }); @@ -10701,6 +10705,9 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (selfUser && !myProfile) { otherItem.addSubItem(logout, R.drawable.msg_leave, LocaleController.getString(R.string.LogOut)); } 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)); } if (!isPulledDown) { @@ -14502,6 +14509,68 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. return true; } + private void showAddCurrentChatToFolderSheet() { + ArrayList selectedDialogs = new ArrayList<>(1); + selectedDialogs.add(getDialogId()); + FiltersListBottomSheet sheet = new FiltersListBottomSheet(ProfileActivity.this, selectedDialogs); + sheet.setDelegate((filter, checked) -> { + ArrayList 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() { if (!myProfile) return; TLRPC.User user = getMessagesController().getUser(userId);