use of com.ferg.awfulapp.popupmenu.UrlContextMenu in project Awful.apk by Awful.
the class ThreadDisplayFragment method showUrlMenu.
private void showUrlMenu(final String url) {
if (url == null) {
Timber.w("Passed null URL to #showUrlMenu!");
return;
}
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager == null) {
Timber.w("showUrlMenu called but can't get FragmentManager!");
return;
}
boolean isImage = false;
boolean isGif = false;
// TODO: parsing fails on magic webdev urls like http://tpm2016.zoffix.com/#/40
// it thinks the # is the start of the ref section of the url, so the Path for that url is '/'
Uri path = Uri.parse(url);
String lastSegment = path.getLastPathSegment();
// null-safe path checking (there may be no path segments, e.g. a link to a domain name)
if (lastSegment != null) {
lastSegment = lastSegment.toLowerCase();
// using 'contains' instead of 'ends with' in case of any url suffix shenanigans, like twitter's ".jpg:large"
isImage = (StringUtils.indexOfAny(lastSegment, ".jpg", ".jpeg", ".png", ".gif") != -1 && !StringUtils.contains(lastSegment, ".gifv")) || (lastSegment.equals("attachment.php") && path.getHost().equals("forums.somethingawful.com"));
isGif = StringUtils.contains(lastSegment, ".gif") && !StringUtils.contains(lastSegment, ".gifv");
}
// TODO: 28/04/2017 remove all this when Crashlytics #717 is fixed
if (AwfulApplication.crashlyticsEnabled()) {
Crashlytics.setString("Menu for URL:", url);
Crashlytics.setInt("Thread ID", getThreadId());
Crashlytics.setInt("Page", getPageNumber());
FragmentActivity activity = getActivity();
Crashlytics.setBool("Activity exists", activity != null);
if (activity != null) {
String state = "Activity:";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
state += (activity.isDestroyed()) ? "IS_DESTROYED " : "";
}
state += (activity.isFinishing()) ? "IS_FINISHING" : "";
state += (activity.isChangingConfigurations()) ? "IS_CHANGING_CONFIGURATIONS" : "";
Crashlytics.setString("Activity state:", state);
}
Crashlytics.setBool("Thread display fragment resumed", isResumed());
Crashlytics.setBool("Thread display fragment attached", isAdded());
Crashlytics.setBool("Thread display fragment removing", isRemoving());
}
// //////////////////////////////////////////////////////////////////////
UrlContextMenu linkActions = UrlContextMenu.newInstance(url, isImage, isGif, isGif ? "Getting file size" : null);
if (isGif) {
queueRequest(new ImageSizeRequest(url, result -> {
if (linkActions == null) {
return;
}
String size = result == null ? "unknown" : Formatter.formatShortFileSize(getContext(), result);
linkActions.setSubheading(String.format("Size: %s", size));
}));
}
linkActions.setTargetFragment(ThreadDisplayFragment.this, -1);
linkActions.show(fragmentManager, "Link Actions");
}
Aggregations