Skip to content

Commit 2dff8f1

Browse files
collingreenMartin Hunt
authored andcommitted
wip - facebook sdk update - requests
1 parent 15a91a8 commit 2dff8f1

File tree

3 files changed

+78
-18
lines changed

3 files changed

+78
-18
lines changed

android/FacebookPlugin.java

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import com.facebook.FacebookRequestError;
4848
import com.facebook.FacebookServiceException;
4949
import com.facebook.login.*;
50+
import com.facebook.share.model.GameRequestContent;
51+
import com.facebook.share.widget.GameRequestDialog;
5052

5153
import java.util.Set;
5254

@@ -66,6 +68,7 @@ public class FacebookPlugin implements IPlugin {
6668
public static final int INVALID_ERROR = -2;
6769
private CallbackManager callbackManager;
6870
private AccessTokenTracker accessTokenTracker;
71+
private GameRequestDialog requestDialog;
6972

7073

7174
void onJSONException (JSONException e) {
@@ -257,7 +260,6 @@ public void onCompleted(GraphResponse res) {
257260
public void ui(String s_json, Integer requestId) {
258261
log("ui");
259262
final Integer _requestId = requestId;
260-
// Session session = Session.getActiveSession();
261263

262264
JSONObject json = null;
263265
Bundle params = null;
@@ -277,6 +279,7 @@ public void ui(String s_json, Integer requestId) {
277279
try {
278280
params = BundleJSONConverter.convertToBundle(json);
279281
} catch (JSONException e) {
282+
log("ui failed to convert JSON to bundle");
280283
onJSONException(e);
281284
sendResponse(
282285
getErrorResponse("error converting JSONObject to bundle"),
@@ -289,6 +292,7 @@ public void ui(String s_json, Integer requestId) {
289292

290293
final String method = params.getString("method");
291294
if (method == null) {
295+
log("ui failed - method param is required");
292296
sendResponse(getErrorResponse("method param is required"), null, requestId);
293297
return;
294298
}
@@ -336,19 +340,47 @@ public void run() {
336340
devkitActivity.runOnUiThread(runnable);
337341
*/
338342
} else if (method.equalsIgnoreCase("apprequests")) {
339-
/*
340-
Runnable runnable = new Runnable() {
341-
public void run() {
342-
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
343-
devkitActivity,
344-
Session.getActiveSession(),
345-
dialogParams)
346-
).setOnCompleteListener(dialogCallback).build();
347-
requestsDialog.show();
343+
344+
ArrayList<String> filtersArray = dialogParams.getStringArrayList("filters");
345+
String filtersString = "";
346+
GameRequestContent.Filters filters = null;
347+
if (filtersArray != null) {
348+
filtersString = filtersArray.get(0);
349+
350+
if (filtersString.equalsIgnoreCase("app_non_users")) {
351+
filters = GameRequestContent.Filters.APP_NON_USERS;
352+
} else {
353+
filters = GameRequestContent.Filters.APP_USERS;
354+
}
348355
}
349-
};
350-
devkitActivity.runOnUiThread(runnable);
351-
*/
356+
357+
String objectId = dialogParams.getString("objectId");
358+
GameRequestContent.ActionType actionType = null;
359+
String actionTypeString = dialogParams.getString("actionType");
360+
361+
if (actionTypeString != null) {
362+
actionType = GameRequestContent.ActionType.valueOf(actionTypeString);
363+
}
364+
365+
366+
activeRequest = requestId;
367+
GameRequestContent.Builder builder = new GameRequestContent.Builder()
368+
.setMessage(dialogParams.getString("message"))
369+
.setTitle(dialogParams.getString("title"));
370+
371+
if (filters != null) {
372+
builder.setFilters(filters);
373+
}
374+
375+
if (actionType != null && objectId != null) {
376+
builder
377+
.setObjectId(objectId)
378+
.setActionType(actionType);
379+
}
380+
381+
GameRequestContent content = builder.build();
382+
requestDialog.show(content);
383+
352384
} else if (method.equalsIgnoreCase("share") || method.equalsIgnoreCase("share_open_graph")) {
353385
/*
354386
Boolean canPresentShareDialog = FacebookDialog.canPresentShareDialog(
@@ -670,7 +702,7 @@ protected void onCurrentAccessTokenChanged(
670702
new FacebookCallback<LoginResult>() {
671703
@Override
672704
public void onSuccess(LoginResult loginResult) {
673-
logger.log("facebook login response - success");
705+
log("facebook login response - success");
674706
JSONObject response = getResponse();
675707
sendEvent("auth.login", response);
676708
// respond to login request
@@ -679,24 +711,40 @@ public void onSuccess(LoginResult loginResult) {
679711

680712
@Override
681713
public void onCancel() {
682-
logger.log("facebook login response - cancel");
714+
log("facebook login response - cancel");
683715
// TODO: is this really the best way to say user cancelled?
684716
handleError(new FacebookOperationCanceledException(), activeRequest);
685717
}
686718

687719
@Override
688720
public void onError(FacebookException exception) {
689-
logger.log("facebook login response - error");
721+
log("facebook login response - error");
690722
handleError(exception, activeRequest);
691723
}
692724
});
693725

726+
requestDialog = new GameRequestDialog(_activity);
727+
requestDialog.registerCallback(callbackManager, new FacebookCallback<GameRequestDialog.Result>() {
728+
public void onSuccess(GameRequestDialog.Result result) {
729+
log("game request result - success");
730+
sendResponse("", null, activeRequest);
731+
}
732+
public void onCancel() {
733+
log("game request result - success");
734+
sendResponse("", "cancelled", activeRequest);
735+
}
736+
public void onError(FacebookException error) {
737+
log("game request result - success");
738+
sendResponse("", "error", activeRequest);
739+
}
740+
});
741+
694742
JSONObject ready = new JSONObject();
695743
try { ready.put("status", "OK"); } catch (JSONException e) {}
696744
PluginManager.sendEvent("FacebookPluginReady", "FacebookPlugin", ready);
697745

698746
} catch (Exception e) {
699-
logger.log("{facebook} Exception on start:", e.getMessage());
747+
log("{facebook} Exception on start:", e.getMessage());
700748
}
701749
}
702750

android/manifest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
<activity android:name="com.facebook.FacebookActivity"
88
android:theme="@android:style/Theme.Translucent.NoTitleBar"
99
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
10-
android:label="@string/app_name" />
10+
android:label="@string/app_name" />
1111
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
1212
<meta-data android:name="com.facebook.sdk.ApplicationName" android:value="@string/app_name"/>
13+
14+
<provider
15+
android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
16+
android:name="com.facebook.FacebookContentProvider"
17+
android:exported="true"/>
1318
<!--END_PLUGINS_APPLICATION-->

android/manifest.xsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
<activity android:name="com.facebook.LoginActivity"
2828
android:theme="@android:style/Theme.Translucent.NoTitleBar"
2929
android:label="{$facebook.facebookDisplayName}" />
30+
</xsl:template>
31+
32+
<xsl:template match="provider[@android:name='com.facebook.FacebookContentProvider']">
33+
<provider
34+
android:authorities="com.facebook.app.FacebookContentProvider{$facebook.facebookAppID}"
35+
android:name="com.facebook.FacebookContentProvider"
36+
android:exported="true"/>
3037
</xsl:template>
3138

3239
<xsl:template match="@*|node()">

0 commit comments

Comments
 (0)