Java Code Examples for com.bumptech.glide.load.model.LazyHeaders#Builder

The following examples show how to use com.bumptech.glide.load.model.LazyHeaders#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HuaBanAdapter.java    From v9porn with MIT License 6 votes vote down vote up
private GlideUrl buildGlideUrl(String url) {
    if (TextUtils.isEmpty(url)) {
        return null;
    } else {
        String host = null;
        String referer = null;
        try {
            URL urlObj = new URL(url);
            host = urlObj.getHost();
            referer = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }


        LazyHeaders.Builder builder = new LazyHeaders.Builder()
                .addHeader("Accept-Language", "zh-CN,zh;q=0.9,zh-TW;q=0.8")
                .addHeader("Host", "i.meizitu.net")
                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
        if (referer != null) {
            builder.addHeader("Referer", referer);
            builder.addHeader("Host", host);
        }
        return new GlideUrl(url, builder.build());
    }
}
 
Example 2
Source File: MeiZiTuAdapter.java    From v9porn with MIT License 6 votes vote down vote up
private GlideUrl buildGlideUrl(String url) {
    if (TextUtils.isEmpty(url)) {
        return null;
    } else {

        String host = null;
        String referer = null;
        try {
            URL urlObj = new URL(url);
            host = urlObj.getHost();
            referer = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        LazyHeaders.Builder builder = new LazyHeaders.Builder()
                .addHeader("Accept-Language", "zh-CN,zh;q=0.9,zh-TW;q=0.8")
                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
        if (referer != null) {
            builder.addHeader("Referer", referer);
            builder.addHeader("Host", host);

        }
        return new GlideUrl(url, builder.build());
    }
}
 
Example 3
Source File: TyUtils.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
private static void getGlideRequest(Context context,
                                    String url,
                                    RequestOptions options,
                                    ImageView imageView) {

    RequestBuilder<Drawable> requestBuilder;

    List<Cookie> cookies = PersistentCookieStore.getInstance().getCookies();
    if (TextUtils.isEmpty(url)) {
        requestBuilder = Glide.with(context).load(url);
    } else if (cookies == null || cookies.size() <= 0) {
        requestBuilder = Glide.with(context).load(url);
    } else {
        LazyHeaders.Builder builder = new LazyHeaders.Builder();
        for (int i = 0; i < cookies.size(); i++) {
            Cookie cookie = cookies.get(i);
            String value = cookie.name() + "=" + cookie.value();
            builder.setHeader("Cookie", value);
        }

        GlideUrl glideUrl = new GlideUrl(url, builder.build());

        requestBuilder = Glide.with(context).load(glideUrl);
    }

    if (options != null) {
        requestBuilder.apply(options);
    }

    requestBuilder.into(imageView);

}
 
Example 4
Source File: ImageFragment.java    From MoeGallery with GNU General Public License v3.0 6 votes vote down vote up
private void cacheImage(final Image image, final LazyHeaders.Builder header) {
    mName = image.getName();
    mUri = image.getFileUrl();

    saveImage(image);

    mRequestManager.load(new GlideUrl(image.getFileUrl(), header.build()))
            .downloadOnly(new SimpleTarget<File>() {
                @Override
                public void onResourceReady(File resource,
                        GlideAnimation<? super File> glideAnimation) {
                    if (mSetting.autoDownload()) {
                        File dir = new File(
                                Environment.getExternalStorageDirectory().getPath(),
                                "MoeGallery");
                        String fileName = image.getName().replace('/', '-');
                        Utils.copy(resource, dir, fileName);
                        mImageDataSource.cacheImageUri(mImage.getFileUrl(),
                                Uri.fromFile(new File(dir, fileName)));
                    }
                    loadImage(image, header);
                }
            });
    mImageDataSource.cacheDetail(mImage.getFileUrl(), image);
}
 
Example 5
Source File: PictureAdapter.java    From v9porn with MIT License 5 votes vote down vote up
private GlideUrl buildGlideUrl(String url) {
    if (TextUtils.isEmpty(url)) {
        return null;
    } else {
        String referer = null;
        String host = null;
        try {
            URL urlObj = new URL(url);
            host = urlObj.getHost();
            referer = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";

        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        LazyHeaders.Builder builder = new LazyHeaders.Builder()
                .addHeader("Accept-Language", "zh-CN,zh;q=0.9,zh-TW;q=0.8")
                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");

        if (referer != null) {
            builder.addHeader("Referer", referer);
            builder.addHeader("Host", host);
        }

        return new GlideUrl(url, builder.build());
    }
}
 
Example 6
Source File: GlideUtil.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
public static void displayImageReferer(String url,ImageView imageView,String referer) {
    if(url==null){
        return;
    }
    LazyHeaders.Builder builder=new LazyHeaders.Builder().addHeader("User-Agent", UserAgent);
    if(referer!=null){
        builder.addHeader("Referer", referer);
    }

    /*
            .addHeader("key2", new LazyHeaderFactory() {
                @Override
                public String buildHeader() {
                    String expensiveAuthHeader = computeExpensiveAuthHeader();
                    return expensiveAuthHeader;
                }
            })
            */

    GlideUrl glideUrl = new GlideUrl(url,builder.build());

    Glide.with(MainApp.getContext())
            .load(glideUrl)
            .placeholder(R.drawable.pictures_no)
            .thumbnail(0.2f)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(imageView);

}
 
Example 7
Source File: SingleSignOnUrl.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Use this as {@link Headers} if you want to do a {@link Glide} request for an {@link SingleSignOnAccount} which is not set by {@link SingleAccountHelper} as current {@link SingleSignOnAccount}.
 *
 * @param ssoAccountName Account name from which host the request should be fired (needs to match {@link SingleSignOnAccount#name})
 */
public SingleSignOnOriginHeader(@NonNull String ssoAccountName, Headers headers) {
    LazyHeaders.Builder builder = new LazyHeaders.Builder();
    for (Map.Entry<String, String> entry : headers.getHeaders().entrySet()) {
        builder.addHeader(entry.getKey(), entry.getValue());
    }
    builder.addHeader(X_HEADER_SSO_ACCOUNT_NAME, ssoAccountName).build();
    this.headers = builder.build();
}
 
Example 8
Source File: ImageFragment.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
private void loadImage(Image image, LazyHeaders.Builder header) {

        if (mUri != null && mUri.toLowerCase().endsWith("gif")) {
            mGifRequestBuilder.load(new GlideUrl(image.getFileUrl(), header.build()))
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .listener(new MediaRequestListener<GlideUrl, GifDrawable>())
                    .into(mPhotoView);
        } else {
            mRequestManager.load(new GlideUrl(image.getFileUrl(), header.build()))
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .listener(new MediaRequestListener<GlideUrl, GlideDrawable>())
                    .into(mPhotoView);
        }
    }
 
Example 9
Source File: PhotoViewWrapper.java    From react-native-image-zoom with MIT License 4 votes vote down vote up
public void setSource(ReadableMap params) {
    mParams = params;
    @Nullable Uri mUri = null;

    String source = params.hasKey("uri") ? params.getString("uri") : null;
    String thumbnail = params.hasKey("thumbnail") ? params.getString("thumbnail") : null;
    ReadableMap headers = params.hasKey("headers") ? params.getMap("headers") : null;

    //handle base64
    if (source.startsWith("data:image/png;base64,")){
        Glide
            .with(this.getContext())
            .load(Base64.decode(source.replaceAll("data:image\\/.*;base64,", ""), Base64.DEFAULT))
            .into(this)
        ;
        return;
    }

    boolean useStorageFile = false ;

    // handle bundled app resources
    try {
        mUri = Uri.parse(source);
        // Verify scheme is set, so that relative uri (used by static resources) are not handled.
        if (mUri.getScheme() == null) {
            mUri = null;
        } else if(
            !mUri.getScheme().equals("http") &&
            !mUri.getScheme().equals("https")
        ){
            useStorageFile = true ;

            if (!mInitialized) {
                this.setImageURI(mUri);
            }
        }
    } catch (Exception e) {
        // ignore malformed uri, then attempt to extract resource ID.
    }

    if (mUri == null) {
        mUri = mResourceDrawableIdHelper.getResourceDrawableUri(
            this.getContext(),
            source
        );
        Glide
            .with(this.getContext())
            .load(mUri)
            .into(this);
    } else if (useStorageFile) {
        Glide
            .with(this.getContext())
            .load(mUri)
            .into(this);
    } else {
        // Handle an http / https address
        RequestListener listener = this.getRequestListener();

        LazyHeaders.Builder lazyHeaders = new LazyHeaders.Builder();
        Log.d("null headers", String.valueOf(headers != null));
        if(headers != null){
            ReadableMapKeySetIterator it = headers.keySetIterator();
            Log.d("next headers", String.valueOf(it.hasNextKey()));
            while(it.hasNextKey()){
                String Key = it.nextKey();
                lazyHeaders.addHeader(Key, headers.getString(Key));
            }
        }

        Log.d("thing", mUri.toString());
        DrawableRequestBuilder builder = Glide
                .with(this.getContext())
                .load(new GlideUrl(mUri.toString(), lazyHeaders.build()))
                .listener(listener);

        //set thumbnails
        if(thumbnail != null) {
            DrawableRequestBuilder<String> thumbnailRequest = Glide
                    .with(this.getContext())
                    .load(thumbnail);
            builder = builder.thumbnail(thumbnailRequest);
        }

        builder.into(this);
    }

    this.setChangeListeners();
}
 
Example 10
Source File: ImageFragment.java    From MoeGallery with GNU General Public License v3.0 4 votes vote down vote up
private static LazyHeaders.Builder header() {
    return new LazyHeaders.Builder().addHeader("User-Agent", OkHttp.USER_AGENT);
}
 
Example 11
Source File: ContentItem.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
private void attachCover(@NonNull final Content content) {
    String thumbLocation = content.getCover().getFileUri();
    if (thumbLocation.isEmpty()) thumbLocation = content.getCover().getUrl();
    if (thumbLocation.isEmpty()) thumbLocation = content.getCoverImageUrl();

    // Use content's cookies to load image (useful for ExHentai when viewing queue screen)
    if (thumbLocation.startsWith("http")
            && content.getDownloadParams() != null
            && content.getDownloadParams().length() > 2 // Avoid empty and "{}"
            && content.getDownloadParams().contains(HttpHelper.HEADER_COOKIE_KEY)) {

        Map<String, String> downloadParams = null;
        try {
            downloadParams = JsonHelper.jsonToObject(content.getDownloadParams(), JsonHelper.MAP_STRINGS);
        } catch (IOException e) {
            Timber.w(e);
        }

        if (downloadParams != null && downloadParams.containsKey(HttpHelper.HEADER_COOKIE_KEY)) {
            String cookiesStr = downloadParams.get(HttpHelper.HEADER_COOKIE_KEY);
            if (cookiesStr != null) {
                LazyHeaders.Builder builder = new LazyHeaders.Builder()
                        .addHeader(HttpHelper.HEADER_COOKIE_KEY, cookiesStr);

                GlideUrl glideUrl = new GlideUrl(thumbLocation, builder.build());
                Glide.with(ivCover)
                        .load(glideUrl)
                        .apply(glideRequestOptions)
                        .into(ivCover);
                return;
            }
        }
    }

    if (thumbLocation.startsWith("http"))
        Glide.with(ivCover)
                .load(thumbLocation)
                .apply(glideRequestOptions)
                .into(ivCover);
    else
        Glide.with(ivCover)
                .load(Uri.parse(thumbLocation))
                .apply(glideRequestOptions)
                .into(ivCover);
}