1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.activity
;
23 import android
.accounts
.Account
;
24 import android
.app
.AlertDialog
;
25 import android
.app
.ProgressDialog
;
26 import android
.app
.Dialog
;
27 import android
.content
.BroadcastReceiver
;
28 import android
.content
.ComponentName
;
29 import android
.content
.ContentResolver
;
30 import android
.content
.Context
;
31 import android
.content
.DialogInterface
;
32 import android
.content
.Intent
;
33 import android
.content
.IntentFilter
;
34 import android
.content
.ServiceConnection
;
35 import android
.content
.SharedPreferences
;
36 import android
.content
.res
.Resources
.NotFoundException
;
37 import android
.database
.Cursor
;
38 import android
.net
.Uri
;
39 import android
.os
.Bundle
;
40 import android
.os
.Handler
;
41 import android
.os
.IBinder
;
42 import android
.preference
.PreferenceManager
;
43 import android
.provider
.MediaStore
;
44 import android
.support
.v4
.app
.Fragment
;
45 import android
.support
.v4
.app
.FragmentManager
;
46 import android
.support
.v4
.app
.FragmentTransaction
;
47 import android
.util
.Log
;
48 import android
.view
.View
;
49 import android
.view
.ViewGroup
;
50 import android
.widget
.ArrayAdapter
;
51 import android
.widget
.TextView
;
52 import android
.widget
.Toast
;
54 import com
.actionbarsherlock
.app
.ActionBar
;
55 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
56 import com
.actionbarsherlock
.view
.Menu
;
57 import com
.actionbarsherlock
.view
.MenuInflater
;
58 import com
.actionbarsherlock
.view
.MenuItem
;
59 import com
.actionbarsherlock
.view
.Window
;
60 import com
.owncloud
.android
.Log_OC
;
61 import com
.owncloud
.android
.MainApp
;
62 import com
.owncloud
.android
.R
;
63 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
64 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
65 import com
.owncloud
.android
.datamodel
.OCFile
;
66 import com
.owncloud
.android
.files
.services
.FileDownloader
;
67 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
68 import com
.owncloud
.android
.files
.services
.FileObserverService
;
69 import com
.owncloud
.android
.files
.services
.FileUploader
;
70 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
71 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
72 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
73 import com
.owncloud
.android
.operations
.RemoteOperation
;
74 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
75 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
76 import com
.owncloud
.android
.operations
.RenameFileOperation
;
77 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
78 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
79 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
80 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
81 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
82 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
83 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
84 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
85 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
86 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
87 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
88 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
89 import com
.owncloud
.android
.ui
.preview
.PreviewImageFragment
;
90 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
91 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
94 * Displays, what files the user has available in his ownCloud.
96 * @author Bartek Przybylski
97 * @author David A. Velasco
100 public class FileDisplayActivity
extends FileActivity
implements
101 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
103 private ArrayAdapter
<String
> mDirectories
;
105 /** Access point to the cached database for the current ownCloud {@link Account} */
106 private DataStorageManager mStorageManager
= null
;
108 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
109 private UploadFinishReceiver mUploadFinishReceiver
;
110 private DownloadFinishReceiver mDownloadFinishReceiver
;
111 private FileDownloaderBinder mDownloaderBinder
= null
;
112 private FileUploaderBinder mUploaderBinder
= null
;
113 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
114 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
116 private boolean mDualPane
;
117 private View mLeftFragmentContainer
;
118 private View mRightFragmentContainer
;
120 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
122 public static final int DIALOG_SHORT_WAIT
= 0;
123 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
124 private static final int DIALOG_SSL_VALIDATOR
= 2;
125 private static final int DIALOG_CERT_NOT_SAVED
= 3;
127 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
129 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
131 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
132 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
134 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
136 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
137 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
139 private OCFile mWaitingToPreview
;
140 private Handler mHandler
;
143 protected void onCreate(Bundle savedInstanceState
) {
144 Log_OC
.d(TAG
, "onCreate() start");
145 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
147 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
149 mHandler
= new Handler();
151 /// bindings to transference services
152 mUploadConnection
= new ListServiceConnection();
153 mDownloadConnection
= new ListServiceConnection();
154 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
155 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
157 // PIN CODE request ; best location is to decide, let's try this first
158 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
163 Intent observer_intent
= new Intent(this, FileObserverService
.class);
164 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
165 startService(observer_intent
);
167 /// Load of saved instance state
168 if(savedInstanceState
!= null
) {
169 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
172 mWaitingToPreview
= null
;
177 // Inflate and set the layout view
178 setContentView(R
.layout
.files
);
179 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
180 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
181 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
182 if (savedInstanceState
== null
) {
183 createMinFragments();
187 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
188 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
189 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to work around bug in its implementation
193 Log_OC
.d(TAG
, "onCreate() end");
198 protected void onDestroy() {
200 if (mDownloadConnection
!= null
)
201 unbindService(mDownloadConnection
);
202 if (mUploadConnection
!= null
)
203 unbindService(mUploadConnection
);
208 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
211 protected void onAccountSet(boolean stateWasRecovered
) {
212 if (getAccount() != null
) {
213 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
215 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
216 OCFile file
= getFile();
217 // get parent from path
218 String parentPath
= "";
220 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
221 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
222 // get parent from path
223 parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
224 if (mStorageManager
.getFileByPath(parentPath
) == null
)
225 file
= null
; // not able to know the directory where the file is uploading
227 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
231 // fall back to root folder
232 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
235 mDirectories
.clear();
236 OCFile fileIt
= file
;
237 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
238 if (fileIt
.isDirectory()) {
239 mDirectories
.add(fileIt
.getFileName());
241 // get parent from path
242 parentPath
= fileIt
.getRemotePath().substring(0, fileIt
.getRemotePath().lastIndexOf(fileIt
.getFileName()));
243 fileIt
= mStorageManager
.getFileByPath(parentPath
);
245 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
246 if (!stateWasRecovered
) {
247 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
248 initFragmentsWithFile();
251 updateFragmentsVisibility(!file
.isDirectory());
252 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
257 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
262 private void createMinFragments() {
263 OCFileListFragment listOfFiles
= new OCFileListFragment();
264 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
265 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
266 transaction
.commit();
269 private void initFragmentsWithFile() {
270 if (getAccount() != null
&& getFile() != null
) {
272 OCFileListFragment listOfFiles
= getListOfFilesFragment();
273 if (listOfFiles
!= null
) {
274 listOfFiles
.listDirectory(getCurrentDir());
276 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
280 OCFile file
= getFile();
281 Fragment secondFragment
= chooseInitialSecondFragment(file
);
282 if (secondFragment
!= null
) {
283 setSecondFragment(secondFragment
);
284 updateFragmentsVisibility(true
);
285 updateNavigationElementsInActionBar(file
);
288 cleanSecondFragment();
292 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
293 if (getAccount() == null
) {
294 Log
.wtf(TAG
, "\t account is NULL");
296 if (getFile() == null
) {
297 Log
.wtf(TAG
, "\t file is NULL");
302 private Fragment
chooseInitialSecondFragment(OCFile file
) {
303 Fragment secondFragment
= null
;
304 if (file
!= null
&& !file
.isDirectory()) {
305 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
306 && file
.getLastSyncDateForProperties() > 0 // temporal fix
308 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
309 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
310 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
313 secondFragment
= new FileDetailFragment(file
, getAccount());
316 return secondFragment
;
321 * Replaces the second fragment managed by the activity with the received as
324 * Assumes never will be more than two fragments managed at the same time.
326 * @param fragment New second Fragment to set.
328 private void setSecondFragment(Fragment fragment
) {
329 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
330 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
331 transaction
.commit();
335 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
337 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
338 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
340 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
341 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
344 } else if (existsSecondFragment
) {
345 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
346 mLeftFragmentContainer
.setVisibility(View
.GONE
);
348 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
349 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
353 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
354 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
356 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
357 mRightFragmentContainer
.setVisibility(View
.GONE
);
363 private OCFileListFragment
getListOfFilesFragment() {
364 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
365 if (listOfFiles
!= null
) {
366 return (OCFileListFragment
)listOfFiles
;
368 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
372 protected FileFragment
getSecondFragment() {
373 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
374 if (second
!= null
) {
375 return (FileFragment
)second
;
380 public void cleanSecondFragment() {
381 Fragment second
= getSecondFragment();
382 if (second
!= null
) {
383 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
387 updateFragmentsVisibility(false
);
388 updateNavigationElementsInActionBar(null
);
391 protected void refeshListOfFilesFragment() {
392 OCFileListFragment fileListFragment
= getListOfFilesFragment();
393 if (fileListFragment
!= null
) {
394 fileListFragment
.listDirectory();
398 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
399 FileFragment secondFragment
= getSecondFragment();
400 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
401 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
402 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
403 OCFile fileInFragment
= detailsFragment
.getFile();
404 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
405 // the user browsed to other file ; forget the automatic preview
406 mWaitingToPreview
= null
;
408 } else if (downloadEvent
.equals(FileDownloader
.getDownloadAddedMessage())) {
409 // grant that the right panel updates the progress bar
410 detailsFragment
.listenForTransferProgress();
411 detailsFragment
.updateFileDetails(true
, false
);
413 } else if (downloadEvent
.equals(FileDownloader
.getDownloadFinishMessage())) {
414 // update the right panel
415 boolean detailsFragmentChanged
= false
;
418 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
419 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
420 startMediaPreview(mWaitingToPreview
, 0, true
);
421 detailsFragmentChanged
= true
;
423 openFile(mWaitingToPreview
);
426 mWaitingToPreview
= null
;
428 if (!detailsFragmentChanged
) {
429 detailsFragment
.updateFileDetails(false
, (success
));
437 public boolean onCreateOptionsMenu(Menu menu
) {
438 MenuInflater inflater
= getSherlock().getMenuInflater();
439 inflater
.inflate(R
.menu
.main_menu
, menu
);
444 public boolean onOptionsItemSelected(MenuItem item
) {
445 boolean retval
= true
;
446 switch (item
.getItemId()) {
447 case R
.id
.action_create_dir
: {
448 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
449 dialog
.show(getSupportFragmentManager(), "createdirdialog");
452 case R
.id
.action_sync_account
: {
453 startSynchronization();
456 case R
.id
.action_upload
: {
457 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
460 case R
.id
.action_settings
: {
461 Intent settingsIntent
= new Intent(this, Preferences
.class);
462 startActivity(settingsIntent
);
465 case android
.R
.id
.home
: {
466 FileFragment second
= getSecondFragment();
467 OCFile currentDir
= getCurrentDir();
468 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
469 (second
!= null
&& second
.getFile() != null
)) {
475 retval
= super.onOptionsItemSelected(item
);
480 private void startSynchronization() {
481 ContentResolver
.cancelSync(null
, MainApp
.getAuthTokenType()); // cancel the current synchronizations of any ownCloud account
482 Bundle bundle
= new Bundle();
483 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
484 ContentResolver
.requestSync(
486 MainApp
.getAuthTokenType(), bundle
);
491 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
492 int i
= itemPosition
;
496 // the next operation triggers a new call to this method, but it's necessary to
497 // ensure that the name exposed in the action bar is the current directory when the
498 // user selected it in the navigation list
499 if (itemPosition
!= 0)
500 getSupportActionBar().setSelectedNavigationItem(0);
505 * Called, when the user selected something for uploading
507 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
508 super.onActivityResult(requestCode
, resultCode
, data
);
510 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
511 requestSimpleUpload(data
, resultCode
);
513 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
514 requestMultipleUpload(data
, resultCode
);
519 private void requestMultipleUpload(Intent data
, int resultCode
) {
520 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
521 if (filePaths
!= null
) {
522 String
[] remotePaths
= new String
[filePaths
.length
];
523 String remotePathBase
= "";
524 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
525 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
527 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
528 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
529 for (int j
= 0; j
< remotePaths
.length
; j
++) {
530 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
533 Intent i
= new Intent(this, FileUploader
.class);
534 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
535 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
536 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
537 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
538 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
539 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
543 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
544 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
551 private void requestSimpleUpload(Intent data
, int resultCode
) {
552 String filepath
= null
;
554 Uri selectedImageUri
= data
.getData();
556 String filemanagerstring
= selectedImageUri
.getPath();
557 String selectedImagePath
= getPath(selectedImageUri
);
559 if (selectedImagePath
!= null
)
560 filepath
= selectedImagePath
;
562 filepath
= filemanagerstring
;
564 } catch (Exception e
) {
565 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
569 if (filepath
== null
) {
570 Log_OC
.e(TAG
, "Couldnt resolve path to file");
571 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
577 Intent i
= new Intent(this, FileUploader
.class);
578 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
580 String remotepath
= new String();
581 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
582 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
584 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
585 remotepath
+= OCFile
.PATH_SEPARATOR
;
586 remotepath
+= new File(filepath
).getName();
588 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
589 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
590 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
591 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
592 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
597 public void onBackPressed() {
598 OCFileListFragment listOfFiles
= getListOfFilesFragment();
599 if (mDualPane
|| getSecondFragment() == null
) {
600 if (listOfFiles
!= null
) { // should never be null, indeed
601 if (mDirectories
.getCount() <= 1) {
606 listOfFiles
.onBrowseUp();
609 if (listOfFiles
!= null
) { // should never be null, indeed
610 setFile(listOfFiles
.getCurrentFile());
612 cleanSecondFragment();
616 protected void onSaveInstanceState(Bundle outState
) {
617 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
618 Log_OC
.e(TAG
, "onSaveInstanceState() start");
619 super.onSaveInstanceState(outState
);
620 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
621 Log_OC
.d(TAG
, "onSaveInstanceState() end");
627 protected void onResume() {
629 Log_OC
.e(TAG
, "onResume() start");
631 // Listen for sync messages
632 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.getSyncMessage());
633 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
634 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
636 // Listen for upload messages
637 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.getUploadFinishMessage());
638 mUploadFinishReceiver
= new UploadFinishReceiver();
639 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
641 // Listen for download messages
642 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.getDownloadAddedMessage());
643 downloadIntentFilter
.addAction(FileDownloader
.getDownloadFinishMessage());
644 mDownloadFinishReceiver
= new DownloadFinishReceiver();
645 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
647 Log_OC
.d(TAG
, "onResume() end");
652 protected void onPause() {
654 Log_OC
.e(TAG
, "onPause() start");
655 if (mSyncBroadcastReceiver
!= null
) {
656 unregisterReceiver(mSyncBroadcastReceiver
);
657 mSyncBroadcastReceiver
= null
;
659 if (mUploadFinishReceiver
!= null
) {
660 unregisterReceiver(mUploadFinishReceiver
);
661 mUploadFinishReceiver
= null
;
663 if (mDownloadFinishReceiver
!= null
) {
664 unregisterReceiver(mDownloadFinishReceiver
);
665 mDownloadFinishReceiver
= null
;
668 Log_OC
.d(TAG
, "onPause() end");
673 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
674 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
675 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
681 protected Dialog
onCreateDialog(int id
) {
682 Dialog dialog
= null
;
683 AlertDialog
.Builder builder
;
685 case DIALOG_SHORT_WAIT
: {
686 ProgressDialog working_dialog
= new ProgressDialog(this);
687 working_dialog
.setMessage(getResources().getString(
688 R
.string
.wait_a_moment
));
689 working_dialog
.setIndeterminate(true
);
690 working_dialog
.setCancelable(false
);
691 dialog
= working_dialog
;
694 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
696 String
[] items
= null
;
698 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
699 getString(R
.string
.actionbar_upload_from_apps
),
700 getString(R
.string
.actionbar_failed_instant_upload
) };
702 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
703 getString(R
.string
.actionbar_upload_from_apps
) };
705 if (InstantUploadActivity
.IS_ENABLED
)
710 builder
= new AlertDialog
.Builder(this);
711 builder
.setTitle(R
.string
.actionbar_upload
);
712 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
713 public void onClick(DialogInterface dialog
, int item
) {
716 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
717 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
718 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
720 // TODO create and handle new fragment
721 // LocalFileListFragment
723 } else if (item
== 1) {
724 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
725 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
726 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
727 ACTION_SELECT_CONTENT_FROM_APPS
);
728 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
729 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
730 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
731 startActivity(action
);
735 dialog
= builder
.create();
738 case DIALOG_SSL_VALIDATOR
: {
739 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
742 case DIALOG_CERT_NOT_SAVED
: {
743 builder
= new AlertDialog
.Builder(this);
744 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
745 builder
.setCancelable(false
);
746 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
748 public void onClick(DialogInterface dialog
, int which
) {
752 dialog
= builder
.create();
764 * Show loading dialog
766 public void showLoadingDialog() {
768 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
769 FragmentManager fm
= getSupportFragmentManager();
770 FragmentTransaction ft
= fm
.beginTransaction();
771 loading
.show(ft
, DIALOG_WAIT_TAG
);
776 * Dismiss loading dialog
778 public void dismissLoadingDialog(){
779 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
781 LoadingDialog loading
= (LoadingDialog
) frag
;
788 * Translates a content URI of an image to a physical path
790 * @param uri The URI to resolve
791 * @return The path to the image or null if it could not be found
793 public String
getPath(Uri uri
) {
794 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
795 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
796 if (cursor
!= null
) {
797 int column_index
= cursor
798 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
799 cursor
.moveToFirst();
800 return cursor
.getString(column_index
);
806 * Pushes a directory to the drop down list
807 * @param directory to push
808 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
810 public void pushDirname(OCFile directory
) {
811 if(!directory
.isDirectory()){
812 throw new IllegalArgumentException("Only directories may be pushed!");
814 mDirectories
.insert(directory
.getFileName(), 0);
819 * Pops a directory name from the drop down list
820 * @return True, unless the stack is empty
822 public boolean popDirname() {
823 mDirectories
.remove(mDirectories
.getItem(0));
824 return !mDirectories
.isEmpty();
827 // Custom array adapter to override text colors
828 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
830 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
834 public View
getView(int position
, View convertView
, ViewGroup parent
) {
835 View v
= super.getView(position
, convertView
, parent
);
837 ((TextView
) v
).setTextColor(getResources().getColorStateList(
838 android
.R
.color
.white
));
842 public View
getDropDownView(int position
, View convertView
,
844 View v
= super.getDropDownView(position
, convertView
, parent
);
846 ((TextView
) v
).setTextColor(getResources().getColorStateList(
847 android
.R
.color
.white
));
854 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
857 * {@link BroadcastReceiver} to enable syncing feedback in UI
860 public void onReceive(Context context
, Intent intent
) {
861 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
862 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
864 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
866 if (getAccount() != null
&& accountName
.equals(getAccount().name
)
867 && mStorageManager
!= null
870 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
872 boolean fillBlankRoot
= false
;
873 OCFile currentDir
= getCurrentDir();
874 if (currentDir
== null
) {
875 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
876 fillBlankRoot
= (currentDir
!= null
);
879 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
882 currentDir
= mStorageManager
.getFileByPath(synchFolderRemotePath
);
883 OCFileListFragment fileListFragment
= getListOfFilesFragment();
884 if (fileListFragment
!= null
) {
885 fileListFragment
.listDirectory(currentDir
);
887 if (getSecondFragment() == null
)
891 setSupportProgressBarIndeterminateVisibility(inProgress
);
892 removeStickyBroadcast(intent
);
896 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
897 if (synchResult
!= null
) {
898 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
899 mLastSslUntrustedServerResult
= synchResult
;
900 showDialog(DIALOG_SSL_VALIDATOR
);
907 private class UploadFinishReceiver
extends BroadcastReceiver
{
909 * Once the file upload has finished -> update view
910 * @author David A. Velasco
911 * {@link BroadcastReceiver} to enable upload feedback in UI
914 public void onReceive(Context context
, Intent intent
) {
915 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
916 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
917 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
918 OCFile currentDir
= getCurrentDir();
919 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
920 if (sameAccount
&& isDescendant
) {
921 refeshListOfFilesFragment();
929 * Class waiting for broadcast events from the {@link FielDownloader} service.
931 * Updates the UI when a download is started or finished, provided that it is relevant for the
934 private class DownloadFinishReceiver
extends BroadcastReceiver
{
936 public void onReceive(Context context
, Intent intent
) {
937 boolean sameAccount
= isSameAccount(context
, intent
);
938 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
939 boolean isDescendant
= isDescendant(downloadedRemotePath
);
941 if (sameAccount
&& isDescendant
) {
942 refeshListOfFilesFragment();
943 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
946 removeStickyBroadcast(intent
);
949 private boolean isDescendant(String downloadedRemotePath
) {
950 OCFile currentDir
= getCurrentDir();
951 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
954 private boolean isSameAccount(Context context
, Intent intent
) {
955 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
956 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
965 public DataStorageManager
getStorageManager() {
966 return mStorageManager
;
973 * Updates action bar and second fragment, if in dual pane mode.
976 public void onBrowsedDownTo(OCFile directory
) {
977 pushDirname(directory
);
978 cleanSecondFragment();
982 * Opens the image gallery showing the image {@link OCFile} received as parameter.
984 * @param file Image {@link OCFile} to show.
987 public void startImagePreview(OCFile file
) {
988 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
989 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
990 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
991 startActivity(showDetailsIntent
);
995 * Stars the preview of an already down media {@link OCFile}.
997 * @param file Media {@link OCFile} to preview.
998 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
999 * @param autoplay When 'true', the playback will start without user interactions.
1002 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1003 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1004 setSecondFragment(mediaFragment
);
1005 updateFragmentsVisibility(true
);
1006 updateNavigationElementsInActionBar(file
);
1011 * Requests the download of the received {@link OCFile} , updates the UI
1012 * to monitor the download progress and prepares the activity to preview
1013 * or open the file when the download finishes.
1015 * @param file {@link OCFile} to download and preview.
1018 public void startDownloadForPreview(OCFile file
) {
1019 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1020 setSecondFragment(detailFragment
);
1021 mWaitingToPreview
= file
;
1022 requestForDownload();
1023 updateFragmentsVisibility(true
);
1024 updateNavigationElementsInActionBar(file
);
1030 * Shows the information of the {@link OCFile} received as a
1031 * parameter in the second fragment.
1033 * @param file {@link OCFile} whose details will be shown
1036 public void showDetails(OCFile file
) {
1037 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1038 setSecondFragment(detailFragment
);
1039 updateFragmentsVisibility(true
);
1040 updateNavigationElementsInActionBar(file
);
1048 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1049 ActionBar actionBar
= getSupportActionBar();
1050 if (chosenFile
== null
|| mDualPane
) {
1051 // only list of files - set for browsing through folders
1052 OCFile currentDir
= getCurrentDir();
1053 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1054 actionBar
.setDisplayShowTitleEnabled(false
);
1055 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1056 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1059 actionBar
.setDisplayHomeAsUpEnabled(true
);
1060 actionBar
.setDisplayShowTitleEnabled(true
);
1061 actionBar
.setTitle(chosenFile
.getFileName());
1062 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1071 public void onFileStateChanged() {
1072 refeshListOfFilesFragment();
1073 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1081 public FileDownloaderBinder
getFileDownloaderBinder() {
1082 return mDownloaderBinder
;
1090 public FileUploaderBinder
getFileUploaderBinder() {
1091 return mUploaderBinder
;
1095 /** Defines callbacks for service binding, passed to bindService() */
1096 private class ListServiceConnection
implements ServiceConnection
{
1099 public void onServiceConnected(ComponentName component
, IBinder service
) {
1100 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1101 Log_OC
.d(TAG
, "Download service connected");
1102 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1103 if (mWaitingToPreview
!= null
) {
1104 requestForDownload();
1107 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1108 Log_OC
.d(TAG
, "Upload service connected");
1109 mUploaderBinder
= (FileUploaderBinder
) service
;
1113 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1114 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1115 if (listOfFiles
!= null
) {
1116 listOfFiles
.listDirectory();
1118 FileFragment secondFragment
= getSecondFragment();
1119 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1120 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1121 detailFragment
.listenForTransferProgress();
1122 detailFragment
.updateFileDetails(false
, false
);
1127 public void onServiceDisconnected(ComponentName component
) {
1128 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1129 Log_OC
.d(TAG
, "Download service disconnected");
1130 mDownloaderBinder
= null
;
1131 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1132 Log_OC
.d(TAG
, "Upload service disconnected");
1133 mUploaderBinder
= null
;
1141 * Launch an intent to request the PIN code to the user before letting him use the app
1143 private void requestPinCode() {
1144 boolean pinStart
= false
;
1145 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1146 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1148 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1149 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1156 public void onSavedCertificate() {
1157 startSynchronization();
1162 public void onFailedSavingCertificate() {
1163 showDialog(DIALOG_CERT_NOT_SAVED
);
1168 * Updates the view associated to the activity after the finish of some operation over files
1169 * in the current account.
1171 * @param operation Removal operation performed.
1172 * @param result Result of the removal.
1175 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1176 if (operation
instanceof RemoveFileOperation
) {
1177 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1179 } else if (operation
instanceof RenameFileOperation
) {
1180 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1182 } else if (operation
instanceof SynchronizeFileOperation
) {
1183 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1185 } else if (operation
instanceof CreateFolderOperation
) {
1186 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1192 * Updates the view associated to the activity after the finish of an operation trying to remove a
1195 * @param operation Removal operation performed.
1196 * @param result Result of the removal.
1198 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1199 dismissLoadingDialog();
1200 if (result
.isSuccess()) {
1201 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1203 OCFile removedFile
= operation
.getFile();
1204 getSecondFragment();
1205 FileFragment second
= getSecondFragment();
1206 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1207 cleanSecondFragment();
1209 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1210 refeshListOfFilesFragment();
1214 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1216 if (result
.isSslRecoverableException()) {
1217 mLastSslUntrustedServerResult
= result
;
1218 showDialog(DIALOG_SSL_VALIDATOR
);
1224 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1226 * @param operation Creation operation performed.
1227 * @param result Result of the creation.
1229 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1230 if (result
.isSuccess()) {
1231 dismissLoadingDialog();
1232 refeshListOfFilesFragment();
1235 //dismissDialog(DIALOG_SHORT_WAIT);
1236 dismissLoadingDialog();
1238 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1241 } catch (NotFoundException e
) {
1242 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1249 * Updates the view associated to the activity after the finish of an operation trying to rename a
1252 * @param operation Renaming operation performed.
1253 * @param result Result of the renaming.
1255 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1256 dismissLoadingDialog();
1257 OCFile renamedFile
= operation
.getFile();
1258 if (result
.isSuccess()) {
1260 FileFragment details
= getSecondFragment();
1261 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1262 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1265 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1266 refeshListOfFilesFragment();
1270 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1271 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1273 // TODO throw again the new rename dialog
1275 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1277 if (result
.isSslRecoverableException()) {
1278 mLastSslUntrustedServerResult
= result
;
1279 showDialog(DIALOG_SSL_VALIDATOR
);
1286 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1287 dismissLoadingDialog();
1288 OCFile syncedFile
= operation
.getLocalFile();
1289 if (!result
.isSuccess()) {
1290 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1291 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1292 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1293 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1297 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1302 if (operation
.transferWasRequested()) {
1303 refeshListOfFilesFragment();
1304 onTransferStateChanged(syncedFile
, true
, true
);
1307 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1318 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1320 FileFragment details
= getSecondFragment();
1321 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1322 if (downloading
|| uploading
) {
1323 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1325 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1332 public void onDismiss(EditNameDialog dialog
) {
1333 if (dialog
.getResult()) {
1334 String newDirectoryName
= dialog
.getNewFilename().trim();
1335 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1336 if (newDirectoryName
.length() > 0) {
1337 String path
= getCurrentDir().getRemotePath();
1340 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1341 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1342 operation
.execute( getAccount(),
1343 FileDisplayActivity
.this,
1344 FileDisplayActivity
.this,
1346 FileDisplayActivity
.this);
1348 showLoadingDialog();
1354 private void requestForDownload() {
1355 Account account
= getAccount();
1356 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1357 Intent i
= new Intent(this, FileDownloader
.class);
1358 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1359 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1365 private OCFile
getCurrentDir() {
1366 OCFile file
= getFile();
1368 if (file
.isDirectory()) {
1370 } else if (mStorageManager
!= null
) {
1371 String parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
1372 return mStorageManager
.getFileByPath(parentPath
);