Example #1
0
 /** Synchronize lists between what is available in the db and on twitter. */
 private void syncLists() {
   TwitterHelper th = new TwitterHelper(this, account);
   TweetDB tdb = new TweetDB(this, accountId);
   if (account.getServerType().equalsIgnoreCase("twitter")) {
     List<UserList> userLists = th.getUserLists();
     Map<String, Integer> storedLists = tdb.getLists();
     // Check for lists to add
     for (UserList userList : userLists) {
       if (!storedLists.containsValue(userList.getId())) {
         tdb.addList(userList.getName(), userList.getId(), DataObjectFactory.getRawJSON(userList));
       }
     }
     // check for outdated lists and remove them
     for (Entry<String, Integer> entry : storedLists.entrySet()) {
       Integer id = entry.getValue();
       boolean found = false;
       for (UserList userList2 : userLists) {
         if (userList2.getId() == id) {
           found = true;
           break;
         }
       }
       if (!found) {
         tdb.removeList(id);
       }
     }
     syncSearches(th, tdb);
   }
 }
Example #2
0
    @Override
    protected Void doInBackground(Integer... params) {
      int accountId = params[0];

      TweetDB tdb = new TweetDB(context, accountId);
      if (tdb.getLists().size() == 0 && tdb.getSavedSearches().size() == 0) syncLists();

      return null;
    }
Example #3
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   Intent i;
   // Handle item selection
   switch (item.getItemId()) {
     case R.id.preferences:
       i = new Intent(this, Preferences.class);
       startActivity(i);
       break;
     case R.id.reloadLists:
       syncLists();
       break;
     case R.id.DevelResetLastRead:
       resetLastRead();
       break;
     case R.id.DevelCleanTweets:
       cleanTweetDB();
       break;
     case R.id.DevelCleanImages:
       cleanImages();
       break;
     case R.id.AccountStuff:
       i = new Intent(this, AccountStuffActivity.class);
       startActivity(i);
       break;
     case R.id.helpMenu:
       i = new Intent(TabWidget.this, HelpActivity.class);
       startActivity(i);
       break;
     case R.id.menu_cleanTweets:
       new CleanupTask(this).execute();
       break;
     case R.id.DevelDumpAccounts:
       TweetDB tmpDb = new TweetDB(this, -1);
       List<Account> allAccounts = tmpDb.getAccountsForSelection();
       for (Account a : allAccounts) System.out.println(a);
       break;
     default:
       return super.onOptionsItemSelected(item);
   }
   return true;
 }
Example #4
0
  private void syncSearches(TwitterHelper th, TweetDB tdb) {
    List<SavedSearch> searches = th.getSavedSearchesFromServer();
    List<SavedSearch> storedSearches = th.getSavedSearchesFromDb();

    for (SavedSearch search : searches) {
      if (!storedSearches.contains(search)) {
        th.persistSavedSearch(search);
      }
    }

    for (SavedSearch search : storedSearches) {
      if (!searches.contains(search)) {
        tdb.deleteSearch(search.getId());
      }
    }
  }
Example #5
0
 private void cleanTweetDB() {
   TweetDB tb = new TweetDB(this, accountId);
   tb.cleanTweetDB();
 }
Example #6
0
 private void resetLastRead() {
   TweetDB tb = new TweetDB(this, accountId);
   tb.resetLastRead();
 }