Skip to content

Commit cabbab0

Browse files
committed
Remove EventBus logic, as it is not wrking properly without rewriting all the code
1 parent 4d7579f commit cabbab0

2 files changed

Lines changed: 50 additions & 12 deletions

File tree

library/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ dependencies {
2525
compile fileTree(dir: 'libs', include: ['*.jar'])
2626
compile 'com.android.support:support-annotations:23.1.1'
2727
compile 'com.github.afollestad:bridge:1.6.4@aar'
28-
compile 'de.greenrobot:eventbus:2.4.0'
2928
}
3029

3130
// build a jar with source files

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

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.proxerme.library.connection;
22

3+
import android.os.Handler;
4+
import android.os.Looper;
35
import android.support.annotation.CheckResult;
46
import android.support.annotation.IntRange;
57
import android.support.annotation.NonNull;
@@ -25,8 +27,6 @@
2527
import java.util.LinkedList;
2628
import java.util.List;
2729

28-
import de.greenrobot.event.EventBus;
29-
3030
import static com.proxerme.library.connection.ProxerException.ErrorCodes.PROXER;
3131
import static com.proxerme.library.connection.ProxerException.ErrorCodes.UNKNOWN;
3232
import static com.proxerme.library.connection.ProxerTag.CONFERENCES;
@@ -166,6 +166,29 @@ public static void cleanup() {
166166
Bridge.cleanup();
167167
}
168168

169+
/**
170+
* An abstract representation of a callback, passed to the
171+
* {@link ProxerRequest#execute(ResultCallback)} method.
172+
*
173+
* @param <T> The generic parameter.
174+
*/
175+
public interface ResultCallback<T> {
176+
/**
177+
* A callback method, called if the request was successful.
178+
*
179+
* @param result The result of the specific request.
180+
*/
181+
void onResult(T result);
182+
183+
/**
184+
* A callback method, called if an error occurred during the request.
185+
*
186+
* @param exception The Exception that occurred.
187+
* @see ProxerException
188+
*/
189+
void onError(@NonNull ProxerException exception);
190+
}
191+
169192
/**
170193
* An abstract representation of a request. All requests to the API are made through this class.
171194
*
@@ -175,7 +198,7 @@ public static abstract class ProxerRequest<T> {
175198

176199
/**
177200
* Builds the request, to be used in the
178-
* {@link #execute()} or
201+
* {@link #execute(ResultCallback)} or
179202
* {@link #executeSynchronized()} method.
180203
*
181204
* @param bridge The Bridge instance to build the request with.
@@ -193,12 +216,13 @@ public static abstract class ProxerRequest<T> {
193216
protected abstract int getTag();
194217

195218
/**
196-
* Asynchronously executes this request. All results are passed back through the EventBus.
219+
* Asynchronously executes this request.
197220
*
221+
* @param callback The callback for notifications about the Result.
198222
* @see #executeSynchronized()
199223
*/
200224
@RequiresPermission(android.Manifest.permission.INTERNET)
201-
public final void execute() {
225+
public final void execute(@NonNull final ResultCallback<T> callback) {
202226
buildRequest(Bridge.client()).tag(getTag()).request(new Callback() {
203227
@Override
204228
public void response(Request request, final Response response, BridgeException exception) {
@@ -209,11 +233,26 @@ public void run() {
209233
try {
210234
final T result = parse(response.asJsonObject());
211235

212-
EventBus.getDefault().post(result);
236+
new Handler(Looper.getMainLooper()).post(new Runnable() {
237+
@Override
238+
public void run() {
239+
callback.onResult(result);
240+
}
241+
});
213242
} catch (final JSONException e) {
214-
EventBus.getDefault().post(ErrorHandler.handleException(e));
243+
new Handler(Looper.getMainLooper()).post(new Runnable() {
244+
@Override
245+
public void run() {
246+
callback.onError(ErrorHandler.handleException(e));
247+
}
248+
});
215249
} catch (final BridgeException e) {
216-
EventBus.getDefault().post(ErrorHandler.handleException(e));
250+
new Handler(Looper.getMainLooper()).post(new Runnable() {
251+
@Override
252+
public void run() {
253+
callback.onError(ErrorHandler.handleException(e));
254+
}
255+
});
217256
}
218257
}
219258
});
@@ -222,7 +261,7 @@ public void run() {
222261
parseThread.start();
223262
} else {
224263
if (exception.reason() != BridgeException.REASON_REQUEST_CANCELLED) {
225-
EventBus.getDefault().post(ErrorHandler.handleException(exception));
264+
callback.onError(ErrorHandler.handleException(exception));
226265
}
227266
}
228267
}
@@ -234,7 +273,7 @@ public void run() {
234273
*
235274
* @return The result, specified by this class.
236275
* @throws ProxerException An Exception, which might occur, while executing the request.
237-
* @see #execute()
276+
* @see #execute(ResultCallback)
238277
*/
239278
@WorkerThread
240279
@RequiresPermission(android.Manifest.permission.INTERNET)
@@ -374,4 +413,4 @@ protected List<Conference> parse(@NonNull JSONObject response) throws JSONExcept
374413
return ProxerParser.parseConferencesJSON(response);
375414
}
376415
}
377-
}
416+
}

0 commit comments

Comments
 (0)