Java Code Examples for org.telegram.ui.ActionBar.BaseFragment#getParentActivity()

The following examples show how to use org.telegram.ui.ActionBar.BaseFragment#getParentActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static Toast showSimpleToast(BaseFragment baseFragment, final String text)
{
    if (text == null)
    {
        return null;
    }
    Context context;
    if (baseFragment != null && baseFragment.getParentActivity() != null)
    {
        context = baseFragment.getParentActivity();
    }
    else
    {
        context = ApplicationLoader.applicationContext;
    }
    Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
    toast.show();
    return toast;
}
 
Example 2
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment)
{
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null)
    {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60)
    {
        timeString = LocaleController.formatPluralString("Seconds", time);
    }
    else
    {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 3
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static void processCreate(EditTextBoldCursor editText, AlertDialog alertDialog, BaseFragment fragment) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    AndroidUtilities.hideKeyboard(editText);
    Theme.ThemeInfo themeInfo = Theme.createNewTheme(editText.getText().toString());
    NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeListUpdated);

    ThemeEditorView themeEditorView = new ThemeEditorView();
    themeEditorView.show(fragment.getParentActivity(), themeInfo);
    alertDialog.dismiss();

    SharedPreferences preferences = MessagesController.getGlobalMainSettings();
    if (preferences.getBoolean("themehint", false)) {
        return;
    }
    preferences.edit().putBoolean("themehint", true).commit();
    try {
        Toast.makeText(fragment.getParentActivity(), LocaleController.getString("CreateNewThemeHelp", R.string.CreateNewThemeHelp), Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 4
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment)
{
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null)
    {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60)
    {
        timeString = LocaleController.formatPluralString("Seconds", time);
    }
    else
    {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 5
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showSendMediaAlert(int result, final BaseFragment fragment)
{
    if (result == 0)
    {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (result == 1)
    {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickers", R.string.ErrorSendRestrictedStickers));
    }
    else if (result == 2)
    {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedMedia", R.string.ErrorSendRestrictedMedia));
    }
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 6
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment) {
    try {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        if (fragment.getParentActivity() == null) {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage(LocaleController.getString("InstallGoogleMaps", R.string.InstallGoogleMaps));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            } catch (Exception e1) {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example 7
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment) {
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60) {
        timeString = LocaleController.formatPluralString("Seconds", time);
    } else {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 8
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String text)
{
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null)
    {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example 9
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog createSupportAlert(BaseFragment fragment) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return null;
    }
    final TextView message = new TextView(fragment.getParentActivity());
    Spannable spanned = new SpannableString(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo).replace("\n", "<br>")));
    URLSpan[] spans = spanned.getSpans(0, spanned.length(), URLSpan.class);
    for (int i = 0; i < spans.length; i++) {
        URLSpan span = spans[i];
        int start = spanned.getSpanStart(span);
        int end = spanned.getSpanEnd(span);
        spanned.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL()) {
            @Override
            public void onClick(View widget) {
                fragment.dismissCurrentDialig();
                super.onClick(widget);
            }
        };
        spanned.setSpan(span, start, end, 0);
    }
    message.setText(spanned);
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
    message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection));
    message.setPadding(AndroidUtilities.dp(23), 0, AndroidUtilities.dp(23), 0);
    message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));

    AlertDialog.Builder builder1 = new AlertDialog.Builder(fragment.getParentActivity());
    builder1.setView(message);
    builder1.setTitle(LocaleController.getString("AskAQuestion", R.string.AskAQuestion));
    builder1.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), (dialogInterface, i) -> performAskAQuestion(fragment));
    builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder1.create();
}
 
Example 10
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment)
{
    try
    {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    }
    catch (PackageManager.NameNotFoundException e)
    {
        if (fragment.getParentActivity() == null)
        {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage("Install Google Maps?");
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) ->
        {
            try
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            }
            catch (Exception e1)
            {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example 11
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static Toast showSimpleToast(BaseFragment baseFragment, final String text) {
    if (text == null) {
        return null;
    }
    Context context;
    if (baseFragment != null && baseFragment.getParentActivity() != null) {
        context = baseFragment.getParentActivity();
    } else {
        context = ApplicationLoader.applicationContext;
    }
    Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
    toast.show();
    return toast;
}
 
Example 12
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
    } else {
        String urlFinal;
        if (punycode) {
            try {
                Uri uri = Uri.parse(url);
                String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
                urlFinal = uri.getScheme() + "://" + host + uri.getPath();
            } catch (Exception e) {
                FileLog.e(e);
                urlFinal = url;
            }
        } else {
            urlFinal = url;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
        String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
        int index = format.indexOf("%");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
        if (index >= 0) {
            stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setMessage(stringBuilder);
        builder.setMessageTextViewClickable(false);
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
    }
}
 
Example 13
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String title, final String text) {
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null) {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), title, text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example 14
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
    } else {
        String urlFinal;
        if (punycode) {
            try {
                Uri uri = Uri.parse(url);
                String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
                urlFinal = uri.getScheme() + "://" + host + uri.getPath();
            } catch (Exception e) {
                FileLog.e(e);
                urlFinal = url;
            }
        } else {
            urlFinal = url;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
        String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
        int index = format.indexOf("%");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
        if (index >= 0) {
            stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setMessage(stringBuilder);
        builder.setMessageTextViewClickable(false);
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
    }
}
 
Example 15
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void createThemeCreateDialog(BaseFragment fragment, int type, Theme.ThemeInfo switchToTheme, Theme.ThemeAccent switchToAccent) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    final EditTextBoldCursor editText = new EditTextBoldCursor(context);
    editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("Create", R.string.Create), (dialog, which) -> {

    });

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    final TextView message = new TextView(context);
    if (type != 0) {
        message.setText(AndroidUtilities.replaceTags(LocaleController.getString("EnterThemeNameEdit", R.string.EnterThemeNameEdit)));
    } else {
        message.setText(LocaleController.getString("EnterThemeName", R.string.EnterThemeName));
    }
    message.setTextSize(16);
    message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23), AndroidUtilities.dp(6));
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    linearLayout.addView(message, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    editText.setGravity(Gravity.LEFT | Gravity.TOP);
    editText.setSingleLine(true);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorSize(AndroidUtilities.dp(20));
    editText.setCursorWidth(1.5f);
    editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
    linearLayout.addView(editText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
    editText.setOnEditorActionListener((textView, i, keyEvent) -> {
        AndroidUtilities.hideKeyboard(textView);
        return false;
    });
    editText.setText(generateThemeName(switchToAccent));
    editText.setSelection(editText.length());

    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    }));
    fragment.showDialog(alertDialog);
    editText.requestFocus();
    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (fragment.getParentActivity() == null) {
            return;
        }
        if (editText.length() == 0) {
            Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator != null) {
                vibrator.vibrate(200);
            }
            AndroidUtilities.shakeView(editText, 2, 0);
            return;
        }
        if (fragment instanceof ThemePreviewActivity) {
            Theme.applyPreviousTheme();
            fragment.finishFragment();
        }
        if (switchToAccent != null) {
            switchToTheme.setCurrentAccentId(switchToAccent.id);
            Theme.refreshThemeColors();
            Utilities.searchQueue.postRunnable(() -> AndroidUtilities.runOnUIThread(() -> processCreate(editText, alertDialog, fragment)));
            return;
        }
        processCreate(editText, alertDialog, fragment);
    });
}
 
Example 16
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    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));
    }
}
 
Example 17
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    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));
    }
}
 
Example 18
Source File: CameraScanActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static ActionBarLayout[] showAsSheet(BaseFragment parentFragment, boolean gallery, CameraScanActivityDelegate delegate) {
    if (parentFragment == null || parentFragment.getParentActivity() == null) {
        return null;
    }
    ActionBarLayout[] actionBarLayout = new ActionBarLayout[]{new ActionBarLayout(parentFragment.getParentActivity())};
    BottomSheet bottomSheet = new BottomSheet(parentFragment.getParentActivity(), false) {
        {
            actionBarLayout[0].init(new ArrayList<>());
            CameraScanActivity fragment = new CameraScanActivity(TYPE_QR) {
                @Override
                public void finishFragment() {
                    dismiss();
                }

                @Override
                public void removeSelfFromStack() {
                    dismiss();
                }
            };
            fragment.needGalleryButton = gallery;
            actionBarLayout[0].addFragmentToStack(fragment);
            actionBarLayout[0].showLastFragment();
            actionBarLayout[0].setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);
            fragment.setDelegate(delegate);
            containerView = actionBarLayout[0];
            setApplyBottomPadding(false);
            setApplyBottomPadding(false);
            setOnDismissListener(dialog -> fragment.onFragmentDestroy());
        }

        @Override
        protected boolean canDismissWithSwipe() {
            return false;
        }

        @Override
        public void onBackPressed() {
            if (actionBarLayout[0] == null || actionBarLayout[0].fragmentsStack.size() <= 1) {
                super.onBackPressed();
            } else {
                actionBarLayout[0].onBackPressed();
            }
        }

        @Override
        public void dismiss() {
            super.dismiss();
            actionBarLayout[0] = null;
        }
    };

    bottomSheet.show();
    return actionBarLayout;
}
 
Example 19
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void openSharing(BaseFragment fragment, String url) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    fragment.showDialog(new ShareAlert(fragment.getParentActivity(), null, url, false, url, false));
}
 
Example 20
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static void openSharing(BaseFragment fragment, String url) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    fragment.showDialog(new ShareAlert(fragment.getParentActivity(), null, url, false, url, false));
}