Search in sources :

Example 1 with UrlContextMenu

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");
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) JavascriptInterface(android.webkit.JavascriptInterface) IgnoreRequest(com.ferg.awfulapp.task.IgnoreRequest) Constants(com.ferg.awfulapp.constants.Constants) SwipyRefreshLayoutDirection(com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection) Bundle(android.os.Bundle) AwfulRequest(com.ferg.awfulapp.task.AwfulRequest) RedirectTask(com.ferg.awfulapp.task.RedirectTask) PackageManager(android.content.pm.PackageManager) MarkLastReadRequest(com.ferg.awfulapp.task.MarkLastReadRequest) AwfulURL(com.ferg.awfulapp.thread.AwfulURL) Uri(android.net.Uri) BookmarkRequest(com.ferg.awfulapp.task.BookmarkRequest) CloseOpenRequest(com.ferg.awfulapp.task.CloseOpenRequest) SwipyRefreshLayout(com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout) ThreadDisplay(com.ferg.awfulapp.thread.ThreadDisplay) WebViewJsInterface(com.ferg.awfulapp.webview.WebViewJsInterface) StringUtils(org.apache.commons.lang3.StringUtils) Manifest(android.Manifest) CookieManager(android.webkit.CookieManager) Handler(android.os.Handler) Keys(com.ferg.awfulapp.preferences.Keys) Map(java.util.Map) WebViewClient(android.webkit.WebViewClient) View(android.view.View) CookieSyncManager(android.webkit.CookieSyncManager) WebView(android.webkit.WebView) LoaderManager(android.support.v4.app.LoaderManager) ColorProvider(com.ferg.awfulapp.provider.ColorProvider) FloatingActionButton(android.support.design.widget.FloatingActionButton) AwfulUtils(com.ferg.awfulapp.util.AwfulUtils) AsyncTask(android.os.AsyncTask) AwfulThread(com.ferg.awfulapp.thread.AwfulThread) MenuItemCompat(android.support.v4.view.MenuItemCompat) ContextCompat(android.support.v4.content.ContextCompat) PostContextMenu(com.ferg.awfulapp.popupmenu.PostContextMenu) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) ContentObserver(android.database.ContentObserver) AwfulError(com.ferg.awfulapp.util.AwfulError) AlertDialog(android.app.AlertDialog) DownloadManager(android.app.DownloadManager) AwfulPost(com.ferg.awfulapp.thread.AwfulPost) List(java.util.List) TextView(android.widget.TextView) InflateException(android.view.InflateException) FragmentActivity(android.support.v4.app.FragmentActivity) SinglePostRequest(com.ferg.awfulapp.task.SinglePostRequest) ReportRequest(com.ferg.awfulapp.task.ReportRequest) Nullable(android.support.annotation.Nullable) Request(android.app.DownloadManager.Request) AwfulMessage(com.ferg.awfulapp.thread.AwfulMessage) Context(android.content.Context) VoteRequest(com.ferg.awfulapp.task.VoteRequest) AwfulProvider(com.ferg.awfulapp.provider.AwfulProvider) Environment(android.os.Environment) DownloadListener(android.webkit.DownloadListener) Intent(android.content.Intent) CursorLoader(android.support.v4.content.CursorLoader) ShareActionProvider(android.support.v7.widget.ShareActionProvider) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) LoggingWebChromeClient(com.ferg.awfulapp.webview.LoggingWebChromeClient) ProfileRequest(com.ferg.awfulapp.task.ProfileRequest) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) NetworkUtils(com.ferg.awfulapp.network.NetworkUtils) PageBar(com.ferg.awfulapp.widget.PageBar) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) Build(android.os.Build) LinkedList(java.util.LinkedList) PostRequest(com.ferg.awfulapp.task.PostRequest) DialogInterface(android.content.DialogInterface) Cursor(android.database.Cursor) Formatter(android.text.format.Formatter) UrlContextMenu(com.ferg.awfulapp.popupmenu.UrlContextMenu) Loader(android.support.v4.content.Loader) AwfulTheme(com.ferg.awfulapp.provider.AwfulTheme) LayoutInflater(android.view.LayoutInflater) AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences) AwfulPagedItem(com.ferg.awfulapp.thread.AwfulPagedItem) TYPE(com.ferg.awfulapp.thread.AwfulURL.TYPE) TextUtils(android.text.TextUtils) VolleyError(com.android.volley.VolleyError) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) PagePicker(com.ferg.awfulapp.widget.PagePicker) FragmentManager(android.support.v4.app.FragmentManager) Crashlytics(com.crashlytics.android.Crashlytics) AwfulWebView(com.ferg.awfulapp.webview.AwfulWebView) ImageSizeRequest(com.ferg.awfulapp.task.ImageSizeRequest) Activity(android.app.Activity) EditText(android.widget.EditText) ContentUris(android.content.ContentUris) FragmentActivity(android.support.v4.app.FragmentActivity) UrlContextMenu(com.ferg.awfulapp.popupmenu.UrlContextMenu) Uri(android.net.Uri) ImageSizeRequest(com.ferg.awfulapp.task.ImageSizeRequest)

Aggregations

Manifest (android.Manifest)1 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 DownloadManager (android.app.DownloadManager)1 Request (android.app.DownloadManager.Request)1 ContentUris (android.content.ContentUris)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 ContentObserver (android.database.ContentObserver)1 Cursor (android.database.Cursor)1 Color (android.graphics.Color)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Environment (android.os.Environment)1 Handler (android.os.Handler)1