Android Open Source - Test-SimpleTwitterClient Followers Fragment






From Project

Back to project page Test-SimpleTwitterClient.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project Test-SimpleTwitterClient 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.example.Twitter_Android.Fragments;
/*  w w w .j  av a2  s .c  om*/
import android.app.Activity;
import android.app.DialogFragment;
import android.app.LoaderManager;
import android.content.Intent;
import android.content.Loader;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import com.example.Twitter_Android.AppActivity.ConcreteUserTimelineActivity;
import com.example.Twitter_Android.Fragments.Adapters.FollowingsListAdapter;
import com.example.Twitter_Android.Fragments.Adapters.TimelineAdapter;
import com.example.Twitter_Android.Fragments.Dialogs.DirectMessageDialog;
import com.example.Twitter_Android.Loaders.FollowersLoader;
import com.example.Twitter_Android.Logic.Constants;
import com.example.Twitter_Android.Logic.DataCache;
import com.example.Twitter_Android.Logic.Person;
import com.example.Twitter_Android.Net.Connector;
import com.example.Twitter_Android.R;

import java.util.List;

public class FollowersFragment extends TimelineFragment<Person> {
  private final Connector connector;
  private TimelineAdapter<Person> currentAdapter;
  private static final FollowersFragment instance;
  private long nextCursor = -1;
  private static final int FOLLOWERS_LOADER = Constants.FOLLOWERS_LOADER_ID;
  public static final String TAG = "TAG_FOLLOWERS_FRAGMENT";
  private static final String ADAPTER_TAG = "FOLLOWERS_ADAPTER";

  static {
    instance = new FollowersFragment();
  }

  private FollowersFragment() {
    connector = new Connector();
    setRetainInstance(true);
    setHasOptionsMenu(true);
  }

  //------------------------------------------------------------------------------------------------------------------

  public static FollowersFragment getInstance() {
    return instance;
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (currentAdapter == null) {
      currentAdapter = (FollowingsListAdapter) DataCache.getInstance().getAdapter(ADAPTER_TAG);
      if (currentAdapter == null) {
        LoaderManager loaderManager = getLoaderManager();
        if (loaderManager != null) {
          loaderManager.initLoader(FOLLOWERS_LOADER, null, this);
        }
      } else {
        setListAdapter(currentAdapter);
      }
    }
    needNewestTweet = false;
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  protected void loadOldItems() {
    LoaderManager loaderManager = getLoaderManager();
    if (loaderManager != null) {
      loaderManager.restartLoader(FOLLOWERS_LOADER, null, this);
    }
  }

  //------------------------------------------------------------------------------------------------------------------

  @Override
  public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Person person = currentAdapter.getItem(position);
    Intent intent = new Intent(getActivity(), ConcreteUserTimelineActivity.class);
    intent.putExtra("PERSON_ID", person.getID());
    DataCache.getInstance().putPerson(person.getID(), person);
    startActivity(intent);
    return true;
  }

  //------------------------------------------------------------------------------------------------------------------

  @Override
  public Loader<List<Person>> onCreateLoader(int id, Bundle args) {
    if (id == FOLLOWERS_LOADER) {
      return new FollowersLoader(getActivity(), connector, nextCursor);
    }
    return null;
  }

  @Override
  public void onLoadFinished(Loader<List<Person>> loader, List<Person> data) {
    if (loader.getId() == FOLLOWERS_LOADER) {
      if (currentAdapter == null) {
        currentAdapter = new FollowingsListAdapter(getActivity(), data, ADAPTER_TAG);
        setListAdapter(currentAdapter);
        DataCache.getInstance().saveAdapter(ADAPTER_TAG, currentAdapter);
      } else {
        currentAdapter.addItemsToBottom(data);
      }
      nextCursor = connector.getCurrentCursor();
      isLoading = false;
      if (nextCursor == 0) {
        needOldTweet = false;
        isLoading = true;
      }
    }
  }

  @Override
  public void onLoaderReset(Loader<List<Person>> loader) {
//    setListAdapter(null);
  }
  //------------------------------------------------------------------------------------------------------------------


  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_followers, menu);
    super.onCreateOptionsMenu(menu, inflater);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.menu_item_send_message:
        sendDirectMessage();
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  private void sendDirectMessage() {
    Activity activity = getActivity();
    if (activity != null) {
      Person selectedPerson = getSelectedItem();
      DialogFragment dialog = DirectMessageDialog.getInstance(selectedPerson);
      dialog.show(activity.getFragmentManager().beginTransaction(), DirectMessageDialog.TAG);
    }
  }
  //------------------------------------------------------------------------------------------------------------------
}




Java Source Code List

com.example.Twitter_Android.AppActivity.ConcreteUserTimelineActivity.java
com.example.Twitter_Android.AppActivity.MainActivity.java
com.example.Twitter_Android.AppActivity.MessagesActivity.java
com.example.Twitter_Android.AppActivity.SearchableActivity.java
com.example.Twitter_Android.AppActivity.SettingsActivity.java
com.example.Twitter_Android.AsynkTasks.ImageDownloader.java
com.example.Twitter_Android.AsynkTasks.TaskDeleteTweet.java
com.example.Twitter_Android.AsynkTasks.TaskFollow.java
com.example.Twitter_Android.AsynkTasks.TaskPostTweet.java
com.example.Twitter_Android.AsynkTasks.TaskReply.java
com.example.Twitter_Android.AsynkTasks.TaskRetweet.java
com.example.Twitter_Android.AsynkTasks.TaskSendMessage.java
com.example.Twitter_Android.AsynkTasks.TaskUnfollow.java
com.example.Twitter_Android.Fragments.ConcreteUserTimelineFragment.java
com.example.Twitter_Android.Fragments.ConnectedUserTimelineFragment.java
com.example.Twitter_Android.Fragments.FollowersFragment.java
com.example.Twitter_Android.Fragments.FollowingsFragment.java
com.example.Twitter_Android.Fragments.HomeTimelineFragment.java
com.example.Twitter_Android.Fragments.TimelineFragment.java
com.example.Twitter_Android.Fragments.UserInfoFragment.java
com.example.Twitter_Android.Fragments.Adapters.ConcreteUserTimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.FollowingsListAdapter.java
com.example.Twitter_Android.Fragments.Adapters.MessagesAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TweetAdapter.java
com.example.Twitter_Android.Fragments.Dialogs.DeleteTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.DirectMessageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ErrorDialog.java
com.example.Twitter_Android.Fragments.Dialogs.PostTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ReplyDialog.java
com.example.Twitter_Android.Fragments.Dialogs.RetweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ShowImageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.UserInfoDialog.java
com.example.Twitter_Android.Fragments.Preferences.SettingsFragment.java
com.example.Twitter_Android.Loaders.AsyncUserInfoLoader.java
com.example.Twitter_Android.Loaders.FollowersLoader.java
com.example.Twitter_Android.Loaders.FollowingsLoader.java
com.example.Twitter_Android.Loaders.HomeTimelineLoader.java
com.example.Twitter_Android.Loaders.MessageLoader.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedTweets.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedUsers.java
com.example.Twitter_Android.Loaders.TweetLoader.java
com.example.Twitter_Android.Loaders.UserTimelineLoader.java
com.example.Twitter_Android.Logic.AppDatabase.java
com.example.Twitter_Android.Logic.Constants.java
com.example.Twitter_Android.Logic.DataCache.java
com.example.Twitter_Android.Logic.FileWorker.java
com.example.Twitter_Android.Logic.Person.java
com.example.Twitter_Android.Logic.Tweet.java
com.example.Twitter_Android.Net.Connector.java
com.example.Twitter_Android.Net.Parser.java
com.mass.cmassive.CMassive.java