Skip to content

Commit

Permalink
Merge pull request #52 from m0skit0/refactoringFAM
Browse files Browse the repository at this point in the history
Refactoring for issue #40
  • Loading branch information
m0skit0 authored Jun 29, 2020
2 parents e1f1f91 + f3ae7a2 commit 58ab0a1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 23 deletions.
3 changes: 2 additions & 1 deletion hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class AdParam : JavaObjectWrapper

[UnityEngine.Scripting.Preserve]
public static AdParam NewInstance(AndroidJavaObject javaObject) => new AdParam(javaObject);



public AdParam(AndroidJavaObject javaObject) : base(javaObject) { }

public virtual string TargetingContentUrl => CallAsString("getTargetingContentUrl");
Expand Down
7 changes: 6 additions & 1 deletion hms-sdk-unity/HuaweiMobileServices/Ads/BannerAdSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ public static BannerAdSize GetLandscapeBannerSize(int paramInt) =>
public static BannerAdSize GetPortraitBannerSize(int paramInt) =>
sJavaClass.CallStaticAsWrapper<BannerAdSize>("getPortraitBannerSize", AndroidContext.ActivityContext, paramInt);

public BannerAdSize(int paramInt1, int paramInt2) : base(CLASS_NAME, paramInt1, paramInt2) { }

[UnityEngine.Scripting.Preserve]
public static BannerAdSize NewInstance(AndroidJavaObject javaObject) => new BannerAdSize(javaObject);

[UnityEngine.Scripting.Preserve]
public static BannerAdSize NewInstance(int paramInt1, int paramInt2) => new BannerAdSize(paramInt1, paramInt2);


public BannerAdSize(int paramInt1, int paramInt2) : base(CLASS_NAME, paramInt1, paramInt2) { }

public BannerAdSize(AndroidJavaObject javaObject) : base(javaObject) { }

public int Height => Call<int>("getHeight");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,15 @@ namespace HuaweiMobileServices.Game

internal class AchievementClientWrapper : JavaObjectWrapper, IAchievementsClient
{
private static readonly AndroidJavaClass sJavaClass = new AndroidJavaClass("org.m0skit0.android.hms.unity.GenericBridge");


[UnityEngine.Scripting.Preserve]
public static AchievementClientWrapper NewInstance(AndroidJavaObject javaObject) => new AchievementClientWrapper(javaObject);

public AchievementClientWrapper(AndroidJavaObject javaObject) : base(javaObject) { }

public void ShowAchievementList(Action onSuccess, Action<HMSException> onFailure)
{
CallAsWrapper<TaskAndroidJavaObject>("getShowAchievementListIntent")
.AddOnSuccessListener((intent) =>
{
var callback = new GenericBridgeCallbackWrapper()
.AddOnFailureListener(onFailure)
.AddOnSuccessListener((nothing) =>
{
onSuccess.Invoke();
});
sJavaClass.CallStatic("receiveShow", intent, callback);

}).AddOnFailureListener((exception) => onFailure.Invoke(exception));
}

public void ShowAchievementList(Action onSuccess, Action<HMSException> onFailure) => new GenericBridgeWrapper(base.JavaObject).CallGenericBridge(onSuccess, onFailure, "getShowAchievementListIntent");

public Task ShowAchievementListAsync()
{
var task = new TaskCompletionSource<int>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace HuaweiMobileServices.Game
{
using HuaweiMobileServices.Base;
using HuaweiMobileServices.Utils;
using System;
using UnityEngine;

internal class ArchivesClientWrapper : JavaObjectWrapper, IArchivesClient
Expand All @@ -27,9 +28,9 @@ public ITask<IList<ArchiveSummary>> GetArchiveSummaryList(bool paramBoolean)
return new TaskWrapper<IList<ArchiveSummary>>(task, AndroidJavaObjectExtensions.AsListFromWrappable<ArchiveSummary>);
}

public ITask<AndroidIntent> GetShowArchiveListIntent(string paramString, bool paramBoolean1, bool paramBoolean2, int paramInt) =>
CallAsWrapper<TaskJavaObjectWrapper<AndroidIntent>>("getShowArchiveListIntent", paramString, paramBoolean1, paramBoolean2, paramInt);

public void ShowArchiveListIntent(Action onSuccess, Action<HMSException> onFailure) =>
this.CallGenericBridge("getShowArchiveListIntent", onSuccess, onFailure);
public ITask<AndroidBitmap> GetThumbnail(string paramString) =>
CallAsWrapper<TaskJavaObjectWrapper<AndroidBitmap>>("getThumbnail", paramString);

Expand Down
3 changes: 2 additions & 1 deletion hms-sdk-unity/HuaweiMobileServices/Game/IArchivesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace HuaweiMobileServices.Game
{
using HuaweiMobileServices.Base;
using HuaweiMobileServices.Utils;
using System;

// Wrapper for com.huawei.hms.jos.games.ArchivesClient
public interface IArchivesClient
Expand All @@ -30,7 +31,7 @@ public interface IArchivesClient

ITask<int> LimitDetailsSize { get; }

ITask<AndroidIntent> GetShowArchiveListIntent(string paramString, bool paramBoolean1, bool paramBoolean2, int paramInt);
void ShowArchiveListIntent(Action onSuccess, Action<HMSException> onFailure);

ITask<IList<ArchiveSummary>> GetArchiveSummaryList(bool paramBoolean);

Expand Down
29 changes: 29 additions & 0 deletions hms-sdk-unity/HuaweiMobileServices/Utils/GenericBridgeWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace HuaweiMobileServices.Utils
{
using HuaweiMobileServices.Base;
using UnityEngine;

internal static class GenericBridgeWrapper
{
private static readonly AndroidJavaClass sJavaClass = new AndroidJavaClass("org.m0skit0.android.hms.unity.GenericBridge");

public static void CallGenericBridge(this JavaObjectWrapper javaObjectWrapper, String methodName, Action onSuccess, Action<HMSException> onFailure)
{

javaObjectWrapper.CallAsWrapper<TaskAndroidJavaObject>(methodName)
.AddOnSuccessListener((intent) =>
{
var callback = new GenericBridgeCallbackWrapper()
.AddOnFailureListener(onFailure)
.AddOnSuccessListener((nothing) =>
{
onSuccess.Invoke();
});
sJavaClass.CallStatic("receiveShow", intent, callback);

}).AddOnFailureListener((exception) => onFailure.Invoke(exception));
}
}
}

0 comments on commit 58ab0a1

Please sign in to comment.