2 * ownCloud Android client application
4 * @author Bartek Przybylski
6 * Copyright (C) 2012 Bartek Przybylski
7 * Copyright (C) 2015 ownCloud Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 package com
.owncloud
.android
.ui
.activity
;
26 import java
.util
.ArrayList
;
27 import java
.util
.HashMap
;
28 import java
.util
.LinkedList
;
29 import java
.util
.List
;
30 import java
.util
.Stack
;
31 import java
.util
.Vector
;
34 import android
.accounts
.Account
;
35 import android
.accounts
.AccountManager
;
36 import android
.app
.AlertDialog
;
37 import android
.app
.AlertDialog
.Builder
;
38 import android
.app
.Dialog
;
39 import android
.app
.ProgressDialog
;
40 import android
.content
.Context
;
41 import android
.content
.DialogInterface
;
42 import android
.content
.DialogInterface
.OnCancelListener
;
43 import android
.content
.DialogInterface
.OnClickListener
;
44 import android
.content
.Intent
;
45 import android
.content
.SharedPreferences
;
46 import android
.content
.res
.Resources
.NotFoundException
;
47 import android
.database
.Cursor
;
48 import android
.net
.Uri
;
49 import android
.os
.Bundle
;
50 import android
.os
.Parcelable
;
51 import android
.preference
.PreferenceManager
;
52 import android
.provider
.MediaStore
;
53 import android
.provider
.MediaStore
.Audio
;
54 import android
.provider
.MediaStore
.Images
;
55 import android
.provider
.MediaStore
.Video
;
56 import android
.support
.v4
.app
.Fragment
;
57 import android
.support
.v4
.app
.FragmentManager
;
58 import android
.support
.v4
.app
.FragmentTransaction
;
59 import android
.support
.v7
.app
.ActionBar
;
60 import android
.view
.Menu
;
61 import android
.view
.MenuInflater
;
62 import android
.view
.MenuItem
;
63 import android
.view
.View
;
64 import android
.widget
.AdapterView
;
65 import android
.widget
.AdapterView
.OnItemClickListener
;
66 import android
.widget
.Button
;
67 import android
.widget
.EditText
;
68 import android
.widget
.ListView
;
69 import android
.widget
.SimpleAdapter
;
70 import android
.widget
.Toast
;
72 import com
.owncloud
.android
.MainApp
;
73 import com
.owncloud
.android
.R
;
74 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
75 import com
.owncloud
.android
.datamodel
.OCFile
;
76 import com
.owncloud
.android
.files
.services
.FileUploader
;
77 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
78 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
79 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
80 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
81 import com
.owncloud
.android
.ui
.dialog
.CreateFolderDialogFragment
;
82 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
83 import com
.owncloud
.android
.utils
.CopyTmpFileAsyncTask
;
84 import com
.owncloud
.android
.utils
.DisplayUtils
;
85 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
89 * This can be used to upload things to an ownCloud instance.
91 public class Uploader
extends FileActivity
92 implements OnItemClickListener
, android
.view
.View
.OnClickListener
,
93 CopyTmpFileAsyncTask
.OnCopyTmpFileTaskListener
{
95 private static final String TAG
= Uploader
.class.getSimpleName();
97 private AccountManager mAccountManager
;
98 private Stack
<String
> mParents
;
99 private ArrayList
<Parcelable
> mStreamsToUpload
;
100 private boolean mCreateDir
;
101 private String mUploadPath
;
102 private OCFile mFile
;
103 private boolean mAccountSelected
;
104 private boolean mAccountSelectionShowing
;
106 private ArrayList
<String
> mRemoteCacheData
;
107 private int mNumCacheFile
;
109 private final static int DIALOG_NO_ACCOUNT
= 0;
110 private final static int DIALOG_WAITING
= 1;
111 private final static int DIALOG_NO_STREAM
= 2;
112 private final static int DIALOG_MULTIPLE_ACCOUNT
= 3;
114 private final static int REQUEST_CODE_SETUP_ACCOUNT
= 0;
116 private final static String KEY_PARENTS
= "PARENTS";
117 private final static String KEY_FILE
= "FILE";
118 private final static String KEY_ACCOUNT_SELECTED
= "ACCOUNT_SELECTED";
119 private final static String KEY_ACCOUNT_SELECTION_SHOWING
= "ACCOUNT_SELECTION_SHOWING";
120 private final static String KEY_NUM_CACHE_FILE
= "NUM_CACHE_FILE";
121 private final static String KEY_REMOTE_CACHE_DATA
= "REMOTE_CACHE_DATA";
123 private static final String DIALOG_WAIT_COPY_FILE
= "DIALOG_WAIT_COPY_FILE";
126 protected void onCreate(Bundle savedInstanceState
) {
127 prepareStreamsToUpload();
129 if (savedInstanceState
== null
) {
130 mParents
= new Stack
<String
>();
131 mAccountSelected
= false
;
132 mAccountSelectionShowing
= false
;
135 // ArrayList for files with path in private storage
136 mRemoteCacheData
= new ArrayList
<String
>();
138 mParents
= (Stack
<String
>) savedInstanceState
.getSerializable(KEY_PARENTS
);
139 mFile
= savedInstanceState
.getParcelable(KEY_FILE
);
140 mAccountSelected
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTED
);
141 mAccountSelectionShowing
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING
);
142 mNumCacheFile
= savedInstanceState
.getInt(KEY_NUM_CACHE_FILE
);
143 mRemoteCacheData
= savedInstanceState
.getStringArrayList(KEY_REMOTE_CACHE_DATA
);
146 super.onCreate(savedInstanceState
);
148 if (mAccountSelected
) {
149 setAccount((Account
) savedInstanceState
.getParcelable(FileActivity
.EXTRA_ACCOUNT
));
153 ActionBar actionBar
= getSupportActionBar();
154 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
159 protected void setAccount(Account account
, boolean savedAccount
) {
160 if (somethingToUpload()) {
161 mAccountManager
= (AccountManager
) getSystemService(Context
.ACCOUNT_SERVICE
);
162 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAccountType());
163 if (accounts
.length
== 0) {
164 Log_OC
.i(TAG
, "No ownCloud account is available");
165 showDialog(DIALOG_NO_ACCOUNT
);
166 } else if (accounts
.length
> 1 && !mAccountSelected
&& !mAccountSelectionShowing
) {
167 Log_OC
.i(TAG
, "More than one ownCloud is available");
168 showDialog(DIALOG_MULTIPLE_ACCOUNT
);
169 mAccountSelectionShowing
= true
;
172 setAccount(accounts
[0]);
177 showDialog(DIALOG_NO_STREAM
);
180 super.setAccount(account
, savedAccount
);
184 protected void onAccountSet(boolean stateWasRecovered
) {
185 super.onAccountSet(mAccountWasRestored
);
187 populateDirectoryList();
191 protected void onSaveInstanceState(Bundle outState
) {
192 Log_OC
.d(TAG
, "onSaveInstanceState() start");
193 super.onSaveInstanceState(outState
);
194 outState
.putSerializable(KEY_PARENTS
, mParents
);
195 //outState.putParcelable(KEY_ACCOUNT, mAccount);
196 outState
.putParcelable(KEY_FILE
, mFile
);
197 outState
.putBoolean(KEY_ACCOUNT_SELECTED
, mAccountSelected
);
198 outState
.putBoolean(KEY_ACCOUNT_SELECTION_SHOWING
, mAccountSelectionShowing
);
199 outState
.putInt(KEY_NUM_CACHE_FILE
, mNumCacheFile
);
200 outState
.putStringArrayList(KEY_REMOTE_CACHE_DATA
, mRemoteCacheData
);
201 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, getAccount());
203 Log_OC
.d(TAG
, "onSaveInstanceState() end");
207 protected Dialog
onCreateDialog(final int id
) {
208 final AlertDialog
.Builder builder
= new Builder(this);
211 ProgressDialog pDialog
= new ProgressDialog(this);
212 pDialog
.setIndeterminate(false
);
213 pDialog
.setCancelable(false
);
214 pDialog
.setMessage(getResources().getString(R
.string
.uploader_info_uploading
));
216 case DIALOG_NO_ACCOUNT
:
217 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
218 builder
.setTitle(R
.string
.uploader_wrn_no_account_title
);
219 builder
.setMessage(String
.format(
220 getString(R
.string
.uploader_wrn_no_account_text
), getString(R
.string
.app_name
)));
221 builder
.setCancelable(false
);
222 builder
.setPositiveButton(R
.string
.uploader_wrn_no_account_setup_btn_text
, new OnClickListener() {
224 public void onClick(DialogInterface dialog
, int which
) {
225 if (android
.os
.Build
.VERSION
.SDK_INT
>
226 android
.os
.Build
.VERSION_CODES
.ECLAIR_MR1
) {
227 // using string value since in API7 this
228 // constatn is not defined
229 // in API7 < this constatant is defined in
230 // Settings.ADD_ACCOUNT_SETTINGS
231 // and Settings.EXTRA_AUTHORITIES
232 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
233 intent
.putExtra("authorities", new String
[] { MainApp
.getAuthTokenType() });
234 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
236 // since in API7 there is no direct call for
237 // account setup, so we need to
238 // show our own AccountSetupAcricity, get
239 // desired results and setup
240 // everything for ourself
241 Intent intent
= new Intent(getBaseContext(), AccountAuthenticator
.class);
242 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
246 builder
.setNegativeButton(R
.string
.uploader_wrn_no_account_quit_btn_text
, new OnClickListener() {
248 public void onClick(DialogInterface dialog
, int which
) {
252 return builder
.create();
253 case DIALOG_MULTIPLE_ACCOUNT
:
254 CharSequence ac
[] = new CharSequence
[
255 mAccountManager
.getAccountsByType(MainApp
.getAccountType()).length
];
256 for (int i
= 0; i
< ac
.length
; ++i
) {
257 ac
[i
] = DisplayUtils
.convertIdn(
258 mAccountManager
.getAccountsByType(MainApp
.getAccountType())[i
].name
, false
);
260 builder
.setTitle(R
.string
.common_choose_account
);
261 builder
.setItems(ac
, new OnClickListener() {
263 public void onClick(DialogInterface dialog
, int which
) {
264 setAccount(mAccountManager
.getAccountsByType(MainApp
.getAccountType())[which
]);
265 onAccountSet(mAccountWasRestored
);
267 mAccountSelected
= true
;
268 mAccountSelectionShowing
= false
;
271 builder
.setCancelable(true
);
272 builder
.setOnCancelListener(new OnCancelListener() {
274 public void onCancel(DialogInterface dialog
) {
275 mAccountSelectionShowing
= false
;
280 return builder
.create();
281 case DIALOG_NO_STREAM
:
282 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
283 builder
.setTitle(R
.string
.uploader_wrn_no_content_title
);
284 builder
.setMessage(R
.string
.uploader_wrn_no_content_text
);
285 builder
.setCancelable(false
);
286 builder
.setNegativeButton(R
.string
.common_cancel
, new OnClickListener() {
288 public void onClick(DialogInterface dialog
, int which
) {
292 return builder
.create();
294 throw new IllegalArgumentException("Unknown dialog id: " + id
);
298 class a
implements OnClickListener
{
302 public a(String path
, EditText dirname
) {
308 public void onClick(DialogInterface dialog
, int which
) {
309 Uploader
.this.mUploadPath
= mPath
+ mDirname
.getText().toString();
310 Uploader
.this.mCreateDir
= true
;
316 public void onBackPressed() {
318 if (mParents
.size() <= 1) {
319 super.onBackPressed();
323 populateDirectoryList();
328 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
329 // click on folder in the list
330 Log_OC
.d(TAG
, "on item click");
331 // TODO Enable when "On Device" is recovered ?
332 Vector
<OCFile
> tmpfiles
= getStorageManager().getFolderContent(mFile
/*, false*/);
333 if (tmpfiles
.size() <= 0) return;
335 Vector
<OCFile
> files
= new Vector
<OCFile
>();
336 for (OCFile f
: tmpfiles
)
339 if (files
.size() < position
) {
340 throw new IndexOutOfBoundsException("Incorrect item selected");
342 mParents
.push(files
.get(position
).getFileName());
343 populateDirectoryList();
347 public void onClick(View v
) {
350 case R
.id
.uploader_choose_folder
:
351 mUploadPath
= ""; // first element in mParents is root dir, represented by "";
352 // init mUploadPath with "/" results in a "//" prefix
353 for (String p
: mParents
)
354 mUploadPath
+= p
+ OCFile
.PATH_SEPARATOR
;
355 Log_OC
.d(TAG
, "Uploading file to dir " + mUploadPath
);
361 case R
.id
.uploader_cancel
:
367 throw new IllegalArgumentException("Wrong element clicked");
372 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
373 super.onActivityResult(requestCode
, resultCode
, data
);
374 Log_OC
.i(TAG
, "result received. req: " + requestCode
+ " res: " + resultCode
);
375 if (requestCode
== REQUEST_CODE_SETUP_ACCOUNT
) {
376 dismissDialog(DIALOG_NO_ACCOUNT
);
377 if (resultCode
== RESULT_CANCELED
) {
380 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAuthTokenType());
381 if (accounts
.length
== 0) {
382 showDialog(DIALOG_NO_ACCOUNT
);
384 // there is no need for checking for is there more then one
385 // account at this point
386 // since account setup can set only one account at time
387 setAccount(accounts
[0]);
388 populateDirectoryList();
393 private void populateDirectoryList() {
394 setContentView(R
.layout
.uploader_layout
);
396 ListView mListView
= (ListView
) findViewById(android
.R
.id
.list
);
398 String current_dir
= mParents
.peek();
399 if(current_dir
.equals("")){
400 getSupportActionBar().setTitle(getString(R
.string
.default_display_name_for_root_folder
));
403 getSupportActionBar().setTitle(current_dir
);
405 boolean notRoot
= (mParents
.size() > 1);
406 ActionBar actionBar
= getSupportActionBar();
407 actionBar
.setDisplayHomeAsUpEnabled(notRoot
);
408 actionBar
.setHomeButtonEnabled(notRoot
);
410 String full_path
= generatePath(mParents
);
412 Log_OC
.d(TAG
, "Populating view with content of : " + full_path
);
414 mFile
= getStorageManager().getFileByPath(full_path
);
416 // TODO Enable when "On Device" is recovered ?
417 Vector
<OCFile
> files
= getStorageManager().getFolderContent(mFile
/*, false*/);
418 List
<HashMap
<String
, Object
>> data
= new LinkedList
<HashMap
<String
,Object
>>();
419 for (OCFile f
: files
) {
420 HashMap
<String
, Object
> h
= new HashMap
<String
, Object
>();
422 h
.put("dirname", f
.getFileName());
426 SimpleAdapter sa
= new SimpleAdapter(this,
428 R
.layout
.uploader_list_item_layout
,
429 new String
[] {"dirname"},
430 new int[] {R
.id
.filename
});
432 mListView
.setAdapter(sa
);
433 Button btnChooseFolder
= (Button
) findViewById(R
.id
.uploader_choose_folder
);
434 btnChooseFolder
.setOnClickListener(this);
436 Button btnNewFolder
= (Button
) findViewById(R
.id
.uploader_cancel
);
437 btnNewFolder
.setOnClickListener(this);
439 mListView
.setOnItemClickListener(this);
443 private String
generatePath(Stack
<String
> dirs
) {
444 String full_path
= "";
446 for (String a
: dirs
)
447 full_path
+= a
+ "/";
451 private void prepareStreamsToUpload() {
452 if (getIntent().getAction().equals(Intent
.ACTION_SEND
)) {
453 mStreamsToUpload
= new ArrayList
<Parcelable
>();
454 mStreamsToUpload
.add(getIntent().getParcelableExtra(Intent
.EXTRA_STREAM
));
455 } else if (getIntent().getAction().equals(Intent
.ACTION_SEND_MULTIPLE
)) {
456 mStreamsToUpload
= getIntent().getParcelableArrayListExtra(Intent
.EXTRA_STREAM
);
460 private boolean somethingToUpload() {
461 return (mStreamsToUpload
!= null
&& mStreamsToUpload
.get(0) != null
);
464 public void uploadFiles() {
467 // ArrayList for files with path in external storage
468 ArrayList
<String
> local
= new ArrayList
<String
>();
469 ArrayList
<String
> remote
= new ArrayList
<String
>();
471 // this checks the mimeType
472 for (Parcelable mStream
: mStreamsToUpload
) {
474 Uri uri
= (Uri
) mStream
;
476 String filePath
= "";
479 if (uri
.getScheme().equals("content")) {
480 String mimeType
= getContentResolver().getType(uri
);
482 if (mimeType
.contains("image")) {
483 String
[] CONTENT_PROJECTION
= { Images
.Media
.DATA
,
484 Images
.Media
.DISPLAY_NAME
, Images
.Media
.MIME_TYPE
,
486 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
489 int index
= c
.getColumnIndex(Images
.Media
.DATA
);
490 data
= c
.getString(index
);
491 filePath
= mUploadPath
+
492 c
.getString(c
.getColumnIndex(Images
.Media
.DISPLAY_NAME
));
494 } else if (mimeType
.contains("video")) {
495 String
[] CONTENT_PROJECTION
= { Video
.Media
.DATA
,
496 Video
.Media
.DISPLAY_NAME
, Video
.Media
.MIME_TYPE
,
497 Video
.Media
.SIZE
, Video
.Media
.DATE_MODIFIED
};
498 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
501 int index
= c
.getColumnIndex(Video
.Media
.DATA
);
502 data
= c
.getString(index
);
503 filePath
= mUploadPath
+
504 c
.getString(c
.getColumnIndex(Video
.Media
.DISPLAY_NAME
));
506 } else if (mimeType
.contains("audio")) {
507 String
[] CONTENT_PROJECTION
= { Audio
.Media
.DATA
,
508 Audio
.Media
.DISPLAY_NAME
, Audio
.Media
.MIME_TYPE
,
510 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
513 int index
= c
.getColumnIndex(Audio
.Media
.DATA
);
514 data
= c
.getString(index
);
515 filePath
= mUploadPath
+
516 c
.getString(c
.getColumnIndex(Audio
.Media
.DISPLAY_NAME
));
519 Cursor cursor
= getContentResolver().query(uri
,
520 new String
[]{MediaStore
.MediaColumns
.DISPLAY_NAME
},
522 cursor
.moveToFirst();
523 int nameIndex
= cursor
.getColumnIndex(cursor
.getColumnNames()[0]);
524 if (nameIndex
>= 0) {
525 filePath
= mUploadPath
+ cursor
.getString(nameIndex
);
529 } else if (uri
.getScheme().equals("file")) {
530 filePath
= Uri
.decode(uri
.toString()).replace(uri
.getScheme() +
532 if (filePath
.contains("mnt")) {
533 String splitedFilePath
[] = filePath
.split("/mnt");
534 filePath
= splitedFilePath
[1];
536 final File file
= new File(filePath
);
537 data
= file
.getAbsolutePath();
538 filePath
= mUploadPath
+ file
.getName();
541 throw new SecurityException();
544 mRemoteCacheData
.add(filePath
);
545 CopyTmpFileAsyncTask copyTask
= new CopyTmpFileAsyncTask(this);
546 Object
[] params
= { uri
, filePath
, mRemoteCacheData
.size()-1,
547 getAccount().name
, getContentResolver()};
549 showWaitingCopyDialog();
550 copyTask
.execute(params
);
552 remote
.add(filePath
);
557 throw new SecurityException();
560 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
561 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
562 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, local
.toArray(new String
[local
.size()]));
563 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
,
564 remote
.toArray(new String
[remote
.size()]));
565 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
566 startService(intent
);
568 //Save the path to shared preferences
569 SharedPreferences
.Editor appPrefs
= PreferenceManager
570 .getDefaultSharedPreferences(getApplicationContext()).edit();
571 appPrefs
.putString("last_upload_path", mUploadPath
);
577 } catch (SecurityException e
) {
578 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
579 getString(R
.string
.app_name
));
580 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
585 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
586 super.onRemoteOperationFinish(operation
, result
);
589 if (operation
instanceof CreateFolderOperation
) {
590 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
596 * Updates the view associated to the activity after the finish of an operation
597 * trying create a new folder
599 * @param operation Creation operation performed.
600 * @param result Result of the creation.
602 private void onCreateFolderOperationFinish(CreateFolderOperation operation
,
603 RemoteOperationResult result
) {
604 if (result
.isSuccess()) {
605 dismissLoadingDialog();
606 populateDirectoryList();
608 dismissLoadingDialog();
610 Toast msg
= Toast
.makeText(this,
611 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
615 } catch (NotFoundException e
) {
616 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
623 * Loads the target folder initialize shown to the user.
625 * The target account has to be chosen before this method is called.
627 private void initTargetFolder() {
628 if (getStorageManager() == null
) {
629 throw new IllegalStateException("Do not call this method before " +
630 "initializing mStorageManager");
633 SharedPreferences appPreferences
= PreferenceManager
634 .getDefaultSharedPreferences(getApplicationContext());
636 String last_path
= appPreferences
.getString("last_upload_path", "");
637 // "/" equals root-directory
638 if(last_path
.equals("/")) {
641 String
[] dir_names
= last_path
.split("/");
643 for (String dir
: dir_names
)
646 //Make sure that path still exists, if it doesn't pop the stack and try the previous path
647 while(!getStorageManager().fileExists(generatePath(mParents
)) && mParents
.size() > 1){
653 public boolean onCreateOptionsMenu(Menu menu
) {
654 MenuInflater inflater
= getMenuInflater();
655 inflater
.inflate(R
.menu
.main_menu
, menu
);
656 menu
.findItem(R
.id
.action_upload
).setVisible(false
);
657 menu
.findItem(R
.id
.action_sort
).setVisible(false
);
658 menu
.findItem(R
.id
.action_sync_account
).setVisible(false
);
663 public boolean onOptionsItemSelected(MenuItem item
) {
664 boolean retval
= true
;
665 switch (item
.getItemId()) {
666 case R
.id
.action_create_dir
:
667 CreateFolderDialogFragment dialog
= CreateFolderDialogFragment
.newInstance(mFile
);
669 getSupportFragmentManager(),
670 CreateFolderDialogFragment
.CREATE_FOLDER_FRAGMENT
);
672 case android
.R
.id
.home
:
673 if((mParents
.size() > 1)) {
679 retval
= super.onOptionsItemSelected(item
);
686 * Process the result of CopyTmpFileAsyncTask
691 public void onTmpFileCopied(String result
, int index
) {
692 if (mNumCacheFile
-- == 0) {
693 dismissWaitingCopyDialog();
695 if (result
!= null
) {
696 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
697 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
698 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, result
);
699 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
, mRemoteCacheData
.get(index
));
700 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
701 startService(intent
);
704 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
705 getString(R
.string
.app_name
));
706 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
707 Log_OC
.d(TAG
, message
);
712 * Show waiting for copy dialog
714 public void showWaitingCopyDialog() {
716 LoadingDialog loading
= new LoadingDialog(
717 getResources().getString(R
.string
.wait_for_tmp_copy_from_private_storage
));
718 FragmentManager fm
= getSupportFragmentManager();
719 FragmentTransaction ft
= fm
.beginTransaction();
720 loading
.show(ft
, DIALOG_WAIT_COPY_FILE
);
726 * Dismiss waiting for copy dialog
728 public void dismissWaitingCopyDialog(){
729 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_COPY_FILE
);
731 LoadingDialog loading
= (LoadingDialog
) frag
;