Search in sources :

Example 1 with LinkPreviewFunnel

use of org.wikipedia.analytics.LinkPreviewFunnel in project apps-android-wikipedia by wikimedia.

the class PageActivity method loadPage.

/**
 * Load a new page, and put it on top of the backstack, optionally allowing state loss of the
 * fragment manager. Useful for when this function is called from an AsyncTask result.
 * @param title Title of the page to load.
 * @param entry HistoryEntry associated with this page.
 * @param position Whether to open this page in the current tab, a new background tab, or new
 *                 foreground tab.
 */
public void loadPage(@NonNull final PageTitle title, @NonNull final HistoryEntry entry, @NonNull final TabPosition position) {
    if (isDestroyed()) {
        return;
    }
    if (entry.getSource() != HistoryEntry.SOURCE_INTERNAL_LINK || !isLinkPreviewEnabled()) {
        new LinkPreviewFunnel(app, entry.getSource()).logNavigate();
    }
    app.putCrashReportProperty("api", title.getWikiSite().authority());
    app.putCrashReportProperty("title", title.toString());
    if (title.isSpecial()) {
        visitInExternalBrowser(this, Uri.parse(title.getMobileUri()));
        return;
    }
    tabsContainerView.post(() -> {
        if (!pageFragment.isAdded()) {
            return;
        }
        // Close the link preview, if one is open.
        hideLinkPreview();
        pageFragment.closeFindInPage();
        if (position == TabPosition.CURRENT_TAB) {
            pageFragment.loadPage(title, entry, true);
        } else if (position == TabPosition.NEW_TAB_BACKGROUND) {
            pageFragment.openInNewBackgroundTabFromMenu(title, entry);
        } else if (position == TabPosition.EXISTING_TAB) {
            pageFragment.openFromExistingTab(title, entry);
        } else {
            pageFragment.openInNewForegroundTabFromMenu(title, entry);
        }
        app.getSessionFunnel().pageViewed(entry);
    });
}
Also used : LinkPreviewFunnel(org.wikipedia.analytics.LinkPreviewFunnel)

Example 2 with LinkPreviewFunnel

use of org.wikipedia.analytics.LinkPreviewFunnel in project apps-android-wikipedia by wikimedia.

the class LinkPreviewDialog method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    WikipediaApp app = WikipediaApp.getInstance();
    pageTitle = getArguments().getParcelable("title");
    entrySource = getArguments().getInt("entrySource");
    location = getArguments().getParcelable("location");
    View rootView = inflater.inflate(R.layout.dialog_link_preview, container);
    dialogContainer = rootView.findViewById(R.id.dialog_link_preview_container);
    contentContainer = rootView.findViewById(R.id.dialog_link_preview_content_container);
    errorContainer = rootView.findViewById(R.id.dialog_link_preview_error_container);
    progressBar = rootView.findViewById(R.id.link_preview_progress);
    toolbarView = rootView.findViewById(R.id.link_preview_toolbar);
    toolbarView.setOnClickListener(goToPageListener);
    titleText = rootView.findViewById(R.id.link_preview_title);
    setConditionalLayoutDirection(rootView, pageTitle.getWikiSite().languageCode());
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // for <5.0, give the title a bit more bottom padding, since these versions
        // incorrectly cut off the bottom of the text when line spacing is <1.
        final int bottomPadding = 8;
        ViewUtil.setBottomPaddingDp(titleText, bottomPadding);
    }
    extractText = rootView.findViewById(R.id.link_preview_extract);
    thumbnailView = rootView.findViewById(R.id.link_preview_thumbnail);
    thumbnailGallery = rootView.findViewById(R.id.link_preview_thumbnail_gallery);
    if (isImageDownloadEnabled()) {
        CallbackTask.execute(() -> client.request(pageTitle.getWikiSite(), pageTitle, true), new CallbackTask.Callback<Map<String, ImageInfo>>() {

            @Override
            public void success(@Nullable Map<String, ImageInfo> result) {
                setThumbGallery(result);
                thumbnailGallery.setGalleryViewListener(galleryViewListener);
            }

            @Override
            public void failure(Throwable caught) {
                L.w("Failed to fetch gallery collection.", caught);
            }
        });
    }
    overflowButton = rootView.findViewById(R.id.link_preview_overflow_button);
    overflowButton.setOnClickListener((View v) -> {
        PopupMenu popupMenu = new PopupMenu(getActivity(), overflowButton);
        popupMenu.inflate(R.menu.menu_link_preview);
        popupMenu.setOnMenuItemClickListener(menuListener);
        popupMenu.show();
    });
    // show the progress bar while we load content...
    progressBar.setVisibility(View.VISIBLE);
    // and kick off the task to load all the things...
    loadContent();
    funnel = new LinkPreviewFunnel(app, entrySource);
    funnel.logLinkClick();
    return rootView;
}
Also used : LinkPreviewFunnel(org.wikipedia.analytics.LinkPreviewFunnel) CallbackTask(org.wikipedia.concurrency.CallbackTask) WikipediaApp(org.wikipedia.WikipediaApp) GalleryThumbnailScrollView(org.wikipedia.gallery.GalleryThumbnailScrollView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) TextView(android.widget.TextView) ImageInfo(org.wikipedia.gallery.ImageInfo) Map(java.util.Map) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

LinkPreviewFunnel (org.wikipedia.analytics.LinkPreviewFunnel)2 PopupMenu (android.support.v7.widget.PopupMenu)1 View (android.view.View)1 TextView (android.widget.TextView)1 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)1 Map (java.util.Map)1 WikipediaApp (org.wikipedia.WikipediaApp)1 CallbackTask (org.wikipedia.concurrency.CallbackTask)1 GalleryThumbnailScrollView (org.wikipedia.gallery.GalleryThumbnailScrollView)1 ImageInfo (org.wikipedia.gallery.ImageInfo)1