use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method openAnotherForward.
private void openAnotherForward() {
if (forwardingMessages == null || forwardingMessages.messages == null) {
return;
}
boolean fewSenders = false;
long lastPeerId = 0;
long dialogId = 0;
for (int a = 0, N = forwardingMessages.messages.size(); a < N; a++) {
MessageObject message = forwardingMessages.messages.get(a);
if (lastPeerId == 0) {
dialogId = message.getDialogId();
lastPeerId = message.getFromChatId();
} else if (lastPeerId != message.getFromChatId()) {
fewSenders = true;
break;
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity(), themeDelegate);
builder.setButtonsVertical(true);
String message;
if (dialogId > 0) {
TLRPC.User user = getMessagesController().getUser(dialogId);
message = LocaleController.formatString("CancelForwardPrivate", R.string.CancelForwardPrivate, LocaleController.formatPluralString("MessagesBold", forwardingMessages.messages.size()), ContactsController.formatName(user.first_name, user.last_name));
} else {
TLRPC.Chat chat = getMessagesController().getChat(-dialogId);
message = LocaleController.formatString("CancelForwardChat", R.string.CancelForwardChat, LocaleController.formatPluralString("MessagesBold", forwardingMessages.messages.size()), chat == null ? "" : chat.title);
}
builder.setMessage(AndroidUtilities.replaceTags(message));
builder.setTitle(LocaleController.formatPluralString("messages", forwardingMessages.messages.size()));
builder.setPositiveButton(LocaleController.getString("CancelForwarding", R.string.CancelForwarding), (dialogInterface, i) -> {
if (forwardingMessages != null) {
forwardingMessages = null;
}
showFieldPanel(false, null, null, null, foundWebPage, true, 0, true, true);
});
// String sendersNameString;
// if (hideForwardSendersName) {
// if (fewSenders) {
// sendersNameString = LocaleController.getString("ShowSendersName", R.string.ShowSendersName);
// } else {
// sendersNameString = LocaleController.getString("ShowSenderName", R.string.ShowSenderName);
// }
// } else {
// if (fewSenders) {
// sendersNameString = LocaleController.getString("HideSendersName", R.string.HideSendersName);
// } else {
// sendersNameString = LocaleController.getString("HideSenderName", R.string.HideSenderName);
// }
// }
// boolean fewSendersFinal = fewSenders;
// builder.setNeutralButton(sendersNameString, (dialogInterface, i) -> {
// hideForwardSendersName = !hideForwardSendersName;
// if (hideForwardSendersName) {
// if (fewSendersFinal) {
// replyNameTextView.setText(LocaleController.getString("YouSendersNameHidden", R.string.YouSendersNameHidden));
// } else {
// replyNameTextView.setText(LocaleController.getString("YouSenderNameHidden", R.string.YouSenderNameHidden));
// }
// } else {
// replyNameTextView.setText(formwardingNameText);
// }
// });
// builder.setNegativeButton(LocaleController.getString("ForwardAnotherChat", R.string.ForwardAnotherChat), (dialogInterface, i) -> {
// if (forwardingMessages != null && !forwardingMessages.isEmpty()) {
// int hasPoll = 0;
// boolean hasInvoice = false;
// for (int a = 0, N = forwardingMessages.size(); a < N; a++) {
// MessageObject messageObject = forwardingMessages.get(a);
// if (messageObject.isPoll()) {
// if (hasPoll != 2) {
// hasPoll = messageObject.isPublicPoll() ? 2 : 1;
// }
// } else if (messageObject.isInvoice()) {
// hasInvoice = true;
// }
// selectedMessagesIds[0].put(messageObject.getId(), messageObject);
// }
// Bundle args = new Bundle();
// args.putBoolean("onlySelect", true);
// args.putInt("dialogsType", 3);
// args.putInt("hasPoll", hasPoll);
// args.putBoolean("hasInvoice", hasInvoice);
// args.putInt("messagesCount", forwardingMessages.size());
// DialogsActivity fragment = new DialogsActivity(args);
// fragment.setDelegate(ChatActivity.this);
// presentFragment(fragment);
// }
// });
builder.setNegativeButton(LocaleController.getString("ShowForwardingOptions", R.string.ShowForwardingOptions), (dialogInterface, i) -> {
openForwardingPreview();
});
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(getThemedColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatEditActivity method processDone.
private void processDone() {
if (donePressed || nameTextView == null) {
return;
}
if (nameTextView.length() == 0) {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(nameTextView, 2, 0);
return;
}
donePressed = true;
if (!ChatObject.isChannel(currentChat) && !historyHidden) {
getMessagesController().convertToMegaGroup(getParentActivity(), chatId, this, param -> {
if (param == 0) {
donePressed = false;
return;
}
chatId = param;
currentChat = getMessagesController().getChat(param);
donePressed = false;
if (info != null) {
info.hidden_prehistory = true;
}
processDone();
});
return;
}
if (info != null) {
if (ChatObject.isChannel(currentChat) && info.hidden_prehistory != historyHidden) {
info.hidden_prehistory = historyHidden;
getMessagesController().toogleChannelInvitesHistory(chatId, historyHidden);
}
}
if (imageUpdater.isUploadingImage()) {
createAfterUpload = true;
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setOnCancelListener(dialog -> {
createAfterUpload = false;
progressDialog = null;
donePressed = false;
});
progressDialog.show();
return;
}
if (!currentChat.title.equals(nameTextView.getText().toString())) {
getMessagesController().changeChatTitle(chatId, nameTextView.getText().toString());
}
String about = info != null && info.about != null ? info.about : "";
if (descriptionTextView != null && !about.equals(descriptionTextView.getText().toString())) {
getMessagesController().updateChatAbout(chatId, descriptionTextView.getText().toString(), info);
}
if (signMessages != currentChat.signatures) {
currentChat.signatures = true;
getMessagesController().toogleChannelSignatures(chatId, signMessages);
}
finishFragment();
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatLinkActivity method linkChat.
private void linkChat(TLRPC.Chat chat, BaseFragment createFragment) {
if (chat == null) {
return;
}
if (!ChatObject.isChannel(chat)) {
getMessagesController().convertToMegaGroup(getParentActivity(), chat.id, this, param -> {
if (param != 0) {
getMessagesController().toogleChannelInvitesHistory(param, false);
linkChat(getMessagesController().getChat(param), createFragment);
}
});
return;
}
final AlertDialog[] progressDialog = new AlertDialog[] { createFragment != null ? null : new AlertDialog(getParentActivity(), 3) };
TLRPC.TL_channels_setDiscussionGroup req = new TLRPC.TL_channels_setDiscussionGroup();
req.broadcast = MessagesController.getInputChannel(currentChat);
req.group = MessagesController.getInputChannel(chat);
int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] != null) {
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
}
info.linked_chat_id = chat.id;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, false, false);
AndroidUtilities.runOnUIThread(() -> getMessagesController().loadFullChat(currentChatId, 0, true), 1000);
if (createFragment != null) {
removeSelfFromStack();
createFragment.finishFragment();
} else {
finishFragment();
}
}), ConnectionsManager.RequestFlagInvokeAfter);
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(requestId, true));
showDialog(progressDialog[0]);
}, 500);
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatLinkActivity method showLinkAlert.
private void showLinkAlert(TLRPC.Chat chat, boolean query) {
TLRPC.ChatFull chatFull = getMessagesController().getChatFull(chat.id);
if (chatFull == null) {
if (query) {
getMessagesController().loadFullChat(chat.id, 0, true);
waitingForFullChat = chat;
waitingForFullChatProgressAlert = new AlertDialog(getParentActivity(), 3);
AndroidUtilities.runOnUIThread(() -> {
if (waitingForFullChatProgressAlert == null) {
return;
}
waitingForFullChatProgressAlert.setOnCancelListener(dialog -> waitingForFullChat = null);
showDialog(waitingForFullChatProgressAlert);
}, 500);
}
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
TextView messageTextView = new TextView(getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
String message;
if (TextUtils.isEmpty(chat.username)) {
message = LocaleController.formatString("DiscussionLinkGroupPublicPrivateAlert", R.string.DiscussionLinkGroupPublicPrivateAlert, chat.title, currentChat.title);
} else {
if (TextUtils.isEmpty(currentChat.username)) {
message = LocaleController.formatString("DiscussionLinkGroupPrivateAlert", R.string.DiscussionLinkGroupPrivateAlert, chat.title, currentChat.title);
} else {
message = LocaleController.formatString("DiscussionLinkGroupPublicAlert", R.string.DiscussionLinkGroupPublicAlert, chat.title, currentChat.title);
}
}
if (chatFull.hidden_prehistory) {
message += "\n\n" + LocaleController.getString("DiscussionLinkGroupAlertHistory", R.string.DiscussionLinkGroupAlertHistory);
}
messageTextView.setText(AndroidUtilities.replaceTags(message));
FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
builder.setView(frameLayout2);
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
BackupImageView imageView = new BackupImageView(getParentActivity());
imageView.setRoundRadius(AndroidUtilities.dp(20));
frameLayout2.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
TextView textView = new TextView(getParentActivity());
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);
textView.setText(chat.title);
frameLayout2.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));
frameLayout2.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
avatarDrawable.setInfo(chat);
imageView.setForUserOrChat(chat, avatarDrawable);
builder.setPositiveButton(LocaleController.getString("DiscussionLinkGroup", R.string.DiscussionLinkGroup), (dialogInterface, i) -> {
if (chatFull.hidden_prehistory) {
getMessagesController().toogleChannelInvitesHistory(chat.id, false);
}
linkChat(chat, null);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatLinkActivity method createView.
@Override
public View createView(Context context) {
searching = false;
searchWas = false;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Discussion", R.string.Discussion));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
emptyView.setShowAtCenter(true);
}
@Override
public void onSearchCollapse() {
searchAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
listView.setFastScrollVisible(true);
listView.setVerticalScrollBarEnabled(false);
emptyView.setShowAtCenter(false);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
fragmentView.setTag(Theme.key_windowBackgroundGray);
emptyView.showProgress();
}
@Override
public void onTextChanged(EditText editText) {
if (searchAdapter == null) {
return;
}
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
if (listView != null && listView.getAdapter() != searchAdapter) {
listView.setAdapter(searchAdapter);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
fragmentView.setTag(Theme.key_windowBackgroundWhite);
searchAdapter.notifyDataSetChanged();
listView.setFastScrollVisible(false);
listView.setVerticalScrollBarEnabled(true);
emptyView.showProgress();
}
}
searchAdapter.searchDialogs(text);
}
});
searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
searchAdapter = new SearchAdapter(context);
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
fragmentView.setTag(Theme.key_windowBackgroundGray);
FrameLayout frameLayout = (FrameLayout) fragmentView;
emptyView = new EmptyTextProgressView(context);
emptyView.showProgress();
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView = new RecyclerListView(context);
listView.setEmptyView(emptyView);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setAdapter(listViewAdapter = new ListAdapter(context));
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null) {
return;
}
final TLRPC.Chat chat;
if (listView.getAdapter() == searchAdapter) {
chat = searchAdapter.getItem(position);
} else if (position >= chatStartRow && position < chatEndRow) {
chat = chats.get(position - chatStartRow);
} else {
chat = null;
}
if (chat != null) {
if (isChannel && info.linked_chat_id == 0) {
showLinkAlert(chat, true);
} else {
Bundle args = new Bundle();
args.putLong("chat_id", chat.id);
presentFragment(new ChatActivity(args));
}
return;
}
if (position == createChatRow) {
if (isChannel && info.linked_chat_id == 0) {
Bundle args = new Bundle();
long[] array = new long[] { getUserConfig().getClientUserId() };
args.putLongArray("result", array);
args.putInt("chatType", ChatObject.CHAT_TYPE_MEGAGROUP);
GroupCreateFinalActivity activity = new GroupCreateFinalActivity(args);
activity.setDelegate(new GroupCreateFinalActivity.GroupCreateFinalActivityDelegate() {
@Override
public void didStartChatCreation() {
}
@Override
public void didFinishChatCreation(GroupCreateFinalActivity fragment, long chatId) {
linkChat(getMessagesController().getChat(chatId), fragment);
}
@Override
public void didFailChatCreation() {
}
});
presentFragment(activity);
} else {
if (chats.isEmpty()) {
return;
}
TLRPC.Chat c = chats.get(0);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
String title;
String message;
if (isChannel) {
title = LocaleController.getString("DiscussionUnlinkGroup", R.string.DiscussionUnlinkGroup);
message = LocaleController.formatString("DiscussionUnlinkChannelAlert", R.string.DiscussionUnlinkChannelAlert, c.title);
} else {
title = LocaleController.getString("DiscussionUnlink", R.string.DiscussionUnlinkChannel);
message = LocaleController.formatString("DiscussionUnlinkGroupAlert", R.string.DiscussionUnlinkGroupAlert, c.title);
}
builder.setTitle(title);
builder.setMessage(AndroidUtilities.replaceTags(message));
builder.setPositiveButton(LocaleController.getString("DiscussionUnlink", R.string.DiscussionUnlink), (dialogInterface, i) -> {
if (!isChannel || info.linked_chat_id != 0) {
final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3) };
TLRPC.TL_channels_setDiscussionGroup req = new TLRPC.TL_channels_setDiscussionGroup();
if (isChannel) {
req.broadcast = MessagesController.getInputChannel(currentChat);
req.group = new TLRPC.TL_inputChannelEmpty();
} else {
req.broadcast = new TLRPC.TL_inputChannelEmpty();
req.group = MessagesController.getInputChannel(currentChat);
}
int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
info.linked_chat_id = 0;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, false, false);
AndroidUtilities.runOnUIThread(() -> getMessagesController().loadFullChat(currentChatId, 0, true), 1000);
if (!isChannel) {
finishFragment();
}
}));
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(requestId, true));
showDialog(progressDialog[0]);
}, 500);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
}
});
updateRows();
return fragmentView;
}
Aggregations