use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createDeleteMessagesAlert.
public static void createDeleteMessagesAlert(BaseFragment fragment, TLRPC.User user, TLRPC.Chat chat, TLRPC.EncryptedChat encryptedChat, TLRPC.ChatFull chatInfo, long mergeDialogId, MessageObject selectedMessage, SparseArray<MessageObject>[] selectedMessages, MessageObject.GroupedMessages selectedGroup, boolean scheduled, int loadParticipant, Runnable onDelete, Runnable hideDim, Theme.ResourcesProvider resourcesProvider) {
if (fragment == null || user == null && chat == null && encryptedChat == null) {
return;
}
Activity activity = fragment.getParentActivity();
if (activity == null) {
return;
}
int currentAccount = fragment.getCurrentAccount();
AlertDialog.Builder builder = new AlertDialog.Builder(activity, resourcesProvider);
builder.setDimEnabled(hideDim == null);
int count;
if (selectedGroup != null) {
count = selectedGroup.messages.size();
} else if (selectedMessage != null) {
count = 1;
} else {
count = selectedMessages[0].size() + selectedMessages[1].size();
}
long dialogId;
if (encryptedChat != null) {
dialogId = DialogObject.makeEncryptedDialogId(encryptedChat.id);
} else if (user != null) {
dialogId = user.id;
} else {
dialogId = -chat.id;
}
int currentDate = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
boolean hasNonDiceMessages = false;
if (selectedMessage != null) {
hasNonDiceMessages = !selectedMessage.isDice() || Math.abs(currentDate - selectedMessage.messageOwner.date) > 24 * 60 * 60;
} else {
for (int a = 0; a < 2; a++) {
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (!msg.isDice() || Math.abs(currentDate - msg.messageOwner.date) > 24 * 60 * 60) {
hasNonDiceMessages = true;
break;
}
}
}
}
final boolean[] checks = new boolean[3];
final boolean[] deleteForAll = new boolean[1];
TLRPC.User actionUser = null;
TLRPC.Chat actionChat = null;
boolean canRevokeInbox = user != null && MessagesController.getInstance(currentAccount).canRevokePmInbox;
int revokeTimeLimit;
if (user != null) {
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimePmLimit;
} else {
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimeLimit;
}
boolean hasDeleteForAllCheck = false;
boolean hasNotOut = false;
int myMessagesCount = 0;
boolean canDeleteInbox = encryptedChat == null && user != null && canRevokeInbox && revokeTimeLimit == 0x7fffffff;
if (chat != null && chat.megagroup && !scheduled) {
boolean canBan = ChatObject.canBlockUsers(chat);
if (selectedMessage != null) {
if (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
if (selectedMessage.messageOwner.from_id.user_id != 0) {
actionUser = MessagesController.getInstance(currentAccount).getUser(selectedMessage.messageOwner.from_id.user_id);
} else if (selectedMessage.messageOwner.from_id.channel_id != 0) {
actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.channel_id);
} else if (selectedMessage.messageOwner.from_id.chat_id != 0) {
actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.chat_id);
}
}
boolean hasOutgoing = !selectedMessage.isSendError() && selectedMessage.getDialogId() == mergeDialogId && (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && selectedMessage.isOut() && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit;
if (hasOutgoing) {
myMessagesCount++;
}
} else {
long from_id = -1;
for (int a = 1; a >= 0; a--) {
long channelId = 0;
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (from_id == -1) {
from_id = msg.getFromChatId();
}
if (from_id < 0 || from_id != msg.getSenderId()) {
from_id = -2;
break;
}
}
if (from_id == -2) {
break;
}
}
for (int a = 1; a >= 0; a--) {
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (a == 1) {
if (msg.isOut() && msg.messageOwner.action == null) {
if ((currentDate - msg.messageOwner.date) <= revokeTimeLimit) {
myMessagesCount++;
}
}
}
}
}
if (from_id != -1) {
actionUser = MessagesController.getInstance(currentAccount).getUser(from_id);
}
}
if ((actionUser != null && actionUser.id != UserConfig.getInstance(currentAccount).getClientUserId()) || (actionChat != null && !ChatObject.hasAdminRights(actionChat))) {
if (loadParticipant == 1 && !chat.creator && actionUser != null) {
final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(activity, 3) };
TLRPC.TL_channels_getParticipant req = new TLRPC.TL_channels_getParticipant();
req.channel = MessagesController.getInputChannel(chat);
req.participant = MessagesController.getInputPeer(actionUser);
int requestId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
int loadType = 2;
if (response != null) {
TLRPC.TL_channels_channelParticipant participant = (TLRPC.TL_channels_channelParticipant) response;
if (!(participant.participant instanceof TLRPC.TL_channelParticipantAdmin || participant.participant instanceof TLRPC.TL_channelParticipantCreator)) {
loadType = 0;
}
} else if (error != null && "USER_NOT_PARTICIPANT".equals(error.text)) {
loadType = 0;
}
createDeleteMessagesAlert(fragment, user, chat, encryptedChat, chatInfo, mergeDialogId, selectedMessage, selectedMessages, selectedGroup, scheduled, loadType, onDelete, hideDim, resourcesProvider);
}));
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(requestId, true));
fragment.showDialog(progressDialog[0]);
}, 1000);
return;
}
FrameLayout frameLayout = new FrameLayout(activity);
int num = 0;
String name = actionUser != null ? ContactsController.formatName(actionUser.first_name, actionUser.last_name) : actionChat.title;
for (int a = 0; a < 3; a++) {
if ((loadParticipant == 2 || !canBan) && a == 0) {
continue;
}
CheckBoxCell cell = new CheckBoxCell(activity, 1, resourcesProvider);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
cell.setTag(a);
if (a == 0) {
cell.setText(LocaleController.getString("DeleteBanUser", R.string.DeleteBanUser), "", false, false);
} else if (a == 1) {
cell.setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", false, false);
} else {
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, name), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 48 * num, 0, 0));
cell.setOnClickListener(v -> {
if (!v.isEnabled()) {
return;
}
CheckBoxCell cell13 = (CheckBoxCell) v;
Integer num1 = (Integer) cell13.getTag();
checks[num1] = !checks[num1];
cell13.setChecked(checks[num1], true);
});
num++;
}
builder.setView(frameLayout);
} else if (!hasNotOut && myMessagesCount > 0 && hasNonDiceMessages) {
hasDeleteForAllCheck = true;
FrameLayout frameLayout = new FrameLayout(activity);
CheckBoxCell cell = new CheckBoxCell(activity, 1, resourcesProvider);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (chat != null && hasNotOut) {
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false);
} else {
cell.setText(LocaleController.getString("DeleteMessagesOption", R.string.DeleteMessagesOption), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
cell.setOnClickListener(v -> {
CheckBoxCell cell12 = (CheckBoxCell) v;
deleteForAll[0] = !deleteForAll[0];
cell12.setChecked(deleteForAll[0], true);
});
builder.setView(frameLayout);
builder.setCustomViewOffset(9);
} else {
actionUser = null;
}
} else if (!scheduled && !ChatObject.isChannel(chat) && encryptedChat == null) {
if (user != null && user.id != UserConfig.getInstance(currentAccount).getClientUserId() && (!user.bot || user.support) || chat != null) {
if (selectedMessage != null) {
boolean hasOutgoing = !selectedMessage.isSendError() && (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionSetChatTheme) && (selectedMessage.isOut() || canRevokeInbox || ChatObject.hasAdminRights(chat)) && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit;
if (hasOutgoing) {
myMessagesCount++;
}
hasNotOut = !selectedMessage.isOut();
} else {
for (int a = 1; a >= 0; a--) {
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (!(msg.messageOwner.action == null || msg.messageOwner.action instanceof TLRPC.TL_messageActionEmpty || msg.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall || msg.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage || msg.messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached)) {
continue;
}
if ((msg.isOut() || canRevokeInbox) || chat != null && ChatObject.canBlockUsers(chat)) {
if ((currentDate - msg.messageOwner.date) <= revokeTimeLimit) {
myMessagesCount++;
if (!hasNotOut && !msg.isOut()) {
hasNotOut = true;
}
}
}
}
}
}
}
if (myMessagesCount > 0 && hasNonDiceMessages && (user == null || !UserObject.isDeleted(user))) {
hasDeleteForAllCheck = true;
FrameLayout frameLayout = new FrameLayout(activity);
CheckBoxCell cell = new CheckBoxCell(activity, 1, resourcesProvider);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (canDeleteInbox) {
cell.setText(LocaleController.formatString("DeleteMessagesOptionAlso", R.string.DeleteMessagesOptionAlso, UserObject.getFirstName(user)), "", false, false);
} else if (chat != null && (hasNotOut || myMessagesCount == count)) {
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false);
} else {
cell.setText(LocaleController.getString("DeleteMessagesOption", R.string.DeleteMessagesOption), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
cell.setOnClickListener(v -> {
CheckBoxCell cell1 = (CheckBoxCell) v;
deleteForAll[0] = !deleteForAll[0];
cell1.setChecked(deleteForAll[0], true);
});
builder.setView(frameLayout);
builder.setCustomViewOffset(9);
}
}
final TLRPC.User userFinal = actionUser;
final TLRPC.Chat chatFinal = actionChat;
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
ArrayList<Integer> ids = null;
if (selectedMessage != null) {
ids = new ArrayList<>();
ArrayList<Long> random_ids = null;
if (selectedGroup != null) {
for (int a = 0; a < selectedGroup.messages.size(); a++) {
MessageObject messageObject = selectedGroup.messages.get(a);
ids.add(messageObject.getId());
if (encryptedChat != null && messageObject.messageOwner.random_id != 0 && messageObject.type != 10) {
if (random_ids == null) {
random_ids = new ArrayList<>();
}
random_ids.add(messageObject.messageOwner.random_id);
}
}
} else {
ids.add(selectedMessage.getId());
if (encryptedChat != null && selectedMessage.messageOwner.random_id != 0 && selectedMessage.type != 10) {
random_ids = new ArrayList<>();
random_ids.add(selectedMessage.messageOwner.random_id);
}
}
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, encryptedChat, dialogId, deleteForAll[0], scheduled);
} else {
for (int a = 1; a >= 0; a--) {
ids = new ArrayList<>();
for (int b = 0; b < selectedMessages[a].size(); b++) {
ids.add(selectedMessages[a].keyAt(b));
}
ArrayList<Long> random_ids = null;
long channelId = 0;
if (!ids.isEmpty()) {
MessageObject msg = selectedMessages[a].get(ids.get(0));
if (msg.messageOwner.peer_id.channel_id != 0) {
channelId = msg.messageOwner.peer_id.channel_id;
}
}
if (encryptedChat != null) {
random_ids = new ArrayList<>();
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
random_ids.add(msg.messageOwner.random_id);
}
}
}
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, encryptedChat, dialogId, deleteForAll[0], scheduled);
selectedMessages[a].clear();
}
}
if (userFinal != null || chatFinal != null) {
if (checks[0]) {
MessagesController.getInstance(currentAccount).deleteParticipantFromChat(chat.id, userFinal, chatFinal, chatInfo, false, false);
}
if (checks[1]) {
TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam();
req.channel = MessagesController.getInputChannel(chat);
if (userFinal != null) {
req.participant = MessagesController.getInputPeer(userFinal);
} else {
req.participant = MessagesController.getInputPeer(chatFinal);
}
req.id = ids;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
});
}
if (checks[2]) {
MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, chatFinal, 0);
}
}
if (onDelete != null) {
onDelete.run();
}
});
if (count == 1) {
builder.setTitle(LocaleController.getString("DeleteSingleMessagesTitle", R.string.DeleteSingleMessagesTitle));
} else {
builder.setTitle(LocaleController.formatString("DeleteMessagesTitle", R.string.DeleteMessagesTitle, LocaleController.formatPluralString("messages", count)));
}
if (chat != null && hasNotOut) {
if (hasDeleteForAllCheck && myMessagesCount != count) {
builder.setMessage(LocaleController.formatString("DeleteMessagesTextGroupPart", R.string.DeleteMessagesTextGroupPart, LocaleController.formatPluralString("messages", myMessagesCount)));
} else if (count == 1) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessage", R.string.AreYouSureDeleteSingleMessage));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessages", R.string.AreYouSureDeleteFewMessages));
}
} else if (hasDeleteForAllCheck && !canDeleteInbox && myMessagesCount != count) {
if (chat != null) {
builder.setMessage(LocaleController.formatString("DeleteMessagesTextGroup", R.string.DeleteMessagesTextGroup, LocaleController.formatPluralString("messages", myMessagesCount)));
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("DeleteMessagesText", R.string.DeleteMessagesText, LocaleController.formatPluralString("messages", myMessagesCount), UserObject.getFirstName(user))));
}
} else {
if (chat != null && chat.megagroup && !scheduled) {
if (count == 1) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessageMega", R.string.AreYouSureDeleteSingleMessageMega));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessagesMega", R.string.AreYouSureDeleteFewMessagesMega));
}
} else {
if (count == 1) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessage", R.string.AreYouSureDeleteSingleMessage));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessages", R.string.AreYouSureDeleteFewMessages));
}
}
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setOnPreDismissListener(di -> {
if (hideDim != null) {
hideDim.run();
}
});
AlertDialog dialog = builder.create();
fragment.showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method showBlockReportSpamReplyAlert.
public static void showBlockReportSpamReplyAlert(ChatActivity fragment, MessageObject messageObject, long peerId, Theme.ResourcesProvider resourcesProvider, Runnable hideDim) {
if (fragment == null || fragment.getParentActivity() == null || messageObject == null) {
return;
}
AccountInstance accountInstance = fragment.getAccountInstance();
TLRPC.User user = peerId > 0 ? accountInstance.getMessagesController().getUser(peerId) : null;
TLRPC.Chat chat = peerId < 0 ? accountInstance.getMessagesController().getChat(-peerId) : null;
if (user == null && chat == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity(), resourcesProvider);
builder.setDimEnabled(hideDim == null);
builder.setOnPreDismissListener(di -> {
if (hideDim != null) {
hideDim.run();
}
});
builder.setTitle(LocaleController.getString("BlockUser", R.string.BlockUser));
if (user != null) {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserReplyAlert", R.string.BlockUserReplyAlert, UserObject.getFirstName(user))));
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserReplyAlert", R.string.BlockUserReplyAlert, chat.title)));
}
CheckBoxCell[] cells = new CheckBoxCell[1];
LinearLayout linearLayout = new LinearLayout(fragment.getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
cells[0] = new CheckBoxCell(fragment.getParentActivity(), 1, resourcesProvider);
cells[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
cells[0].setTag(0);
cells[0].setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", true, false);
cells[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
linearLayout.addView(cells[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
cells[0].setOnClickListener(v -> {
Integer num = (Integer) v.getTag();
cells[num].setChecked(!cells[num].isChecked(), true);
});
builder.setCustomViewOffset(12);
builder.setView(linearLayout);
builder.setPositiveButton(LocaleController.getString("BlockAndDeleteReplies", R.string.BlockAndDeleteReplies), (dialogInterface, i) -> {
if (user != null) {
accountInstance.getMessagesStorage().deleteUserChatHistory(fragment.getDialogId(), user.id);
} else {
accountInstance.getMessagesStorage().deleteUserChatHistory(fragment.getDialogId(), -chat.id);
}
TLRPC.TL_contacts_blockFromReplies request = new TLRPC.TL_contacts_blockFromReplies();
request.msg_id = messageObject.getId();
request.delete_message = true;
request.delete_history = true;
if (cells[0].isChecked()) {
request.report_spam = true;
if (fragment.getParentActivity() != null) {
if (fragment instanceof ChatActivity) {
fragment.getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
} else if (fragment != null) {
BulletinFactory.of(fragment).createReportSent(resourcesProvider).show();
} else {
Toast.makeText(fragment.getParentActivity(), LocaleController.getString("ReportChatSent", R.string.ReportChatSent), Toast.LENGTH_SHORT).show();
}
}
}
accountInstance.getConnectionsManager().sendRequest(request, (response, error) -> {
if (response instanceof TLRPC.Updates) {
accountInstance.getMessagesController().processUpdates((TLRPC.Updates) response, false);
}
});
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
fragment.showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createClearOrDeleteDialogAlert.
public static void createClearOrDeleteDialogAlert(BaseFragment fragment, boolean clear, boolean admin, boolean second, TLRPC.Chat chat, TLRPC.User user, boolean secret, boolean checkDeleteForAll, MessagesStorage.BooleanCallback onProcessRunnable, Theme.ResourcesProvider resourcesProvider) {
if (fragment == null || fragment.getParentActivity() == null || chat == null && user == null) {
return;
}
int account = fragment.getCurrentAccount();
Context context = fragment.getParentActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(context, resourcesProvider);
long selfUserId = UserConfig.getInstance(account).getClientUserId();
CheckBoxCell[] cell = new CheckBoxCell[1];
TextView messageTextView = new TextView(context);
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
boolean clearingCache = ChatObject.isChannel(chat) && !TextUtils.isEmpty(chat.username);
FrameLayout frameLayout = new FrameLayout(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (cell[0] != null) {
setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + cell[0].getMeasuredHeight() + AndroidUtilities.dp(7));
}
}
};
builder.setView(frameLayout);
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
BackupImageView imageView = new BackupImageView(context);
imageView.setRoundRadius(AndroidUtilities.dp(20));
frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
TextView textView = new TextView(context);
textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
if (clear) {
if (clearingCache) {
textView.setText(LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache));
} else {
textView.setText(LocaleController.getString("ClearHistory", R.string.ClearHistory));
}
} else {
if (admin) {
if (ChatObject.isChannel(chat)) {
if (chat.megagroup) {
textView.setText(LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu));
} else {
textView.setText(LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu));
}
} else {
textView.setText(LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu));
}
} else {
if (chat != null) {
if (ChatObject.isChannel(chat)) {
if (chat.megagroup) {
textView.setText(LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu));
} else {
textView.setText(LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu));
}
} else {
textView.setText(LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu));
}
} else {
textView.setText(LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser));
}
}
}
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
boolean canRevokeInbox = user != null && !user.bot && user.id != selfUserId && MessagesController.getInstance(account).canRevokePmInbox;
int revokeTimeLimit;
if (user != null) {
revokeTimeLimit = MessagesController.getInstance(account).revokeTimePmLimit;
} else {
revokeTimeLimit = MessagesController.getInstance(account).revokeTimeLimit;
}
boolean canDeleteInbox = !secret && user != null && canRevokeInbox && revokeTimeLimit == 0x7fffffff;
final boolean[] deleteForAll = new boolean[1];
boolean deleteChatForAll = false;
if (!second && (secret && !clear || canDeleteInbox) && !UserObject.isDeleted(user) || (deleteChatForAll = checkDeleteForAll && !clear && chat != null && chat.creator)) {
cell[0] = new CheckBoxCell(context, 1, resourcesProvider);
cell[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (deleteChatForAll) {
if (ChatObject.isChannel(chat) && !chat.megagroup) {
cell[0].setText(LocaleController.getString("DeleteChannelForAll", R.string.DeleteChannelForAll), "", false, false);
} else {
cell[0].setText(LocaleController.getString("DeleteGroupForAll", R.string.DeleteGroupForAll), "", false, false);
}
} else if (clear) {
cell[0].setText(LocaleController.formatString("ClearHistoryOptionAlso", R.string.ClearHistoryOptionAlso, UserObject.getFirstName(user)), "", false, false);
} else {
cell[0].setText(LocaleController.formatString("DeleteMessagesOptionAlso", R.string.DeleteMessagesOptionAlso, UserObject.getFirstName(user)), "", false, false);
}
cell[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell[0], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 0));
cell[0].setOnClickListener(v -> {
CheckBoxCell cell1 = (CheckBoxCell) v;
deleteForAll[0] = !deleteForAll[0];
cell1.setChecked(deleteForAll[0], true);
});
}
if (user != null) {
if (UserObject.isReplyUser(user)) {
avatarDrawable.setSmallSize(true);
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
imageView.setImage(null, null, avatarDrawable, user);
} else if (user.id == selfUserId) {
avatarDrawable.setSmallSize(true);
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
imageView.setImage(null, null, avatarDrawable, user);
} else {
avatarDrawable.setSmallSize(false);
avatarDrawable.setInfo(user);
imageView.setForUserOrChat(user, avatarDrawable);
}
} else {
avatarDrawable.setInfo(chat);
imageView.setForUserOrChat(chat, avatarDrawable);
}
if (second) {
if (UserObject.isUserSelf(user)) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllMessagesSavedAlert", R.string.DeleteAllMessagesSavedAlert)));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllMessagesAlert", R.string.DeleteAllMessagesAlert)));
}
} else {
if (clear) {
if (user != null) {
if (secret) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithSecretUser", R.string.AreYouSureClearHistoryWithSecretUser, UserObject.getUserName(user))));
} else {
if (user.id == selfUserId) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("AreYouSureClearHistorySavedMessages", R.string.AreYouSureClearHistorySavedMessages)));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithUser", R.string.AreYouSureClearHistoryWithUser, UserObject.getUserName(user))));
}
}
} else {
if (!ChatObject.isChannel(chat) || chat.megagroup && TextUtils.isEmpty(chat.username)) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureClearHistoryWithChat", R.string.AreYouSureClearHistoryWithChat, chat.title)));
} else if (chat.megagroup) {
messageTextView.setText(LocaleController.getString("AreYouSureClearHistoryGroup", R.string.AreYouSureClearHistoryGroup));
} else {
messageTextView.setText(LocaleController.getString("AreYouSureClearHistoryChannel", R.string.AreYouSureClearHistoryChannel));
}
}
} else {
if (admin) {
if (ChatObject.isChannel(chat)) {
if (chat.megagroup) {
messageTextView.setText(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
} else {
messageTextView.setText(LocaleController.getString("AreYouSureDeleteAndExitChannel", R.string.AreYouSureDeleteAndExitChannel));
}
} else {
messageTextView.setText(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
}
} else {
if (user != null) {
if (secret) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithSecretUser", R.string.AreYouSureDeleteThisChatWithSecretUser, UserObject.getUserName(user))));
} else {
if (user.id == selfUserId) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("AreYouSureDeleteThisChatSavedMessages", R.string.AreYouSureDeleteThisChatSavedMessages)));
} else {
if (user.bot && !user.support) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithBot", R.string.AreYouSureDeleteThisChatWithBot, UserObject.getUserName(user))));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteThisChatWithUser", R.string.AreYouSureDeleteThisChatWithUser, UserObject.getUserName(user))));
}
}
}
} else if (ChatObject.isChannel(chat)) {
if (chat.megagroup) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("MegaLeaveAlertWithName", R.string.MegaLeaveAlertWithName, chat.title)));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ChannelLeaveAlertWithName", R.string.ChannelLeaveAlertWithName, chat.title)));
}
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("AreYouSureDeleteAndExitName", R.string.AreYouSureDeleteAndExitName, chat.title)));
}
}
}
}
String actionText;
if (second) {
actionText = LocaleController.getString("DeleteAll", R.string.DeleteAll);
} else {
if (clear) {
if (clearingCache) {
actionText = LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache);
} else {
actionText = LocaleController.getString("ClearHistory", R.string.ClearHistory);
}
} else {
if (admin) {
if (ChatObject.isChannel(chat)) {
if (chat.megagroup) {
actionText = LocaleController.getString("DeleteMega", R.string.DeleteMega);
} else {
actionText = LocaleController.getString("ChannelDelete", R.string.ChannelDelete);
}
} else {
actionText = LocaleController.getString("DeleteMega", R.string.DeleteMega);
}
} else {
if (ChatObject.isChannel(chat)) {
if (chat.megagroup) {
actionText = LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu);
} else {
actionText = LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu);
}
} else {
actionText = LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser);
}
}
}
}
builder.setPositiveButton(actionText, (dialogInterface, i) -> {
if (!clearingCache && !second && !secret) {
if (UserObject.isUserSelf(user)) {
createClearOrDeleteDialogAlert(fragment, clear, admin, true, chat, user, false, checkDeleteForAll, onProcessRunnable, resourcesProvider);
return;
} else if (user != null && deleteForAll[0]) {
MessagesStorage.getInstance(fragment.getCurrentAccount()).getMessagesCount(user.id, (count) -> {
if (count >= 50) {
createClearOrDeleteDialogAlert(fragment, clear, admin, true, chat, user, false, checkDeleteForAll, onProcessRunnable, resourcesProvider);
} else {
if (onProcessRunnable != null) {
onProcessRunnable.run(deleteForAll[0]);
}
}
});
return;
}
}
if (onProcessRunnable != null) {
onProcessRunnable.run(second || deleteForAll[0]);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
fragment.showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class CallLogActivity method showDeleteAlert.
private void showDeleteAlert(boolean all) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (all) {
builder.setTitle(LocaleController.getString("DeleteAllCalls", R.string.DeleteAllCalls));
builder.setMessage(LocaleController.getString("DeleteAllCallsText", R.string.DeleteAllCallsText));
} else {
builder.setTitle(LocaleController.getString("DeleteCalls", R.string.DeleteCalls));
builder.setMessage(LocaleController.getString("DeleteSelectedCallsText", R.string.DeleteSelectedCallsText));
}
final boolean[] checks = new boolean[] { false };
FrameLayout frameLayout = new FrameLayout(getParentActivity());
CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
cell.setText(LocaleController.getString("DeleteCallsForEveryone", R.string.DeleteCallsForEveryone), "", false, false);
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0));
cell.setOnClickListener(v -> {
CheckBoxCell cell1 = (CheckBoxCell) v;
checks[0] = !checks[0];
cell1.setChecked(checks[0], true);
});
builder.setView(frameLayout);
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
if (all) {
deleteAllMessages(checks[0]);
calls.clear();
loading = false;
endReached = true;
otherItem.setVisibility(View.GONE);
listViewAdapter.notifyDataSetChanged();
} else {
getMessagesController().deleteMessages(new ArrayList<>(selectedIds), null, null, 0, checks[0], false);
}
hideActionMode(false);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class CacheControlActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("StorageUsage", R.string.StorageUsage));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
listView = new RecyclerListView(context);
listView.setVerticalScrollBarEnabled(false);
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null) {
return;
}
if (position == migrateOldFolderRow) {
migrateOldFolder();
} else if (position == databaseRow) {
clearDatabase();
} else if (position == storageUsageRow) {
if (totalSize <= 0 || getParentActivity() == null) {
return;
}
bottomSheet = new BottomSheet(getParentActivity(), false) {
@Override
protected boolean canDismissWithSwipe() {
return false;
}
};
bottomSheet.setAllowNestedScroll(true);
bottomSheet.setApplyBottomPadding(false);
LinearLayout linearLayout = new LinearLayout(getParentActivity());
bottomSheetView = linearLayout;
linearLayout.setOrientation(LinearLayout.VERTICAL);
StorageDiagramView circleDiagramView = new StorageDiagramView(context);
linearLayout.addView(circleDiagramView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 16));
CheckBoxCell lastCreatedCheckbox = null;
for (int a = 0; a < 7; a++) {
long size;
String name;
String color;
if (a == 0) {
size = photoSize;
name = LocaleController.getString("LocalPhotoCache", R.string.LocalPhotoCache);
color = Theme.key_statisticChartLine_blue;
} else if (a == 1) {
size = videoSize;
name = LocaleController.getString("LocalVideoCache", R.string.LocalVideoCache);
color = Theme.key_statisticChartLine_golden;
} else if (a == 2) {
size = documentsSize;
name = LocaleController.getString("LocalDocumentCache", R.string.LocalDocumentCache);
color = Theme.key_statisticChartLine_green;
} else if (a == 3) {
size = musicSize;
name = LocaleController.getString("LocalMusicCache", R.string.LocalMusicCache);
color = Theme.key_statisticChartLine_indigo;
} else if (a == 4) {
size = audioSize;
name = LocaleController.getString("LocalAudioCache", R.string.LocalAudioCache);
color = Theme.key_statisticChartLine_red;
} else if (a == 5) {
size = stickersSize;
name = LocaleController.getString("AnimatedStickers", R.string.AnimatedStickers);
color = Theme.key_statisticChartLine_lightgreen;
} else {
size = cacheSize;
name = LocaleController.getString("LocalCache", R.string.LocalCache);
color = Theme.key_statisticChartLine_lightblue;
}
if (size > 0) {
clearViewData[a] = new StorageDiagramView.ClearViewData(circleDiagramView);
clearViewData[a].size = size;
clearViewData[a].color = color;
CheckBoxCell checkBoxCell = new CheckBoxCell(getParentActivity(), 4, 21, null);
lastCreatedCheckbox = checkBoxCell;
checkBoxCell.setTag(a);
checkBoxCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
checkBoxCell.setText(name, AndroidUtilities.formatFileSize(size), true, true);
checkBoxCell.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
checkBoxCell.setCheckBoxColor(color, Theme.key_windowBackgroundWhiteGrayIcon, Theme.key_checkboxCheck);
checkBoxCell.setOnClickListener(v -> {
int enabledCount = 0;
for (int i = 0; i < clearViewData.length; i++) {
if (clearViewData[i] != null && clearViewData[i].clear) {
enabledCount++;
}
}
CheckBoxCell cell = (CheckBoxCell) v;
int num = (Integer) cell.getTag();
if (enabledCount == 1 && clearViewData[num].clear) {
AndroidUtilities.shakeView(((CheckBoxCell) v).getCheckBoxView(), 2, 0);
return;
}
clearViewData[num].setClear(!clearViewData[num].clear);
cell.setChecked(clearViewData[num].clear, true);
});
} else {
clearViewData[a] = null;
}
}
if (lastCreatedCheckbox != null) {
lastCreatedCheckbox.setNeedDivider(false);
}
circleDiagramView.setData(clearViewData);
BottomSheet.BottomSheetCell cell = new BottomSheet.BottomSheetCell(getParentActivity(), 2);
cell.setTextAndIcon(LocaleController.getString("ClearMediaCache", R.string.ClearMediaCache), 0);
actionTextView = cell.getTextView();
cell.getTextView().setOnClickListener(v -> {
try {
if (visibleDialog != null) {
visibleDialog.dismiss();
}
} catch (Exception e) {
FileLog.e(e);
}
cleanupFolders();
});
linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
NestedScrollView scrollView = new NestedScrollView(context);
scrollView.setVerticalScrollBarEnabled(false);
scrollView.addView(linearLayout);
bottomSheet.setCustomView(scrollView);
showDialog(bottomSheet);
}
});
cacheRemovedTooltip = new UndoView(context);
frameLayout.addView(cacheRemovedTooltip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
return fragmentView;
}
Aggregations