diff --git a/res/values/strings.xml b/res/values/strings.xml index 7620dff3c7..0b68b93c51 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -57,6 +57,7 @@ Files Connect Upload + Create textfile Choose upload folder No account found There are no %1$s accounts on your device. Please set up an account first. diff --git a/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index 5193c28b43..8f004b76b5 100644 --- a/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -40,8 +40,9 @@ import android.os.Bundle; import android.os.Parcelable; import android.support.v4.app.FragmentManager; import android.support.v7.app.ActionBar; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AlertDialog.Builder; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -49,6 +50,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; +import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; @@ -76,6 +78,9 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.FileStorageUtils; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -175,13 +180,6 @@ public class ReceiveExternalFilesActivity extends FileActivity setAccount(accounts[0]); } } - - } else if (getIntent().getStringExtra(Intent.EXTRA_TEXT) != null) { - showErrorDialog( - R.string.uploader_error_message_received_piece_of_text, - R.string.uploader_error_title_no_file_to_upload - ); - } else { showErrorDialog( R.string.uploader_error_message_no_file_to_upload, @@ -342,8 +340,63 @@ public class ReceiveExternalFilesActivity extends FileActivity for (String p : mParents) { mUploadPath += p + OCFile.PATH_SEPARATOR; } - Log_OC.d(TAG, "Uploading file to dir " + mUploadPath); - uploadFiles(); + + if (uploadTextSnippet()){ + LayoutInflater layout = LayoutInflater.from(Uploader.this); + View view = layout.inflate(R.layout.edit_box_dialog, null); + + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( + Uploader.this); + + alertDialogBuilder.setView(view); + + final EditText userInput = (EditText) view.findViewById(R.id.user_input); + userInput.setText(".txt"); + + alertDialogBuilder.setCancelable(false) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog,int id) { + PrintWriter out; + try { + File f = File.createTempFile("owncloud", ".txt"); + out = new PrintWriter(f); + out.println(getIntent().getStringExtra( + Intent.EXTRA_TEXT)); + out.close(); + + FileUploader.UploadRequester requester = + new FileUploader.UploadRequester(); + + requester.uploadNewFile( + getBaseContext(), + getAccount(), + f.getAbsolutePath(), + mFile.getRemotePath() + userInput.getText() + + ".txt", + FileUploader.LOCAL_BEHAVIOUR_COPY, + null, + true, + UploadFileOperation.CREATED_BY_USER + ); + } catch (IOException e) { + e.printStackTrace(); + } + + finish(); + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog,int id) { + dialog.cancel(); + } + }); + + alertDialogBuilder.create().show(); + } else { + + Log_OC.d(TAG, "Uploading file to dir " + mUploadPath); + uploadFiles(); + } break; case R.id.uploader_cancel: @@ -423,6 +476,10 @@ public class ReceiveExternalFilesActivity extends FileActivity Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder); btnChooseFolder.setOnClickListener(this); + if (uploadTextSnippet()){ + btnChooseFolder.setText(R.string.uploader_btn_uploadTextSnippet_text); + } + Button btnNewFolder = (Button) findViewById(R.id.uploader_cancel); btnNewFolder.setOnClickListener(this); @@ -478,7 +535,11 @@ public class ReceiveExternalFilesActivity extends FileActivity } private boolean somethingToUpload() { - return (mStreamsToUpload != null && mStreamsToUpload.get(0) != null); + return (mStreamsToUpload != null && mStreamsToUpload.get(0) != null || uploadTextSnippet()); + } + + private boolean uploadTextSnippet(){ + return getIntent().getStringExtra(Intent.EXTRA_TEXT) != null; } @SuppressLint("NewApi")