Skip to content

Commit

Permalink
Add Show Compare Profile UI *
Browse files Browse the repository at this point in the history
  • Loading branch information
redls committed Sep 9, 2019
1 parent f7404f8 commit ad22443
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 0 deletions.
16 changes: 16 additions & 0 deletions source/PluginDev/Assets/GooglePlayGames/BasicApi/DummyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,22 @@ private static void LogUsage()
{
Logger.d("Received method call on DummyClient - using stub implementation.");
}

/// <summary>
/// Shows the Player Games Profile UI for the given user identifier.
/// </summary>
/// <param name="userId">User Identifier.</param>
/// <param name="callback">Callback invoked upon completion.</param>
public void ShowCompareProfileUI(
string userId,
Action<UIStatus> callback)
{
LogUsage();
if (callback != null)
{
callback.Invoke(UIStatus.VersionUpdateRequired);
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ void SubmitScore(string leaderboardId, long score, string metadata,
/// popups for achievements and other game services elements.</remarks>
/// <param name="gravity">Gravity for the popup.</param>
void SetGravityForPopups(Gravity gravity);

/// <summary>
/// Shows the Play Games Player Profile UI for a specific user identifier.
/// </summary>
/// <param name="userId">User identifier.</param>
/// <param name="callback">Callback invoked upon completion.</param>
void ShowCompareProfileUI(string userId, Action<UIStatus> callback);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,28 @@ public void ReportProgress(string achievementID, double progress, Action<bool> c
});
}

/// <summary>
/// Shows the Player Profile UI for the given user identifier.
/// </summary>
/// <param name="userId">User Identifier.</param>
/// <param name="callback">Callback invoked upon completion.</param>
public void ShowCompareProfileUI(string userId, Action<UIStatus> callback)
{
if (!IsAuthenticated())
{
GooglePlayGames.OurUtils.Logger.e("ShowCompareProfileUI can only be called after authentication.");
if (callback != null)
{
callback(UIStatus.NotAuthorized);
}

return;
}
GooglePlayGames.OurUtils.Logger.d("ShowCompareProfileUI, userId=" +
userId + " callback is " + callback);
mClient.ShowCompareProfileUI(userId, callback);
}

/// <summary>
/// Reveals the achievement with the passed identifier. This is a Play Games extension of the ISocialPlatform API.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,34 @@ public void GetPlayerStats(Action<CommonStatusCodes, PlayerStats> callback)
});
}
}

///<summary></summary>
/// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.ShowCompareProfileUI"/>
public void ShowCompareProfileUI(string userId, Action<UIStatus> callback)
{
if (!IsAuthenticated())
{
InvokeCallbackOnGameThread(callback, UIStatus.NotAuthorized);
return;
}

using (var playersClient = getPlayersClient())
using (var task = playersClient.Call<AndroidJavaObject>("loadPlayer", userId))
{
AndroidTaskUtils.AddOnSuccessListener<AndroidJavaObject>(
task, annotatedData =>
{
using (var user = annotatedData.Call<AndroidJavaObject>("get"))
{
AndroidHelperFragment.ShowCompareProfileUI(user, AsOnGameThreadCallback(callback));
}
});
AndroidTaskUtils.AddOnFailureListener(task, exception =>
{
InvokeCallbackOnGameThread(callback, UIStatus.NotAuthorized);
});
}
}

///<summary></summary>
/// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.LoadUsers"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ public static void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan t
}
}

public static void ShowCompareProfileUI(AndroidJavaObject user, Action<UIStatus> cb)
{
using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
using (var task = helperFragment.CallStatic<AndroidJavaObject>("showCompareProfileUI",
AndroidHelperFragment.GetActivity(), user))
{
AndroidTaskUtils.AddOnSuccessListener<int>(
task,
uiCode =>
{
Debug.Log("ShowCompareProfileUI result " + uiCode);
cb.Invoke((UIStatus) uiCode);
});
AndroidTaskUtils.AddOnFailureListener(
task,
exception =>
{
Debug.Log("ShowCompareProfileUI failed with exception");
cb.Invoke(UIStatus.InternalError);
});
}
}

public static void ShowSelectSnapshotUI(bool showCreateSaveUI, bool showDeleteSaveUI,
int maxDisplayedSavedGames, string uiTitle, Action<SelectUIStatus, ISavedGameMetadata> cb)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.google.games.bridge;

import android.app.Activity;
import android.content.Intent;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.games.Games;
import com.google.android.gms.games.PlayersClient;
import com.google.android.gms.games.Player;
import com.google.android.gms.tasks.Task;

class CompareProfileUiRequest extends SimpleUiRequest {
private static final String TAG = "CompareProfileUiRequest";
private Player player;

CompareProfileUiRequest(Player player) {
this.player = player;
}

@Override
protected Task<Intent> getIntent(Activity activity) {
GoogleSignInAccount account = HelperFragment.getAccount(activity);
PlayersClient playersClient = Games.getPlayersClient(activity, account);
return playersClient.getCompareProfileIntent(player);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.android.gms.common.api.Status;
import com.google.android.gms.games.Games;
import com.google.android.gms.games.GamesActivityResultCodes;
import com.google.android.gms.games.Player;
import com.google.android.gms.games.multiplayer.Invitation;
import com.google.android.gms.games.multiplayer.realtime.Room;
import com.google.android.gms.tasks.Task;
Expand Down Expand Up @@ -173,6 +174,17 @@ public static Task<BaseSelectOpponentsUiRequest.Result> showRtmpSelectOpponentsU

return request.getTask();
}

public static Task<Integer> showCompareProfileUI(Activity parentActivity, Player player) {
CompareProfileUiRequest request = new CompareProfileUiRequest(player);

if(!HelperFragment.startRequest(parentActivity, request)) {
request.setResult(CommonUIStatus.UI_BUSY);
}

return request.getTask();
}


public static Task<BaseSelectOpponentsUiRequest.Result> showTbmpSelectOpponentsUi(Activity parentActivity, int minOpponents, int maxOpponents) {
TbmpSelectOpponentsUiRequest request = new TbmpSelectOpponentsUiRequest(minOpponents, maxOpponents);
Expand Down

0 comments on commit ad22443

Please sign in to comment.