Search in sources :

Example 41 with ChatActivity

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

the class AlertsCreator method showOpenUrlAlert.

public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask, Theme.ResourcesProvider resourcesProvider) {
    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(), resourcesProvider);
        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());
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ChatActivity(org.telegram.ui.ChatActivity) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) SpannableStringBuilder(android.text.SpannableStringBuilder)

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