This commit is contained in:
tobiasKaminsky 2016-05-01 10:15:08 +02:00 committed by Andy Scherzinger
parent 45c98398ac
commit 993264c8b1
2 changed files with 74 additions and 12 deletions

View file

@ -57,6 +57,7 @@
<string name="sync_string_files">Files</string>
<string name="setup_btn_connect">Connect</string>
<string name="uploader_btn_upload_text">Upload</string>
<string name="uploader_btn_uploadTextSnippet_text">Create textfile</string>
<string name="uploader_top_message">Choose upload folder</string>
<string name="uploader_wrn_no_account_title">No account found</string>
<string name="uploader_wrn_no_account_text">There are no %1$s accounts on your device. Please set up an account first.</string>

View file

@ -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;
}
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")