|
@@ -1,23 +1,22 @@
|
|
/**
|
|
/**
|
|
- * ownCloud Android client application
|
|
|
|
- *
|
|
|
|
- * @author Bartek Przybylski
|
|
|
|
- * @author masensio
|
|
|
|
- * Copyright (C) 2012 Bartek Przybylski
|
|
|
|
- * Copyright (C) 2015 ownCloud Inc.
|
|
|
|
- *
|
|
|
|
- * This program is free software: you can redistribute it and/or modify
|
|
|
|
- * it under the terms of the GNU General Public License version 2,
|
|
|
|
- * as published by the Free Software Foundation.
|
|
|
|
- *
|
|
|
|
- * This program is distributed in the hope that it will be useful,
|
|
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
- * GNU General Public License for more details.
|
|
|
|
- *
|
|
|
|
- * You should have received a copy of the GNU General Public License
|
|
|
|
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
+ * ownCloud Android client application
|
|
*
|
|
*
|
|
|
|
+ * @author Bartek Przybylski
|
|
|
|
+ * @author masensio
|
|
|
|
+ * Copyright (C) 2012 Bartek Przybylski
|
|
|
|
+ * Copyright (C) 2015 ownCloud Inc.
|
|
|
|
+ * <p/>
|
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
|
+ * it under the terms of the GNU General Public License version 2,
|
|
|
|
+ * as published by the Free Software Foundation.
|
|
|
|
+ * <p/>
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
+ * <p/>
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
*/
|
|
|
|
|
|
package com.owncloud.android.ui.activity;
|
|
package com.owncloud.android.ui.activity;
|
|
@@ -109,7 +108,7 @@ public class Uploader extends FileActivity
|
|
|
|
|
|
private ArrayList<String> mRemoteCacheData;
|
|
private ArrayList<String> mRemoteCacheData;
|
|
private int mNumCacheFile;
|
|
private int mNumCacheFile;
|
|
-
|
|
|
|
|
|
+
|
|
private final static int DIALOG_NO_ACCOUNT = 0;
|
|
private final static int DIALOG_NO_ACCOUNT = 0;
|
|
private final static int DIALOG_WAITING = 1;
|
|
private final static int DIALOG_WAITING = 1;
|
|
private final static int DIALOG_NO_STREAM = 2;
|
|
private final static int DIALOG_NO_STREAM = 2;
|
|
@@ -188,7 +187,7 @@ public class Uploader extends FileActivity
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
- Log_OC.d(TAG, "onSaveInstanceState() start");
|
|
|
|
|
|
+ Log_OC.d(TAG, "onSaveInstanceState() start");
|
|
super.onSaveInstanceState(outState);
|
|
super.onSaveInstanceState(outState);
|
|
outState.putSerializable(KEY_PARENTS, mParents);
|
|
outState.putSerializable(KEY_PARENTS, mParents);
|
|
//outState.putParcelable(KEY_ACCOUNT, mAccount);
|
|
//outState.putParcelable(KEY_ACCOUNT, mAccount);
|
|
@@ -206,101 +205,101 @@ public class Uploader extends FileActivity
|
|
protected Dialog onCreateDialog(final int id) {
|
|
protected Dialog onCreateDialog(final int id) {
|
|
final AlertDialog.Builder builder = new Builder(this);
|
|
final AlertDialog.Builder builder = new Builder(this);
|
|
switch (id) {
|
|
switch (id) {
|
|
- case DIALOG_WAITING:
|
|
|
|
- final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme);
|
|
|
|
- pDialog.setIndeterminate(false);
|
|
|
|
- pDialog.setCancelable(false);
|
|
|
|
- pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading));
|
|
|
|
- pDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onShow(DialogInterface dialog) {
|
|
|
|
- ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress);
|
|
|
|
- v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent),
|
|
|
|
- android.graphics.PorterDuff.Mode.MULTIPLY);
|
|
|
|
|
|
+ case DIALOG_WAITING:
|
|
|
|
+ final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme);
|
|
|
|
+ pDialog.setIndeterminate(false);
|
|
|
|
+ pDialog.setCancelable(false);
|
|
|
|
+ pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading));
|
|
|
|
+ pDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onShow(DialogInterface dialog) {
|
|
|
|
+ ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress);
|
|
|
|
+ v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent),
|
|
|
|
+ android.graphics.PorterDuff.Mode.MULTIPLY);
|
|
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return pDialog;
|
|
|
|
- case DIALOG_NO_ACCOUNT:
|
|
|
|
- builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
- builder.setTitle(R.string.uploader_wrn_no_account_title);
|
|
|
|
- builder.setMessage(String.format(
|
|
|
|
- getString(R.string.uploader_wrn_no_account_text),
|
|
|
|
- getString(R.string.app_name)));
|
|
|
|
- builder.setCancelable(false);
|
|
|
|
- builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
- if (android.os.Build.VERSION.SDK_INT >
|
|
|
|
- android.os.Build.VERSION_CODES.ECLAIR_MR1) {
|
|
|
|
- // using string value since in API7 this
|
|
|
|
- // constatn is not defined
|
|
|
|
- // in API7 < this constatant is defined in
|
|
|
|
- // Settings.ADD_ACCOUNT_SETTINGS
|
|
|
|
- // and Settings.EXTRA_AUTHORITIES
|
|
|
|
- Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
|
|
|
|
- intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() });
|
|
|
|
- startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
|
|
|
|
- } else {
|
|
|
|
- // since in API7 there is no direct call for
|
|
|
|
- // account setup, so we need to
|
|
|
|
- // show our own AccountSetupAcricity, get
|
|
|
|
- // desired results and setup
|
|
|
|
- // everything for ourself
|
|
|
|
- Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
|
|
|
|
- startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
|
|
|
|
}
|
|
}
|
|
|
|
+ });
|
|
|
|
+ return pDialog;
|
|
|
|
+ case DIALOG_NO_ACCOUNT:
|
|
|
|
+ builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
+ builder.setTitle(R.string.uploader_wrn_no_account_title);
|
|
|
|
+ builder.setMessage(String.format(
|
|
|
|
+ getString(R.string.uploader_wrn_no_account_text),
|
|
|
|
+ getString(R.string.app_name)));
|
|
|
|
+ builder.setCancelable(false);
|
|
|
|
+ builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >
|
|
|
|
+ android.os.Build.VERSION_CODES.ECLAIR_MR1) {
|
|
|
|
+ // using string value since in API7 this
|
|
|
|
+ // constatn is not defined
|
|
|
|
+ // in API7 < this constatant is defined in
|
|
|
|
+ // Settings.ADD_ACCOUNT_SETTINGS
|
|
|
|
+ // and Settings.EXTRA_AUTHORITIES
|
|
|
|
+ Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
|
|
|
|
+ intent.putExtra("authorities", new String[]{MainApp.getAuthTokenType()});
|
|
|
|
+ startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
|
|
|
|
+ } else {
|
|
|
|
+ // since in API7 there is no direct call for
|
|
|
|
+ // account setup, so we need to
|
|
|
|
+ // show our own AccountSetupAcricity, get
|
|
|
|
+ // desired results and setup
|
|
|
|
+ // everything for ourself
|
|
|
|
+ Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
|
|
|
|
+ startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return builder.create();
|
|
|
|
+ case DIALOG_MULTIPLE_ACCOUNT:
|
|
|
|
+ CharSequence ac[] = new CharSequence[
|
|
|
|
+ mAccountManager.getAccountsByType(MainApp.getAccountType()).length];
|
|
|
|
+ for (int i = 0; i < ac.length; ++i) {
|
|
|
|
+ ac[i] = DisplayUtils.convertIdn(
|
|
|
|
+ mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name, false);
|
|
}
|
|
}
|
|
- });
|
|
|
|
- builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
- finish();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return builder.create();
|
|
|
|
- case DIALOG_MULTIPLE_ACCOUNT:
|
|
|
|
- CharSequence ac[] = new CharSequence[
|
|
|
|
- mAccountManager.getAccountsByType(MainApp.getAccountType()).length];
|
|
|
|
- for (int i = 0; i < ac.length; ++i) {
|
|
|
|
- ac[i] = DisplayUtils.convertIdn(
|
|
|
|
- mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name, false);
|
|
|
|
- }
|
|
|
|
- builder.setTitle(R.string.common_choose_account);
|
|
|
|
- builder.setItems(ac, new OnClickListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
- setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
|
|
|
|
- onAccountSet(mAccountWasRestored);
|
|
|
|
- dialog.dismiss();
|
|
|
|
- mAccountSelected = true;
|
|
|
|
- mAccountSelectionShowing = false;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- builder.setCancelable(true);
|
|
|
|
- builder.setOnCancelListener(new OnCancelListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onCancel(DialogInterface dialog) {
|
|
|
|
- mAccountSelectionShowing = false;
|
|
|
|
- dialog.cancel();
|
|
|
|
- finish();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return builder.create();
|
|
|
|
- case DIALOG_NO_STREAM:
|
|
|
|
- builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
- builder.setTitle(R.string.uploader_wrn_no_content_title);
|
|
|
|
- builder.setMessage(R.string.uploader_wrn_no_content_text);
|
|
|
|
- builder.setCancelable(false);
|
|
|
|
- builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
- finish();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return builder.create();
|
|
|
|
- default:
|
|
|
|
- throw new IllegalArgumentException("Unknown dialog id: " + id);
|
|
|
|
|
|
+ builder.setTitle(R.string.common_choose_account);
|
|
|
|
+ builder.setItems(ac, new OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
+ setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
|
|
|
|
+ onAccountSet(mAccountWasRestored);
|
|
|
|
+ dialog.dismiss();
|
|
|
|
+ mAccountSelected = true;
|
|
|
|
+ mAccountSelectionShowing = false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ builder.setCancelable(true);
|
|
|
|
+ builder.setOnCancelListener(new OnCancelListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onCancel(DialogInterface dialog) {
|
|
|
|
+ mAccountSelectionShowing = false;
|
|
|
|
+ dialog.cancel();
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return builder.create();
|
|
|
|
+ case DIALOG_NO_STREAM:
|
|
|
|
+ builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
+ builder.setTitle(R.string.uploader_wrn_no_content_title);
|
|
|
|
+ builder.setMessage(R.string.uploader_wrn_no_content_text);
|
|
|
|
+ builder.setCancelable(false);
|
|
|
|
+ builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return builder.create();
|
|
|
|
+ default:
|
|
|
|
+ throw new IllegalArgumentException("Unknown dialog id: " + id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -309,7 +308,7 @@ public class Uploader extends FileActivity
|
|
EditText mDirname;
|
|
EditText mDirname;
|
|
|
|
|
|
public a(String path, EditText dirname) {
|
|
public a(String path, EditText dirname) {
|
|
- mPath = path;
|
|
|
|
|
|
+ mPath = path;
|
|
mDirname = dirname;
|
|
mDirname = dirname;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -356,24 +355,24 @@ public class Uploader extends FileActivity
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
// click on button
|
|
// click on button
|
|
switch (v.getId()) {
|
|
switch (v.getId()) {
|
|
- case R.id.uploader_choose_folder:
|
|
|
|
- mUploadPath = ""; // first element in mParents is root dir, represented by "";
|
|
|
|
- // init mUploadPath with "/" results in a "//" prefix
|
|
|
|
- for (String p : mParents)
|
|
|
|
- mUploadPath += p + OCFile.PATH_SEPARATOR;
|
|
|
|
- Log_OC.d(TAG, "Uploading file to dir " + mUploadPath);
|
|
|
|
|
|
+ case R.id.uploader_choose_folder:
|
|
|
|
+ mUploadPath = ""; // first element in mParents is root dir, represented by "";
|
|
|
|
+ // init mUploadPath with "/" results in a "//" prefix
|
|
|
|
+ for (String p : mParents)
|
|
|
|
+ mUploadPath += p + OCFile.PATH_SEPARATOR;
|
|
|
|
+ Log_OC.d(TAG, "Uploading file to dir " + mUploadPath);
|
|
|
|
|
|
- uploadFiles();
|
|
|
|
|
|
+ uploadFiles();
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case R.id.uploader_cancel:
|
|
|
|
+ finish();
|
|
|
|
+ break;
|
|
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case R.id.uploader_cancel:
|
|
|
|
- finish();
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- default:
|
|
|
|
- throw new IllegalArgumentException("Wrong element clicked");
|
|
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ throw new IllegalArgumentException("Wrong element clicked");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -401,14 +400,13 @@ public class Uploader extends FileActivity
|
|
|
|
|
|
private void populateDirectoryList() {
|
|
private void populateDirectoryList() {
|
|
setContentView(R.layout.uploader_layout);
|
|
setContentView(R.layout.uploader_layout);
|
|
-
|
|
|
|
|
|
+
|
|
ListView mListView = (ListView) findViewById(android.R.id.list);
|
|
ListView mListView = (ListView) findViewById(android.R.id.list);
|
|
|
|
|
|
String current_dir = mParents.peek();
|
|
String current_dir = mParents.peek();
|
|
- if(current_dir.equals("")){
|
|
|
|
|
|
+ if (current_dir.equals("")) {
|
|
getSupportActionBar().setTitle(getString(R.string.default_display_name_for_root_folder));
|
|
getSupportActionBar().setTitle(getString(R.string.default_display_name_for_root_folder));
|
|
- }
|
|
|
|
- else{
|
|
|
|
|
|
+ } else {
|
|
getSupportActionBar().setTitle(current_dir);
|
|
getSupportActionBar().setTitle(current_dir);
|
|
}
|
|
}
|
|
boolean notRoot = (mParents.size() > 1);
|
|
boolean notRoot = (mParents.size() > 1);
|
|
@@ -424,7 +422,7 @@ public class Uploader extends FileActivity
|
|
if (mFile != null) {
|
|
if (mFile != null) {
|
|
// TODO Enable when "On Device" is recovered ?
|
|
// TODO Enable when "On Device" is recovered ?
|
|
Vector<OCFile> files = getStorageManager().getFolderContent(mFile/*, false*/);
|
|
Vector<OCFile> files = getStorageManager().getFolderContent(mFile/*, false*/);
|
|
- List<HashMap<String, Object>> data = new LinkedList<HashMap<String,Object>>();
|
|
|
|
|
|
+ List<HashMap<String, Object>> data = new LinkedList<HashMap<String, Object>>();
|
|
for (OCFile f : files) {
|
|
for (OCFile f : files) {
|
|
HashMap<String, Object> h = new HashMap<String, Object>();
|
|
HashMap<String, Object> h = new HashMap<String, Object>();
|
|
if (f.isFolder()) {
|
|
if (f.isFolder()) {
|
|
@@ -433,18 +431,18 @@ public class Uploader extends FileActivity
|
|
}
|
|
}
|
|
}
|
|
}
|
|
SimpleAdapter sa = new SimpleAdapter(this,
|
|
SimpleAdapter sa = new SimpleAdapter(this,
|
|
- data,
|
|
|
|
- R.layout.uploader_list_item_layout,
|
|
|
|
- new String[] {"dirname"},
|
|
|
|
- new int[] {R.id.filename});
|
|
|
|
-
|
|
|
|
|
|
+ data,
|
|
|
|
+ R.layout.uploader_list_item_layout,
|
|
|
|
+ new String[]{"dirname"},
|
|
|
|
+ new int[]{R.id.filename});
|
|
|
|
+
|
|
mListView.setAdapter(sa);
|
|
mListView.setAdapter(sa);
|
|
Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder);
|
|
Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder);
|
|
btnChooseFolder.setOnClickListener(this);
|
|
btnChooseFolder.setOnClickListener(this);
|
|
-
|
|
|
|
|
|
+
|
|
Button btnNewFolder = (Button) findViewById(R.id.uploader_cancel);
|
|
Button btnNewFolder = (Button) findViewById(R.id.uploader_cancel);
|
|
btnNewFolder.setOnClickListener(this);
|
|
btnNewFolder.setOnClickListener(this);
|
|
-
|
|
|
|
|
|
+
|
|
mListView.setOnItemClickListener(this);
|
|
mListView.setOnItemClickListener(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -471,16 +469,16 @@ public class Uploader extends FileActivity
|
|
}
|
|
}
|
|
|
|
|
|
@SuppressLint("NewApi")
|
|
@SuppressLint("NewApi")
|
|
- public void uploadFiles() {
|
|
|
|
|
|
+ public void uploadFiles() {
|
|
try {
|
|
try {
|
|
|
|
|
|
// ArrayList for files with path in external storage
|
|
// ArrayList for files with path in external storage
|
|
ArrayList<String> local = new ArrayList<String>();
|
|
ArrayList<String> local = new ArrayList<String>();
|
|
ArrayList<String> remote = new ArrayList<String>();
|
|
ArrayList<String> remote = new ArrayList<String>();
|
|
-
|
|
|
|
|
|
+
|
|
// this checks the mimeType
|
|
// this checks the mimeType
|
|
for (Parcelable mStream : mStreamsToUpload) {
|
|
for (Parcelable mStream : mStreamsToUpload) {
|
|
-
|
|
|
|
|
|
+
|
|
Uri uri = (Uri) mStream;
|
|
Uri uri = (Uri) mStream;
|
|
String data = null;
|
|
String data = null;
|
|
String filePath = "";
|
|
String filePath = "";
|
|
@@ -490,9 +488,9 @@ public class Uploader extends FileActivity
|
|
String mimeType = getContentResolver().getType(uri);
|
|
String mimeType = getContentResolver().getType(uri);
|
|
|
|
|
|
if (mimeType.contains("image")) {
|
|
if (mimeType.contains("image")) {
|
|
- String[] CONTENT_PROJECTION = { Images.Media.DATA,
|
|
|
|
|
|
+ String[] CONTENT_PROJECTION = {Images.Media.DATA,
|
|
Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE,
|
|
Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE,
|
|
- Images.Media.SIZE };
|
|
|
|
|
|
+ Images.Media.SIZE};
|
|
Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null,
|
|
Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null,
|
|
null, null);
|
|
null, null);
|
|
c.moveToFirst();
|
|
c.moveToFirst();
|
|
@@ -502,37 +500,37 @@ public class Uploader extends FileActivity
|
|
c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));
|
|
c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));
|
|
|
|
|
|
} else if (mimeType.contains("video")) {
|
|
} else if (mimeType.contains("video")) {
|
|
- String[] CONTENT_PROJECTION = { Video.Media.DATA,
|
|
|
|
- Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE,
|
|
|
|
- Video.Media.SIZE, Video.Media.DATE_MODIFIED };
|
|
|
|
|
|
+ String[] CONTENT_PROJECTION = {Video.Media.DATA,
|
|
|
|
+ Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE,
|
|
|
|
+ Video.Media.SIZE, Video.Media.DATE_MODIFIED};
|
|
Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null,
|
|
Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null,
|
|
- null, null);
|
|
|
|
|
|
+ null, null);
|
|
c.moveToFirst();
|
|
c.moveToFirst();
|
|
int index = c.getColumnIndex(Video.Media.DATA);
|
|
int index = c.getColumnIndex(Video.Media.DATA);
|
|
data = c.getString(index);
|
|
data = c.getString(index);
|
|
filePath = mUploadPath +
|
|
filePath = mUploadPath +
|
|
- c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
|
|
|
|
-
|
|
|
|
|
|
+ c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
|
|
|
|
+
|
|
} else if (mimeType.contains("audio")) {
|
|
} else if (mimeType.contains("audio")) {
|
|
- String[] CONTENT_PROJECTION = { Audio.Media.DATA,
|
|
|
|
- Audio.Media.DISPLAY_NAME, Audio.Media.MIME_TYPE,
|
|
|
|
- Audio.Media.SIZE };
|
|
|
|
|
|
+ String[] CONTENT_PROJECTION = {Audio.Media.DATA,
|
|
|
|
+ Audio.Media.DISPLAY_NAME, Audio.Media.MIME_TYPE,
|
|
|
|
+ Audio.Media.SIZE};
|
|
Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null,
|
|
Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null,
|
|
- null, null);
|
|
|
|
|
|
+ null, null);
|
|
c.moveToFirst();
|
|
c.moveToFirst();
|
|
int index = c.getColumnIndex(Audio.Media.DATA);
|
|
int index = c.getColumnIndex(Audio.Media.DATA);
|
|
data = c.getString(index);
|
|
data = c.getString(index);
|
|
filePath = mUploadPath +
|
|
filePath = mUploadPath +
|
|
- c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));
|
|
|
|
|
|
+ c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ } else {
|
|
Cursor cursor = getContentResolver().query(uri,
|
|
Cursor cursor = getContentResolver().query(uri,
|
|
- new String[]{MediaStore.MediaColumns.DISPLAY_NAME},
|
|
|
|
- null, null, null);
|
|
|
|
|
|
+ new String[]{MediaStore.MediaColumns.DISPLAY_NAME},
|
|
|
|
+ null, null, null);
|
|
cursor.moveToFirst();
|
|
cursor.moveToFirst();
|
|
int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
|
|
int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
|
|
if (nameIndex >= 0) {
|
|
if (nameIndex >= 0) {
|
|
- filePath = mUploadPath + cursor.getString(nameIndex);
|
|
|
|
|
|
+ filePath = mUploadPath + cursor.getString(nameIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -540,20 +538,19 @@ public class Uploader extends FileActivity
|
|
filePath = Uri.decode(uri.toString()).replace(uri.getScheme() +
|
|
filePath = Uri.decode(uri.toString()).replace(uri.getScheme() +
|
|
"://", "");
|
|
"://", "");
|
|
if (filePath.contains("mnt")) {
|
|
if (filePath.contains("mnt")) {
|
|
- String splitedFilePath[] = filePath.split("/mnt");
|
|
|
|
- filePath = splitedFilePath[1];
|
|
|
|
|
|
+ String splitedFilePath[] = filePath.split("/mnt");
|
|
|
|
+ filePath = splitedFilePath[1];
|
|
}
|
|
}
|
|
final File file = new File(filePath);
|
|
final File file = new File(filePath);
|
|
data = file.getAbsolutePath();
|
|
data = file.getAbsolutePath();
|
|
filePath = mUploadPath + file.getName();
|
|
filePath = mUploadPath + file.getName();
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
throw new SecurityException();
|
|
throw new SecurityException();
|
|
}
|
|
}
|
|
if (data == null) {
|
|
if (data == null) {
|
|
mRemoteCacheData.add(filePath);
|
|
mRemoteCacheData.add(filePath);
|
|
CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
|
|
CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
|
|
- Object[] params = { uri, filePath, mRemoteCacheData.size()-1,
|
|
|
|
|
|
+ Object[] params = {uri, filePath, mRemoteCacheData.size() - 1,
|
|
getAccount().name, getContentResolver()};
|
|
getAccount().name, getContentResolver()};
|
|
mNumCacheFile++;
|
|
mNumCacheFile++;
|
|
showWaitingCopyDialog();
|
|
showWaitingCopyDialog();
|
|
@@ -562,12 +559,12 @@ public class Uploader extends FileActivity
|
|
remote.add(filePath);
|
|
remote.add(filePath);
|
|
local.add(data);
|
|
local.add(data);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
throw new SecurityException();
|
|
throw new SecurityException();
|
|
}
|
|
}
|
|
|
|
|
|
- FileUploader.uploadNewFile(getApplicationContext(), getAccount(), local.toArray(new String[local.size()]), remote.toArray(new String[remote.size()]));
|
|
|
|
|
|
+ FileUploader.uploadNewFile(this, getAccount(), local.toArray(new String[local.size()]), remote
|
|
|
|
+ .toArray(new String[remote.size()]));
|
|
|
|
|
|
//Save the path to shared preferences
|
|
//Save the path to shared preferences
|
|
SharedPreferences.Editor appPrefs = PreferenceManager
|
|
SharedPreferences.Editor appPrefs = PreferenceManager
|
|
@@ -577,29 +574,29 @@ public class Uploader extends FileActivity
|
|
|
|
|
|
finish();
|
|
finish();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
} catch (SecurityException e) {
|
|
} catch (SecurityException e) {
|
|
String message = String.format(getString(R.string.uploader_error_forbidden_content),
|
|
String message = String.format(getString(R.string.uploader_error_forbidden_content),
|
|
getString(R.string.app_name));
|
|
getString(R.string.app_name));
|
|
- Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
+ Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
|
|
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
|
|
super.onRemoteOperationFinish(operation, result);
|
|
super.onRemoteOperationFinish(operation, result);
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
if (operation instanceof CreateFolderOperation) {
|
|
if (operation instanceof CreateFolderOperation) {
|
|
- onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
|
|
|
|
|
|
+ onCreateFolderOperationFinish((CreateFolderOperation) operation, result);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Updates the view associated to the activity after the finish of an operation
|
|
* Updates the view associated to the activity after the finish of an operation
|
|
* trying create a new folder
|
|
* trying create a new folder
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param operation Creation operation performed.
|
|
* @param operation Creation operation performed.
|
|
* @param result Result of the creation.
|
|
* @param result Result of the creation.
|
|
*/
|
|
*/
|
|
@@ -609,21 +606,21 @@ public class Uploader extends FileActivity
|
|
populateDirectoryList();
|
|
populateDirectoryList();
|
|
} else {
|
|
} else {
|
|
try {
|
|
try {
|
|
- Toast msg = Toast.makeText(this,
|
|
|
|
- ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
|
|
|
|
- Toast.LENGTH_LONG);
|
|
|
|
|
|
+ Toast msg = Toast.makeText(this,
|
|
|
|
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
|
|
|
|
+ Toast.LENGTH_LONG);
|
|
msg.show();
|
|
msg.show();
|
|
|
|
|
|
} catch (NotFoundException e) {
|
|
} catch (NotFoundException e) {
|
|
- Log_OC.e(TAG, "Error while trying to show fail message " , e);
|
|
|
|
|
|
+ Log_OC.e(TAG, "Error while trying to show fail message ", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Loads the target folder initialize shown to the user.
|
|
* Loads the target folder initialize shown to the user.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* The target account has to be chosen before this method is called.
|
|
* The target account has to be chosen before this method is called.
|
|
*/
|
|
*/
|
|
private void initTargetFolder() {
|
|
private void initTargetFolder() {
|
|
@@ -631,22 +628,22 @@ public class Uploader extends FileActivity
|
|
throw new IllegalStateException("Do not call this method before " +
|
|
throw new IllegalStateException("Do not call this method before " +
|
|
"initializing mStorageManager");
|
|
"initializing mStorageManager");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
SharedPreferences appPreferences = PreferenceManager
|
|
SharedPreferences appPreferences = PreferenceManager
|
|
.getDefaultSharedPreferences(getApplicationContext());
|
|
.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
|
|
String last_path = appPreferences.getString("last_upload_path", "");
|
|
String last_path = appPreferences.getString("last_upload_path", "");
|
|
// "/" equals root-directory
|
|
// "/" equals root-directory
|
|
- if(last_path.equals("/")) {
|
|
|
|
|
|
+ if (last_path.equals("/")) {
|
|
mParents.add("");
|
|
mParents.add("");
|
|
- } else{
|
|
|
|
|
|
+ } else {
|
|
String[] dir_names = last_path.split("/");
|
|
String[] dir_names = last_path.split("/");
|
|
mParents.clear();
|
|
mParents.clear();
|
|
for (String dir : dir_names)
|
|
for (String dir : dir_names)
|
|
mParents.add(dir);
|
|
mParents.add(dir);
|
|
}
|
|
}
|
|
//Make sure that path still exists, if it doesn't pop the stack and try the previous path
|
|
//Make sure that path still exists, if it doesn't pop the stack and try the previous path
|
|
- while(!getStorageManager().fileExists(generatePath(mParents)) && mParents.size() > 1){
|
|
|
|
|
|
+ while (!getStorageManager().fileExists(generatePath(mParents)) && mParents.size() > 1) {
|
|
mParents.pop();
|
|
mParents.pop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -660,7 +657,7 @@ public class Uploader extends FileActivity
|
|
menu.findItem(R.id.action_sync_account).setVisible(false);
|
|
menu.findItem(R.id.action_sync_account).setVisible(false);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
boolean retval = true;
|
|
boolean retval = true;
|
|
@@ -672,7 +669,7 @@ public class Uploader extends FileActivity
|
|
CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT);
|
|
CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT);
|
|
break;
|
|
break;
|
|
case android.R.id.home:
|
|
case android.R.id.home:
|
|
- if((mParents.size() > 1)) {
|
|
|
|
|
|
+ if ((mParents.size() > 1)) {
|
|
onBackPressed();
|
|
onBackPressed();
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -691,11 +688,11 @@ public class Uploader extends FileActivity
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void onTmpFileCopied(String result, int index) {
|
|
public void onTmpFileCopied(String result, int index) {
|
|
- if (mNumCacheFile -- == 0) {
|
|
|
|
|
|
+ if (mNumCacheFile-- == 0) {
|
|
dismissWaitingCopyDialog();
|
|
dismissWaitingCopyDialog();
|
|
}
|
|
}
|
|
if (result != null) {
|
|
if (result != null) {
|
|
- FileUploader.uploadNewFile(getApplicationContext(), getAccount(), result, mRemoteCacheData.get(index));
|
|
|
|
|
|
+ FileUploader.uploadNewFile(this, getAccount(), result, mRemoteCacheData.get(index));
|
|
|
|
|
|
} else {
|
|
} else {
|
|
String message = String.format(getString(R.string.uploader_error_forbidden_content),
|
|
String message = String.format(getString(R.string.uploader_error_forbidden_content),
|
|
@@ -705,7 +702,8 @@ public class Uploader extends FileActivity
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-/**
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
* Show waiting for copy dialog
|
|
* Show waiting for copy dialog
|
|
*/
|
|
*/
|
|
public void showWaitingCopyDialog() {
|
|
public void showWaitingCopyDialog() {
|
|
@@ -722,7 +720,7 @@ public class Uploader extends FileActivity
|
|
/**
|
|
/**
|
|
* Dismiss waiting for copy dialog
|
|
* Dismiss waiting for copy dialog
|
|
*/
|
|
*/
|
|
- public void dismissWaitingCopyDialog(){
|
|
|
|
|
|
+ public void dismissWaitingCopyDialog() {
|
|
Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_COPY_FILE);
|
|
Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_COPY_FILE);
|
|
if (frag != null) {
|
|
if (frag != null) {
|
|
LoadingDialog loading = (LoadingDialog) frag;
|
|
LoadingDialog loading = (LoadingDialog) frag;
|