diff --git a/TravelPost/.classpath b/TravelPost/.classpath
index 268bc78..fee4f71 100644
--- a/TravelPost/.classpath
+++ b/TravelPost/.classpath
@@ -9,7 +9,7 @@
-
+
diff --git a/TravelPost/src/com/TwentyCodes/android/Facebook/FacebookAuth.java b/TravelPost/src/com/TwentyCodes/android/Facebook/FacebookAuth.java
index 17cc19f..7c63a77 100644
--- a/TravelPost/src/com/TwentyCodes/android/Facebook/FacebookAuth.java
+++ b/TravelPost/src/com/TwentyCodes/android/Facebook/FacebookAuth.java
@@ -72,7 +72,7 @@ public class FacebookAuth {
* @author warren
*/
- public void authorize() {
+ public void authorize() throws NullPointerException {
if (!mFb.isSessionValid()) {
mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener());
}
@@ -252,4 +252,12 @@ public class FacebookAuth {
Log.i(TAG, "WallPostRequestListener.post successful");
}
}
+
+ /**
+ * @return true if the session is valid
+ * @author ricky barrette
+ */
+ public boolean isSessionValid() {
+ return mFb.isSessionValid();
+ }
}
diff --git a/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java b/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java
index 2ef6076..9ed5216 100644
--- a/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java
+++ b/TravelPost/src/com/TwentyCodes/android/TravelPost/LocationReceiver.java
@@ -6,9 +6,12 @@
*/
package com.TwentyCodes.android.TravelPost;
+import com.TwentyCodes.android.Facebook.FacebookAuth;
+import com.TwentyCodes.android.Facebook.SessionNotValidException;
import com.TwentyCodes.android.location.ReverseGeocoder;
import twitter4j.TwitterException;
+import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -77,11 +80,26 @@ public class LocationReceiver extends BroadcastReceiver{
// TODO check post size, is it greater than 140 chars?
// TODO Add more social services
+
+ //post to twitter
try {
Log.d(TravelPost.TAG, TwitterServices.tweet(mContext, thePost).toString());
} catch (TwitterException e) {
e.printStackTrace();
}
+
+ //post to facebook
+ FacebookAuth fbAuth = new FacebookAuth(mContext, new Activity());
+ fbAuth.authorize();
+ if(fbAuth.isSessionValid())
+ try {
+ fbAuth.postToWall(thePost);
+ } catch (SessionNotValidException e) {
+ e.printStackTrace();
+ }
+ else
+ Log.d(TravelPost.TAG, "cant post to FB, not auth'd");
+
}
/**
diff --git a/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java b/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java
index 15e9584..978f11f 100644
--- a/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java
+++ b/TravelPost/src/com/TwentyCodes/android/TravelPost/TravelPost.java
@@ -20,7 +20,6 @@ import android.util.Log;
import android.widget.RemoteViews;
import com.TwentyCodes.android.Facebook.FacebookAuth;
-import com.TwentyCodes.android.Facebook.SessionNotValidException;
import com.TwentyCodes.android.location.LocationService;
/**
@@ -95,10 +94,7 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
this.addPreferencesFromResource(R.xml.settings);
this.findPreference("twitter_sign_in").setOnPreferenceClickListener(this);
- this.findPreference("facebook_sign_in").setOnPreferenceClickListener(this);
-// mFbAuth = new FacebookAuth(this, this);
-// mFbAuth.authorize();
-
+ this.findPreference("facebook_sign_in").setOnPreferenceClickListener(this);
}
@Override
@@ -118,11 +114,13 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
e.printStackTrace();
}
} else if (preference.getKey().equals("facebook_sign_in")) {
- try {
- mFbAuth.postToWall("Another test");
- } catch (SessionNotValidException e) {
- e.printStackTrace();
- }
+ mFbAuth = new FacebookAuth(this, this);
+ mFbAuth.authorize();
+// try {
+// mFbAuth.postToWall("Another test");
+// } catch (SessionNotValidException e) {
+// e.printStackTrace();
+// }
Log.i(TAG, "onPreferenceClick.posted to wall");
}