X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/002e1bf9e3872734f050638c7291540879cd42e8..c75e5aa71cf93e677e5abb95cb3d9c1f45a64ea7:/src/com/owncloud/android/Uploader.java diff --git a/src/com/owncloud/android/Uploader.java b/src/com/owncloud/android/Uploader.java index 2a831792..a15ef3ab 100644 --- a/src/com/owncloud/android/Uploader.java +++ b/src/com/owncloud/android/Uploader.java @@ -3,9 +3,8 @@ * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. + * 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 @@ -16,6 +15,7 @@ * along with this program. If not, see . * */ + package com.owncloud.android; import java.io.File; @@ -45,7 +45,6 @@ import android.os.Parcelable; import android.provider.MediaStore.Audio; import android.provider.MediaStore.Images; import android.provider.MediaStore.Video; -import android.util.Log; import android.view.View; import android.view.Window; import android.widget.AdapterView; @@ -55,14 +54,12 @@ import android.widget.EditText; import android.widget.SimpleAdapter; import android.widget.Toast; -import com.owncloud.android.authenticator.AccountAuthenticator; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileUploader; -import com.owncloud.android.network.OwnCloudClientUtils; -import eu.alefzero.webdav.WebdavClient; +import com.owncloud.android.R; /** * This can be used to upload things to an ownCloud instance. @@ -79,14 +76,13 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro private ArrayList mStreamsToUpload; private boolean mCreateDir; private String mUploadPath; - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private OCFile mFile; private final static int DIALOG_NO_ACCOUNT = 0; private final static int DIALOG_WAITING = 1; private final static int DIALOG_NO_STREAM = 2; private final static int DIALOG_MULTIPLE_ACCOUNT = 3; - //private final static int DIALOG_GET_DIRNAME = 4; private final static int REQUEST_CODE_SETUP_ACCOUNT = 0; @@ -96,16 +92,14 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro getWindow().requestFeature(Window.FEATURE_NO_TITLE); mParents = new Stack(); mParents.add(""); - /*if (getIntent().hasExtra(Intent.EXTRA_STREAM)) { - prepareStreamsToUpload();*/ if (prepareStreamsToUpload()) { mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); - Account[] accounts = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); + Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType()); if (accounts.length == 0) { - Log.i(TAG, "No ownCloud account is available"); + Log_OC.i(TAG, "No ownCloud account is available"); showDialog(DIALOG_NO_ACCOUNT); } else if (accounts.length > 1) { - Log.i(TAG, "More then one ownCloud is available"); + Log_OC.i(TAG, "More then one ownCloud is available"); showDialog(DIALOG_MULTIPLE_ACCOUNT); } else { mAccount = accounts[0]; @@ -141,8 +135,8 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro // in API7 < this constatant is defined in // Settings.ADD_ACCOUNT_SETTINGS // and Settings.EXTRA_AUTHORITIES - Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); - intent.putExtra("authorities", new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE }); + 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 @@ -163,15 +157,15 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro }); return builder.create(); case DIALOG_MULTIPLE_ACCOUNT: - CharSequence ac[] = new CharSequence[mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE).length]; + CharSequence ac[] = new CharSequence[mAccountManager.getAccountsByType(MainApp.getAccountType()).length]; for (int i = 0; i < ac.length; ++i) { - ac[i] = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[i].name; + ac[i] = mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name; } builder.setTitle(R.string.common_choose_account); builder.setItems(ac, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[which]; + mAccount = mAccountManager.getAccountsByType(MainApp.getAccountType())[which]; mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); populateDirectoryList(); } @@ -234,13 +228,13 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro @Override public void onItemClick(AdapterView parent, View view, int position, long id) { // click on folder in the list - Log.d(TAG, "on item click"); - Vector tmpfiles = mStorageManager.getDirectoryContent(mFile); + Log_OC.d(TAG, "on item click"); + Vector tmpfiles = mStorageManager.getFolderContent(mFile); if (tmpfiles.size() <= 0) return; // filter on dirtype Vector files = new Vector(); for (OCFile f : tmpfiles) - if (f.isDirectory()) + if (f.isFolder()) files.add(f); if (files.size() < position) { throw new IndexOutOfBoundsException("Incorrect item selected"); @@ -257,7 +251,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro 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.d(TAG, "Uploading file to dir " + mUploadPath); + Log_OC.d(TAG, "Uploading file to dir " + mUploadPath); uploadFiles(); @@ -270,13 +264,13 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - Log.i(TAG, "result received. req: " + requestCode + " res: " + resultCode); + Log_OC.i(TAG, "result received. req: " + requestCode + " res: " + resultCode); if (requestCode == REQUEST_CODE_SETUP_ACCOUNT) { dismissDialog(DIALOG_NO_ACCOUNT); if (resultCode == RESULT_CANCELED) { finish(); } - Account[] accounts = mAccountManager.getAccountsByType(AccountAuthenticator.AUTH_TOKEN_TYPE); + Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAuthTokenType()); if (accounts.length == 0) { showDialog(DIALOG_NO_ACCOUNT); } else { @@ -296,15 +290,15 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro for (String a : mParents) full_path += a + "/"; - Log.d(TAG, "Populating view with content of : " + full_path); + Log_OC.d(TAG, "Populating view with content of : " + full_path); mFile = mStorageManager.getFileByPath(full_path); if (mFile != null) { - Vector files = mStorageManager.getDirectoryContent(mFile); + Vector files = mStorageManager.getFolderContent(mFile); List> data = new LinkedList>(); for (OCFile f : files) { HashMap h = new HashMap(); - if (f.isDirectory()) { + if (f.isFolder()) { h.put("dirname", f.getFileName()); data.add(h); } @@ -333,15 +327,19 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro public void uploadFiles() { try { - WebdavClient webdav = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext()); + //WebdavClient webdav = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext()); ArrayList local = new ArrayList(); ArrayList remote = new ArrayList(); + /* TODO - mCreateDir can never be true at this moment; we will replace wdc.createDirectory by CreateFolderOperation when that is fixed + WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext()); // create last directory in path if necessary if (mCreateDir) { - webdav.createDirectory(mUploadPath); + wdc.createDirectory(mUploadPath); } + */ + // this checks the mimeType for (Parcelable mStream : mStreamsToUpload) { @@ -419,6 +417,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro startService(intent); finish(); } + } catch (SecurityException e) { String message = String.format(getString(R.string.uploader_error_forbidden_content), getString(R.string.app_name)); Toast.makeText(this, message, Toast.LENGTH_LONG).show();