Skip to content

Commit

Permalink
ios-moe setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Pronold committed Jul 10, 2016
1 parent a68c4c5 commit 0a86837
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 1 deletion.
30 changes: 30 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ buildscript {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
maven { url uri(System.getenv("INTEL_MULTI_OS_ENGINE_HOME") + "/gradle") }
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0-SNAPSHOT'
classpath 'com.intel.gradle:moeGradlePlugin:1.1.0.final-1'
}
}

Expand Down Expand Up @@ -178,7 +180,35 @@ project(":ios") {
}


project(":ios-moe") {
apply plugin: 'java'
apply plugin: 'moe'


apply from: '../publish.gradle'

configurations {
custom
compile.extendsFrom custom
natives
}

eclipse {
project {
name = appName + "-ios-moe"
}
}

dependencies {

compile project(':core')

compile "com.badlogicgames.gdx:gdx-backend-moe:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"

compile "org.robovm:robopods-facebook-ios:$facebookRoboPodsVersion"
}
}



Expand Down
13 changes: 12 additions & 1 deletion core/src/de/tomgrill/gdxfacebook/core/ReflectionLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public static GDXFacebook load(GDXFacebookConfig config) {
}

if (Gdx.app.getType() == Application.ApplicationType.iOS) {
loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.ios.IOSFacebookLoader");
// tell robovm and moe apart
try {
loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.ios.IOSFacebookLoader");
} catch (ReflectionException e) {
loaderCls = ClassReflection.forName("de.tomgrill.gdxfacebook.ios.IOSMOEFacebookLoader");
}
}

if (loaderCls != null) {
Expand All @@ -52,6 +57,12 @@ public static GDXFacebook load(GDXFacebookConfig config) {
Gdx.app.error(GDXFacebookVars.LOG_TAG, "Error installing " + GDXFacebookVars.LOG_TAG + " for " + Gdx.app.getType() + "\n");
Gdx.app.error(GDXFacebookVars.LOG_TAG, "Did you add >> compile \"de.tomgrill.gdxfacebook:gdx-facebook-" + artifactByAppType(Gdx.app.getType()) + ":" + GDXFacebookVars.VERSION
+ "\" << to your gradle dependencies? View https://github.com/TomGrill/gdx-facebook/wiki for more information.\n");

if (Gdx.app.getType() == Application.ApplicationType.iOS) {
Gdx.app.error(GDXFacebookVars.LOG_TAG, "or in cas you use multi-os-engine >> compile \"de.tomgrill.gdxfacebook:gdx-facebook-ios-moe:" + GDXFacebookVars.VERSION
+ "\" <<\n");

}
}

return new FallbackGDXFacebook();
Expand Down
9 changes: 9 additions & 0 deletions ios-moe/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
targetCompatibility = 1.7
sourceCompatibility = 1.7

sourceSets.main.java.srcDirs = [ "src/" ]


ext {
ARTIFACTID = 'gdx-facebook-ios-moe'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright 2015 See AUTHORS file.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package de.tomgrill.gdxfacebook.iosmoe;

import de.tomgrill.gdxfacebook.core.GDXFacebookConfig;
import de.tomgrill.gdxfacebook.core.GDXFacebook;
import de.tomgrill.gdxfacebook.core.FacebookLoader;

public class IOSMOEFacebookLoader implements FacebookLoader {
@Override
public GDXFacebook load(GDXFacebookConfig config) {
return new IOSMOEGDXFacebook(config);
}
}
223 changes: 223 additions & 0 deletions ios-moe/src/de/tomgrill/gdxfacebook/iosmoe/IOSMOEGDXFacebook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/*******************************************************************************
* Copyright 2015 See AUTHORS file.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/


package de.tomgrill.gdxfacebook.iosmoe;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import de.tomgrill.gdxfacebook.core.*;
import org.robovm.apple.foundation.NSDictionary;
import org.robovm.apple.foundation.NSError;
import org.robovm.apple.foundation.NSObject;
import org.robovm.objc.block.VoidBlock2;
import org.robovm.pods.facebook.core.FBSDKAccessToken;
import org.robovm.pods.facebook.login.FBSDKLoginManager;
import org.robovm.pods.facebook.login.FBSDKLoginManagerLoginResult;
import org.robovm.pods.facebook.share.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class IOSMOEGDXFacebook extends GDXFacebookBasic {

private FBSDKLoginManager loginManager;
private SignInMode signInMode;

public IOSMOEGDXFacebook(GDXFacebookConfig config) {
super(config);

loginManager = new FBSDKLoginManager();
}

@Override
public void signIn(SignInMode mode, Array<String> permissions, GDXFacebookCallback<SignInResult> callback) {
this.callback = callback;
this.permissions = permissions;
this.signInMode = mode;

loadAccessToken();

if (accessToken == null && FBSDKAccessToken.getCurrentAccessToken() != null) {
accessToken = new GDXFacebookAccessToken(FBSDKAccessToken.getCurrentAccessToken().getTokenString(), FBSDKAccessToken.getCurrentAccessToken().getExpirationDate().toDate().getTime());
}


if (accessToken != null) {
startSilentSignIn();
} else {
startGUISignIn();
}
}

@Override
public void showGameRequest(GDXFacebookGameRequest request, final GDXFacebookCallback<GameRequestResult> gameRequestCallback) {
gameRequest(request, gameRequestCallback);
}

@Override
public void gameRequest(final GDXFacebookGameRequest request, final GDXFacebookCallback<GameRequestResult> gameRequestCallback) {
Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting Game Request dialog.");

FBSDKGameRequestContent gameRequestContent = new FBSDKGameRequestContent();


if (request.getMessage() != null) gameRequestContent.setMessage(request.getMessage());
if (request.getData() != null) gameRequestContent.setData(request.getData());
if (request.getTitle() != null) gameRequestContent.setTitle(request.getTitle());
if (request.getObjectId() != null) gameRequestContent.setObjectID(request.getObjectId());

Array<String> suggestions = request.getSuggestions();
if (suggestions != null && suggestions.size > 0) {
ArrayList<String> suggestionList = new ArrayList<String>();
for (int i = 0; i < suggestions.size; i++) {
suggestionList.add(suggestions.get(i));
}
gameRequestContent.setRecipientSuggestions(suggestionList);
}

Array<String> recipients = request.getRecipients();
if (recipients != null && recipients.size > 0) {
ArrayList<String> recipientsList = new ArrayList<String>();
for (int i = 0; i < recipients.size; i++) {
recipientsList.add(recipients.get(i));
}
gameRequestContent.setRecipients(recipientsList);
}


if (request.getActionType() != null) {
switch (request.getActionType()) {
case ASKFOR:
gameRequestContent.setActionType(FBSDKGameRequestActionType.AskFor);
break;
case SEND:
gameRequestContent.setActionType(FBSDKGameRequestActionType.Send);
break;
case TURN:
gameRequestContent.setActionType(FBSDKGameRequestActionType.Turn);
break;
}
}

if (request.getFilters() != null) {
switch (request.getFilters()) {
case APP_NON_USERS:
gameRequestContent.setFilters(FBSDKGameRequestFilter.AppNonUsers);
break;
case APP_USERS:
gameRequestContent.setFilters(FBSDKGameRequestFilter.AppUsers);
break;
}
}

FBSDKGameRequestDialog.show(gameRequestContent, new FBSDKGameRequestDialogDelegateAdapter() {
@Override
public void didComplete(FBSDKGameRequestDialog gameRequestDialog, NSDictionary<?, ?> results) {
Array<String> recipients = new Array<String>();

String requestId = "";

for (Map.Entry<? extends NSObject, ? extends NSObject> entry : results.entrySet()) {
String key = entry.getKey().toString();
String value = entry.getValue().toString();

if (key.equals("request")) {
requestId = value;
} else {
recipients.add(value);
}
}

Gdx.app.debug(GDXFacebookVars.LOG_TAG, "User finished Game Request dialog successful.");
gameRequestCallback.onSuccess(new GameRequestResult(requestId, recipients));
}

@Override
public void didFail(FBSDKGameRequestDialog gameRequestDialog, NSError error) {
Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Game Request finished with error: " + error.getLocalizedDescription());
gameRequestCallback.onError(new GDXFacebookError(error.getLocalizedDescription()));
}

@Override
public void didCancel(FBSDKGameRequestDialog gameRequestDialog) {
Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Game Request has been fail.");
gameRequestCallback.onCancel();
}
});
}

@Override
public void signOut(boolean keepSessionData) {
super.signOut(keepSessionData);
loginManager.logOut();

if (keepSessionData == SignOutMode.DELETE_SESSION_DATA) {
FBSDKAccessToken.setCurrentAccessToken(null);

deleteTokenData();
}
}

@Override
public boolean isLoaded() {
return true;
}

@Override
protected void startGUISignIn() {
Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting GUI sign in.");

VoidBlock2<FBSDKLoginManagerLoginResult, NSError> result = new VoidBlock2<FBSDKLoginManagerLoginResult, NSError>() {

@Override
public void invoke(FBSDKLoginManagerLoginResult loginResult, NSError nsError) {
if (nsError != null) {
signOut();
Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Error while trying to sign in: " + nsError.getLocalizedDescription());
callback.onError(new GDXFacebookError(nsError.getLocalizedDescription()));
} else if (loginResult.isCancelled()) {
Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Sign fail by user.");
signOut();
callback.onCancel();
} else {
accessToken = new GDXFacebookAccessToken(FBSDKAccessToken.getCurrentAccessToken().getTokenString(), FBSDKAccessToken.getCurrentAccessToken().getExpirationDate().toDate().getTime());
storeNewToken(accessToken);
Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Sign successful. User token: " + accessToken.getToken());
callback.onSuccess(new SignInResult(accessToken, "Sign in successful."));
}

}

};

List<String> listPermissions = new ArrayList<String>();

for (int i = 0; i < permissions.size; i++) {
listPermissions.add(permissions.get(i));
}

if (this.signInMode == SignInMode.PUBLISH) {
loginManager.logInWithPublishPermissions(listPermissions, result);
} else {
loginManager.logInWithReadPermissions(listPermissions, result);
}


}

}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ include ':core'
include ':desktop'
include ':html'
include ':ios'
include ':ios-moe'

0 comments on commit 0a86837

Please sign in to comment.