Search in sources :

Example 11 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChangeBioActivity method saveName.

private void saveName() {
    final TLRPC.UserFull userFull = MessagesController.getInstance(currentAccount).getUserFull(UserConfig.getInstance(currentAccount).getClientUserId());
    if (getParentActivity() == null || userFull == null) {
        return;
    }
    String currentName = userFull.about;
    if (currentName == null) {
        currentName = "";
    }
    final String newName = firstNameField.getText().toString().replace("\n", "");
    if (currentName.equals(newName)) {
        finishFragment();
        return;
    }
    final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
    final TLRPC.TL_account_updateProfile req = new TLRPC.TL_account_updateProfile();
    req.about = newName;
    req.flags |= 4;
    final int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (error == null) {
            final TLRPC.User user = (TLRPC.User) response;
            AndroidUtilities.runOnUIThread(() -> {
                try {
                    progressDialog.dismiss();
                } catch (Exception e) {
                    FileLog.e(e);
                }
                userFull.about = newName;
                NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.userInfoDidLoad, user.id, userFull);
                finishFragment();
            });
        } else {
            AndroidUtilities.runOnUIThread(() -> {
                try {
                    progressDialog.dismiss();
                } catch (Exception e) {
                    FileLog.e(e);
                }
                AlertsCreator.processError(currentAccount, error, ChangeBioActivity.this, req);
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
    ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
    progressDialog.setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true));
    progressDialog.show();
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TLRPC(org.telegram.tgnet.TLRPC)

Example 12 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class JoinCallAlert method checkFewUsers.

public static void checkFewUsers(Context context, long did, AccountInstance accountInstance, MessagesStorage.BooleanCallback callback) {
    if (lastCachedAccount == accountInstance.getCurrentAccount() && lastCacheDid == did && cachedChats != null && SystemClock.elapsedRealtime() - lastCacheTime < 4 * 60 * 1000) {
        callback.run(cachedChats.size() == 1);
        return;
    }
    final AlertDialog progressDialog = new AlertDialog(context, 3);
    TLRPC.TL_phone_getGroupCallJoinAs req = new TLRPC.TL_phone_getGroupCallJoinAs();
    req.peer = accountInstance.getMessagesController().getInputPeer(did);
    int reqId = accountInstance.getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        try {
            progressDialog.dismiss();
        } catch (Exception e) {
            FileLog.e(e);
        }
        if (response != null) {
            TLRPC.TL_phone_joinAsPeers res = (TLRPC.TL_phone_joinAsPeers) response;
            cachedChats = res.peers;
            lastCacheDid = did;
            lastCacheTime = SystemClock.elapsedRealtime();
            lastCachedAccount = accountInstance.getCurrentAccount();
            accountInstance.getMessagesController().putChats(res.chats, false);
            accountInstance.getMessagesController().putUsers(res.users, false);
            callback.run(res.peers.size() == 1);
        }
    }));
    progressDialog.setOnCancelListener(dialog -> accountInstance.getConnectionsManager().cancelRequest(reqId, true));
    try {
        progressDialog.showDelayed(500);
    } catch (Exception ignore) {
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TLRPC(org.telegram.tgnet.TLRPC)

Example 13 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesController method checkCanOpenChat.

public boolean checkCanOpenChat(Bundle bundle, BaseFragment fragment, MessageObject originalMessage) {
    if (bundle == null || fragment == null) {
        return true;
    }
    TLRPC.User user = null;
    TLRPC.Chat chat = null;
    long userId = bundle.getLong("user_id", 0);
    long chatId = bundle.getLong("chat_id", 0);
    int messageId = bundle.getInt("message_id", 0);
    if (userId != 0) {
        user = getUser(userId);
    } else if (chatId != 0) {
        chat = getChat(chatId);
    }
    if (user == null && chat == null) {
        return true;
    }
    String reason;
    if (chat != null) {
        reason = getRestrictionReason(chat.restriction_reason);
    } else {
        reason = getRestrictionReason(user.restriction_reason);
    }
    if (reason != null) {
        showCantOpenAlert(fragment, reason);
        return false;
    }
    if (messageId != 0 && originalMessage != null && chat != null && chat.access_hash == 0) {
        long did = originalMessage.getDialogId();
        if (!DialogObject.isEncryptedDialog(did)) {
            AlertDialog progressDialog = new AlertDialog(fragment.getParentActivity(), 3);
            TLObject req;
            if (did < 0) {
                chat = getChat(-did);
            }
            if (did > 0 || !ChatObject.isChannel(chat)) {
                TLRPC.TL_messages_getMessages request = new TLRPC.TL_messages_getMessages();
                request.id.add(originalMessage.getId());
                req = request;
            } else {
                chat = getChat(-did);
                TLRPC.TL_channels_getMessages request = new TLRPC.TL_channels_getMessages();
                request.channel = getInputChannel(chat);
                request.id.add(originalMessage.getId());
                req = request;
            }
            int reqId = getConnectionsManager().sendRequest(req, (response, error) -> {
                if (response != null) {
                    AndroidUtilities.runOnUIThread(() -> {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                        putUsers(res.users, false);
                        putChats(res.chats, false);
                        getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
                        fragment.presentFragment(new ChatActivity(bundle), true);
                    });
                }
            });
            progressDialog.setOnCancelListener(dialog -> {
                getConnectionsManager().cancelRequest(reqId, true);
                fragment.setVisibleDialog(null);
            });
            fragment.setVisibleDialog(progressDialog);
            progressDialog.show();
            return false;
        }
    }
    return true;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ChatActivity(org.telegram.ui.ChatActivity) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) TLObject(org.telegram.tgnet.TLObject)

Example 14 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesController method convertToMegaGroup.

public void convertToMegaGroup(Context context, long chatId, BaseFragment fragment, MessagesStorage.LongCallback convertRunnable) {
    TLRPC.TL_messages_migrateChat req = new TLRPC.TL_messages_migrateChat();
    req.chat_id = chatId;
    AlertDialog progressDialog = context != null ? new AlertDialog(context, 3) : null;
    int reqId = getConnectionsManager().sendRequest(req, (response, error) -> {
        if (error == null) {
            if (context != null) {
                AndroidUtilities.runOnUIThread(() -> {
                    if (!((Activity) context).isFinishing()) {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    }
                });
            }
            TLRPC.Updates updates = (TLRPC.Updates) response;
            processUpdates((TLRPC.Updates) response, false);
            AndroidUtilities.runOnUIThread(() -> {
                if (convertRunnable != null) {
                    for (int a = 0; a < updates.chats.size(); a++) {
                        TLRPC.Chat chat = updates.chats.get(a);
                        if (ChatObject.isChannel(chat)) {
                            convertRunnable.run(chat.id);
                            break;
                        }
                    }
                }
            });
        } else {
            AndroidUtilities.runOnUIThread(() -> {
                if (convertRunnable != null) {
                    convertRunnable.run(0);
                }
                if (context != null) {
                    if (!((Activity) context).isFinishing()) {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        AlertsCreator.processError(currentAccount, error, fragment, req, false);
                    }
                }
            });
        }
    });
    if (progressDialog != null) {
        progressDialog.setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(reqId, true));
        try {
            progressDialog.show();
        } catch (Exception ignore) {
        }
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 15 with AlertDialog

use of org.telegram.ui.ActionBar.AlertDialog 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));
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView)

Aggregations

AlertDialog (org.telegram.ui.ActionBar.AlertDialog)101 TLRPC (org.telegram.tgnet.TLRPC)71 TextView (android.widget.TextView)63 FrameLayout (android.widget.FrameLayout)47 ArrayList (java.util.ArrayList)47 Context (android.content.Context)45 View (android.view.View)44 AndroidUtilities (org.telegram.messenger.AndroidUtilities)41 LocaleController (org.telegram.messenger.LocaleController)41 Theme (org.telegram.ui.ActionBar.Theme)41 R (org.telegram.messenger.R)40 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)40 LinearLayout (android.widget.LinearLayout)38 Paint (android.graphics.Paint)37 MessagesController (org.telegram.messenger.MessagesController)37 SuppressLint (android.annotation.SuppressLint)36 TextUtils (android.text.TextUtils)36 FileLog (org.telegram.messenger.FileLog)36 Build (android.os.Build)34 Gravity (android.view.Gravity)34