16 | *
If you're using gradle, you can include this module simply by depending on the aar, the 17 | * module will be merged in by manifest merger. For other build systems or for more more 18 | * information, see {@link TKClientModule}.
19 | */ 20 | public class OkHttpTKClientModule implements TKClientModule { 21 | 22 | @Override 23 | public void register(Context context, Registry registry) { 24 | registry.register(TKClientUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /integration/okhttp/src/main/java/com/xmonster/tkclient/integration/okhttp/OkHttpUrlLoader.java: -------------------------------------------------------------------------------- 1 | package com.xmonster.tkclient.integration.okhttp; 2 | 3 | import com.squareup.okhttp.OkHttpClient; 4 | import com.xmonster.tkclient.model.DataFetcher; 5 | import com.xmonster.tkclient.model.RequestLoader; 6 | import com.xmonster.tkclient.model.RequestLoaderFactory; 7 | import com.xmonster.tkclient.model.TKClientUrl; 8 | 9 | import java.io.InputStream; 10 | 11 | /** 12 | * A simple model loader for fetching media over http/https using OkHttp. 13 | */ 14 | public class OkHttpUrlLoader implements RequestLoader16 | *
If you're using gradle, you can include this module simply by depending on the aar, the 17 | * module will be merged in by manifest merger. For other build systems or for more more 18 | * information, see {@link com.xmonster.tkclient.module.TKClientModule}.
19 | */ 20 | public class OkHttp3TKClientModule implements TKClientModule { 21 | 22 | @Override 23 | public void register(Context context, Registry registry) { 24 | registry.register(TKClientUrl.class, InputStream.class, new OkHttp3UrlLoader.Factory()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /integration/okhttp3/src/main/java/com/xmonster/tkclient/integration/okhttp3/OkHttp3UrlLoader.java: -------------------------------------------------------------------------------- 1 | package com.xmonster.tkclient.integration.okhttp3; 2 | 3 | import com.xmonster.tkclient.model.DataFetcher; 4 | import com.xmonster.tkclient.model.RequestLoader; 5 | import com.xmonster.tkclient.model.RequestLoaderFactory; 6 | import com.xmonster.tkclient.model.TKClientUrl; 7 | 8 | import java.io.InputStream; 9 | 10 | import okhttp3.Call; 11 | import okhttp3.OkHttpClient; 12 | 13 | /** 14 | * A simple model loader for fetching media over http/https using OkHttp. 15 | */ 16 | public class OkHttp3UrlLoader implements RequestLoader35 | *
This will always be called on 36 | * background thread so it is safe to perform long running tasks here. Any third party libraries 37 | * called must be thread safe since this method will be called from a thread in a {@link 38 | * java.util.concurrent.ExecutorService} that may have more than one background thread.
39 | *40 | *
This method will only be called when the corresponding resource is not in the cache.
41 | *42 | *
Note - this method will be run on a background thread so blocking I/O is safe.
43 | * 44 | * @see #cleanup() where the data retuned will be cleaned up 45 | */ 46 | void loadData(DataCallback super T> callback); 47 | 48 | /** 49 | * Cleanup or recycle any resources used by this data fetcher. This method will be called in a 50 | * finally block after the data provided by 51 | *Note - this method will be run on a background thread so blocking I/O is safe.
52 | */ 53 | void cleanup(); 54 | 55 | void cancel(); 56 | 57 | /** 58 | * Returns the class of the data this fetcher will attempt to obtain. 59 | */ 60 | Class