| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5c3c31c commit 517101a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,20 +9,23 @@ | |||
| 9 | 9 | import android.view.View; | |
| 10 | 10 | import android.view.ViewGroup; | |
| 11 | 11 | import android.widget.ArrayAdapter; | |
| 12 | + import android.widget.EditText; | ||
| 12 | 13 | import android.widget.ListView; | |
| 13 | 14 | import butterknife.ButterKnife; | |
| 14 | 15 | import butterknife.InjectView; | |
| 15 | - import butterknife.OnTextChanged; | ||
| 16 | 16 | import java.util.ArrayList; | |
| 17 | 17 | import java.util.List; | |
| 18 | 18 | import java.util.concurrent.TimeUnit; | |
| 19 | + import rx.Observable; | ||
| 19 | 20 | import rx.Observer; | |
| 20 | 21 | import rx.Subscription; | |
| 21 | 22 | import rx.android.schedulers.AndroidSchedulers; | |
| 23 | + import rx.android.widget.OnTextChangeEvent; | ||
| 24 | + import rx.android.widget.WidgetObservable; | ||
| 22 | 25 | import rx.schedulers.Schedulers; | |
| 23 | - import rx.subjects.PublishSubject; | ||
| 24 | 26 | import timber.log.Timber; | |
| 25 | 27 | ||
| 28 | + import static java.lang.String.format; | ||
| 26 | 29 | import static rx.android.app.AppObservable.bindFragment; | |
| 27 | 30 | ||
| 28 | 31 | /** | |
@@ -46,12 +49,12 @@ public class SubjectDebounceSearchEmitterFragment | |||
| 46 | 49 | extends BaseFragment { | |
| 47 | 50 | ||
| 48 | 51 | @InjectView(R.id.list_threading_log) ListView _logsList; | |
| 52 | + @InjectView(R.id.input_txt_subject_debounce) EditText _inputSearchText; | ||
| 49 | 53 | ||
| 50 | 54 | private LogAdapter _adapter; | |
| 51 | 55 | private List<String> _logs; | |
| 52 | 56 | ||
| 53 | 57 | private Subscription _subscription; | |
| 54 | - private PublishSubject<String> _searchTextEmitterSubject; | ||
| 55 | 58 | ||
| 56 | 59 | @Override | |
| 57 | 60 | public void onDestroy() { | |
@@ -75,27 +78,20 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |||
| 75 | 78 | super.onActivityCreated(savedInstanceState); | |
| 76 | 79 | _setupLogger(); | |
| 77 | 80 | ||
| 78 | - _searchTextEmitterSubject = PublishSubject.create(); | ||
| 81 | + Observable<OnTextChangeEvent> textChangeObservable = WidgetObservable.text(_inputSearchText); | ||
| 79 | 82 | ||
| 80 | 83 | _subscription = bindFragment(this,// | |
| 81 | - _searchTextEmitterSubject// | ||
| 84 | + textChangeObservable// | ||
| 82 | 85 | .debounce(400, TimeUnit.MILLISECONDS, Schedulers.io())// | |
| 83 | 86 | .observeOn(AndroidSchedulers.mainThread()))// | |
| 84 | 87 | .subscribe(_getSearchObserver()); | |
| 85 | 88 | } | |
| 86 | 89 | ||
| 87 | - @OnTextChanged(R.id.input_txt_subject_debounce) | ||
| 88 | - public void onTextEntered(CharSequence charsEntered) { | ||
| 89 | - Timber.d("---------- text entered %s", charsEntered); | ||
| 90 | - _searchTextEmitterSubject.onNext(charsEntered.toString()); | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | 90 | // ----------------------------------------------------------------------------------- | |
| 94 | 91 | // Main Rx entities | |
| 95 | 92 | ||
| 96 | - private Observer<String> _getSearchObserver() { | ||
| 97 | - return new Observer<String>() { | ||
| 98 | - | ||
| 93 | + private Observer<OnTextChangeEvent> _getSearchObserver() { | ||
| 94 | + return new Observer<OnTextChangeEvent>() { | ||
| 99 | 95 | @Override | |
| 100 | 96 | public void onCompleted() { | |
| 101 | 97 | Timber.d("--------- onComplete"); | |
@@ -104,13 +100,12 @@ public void onCompleted() { | |||
| 104 | 100 | @Override | |
| 105 | 101 | public void onError(Throwable e) { | |
| 106 | 102 | Timber.e(e, "--------- Woops on error!"); | |
| 107 | - _log(String.format("Dang error. check your logs")); | ||
| 103 | + _log("Dang error. check your logs"); | ||
| 108 | 104 | } | |
| 109 | 105 | ||
| 110 | 106 | @Override | |
| 111 | - public void onNext(String searchText) { | ||
| 112 | - _log(String.format("onNext You searched for %s", searchText)); | ||
| 113 | - onCompleted(); | ||
| 107 | + public void onNext(OnTextChangeEvent onTextChangeEvent) { | ||
| 108 | + _log(format("onNext You searched for %s", onTextChangeEvent.text().toString())); | ||
| 114 | 109 | } | |
| 115 | 110 | }; | |
| 116 | 111 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments