public void run()
{
String programWorkingFolder = Program.getFolder();
File dataFile = new File(programWorkingFolder + DATA_FILE);
PhotoList photoListPrevious = GetPreviousPhotoList( dataFile );
PhotoList newPhotoList = null;
boolean contactFlickr = false;
// No saved photo list found, must access flickr data.
if( photoListPrevious == null )
contactFlickr = true;
if( !contactFlickr )
{
String lastConnectionProp = Program.getProperty("flickr.lastConnection");
String daysToReconnectProp = Program.getProperty("flickr.daysToReconnect");
contactFlickr = CheckPastUpdateDate( lastConnectionProp, daysToReconnectProp );
}
if( contactFlickr )
{
newPhotoList = GetPhotoListFromFlickr();
if( newPhotoList != null )
{
//
// Set the new contact date.
//
DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd");
String today = dfm.format(new Date());
Program.setProperty("flickr.lastConnection", today);
//
// Save the new list of photos
//
FileOutputStream f_out = null;
try
{
f_out = new FileOutputStream( programWorkingFolder + DATA_FILE );
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject ( newPhotoList );
}
catch (Exception e) {}// FileNotFoundException, IOException
finally
{
if( f_out != null )
{
try {
f_out.close();
} catch (IOException e) {}
}
}
}
}
PhotoList photoListToShow = photoListPrevious;
if( newPhotoList != null )
photoListToShow = newPhotoList;
if( photoListToShow == null )
return;
//
// Add the photos, download if necessary?
//
String storeFolder = programWorkingFolder + STORE_FOLDER;
String tempFolder = System.getProperty("java.io.tmpdir");
if( tempFolder.isEmpty() )
tempFolder = programWorkingFolder + TEMP_FOLDER;
else
tempFolder += File.separator + TEMP_FOLDER;
File checkFolder = new File( storeFolder );
if( !checkFolder.exists() )
checkFolder.mkdirs();
checkFolder = new File( tempFolder );
if( !checkFolder.exists() )
checkFolder.mkdirs();
// TODO: Check if file already exists, but delete ones we aren't using any more.
// Should only be less than the number of photos allowed to be downloaded some
// may need to delete before downloading
@SuppressWarnings("unchecked")
Iterator<com.aetrion.flickr.photos.Photo> i = (Iterator<com.aetrion.flickr.photos.Photo>)photoListToShow.iterator();
for(; i.hasNext();)
{
com.aetrion.flickr.photos.Photo photo = i.next();