Created
July 20, 2015 23:30
-
-
Save franc014/254075a49d3ae7bffc68 to your computer and use it in GitHub Desktop.
DRY Ribbit App Tree House
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package co.jandrade.ribbit; | |
import android.content.Context; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.ProgressBar; | |
import com.parse.FindCallback; | |
import com.parse.ParseException; | |
import com.parse.ParseRelation; | |
import com.parse.ParseUser; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
/** | |
* Created by Juan Francisco Andrade on 7/14/15. | |
*/ | |
public class FriendsChooser { | |
private static final String TAG = FriendsChooser.class.getSimpleName(); | |
private List<ParseUser> mFriends; | |
private ParseRelation<ParseUser> mFriendsRelation; | |
private ParseUser mCurrentUser; | |
private Context mContext; | |
private ProgressBar mProgressBar; | |
public List<String> mUserNames; | |
private boolean mError; | |
public FriendsChooser(Context context, ProgressBar progressBar) { | |
mContext = context; | |
mProgressBar = progressBar; | |
} | |
public FriendsChooser() { | |
} | |
public boolean getError() { | |
return mError; | |
} | |
public void setError(boolean error) { | |
mError = error; | |
} | |
public List<String> getUserNames() { | |
return mUserNames; | |
} | |
public void setUserNames(List<String> userNames) { | |
mUserNames = userNames; | |
} | |
public Context getContext() { | |
return mContext; | |
} | |
public void setContext(Context context) { | |
mContext = context; | |
} | |
public void friends(){ | |
mCurrentUser = ParseUser.getCurrentUser(); | |
mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); | |
mProgressBar.setVisibility(View.VISIBLE); | |
mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() { | |
@Override | |
public void done(List<ParseUser> friends, ParseException e) { | |
mProgressBar.setVisibility(View.INVISIBLE); | |
if(e==null) { | |
mFriends = friends; | |
String[]usernames = new String[mFriends.size()]; | |
int i = 0; | |
for(ParseUser user : mFriends){ | |
usernames[i] = user.getUsername(); | |
i++; | |
} | |
setError(false); | |
setUserNames(new ArrayList<>(Arrays.asList(usernames))); | |
}else{ | |
setError(true); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment