Android Open Source - android_twitter_client Tweet Db Helper






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.db;
/*from   w  w w.j  ava  2s.c o m*/
import java.util.List;

import com.activeandroid.ActiveAndroid;
import com.activeandroid.query.From;
import com.activeandroid.query.Select;
import com.github.snambi.twitterclient.models.Tweet;

public class TweetDbHelper {

  public static boolean existsInDb( List<Tweet> tweets ){
    boolean result = true;
    
    // if all the tweets are already present in the table, then return "true"
    Select select = new Select();
    for( Tweet tweet: tweets ){
      Tweet t = select.from(Tweet.class).where("uid == ? ", tweet.getUid() ).executeSingle();
      if( t != null || t.getUid() == 0 ){
        // its fake
        result=false;
        break;
      }
    }
    
    return result;
  }
  
  public static void saveWhenNotPresent( List<Tweet> tweets ){
    
    try
    {
      ActiveAndroid.beginTransaction();
      
      Select select = new Select();
      From from = select.from(Tweet.class);
    
      for( Tweet tweet : tweets ){
        Tweet  t = from.where("uid == ? ", tweet.getUid() ).executeSingle();
        if( t==null ){
          tweet.save();
        }
      }
      ActiveAndroid.setTransactionSuccessful();
    }finally{
      ActiveAndroid.endTransaction();
    }
  }
}




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