Android Open Source - ChitChat Contacts Fragment






From Project

Back to project page ChitChat.

License

The source code is released under:

MIT License

If you think the Android project ChitChat 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.shivamb7.chitchat.fragments;
/* www  . ja va2 s .  c o  m*/
import java.util.List;

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

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import com.shivamb7.chitchat.R;
import com.shivamb7.chitchat.adapters.FriendGridAdapter;

public class ContactsFragment extends Fragment {

  List<ParseUser> pfriends;
  ParseUser currentUser;
  ParseRelation<ParseUser> mFriendRelation;
  GridView mFriendGrid;
  TextView mEmptyText;
  ImageView mEmptyImage;
  static int numberofFriends;

  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_friends, container,
        false);
    mFriendGrid = (GridView) rootView.findViewById(R.id.friends_grid);
    mEmptyText = (TextView) rootView.findViewById(R.id.empty_state_text);
    mEmptyImage = (ImageView) rootView.findViewById(R.id.empty_state_image);
    return rootView;
  }

  @Override
  public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    getActivity().setProgressBarIndeterminateVisibility(true);
    currentUser = ParseUser.getCurrentUser();
    mFriendRelation = currentUser.getRelation("friendRelation");
    mFriendRelation.getQuery().findInBackground(
        new FindCallback<ParseUser>() {

          @Override
          public void done(List<ParseUser> friends, ParseException e) {
            getActivity().setProgressBarIndeterminateVisibility(false);
            // TODO Auto-generated method stub
            if (e == null) {
              pfriends = friends;
              String[] usernames = new String[pfriends.size()];
              int i = 0;
              for (ParseUser user : pfriends) {
                usernames[i] = user.getUsername();
                i++;
                numberofFriends++;
              }
              if (usernames.length == 0) {
                mEmptyImage.setVisibility(View.VISIBLE);
                mEmptyText.setVisibility(View.VISIBLE);
                mFriendGrid.setVisibility(View.GONE);
              } else {
                //numberofFriends = usernames.length;
                mEmptyImage.setVisibility(View.GONE);
                mEmptyText.setVisibility(View.GONE);
                mFriendGrid.setVisibility(View.VISIBLE);
                /*ArrayAdapter<String> mAdapter = new ArrayAdapter<>(
                    getActivity(),
                    android.R.layout.simple_list_item_1,
                    usernames);*/
                if(mFriendGrid.getAdapter() == null)
                {
                FriendGridAdapter mAdapter = new FriendGridAdapter(getActivity(), pfriends);
                mFriendGrid.setAdapter(mAdapter);
                }
                else
                {
                  ((FriendGridAdapter)(mFriendGrid.getAdapter())).refreshAdapter(pfriends);
                }
              }
            } else {

              AlertDialog.Builder builder = new AlertDialog.Builder(
                  getActivity());
              builder.setMessage(R.string.friend_error);
              builder.setTitle(R.string.signup_error_title);
              builder.setPositiveButton(android.R.string.ok, null);
              AlertDialog dialog = builder.create();
              dialog.show();
            }
          }
        });

  }

}




Java Source Code List

com.pkmmte.circularimageview.CircularImageView.java
com.shivamb7.chitchat.AddFriendsActivity.java
com.shivamb7.chitchat.ChatsActivity.java
com.shivamb7.chitchat.ComposeTextActivity.java
com.shivamb7.chitchat.ImageMessageActivity.java
com.shivamb7.chitchat.MainActivity.java
com.shivamb7.chitchat.ProfileActivity.java
com.shivamb7.chitchat.RecipientsActivity.java
com.shivamb7.chitchat.RegisterActivity2.java
com.shivamb7.chitchat.RegisterActivity.java
com.shivamb7.chitchat.adapters.ChatsAdapter.java
com.shivamb7.chitchat.adapters.FriendGridAdapter.java
com.shivamb7.chitchat.adapters.LevelAdapter.java
com.shivamb7.chitchat.fragments.ChatsFragment.java
com.shivamb7.chitchat.fragments.ContactsFragment.java
com.shivamb7.chitchat.fragments.ProfileFragment.java
com.shivamb7.chitchat.workers.ChitChatApplication.java
com.shivamb7.chitchat.workers.CircularImageView.java
com.shivamb7.chitchat.workers.Constants.java
com.shivamb7.chitchat.workers.Fab.java
com.shivamb7.chitchat.workers.FileHelper.java
com.shivamb7.chitchat.workers.ImageResizer.java
com.shivamb7.chitchat.workers.Level.java
com.shivamb7.chitchat.workers.RippleView.java
com.shivamb7.chitchat.workers.TypefaceSpan.java