Android Open Source - ribbit Friends Fragment






From Project

Back to project page ribbit.

License

The source code is released under:

MIT License

If you think the Android project ribbit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lleshiart.ribbit;
//from w w  w  . java 2 s  . c om
import java.util.List;

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;

public class FriendsFragment extends ListFragment {
  
  public static final String TAG = FriendsFragment.class.getSimpleName();
  
  protected List<ParseUser> mFriends;
  protected ParseRelation<ParseUser> mFriendsRelation;
  protected ParseUser mCurrentUser;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_friends, container,
        false);
    
    return rootView;
  }
  
  @Override
  public void onResume() {
    super.onResume();
    
    mCurrentUser = ParseUser.getCurrentUser();
    mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
    
    getActivity().setProgressBarIndeterminateVisibility(true);
    
    ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
    query.addAscendingOrder(ParseConstants.KEY_USERNAME);
    query.findInBackground(new FindCallback<ParseUser>() {

      @Override
      public void done(List<ParseUser> friends, ParseException e) {
        getActivity().setProgressBarIndeterminateVisibility(false);
        if (e == null) {
        mFriends = friends;
        
        String[] usernames = new String[mFriends.size()];
        int i = 0;
        for(ParseUser user : mFriends) {
          usernames[i] = user.getUsername();
          i++;
        }
        
        ArrayAdapter<String> adapter = new ArrayAdapter<>(
            getListView().getContext(), 
            android.R.layout.simple_list_item_1, 
            usernames);
        setListAdapter(adapter);
        }
        else {
          Log.e(TAG, e.getMessage());
          AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());
          builder.setMessage(e.getMessage())
            .setTitle(R.string.error_title)
            .setPositiveButton(android.R.string.ok, null);
          AlertDialog dialog = builder.create();
          dialog.show();
        }
      }
    });
  }
  
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    
    // Username of the user that was clicked
    final String whichUser = (String) getListAdapter().getItem(position);
    // Find the user with the username
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo(ParseConstants.KEY_USERNAME, whichUser);
    query.getFirstInBackground(new GetCallback<ParseUser>() {

      @Override
      public void done(ParseUser user, ParseException e) {
        if (e == null) {
          // Get the additional fields to display
          String firstName = user.getString(ParseConstants.KEY_FIRST_NAME);
          String lastName = user.getString(ParseConstants.KEY_LAST_NAME);
          String website = user.getString(ParseConstants.KEY_WEBSITE);
          // Display the fields
          AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());
          builder.setTitle("User: " + whichUser)
               .setMessage("First name: " + firstName
                     +"\nLast Name: " + lastName
                     +"\nWebsite: " + website)
            .setPositiveButton(android.R.string.ok, null);
          AlertDialog dialog = builder.create();
          dialog.show();
        }
        else {
          Log.i(TAG, e.getMessage());
        }
      }
    });
  }
  
}




Java Source Code List

com.lleshiart.ribbit.EditFriendsActivity.java
com.lleshiart.ribbit.FileHelper.java
com.lleshiart.ribbit.ForgotPasswordActivity.java
com.lleshiart.ribbit.FriendsFragment.java
com.lleshiart.ribbit.ImageResizer.java
com.lleshiart.ribbit.InboxFragment.java
com.lleshiart.ribbit.LoginActivity.java
com.lleshiart.ribbit.MainActivity.java
com.lleshiart.ribbit.MessageAdapter.java
com.lleshiart.ribbit.NewMessageActivity.java
com.lleshiart.ribbit.ParseConstants.java
com.lleshiart.ribbit.RecipientsActivity.java
com.lleshiart.ribbit.SectionsPagerAdapter.java
com.lleshiart.ribbit.SignUpActivity.java
com.lleshiart.ribbit.ViewImageActivity.java