Add this in your build.gradle
implementation 'com.mindorks.scheduler:rxps:0.1.0'getObservable()| class NewsScreen extends StatefulWidget { | |
| @override | |
| State<StatefulWidget> createState() => _NewsScreenState(); | |
| } | |
| class _NewsScreenState extends State<NewsScreen> { | |
| final List<String> listItems = []; | |
| final List<String> _tabs = <String>[ | |
| "Featured", |
| // TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" /> | |
| // TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" /> | |
| // or not use 'okhttp@aar' in Gradle depdendencies | |
| public class OkHttpProgressGlideModule implements GlideModule { | |
| @Override public void applyOptions(Context context, GlideBuilder builder) { } | |
| @Override public void registerComponents(Context context, Glide glide) { | |
| OkHttpClient client = new OkHttpClient(); | |
| client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener())); | |
| glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client)); | |
| } |
| public class PaginationActivity extends AppCompatActivity { | |
| // removed for brevity.. | |
| private PublishProcessor<Integer> paginator = PublishProcessor.create(); | |
| private ProgressBar progressBar; | |
| private boolean loading = false; | |
| private int pageNumber = 1; | |
| private final int VISIBLE_THRESHOLD = 1; | |
| private int lastVisibleItem, totalItemCount; |
| /** | |
| * Will process the data with the callable by splitting the data into the specified number of threads. | |
| * <b>T</b> is ths type of data being parsed, and <b>U</b> is the type of data being returned. | |
| */ | |
| public static <T, U> Iterable<U> parseDataInParallel(@NonNull List<T> data, Function<List<T>, ObservableSource<U>> worker) { | |
| int threadCount = Runtime.getRuntime().availableProcessors(); | |
| ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(threadCount); | |
| Scheduler scheduler = Schedulers.from(threadPoolExecutor); | |
| AtomicInteger groupIndex = new AtomicInteger(); |
| public static Observable<Response> getData() { | |
| StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); | |
| StrictMode.setThreadPolicy(policy); | |
| final OkHttpClient client = new OkHttpClient(); | |
| final Request request = new Request.Builder() | |
| .url("https://github.com/ar-android/panfic/raw/master/Panfic/gen/com/ocit/data.json") | |
| .get() | |
| .addHeader("cache-control", "no-cache") |
| import java.io.Serializable; | |
| /** | |
| * The perfect implementation of Singleton design pattern | |
| * Properly solves all the below mentioned problems in Singleton pattern | |
| * <p> | |
| * 1) Attack using Reflection API | |
| * 2) Problems from serialization/deserialization of your object | |
| * 3) Problems from cloning your object | |
| * 4) Uncertainty in a multi-threaded environment |
RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.
Set an OnClickListener in your ViewHolder creation:
private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
public static class ViewHolder extends RecyclerView.ViewHolder| package com.mirth.stevek.rxtest; | |
| import rx.Observable; | |
| import rx.functions.Action1; | |
| import rx.functions.Func1; | |
| import rx.functions.Func3; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.concurrent.*; |