Search in sources :

Example 1 with ChatActivity

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

the class SendMessagesHelper method sendCallback.

public void sendCallback(final boolean cache, final MessageObject messageObject, final TLRPC.KeyboardButton button, TLRPC.InputCheckPasswordSRP srp, TwoStepVerificationActivity passwordFragment, final ChatActivity parentFragment) {
    if (messageObject == null || button == null || parentFragment == null) {
        return;
    }
    final boolean cacheFinal;
    int type;
    if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
        cacheFinal = false;
        type = 3;
    } else if (button instanceof TLRPC.TL_keyboardButtonGame) {
        cacheFinal = false;
        type = 1;
    } else {
        cacheFinal = cache;
        if (button instanceof TLRPC.TL_keyboardButtonBuy) {
            type = 2;
        } else {
            type = 0;
        }
    }
    final String key = messageObject.getDialogId() + "_" + messageObject.getId() + "_" + Utilities.bytesToHex(button.data) + "_" + type;
    waitingForCallback.put(key, true);
    TLObject[] request = new TLObject[1];
    RequestDelegate requestDelegate = (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        waitingForCallback.remove(key);
        if (cacheFinal && response == null) {
            sendCallback(false, messageObject, button, parentFragment);
        } else if (response != null) {
            if (passwordFragment != null) {
                passwordFragment.needHideProgress();
                passwordFragment.finishFragment();
            }
            if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
                if (response instanceof TLRPC.TL_urlAuthResultRequest) {
                    TLRPC.TL_urlAuthResultRequest res = (TLRPC.TL_urlAuthResultRequest) response;
                    parentFragment.showRequestUrlAlert(res, (TLRPC.TL_messages_requestUrlAuth) request[0], button.url, false);
                } else if (response instanceof TLRPC.TL_urlAuthResultAccepted) {
                    TLRPC.TL_urlAuthResultAccepted res = (TLRPC.TL_urlAuthResultAccepted) response;
                    AlertsCreator.showOpenUrlAlert(parentFragment, res.url, false, false);
                } else if (response instanceof TLRPC.TL_urlAuthResultDefault) {
                    TLRPC.TL_urlAuthResultDefault res = (TLRPC.TL_urlAuthResultDefault) response;
                    AlertsCreator.showOpenUrlAlert(parentFragment, button.url, false, true);
                }
            } else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
                if (response instanceof TLRPC.TL_payments_paymentForm) {
                    final TLRPC.TL_payments_paymentForm form = (TLRPC.TL_payments_paymentForm) response;
                    getMessagesController().putUsers(form.users, false);
                    parentFragment.presentFragment(new PaymentFormActivity(form, messageObject, parentFragment));
                } else if (response instanceof TLRPC.TL_payments_paymentReceipt) {
                    parentFragment.presentFragment(new PaymentFormActivity((TLRPC.TL_payments_paymentReceipt) response));
                }
            } else {
                TLRPC.TL_messages_botCallbackAnswer res = (TLRPC.TL_messages_botCallbackAnswer) response;
                if (!cacheFinal && res.cache_time != 0 && !button.requires_password) {
                    getMessagesStorage().saveBotCache(key, res);
                }
                if (res.message != null) {
                    long uid = messageObject.getFromChatId();
                    if (messageObject.messageOwner.via_bot_id != 0) {
                        uid = messageObject.messageOwner.via_bot_id;
                    }
                    String name = null;
                    if (uid > 0) {
                        TLRPC.User user = getMessagesController().getUser(uid);
                        if (user != null) {
                            name = ContactsController.formatName(user.first_name, user.last_name);
                        }
                    } else {
                        TLRPC.Chat chat = getMessagesController().getChat(-uid);
                        if (chat != null) {
                            name = chat.title;
                        }
                    }
                    if (name == null) {
                        name = "bot";
                    }
                    if (res.alert) {
                        if (parentFragment.getParentActivity() == null) {
                            return;
                        }
                        AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
                        builder.setTitle(name);
                        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                        builder.setMessage(res.message);
                        parentFragment.showDialog(builder.create());
                    } else {
                        parentFragment.showAlert(name, res.message);
                    }
                } else if (res.url != null) {
                    if (parentFragment.getParentActivity() == null) {
                        return;
                    }
                    long uid = messageObject.getFromChatId();
                    if (messageObject.messageOwner.via_bot_id != 0) {
                        uid = messageObject.messageOwner.via_bot_id;
                    }
                    TLRPC.User user = getMessagesController().getUser(uid);
                    boolean verified = user != null && user.verified;
                    if (button instanceof TLRPC.TL_keyboardButtonGame) {
                        TLRPC.TL_game game = messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame ? messageObject.messageOwner.media.game : null;
                        if (game == null) {
                            return;
                        }
                        parentFragment.showOpenGameAlert(game, messageObject, res.url, !verified && MessagesController.getNotificationsSettings(currentAccount).getBoolean("askgame_" + uid, true), uid);
                    } else {
                        AlertsCreator.showOpenUrlAlert(parentFragment, res.url, false, false);
                    }
                }
            }
        } else if (error != null) {
            if (parentFragment.getParentActivity() == null) {
                return;
            }
            if ("PASSWORD_HASH_INVALID".equals(error.text)) {
                if (srp == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
                    builder.setTitle(LocaleController.getString("BotOwnershipTransfer", R.string.BotOwnershipTransfer));
                    builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BotOwnershipTransferReadyAlertText", R.string.BotOwnershipTransferReadyAlertText)));
                    builder.setPositiveButton(LocaleController.getString("BotOwnershipTransferChangeOwner", R.string.BotOwnershipTransferChangeOwner), (dialogInterface, i) -> {
                        TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
                        fragment.setDelegate(password -> sendCallback(cache, messageObject, button, password, fragment, parentFragment));
                        parentFragment.presentFragment(fragment);
                    });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    parentFragment.showDialog(builder.create());
                }
            } else if ("PASSWORD_MISSING".equals(error.text) || error.text.startsWith("PASSWORD_TOO_FRESH_") || error.text.startsWith("SESSION_TOO_FRESH_")) {
                if (passwordFragment != null) {
                    passwordFragment.needHideProgress();
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
                builder.setTitle(LocaleController.getString("EditAdminTransferAlertTitle", R.string.EditAdminTransferAlertTitle));
                LinearLayout linearLayout = new LinearLayout(parentFragment.getParentActivity());
                linearLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(2), AndroidUtilities.dp(24), 0);
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                builder.setView(linearLayout);
                TextView messageTextView = new TextView(parentFragment.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);
                messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("BotOwnershipTransferAlertText", R.string.BotOwnershipTransferAlertText)));
                linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                LinearLayout linearLayout2 = new LinearLayout(parentFragment.getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
                ImageView dotImageView = new ImageView(parentFragment.getParentActivity());
                dotImageView.setImageResource(R.drawable.list_circle);
                dotImageView.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(11) : 0, AndroidUtilities.dp(9), LocaleController.isRTL ? 0 : AndroidUtilities.dp(11), 0);
                dotImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogTextBlack), PorterDuff.Mode.MULTIPLY));
                messageTextView = new TextView(parentFragment.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);
                messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("EditAdminTransferAlertText1", R.string.EditAdminTransferAlertText1)));
                if (LocaleController.isRTL) {
                    linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                    linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT));
                } else {
                    linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
                    linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                }
                linearLayout2 = new LinearLayout(parentFragment.getParentActivity());
                linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
                dotImageView = new ImageView(parentFragment.getParentActivity());
                dotImageView.setImageResource(R.drawable.list_circle);
                dotImageView.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(11) : 0, AndroidUtilities.dp(9), LocaleController.isRTL ? 0 : AndroidUtilities.dp(11), 0);
                dotImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogTextBlack), PorterDuff.Mode.MULTIPLY));
                messageTextView = new TextView(parentFragment.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);
                messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("EditAdminTransferAlertText2", R.string.EditAdminTransferAlertText2)));
                if (LocaleController.isRTL) {
                    linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                    linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT));
                } else {
                    linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
                    linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                }
                if ("PASSWORD_MISSING".equals(error.text)) {
                    builder.setPositiveButton(LocaleController.getString("EditAdminTransferSetPassword", R.string.EditAdminTransferSetPassword), (dialogInterface, i) -> parentFragment.presentFragment(new TwoStepVerificationSetupActivity(TwoStepVerificationSetupActivity.TYPE_INTRO, null)));
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                } else {
                    messageTextView = new TextView(parentFragment.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);
                    messageTextView.setText(LocaleController.getString("EditAdminTransferAlertText3", R.string.EditAdminTransferAlertText3));
                    linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
                    builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
                }
                parentFragment.showDialog(builder.create());
            } else if ("SRP_ID_INVALID".equals(error.text)) {
                TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
                ConnectionsManager.getInstance(currentAccount).sendRequest(getPasswordReq, (response2, error2) -> AndroidUtilities.runOnUIThread(() -> {
                    if (error2 == null) {
                        TLRPC.TL_account_password currentPassword = (TLRPC.TL_account_password) response2;
                        passwordFragment.setCurrentPasswordInfo(null, currentPassword);
                        TwoStepVerificationActivity.initPasswordNewAlgo(currentPassword);
                        sendCallback(cache, messageObject, button, passwordFragment.getNewSrpPassword(), passwordFragment, parentFragment);
                    }
                }), ConnectionsManager.RequestFlagWithoutLogin);
            } else {
                if (passwordFragment != null) {
                    passwordFragment.needHideProgress();
                    passwordFragment.finishFragment();
                }
            }
        }
    });
    if (cacheFinal) {
        getMessagesStorage().getBotCache(key, requestDelegate);
    } else {
        if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
            TLRPC.TL_messages_requestUrlAuth req = new TLRPC.TL_messages_requestUrlAuth();
            req.peer = getMessagesController().getInputPeer(messageObject.getDialogId());
            req.msg_id = messageObject.getId();
            req.button_id = button.button_id;
            req.flags |= 2;
            request[0] = req;
            getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
        } else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
            if ((messageObject.messageOwner.media.flags & 4) == 0) {
                TLRPC.TL_payments_getPaymentForm req = new TLRPC.TL_payments_getPaymentForm();
                req.msg_id = messageObject.getId();
                req.peer = getMessagesController().getInputPeer(messageObject.messageOwner.peer_id);
                try {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("bg_color", Theme.getColor(Theme.key_windowBackgroundWhite));
                    jsonObject.put("text_color", Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                    jsonObject.put("hint_color", Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
                    jsonObject.put("link_color", Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
                    jsonObject.put("button_color", Theme.getColor(Theme.key_featuredStickers_addButton));
                    jsonObject.put("button_text_color", Theme.getColor(Theme.key_featuredStickers_buttonText));
                    req.theme_params = new TLRPC.TL_dataJSON();
                    req.theme_params.data = jsonObject.toString();
                    req.flags |= 1;
                } catch (Exception e) {
                    FileLog.e(e);
                }
                getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
            } else {
                TLRPC.TL_payments_getPaymentReceipt req = new TLRPC.TL_payments_getPaymentReceipt();
                req.msg_id = messageObject.messageOwner.media.receipt_msg_id;
                req.peer = getMessagesController().getInputPeer(messageObject.messageOwner.peer_id);
                getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
            }
        } else {
            TLRPC.TL_messages_getBotCallbackAnswer req = new TLRPC.TL_messages_getBotCallbackAnswer();
            req.peer = getMessagesController().getInputPeer(messageObject.getDialogId());
            req.msg_id = messageObject.getId();
            req.game = button instanceof TLRPC.TL_keyboardButtonGame;
            if (button.requires_password) {
                req.password = req.password = srp != null ? srp : new TLRPC.TL_inputCheckPasswordEmpty();
                ;
                req.flags |= 4;
            }
            if (button.data != null) {
                req.flags |= 1;
                req.data = button.data;
            }
            getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) LinearLayout(android.widget.LinearLayout) SparseLongArray(org.telegram.messenger.support.SparseLongArray) Bundle(android.os.Bundle) Uri(android.net.Uri) ImageView(android.widget.ImageView) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) LocationListener(android.location.LocationListener) Bulletin(org.telegram.ui.Components.Bulletin) ByteBuffer(java.nio.ByteBuffer) AudioInfo(org.telegram.messenger.audioinfo.AudioInfo) JSONObject(org.json.JSONObject) MediaCodecInfo(android.media.MediaCodecInfo) Locale(java.util.Locale) MediaStore(android.provider.MediaStore) UiThread(androidx.annotation.UiThread) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) SparseArray(android.util.SparseArray) CountDownLatch(java.util.concurrent.CountDownLatch) TextView(android.widget.TextView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Location(android.location.Location) LocationManager(android.location.LocationManager) ChatActivity(org.telegram.ui.ChatActivity) Context(android.content.Context) MediaMetadataRetriever(android.media.MediaMetadataRetriever) Theme(org.telegram.ui.ActionBar.Theme) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RequestDelegate(org.telegram.tgnet.RequestDelegate) TwoStepVerificationActivity(org.telegram.ui.TwoStepVerificationActivity) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) MediaPlayer(android.media.MediaPlayer) SystemClock(android.os.SystemClock) HashMap(java.util.HashMap) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TLRPC(org.telegram.tgnet.TLRPC) Point(org.telegram.ui.Components.Point) Toast(android.widget.Toast) PaymentFormActivity(org.telegram.ui.PaymentFormActivity) TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Build(android.os.Build) SerializedData(org.telegram.tgnet.SerializedData) LongSparseArray(androidx.collection.LongSparseArray) TwoStepVerificationSetupActivity(org.telegram.ui.TwoStepVerificationSetupActivity) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) InputContentInfoCompat(androidx.core.view.inputmethod.InputContentInfoCompat) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileInputStream(java.io.FileInputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Gravity(android.view.Gravity) TypedValue(android.util.TypedValue) Bitmap(android.graphics.Bitmap) Base64(android.util.Base64) ClipDescription(android.content.ClipDescription) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) FileChannel(java.nio.channels.FileChannel) MimeTypeMap(android.webkit.MimeTypeMap) InputStream(java.io.InputStream) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TLRPC(org.telegram.tgnet.TLRPC) PaymentFormActivity(org.telegram.ui.PaymentFormActivity) TextView(android.widget.TextView) ImageView(android.widget.ImageView) RequestDelegate(org.telegram.tgnet.RequestDelegate) TwoStepVerificationActivity(org.telegram.ui.TwoStepVerificationActivity) JSONObject(org.json.JSONObject) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) TwoStepVerificationSetupActivity(org.telegram.ui.TwoStepVerificationSetupActivity) Point(org.telegram.ui.Components.Point) TLObject(org.telegram.tgnet.TLObject) LinearLayout(android.widget.LinearLayout)

Example 2 with ChatActivity

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

the class AlertsCreator method createReportAlert.

public static void createReportAlert(final Context context, final long dialog_id, final int messageId, final BaseFragment parentFragment, Theme.ResourcesProvider resourcesProvider, Runnable hideDim) {
    if (context == null || parentFragment == null) {
        return;
    }
    BottomSheet.Builder builder = new BottomSheet.Builder(context, true, resourcesProvider);
    builder.setDimBehind(hideDim == null);
    builder.setOnPreDismissListener(di -> {
        if (hideDim != null) {
            hideDim.run();
        }
    });
    builder.setTitle(LocaleController.getString("ReportChat", R.string.ReportChat), true);
    CharSequence[] items;
    int[] icons;
    if (messageId != 0) {
        items = new CharSequence[] { LocaleController.getString("ReportChatSpam", R.string.ReportChatSpam), LocaleController.getString("ReportChatViolence", R.string.ReportChatViolence), LocaleController.getString("ReportChatChild", R.string.ReportChatChild), LocaleController.getString("ReportChatPornography", R.string.ReportChatPornography), LocaleController.getString("ReportChatOther", R.string.ReportChatOther) };
        icons = new int[] { R.drawable.msg_report_spam, R.drawable.msg_report_violence, R.drawable.msg_report_abuse, R.drawable.msg_report_xxx, R.drawable.msg_report_other };
    } else {
        items = new CharSequence[] { LocaleController.getString("ReportChatSpam", R.string.ReportChatSpam), LocaleController.getString("ReportChatFakeAccount", R.string.ReportChatFakeAccount), LocaleController.getString("ReportChatViolence", R.string.ReportChatViolence), LocaleController.getString("ReportChatChild", R.string.ReportChatChild), LocaleController.getString("ReportChatPornography", R.string.ReportChatPornography), LocaleController.getString("ReportChatOther", R.string.ReportChatOther) };
        icons = new int[] { R.drawable.msg_report_spam, R.drawable.msg_report_fake, R.drawable.msg_report_violence, R.drawable.msg_report_abuse, R.drawable.msg_report_xxx, R.drawable.msg_report_other };
    }
    builder.setItems(items, icons, (dialogInterface, i) -> {
        if (messageId == 0 && (i == 0 || i == 2 || i == 3 || i == 4) && parentFragment instanceof ChatActivity) {
            ((ChatActivity) parentFragment).openReportChat(i);
            return;
        } else if (messageId == 0 && (i == 5 || i == 1) || messageId != 0 && i == 4) {
            if (parentFragment instanceof ChatActivity) {
                AndroidUtilities.requestAdjustNothing(parentFragment.getParentActivity(), parentFragment.getClassGuid());
            }
            parentFragment.showDialog(new ReportAlert(context, i == 4 ? 5 : i) {

                @Override
                public void dismissInternal() {
                    super.dismissInternal();
                    if (parentFragment instanceof ChatActivity) {
                        ((ChatActivity) parentFragment).checkAdjustResize();
                    }
                }

                @Override
                protected void onSend(int type, String message) {
                    ArrayList<Integer> ids = new ArrayList<>();
                    if (messageId != 0) {
                        ids.add(messageId);
                    }
                    TLRPC.InputPeer peer = MessagesController.getInstance(UserConfig.selectedAccount).getInputPeer(dialog_id);
                    sendReport(peer, type, message, ids);
                    if (parentFragment instanceof ChatActivity) {
                        ((ChatActivity) parentFragment).getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
                    }
                }
            });
            return;
        }
        TLObject req;
        TLRPC.InputPeer peer = MessagesController.getInstance(UserConfig.selectedAccount).getInputPeer(dialog_id);
        if (messageId != 0) {
            TLRPC.TL_messages_report request = new TLRPC.TL_messages_report();
            request.peer = peer;
            request.id.add(messageId);
            request.message = "";
            if (i == 0) {
                request.reason = new TLRPC.TL_inputReportReasonSpam();
            } else if (i == 1) {
                request.reason = new TLRPC.TL_inputReportReasonViolence();
            } else if (i == 2) {
                request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
            } else if (i == 3) {
                request.reason = new TLRPC.TL_inputReportReasonPornography();
            }
            req = request;
        } else {
            TLRPC.TL_account_reportPeer request = new TLRPC.TL_account_reportPeer();
            request.peer = peer;
            request.message = "";
            if (i == 0) {
                request.reason = new TLRPC.TL_inputReportReasonSpam();
            } else if (i == 1) {
                request.reason = new TLRPC.TL_inputReportReasonFake();
            } else if (i == 2) {
                request.reason = new TLRPC.TL_inputReportReasonViolence();
            } else if (i == 3) {
                request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
            } else if (i == 4) {
                request.reason = new TLRPC.TL_inputReportReasonPornography();
            }
            req = request;
        }
        ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, (response, error) -> {
        });
        if (parentFragment instanceof ChatActivity) {
            ((ChatActivity) parentFragment).getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
        } else {
            BulletinFactory.of(parentFragment).createReportSent(resourcesProvider).show();
        }
    });
    BottomSheet sheet = builder.create();
    parentFragment.showDialog(sheet);
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) BottomSheet(org.telegram.ui.ActionBar.BottomSheet)

Example 3 with ChatActivity

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

the class AlertsCreator method performAskAQuestion.

private static void performAskAQuestion(BaseFragment fragment) {
    int currentAccount = fragment.getCurrentAccount();
    final SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
    long uid = AndroidUtilities.getPrefIntOrLong(preferences, "support_id2", 0);
    TLRPC.User supportUser = null;
    if (uid != 0) {
        supportUser = MessagesController.getInstance(currentAccount).getUser(uid);
        if (supportUser == null) {
            String userString = preferences.getString("support_user", null);
            if (userString != null) {
                try {
                    byte[] datacentersBytes = Base64.decode(userString, Base64.DEFAULT);
                    if (datacentersBytes != null) {
                        SerializedData data = new SerializedData(datacentersBytes);
                        supportUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
                        if (supportUser != null && supportUser.id == 333000) {
                            supportUser = null;
                        }
                        data.cleanup();
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                    supportUser = null;
                }
            }
        }
    }
    if (supportUser == null) {
        final AlertDialog progressDialog = new AlertDialog(fragment.getParentActivity(), 3);
        progressDialog.setCanCacnel(false);
        progressDialog.show();
        TLRPC.TL_help_getSupport req = new TLRPC.TL_help_getSupport();
        ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
            if (error == null) {
                final TLRPC.TL_help_support res = (TLRPC.TL_help_support) response;
                AndroidUtilities.runOnUIThread(() -> {
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putLong("support_id2", res.user.id);
                    SerializedData data = new SerializedData();
                    res.user.serializeToStream(data);
                    editor.putString("support_user", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
                    editor.commit();
                    data.cleanup();
                    try {
                        progressDialog.dismiss();
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                    ArrayList<TLRPC.User> users = new ArrayList<>();
                    users.add(res.user);
                    MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
                    MessagesController.getInstance(currentAccount).putUser(res.user, false);
                    Bundle args = new Bundle();
                    args.putLong("user_id", res.user.id);
                    fragment.presentFragment(new ChatActivity(args));
                });
            } else {
                AndroidUtilities.runOnUIThread(() -> {
                    try {
                        progressDialog.dismiss();
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                });
            }
        });
    } else {
        MessagesController.getInstance(currentAccount).putUser(supportUser, true);
        Bundle args = new Bundle();
        args.putLong("user_id", supportUser.id);
        fragment.presentFragment(new ChatActivity(args));
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ChatActivity(org.telegram.ui.ChatActivity) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) SerializedData(org.telegram.tgnet.SerializedData) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC)

Example 4 with ChatActivity

use of org.telegram.ui.ChatActivity 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));
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ChatActivity(org.telegram.ui.ChatActivity) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) AccountInstance(org.telegram.messenger.AccountInstance) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 5 with ChatActivity

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

the class BackButtonMenu method getStackedHistoryDialogs.

public static ArrayList<PulledDialog> getStackedHistoryDialogs(BaseFragment thisFragment, long ignoreDialogId) {
    ArrayList<PulledDialog> dialogs = new ArrayList<>();
    if (thisFragment == null)
        return dialogs;
    final ActionBarLayout parentLayout = thisFragment.getParentLayout();
    if (parentLayout == null)
        return dialogs;
    ArrayList<BaseFragment> fragmentsStack = parentLayout.fragmentsStack;
    ArrayList<PulledDialog> pulledDialogs = parentLayout.pulledDialogs;
    if (fragmentsStack != null) {
        final int count = fragmentsStack.size();
        for (int i = 0; i < count; ++i) {
            BaseFragment fragment = fragmentsStack.get(i);
            Class activity;
            TLRPC.Chat chat;
            TLRPC.User user = null;
            long dialogId;
            int folderId, filterId;
            if (fragment instanceof ChatActivity) {
                activity = ChatActivity.class;
                ChatActivity chatActivity = (ChatActivity) fragment;
                if (chatActivity.getChatMode() != 0 || chatActivity.isReport()) {
                    continue;
                }
                chat = chatActivity.getCurrentChat();
                user = chatActivity.getCurrentUser();
                dialogId = chatActivity.getDialogId();
                folderId = chatActivity.getDialogFolderId();
                filterId = chatActivity.getDialogFilterId();
            } else if (fragment instanceof ProfileActivity) {
                activity = ProfileActivity.class;
                ProfileActivity profileActivity = (ProfileActivity) fragment;
                chat = profileActivity.getCurrentChat();
                try {
                    user = profileActivity.getUserInfo().user;
                } catch (Exception ignore) {
                }
                dialogId = profileActivity.getDialogId();
                folderId = 0;
                filterId = 0;
            } else {
                continue;
            }
            if (dialogId != ignoreDialogId && !(ignoreDialogId == 0 && UserObject.isUserSelf(user))) {
                boolean alreadyAddedDialog = false;
                for (int d = 0; d < dialogs.size(); ++d) {
                    if (dialogs.get(d).dialogId == dialogId) {
                        alreadyAddedDialog = true;
                        break;
                    }
                }
                if (!alreadyAddedDialog) {
                    PulledDialog pDialog = new PulledDialog();
                    pDialog.activity = activity;
                    pDialog.stackIndex = i;
                    pDialog.chat = chat;
                    pDialog.user = user;
                    pDialog.dialogId = dialogId;
                    pDialog.folderId = folderId;
                    pDialog.filterId = filterId;
                    if (pDialog.chat != null || pDialog.user != null) {
                        dialogs.add(pDialog);
                    }
                }
            }
        }
    }
    if (pulledDialogs != null) {
        for (PulledDialog pulledDialog : pulledDialogs) {
            if (pulledDialog.dialogId == ignoreDialogId) {
                continue;
            }
            boolean alreadyAddedDialog = false;
            for (int d = 0; d < dialogs.size(); ++d) {
                if (dialogs.get(d).dialogId == pulledDialog.dialogId) {
                    alreadyAddedDialog = true;
                    break;
                }
            }
            if (!alreadyAddedDialog) {
                dialogs.add(pulledDialog);
            }
        }
    }
    Collections.sort(dialogs, (d1, d2) -> d2.stackIndex - d1.stackIndex);
    return dialogs;
}
Also used : ProfileActivity(org.telegram.ui.ProfileActivity) ChatActivity(org.telegram.ui.ChatActivity) ArrayList(java.util.ArrayList) ActionBarLayout(org.telegram.ui.ActionBar.ActionBarLayout) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) TLRPC(org.telegram.tgnet.TLRPC)

Aggregations

ChatActivity (org.telegram.ui.ChatActivity)41 Paint (android.graphics.Paint)22 TLRPC (org.telegram.tgnet.TLRPC)21 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 Animator (android.animation.Animator)12 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)12 View (android.view.View)12 TextPaint (android.text.TextPaint)11 AnimatorSet (android.animation.AnimatorSet)10 ObjectAnimator (android.animation.ObjectAnimator)10 ImageView (android.widget.ImageView)10 MessageObject (org.telegram.messenger.MessageObject)10 Bundle (android.os.Bundle)9 ChatObject (org.telegram.messenger.ChatObject)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)8 ValueAnimator (android.animation.ValueAnimator)7 SuppressLint (android.annotation.SuppressLint)7 FrameLayout (android.widget.FrameLayout)6