import com.owncloud.android.AccountUtils;
import com.owncloud.android.authenticator.AccountAuthenticator;
import com.owncloud.android.db.DbHandler;
-import com.owncloud.android.files.services.InstantUploadService;
+import com.owncloud.android.files.services.FileUploader;
-import com.owncloud.android.R;
import android.accounts.Account;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.ConnectivityManager;
-import android.preference.Preference;
import android.preference.PreferenceManager;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
public class PhotoTakenBroadcastReceiver extends BroadcastReceiver {
+ public static String INSTANT_UPLOAD_DIR = "/InstantUpload/";
private static String TAG = "PhotoTakenBroadcastReceiver";
private static final String[] CONTENT_PROJECTION = { Media.DATA, Media.DISPLAY_NAME, Media.MIME_TYPE, Media.SIZE };
-
private static String NEW_PHOTO_ACTION = "com.android.camera.NEW_PICTURE";
@Override
if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
handleConnectivityAction(context, intent);
} else if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
- handleNewPhontoAction(context, intent);
+ handleNewPhotoAction(context, intent);
} else {
Log.e(TAG, "Incorrect intent sent: " + intent.getAction());
}
}
- private void handleNewPhontoAction(Context context, Intent intent) {
+ private void handleNewPhotoAction(Context context, Intent intent) {
Account account = AccountUtils.getCurrentOwnCloudAccount(context);
if (account == null) {
- Log.w(TAG, "No owncloud account found for instant upload, abording");
+ Log.w(TAG, "No owncloud account found for instant upload, aborting");
return;
}
String file_path = c.getString(c.getColumnIndex(Media.DATA));
String file_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME));
String mime_type = c.getString(c.getColumnIndex(Media.MIME_TYPE));
- long file_size = c.getLong(c.getColumnIndex(Media.SIZE));
+ //long file_size = c.getLong(c.getColumnIndex(Media.SIZE));
c.close();
db.close();
return;
}
-
+
+ /*
Intent upload_intent = new Intent(context, InstantUploadService.class);
upload_intent.putExtra(InstantUploadService.KEY_ACCOUNT, account);
upload_intent.putExtra(InstantUploadService.KEY_FILE_PATH, file_path);
upload_intent.putExtra(InstantUploadService.KEY_MIME_TYPE, mime_type);
context.startService(upload_intent);
+ */
+
+ Intent i = new Intent(context, FileUploader.class);
+ i.putExtra(FileUploader.KEY_ACCOUNT, account);
+ i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path);
+ i.putExtra(FileUploader.KEY_REMOTE_FILE, INSTANT_UPLOAD_DIR + "/" + file_name);
+ i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
+ i.putExtra(FileUploader.KEY_MIME_TYPE, mime_type);
+ i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true);
+ context.startService(i);
+
}
private void handleConnectivityAction(Context context, Intent intent) {
String file_path = c.getString(c.getColumnIndex("path"));
File f = new File(file_path);
if (f.exists()) {
- Intent upload_intent = new Intent(context, InstantUploadService.class);
+ //Intent upload_intent = new Intent(context, InstantUploadService.class);
Account account = new Account(account_name, AccountAuthenticator.ACCOUNT_TYPE);
String mimeType = null;
}
if (mimeType == null)
mimeType = "application/octet-stream";
-
+
+ /*
upload_intent.putExtra(InstantUploadService.KEY_ACCOUNT, account);
upload_intent.putExtra(InstantUploadService.KEY_FILE_PATH, file_path);
upload_intent.putExtra(InstantUploadService.KEY_DISPLAY_NAME, f.getName());
upload_intent.putExtra(InstantUploadService.KEY_MIME_TYPE, mimeType);
context.startService(upload_intent);
+ */
+
+ Intent i = new Intent(context, FileUploader.class);
+ i.putExtra(FileUploader.KEY_ACCOUNT, account);
+ i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path);
+ i.putExtra(FileUploader.KEY_REMOTE_FILE, INSTANT_UPLOAD_DIR + f.getName());
+ i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
+ i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true);
+ context.startService(i);
+
} else {
Log.w(TAG, "Instant upload file " + f.getName() + " dont exist anymore");
}
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.PhotoTakenBroadcastReceiver;
+
import eu.alefzero.webdav.OnDatatransferProgressListener;
import com.owncloud.android.utils.OwnCloudClientUtils;
public static final String KEY_ACCOUNT = "ACCOUNT";
public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE";
public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
+ public static final String KEY_MIME_TYPE = "MIME_TYPE";
+ public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD";
public static final int UPLOAD_SINGLE_FILE = 0;
public static final int UPLOAD_MULTIPLE_FILES = 1;
private Looper mServiceLooper;
private ServiceHandler mServiceHandler;
private Account mAccount;
- private String[] mLocalPaths, mRemotePaths;
+ private String[] mLocalPaths, mRemotePaths, mMimeTypes;
private int mUploadType;
private Notification mNotification;
private long mTotalDataToSend, mSendData;
private int mCurrentIndexUpload, mPreviousPercent;
private int mSuccessCounter;
+ private boolean mIsInstant;
/**
* Static map with the files being download and the path to the temporal file were are download
mLocalPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
mRemotePaths = new String[] { intent
.getStringExtra(KEY_REMOTE_FILE) };
+ mMimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
+
} else { // mUploadType == UPLOAD_MULTIPLE_FILES
mLocalPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
mRemotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
+ mMimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
}
-
+
if (mLocalPaths.length != mRemotePaths.length) {
Log.e(TAG, "Different number of remote paths and local paths!");
return Service.START_NOT_STICKY;
}
+ mIsInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
+
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
mServiceHandler.sendMessage(msg);
mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification);
+ /// create remote folder for instant uploads if necessary
+ if (mIsInstant) {
+ OCFile instantUploadDir = storageManager.getFileByPath(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR);
+ if (instantUploadDir == null) {
+ wc.createDirectory(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR); // fail could just mean that it already exists, but local database is not synchronized; the upload will be started anyway
+ OCFile newDir = new OCFile(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR);
+ newDir.setMimetype("DIR");
+ newDir.setParentId(storageManager.getFileByPath(OCFile.PATH_SEPARATOR).getFileId());
+ storageManager.saveFile(newDir);
+ }
+ }
/// perform the upload
File [] localFiles = new File[mLocalPaths.length];
Log.d(TAG, "Will upload " + mTotalDataToSend + " bytes, with " + mLocalPaths.length + " files");
mSuccessCounter = 0;
for (int i = 0; i < mLocalPaths.length; ++i) {
- String mimeType = null;
- try {
- mimeType = MimeTypeMap.getSingleton()
+ String mimeType = (mMimeTypes != null) ? mMimeTypes[i] : null;
+ if (mimeType == null) {
+ try {
+ mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(
mLocalPaths[i].substring(mLocalPaths[i]
.lastIndexOf('.') + 1));
- } catch (IndexOutOfBoundsException e) {
- Log.e(TAG, "Trying to find out MIME type of a file without extension: " + mLocalPaths[i]);
+ } catch (IndexOutOfBoundsException e) {
+ Log.e(TAG, "Trying to find out MIME type of a file without extension: " + mLocalPaths[i]);
+ }
}
if (mimeType == null)
mimeType = "application/octet-stream";
package com.owncloud.android.files.services;
-import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
-
-import com.owncloud.android.AccountUtils;
-import com.owncloud.android.authenticator.AccountAuthenticator;
import com.owncloud.android.utils.OwnCloudClientUtils;
-import com.owncloud.android.utils.OwnCloudVersion;
import eu.alefzero.webdav.WebdavClient;
import android.accounts.Account;
-import android.accounts.AccountManager;
import android.app.Service;
import android.content.Intent;
-import android.net.Uri;
import android.os.IBinder;
import android.util.Log;
WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(account, getApplicationContext());
- int status = 0;
- wdc.createDirectory(INSTANT_UPLOAD_DIR);
- Log.e(TAG, "mkcol returned " + status);
+ wdc.createDirectory(INSTANT_UPLOAD_DIR); // fail could just mean that it already exists; put will be tried anyway
wdc.putFile(filepath, INSTANT_UPLOAD_DIR + "/" + filename, mimetype);
}
}