Android Open Source - android-ribbit-design Friends Fragment






From Project

Back to project page android-ribbit-design.

License

The source code is released under:

MIT License

If you think the Android project android-ribbit-design 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.teamtreehouse.ribbit.ui;
//from w  ww .  j a v  a2  s  .c o  m
import java.util.List;

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import com.teamtreehouse.ribbit.R;
import com.teamtreehouse.ribbit.adapters.UserAdapter;
import com.teamtreehouse.ribbit.utils.ParseConstants;

public class FriendsFragment extends Fragment {
  
  public static final String TAG = FriendsFragment.class.getSimpleName();

  protected ParseRelation<ParseUser> mFriendsRelation;
  protected ParseUser mCurrentUser;  
  protected List<ParseUser> mFriends;
  protected GridView mGridView;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.user_grid,
        container, false);
    
    mGridView = (GridView)rootView.findViewById(R.id.friendsGrid);
    
    TextView emptyTextView = (TextView)rootView.findViewById(android.R.id.empty);
    mGridView.setEmptyView(emptyTextView);

    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++;
          }
          if (mGridView.getAdapter() == null) {
            UserAdapter adapter = new UserAdapter(getActivity(), mFriends);
            mGridView.setAdapter(adapter);
          }
          else {
            ((UserAdapter)mGridView.getAdapter()).refill(mFriends);
          }
        }
        else {
          Log.e(TAG, e.getMessage());
          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
          builder.setMessage(e.getMessage())
            .setTitle(R.string.error_title)
            .setPositiveButton(android.R.string.ok, null);
          AlertDialog dialog = builder.create();
          dialog.show();
        }
      }
    });
  }

}




Java Source Code List

com.teamtreehouse.ribbit.RibbitApplication.java
com.teamtreehouse.ribbit.adapters.MessageAdapter.java
com.teamtreehouse.ribbit.adapters.SectionsPagerAdapter.java
com.teamtreehouse.ribbit.adapters.UserAdapter.java
com.teamtreehouse.ribbit.ui.EditFriendsActivity.java
com.teamtreehouse.ribbit.ui.FriendsFragment.java
com.teamtreehouse.ribbit.ui.InboxFragment.java
com.teamtreehouse.ribbit.ui.LoginActivity.java
com.teamtreehouse.ribbit.ui.MainActivity.java
com.teamtreehouse.ribbit.ui.RecipientsActivity.java
com.teamtreehouse.ribbit.ui.SignUpActivity.java
com.teamtreehouse.ribbit.ui.ViewImageActivity.java
com.teamtreehouse.ribbit.utils.FileHelper.java
com.teamtreehouse.ribbit.utils.ImageResizer.java
com.teamtreehouse.ribbit.utils.MD5Util.java
com.teamtreehouse.ribbit.utils.ParseConstants.java