Skip to content

Commit

Permalink
Made some methods onliners, removed unecessary variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzeferino committed Jul 31, 2017
1 parent 69acd73 commit dacb047
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 54 deletions.
36 changes: 12 additions & 24 deletions src/Xamarin.Android.LinkedIn/APIHelper.cs
Expand Up @@ -12,60 +12,48 @@ partial class APIHelper
{
public void GetRequest(Context context, string url, Action<ApiResponse> onSuccess, Action<LIApiError> onError)
{
var listener = new ApiListener(onSuccess, onError);
GetRequest(context, url, listener);
GetRequest(context, url, new ApiListener(onSuccess, onError));
}

public void DeleteRequest(Context context, string url, Action<ApiResponse> onSuccess, Action<LIApiError> onError)
{
var listener = new ApiListener(onSuccess, onError);
DeleteRequest(context, url, listener);
DeleteRequest(context, url, new ApiListener(onSuccess, onError));
}

public void PostRequest(Context context, string url, JSONObject body, Action<ApiResponse> onSuccess, Action<LIApiError> onError)
{
var listener = new ApiListener(onSuccess, onError);
PostRequest(context, url, body, listener);
PostRequest(context, url, body, new ApiListener(onSuccess, onError));
}

public void PostRequest(Context context, string url, string body, Action<ApiResponse> onSuccess, Action<LIApiError> onError)
{
var listener = new ApiListener(onSuccess, onError);
PostRequest(context, url, body, listener);
PostRequest(context, url, body, new ApiListener(onSuccess, onError));
}

public void PutRequest(Context context, string url, JSONObject body, Action<ApiResponse> onSuccess, Action<LIApiError> onError)
{
var listener = new ApiListener(onSuccess, onError);
PutRequest(context, url, body, listener);
PutRequest(context, url, body, new ApiListener(onSuccess, onError));
}

public void PutRequest(Context context, string url, string body, Action<ApiResponse> onSuccess, Action<LIApiError> onError)
{
var listener = new ApiListener(onSuccess, onError);
PutRequest(context, url, body, listener);
PutRequest(context, url, body, new ApiListener(onSuccess, onError));
}

private class ApiListener : Java.Lang.Object, IApiListener
{
readonly Action<ApiResponse> onSuccess;
readonly Action<LIApiError> onError;
private readonly Action<ApiResponse> _onSuccess;
private readonly Action<LIApiError> _onError;

public ApiListener(Action<ApiResponse> onSuccess, Action<LIApiError> onError)
{
this.onError = onError;
this.onSuccess = onSuccess;
_onError = onError;
_onSuccess = onSuccess;
}

public void OnApiError(LIApiError error)
{
onError?.Invoke(error);
}
public void OnApiError(LIApiError error) => _onError?.Invoke(error);

public void OnApiSuccess(ApiResponse response)
{
onSuccess?.Invoke(response);
}
public void OnApiSuccess(ApiResponse response) => _onSuccess?.Invoke(response);
}
}
}
24 changes: 8 additions & 16 deletions src/Xamarin.Android.LinkedIn/DeepLinkHelper.cs
Expand Up @@ -11,36 +11,28 @@ partial class DeepLinkHelper
{
public void OpenCurrentProfile(Activity activity, Action onSuccess, Action<LIDeepLinkError> onError)
{
var listener = new DeepLinkListener(onSuccess, onError);
OpenCurrentProfile(activity, listener);
OpenCurrentProfile(activity, new DeepLinkListener(onSuccess, onError));
}

public void OpenOtherProfile(Activity activity, string memberId, Action onSuccess, Action<LIDeepLinkError> onError)
{
var listener = new DeepLinkListener(onSuccess, onError);
OpenOtherProfile(activity, memberId, listener);
OpenOtherProfile(activity, memberId, new DeepLinkListener(onSuccess, onError));
}

private class DeepLinkListener : Java.Lang.Object, IDeepLinkListener
{
readonly Action onSuccess;
readonly Action<LIDeepLinkError> onError;
private readonly Action _onSuccess;
private readonly Action<LIDeepLinkError> _onError;

public DeepLinkListener(Action onSuccess, Action<LIDeepLinkError> onError)
{
this.onError = onError;
this.onSuccess = onSuccess;
_onError = onError;
_onSuccess = onSuccess;
}

public void OnDeepLinkError(LIDeepLinkError error)
{
onError?.Invoke(error);
}
public void OnDeepLinkError(LIDeepLinkError error) => _onError?.Invoke(error);

public void OnDeepLinkSuccess()
{
onSuccess?.Invoke();
}
public void OnDeepLinkSuccess() => _onSuccess?.Invoke();
}
}
}
21 changes: 7 additions & 14 deletions src/Xamarin.Android.LinkedIn/LISessionManager.cs
Expand Up @@ -12,30 +12,23 @@ partial class LISessionManager
{
public void Init(Activity activity, Scope scope, bool showGoToAppStoreDialog, Action onSuccess, Action<LIAuthError> onError)
{
var listener = new AuthListener(onSuccess, onError);
Init(activity, scope, listener, showGoToAppStoreDialog);
Init(activity, scope, new AuthListener(onSuccess, onError), showGoToAppStoreDialog);
}

private class AuthListener : Java.Lang.Object, IAuthListener
{
readonly Action onSuccess;
readonly Action<LIAuthError> onError;
private readonly Action _onSuccess;
private readonly Action<LIAuthError> _onError;

public AuthListener(Action onSuccess, Action<LIAuthError> onError)
{
this.onError = onError;
this.onSuccess = onSuccess;
_onError = onError;
_onSuccess = onSuccess;
}

public void OnAuthError(LIAuthError error)
{
onError?.Invoke(error);
}
public void OnAuthError(LIAuthError error) => _onError?.Invoke(error);

public void OnAuthSuccess()
{
onSuccess?.Invoke();
}
public void OnAuthSuccess() => _onSuccess?.Invoke();
}
}
}

0 comments on commit dacb047

Please sign in to comment.