Search in sources :

Example 1 with ImageLicenseFetchClient

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

the class ShareHandler method shareSnippet.

private void shareSnippet(@NonNull CharSequence input) {
    final String selectedText = StringUtil.sanitizeText(input.toString());
    final PageTitle title = fragment.getTitle();
    final String leadImageNameText = fragment.getPage().getPageProperties().getLeadImageName() != null ? fragment.getPage().getPageProperties().getLeadImageName() : "";
    new ImageLicenseFetchClient().request(title.getWikiSite(), new PageTitle(Namespace.FILE.toLegacyString(), leadImageNameText, title.getWikiSite()), new ImageLicenseFetchClient.Callback() {

        @Override
        public void success(@NonNull Call<MwQueryResponse> call, @NonNull ImageLicense result) {
            final Bitmap snippetBitmap = SnippetImage.getSnippetImage(fragment.getContext(), fragment.getLeadImageBitmap(), title.getDisplayText(), fragment.getPage().isMainPage() ? "" : StringUtils.capitalize(title.getDescription()), selectedText, result);
            fragment.showBottomSheet(new PreviewDialog(fragment.getContext(), snippetBitmap, title, selectedText, funnel));
        }

        @Override
        public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
            // If we failed to get license info for the lead image, just share the text
            PreviewDialog.shareAsText(fragment.getContext(), title, selectedText, funnel);
            L.e("Error fetching image license info for " + title.getDisplayText(), caught);
        }
    });
}
Also used : ImageLicense(org.wikipedia.gallery.ImageLicense) Bitmap(android.graphics.Bitmap) ImageLicenseFetchClient(org.wikipedia.gallery.ImageLicenseFetchClient) PageTitle(org.wikipedia.page.PageTitle) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse)

Aggregations

Bitmap (android.graphics.Bitmap)1 MwQueryResponse (org.wikipedia.dataclient.mwapi.MwQueryResponse)1 ImageLicense (org.wikipedia.gallery.ImageLicense)1 ImageLicenseFetchClient (org.wikipedia.gallery.ImageLicenseFetchClient)1 PageTitle (org.wikipedia.page.PageTitle)1