<string name="unshare_link_file_error">An error occurred while trying to unshare this file or folder</string>
<string name="activity_chooser_send_file_title">Send</string>
-
+ <string name="send_file_missing_file">Sorry, trying to send a missing file.</string>
+
<string name="copy_link">Copy link</string>
<string name="clipboard_text_copied">Copied to clipboard</string>
</resources>
package com.owncloud.android.files;
+import java.io.File;
+import java.io.IOException;
import org.apache.http.protocol.HTTP;
import android.accounts.AccountManager;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.dialog.ShareLinkToDialog;
+import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.Log_OC;
/**
private static final String TAG = FileOperationsHelper.class.getName();
- private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG";
+ private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG";
+
+ public final static int REQUEST_CODE_FILE_OPEN_HELPER = 100;
public void openFile(OCFile file, FileActivity callerActivity) {
Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
}
}
+
+ public void sendFileToApp(Intent sendIntent, FileActivity callerActivity) {
+ Uri filePath = sendIntent.getParcelableExtra(Intent.EXTRA_STREAM);
+ File file = new File(filePath.getPath());
+ Log_OC.d(TAG, "FILE " + filePath.getPath());
+ if (file.exists()) {
+ File folder = new File(FileStorageUtils.getTemporalPath(callerActivity.getAccount().name) + "/send");
+ boolean success = true;
+ if (!folder.exists()) {
+ success = folder.mkdir();
+ }
+ if (success) {
+ File tmpFile = new File(folder.getAbsolutePath()+ "/" + file.getName());
+ try {
+ tmpFile.createNewFile();
+ FileStorageUtils.copyFile(file, tmpFile);
+ } catch (IOException e) {
+ Log_OC.e(TAG, "An error occurred while it was trying to copy in a temporal folder " + e.getMessage());
+ }
+ // Update Uri
+ Uri uri = Uri.fromFile(tmpFile);
+ sendIntent.removeExtra(Intent.EXTRA_STREAM);
+ sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
+ callerActivity.startActivityForResult(sendIntent, REQUEST_CODE_FILE_OPEN_HELPER);
+ }
+ } else {
+ // Show a Message
+ Toast t = Toast.makeText(callerActivity, callerActivity.getString(R.string.send_file_missing_file), Toast.LENGTH_LONG);
+ t.show();
+ Log_OC.d(TAG, "Missing file");
+ }
+ }
+
+
+
+
}
package com.owncloud.android.ui.activity;
+import java.io.File;
+
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.dialog.LoadingDialog;
+import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.Log_OC;
if (mOperationsServiceBinder != null) {
mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
}
+
}
public FileOperationsHelper getFileOperationsHelper() {
return mFileOperationsHelper;
}
-
+
/**
*
* @param operation Removal operation performed.
// TODO whatever could be waiting for the service is unbound
}
}
- };
-
+ }
+
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ Log_OC.d(TAG, "requestCode " + String.valueOf(requestCode) );
+ if (requestCode == FileOperationsHelper.REQUEST_CODE_FILE_OPEN_HELPER) {
+ // Remove "send" folder
+ File folder = new File(FileStorageUtils.getTemporalPath(getAccount().name) + "/send");
+ if (folder.exists()) {
+ FileStorageUtils.deleteFolder(folder);
+ }
+ }
+
+ };
+
+
}
Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm));
mAdapter = new ActivityAdapter(getSherlockActivity(), pm, activities);
-
-
if (sendAction) {
-
return new AlertDialog.Builder(getSherlockActivity())
.setTitle(R.string.activity_chooser_send_file_title)
.setAdapter(mAdapter, new DialogInterface.OnClickListener() {
mIntent.setComponent(name);
// Send the file
- ((FileActivity)getSherlockActivity()).startActivity(mIntent);
+ FileOperationsHelper foh = new FileOperationsHelper();
+ foh.sendFileToApp(mIntent, (FileActivity)getSherlockActivity());
}
})
.create();
+
} else {
return new AlertDialog.Builder(getSherlockActivity())
.setTitle(R.string.activity_chooser_title)
package com.owncloud.android.utils;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
file.setEtag(ocFile.getEtag());
return file;
}
+
+ /**
+ * Copy file src in dst
+ * @param src
+ * @param dst
+ * @throws IOException
+ */
+ @SuppressWarnings("resource")
+ public static void copyFile(File src, File dst) throws IOException {
+ FileChannel inChannel = new FileInputStream(src).getChannel();
+ FileChannel outChannel = new FileOutputStream(dst).getChannel();
+ try {
+ inChannel.transferTo(0, inChannel.size(), outChannel);
+ } finally {
+ if (inChannel != null)
+ inChannel.close();
+ if (outChannel != null)
+ outChannel.close();
+ }
+ }
+
+
+ /**
+ * Delete folder
+ * @param folder
+ * @return true if folder is deleted
+ */
+ public static boolean deleteFolder(File folder){
+ if (folder.isDirectory()) {
+ String[] children = folder.list();
+ for (int i=0; i<children.length; i++) {
+ boolean success = deleteFolder(new File(folder, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+ // The folder is now empty so delete it
+ return folder.delete();
+
+ }
}
\ No newline at end of file