GeezerVison is showing github.com — Merge pull request #62 from ObjectiveTruth/master · linuxgg/RxJava-Android-Samples@fb5cb28
File tree
Expand file treeCollapse file tree
Open diff view settings
app/src/main/java/com/morihacky/android/rxjava/volley
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/volley/VolleyDemoFragment.java +13-2Lines changed: 13 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -74,6 +74,12 @@ public void onDestroyView() { |
74 | 74 | ButterKnife.unbind(this); |
75 | 75 | } |
76 | 76 |
|
| 77 | + /** |
| 78 | + * Creates and returns an observable generated from the Future returned from |
| 79 | + * {@code getRouteData()}. The observable can then be subscribed to as shown in |
| 80 | + * {@code startVolleyRequest()} |
| 81 | + * @return Observable<JSONObject> |
| 82 | + */ |
77 | 83 | public Observable<JSONObject> newGetRouteData() { |
78 | 84 | return Observable.defer(() -> { |
79 | 85 | try { |
@@ -119,11 +125,16 @@ public void onNext(JSONObject jsonObject) { |
119 | 125 | } |
120 | 126 | })); |
121 | 127 | } |
122 | | - |
| 128 | + /** |
| 129 | + * Converts the Asynchronous Request into a Synchronous Future that can be used to |
| 130 | + * block via {@code Future.get()}. Observables require blocking/synchronous functions |
| 131 | + * @return JSONObject |
| 132 | + * @throws ExecutionException |
| 133 | + * @throws InterruptedException |
| 134 | + */ |
123 | 135 | private JSONObject getRouteData() throws ExecutionException, InterruptedException { |
124 | 136 | RequestFuture<JSONObject> future = RequestFuture.newFuture(); |
125 | 137 | String url = "http://www.weather.com.cn/adat/sk/101010100.html"; |
126 | | - final Request.Priority priority = Request.Priority.IMMEDIATE; |
127 | 138 | JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, url, future, future); |
128 | 139 | MyVolley.getRequestQueue().add(req); |
129 | 140 | return future.get(); |
|