All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dg.libs.rest.handlers.UIThreadResponseHandler Maven / Gradle / Ivy

package com.dg.libs.rest.handlers;

import android.os.Handler;
import android.os.Looper;

import com.dg.libs.rest.callbacks.HttpCallback;
import com.dg.libs.rest.domain.ResponseStatus;

public class UIThreadResponseHandler extends BackgroundThreadResponseHandler implements ResponseHandler {

	public static final String TAG = UIThreadResponseHandler.class.getSimpleName();
	private static Handler handler;

	public UIThreadResponseHandler(HttpCallback callback) {
		super(callback);
		if (handler == null) {
			handler = new Handler(Looper.getMainLooper());
		}
	}

	@Override
	public void handleSuccess(final T responseData) {
		handler.post(new Runnable() {

			@Override
			public void run() {
				if (callback != null) {
					callback.onSuccess(responseData);
				}
			}
		});
	}

	@Override
	public void handleError(final ResponseStatus status) {
		handler.post(new Runnable() {

			@Override
			public void run() {
				if (callback != null) {
					callback.onHttpError(status);
				}
			}
		});
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy