Skip to content

Commit 01b306a

Browse files
committed
Added query methods to support Android SDK 1.3.x
1 parent 40436fd commit 01b306a

36 files changed

+2721
-908
lines changed

Assets/Zapic/Android.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#if !UNITY_EDITOR && UNITY_ANDROID
2+
3+
using System;
4+
using UnityEngine;
5+
6+
namespace ZapicSDK
7+
{
8+
internal sealed class ZapicAndroidAuthenticationHandler : AndroidJavaProxy
9+
{
10+
/// <summary>The <see cref="IZapicInterface"/> that communicates with the Zapic Android SDK.</summary>
11+
private readonly ZapicAndroidInterface platform;
12+
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="ZapicAndroidAuthenticationHandler"/> class.
15+
/// </summary>
16+
/// <param name="platform">
17+
/// The <see cref="IZapicInterface"/> that communicates with the Zapic Android SDK.
18+
/// </param>
19+
internal ZapicAndroidAuthenticationHandler(ZapicAndroidInterface platform)
20+
: base("com/zapic/sdk/android/ZapicPlayerAuthenticationHandler")
21+
{
22+
this.platform = platform;
23+
}
24+
25+
public void onLogin(AndroidJavaObject playerObject)
26+
{
27+
try
28+
{
29+
var handler = platform.OnLogin;
30+
if (handler == null)
31+
{
32+
return;
33+
}
34+
35+
ZapicPlayer player;
36+
try
37+
{
38+
player = ZapicAndroidUtilities.ConvertPlayer(playerObject);
39+
}
40+
catch (Exception e)
41+
{
42+
Debug.LogError("Zapic: An error occurred converting the Java object to ZapicPlayer");
43+
Debug.LogException(e);
44+
return;
45+
}
46+
finally
47+
{
48+
if (playerObject != null)
49+
{
50+
playerObject.Dispose();
51+
playerObject = null;
52+
}
53+
}
54+
55+
try
56+
{
57+
handler(player);
58+
}
59+
catch (Exception e)
60+
{
61+
Debug.LogError("Zapic: An error occurred invoking the application callback");
62+
Debug.LogException(e);
63+
}
64+
}
65+
finally
66+
{
67+
if (playerObject != null)
68+
{
69+
playerObject.Dispose();
70+
}
71+
}
72+
}
73+
74+
public void onLogout(AndroidJavaObject playerObject)
75+
{
76+
try
77+
{
78+
var handler = platform.OnLogout;
79+
if (handler == null)
80+
{
81+
return;
82+
}
83+
84+
ZapicPlayer player;
85+
try
86+
{
87+
player = ZapicAndroidUtilities.ConvertPlayer(playerObject);
88+
}
89+
catch (Exception e)
90+
{
91+
Debug.LogError("Zapic: An error occurred converting the Java object to ZapicPlayer");
92+
Debug.LogException(e);
93+
return;
94+
}
95+
finally
96+
{
97+
if (playerObject != null)
98+
{
99+
playerObject.Dispose();
100+
playerObject = null;
101+
}
102+
}
103+
104+
try
105+
{
106+
handler(player);
107+
}
108+
catch (Exception e)
109+
{
110+
Debug.LogError("Zapic: An error occurred invoking the application callback");
111+
Debug.LogException(e);
112+
}
113+
}
114+
finally
115+
{
116+
if (playerObject != null)
117+
{
118+
playerObject.Dispose();
119+
}
120+
}
121+
}
122+
}
123+
}
124+
125+
#endif

Assets/Zapic/ZapicPlayType.cs.meta renamed to Assets/Zapic/Android/ZapicAndroidAuthenticationHandler.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#if !UNITY_EDITOR && UNITY_ANDROID
2+
3+
using System;
4+
using UnityEngine;
5+
6+
namespace ZapicSDK
7+
{
8+
internal sealed class ZapicAndroidFunctionCallback<T> : AndroidJavaProxy
9+
where T : class
10+
{
11+
/// <summary>The callback invoked with the result of the asynchronous query.</summary>
12+
private readonly Action<T, ZapicException> callback;
13+
14+
/// <summary>The callback invoked to convert the result of the asynchronous query.</summary>
15+
private readonly Func<AndroidJavaObject, T> convertResult;
16+
17+
/// <summary>Initializes a new instance of the <see cref="ZapicAndroidFunctionCallback{T}"/> class.</summary>
18+
/// <param name="callback">The callback invoked with the result of the asynchronous query.</param>
19+
/// <param name="convertResult">The callback invoked to convert the result of the asynchronous query.</param>
20+
/// <exception cref="ArgumentNullException">
21+
/// If <paramref name="callback"/> or <paramref name="convertResult"/> are <c>null</c>.
22+
/// </exception>
23+
internal ZapicAndroidFunctionCallback(
24+
Action<T, ZapicException> callback,
25+
Func<AndroidJavaObject, T> convertResult)
26+
: base("com/zapic/sdk/android/ZapicCallback")
27+
{
28+
if (callback == null)
29+
{
30+
throw new ArgumentNullException("callback");
31+
}
32+
33+
if (convertResult == null)
34+
{
35+
throw new ArgumentNullException("convertResult");
36+
}
37+
38+
this.callback = callback;
39+
this.convertResult = convertResult;
40+
}
41+
42+
public void onComplete(AndroidJavaObject resultObject, AndroidJavaObject errorObject)
43+
{
44+
try
45+
{
46+
ZapicException error;
47+
try
48+
{
49+
error = ZapicAndroidUtilities.ConvertError(errorObject);
50+
}
51+
catch (Exception e)
52+
{
53+
Debug.LogError("Zapic: An error occurred converting the Java object to ZapicException");
54+
Debug.LogException(e);
55+
56+
error = new ZapicException(
57+
ZapicErrorCode.INVALID_RESPONSE,
58+
"An error occurred converting the Java object to ZapicException",
59+
e);
60+
}
61+
finally
62+
{
63+
if (errorObject != null)
64+
{
65+
errorObject.Dispose();
66+
errorObject = null;
67+
}
68+
}
69+
70+
if (error != null)
71+
{
72+
if (resultObject != null)
73+
{
74+
resultObject.Dispose();
75+
resultObject = null;
76+
}
77+
78+
try
79+
{
80+
callback(null, error);
81+
}
82+
catch (Exception e)
83+
{
84+
Debug.LogError("Zapic: An error occurred invoking the application callback");
85+
Debug.LogException(e);
86+
}
87+
88+
return;
89+
}
90+
91+
T result;
92+
try
93+
{
94+
result = convertResult(resultObject);
95+
}
96+
catch (Exception e)
97+
{
98+
Debug.LogError("Zapic: An error occurred converting the Java object to " + typeof(T).Name);
99+
Debug.LogException(e);
100+
101+
error = new ZapicException(
102+
ZapicErrorCode.INVALID_RESPONSE,
103+
"An error occurred converting the Java object to " + typeof(T).Name,
104+
e);
105+
result = null;
106+
}
107+
finally
108+
{
109+
if (resultObject != null)
110+
{
111+
resultObject.Dispose();
112+
resultObject = null;
113+
}
114+
}
115+
116+
try
117+
{
118+
if (error != null)
119+
{
120+
callback(null, error);
121+
}
122+
else
123+
{
124+
callback(result, null);
125+
}
126+
}
127+
catch (Exception e)
128+
{
129+
Debug.LogError("Zapic: An error occurred invoking the application callback");
130+
Debug.LogException(e);
131+
}
132+
}
133+
finally
134+
{
135+
if (errorObject != null)
136+
{
137+
errorObject.Dispose();
138+
}
139+
140+
if (resultObject != null)
141+
{
142+
resultObject.Dispose();
143+
}
144+
}
145+
}
146+
}
147+
}
148+
149+
#endif

Assets/Zapic/Android/ZapicAndroidFunctionCallback{T}.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)