2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.client.Glide;
|
2017-12-13 11:09:58 +01:00
|
|
|
|
2018-01-20 09:13:17 +01:00
|
|
|
import android.content.Context;
|
2017-12-13 11:09:58 +01:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
import com.bumptech.glide.Priority;
|
|
|
|
import com.bumptech.glide.load.DataSource;
|
|
|
|
import com.bumptech.glide.load.data.DataFetcher;
|
|
|
|
import com.bumptech.glide.load.model.GlideUrl;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
2018-01-20 09:13:17 +01:00
|
|
|
import java.lang.ref.WeakReference;
|
2017-12-13 11:09:58 +01:00
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.HttpsConnection;
|
2019-05-23 07:46:34 +02:00
|
|
|
import app.fedilab.android.helper.Helper;
|
2017-12-13 11:09:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 13/12/2017.
|
2017-12-13 11:19:55 +01:00
|
|
|
* Custom stream fetcher which will use getPicture from HttpsConnection to get the inputstream
|
2017-12-13 11:09:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class CustomStreamFetcher implements DataFetcher<InputStream> {
|
|
|
|
|
|
|
|
private GlideUrl url;
|
2018-01-20 09:13:17 +01:00
|
|
|
private WeakReference<Context> contextWeakReference;
|
2017-12-13 11:09:58 +01:00
|
|
|
|
2018-01-20 09:13:17 +01:00
|
|
|
CustomStreamFetcher(Context context, GlideUrl url) {
|
|
|
|
this.contextWeakReference = new WeakReference<>(context);
|
2017-12-13 11:09:58 +01:00
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-01-20 09:13:17 +01:00
|
|
|
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) {
|
2019-05-23 07:46:34 +02:00
|
|
|
String instance = Helper.getLiveInstance(this.contextWeakReference.get());
|
|
|
|
callback.onDataReady(new HttpsConnection(this.contextWeakReference.get(), instance).getPicture(url.toStringUrl()));
|
2017-12-13 11:09:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cleanup() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cancel() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Class<InputStream> getDataClass() {
|
|
|
|
return InputStream.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public DataSource getDataSource() {
|
|
|
|
return DataSource.REMOTE;
|
|
|
|
}
|
|
|
|
}
|