use of org.telegram.ui.Components.FiltersListBottomSheet in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsActivity method createActionMode.
private void createActionMode(String tag) {
if (actionBar.actionModeIsExist(tag)) {
return;
}
final ActionBarMenu actionMode = actionBar.createActionMode(false, tag);
actionMode.setBackground(null);
selectedDialogsCountTextView = new NumberTextView(actionMode.getContext());
selectedDialogsCountTextView.setTextSize(18);
selectedDialogsCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedDialogsCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarActionModeDefaultIcon));
actionMode.addView(selectedDialogsCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 72, 0, 0, 0));
selectedDialogsCountTextView.setOnTouchListener((v, event) -> true);
pinItem = actionMode.addItemWithWidth(pin, R.drawable.msg_pin, AndroidUtilities.dp(54));
muteItem = actionMode.addItemWithWidth(mute, R.drawable.msg_mute, AndroidUtilities.dp(54));
archive2Item = actionMode.addItemWithWidth(archive2, R.drawable.msg_archive, AndroidUtilities.dp(54));
deleteItem = actionMode.addItemWithWidth(delete, R.drawable.msg_delete, AndroidUtilities.dp(54), LocaleController.getString("Delete", R.string.Delete));
ActionBarMenuItem otherItem = actionMode.addItemWithWidth(0, R.drawable.ic_ab_other, AndroidUtilities.dp(54), LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
archiveItem = otherItem.addSubItem(archive, R.drawable.msg_archive, LocaleController.getString("Archive", R.string.Archive));
pin2Item = otherItem.addSubItem(pin2, R.drawable.msg_pin, LocaleController.getString("DialogPin", R.string.DialogPin));
addToFolderItem = otherItem.addSubItem(add_to_folder, R.drawable.msg_addfolder, LocaleController.getString("FilterAddTo", R.string.FilterAddTo));
removeFromFolderItem = otherItem.addSubItem(remove_from_folder, R.drawable.msg_removefolder, LocaleController.getString("FilterRemoveFrom", R.string.FilterRemoveFrom));
readItem = otherItem.addSubItem(read, R.drawable.msg_markread, LocaleController.getString("MarkAsRead", R.string.MarkAsRead));
clearItem = otherItem.addSubItem(clear, R.drawable.msg_clear, LocaleController.getString("ClearHistory", R.string.ClearHistory));
blockItem = otherItem.addSubItem(block, R.drawable.msg_block, LocaleController.getString("BlockUser", R.string.BlockUser));
actionModeViews.add(pinItem);
actionModeViews.add(archive2Item);
actionModeViews.add(muteItem);
actionModeViews.add(deleteItem);
actionModeViews.add(otherItem);
if (tag == null) {
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == SearchViewPager.forwardItemId || id == SearchViewPager.gotoItemId && searchViewPager != null) {
searchViewPager.onActionBarItemClick(id);
return;
}
if (id == -1) {
if (filterTabsView != null && filterTabsView.isEditing()) {
filterTabsView.setIsEditing(false);
showDoneItem(false);
} else if (actionBar.isActionModeShowed()) {
if (searchViewPager != null && searchViewPager.getVisibility() == View.VISIBLE && searchViewPager.actionModeShowing()) {
searchViewPager.hideActionMode();
} else {
hideActionMode(true);
}
} else if (onlySelect || folderId != 0) {
finishFragment();
} else if (parentLayout != null) {
parentLayout.getDrawerLayoutContainer().openDrawer(false);
}
} else if (id == 1) {
if (getParentActivity() == null) {
return;
}
SharedConfig.appLocked = true;
SharedConfig.saveConfig();
int[] position = new int[2];
passcodeItem.getLocationInWindow(position);
((LaunchActivity) getParentActivity()).showPasscodeActivity(false, true, position[0] + passcodeItem.getMeasuredWidth() / 2, position[1] + passcodeItem.getMeasuredHeight() / 2, () -> passcodeItem.setAlpha(1.0f), () -> passcodeItem.setAlpha(0.0f));
updatePasscodeButton();
} else if (id == 2) {
presentFragment(new ProxyListActivity());
} else if (id >= 10 && id < 10 + UserConfig.MAX_ACCOUNT_COUNT) {
if (getParentActivity() == null) {
return;
}
DialogsActivityDelegate oldDelegate = delegate;
LaunchActivity launchActivity = (LaunchActivity) getParentActivity();
launchActivity.switchToAccount(id - 10, true);
DialogsActivity dialogsActivity = new DialogsActivity(arguments);
dialogsActivity.setDelegate(oldDelegate);
launchActivity.presentFragment(dialogsActivity, false, true);
} else if (id == add_to_folder) {
FiltersListBottomSheet sheet = new FiltersListBottomSheet(DialogsActivity.this, selectedDialogs);
sheet.setDelegate(filter -> {
ArrayList<Long> alwaysShow = FiltersListBottomSheet.getDialogsCount(DialogsActivity.this, filter, selectedDialogs, true, false);
int currentCount;
if (filter != null) {
currentCount = filter.alwaysShow.size();
} else {
currentCount = 0;
}
if (currentCount + alwaysShow.size() > 100) {
showDialog(AlertsCreator.createSimpleAlert(getParentActivity(), LocaleController.getString("FilterAddToAlertFullTitle", R.string.FilterAddToAlertFullTitle), LocaleController.getString("FilterRemoveFromAlertFullText", R.string.FilterRemoveFromAlertFullText)).create());
return;
}
if (filter != null) {
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.name, filter.alwaysShow, filter.neverShow, filter.pinnedDialogs, false, false, true, true, false, DialogsActivity.this, null);
}
long did;
if (alwaysShow.size() == 1) {
did = alwaysShow.get(0);
} else {
did = 0;
}
getUndoView().showWithAction(did, UndoView.ACTION_ADDED_TO_FOLDER, alwaysShow.size(), filter, null, null);
} else {
presentFragment(new FilterCreateActivity(null, alwaysShow));
}
hideActionMode(true);
});
showDialog(sheet);
} else if (id == remove_from_folder) {
MessagesController.DialogFilter filter = getMessagesController().dialogFilters.get(viewPages[0].selectedType);
ArrayList<Long> neverShow = FiltersListBottomSheet.getDialogsCount(DialogsActivity.this, filter, selectedDialogs, false, false);
int currentCount;
if (filter != null) {
currentCount = filter.neverShow.size();
} else {
currentCount = 0;
}
if (currentCount + neverShow.size() > 100) {
showDialog(AlertsCreator.createSimpleAlert(getParentActivity(), LocaleController.getString("FilterAddToAlertFullTitle", R.string.FilterAddToAlertFullTitle), LocaleController.getString("FilterAddToAlertFullText", R.string.FilterAddToAlertFullText)).create());
return;
}
if (!neverShow.isEmpty()) {
filter.neverShow.addAll(neverShow);
for (int a = 0; a < neverShow.size(); a++) {
Long did = neverShow.get(a);
filter.alwaysShow.remove(did);
filter.pinnedDialogs.delete(did);
}
FilterCreateActivity.saveFilterToServer(filter, filter.flags, filter.name, filter.alwaysShow, filter.neverShow, filter.pinnedDialogs, false, false, true, false, false, DialogsActivity.this, null);
}
long did;
if (neverShow.size() == 1) {
did = neverShow.get(0);
} else {
did = 0;
}
getUndoView().showWithAction(did, UndoView.ACTION_REMOVED_FROM_FOLDER, neverShow.size(), filter, null, null);
hideActionMode(false);
} else if (id == pin || id == read || id == delete || id == clear || id == mute || id == archive || id == block || id == archive2 || id == pin2) {
performSelectedDialogsAction(selectedDialogs, id, true);
}
}
});
}
}
Aggregations