From 60efbf15df969bfd45376cadd8d0722b134a94d8 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 1 Aug 2010 20:22:11 -0700 Subject: [PATCH] upload all --- .../src/com/danga/camli/Preferences.java | 2 + .../src/com/danga/camli/UploadService.java | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/clients/android/uploader/src/com/danga/camli/Preferences.java b/clients/android/uploader/src/com/danga/camli/Preferences.java index e2d712178..f3893feec 100644 --- a/clients/android/uploader/src/com/danga/camli/Preferences.java +++ b/clients/android/uploader/src/com/danga/camli/Preferences.java @@ -11,6 +11,8 @@ public final class Preferences { public static final String AUTO_REQUIRE_POWER = "camli.auto.require_power"; public static final String AUTO_REQUIRE_WIFI = "camli.auto.require_wifi"; + public static final String AUTO_DIR_PHOTOS = "camli.auto.photos"; + private Preferences() { } } diff --git a/clients/android/uploader/src/com/danga/camli/UploadService.java b/clients/android/uploader/src/com/danga/camli/UploadService.java index 7526f2bdb..ee93946f6 100644 --- a/clients/android/uploader/src/com/danga/camli/UploadService.java +++ b/clients/android/uploader/src/com/danga/camli/UploadService.java @@ -120,6 +120,15 @@ public class UploadService extends Service { return; } + if (INTENT_UPLOAD_ALL.equals(action)) { + Util.runAsync(new Runnable() { + public void run() { + handleUploadAll(); + } + }); + return; + } + try { if (INTENT_POWER_CONNECTED.equals(action)) { service.resume(); @@ -165,6 +174,37 @@ public class UploadService extends Service { }); } + // Blocks; to be run from AsyncTask only. + private void handleUploadAll() { + List dirs = getBackupDirs(); + List filesToQueue = new ArrayList(); + for (String dirName : dirs) { + File dir = new File(dirName); + File[] files = dir.listFiles(); + Log.d(TAG, "Contents of " + dirName + ": " + files); + if (files != null) { + for (int i = 0; i < files.length; ++i) { + Log.d(TAG, " " + files[i]); + filesToQueue.add(Uri.fromFile(files[i])); + } + } + } + try { + service.enqueueUploadList(filesToQueue); + } catch (RemoteException e) { + } finally { + stopServiceIfEmpty(); + } + } + + private List getBackupDirs() { + ArrayList dirs = new ArrayList(); + if (mPrefs.getBoolean(Preferences.AUTO_DIR_PHOTOS, true)) { + dirs.add(Environment.getExternalStorageDirectory() + "/DCIM/Camera"); + } + return dirs; + } + private void handleSendMultiple(Intent intent) { ArrayList items = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); ArrayList uris = new ArrayList(items.size());