GeezerVison is showing github.com — Merge branch 'kg/composite_sub_clean' · cnoldtree/RxJava-Android-Samples@27a1ddb
File treeExpand file treeCollapse file tree Open diff view settings src/main/java/com/morihacky/android/rxjava
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: app/build.gradle +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | apply plugin: 'com.android.application' | 2 | 2 |
| 3 | 3 | dependencies { | 4 | | - compile 'com.android.support:support-v13:23.1.1' | 5 | | - compile 'com.android.support:appcompat-v7:23.1.1' | | 4 | + compile 'com.android.support:support-v13:23.2.1' | | 5 | + compile 'com.android.support:appcompat-v7:23.2.1' | 6 | 6 |
| 7 | 7 | compile 'io.reactivex:rxandroid:1.0.1' | 8 | 8 | // Because RxAndroid releases are few and far between, it is recommended you also | 9 | 9 | // explicitly depend on RxJava's latest version for bug fixes and new features. | 10 | 10 | compile 'io.reactivex:rxjava:1.0.14' | 11 | 11 | compile 'io.reactivex:rxjava-math:1.0.0' | | 12 | + compile 'io.reactivex:rxjava-math:1.0.0' | | 13 | + compile 'com.github.kaushikgopal:CoreTextUtils:c703fa12b6' | 12 | 14 | compile 'com.jakewharton.rxbinding:rxbinding:0.2.0' | 13 | | - | 14 | 15 | compile 'com.jakewharton:butterknife:7.0.1' | 15 | 16 | compile 'com.jakewharton.timber:timber:2.4.2' | 16 | 17 | compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3' | @@ -30,7 +31,7 @@ android { | 30 | 31 |
| 31 | 32 | defaultConfig { | 32 | 33 | applicationId "com.morihacky.android.rxjava" | 33 | | - minSdkVersion 14 | | 34 | + minSdkVersion 15 | 34 | 35 | targetSdkVersion 22 | 35 | 36 | versionCode 1 | 36 | 37 | versionName "1.0" | |
Collapse file Copy file name to clipboard -9Lines changed: 0 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package com.morihacky.android.rxjava; | 2 | 2 |
| 3 | 3 | import rx.Subscription; | 4 | | -import rx.subscriptions.CompositeSubscription; | 5 | 4 |
| 6 | 5 | public class RxUtils { | 7 | 6 |
| @@ -10,12 +9,4 @@ public static void unsubscribeIfNotNull(Subscription subscription) { | 10 | 9 | subscription.unsubscribe(); | 11 | 10 | } | 12 | 11 | } | 13 | | - | 14 | | - public static CompositeSubscription getNewCompositeSubIfUnsubscribed(CompositeSubscription subscription) { | 15 | | - if (subscription == null || subscription.isUnsubscribed()) { | 16 | | - return new CompositeSubscription(); | 17 | | - } | 18 | | - | 19 | | - return subscription; | 20 | | - } | 21 | 12 | } |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/BufferDemoFragment.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,8 +53,8 @@ public class BufferDemoFragment | 53 | 53 | private Subscription _subscription; | 54 | 54 |
| 55 | 55 | @Override | 56 | | - public void onStart() { | 57 | | - super.onStart(); | | 56 | + public void onResume() { | | 57 | + super.onResume(); | 58 | 58 | _subscription = _getBufferedSubscription(); | 59 | 59 | } | 60 | 60 |
| |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/ConcurrencyWithSchedulersDemoFragment.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,8 +42,8 @@ public class ConcurrencyWithSchedulersDemoFragment | 42 | 42 | @Override | 43 | 43 | public void onDestroy() { | 44 | 44 | super.onDestroy(); | 45 | | - RxUtils.unsubscribeIfNotNull(_subscription); | 46 | 45 | ButterKnife.unbind(this); | | 46 | + RxUtils.unsubscribeIfNotNull(_subscription); | 47 | 47 | } | 48 | 48 |
| 49 | 49 | @Override | |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/DebounceSearchEmitterFragment.java +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | import com.jakewharton.rxbinding.widget.RxTextView; | 16 | 16 | import com.jakewharton.rxbinding.widget.TextViewTextChangeEvent; | 17 | 17 | import com.morihacky.android.rxjava.R; | 18 | | -import com.morihacky.android.rxjava.RxUtils; | 19 | 18 |
| 20 | 19 | import java.util.ArrayList; | 21 | 20 | import java.util.List; | | 24 | 23 | import butterknife.Bind; | 25 | 24 | import butterknife.ButterKnife; | 26 | 25 | import butterknife.OnClick; | | 26 | +import co.kaush.core.util.CoreNullnessUtils; | 27 | 27 | import rx.Observer; | 28 | 28 | import rx.Subscription; | 29 | 29 | import rx.android.schedulers.AndroidSchedulers; | | 30 | +import rx.functions.Func1; | 30 | 31 | import timber.log.Timber; | 31 | 32 |
| 32 | 33 | import static java.lang.String.format; | @@ -45,7 +46,7 @@ public class DebounceSearchEmitterFragment | 45 | 46 | @Override | 46 | 47 | public void onDestroy() { | 47 | 48 | super.onDestroy(); | 48 | | - RxUtils.unsubscribeIfNotNull(_subscription); | | 49 | + _subscription.unsubscribe(); | 49 | 50 | ButterKnife.unbind(this); | 50 | 51 | } | 51 | 52 |
| @@ -72,6 +73,12 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { | 72 | 73 |
| 73 | 74 | _subscription = RxTextView.textChangeEvents(_inputSearchText)// | 74 | 75 | .debounce(400, TimeUnit.MILLISECONDS)// default Scheduler is Computation | | 76 | + .filter(new Func1<TextViewTextChangeEvent, Boolean>() { | | 77 | + @Override | | 78 | + public Boolean call(TextViewTextChangeEvent changes) { | | 79 | + return CoreNullnessUtils.isNotNullOrEmpty(_inputSearchText.getText().toString()); | | 80 | + } | | 81 | + }) | 75 | 82 | .observeOn(AndroidSchedulers.mainThread())// | 76 | 83 | .subscribe(_getSearchObserver()); | 77 | 84 | } | |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/DoubleBindingTextViewFragment.java +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | import android.widget.TextView; | 10 | 10 |
| 11 | 11 | import com.morihacky.android.rxjava.R; | 12 | | -import com.morihacky.android.rxjava.RxUtils; | 13 | 12 |
| 14 | 13 | import butterknife.Bind; | 15 | 14 | import butterknife.ButterKnife; | @@ -70,7 +69,7 @@ public void onNumberChanged() { | 70 | 69 | @Override | 71 | 70 | public void onDestroyView() { | 72 | 71 | super.onDestroyView(); | 73 | | - RxUtils.unsubscribeIfNotNull(_subscription); | | 72 | + _subscription.unsubscribe(); | 74 | 73 | ButterKnife.unbind(this); | 75 | 74 | } | 76 | 75 | } |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/ExponentialBackoffFragment.java +1-8Lines changed: 1 addition & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | import android.widget.ListView; | 10 | 10 |
| 11 | 11 | import com.morihacky.android.rxjava.R; | 12 | | -import com.morihacky.android.rxjava.RxUtils; | 13 | 12 | import com.morihacky.android.rxjava.wiring.LogAdapter; | 14 | 13 |
| 15 | 14 | import java.util.ArrayList; | @@ -38,12 +37,6 @@ public class ExponentialBackoffFragment | 38 | 37 |
| 39 | 38 | private CompositeSubscription _subscriptions = new CompositeSubscription(); | 40 | 39 |
| 41 | | - @Override | 42 | | - public void onResume() { | 43 | | - super.onResume(); | 44 | | - _subscriptions = RxUtils.getNewCompositeSubIfUnsubscribed(_subscriptions); | 45 | | - } | 46 | | - | 47 | 40 | @Override | 48 | 41 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { | 49 | 42 | super.onActivityCreated(savedInstanceState); | @@ -63,7 +56,7 @@ public View onCreateView(LayoutInflater inflater, | 63 | 56 | public void onPause() { | 64 | 57 | super.onPause(); | 65 | 58 |
| 66 | | - RxUtils.unsubscribeIfNotNull(_subscriptions); | | 59 | + _subscriptions.clear(); | 67 | 60 | } | 68 | 61 |
| 69 | 62 | @Override | |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/FormValidationCombineLatestFragment.java +1-7Lines changed: 1 addition & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 |
| 11 | 11 | import com.jakewharton.rxbinding.widget.RxTextView; | 12 | 12 | import com.morihacky.android.rxjava.R; | 13 | | -import com.morihacky.android.rxjava.RxUtils; | 14 | 13 |
| 15 | 14 | import butterknife.Bind; | 16 | 15 | import butterknife.ButterKnife; | @@ -55,16 +54,11 @@ public View onCreateView(LayoutInflater inflater, | 55 | 54 | return layout; | 56 | 55 | } | 57 | 56 |
| 58 | | - @Override | 59 | | - public void onPause() { | 60 | | - super.onPause(); | 61 | | - RxUtils.unsubscribeIfNotNull(_subscription); | 62 | | - } | 63 | | - | 64 | 57 | @Override | 65 | 58 | public void onDestroyView() { | 66 | 59 | super.onDestroyView(); | 67 | 60 | ButterKnife.unbind(this); | | 61 | + _subscription.unsubscribe(); | 68 | 62 | } | 69 | 63 |
| 70 | 64 | private void _combineLatestEvents() { | |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/PollingFragment.java +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | import android.widget.ListView; | 13 | 13 |
| 14 | 14 | import com.morihacky.android.rxjava.R; | 15 | | -import com.morihacky.android.rxjava.RxUtils; | 16 | 15 |
| 17 | 16 | import java.util.ArrayList; | 18 | 17 | import java.util.List; | @@ -40,9 +39,18 @@ public class PollingFragment | 40 | 39 |
| 41 | 40 | private LogAdapter _adapter; | 42 | 41 | private List<String> _logs; | 43 | | - private CompositeSubscription _subscriptions = new CompositeSubscription(); | | 42 | + | | 43 | + private CompositeSubscription _subscriptions; | 44 | 44 | private int _counter = 0; | 45 | 45 |
| | 46 | + | | 47 | + @Override | | 48 | + public void onCreate(@Nullable Bundle savedInstanceState) { | | 49 | + super.onCreate(savedInstanceState); | | 50 | + | | 51 | + _subscriptions = new CompositeSubscription(); | | 52 | + } | | 53 | + | 46 | 54 | @Override | 47 | 55 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { | 48 | 56 | super.onActivityCreated(savedInstanceState); | @@ -61,7 +69,7 @@ public View onCreateView(LayoutInflater inflater, | 61 | 69 | @Override | 62 | 70 | public void onDestroy() { | 63 | 71 | super.onDestroy(); | 64 | | - RxUtils.unsubscribeIfNotNull(_subscriptions); | | 72 | + _subscriptions.unsubscribe(); | 65 | 73 | ButterKnife.unbind(this); | 66 | 74 | } | 67 | 75 |
| |
Collapse file Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/PseudoCacheConcatFragment.java -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | import android.widget.ListView; | 10 | 10 |
| 11 | 11 | import com.morihacky.android.rxjava.R; | 12 | | -import com.morihacky.android.rxjava.RxUtils; | 13 | 12 | import com.morihacky.android.rxjava.retrofit.Contributor; | 14 | 13 | import com.morihacky.android.rxjava.retrofit.GithubApi; | 15 | 14 | import com.morihacky.android.rxjava.retrofit.GithubService; | @@ -33,7 +32,6 @@ public class PseudoCacheConcatFragment | 33 | 32 |
| 34 | 33 | @Bind(R.id.log_list) ListView _resultList; | 35 | 34 |
| 36 | | - private Subscription _subscription = null; | 37 | 35 | private HashMap<String, Long> _contributionMap = null; | 38 | 36 | private ArrayAdapter<String> _adapter; | 39 | 37 |
| @@ -47,12 +45,6 @@ public View onCreateView(LayoutInflater inflater, | 47 | 45 | return layout; | 48 | 46 | } | 49 | 47 |
| 50 | | - @Override | 51 | | - public void onPause() { | 52 | | - super.onPause(); | 53 | | - RxUtils.unsubscribeIfNotNull(_subscription); | 54 | | - } | 55 | | - | 56 | 48 | @Override | 57 | 49 | public void onDestroyView() { | 58 | 50 | super.onDestroyView(); | |
|