GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: change BehaviorSubject to PublishSubject because that is really … · haikuowuya/Android-RxJava@c852573

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main/java/com/morihacky/android/rxjava
    • ConcurrencyWithSchedulersDemoFragment.java
    • MainActivity.java
    • MainFragment.java
    • SubjectSearchEmitterFragment.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/ConcurrencyWithSchedulersDemoFragment.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/ConcurrencyWithSchedulersDemoFragment.java
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ public void startLongOperation() {
5656
// -----------------------------------------------------------------------------------
5757
// Main Rx entities
5858

59-
/**
60-
* Gets the Observable as emitted from BehaviorSubject
61-
*
62-
* It begins by emitting the item most recently emitted by source Observable
63-
* (or seed/default if none has yet been emitted - which is the case here)
64-
*
65-
* https://github.com/Netflix/RxJava/wiki/Subject#behaviorsubject
66-
*/
6759
private Observable<Boolean> _getObservable() {
6860
return Observable.create(new Observable.OnSubscribe<Boolean>() {
6961

Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/MainActivity.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/MainActivity.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
2020
getSupportFragmentManager().beginTransaction()
2121
.addToBackStack(this.toString())
2222
// .replace(R.id.activity_main, new MainFragment(), this.toString())
23-
.replace(R.id.activity_main, new BehaviorSubjectSearchEmitterFragment(), this.toString())
23+
.replace(R.id.activity_main, new SubjectSearchEmitterFragment(), this.toString())
2424
.commit();
2525
}
2626
}
Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/MainFragment.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/MainFragment.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void demoThrottling() {
5252
.beginTransaction()
5353
.addToBackStack(this.toString())
5454
.replace(R.id.activity_main,
55-
new BehaviorSubjectSearchEmitterFragment(),
55+
new SubjectSearchEmitterFragment(),
5656
this.toString())
5757
.commit();
5858
}
Collapse file

‎…ehaviorSubjectSearchEmitterFragment.java‎ ‎…rxjava/SubjectSearchEmitterFragment.java‎app/src/main/java/com/morihacky/android/rxjava/BehaviorSubjectSearchEmitterFragment.java renamed to app/src/main/java/com/morihacky/android/rxjava/SubjectSearchEmitterFragment.java app/src/main/java/com/morihacky/android/rxjava/BehaviorSubjectSearchEmitterFragment.java renamed to app/src/main/java/com/morihacky/android/rxjava/SubjectSearchEmitterFragment.java

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/SubjectSearchEmitterFragment.java
+14-13Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import rx.android.observables.AndroidObservable;
2828
import rx.android.schedulers.AndroidSchedulers;
2929
import rx.schedulers.Schedulers;
30-
import rx.subjects.BehaviorSubject;
30+
import rx.subjects.PublishSubject;
3131
import timber.log.Timber;
3232

3333

@@ -37,16 +37,18 @@
3737
* (if that Observable is "cold" — that is, if it waits for a subscription before it begins to emit items).
3838
* This can have the effect of making the resulting Subject a "hot" Observable variant of the original "cold" Observable.
3939
*
40-
* This allows us to create the subject and subscription one time onActivity creation. Subsequently
41-
* we send in Observables to the Subject's subscriber onTextChanged
40+
* This allows us to create the subject and subscription one time onActivity creation
41+
* Subsequently we send in Observables to the Subject's subscriber onTextChanged
4242
*
43-
* Otherwise we would have to create the subscription onTextChanged every single time, which is
44-
* wasteful (not really since we anyway unsubscribe at the end).
45-
* less-elegant (as a concept for sure, but not for simplicity vs. the 3 step basic subscription creation)
46-
* doesn't allow us to debounce/throttle/sample ?
43+
* (unlike the way it's done in {@link com.morihacky.android.rxjava.ConcurrencyWithSchedulersDemoFragment#startLongOperation()})
44+
* where we create the subscription on every single event change (OnClick or OnTextchanged) which is
45+
*
46+
* ? wasteful (not really since we anyway unsubscribe at the end).
47+
* less-elegant (as a concept for sure, but not for simplicity vs. the 3 step basic subscription creation)
48+
* ? doesn't allow us to debounce/throttle/sample
4749
*
4850
*/
49-
public class BehaviorSubjectSearchEmitterFragment
51+
public class SubjectSearchEmitterFragment
5052
extends Fragment {
5153

5254
@InjectView(R.id.list_threading_log) ListView _logsList;
@@ -55,16 +57,15 @@ public class BehaviorSubjectSearchEmitterFragment
5557
private List<String> _logs;
5658

5759
private Subscription _subscription;
58-
private BehaviorSubject<Observable<String>> _searchTextEmitterSubject;
60+
private PublishSubject<Observable<String>> _searchTextEmitterSubject;
5961

6062
@Override
6163
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
6264
super.onActivityCreated(savedInstanceState);
6365
_setupLogger();
6466

65-
_searchTextEmitterSubject = BehaviorSubject.create(Observable.<String>empty());
66-
67-
_subscription = AndroidObservable.bindFragment(BehaviorSubjectSearchEmitterFragment.this,
67+
_searchTextEmitterSubject = PublishSubject.create();
68+
_subscription = AndroidObservable.bindFragment(SubjectSearchEmitterFragment.this,
6869
Observable.switchOnNext(_searchTextEmitterSubject))
6970
.subscribeOn(Schedulers.io())
7071
.observeOn(AndroidSchedulers.mainThread())
@@ -175,4 +176,4 @@ public LogAdapter(Context context, List<String> logs) {
175176
super(context, R.layout.item_log, R.id.item_log, logs);
176177
}
177178
}
178-
}
179+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.