Search in sources :

Example 6 with WikipediaApp

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

the class PageCacher method loadIntoCache.

static void loadIntoCache(@NonNull PageTitle title) {
    L.d("Loading page into cache: " + title.getPrefixedText());
    WikipediaApp app = WikipediaApp.getInstance();
    PageImageUrlParser parser = new PageImageUrlParser(new ImageTagParser(), new PixelDensityDescriptorParser());
    PageClient client = PageClientFactory.create(title.getWikiSite(), title.namespace());
    app.getSessionFunnel().leadSectionFetchStart();
    leadReq(client, title).enqueue(new LeadCallback(title.getWikiSite(), parser));
    app.getSessionFunnel().restSectionsFetchStart();
    remainingReq(client, title).enqueue(new RemainingCallback(title.getWikiSite(), parser));
}
Also used : ImageTagParser(org.wikipedia.html.ImageTagParser) WikipediaApp(org.wikipedia.WikipediaApp) PageImageUrlParser(org.wikipedia.savedpages.PageImageUrlParser) PixelDensityDescriptorParser(org.wikipedia.html.PixelDensityDescriptorParser) PageClient(org.wikipedia.dataclient.page.PageClient)

Example 7 with WikipediaApp

use of org.wikipedia.WikipediaApp 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

WikipediaApp (org.wikipedia.WikipediaApp)7 PageTitle (org.wikipedia.page.PageTitle)2 NonNull (android.support.annotation.NonNull)1 PopupMenu (android.support.v7.widget.PopupMenu)1 View (android.view.View)1 TextView (android.widget.TextView)1 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Map (java.util.Map)1 Request (okhttp3.Request)1 LinkPreviewFunnel (org.wikipedia.analytics.LinkPreviewFunnel)1 ShareAFactFunnel (org.wikipedia.analytics.ShareAFactFunnel)1 CallbackTask (org.wikipedia.concurrency.CallbackTask)1 PageClient (org.wikipedia.dataclient.page.PageClient)1 PageLead (org.wikipedia.dataclient.page.PageLead)1 GalleryThumbnailScrollView (org.wikipedia.gallery.GalleryThumbnailScrollView)1 ImageInfo (org.wikipedia.gallery.ImageInfo)1 ImageTagParser (org.wikipedia.html.ImageTagParser)1 PixelDensityDescriptorParser (org.wikipedia.html.PixelDensityDescriptorParser)1