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());
}
}
Aggregations