Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Show Compare Profile UI * #2718

Open
wants to merge 1 commit into
base: android-java-client
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIStatus.NotAuthorized probably there are more cases it could faild and most frequent one will be no internet connection.
We should get status code from ApiException and switch over possible status codes

});
}
}

///<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