Skip to content

Commit 8f56f3f

Browse files
committed
Try EventBus instead of Callbacks
1 parent ccf8f84 commit 8f56f3f

3 files changed

Lines changed: 13 additions & 31 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
8+
classpath 'com.android.tools.build:gradle:2.0.0-alpha8'
99
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
1010
}
1111
}

library/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ android {
1818
dependencies {
1919
compile 'com.android.support:support-annotations:23.1.1'
2020
compile 'com.github.afollestad:bridge:3.1.1'
21+
compile 'de.greenrobot:eventbus:2.4.0'
2122
}
2223

2324

library/src/main/java/com/proxerme/library/connection/ProxerConnection.java

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.List;
2929
import java.util.concurrent.ConcurrentLinkedQueue;
3030

31+
import de.greenrobot.event.EventBus;
32+
3133
import static com.proxerme.library.connection.ProxerException.ErrorCodes.PROXER;
3234
import static com.proxerme.library.connection.ProxerException.ErrorCodes.UNKNOWN;
3335
import static com.proxerme.library.connection.ProxerTag.CONFERENCES;
@@ -164,7 +166,7 @@ public static void cleanup() {
164166

165167
/**
166168
* An abstract representation of a callback, passed to the
167-
* {@link ProxerRequest#execute(ResultCallback)} method.
169+
* {@link ProxerRequest#execute()} method.
168170
*
169171
* @param <T> The generic parameter.
170172
*/
@@ -194,7 +196,7 @@ public static abstract class ProxerRequest<T> {
194196

195197
/**
196198
* Builds the request, to be used in the
197-
* {@link #execute(ResultCallback)} or
199+
* {@link #execute()} or
198200
* {@link #executeSynchronized()} method.
199201
*
200202
* @return The {@link RequestBuilder} to use for further invocations.
@@ -213,11 +215,10 @@ public static abstract class ProxerRequest<T> {
213215
/**
214216
* Asynchronously executes this request.
215217
*
216-
* @param callback The callback for notifications about the Result.
217218
* @see #executeSynchronized()
218219
*/
219220
@RequiresPermission(android.Manifest.permission.INTERNET)
220-
public final void execute(@NonNull final ResultCallback<T> callback) {
221+
public final void execute() {
221222
buildRequest().throwIfNotSuccess().tag(String.valueOf(getTag())).request(new Callback() {
222223
@Override
223224
public void response(Request request, final Response response,
@@ -230,36 +231,16 @@ public void run() {
230231
JSONObject json = response.asJsonObject();
231232

232233
if (json == null) {
233-
handler.post(new Runnable() {
234-
@Override
235-
public void run() {
236-
callback.onError(new ProxerException(UNKNOWN));
237-
}
238-
});
234+
EventBus.getDefault().post(new ProxerException(UNKNOWN));
239235
} else {
240236
final T result = parse(json);
241237

242-
handler.post(new Runnable() {
243-
@Override
244-
public void run() {
245-
callback.onResult(result);
246-
}
247-
});
238+
EventBus.getDefault().post(result);
248239
}
249240
} catch (final JSONException e) {
250-
handler.post(new Runnable() {
251-
@Override
252-
public void run() {
253-
callback.onError(ErrorHandler.handleException(e));
254-
}
255-
});
241+
EventBus.getDefault().post(ErrorHandler.handleException(e));
256242
} catch (final BridgeException e) {
257-
handler.post(new Runnable() {
258-
@Override
259-
public void run() {
260-
callback.onError(ErrorHandler.handleException(e));
261-
}
262-
});
243+
EventBus.getDefault().post(ErrorHandler.handleException(e));
263244
}
264245

265246
parseThreads.remove(getThread());
@@ -270,7 +251,7 @@ public void run() {
270251
parseThread.start();
271252
} else {
272253
if (exception.reason() != BridgeException.REASON_REQUEST_CANCELLED) {
273-
callback.onError(ErrorHandler.handleException(exception));
254+
EventBus.getDefault().post(ErrorHandler.handleException(exception));
274255
}
275256
}
276257
}
@@ -282,7 +263,7 @@ public void run() {
282263
*
283264
* @return The result, specified by this class.
284265
* @throws ProxerException An Exception, which might occur, while executing the request.
285-
* @see #execute(ResultCallback)
266+
* @see #execute()
286267
*/
287268
@WorkerThread
288269
@RequiresPermission(android.Manifest.permission.INTERNET)

0 commit comments

Comments
 (0)