У меня есть этот класс в Java
public abstract class SimpleApiCallback<T> implements ApiCallback<T> {
private static final String LOG_TAG = "SimpleApiCallback";
private Activity mActivity;
private Context mContext = null;
private View mPostView = null;
/**
* Failure callback to pass on failures to.
*/
private ApiFailureCallback failureCallback = null;
/**
* Constructor
*/
public SimpleApiCallback() {
}
/**
* Constructor
*
* @param activity The context.
*/
public SimpleApiCallback(Activity activity) {
mActivity = activity;
}
/**
* Constructor
*
* @param context The context.
* @param postOnView the view to post the code to execute
*/
public SimpleApiCallback(Context context, View postOnView) {
mContext = context;
mPostView = postOnView;
}
/**
* Constructor to delegate failure callback to another object. This allows us to stack failure callback implementations
* in a decorator-type approach.
*
* @param failureCallback the failure callback implementation to delegate to
*/
public SimpleApiCallback(ApiFailureCallback failureCallback) {
this.failureCallback = failureCallback;
}
private void displayToast(final String message) {
if (null != mActivity) {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mActivity, message, Toast.LENGTH_SHORT).show();
}
});
} else if ((null != mContext) && (null != mPostView)) {
mPostView.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
}
});
}
}
@Override
public void onNetworkError(Exception e) {
if (failureCallback != null) {
try {
failureCallback.onNetworkError(e);
} catch (Exception exception) {
Log.e(LOG_TAG, "## onNetworkError() failed" + exception.getMessage(), exception);
}
} else {
displayToast("Network Error");
}
}
@Override
public void onMatrixError(final MatrixError e) {
if (failureCallback != null) {
try {
failureCallback.onMatrixError(e);
} catch (Exception exception) {
Log.e(LOG_TAG, "## onMatrixError() failed" + exception.getMessage(), exception);
}
} else {
displayToast("Matrix Error : " + e.getLocalizedMessage());
}
}
@Override
public void onUnexpectedError(final Exception e) {
if (failureCallback != null) {
try {
failureCallback.onUnexpectedError(e);
} catch (Exception exception) {
Log.e(LOG_TAG, "## onUnexpectedError() failed" + exception.getMessage(), exception);
}
} else {
displayToast(e.getLocalizedMessage());
}
}
}
Я могу назвать его в Java следующим образом
new SimpleApiCallback<Void>(this) {
@Override
public void onSuccess(Void avoid) {
///
}
@Override
public void onNetworkError(Exception e) {
///
}
@Override
public void onUnexpectedError(Exception e) {
///
}
@Override
public void onMatrixError(MatrixError e) {
//
}
}
но в kotlin я пробовал много форматов, чтобы вызвать его, но это не такработа
как
val callback = object : SimpleApiCallback<>(activity){
fun onSuccess(avoid: Void) {
///
}
fun onNetworkError(e: Exception) {
///
}
fun onUnexpectedError(e: Exception) {
///
}
fun onMatrixError(e: MatrixError) {
//
}
}
кто-нибудь может посоветовать, пожалуйста?