Skip to content

Commit

Permalink
Feature/facebook sdk 16 (#3731)
Browse files Browse the repository at this point in the history
* Removed AppInvite dialog code for migration to Facebook SDK 16.2.0

* Added support for Facebook SDK 16 in android gradle version.
Still WIP. For build to successed, it seams that gradle version >= 7.2 is required, which requires JDK 11.
But since we already needto update to gradle 8.1 for firebase support, we may want to simply skip that, and do what is required to get gradle 8.1
working as the new standard.

* Updated facebook and FCM support.
Both of these require gradle 8.1, which requires JDK 17, but builder still doesn't support JDK17 in general, so for android builds
we need to set JAVA17_HOME environment variable when performing Android local builds.

* isFriendsInviteSupported now returns false for facebook
  • Loading branch information
shannah authored Sep 9, 2023
1 parent 79f822b commit ae2afee
Show file tree
Hide file tree
Showing 2 changed files with 252 additions and 141 deletions.
68 changes: 2 additions & 66 deletions Ports/Android/src/com/codename1/social/FacebookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginManager;
import com.facebook.share.model.AppInviteContent;
import com.facebook.share.widget.AppInviteDialog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -71,10 +69,7 @@ public static void init() {
} catch (Exception e) {
//the pattern is not valid
}

}
FacebookSdk.sdkInitialize(AndroidNativeUtil.getContext().getApplicationContext());

}

@Override
Expand Down Expand Up @@ -200,71 +195,12 @@ public void inviteFriends(String appLinkUrl, String previewImageUrl) {

@Override
public void inviteFriends(String appLinkUrl, String previewImageUrl, final Callback cb) {
if (AndroidNativeUtil.getActivity() == null) {
throw new RuntimeException("Cannot invite friends while running in the background.");
}
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.build();
final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
if(cb == null){
AppInviteDialog.show(activity, content);
}else{
AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
final CallbackManager mCallbackManager = CallbackManager.Factory.create();
activity.setIntentResultListener(new IntentResultListener() {

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
activity.restoreIntentResultListener();
}
});
appInviteDialog.registerCallback(mCallbackManager, new FacebookCallback<AppInviteDialog.Result>() {
@Override
public void onSuccess(AppInviteDialog.Result result) {
Display.getInstance().callSerially(new Runnable() {

@Override
public void run() {
cb.onSucess(null);
}
});
}

@Override
public void onCancel() {
Display.getInstance().callSerially(new Runnable() {

@Override
public void run() {
cb.onError(null, null, -1, "User Cancelled");
}
});
}

@Override
public void onError(final FacebookException e) {
Display.getInstance().callSerially(new Runnable() {

@Override
public void run() {
cb.onError(null, e, 0, e.getMessage());
}
});
}
});
appInviteDialog.show(content);
}
}

throw new RuntimeException("The Facebook App Invite feature is no longer supported by the Facebook SDK. See https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/");
}

@Override
public boolean isInviteFriendsSupported() {
return true;
return false;
}

class FBCallback implements FacebookCallback {
Expand Down
Loading

0 comments on commit ae2afee

Please sign in to comment.