@Test public void testUpdatingBuilderAfterBuildingDoesNotModifyOriginalHeaders() { Builder builder = new Builder(); builder.addHeader("key", "firstValue"); builder.addHeader("otherKey", "otherValue"); LazyHeaders first = builder.build(); LazyHeaderFactory factory = mock(LazyHeaderFactory.class); when(factory.buildHeader()).thenReturn("otherValue"); builder.addHeader("key", "secondValue"); builder.setHeader("otherKey", factory); LazyHeaders second = builder.build(); assertThat(first.getHeaders()).isNotEqualTo(second.getHeaders()); assertThat(first.getHeaders()).containsEntry("key", "firstValue"); assertThat(first.getHeaders()).containsEntry("otherKey", "otherValue"); assertThat(second.getHeaders()).containsEntry("key", "firstValue,secondValue"); assertThat(second.getHeaders()).containsEntry("otherKey", "otherValue"); }
/** * Replaces all existing {@link LazyHeaderFactory LazyHeaderFactorys} for the given key * with the given {@link LazyHeaderFactory}. * * <p> If the given value is {@code null}, the header at the given key will be removed. </p> */ public Builder setHeader(@NonNull String key, @Nullable LazyHeaderFactory factory) { copyIfNecessary(); if (factory == null) { headers.remove(key); } else { List<LazyHeaderFactory> factories = getFactories(key); factories.clear(); factories.add(factory); } if (isUserAgentDefault && USER_AGENT_HEADER.equalsIgnoreCase(key)) { isUserAgentDefault = false; } return this; }
LazyHeaders.Builder builder = new LazyHeaders.Builder(); for (Map.Entry<String, String> entry : map.entrySet()) { builder.addHeader(entry.getKey(), entry.getValue()); Headers headers = builder.build(); GlideUrl glideUrl = new GlideUrl(imgUrl, headers); Glide.with(activity)
Bitmap bitmap = null; try { GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder() .addHeader("Referer", "http://www.mzitu.com/mm/") .build()); bitmap = Glide.with(activity) .asBitmap()
url = first + end; GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder() .addHeader("referer", "http://www.mzitu.com/mm/") .build());
GlideUrl glideUrl; if (url.contains("meizitu") || url.contains("mzitu")) { glideUrl = new GlideUrl(url, new LazyHeaders.Builder() .addHeader("Referer", "http://www.mzitu.com/mm/") .build()); } else { glideUrl = new GlideUrl(url, new LazyHeaders.Builder() .build());
temp = new GlideUrl(url, new LazyHeaders.Builder() .addHeader(HeaderGlide.REFERER, SOURCE_URL) .build()); } else { temp = new File(url);
/** * Replaces all existing {@link LazyHeaderFactory LazyHeaderFactorys} for the given key * with the given {@link LazyHeaderFactory}. * * <p> If the given value is {@code null}, the header at the given key will be removed. </p> */ public Builder setHeader(String key, LazyHeaderFactory factory) { copyIfNecessary(); if (factory == null) { headers.remove(key); } else { List<LazyHeaderFactory> factories = getFactories(key); factories.clear(); factories.add(factory); } if (isUserAgentDefault && USER_AGENT_HEADER.equalsIgnoreCase(key)) { isUserAgentDefault = false; } return this; }
@Override public void onBindViewHolder(GankViewHolder holder, int position) { final GiftBean bean = mResults.get(holder.getAdapterPosition()); holder.mGiftBean = bean; holder.position = position; holder.txtDesc.setText(bean.getTitle()); holder.txtAuthor.setText(bean.getTime()); GlideUrl glideUrl = new GlideUrl(bean.getImgUrl(), new LazyHeaders.Builder() .addHeader("referer", "http://www.mzitu.com/mm/") .build()); Glide.with(mContext) .asBitmap() .load(glideUrl) .apply(new RequestOptions() .fitCenter() .diskCacheStrategy(DiskCacheStrategy.ALL) ) .into(holder.mImageView); }
/** * Adds an {@link LazyHeaderFactory} that will be used to construct a value for the given * key lazily on a background thread. * * <p> Headers may have multiple values whose order is defined by the order in which * this method is called. </p> * * <p> This class does not prevent you from adding the same value to a given key multiple * times </p> */ public Builder addHeader(String key, LazyHeaderFactory factory) { if (isUserAgentDefault && USER_AGENT_HEADER.equalsIgnoreCase(key)) { return setHeader(key, factory); } copyIfNecessary(); getFactories(key).add(factory); return this; }
public static void loadBitmap(Context context, String url, final ImageView view, String source) { GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder() .addHeader(REFERER, getReferer(source)) .build()); Glide.with(context) .load(glideUrl) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { view.setImageBitmap(FastBlur.doBlur(resource, 100, false)); } }); }
public static void downloadImage(Context context, String url, String source) { String referer = getReferer(source); LazyHeaders.Builder builder = new LazyHeaders.Builder(); builder.addHeader(REFERER, referer); if (referer.equals(URL_IKAN)) { builder.addHeader(HOST, HOST_IKAN); } GlideUrl glideUrl = new GlideUrl(url, builder.build()); Glide.with(context) .load(glideUrl) .downloadOnly(720, 1280); } }
/** * Replaces all existing {@link LazyHeaderFactory LazyHeaderFactorys} for the given key * with the given {@link LazyHeaderFactory}. * * <p> If the given value is {@code null}, the header at the given key will be removed. </p> * * <p> Use {@link #setHeader(String, LazyHeaderFactory)} if obtaining the value requires I/O * (i.e. an OAuth token). </p> */ public Builder setHeader(String key, String value) { return setHeader(key, value == null ? null : new StringHeaderFactory(value)); }
private void copyIfNecessary() { if (copyOnModify) { copyOnModify = false; headers = copyHeaders(); } }
/** * Adds a value for the given header and returns this builder. * * <p> Use {@link #addHeader(String, LazyHeaderFactory)} if obtaining the value requires I/O * (i.e. an OAuth token). </p> * * @see #addHeader(String, LazyHeaderFactory) */ public Builder addHeader(String key, String value) { return addHeader(key, new StringHeaderFactory(value)); }
public static void loadImage(Context context, String url, ImageView view, String source) { GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder() .addHeader(REFERER, getReferer(source)) .build()); Glide.with(context) .load(glideUrl) // .placeholder(R.drawable.comic_placeholder) .diskCacheStrategy(DiskCacheStrategy.ALL) .crossFade() .into(view); }
/** * Replaces all existing {@link LazyHeaderFactory LazyHeaderFactorys} for the given key * with the given {@link LazyHeaderFactory}. * * <p> If the given value is {@code null}, the header at the given key will be removed. </p> */ public Builder setHeader(String key, LazyHeaderFactory factory) { copyIfNecessary(); if (factory == null) { headers.remove(key); } else { List<LazyHeaderFactory> factories = getFactories(key); factories.clear(); factories.add(factory); } if (isEncodingDefault && ENCODING_HEADER.equalsIgnoreCase(key)) { isEncodingDefault = false; } if (isUserAgentDefault && USER_AGENT_HEADER.equalsIgnoreCase(key)) { isUserAgentDefault = false; } return this; }
/** * Adds an {@link LazyHeaderFactory} that will be used to construct a value for the given * key lazily on a background thread. * * <p> Headers may have multiple values whose order is defined by the order in which * this method is called. </p> * * <p> This class does not prevent you from adding the same value to a given key multiple * times </p> */ public Builder addHeader(String key, LazyHeaderFactory factory) { if ((isEncodingDefault && ENCODING_HEADER.equalsIgnoreCase(key)) || (isUserAgentDefault && USER_AGENT_HEADER.equalsIgnoreCase(key))) { return setHeader(key, factory); } copyIfNecessary(); getFactories(key).add(factory); return this; }
/** * Adds a value for the given header and returns this builder. * * <p> Use {@link #addHeader(String, LazyHeaderFactory)} if obtaining the value requires I/O * (ie an oauth token). </p> * * @see #addHeader(String, LazyHeaderFactory) */ public Builder addHeader(String key, String value) { return addHeader(key, new StringHeaderFactory(value)); }
private void copyIfNecessary() { if (copyOnModify) { copyOnModify = false; headers = copyHeaders(); } }