Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
compileSdkVersion 21
buildToolsVersion '21.1.2'

defaultConfig {
applicationId "com.github.gorbin.asnetutorial"
minSdkVersion 10
targetSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.github.asne:asne-facebook:0.3.1'
compile 'com.github.asne:asne-linkedin:0.3.1'
compile 'com.github.asne:asne-twitter:0.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import com.github.gorbin.asne.core.listener.OnRequestGetFriendsCompleteListener;
import com.github.gorbin.asne.core.persons.SocialPerson;

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

public class FriendsFragment extends Fragment implements OnRequestGetFriendsCompleteListener {

private static final String NETWORK_ID = "NETWORK_ID";
private ListView listView;

public static FriendsFragment newInstannce(int id) {
public static FriendsFragment newInstance(int id) {
FriendsFragment fragment = new FriendsFragment();
Bundle args = new Bundle();
args.putInt(NETWORK_ID, id);
Expand All @@ -37,23 +37,26 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
int networkId = getArguments().containsKey(NETWORK_ID) ? getArguments().getInt(NETWORK_ID) : 0;

View rootView = inflater.inflate(R.layout.friends_list_fragment, container, false);
listView = (ListView) rootView.findViewById(R.id.list);
listView = (ListView) rootView.findViewById(android.R.id.list);

MainActivity.showProgress(getText(R.string.loading_friends));

SocialNetwork socialNetwork = MainFragment.mSocialNetworkManager.getSocialNetwork(networkId);
socialNetwork.setOnRequestGetFriendsCompleteListener(this);
socialNetwork.requestGetFriends();
MainActivity.showProgress("Loading friends");

return rootView;
}

@Override
public void OnGetFriendsIdComplete(int id, String[] friendsID) {
((MainActivity)getActivity()).getSupportActionBar().setTitle(friendsID.length + " Friends");
public void onGetFriendsIdComplete(int id, String[] friendsID) {
int friendsCount = friendsID.length;
String title = getResources().getQuantityString(R.plurals.friends, friendsCount, friendsCount);
((MainActivity) getActivity()).getSupportActionBar().setTitle(title);
}

@Override
public void OnGetFriendsComplete(int networkID, ArrayList<SocialPerson> socialPersons) {
public void onGetFriendsComplete(int networkID, List<SocialPerson> socialPersons) {
MainActivity.hideProgress();
FriendsListAdapter adapter = new FriendsListAdapter(getActivity(), socialPersons, networkID);
listView.setAdapter(adapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
import com.github.gorbin.asne.twitter.TwitterSocialNetwork;
import com.squareup.picasso.Picasso;

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

public class FriendsListAdapter extends BaseAdapter {
private final Activity context;
private ViewHolder holder;
private ArrayList<SocialPerson> friends;
private List<SocialPerson> friends;
private int networkId;
private int image;

public FriendsListAdapter(Activity context, ArrayList<SocialPerson> friends, int socialNetworkID) {
public FriendsListAdapter(Activity context, List<SocialPerson> friends, int socialNetworkID) {
this.context = context;
this.friends = friends;
this.networkId = socialNetworkID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

Expand All @@ -15,6 +15,7 @@ public class MainActivity extends ActionBarActivity implements FragmentManager.O
public static final String SOCIAL_NETWORK_TAG = "SocialIntegrationMain.SOCIAL_NETWORK_TAG";
private static ProgressDialog pd;
static Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -59,7 +60,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

protected static void showProgress(String message) {
protected static void showProgress(CharSequence message) {
pd = new ProgressDialog(context);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setMessage(message);
Expand All @@ -69,6 +70,7 @@ protected static void showProgress(String message) {
}

protected static void hideProgress() {
if (pd != null)
pd.dismiss();
}

Expand Down
55 changes: 27 additions & 28 deletions app/src/main/java/com/github/gorbin/asnetutorial/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.github.gorbin.asne.linkedin.LinkedInSocialNetwork;
import com.github.gorbin.asne.twitter.TwitterSocialNetwork;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -44,28 +43,27 @@ public MainFragment() {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.main_fragment, container, false);
((MainActivity)getActivity()).getSupportActionBar().setTitle(R.string.app_name);
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.app_name);
// init buttons and set Listener
facebook = (Button) rootView.findViewById(R.id.facebook);
facebook.setOnClickListener(loginClick);
facebook.setOnClickListener(mLoginClick);
twitter = (Button) rootView.findViewById(R.id.twitter);
twitter.setOnClickListener(loginClick);
twitter.setOnClickListener(mLoginClick);
linkedin = (Button) rootView.findViewById(R.id.linkedin);
linkedin.setOnClickListener(loginClick);
linkedin.setOnClickListener(mLoginClick);
googleplus = (Button) rootView.findViewById(R.id.googleplus);
googleplus.setOnClickListener(loginClick);
googleplus.setOnClickListener(mLoginClick);

//Get Keys for initiate SocialNetworks
String TWITTER_CONSUMER_KEY = getActivity().getString(R.string.twitter_consumer_key);
String TWITTER_CONSUMER_SECRET = getActivity().getString(R.string.twitter_consumer_secret);
String TWITTER_CONSUMER_KEY = getString(R.string.twitter_consumer_key);
String TWITTER_CONSUMER_SECRET = getString(R.string.twitter_consumer_secret);
String TWITTER_CALLBACK_URL = "oauth://ASNE";
String LINKEDIN_CONSUMER_KEY = getActivity().getString(R.string.linkedin_consumer_key);
String LINKEDIN_CONSUMER_SECRET = getActivity().getString(R.string.linkedin_consumer_secret);
String LINKEDIN_CONSUMER_KEY = getString(R.string.linkedin_consumer_key);
String LINKEDIN_CONSUMER_SECRET = getString(R.string.linkedin_consumer_secret);
String LINKEDIN_CALLBACK_URL = "https://asneTutorial";

//Chose permissions
ArrayList<String> fbScope = new ArrayList<String>();
fbScope.addAll(Arrays.asList("public_profile, email, user_friends"));
List<String> fbScope = Arrays.asList("public_profile, email, user_friends");
String linkedInScope = "r_basicprofile+r_fullprofile+rw_nus+r_network+w_messages+r_emailaddress+r_contactinfo";

//Use manager to manage SocialNetworks
Expand Down Expand Up @@ -96,7 +94,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mSocialNetworkManager.setOnInitializationCompleteListener(this);
} else {
//if manager exist - get and setup login only for initialized SocialNetworks
if(!mSocialNetworkManager.getInitializedSocialNetworks().isEmpty()) {
if (!mSocialNetworkManager.getInitializedSocialNetworks().isEmpty()) {
List<SocialNetwork> socialNetworks = mSocialNetworkManager.getInitializedSocialNetworks();
for (SocialNetwork socialNetwork : socialNetworks) {
socialNetwork.setOnLoginCompleteListener(this);
Expand All @@ -107,24 +105,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return rootView;
}

private void initSocialNetwork(SocialNetwork socialNetwork){
if(socialNetwork.isConnected()){
switch (socialNetwork.getID()){
private void initSocialNetwork(SocialNetwork socialNetwork) {
if (socialNetwork.isConnected()) {
switch (socialNetwork.getID()) {
case FacebookSocialNetwork.ID:
facebook.setText("Show Facebook profile");
facebook.setText(R.string.facebook_show);
break;
case TwitterSocialNetwork.ID:
twitter.setText("Show Twitter profile");
twitter.setText(R.string.twitter_show);
break;
case LinkedInSocialNetwork.ID:
linkedin.setText("Show LinkedIn profile");
linkedin.setText(R.string.linkedin_show);
break;
case GooglePlusSocialNetwork.ID:
googleplus.setText("Show GooglePlus profile");
googleplus.setText(R.string.gplus_show);
break;
}
}
}

@Override
public void onSocialNetworkManagerInitialized() {
//when init SocialNetworks - get and setup login only for initialized SocialNetworks
Expand All @@ -136,11 +135,11 @@ public void onSocialNetworkManagerInitialized() {

//Login listener

private View.OnClickListener loginClick = new View.OnClickListener() {
private View.OnClickListener mLoginClick = new View.OnClickListener() {
@Override
public void onClick(View view) {
int networkId = 0;
switch (view.getId()){
switch (view.getId()) {
case R.id.facebook:
networkId = FacebookSocialNetwork.ID;
break;
Expand All @@ -155,10 +154,10 @@ public void onClick(View view) {
break;
}
SocialNetwork socialNetwork = mSocialNetworkManager.getSocialNetwork(networkId);
if(!socialNetwork.isConnected()) {
if(networkId != 0) {
socialNetwork.requestLogin();
MainActivity.showProgress("Loading social person");
if (!socialNetwork.isConnected()) {
if (networkId != 0) {
MainActivity.showProgress(getText(R.string.loading_person));
socialNetwork.requestLogin(MainFragment.this);
} else {
Toast.makeText(getActivity(), "Wrong networkId", Toast.LENGTH_LONG).show();
}
Expand All @@ -180,8 +179,8 @@ public void onError(int networkId, String requestID, String errorMessage, Object
Toast.makeText(getActivity(), "ERROR: " + errorMessage, Toast.LENGTH_LONG).show();
}

private void startProfile(int networkId){
ProfileFragment profile = ProfileFragment.newInstannce(networkId);
private void startProfile(int networkId) {
ProfileFragment profile = ProfileFragment.newInstance(networkId);
getActivity().getSupportFragmentManager().beginTransaction()
.addToBackStack("profile")
.replace(R.id.container, profile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -27,9 +28,6 @@
import com.squareup.picasso.Picasso;

public class ProfileFragment extends Fragment implements OnRequestSocialPersonCompleteListener {
private String message = "Need simple social networks integration? Check this lbrary:";
private String link = "https://github.com/gorbin/ASNE";

private static final String NETWORK_ID = "NETWORK_ID";
private SocialNetwork socialNetwork;
private int networkId;
Expand All @@ -41,7 +39,7 @@ public class ProfileFragment extends Fragment implements OnRequestSocialPersonCo
private Button share;
private RelativeLayout frame;

public static ProfileFragment newInstannce(int id) {
public static ProfileFragment newInstance(int id) {
ProfileFragment fragment = new ProfileFragment();
Bundle args = new Bundle();
args.putInt(NETWORK_ID, id);
Expand All @@ -57,7 +55,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
networkId = getArguments().containsKey(NETWORK_ID) ? getArguments().getInt(NETWORK_ID) : 0;
((MainActivity)getActivity()).getSupportActionBar().setTitle("Profile");
((MainActivity) getActivity()).getSupportActionBar().setTitle("Profile");

MainActivity.showProgress(getText(R.string.loading_person));

View rootView = inflater.inflate(R.layout.profile_fragment, container, false);

Expand All @@ -74,9 +74,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

socialNetwork = MainFragment.mSocialNetworkManager.getSocialNetwork(networkId);
socialNetwork.setOnRequestCurrentPersonCompleteListener(this);
socialNetwork.requestCurrentPerson();
socialNetwork.requestCurrentPerson(this);

MainActivity.showProgress("Loading social person");
return rootView;
}

Expand Down Expand Up @@ -104,12 +103,14 @@ public void onRequestSocialPersonSuccess(int i, SocialPerson socialPerson) {
name.setText(socialPerson.name);
id.setText(socialPerson.id);
String socialPersonString = socialPerson.toString();
String infoString = socialPersonString.substring(socialPersonString.indexOf("{")+1, socialPersonString.lastIndexOf("}"));
String infoString = socialPersonString.substring(socialPersonString.indexOf("{") + 1, socialPersonString.lastIndexOf("}"));
info.setText(infoString.replace(", ", "\n"));
if (!TextUtils.isEmpty(socialPerson.avatarURL)) {
Picasso.with(getActivity())
.load(socialPerson.avatarURL)
.into(photo);
}
}

@Override
public void onError(int networkId, String requestID, String errorMessage, Object data) {
Expand All @@ -120,7 +121,7 @@ public void onError(int networkId, String requestID, String errorMessage, Object
private View.OnClickListener friendsClick = new View.OnClickListener() {
@Override
public void onClick(View view) {
FriendsFragment friends = FriendsFragment.newInstannce(networkId);
FriendsFragment friends = FriendsFragment.newInstance(networkId);
getActivity().getSupportFragmentManager().beginTransaction()
.addToBackStack("friends")
.replace(R.id.container, friends)
Expand All @@ -131,20 +132,21 @@ public void onClick(View view) {
private View.OnClickListener shareClick = new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder ad = alertDialogInit("Would you like to post Link:", link);
ad.setPositiveButton("Post link", new DialogInterface.OnClickListener() {
final String link = getString(R.string.share_link);
AlertDialog.Builder ad = alertDialogInit(getString(R.string.share_title), link);
ad.setPositiveButton(R.string.share_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Bundle postParams = new Bundle();
postParams.putString(SocialNetwork.BUNDLE_NAME, "Simple and easy way to add social networks for android application");
postParams.putString(SocialNetwork.BUNDLE_LINK, link);
if(networkId == GooglePlusSocialNetwork.ID) {
if (networkId == GooglePlusSocialNetwork.ID) {
socialNetwork.requestPostDialog(postParams, postingComplete);
} else {
socialNetwork.requestPostLink(postParams, message, postingComplete);
socialNetwork.requestPostLink(postParams, getString(R.string.share_message), postingComplete);
}
}
});
ad.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
ad.setNegativeButton(R.string.share_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.cancel();
Expand All @@ -162,7 +164,7 @@ public void onCancel(DialogInterface dialog) {
private OnPostingCompleteListener postingComplete = new OnPostingCompleteListener() {
@Override
public void onPostSuccessfully(int socialNetworkID) {
Toast.makeText(getActivity(), "Sent", Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), getText(R.string.sent), Toast.LENGTH_LONG).show();
}

@Override
Expand All @@ -171,7 +173,7 @@ public void onError(int socialNetworkID, String requestID, String errorMessage,
}
};

private void colorProfile(int networkId){
private void colorProfile(int networkId) {
int color = getResources().getColor(R.color.dark);
int image = R.drawable.user;
switch (networkId) {
Expand Down Expand Up @@ -200,7 +202,7 @@ private void colorProfile(int networkId){
photo.setImageResource(image);
}

private AlertDialog.Builder alertDialogInit(String title, String message){
private AlertDialog.Builder alertDialogInit(String title, String message) {
AlertDialog.Builder ad = new AlertDialog.Builder(getActivity());
ad.setTitle(title);
ad.setMessage(message);
Expand Down
Binary file added app/src/main/res/drawable/g_plus_user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading