Skip to content

Commit

Permalink
Merge remote-tracking branch 'teamOSC/signon'
Browse files Browse the repository at this point in the history
Conflicts:
	app/build.gradle
	app/src/main/java/in/tosc/studddin/externalapi/FacebookApi.java
	app/src/main/java/in/tosc/studddin/fragments/people/ViewPerson.java
  • Loading branch information
championswimmer committed Apr 26, 2015
2 parents ddb96de + 96b272d commit 84a3d25
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 140 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ android {
}
}

repositories {
mavenCentral()
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.parse.bolts:bolts-android:1.1.4'
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
//compile 'com.koushikdutta.ion:ion:2.0.5'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.facebook.fresco:fresco:0.4.0+'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:palette-v7:21.0.0'
Expand Down
Binary file removed app/libs/Parse-1.8.2.jar
Binary file not shown.
Binary file added app/libs/Parse-1.9.1.jar
Binary file not shown.
Binary file added app/libs/ParseFacebookUtilsV4-1.9.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</intent-filter>
</activity>
<activity
android:name="com.facebook.LoginActivity"
android:name="com.facebook.FacebookActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/in/tosc/studddin/ApplicationWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onCreate() {
Parse.initialize(this, "9nhyJ0OEkfqmGygl44OAYfdFdnapE27d9yj9UI5x", "7pJlc2KZgpFXZHwvoXwVeZUsEtiDoTrtjPM7EGBa");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseFacebookUtils.initialize(getResources().getString(R.string.facebook_app_id));
ParseFacebookUtils.initialize(this);
ParseTwitterUtils.initialize("FfUOeQ5OBuv0qOkdHbfXCrwdk", "xQmFnUSii54eS3iUrl0uIrxfeL4EfIdFc6iyoHUDgSIVGDbauD");
Fresco.initialize(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
//mDrawerListView.addFooterView(mDrawerLinearLayout);

mProfilePic = ((ParseCircularImageView) mDrawerLinearLayout.findViewById(R.id.nav_drawer_profile_pic));
mProfilePic.setPlaceholder(getResources().getDrawable(R.drawable.com_facebook_profile_default_icon));
mProfilePic.setPlaceholder(getResources().getDrawable(R.drawable.ic_launcher));
mProfilePic.setParseFile(ParseUser.getCurrentUser().getParseFile(ParseTables.Users.IMAGE));

mCoverPic = ((ParseImageView) mDrawerLinearLayout.findViewById(R.id.nav_drawer_cover_picture));
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/in/tosc/studddin/SignOnActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
{
fragment.onActivityResult(requestCode, resultCode,data);
}
ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
// ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}
}
118 changes: 36 additions & 82 deletions app/src/main/java/in/tosc/studddin/externalapi/FacebookApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import android.os.Bundle;
import android.util.Log;

import com.facebook.HttpMethod;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.model.GraphUser;
import com.facebook.AccessToken;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -26,39 +24,46 @@ public class FacebookApi {
public static final boolean INFO = ApplicationWrapper.LOG_INFO;
public static final String APP_ID = "903137443064438";
private static final String TAG = "FacebookApi";
public static String USER_ID = "";
public static Bundle FbDataBundle = new Bundle();
private static Session session;

public static void setSession(Session s) {
session = s;
}
public static String PROFILE_URL = "";
public static String COVER_URL = "";

public static void getFacebookData(final FbGotDataCallback fgdc) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser gu, Response response) {
if (gu != null) {
if (DEBUG) Log.d(TAG, "json = " + response.getGraphObject().getInnerJSONObject().toString());
JSONObject responseObject = response.getGraphObject().getInnerJSONObject();
USER_ID = gu.getId();
try {
FbDataBundle.putString(ParseTables.Users.EMAIL, responseObject.getString("email"));
FbDataBundle.putString(ParseTables.Users.NAME, gu.getName());
FbDataBundle.putString(ParseTables.Users.USERNAME, gu.getUsername());
FbDataBundle.putString(ParseTables.Users.CITY, "" + gu.getLocation().getLocation().getCity());
} catch (Exception e) {
// e.printStackTrace();

final Bundle b = new Bundle();
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
if (DEBUG) Log.d(TAG,"" +object.toString());
try {
if(!object.isNull("cover"))
b.putString(ParseTables.Users.COVER,object.getJSONObject("cover").getString("source"));
else
b.putString(ParseTables.Users.COVER, "");
String id = object.getString("id");
b.putString(ParseTables.Users.IMAGE,"https://graph.facebook.com/" + id + "/picture??width=300&&height=300");
b.putString(ParseTables.Users.NAME, object.getString("name"));
b.putString(ParseTables.Users.EMAIL, object.getString("email"));

fgdc.gotData(b);
} catch (JSONException e1) {
e1.printStackTrace();
}
}
FbDataBundle.putString(ParseTables.Users.DOB, gu.getBirthday());
fgdc.gotData(FbDataBundle);
}
}
}).executeAsync();
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,id,cover,email,birthday");
request.setParameters(parameters);
request.executeAsync();
return;
}

public static void getFacebookUserEvents(final FbGotEventDataCallback fgedc) {
/*
Bundle bundle = new Bundle();
bundle.putString("fields", "description,start_time,owner,name,cover");
Request r = new Request(session, "/me/events", bundle,
Expand All @@ -73,58 +78,7 @@ public void onCompleted(Response response) {
}
}
});
r.executeAsync();
}

public static void getProfilePicture(final FbGotProfilePictureCallback listener) {
if (DEBUG) Log.d(TAG, "getting profile picture");
Bundle bundle = new Bundle();
bundle.putString("fields", "picture");
new Request(session, "me", bundle,
HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(final Response response) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
String objectId = response.getGraphObject().getInnerJSONObject().getString("id");
String sUrl = "https://graph.facebook.com/" + objectId + "/picture??width=300&&height=300";
Bitmap bitmap = Utilities.downloadBitmap(sUrl);
listener.gotProfilePicture(bitmap);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
}).executeAsync();
}

public static void getCoverPicture(final FbGotCoverPictureCallback listener) {
if (DEBUG) Log.d(TAG, "getting cover picture");
Bundle bundle = new Bundle();
bundle.putString("fields", "cover");
new Request(session, "me", bundle,
HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(final Response response) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
String sUrl = response.getGraphObject().getInnerJSONObject().getJSONObject("cover").getString("source");
Bitmap bitmap = Utilities.downloadBitmap(sUrl);
listener.gotCoverPicture(bitmap);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
}).executeAsync();
r.executeAsync();*/
}

public interface FbGotDataCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.model.GraphUser;
import com.parse.Parse;
import com.parse.ParseFacebookUtils;
import com.parse.ParseTwitterUtils;

Expand Down Expand Up @@ -80,11 +77,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

if (susername.contains("@")) {
mail.setVisibility(View.VISIBLE);
}
if (makeMeRequest(ParseFacebookUtils.getSession())) {
}/*
if(makeMeRequest(ParseFacebookUtils.getSession())){
facebook.setVisibility(View.VISIBLE);
}
if (ParseTwitterUtils.getTwitter().getUserId() != null) {
}*/
if(ParseTwitterUtils.getTwitter().getUserId()!=null){
twitter.setVisibility(View.VISIBLE);
}

Expand Down Expand Up @@ -165,7 +162,7 @@ public void onClick(View v) {

}


/*
private boolean makeMeRequest(final Session session) {
Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
Expand All @@ -187,5 +184,5 @@ public void onCompleted(GraphUser user, Response response) {
request.executeAsync();
return false;
}

}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package in.tosc.studddin.fragments.signon;

import android.graphics.Bitmap;
import android.util.Log;

import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseUser;

import java.io.ByteArrayOutputStream;

import in.tosc.studddin.externalapi.ParseTables;

/**
* Created by omerjerk on 26/4/15.
*/
public class FetchUserPhotos extends Thread {

private PhotosFetcher photosFetcher;

private static final String TAG = "FetchUserPhotos";

public FetchUserPhotos(PhotosFetcher pf) {
photosFetcher = pf;
}

public interface PhotosFetcher {
public Bitmap downloadCoverPhoto();
public Bitmap downloadProfilePhoto();
}

@Override
public void run() {
try {
Log.d(TAG, "starting download pictures thread");
ParseUser currentUser = ParseUser.getCurrentUser();

Bitmap coverPhoto = photosFetcher.downloadCoverPhoto();
Log.d(TAG, "Downloaded cover photo");
Bitmap profilePhoto = photosFetcher.downloadProfilePhoto();
Log.d(TAG, "downloaded profile photo");

// Compress image to lower quality scale 1 - 100
if (coverPhoto != null) {
ByteArrayOutputStream profilePhotoStream = new ByteArrayOutputStream();
coverPhoto.compress(Bitmap.CompressFormat.PNG, 100, profilePhotoStream);
byte[] profilePhotoBytes = profilePhotoStream.toByteArray();
ParseFile profilePhotoFile = new ParseFile("profilePicture.png", profilePhotoBytes);
profilePhotoFile.save();
currentUser.put(ParseTables.Users.IMAGE, profilePhotoFile);
}

if (profilePhoto != null) {
ByteArrayOutputStream coverPhotoStream = new ByteArrayOutputStream();
profilePhoto.compress(Bitmap.CompressFormat.PNG, 100, coverPhotoStream);
byte[] coverPhotoBytes = coverPhotoStream.toByteArray();
ParseFile coverPhotoFile = new ParseFile("coverPicture.png", coverPhotoBytes);
coverPhotoFile.save();
currentUser.put(ParseTables.Users.COVER, coverPhotoFile);
}

currentUser.save();
Log.d(TAG, "Done with everything");
} catch (ParseException e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit 84a3d25

Please sign in to comment.