Android Open Source - android_twitter_client User Timeline Fragment






From Project

Back to project page android_twitter_client.

License

The source code is released under:

GNU General Public License

If you think the Android project android_twitter_client 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.github.snambi.twitterclient.fragemets;
//from  w  ww .ja va  2 s  . co m
import java.util.List;

import org.json.JSONArray;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.activeandroid.util.Log;
import com.github.snambi.twitterclient.clients.TwitterRestClient.TweetsCounter;
import com.github.snambi.twitterclient.db.TweetDbHelper;
import com.github.snambi.twitterclient.listeners.EndlessScrollListener;
import com.github.snambi.twitterclient.models.Tweet;
import com.loopj.android.http.JsonHttpResponseHandler;

public class UserTimelineFragment extends TwitterListFragment {
  public static final String SCREEN_NAME="screen-name";

  protected TweetsCounter counter = new TweetsCounter();
  protected String screenName=null;
  
  public static UserTimelineFragment newInstance(String screenName ){
    UserTimelineFragment fragment = new UserTimelineFragment();
    if( screenName != null && !screenName.trim().equals("")){
      Bundle data = new Bundle();
      data.putString( SCREEN_NAME, screenName);
      fragment.setArguments(data);
    }
    return fragment;
  }
  
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
  }
  
  @Override
  public void onCreate(Bundle args) {
    super.onCreate(args);
    
    if(  getArguments() != null &&
        getArguments().getString(SCREEN_NAME) != null && 
        !getArguments().getString(SCREEN_NAME).trim().equals("") ){
      screenName = getArguments().getString(SCREEN_NAME).trim();
    }
    
    populateTimeline();
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    // attach the endless scrollview listener to the listview
    lvTweets.setOnScrollListener( new EndlessScrollListener() {
      
      @Override
      public void onLoadMore(int page, int totalItemsCount) {
        populateTimeline();
      }
    });

    return view;
  }
  
  private void populateTimeline() {
    client.getUserTimeline( screenName, counter, new JsonHttpResponseHandler(){
      
      @Override
      public void onFailure(Throwable t, String s) {
        Log.d( "debug", s, t);
      }
      
      @Override
      public void onSuccess(JSONArray jsonArray) {
        Log.d("debug", jsonArray.toString() );
        
        List<Tweet> tweets = Tweet.fromJSONArray(jsonArray);
                
        // these values are used for next iteration
        counter.setSinceIdMaxIdFrom(tweets);
        TweetDbHelper.saveWhenNotPresent(tweets);
        
        //aTweets.addAll( tweets );
        addTweets(tweets);
      }
    });    
  }
  
}




Java Source Code List

com.github.snambi.twitterclient.TwitterApplication.java
com.github.snambi.twitterclient.activities.ComposeActivity.java
com.github.snambi.twitterclient.activities.LoginActivity.java
com.github.snambi.twitterclient.activities.ProfileActivity.java
com.github.snambi.twitterclient.activities.TimelineActivity.java
com.github.snambi.twitterclient.adapters.TwitterArrayAdapter.java
com.github.snambi.twitterclient.clients.TwitterRestClient.java
com.github.snambi.twitterclient.db.TweetDbHelper.java
com.github.snambi.twitterclient.fragemets.HomeTimelineFragment.java
com.github.snambi.twitterclient.fragemets.MentionsTimelineFragment.java
com.github.snambi.twitterclient.fragemets.ProfileHeaderFragment.java
com.github.snambi.twitterclient.fragemets.TwitterListFragment.java
com.github.snambi.twitterclient.fragemets.UserTimelineFragment.java
com.github.snambi.twitterclient.listeners.EndlessScrollListener.java
com.github.snambi.twitterclient.listeners.FragmentTabListener.java
com.github.snambi.twitterclient.models.SampleModel.java
com.github.snambi.twitterclient.models.Tweet.java
com.github.snambi.twitterclient.models.User.java
com.github.snambi.twitterclient.utils.TwitterTimeUtils.java