Android Open Source - BBC-News-Reader Item Clearer






From Project

Back to project page BBC-News-Reader.

License

The source code is released under:

Copyright (c) 2011, 2012, Digital Lizard (Oscar Key, Thomas Boby) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the...

If you think the Android project BBC-News-Reader 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.digitallizard.bbcnewsreader.data;
// w ww.  ja  v  a 2  s . c  o  m
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

public class ItemClearer implements Runnable {
  volatile boolean isClearing;
  Thread thread;
  ContentResolver contentResolver;
  long threshold;
  
  public void clearItems(ContentResolver contentResolver, long threshold) {
    // only allow clearing if the thread isn't running
    if (!isClearing) {
      this.isClearing = true;
      this.contentResolver = contentResolver;
      this.threshold = threshold;
      thread = new Thread(this);
      thread.start();
    }
  }
  
  public void run() {
    // FIXME Optimise, should use a join
    // find items older than the threshold
    Uri uri = DatabaseProvider.CONTENT_URI_ITEMS;
    String[] projection = { DatabaseHelper.COLUMN_ITEM_ID };
    String selection = DatabaseHelper.COLUMN_ITEM_PUBDATE + "<?";
    String[] selectionArgs = { Long.toString(threshold) };
    Cursor cursor = contentResolver.query(uri, projection, selection, selectionArgs, null);
    
    // find the column indexes
    int id = cursor.getColumnIndex(DatabaseHelper.COLUMN_ITEM_ID);
    
    // loop through and delete the items
    while (cursor.moveToNext()) {
      Uri tempUri = Uri.withAppendedPath(DatabaseProvider.CONTENT_URI_ITEMS, Integer.toString(cursor.getInt(id)));
      contentResolver.delete(tempUri, null, null);
    }
    
    cursor.close();
    
    // mark the clearing as finished
    isClearing = false;
  }
  
  public ItemClearer() {
    isClearing = false;
    thread = null;
    contentResolver = null;
    threshold = 0;
  }
}




Java Source Code List

com.digitallizard.bbcnewsreader.ArticleActivity.java
com.digitallizard.bbcnewsreader.CategoryActivity.java
com.digitallizard.bbcnewsreader.CategoryChooserActivity.java
com.digitallizard.bbcnewsreader.CategoryChooserAdapter.java
com.digitallizard.bbcnewsreader.CategoryPagerAdapter.java
com.digitallizard.bbcnewsreader.Eula.java
com.digitallizard.bbcnewsreader.ItemAdapter.java
com.digitallizard.bbcnewsreader.ItemLayout.java
com.digitallizard.bbcnewsreader.Item.java
com.digitallizard.bbcnewsreader.RSSManager.java
com.digitallizard.bbcnewsreader.ReaderActivity.java
com.digitallizard.bbcnewsreader.ResourceInterface.java
com.digitallizard.bbcnewsreader.ResourceService.java
com.digitallizard.bbcnewsreader.ServiceManager.java
com.digitallizard.bbcnewsreader.SettingsActivity.java
com.digitallizard.bbcnewsreader.data.DatabaseHandler.java
com.digitallizard.bbcnewsreader.data.DatabaseHelper.java
com.digitallizard.bbcnewsreader.data.DatabaseProvider.java
com.digitallizard.bbcnewsreader.data.ItemClearer.java
com.digitallizard.bbcnewsreader.data.WrapBackwards.java
com.digitallizard.bbcnewsreader.fragments.ArticleFragment.java
com.digitallizard.bbcnewsreader.fragments.CategoryChooserFragment.java
com.digitallizard.bbcnewsreader.fragments.CategoryFragment.java
com.digitallizard.bbcnewsreader.fragments.FrontpageFragment.java
com.digitallizard.bbcnewsreader.resource.web.HtmlParser.java
com.digitallizard.bbcnewsreader.resource.web.ImageDownloader.java
com.digitallizard.bbcnewsreader.resource.web.QueueItem.java
com.digitallizard.bbcnewsreader.resource.web.WebManager.java
com.digitallizard.bbcnewsreader.widget.ReaderWidget.java
com.digitallizard.bbcnewsreader.widget.WidgetConfigActivity.java
com.hlidskialf.android.preference.SeekBarPreference.java