2 * ownCloud Android client application
4 * @author Bartek Przybylski
5 * Copyright (C) 2012 Bartek Przybylski
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.ui
.activity
;
25 import java
.util
.ArrayList
;
26 import java
.util
.HashMap
;
27 import java
.util
.LinkedList
;
28 import java
.util
.List
;
29 import java
.util
.Stack
;
30 import java
.util
.Vector
;
33 import android
.accounts
.Account
;
34 import android
.accounts
.AccountManager
;
35 import android
.app
.AlertDialog
;
36 import android
.app
.AlertDialog
.Builder
;
37 import android
.app
.Dialog
;
38 import android
.app
.ProgressDialog
;
39 import android
.content
.Context
;
40 import android
.content
.DialogInterface
;
41 import android
.content
.DialogInterface
.OnCancelListener
;
42 import android
.content
.DialogInterface
.OnClickListener
;
43 import android
.content
.Intent
;
44 import android
.content
.SharedPreferences
;
45 import android
.content
.res
.Resources
.NotFoundException
;
46 import android
.database
.Cursor
;
47 import android
.net
.Uri
;
48 import android
.os
.Bundle
;
49 import android
.os
.Parcelable
;
50 import android
.preference
.PreferenceManager
;
51 import android
.provider
.MediaStore
;
52 import android
.provider
.MediaStore
.Audio
;
53 import android
.provider
.MediaStore
.Images
;
54 import android
.provider
.MediaStore
.Video
;
55 import android
.support
.v4
.app
.Fragment
;
56 import android
.support
.v4
.app
.FragmentManager
;
57 import android
.support
.v4
.app
.FragmentTransaction
;
58 import android
.view
.View
;
59 import android
.widget
.AdapterView
;
60 import android
.widget
.AdapterView
.OnItemClickListener
;
61 import android
.widget
.Button
;
62 import android
.widget
.EditText
;
63 import android
.widget
.ListView
;
64 import android
.widget
.SimpleAdapter
;
65 import android
.widget
.Toast
;
67 import com
.actionbarsherlock
.app
.ActionBar
;
68 import com
.actionbarsherlock
.view
.MenuItem
;
69 import com
.owncloud
.android
.MainApp
;
70 import com
.owncloud
.android
.R
;
71 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
72 import com
.owncloud
.android
.datamodel
.OCFile
;
73 import com
.owncloud
.android
.files
.services
.FileUploader
;
74 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
75 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
76 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
77 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
78 import com
.owncloud
.android
.ui
.dialog
.CreateFolderDialogFragment
;
79 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
80 import com
.owncloud
.android
.utils
.CopyTmpFileAsyncTask
;
81 import com
.owncloud
.android
.utils
.DisplayUtils
;
82 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
86 * This can be used to upload things to an ownCloud instance.
88 public class Uploader
extends FileActivity
89 implements OnItemClickListener
, android
.view
.View
.OnClickListener
,
90 CopyTmpFileAsyncTask
.OnCopyTmpFileTaskListener
{
92 private static final String TAG
= Uploader
.class.getSimpleName();
94 private AccountManager mAccountManager
;
95 private Stack
<String
> mParents
;
96 private ArrayList
<Parcelable
> mStreamsToUpload
;
97 private boolean mCreateDir
;
98 private String mUploadPath
;
100 private boolean mAccountSelected
;
101 private boolean mAccountSelectionShowing
;
103 private ArrayList
<String
> mRemoteCacheData
;
104 private int mNumCacheFile
;
106 private final static int DIALOG_NO_ACCOUNT
= 0;
107 private final static int DIALOG_WAITING
= 1;
108 private final static int DIALOG_NO_STREAM
= 2;
109 private final static int DIALOG_MULTIPLE_ACCOUNT
= 3;
111 private final static int REQUEST_CODE_SETUP_ACCOUNT
= 0;
113 private final static String KEY_PARENTS
= "PARENTS";
114 private final static String KEY_FILE
= "FILE";
115 private final static String KEY_ACCOUNT_SELECTED
= "ACCOUNT_SELECTED";
116 private final static String KEY_ACCOUNT_SELECTION_SHOWING
= "ACCOUNT_SELECTION_SHOWING";
117 private final static String KEY_NUM_CACHE_FILE
= "NUM_CACHE_FILE";
118 private final static String KEY_REMOTE_CACHE_DATA
= "REMOTE_CACHE_DATA";
120 private static final String DIALOG_WAIT_COPY_FILE
= "DIALOG_WAIT_COPY_FILE";
123 protected void onCreate(Bundle savedInstanceState
) {
124 prepareStreamsToUpload();
126 if (savedInstanceState
== null
) {
127 mParents
= new Stack
<String
>();
128 mAccountSelected
= false
;
129 mAccountSelectionShowing
= false
;
132 // ArrayList for files with path in private storage
133 mRemoteCacheData
= new ArrayList
<String
>();
135 mParents
= (Stack
<String
>) savedInstanceState
.getSerializable(KEY_PARENTS
);
136 mFile
= savedInstanceState
.getParcelable(KEY_FILE
);
137 mAccountSelected
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTED
);
138 mAccountSelectionShowing
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING
);
139 mNumCacheFile
= savedInstanceState
.getInt(KEY_NUM_CACHE_FILE
);
140 mRemoteCacheData
= savedInstanceState
.getStringArrayList(KEY_REMOTE_CACHE_DATA
);
143 super.onCreate(savedInstanceState
);
145 if (mAccountSelected
) {
146 setAccount((Account
) savedInstanceState
.getParcelable(FileActivity
.EXTRA_ACCOUNT
));
150 ActionBar actionBar
= getSupportActionBar();
151 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
156 protected void setAccount(Account account
, boolean savedAccount
) {
157 if (somethingToUpload()) {
158 mAccountManager
= (AccountManager
) getSystemService(Context
.ACCOUNT_SERVICE
);
159 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAccountType());
160 if (accounts
.length
== 0) {
161 Log_OC
.i(TAG
, "No ownCloud account is available");
162 showDialog(DIALOG_NO_ACCOUNT
);
163 } else if (accounts
.length
> 1 && !mAccountSelected
&& !mAccountSelectionShowing
) {
164 Log_OC
.i(TAG
, "More than one ownCloud is available");
165 showDialog(DIALOG_MULTIPLE_ACCOUNT
);
166 mAccountSelectionShowing
= true
;
169 setAccount(accounts
[0]);
174 showDialog(DIALOG_NO_STREAM
);
177 super.setAccount(account
, savedAccount
);
181 protected void onAccountSet(boolean stateWasRecovered
) {
182 super.onAccountSet(mAccountWasRestored
);
184 populateDirectoryList();
188 protected void onSaveInstanceState(Bundle outState
) {
189 Log_OC
.d(TAG
, "onSaveInstanceState() start");
190 super.onSaveInstanceState(outState
);
191 outState
.putSerializable(KEY_PARENTS
, mParents
);
192 //outState.putParcelable(KEY_ACCOUNT, mAccount);
193 outState
.putParcelable(KEY_FILE
, mFile
);
194 outState
.putBoolean(KEY_ACCOUNT_SELECTED
, mAccountSelected
);
195 outState
.putBoolean(KEY_ACCOUNT_SELECTION_SHOWING
, mAccountSelectionShowing
);
196 outState
.putInt(KEY_NUM_CACHE_FILE
, mNumCacheFile
);
197 outState
.putStringArrayList(KEY_REMOTE_CACHE_DATA
, mRemoteCacheData
);
198 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, getAccount());
200 Log_OC
.d(TAG
, "onSaveInstanceState() end");
204 protected Dialog
onCreateDialog(final int id
) {
205 final AlertDialog
.Builder builder
= new Builder(this);
208 ProgressDialog pDialog
= new ProgressDialog(this);
209 pDialog
.setIndeterminate(false
);
210 pDialog
.setCancelable(false
);
211 pDialog
.setMessage(getResources().getString(R
.string
.uploader_info_uploading
));
213 case DIALOG_NO_ACCOUNT
:
214 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
215 builder
.setTitle(R
.string
.uploader_wrn_no_account_title
);
216 builder
.setMessage(String
.format(
217 getString(R
.string
.uploader_wrn_no_account_text
), getString(R
.string
.app_name
)));
218 builder
.setCancelable(false
);
219 builder
.setPositiveButton(R
.string
.uploader_wrn_no_account_setup_btn_text
, new OnClickListener() {
221 public void onClick(DialogInterface dialog
, int which
) {
222 if (android
.os
.Build
.VERSION
.SDK_INT
> android
.os
.Build
.VERSION_CODES
.ECLAIR_MR1
) {
223 // using string value since in API7 this
224 // constatn is not defined
225 // in API7 < this constatant is defined in
226 // Settings.ADD_ACCOUNT_SETTINGS
227 // and Settings.EXTRA_AUTHORITIES
228 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
229 intent
.putExtra("authorities", new String
[] { MainApp
.getAuthTokenType() });
230 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
232 // since in API7 there is no direct call for
233 // account setup, so we need to
234 // show our own AccountSetupAcricity, get
235 // desired results and setup
236 // everything for ourself
237 Intent intent
= new Intent(getBaseContext(), AccountAuthenticator
.class);
238 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
242 builder
.setNegativeButton(R
.string
.uploader_wrn_no_account_quit_btn_text
, new OnClickListener() {
244 public void onClick(DialogInterface dialog
, int which
) {
248 return builder
.create();
249 case DIALOG_MULTIPLE_ACCOUNT
:
250 CharSequence ac
[] = new CharSequence
[
251 mAccountManager
.getAccountsByType(MainApp
.getAccountType()).length
];
252 for (int i
= 0; i
< ac
.length
; ++i
) {
253 ac
[i
] = DisplayUtils
.convertIdn(
254 mAccountManager
.getAccountsByType(MainApp
.getAccountType())[i
].name
, false
);
256 builder
.setTitle(R
.string
.common_choose_account
);
257 builder
.setItems(ac
, new OnClickListener() {
259 public void onClick(DialogInterface dialog
, int which
) {
260 setAccount(mAccountManager
.getAccountsByType(MainApp
.getAccountType())[which
]);
261 onAccountSet(mAccountWasRestored
);
263 mAccountSelected
= true
;
264 mAccountSelectionShowing
= false
;
267 builder
.setCancelable(true
);
268 builder
.setOnCancelListener(new OnCancelListener() {
270 public void onCancel(DialogInterface dialog
) {
271 mAccountSelectionShowing
= false
;
276 return builder
.create();
277 case DIALOG_NO_STREAM
:
278 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
279 builder
.setTitle(R
.string
.uploader_wrn_no_content_title
);
280 builder
.setMessage(R
.string
.uploader_wrn_no_content_text
);
281 builder
.setCancelable(false
);
282 builder
.setNegativeButton(R
.string
.common_cancel
, new OnClickListener() {
284 public void onClick(DialogInterface dialog
, int which
) {
288 return builder
.create();
290 throw new IllegalArgumentException("Unknown dialog id: " + id
);
294 class a
implements OnClickListener
{
298 public a(String path
, EditText dirname
) {
304 public void onClick(DialogInterface dialog
, int which
) {
305 Uploader
.this.mUploadPath
= mPath
+ mDirname
.getText().toString();
306 Uploader
.this.mCreateDir
= true
;
312 public void onBackPressed() {
314 if (mParents
.size() <= 1) {
315 super.onBackPressed();
319 populateDirectoryList();
324 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
325 // click on folder in the list
326 Log_OC
.d(TAG
, "on item click");
327 Vector
<OCFile
> tmpfiles
= getStorageManager().getFolderContent(mFile
);
328 if (tmpfiles
.size() <= 0) return;
330 Vector
<OCFile
> files
= new Vector
<OCFile
>();
331 for (OCFile f
: tmpfiles
)
334 if (files
.size() < position
) {
335 throw new IndexOutOfBoundsException("Incorrect item selected");
337 mParents
.push(files
.get(position
).getFileName());
338 populateDirectoryList();
342 public void onClick(View v
) {
345 case R
.id
.uploader_choose_folder
:
346 mUploadPath
= ""; // first element in mParents is root dir, represented by "";
347 // init mUploadPath with "/" results in a "//" prefix
348 for (String p
: mParents
)
349 mUploadPath
+= p
+ OCFile
.PATH_SEPARATOR
;
350 Log_OC
.d(TAG
, "Uploading file to dir " + mUploadPath
);
356 case R
.id
.uploader_new_folder
:
357 CreateFolderDialogFragment dialog
= CreateFolderDialogFragment
.newInstance(mFile
);
358 dialog
.show(getSupportFragmentManager(), "createdirdialog");
363 throw new IllegalArgumentException("Wrong element clicked");
368 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
369 super.onActivityResult(requestCode
, resultCode
, data
);
370 Log_OC
.i(TAG
, "result received. req: " + requestCode
+ " res: " + resultCode
);
371 if (requestCode
== REQUEST_CODE_SETUP_ACCOUNT
) {
372 dismissDialog(DIALOG_NO_ACCOUNT
);
373 if (resultCode
== RESULT_CANCELED
) {
376 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAuthTokenType());
377 if (accounts
.length
== 0) {
378 showDialog(DIALOG_NO_ACCOUNT
);
380 // there is no need for checking for is there more then one
381 // account at this point
382 // since account setup can set only one account at time
383 setAccount(accounts
[0]);
384 populateDirectoryList();
389 private void populateDirectoryList() {
390 setContentView(R
.layout
.uploader_layout
);
392 ListView mListView
= (ListView
) findViewById(android
.R
.id
.list
);
394 String current_dir
= mParents
.peek();
395 if(current_dir
.equals("")){
396 getSupportActionBar().setTitle(getString(R
.string
.default_display_name_for_root_folder
));
399 getSupportActionBar().setTitle(current_dir
);
401 boolean notRoot
= (mParents
.size() > 1);
402 ActionBar actionBar
= getSupportActionBar();
403 actionBar
.setDisplayHomeAsUpEnabled(notRoot
);
404 actionBar
.setHomeButtonEnabled(notRoot
);
406 String full_path
= generatePath(mParents
);
408 Log_OC
.d(TAG
, "Populating view with content of : " + full_path
);
410 mFile
= getStorageManager().getFileByPath(full_path
);
412 Vector
<OCFile
> files
= getStorageManager().getFolderContent(mFile
);
413 List
<HashMap
<String
, Object
>> data
= new LinkedList
<HashMap
<String
,Object
>>();
414 for (OCFile f
: files
) {
415 HashMap
<String
, Object
> h
= new HashMap
<String
, Object
>();
417 h
.put("dirname", f
.getFileName());
421 SimpleAdapter sa
= new SimpleAdapter(this,
423 R
.layout
.uploader_list_item_layout
,
424 new String
[] {"dirname"},
425 new int[] {R
.id
.textView1
});
427 mListView
.setAdapter(sa
);
428 Button btnChooseFolder
= (Button
) findViewById(R
.id
.uploader_choose_folder
);
429 btnChooseFolder
.setOnClickListener(this);
431 Button btnNewFolder
= (Button
) findViewById(R
.id
.uploader_new_folder
);
432 btnNewFolder
.setOnClickListener(this);
434 mListView
.setOnItemClickListener(this);
438 private String
generatePath(Stack
<String
> dirs
) {
439 String full_path
= "";
441 for (String a
: dirs
)
442 full_path
+= a
+ "/";
446 private void prepareStreamsToUpload() {
447 if (getIntent().getAction().equals(Intent
.ACTION_SEND
)) {
448 mStreamsToUpload
= new ArrayList
<Parcelable
>();
449 mStreamsToUpload
.add(getIntent().getParcelableExtra(Intent
.EXTRA_STREAM
));
450 } else if (getIntent().getAction().equals(Intent
.ACTION_SEND_MULTIPLE
)) {
451 mStreamsToUpload
= getIntent().getParcelableArrayListExtra(Intent
.EXTRA_STREAM
);
455 private boolean somethingToUpload() {
456 return (mStreamsToUpload
!= null
&& mStreamsToUpload
.get(0) != null
);
459 public void uploadFiles() {
462 // ArrayList for files with path in external storage
463 ArrayList
<String
> local
= new ArrayList
<String
>();
464 ArrayList
<String
> remote
= new ArrayList
<String
>();
466 // this checks the mimeType
467 for (Parcelable mStream
: mStreamsToUpload
) {
469 Uri uri
= (Uri
) mStream
;
471 String filePath
= "";
474 if (uri
.getScheme().equals("content")) {
475 String mimeType
= getContentResolver().getType(uri
);
477 if (mimeType
.contains("image")) {
478 String
[] CONTENT_PROJECTION
= { Images
.Media
.DATA
,
479 Images
.Media
.DISPLAY_NAME
, Images
.Media
.MIME_TYPE
,
481 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
484 int index
= c
.getColumnIndex(Images
.Media
.DATA
);
485 data
= c
.getString(index
);
486 filePath
= mUploadPath
+
487 c
.getString(c
.getColumnIndex(Images
.Media
.DISPLAY_NAME
));
489 } else if (mimeType
.contains("video")) {
490 String
[] CONTENT_PROJECTION
= { Video
.Media
.DATA
,
491 Video
.Media
.DISPLAY_NAME
, Video
.Media
.MIME_TYPE
,
492 Video
.Media
.SIZE
, Video
.Media
.DATE_MODIFIED
};
493 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
496 int index
= c
.getColumnIndex(Video
.Media
.DATA
);
497 data
= c
.getString(index
);
498 filePath
= mUploadPath
+
499 c
.getString(c
.getColumnIndex(Video
.Media
.DISPLAY_NAME
));
501 } else if (mimeType
.contains("audio")) {
502 String
[] CONTENT_PROJECTION
= { Audio
.Media
.DATA
,
503 Audio
.Media
.DISPLAY_NAME
, Audio
.Media
.MIME_TYPE
,
505 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
508 int index
= c
.getColumnIndex(Audio
.Media
.DATA
);
509 data
= c
.getString(index
);
510 filePath
= mUploadPath
+
511 c
.getString(c
.getColumnIndex(Audio
.Media
.DISPLAY_NAME
));
514 Cursor cursor
= getContentResolver().query(uri
,
515 new String
[]{MediaStore
.MediaColumns
.DISPLAY_NAME
},
517 cursor
.moveToFirst();
518 int nameIndex
= cursor
.getColumnIndex(cursor
.getColumnNames()[0]);
519 if (nameIndex
>= 0) {
520 filePath
= mUploadPath
+ cursor
.getString(nameIndex
);
524 } else if (uri
.getScheme().equals("file")) {
525 filePath
= Uri
.decode(uri
.toString()).replace(uri
.getScheme() +
527 if (filePath
.contains("mnt")) {
528 String splitedFilePath
[] = filePath
.split("/mnt");
529 filePath
= splitedFilePath
[1];
531 final File file
= new File(filePath
);
532 data
= file
.getAbsolutePath();
533 filePath
= mUploadPath
+ file
.getName();
536 throw new SecurityException();
539 mRemoteCacheData
.add(filePath
);
540 CopyTmpFileAsyncTask copyTask
= new CopyTmpFileAsyncTask(this);
541 Object
[] params
= { uri
, filePath
, mRemoteCacheData
.size()-1 };
543 showWaitingCopyDialog();
544 copyTask
.execute(params
);
546 remote
.add(filePath
);
551 throw new SecurityException();
554 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
555 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
556 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, local
.toArray(new String
[local
.size()]));
557 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
,
558 remote
.toArray(new String
[remote
.size()]));
559 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
560 startService(intent
);
562 //Save the path to shared preferences
563 SharedPreferences
.Editor appPrefs
= PreferenceManager
564 .getDefaultSharedPreferences(getApplicationContext()).edit();
565 appPrefs
.putString("last_upload_path", mUploadPath
);
571 } catch (SecurityException e
) {
572 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
573 getString(R
.string
.app_name
));
574 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
579 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
580 super.onRemoteOperationFinish(operation
, result
);
583 if (operation
instanceof CreateFolderOperation
) {
584 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
590 * Updates the view associated to the activity after the finish of an operation
591 * trying create a new folder
593 * @param operation Creation operation performed.
594 * @param result Result of the creation.
596 private void onCreateFolderOperationFinish(CreateFolderOperation operation
,
597 RemoteOperationResult result
) {
598 if (result
.isSuccess()) {
599 dismissLoadingDialog();
600 populateDirectoryList();
602 dismissLoadingDialog();
604 Toast msg
= Toast
.makeText(this,
605 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
609 } catch (NotFoundException e
) {
610 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
617 * Loads the target folder initialize shown to the user.
619 * The target account has to be chosen before this method is called.
621 private void initTargetFolder() {
622 if (getStorageManager() == null
) {
623 throw new IllegalStateException("Do not call this method before " +
624 "initializing mStorageManager");
627 SharedPreferences appPreferences
= PreferenceManager
628 .getDefaultSharedPreferences(getApplicationContext());
630 String last_path
= appPreferences
.getString("last_upload_path", "");
631 // "/" equals root-directory
632 if(last_path
.equals("/")) {
635 String
[] dir_names
= last_path
.split("/");
636 for (String dir
: dir_names
)
639 //Make sure that path still exists, if it doesn't pop the stack and try the previous path
640 while(!getStorageManager().fileExists(generatePath(mParents
)) && mParents
.size() > 1){
647 public boolean onOptionsItemSelected(MenuItem item
) {
648 boolean retval
= true
;
649 switch (item
.getItemId()) {
650 case android
.R
.id
.home
:
651 if((mParents
.size() > 1)) {
657 retval
= super.onOptionsItemSelected(item
);
664 * Process the result of CopyTmpFileAsyncTask
669 public void OnCopyTmpFileTaskListener(String result
, int index
) {
670 if (mNumCacheFile
-- == 0) {
671 dismissWaitingCopyDialog();
673 if (result
!= null
) {
674 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
675 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
676 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, result
);
677 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
, mRemoteCacheData
.get(index
));
678 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
679 startService(intent
);
682 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
683 getString(R
.string
.app_name
));
684 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
685 Log_OC
.d(TAG
, message
);
690 * Show waiting for copy dialog
692 public void showWaitingCopyDialog() {
694 LoadingDialog loading
= new LoadingDialog(
695 getResources().getString(R
.string
.wait_for_tmp_copy_from_private_storage
));
696 FragmentManager fm
= getSupportFragmentManager();
697 FragmentTransaction ft
= fm
.beginTransaction();
698 loading
.show(ft
, DIALOG_WAIT_COPY_FILE
);
704 * Dismiss waiting for copy dialog
706 public void dismissWaitingCopyDialog(){
707 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_COPY_FILE
);
709 LoadingDialog loading
= (LoadingDialog
) frag
;