Skip to content

Commit

Permalink
Merge pull request #282 from m1ga/android_update
Browse files Browse the repository at this point in the history
feat(android) update to Facebook SDK 13.1.0, remove deprecated game request
  • Loading branch information
hansemannn committed Mar 25, 2022
2 parents 70277f6 + 35effd9 commit 6659700
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 169 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Expand Up @@ -6,5 +6,5 @@ buildscript {
}

dependencies {
implementation 'com.facebook.android:facebook-android-sdk:9.0.0'
implementation 'com.facebook.android:facebook-android-sdk:13.1.0'
}
2 changes: 1 addition & 1 deletion android/manifest
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 11.0.2
version: 11.1.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: facebook
Expand Down
115 changes: 1 addition & 114 deletions android/src/facebook/TiFacebookModule.java
Expand Up @@ -34,13 +34,9 @@
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.share.Sharer;
import com.facebook.share.model.GameRequestContent;
import com.facebook.share.model.GameRequestContent.ActionType;
import com.facebook.share.model.GameRequestContent.Filters;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.model.SharePhoto;
import com.facebook.share.model.SharePhotoContent;
import com.facebook.share.widget.GameRequestDialog;
import com.facebook.share.widget.ShareDialog;
import com.facebook.share.widget.ShareDialog.Mode;
import java.math.BigDecimal;
Expand Down Expand Up @@ -165,7 +161,7 @@ public class TiFacebookModule extends KrollModule implements OnActivityResultEve

private static TiFacebookModule module;
private static String[] permissions = new String[] {};
private LoginBehavior loginBehavior;
private LoginBehavior loginBehavior = LoginBehavior.NATIVE_WITH_FALLBACK;

private KrollFunction permissionCallback = null;

Expand Down Expand Up @@ -827,115 +823,6 @@ public void onSuccess(Sharer.Result results)
}
}

@Kroll.method
public void presentSendRequestDialog(@Kroll.argument(optional = true) final KrollDict args)
{
GameRequestDialog requestDialog = new GameRequestDialog(TiApplication.getInstance().getCurrentActivity());
requestDialog.registerCallback(callbackManager, new FacebookCallback<GameRequestDialog.Result>() {
KrollDict data = new KrollDict();
public void onSuccess(GameRequestDialog.Result result)
{
final String postId = result.getRequestId();
if (postId != null) {
data.put(PROPERTY_RESULT, postId);
}
data.put(PROPERTY_SUCCESS, true);
data.put(PROPERTY_CANCELLED, false);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}

public void onCancel()
{
data.put(PROPERTY_SUCCESS, false);
data.put(PROPERTY_CANCELLED, true);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}

public void onError(FacebookException error)
{
data.put(PROPERTY_SUCCESS, false);
data.put(PROPERTY_CANCELLED, false);
data.put(PROPERTY_ERROR, "Error sending Game Request");
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}
});

String title = (String) args.get("title");
String message = (String) args.get("message");
@SuppressWarnings("unchecked")
Map<String, String> data = (Map<String, String>) args.get("data");
String recipients = (String) args.get("recipients");
String suggestions = (String) args.get("recipientSuggestions");
String objectID = (String) args.get("objectID");

String to = (String) args.get("to");
if (to != null) {
Log.w(TAG, "Property `to` is deprecated. Please use `recipients`.");
}

int actionTypeChoice = args.optInt("actionType", TiFacebookModule.ACTION_TYPE_NONE);
ActionType actionType;
switch (actionTypeChoice) {
case TiFacebookModule.ACTION_TYPE_SEND:
actionType = ActionType.SEND;
break;
case TiFacebookModule.ACTION_TYPE_TURN:
actionType = ActionType.TURN;
break;
case TiFacebookModule.ACTION_TYPE_ASK_FOR:
actionType = ActionType.ASKFOR;
break;
default:
case TiFacebookModule.ACTION_TYPE_NONE:
actionType = null;
break;
}

int filtersChoice = args.optInt("filters", TiFacebookModule.FILTER_NONE);
Filters filters;
switch (filtersChoice) {
case TiFacebookModule.FILTER_APP_NON_USERS:
filters = Filters.APP_NON_USERS;
break;
case TiFacebookModule.FILTER_APP_USERS:
filters = Filters.APP_USERS;
break;
default:
case TiFacebookModule.FILTER_NONE:
filters = null;
break;
}

String dataString = null;
if (data != null) {
dataString = data.toString();
}

List<String> recipientsList = null;
if (recipients != null) {
String[] recipientsArray = recipients.split(",");
recipientsList = Arrays.asList(recipientsArray);
}

List<String> suggestionsList = null;
if (suggestions != null) {
String[] suggestionsArray = suggestions.split(",");
suggestionsList = Arrays.asList(suggestionsArray);
}

GameRequestContent content = new GameRequestContent.Builder()
.setTitle(title)
.setMessage(message)
.setData(dataString)
.setRecipients(recipientsList)
.setActionType(actionType)
.setObjectId(objectID)
.setFilters(filters)
.setSuggestions(suggestionsList)
.build();
requestDialog.show(content);
}

@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data)
{
Expand Down
47 changes: 0 additions & 47 deletions apidoc/Facebook.yml
Expand Up @@ -282,40 +282,6 @@ description: |
For details on the Share dialog, see the
[official Facebook Share Dialogs documentation](https://developers.facebook.com/docs/sharing/reference/share-dialog).
### Game Requests Dialog
To send a game request to a user, call the
[presentSendRequestDialog()](Modules.Facebook.presentSendRequestDialog) method and pass the
method a dictionary with the `message` property set the message you want to send the invited user.
Optional: You can set the `title` property with a title string. You can also set the `data` property
with a dictionary of custom parameters. If you want to preselect users to send invite to, you can set
the `to` property with string of values that are facebook ids seperated by comma.
To monitor if the request succeeded or not, listen to the <Modules.Facebook.requestDialogCompleted> event.
``` javascript
fb.addEventListener('requestDialogCompleted', function (e) {
if (e.success) {
Ti.API.info('request succeeded.');
} else {
Ti.API.warn('Failed to share.');
}
});
fb.presentSendRequestDialog({
message: 'Go to https://appcelerator.com/',
title: 'Invitation to Appcelerator',
recipients: ['123456789', '987654321'],
data: {
badge_of_awesomeness: '1',
social_karma: '5'
}
});
```
For details on game request dialogs see the
[official Facebook Request Dialogs documentation](https://developers.facebook.com/docs/games/services/gamerequests).
### Messenger Button
The Messenger button provides a quick mechanism for users to share content to the Facebook Messenger.
Expand Down Expand Up @@ -491,19 +457,6 @@ methods:
type: SharePhotoContentParams
since: "7.4.0"

- name: presentSendRequestDialog
summary: |
Opens an App Request dialog.
description: |
A `requestDialogCompleted` event is generated to indicate if the request attempt was successful or unsuccessful,
and the resultURL.
parameters:
- name: params
summary: |
A dictionary object containing parameters.
type: RequestDialogParams
since: "4.0.0"

- name: refreshPermissionsFromServer
summary: Makes a request to Facebook to get the latest permissions granted.
description: |
Expand Down
6 changes: 0 additions & 6 deletions test/unit/specs/module.spec.js
Expand Up @@ -408,12 +408,6 @@ describe('ti.facebook', () => {
});
});

describe('#presentSendRequestDialog(params)', () => {
it('is a function', () => {
expect(Facebook.presentSendRequestDialog).toEqual(jasmine.any(Function));
});
});

describe('#presentShareDialog(params)', () => {
it('is a function', () => {
expect(Facebook.presentShareDialog).toEqual(jasmine.any(Function));
Expand Down

0 comments on commit 6659700

Please sign in to comment.