Combine two callbacks into one
Этот коммит содержится в:
@@ -31,8 +31,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
public static final String DATABASE_NAME = "traccar.db";
|
||||
|
||||
public interface DatabaseHandler<T> {
|
||||
void onSuccess(T result);
|
||||
void onFailure(RuntimeException error);
|
||||
void onComplete(boolean success, T result);
|
||||
}
|
||||
|
||||
private static abstract class DatabaseAsyncTask<T> extends AsyncTask<Void, Void, T> {
|
||||
@@ -58,11 +57,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(T result) {
|
||||
if (error == null) {
|
||||
handler.onSuccess(result);
|
||||
} else {
|
||||
handler.onFailure(error);
|
||||
}
|
||||
handler.onComplete(error == null, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ public class RequestManager {
|
||||
private static final int TIMEOUT = 15 * 1000;
|
||||
|
||||
public interface RequestHandler {
|
||||
void onSuccess();
|
||||
void onFailure();
|
||||
void onComplete(boolean success);
|
||||
}
|
||||
|
||||
private static class RequestAsyncTask extends AsyncTask<String, Void, Boolean> {
|
||||
@@ -46,11 +45,7 @@ public class RequestManager {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (result) {
|
||||
handler.onSuccess();
|
||||
} else {
|
||||
handler.onFailure();
|
||||
}
|
||||
handler.onComplete(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,18 +122,15 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
||||
lock();
|
||||
databaseHelper.insertPositionAsync(position, new DatabaseHelper.DatabaseHandler<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
if (isOnline && isWaiting) {
|
||||
read();
|
||||
isWaiting = false;
|
||||
public void onComplete(boolean success, Void result) {
|
||||
if (success) {
|
||||
if (isOnline && isWaiting) {
|
||||
read();
|
||||
isWaiting = false;
|
||||
}
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(RuntimeException error) {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,20 +139,18 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
||||
lock();
|
||||
databaseHelper.selectPositionAsync(new DatabaseHelper.DatabaseHandler<Position>() {
|
||||
@Override
|
||||
public void onSuccess(Position result) {
|
||||
if (result != null) {
|
||||
send(result);
|
||||
public void onComplete(boolean success, Position result) {
|
||||
if (success) {
|
||||
if (result != null) {
|
||||
send(result);
|
||||
} else {
|
||||
isWaiting = true;
|
||||
}
|
||||
} else {
|
||||
isWaiting = true;
|
||||
retry();
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(RuntimeException error) {
|
||||
retry();
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -164,14 +159,12 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
||||
lock();
|
||||
databaseHelper.deletePositionAsync(position.getId(), new DatabaseHelper.DatabaseHandler<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
read();
|
||||
unlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(RuntimeException error) {
|
||||
retry();
|
||||
public void onComplete(boolean success, Void result) {
|
||||
if (success) {
|
||||
read();
|
||||
} else {
|
||||
retry();
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
@@ -187,15 +180,12 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
||||
|
||||
RequestManager.sendRequestAsync(request, new RequestManager.RequestHandler() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
delete(position);
|
||||
unlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
StatusActivity.addMessage(context.getString(R.string.status_send_fail));
|
||||
retry();
|
||||
public void onComplete(boolean success) {
|
||||
if (success) {
|
||||
delete(position);
|
||||
} else {
|
||||
retry();
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
Ссылка в новой задаче
Block a user