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
.R
;
62 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
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
.PreviewMediaFragment
;
90 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
93 * Displays, what files the user has available in his ownCloud.
95 * @author Bartek Przybylski
96 * @author David A. Velasco
99 public class FileDisplayActivity
extends FileActivity
implements
100 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
102 private ArrayAdapter
<String
> mDirectories
;
104 /** Access point to the cached database for the current ownCloud {@link Account} */
105 private DataStorageManager mStorageManager
= null
;
107 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
108 private UploadFinishReceiver mUploadFinishReceiver
;
109 private DownloadFinishReceiver mDownloadFinishReceiver
;
110 private FileDownloaderBinder mDownloaderBinder
= null
;
111 private FileUploaderBinder mUploaderBinder
= null
;
112 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
113 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
115 private boolean mDualPane
;
116 private View mLeftFragmentContainer
;
117 private View mRightFragmentContainer
;
119 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
121 public static final int DIALOG_SHORT_WAIT
= 0;
122 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
123 private static final int DIALOG_SSL_VALIDATOR
= 2;
124 private static final int DIALOG_CERT_NOT_SAVED
= 3;
126 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
128 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
130 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
131 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
133 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
135 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
136 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
138 private OCFile mWaitingToPreview
;
139 private Handler mHandler
;
142 protected void onCreate(Bundle savedInstanceState
) {
143 Log_OC
.d(TAG
, "onCreate() start");
144 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
146 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
148 mHandler
= new Handler();
150 /// bindings to transference services
151 mUploadConnection
= new ListServiceConnection();
152 mDownloadConnection
= new ListServiceConnection();
153 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
154 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
156 // PIN CODE request ; best location is to decide, let's try this first
157 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
162 Intent observer_intent
= new Intent(this, FileObserverService
.class);
163 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
164 startService(observer_intent
);
166 /// Load of saved instance state
167 if(savedInstanceState
!= null
) {
168 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
171 mWaitingToPreview
= null
;
176 // Inflate and set the layout view
177 setContentView(R
.layout
.files
);
178 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
179 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
180 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
181 if (savedInstanceState
== null
) {
182 createMinFragments();
186 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
187 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
188 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to work around bug in its implementation
190 Log_OC
.d(TAG
, "onCreate() end");
195 protected void onDestroy() {
197 if (mDownloadConnection
!= null
)
198 unbindService(mDownloadConnection
);
199 if (mUploadConnection
!= null
)
200 unbindService(mUploadConnection
);
205 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
208 protected void onAccountSet(boolean stateWasRecovered
) {
209 if (getAccount() != null
) {
210 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
212 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
213 OCFile file
= getFile();
215 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
216 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
217 if (mStorageManager
.getFileById(file
.getParentId()) == null
) {
218 file
= null
; // not able to know the directory where the file is uploading
221 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
225 // fall back to root folder
226 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
229 mDirectories
.clear();
230 OCFile fileIt
= file
;
231 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
232 if (fileIt
.isDirectory()) {
233 mDirectories
.add(fileIt
.getFileName());
235 fileIt
= mStorageManager
.getFileById(fileIt
.getParentId());
237 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
238 if (!stateWasRecovered
) {
239 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
240 initFragmentsWithFile();
243 updateFragmentsVisibility(!file
.isDirectory());
244 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
249 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
254 private void createMinFragments() {
255 OCFileListFragment listOfFiles
= new OCFileListFragment();
256 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
257 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
258 transaction
.commit();
261 private void initFragmentsWithFile() {
262 if (getAccount() != null
&& getFile() != null
) {
264 OCFileListFragment listOfFiles
= getListOfFilesFragment();
265 if (listOfFiles
!= null
) {
266 listOfFiles
.listDirectory(getCurrentDir());
268 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
272 OCFile file
= getFile();
273 Fragment secondFragment
= chooseInitialSecondFragment(file
);
274 if (secondFragment
!= null
) {
275 setSecondFragment(secondFragment
);
276 updateFragmentsVisibility(true
);
277 updateNavigationElementsInActionBar(file
);
280 cleanSecondFragment();
284 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
285 if (getAccount() == null
) {
286 Log
.wtf(TAG
, "\t account is NULL");
288 if (getFile() == null
) {
289 Log
.wtf(TAG
, "\t file is NULL");
294 private Fragment
chooseInitialSecondFragment(OCFile file
) {
295 Fragment secondFragment
= null
;
296 if (file
!= null
&& !file
.isDirectory()) {
297 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
298 && file
.getLastSyncDateForProperties() > 0 // temporal fix
300 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
301 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
302 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
305 secondFragment
= new FileDetailFragment(file
, getAccount());
308 return secondFragment
;
313 * Replaces the second fragment managed by the activity with the received as
316 * Assumes never will be more than two fragments managed at the same time.
318 * @param fragment New second Fragment to set.
320 private void setSecondFragment(Fragment fragment
) {
321 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
322 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
323 transaction
.commit();
327 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
329 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
330 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
332 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
333 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
336 } else if (existsSecondFragment
) {
337 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
338 mLeftFragmentContainer
.setVisibility(View
.GONE
);
340 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
341 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
345 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
346 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
348 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
349 mRightFragmentContainer
.setVisibility(View
.GONE
);
355 private OCFileListFragment
getListOfFilesFragment() {
356 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
357 if (listOfFiles
!= null
) {
358 return (OCFileListFragment
)listOfFiles
;
360 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
364 protected FileFragment
getSecondFragment() {
365 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
366 if (second
!= null
) {
367 return (FileFragment
)second
;
372 public void cleanSecondFragment() {
373 Fragment second
= getSecondFragment();
374 if (second
!= null
) {
375 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
379 updateFragmentsVisibility(false
);
380 updateNavigationElementsInActionBar(null
);
383 protected void refeshListOfFilesFragment() {
384 OCFileListFragment fileListFragment
= getListOfFilesFragment();
385 if (fileListFragment
!= null
) {
386 fileListFragment
.listDirectory();
390 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
391 FileFragment secondFragment
= getSecondFragment();
392 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
393 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
394 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
395 OCFile fileInFragment
= detailsFragment
.getFile();
396 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
397 // the user browsed to other file ; forget the automatic preview
398 mWaitingToPreview
= null
;
400 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
401 // grant that the right panel updates the progress bar
402 detailsFragment
.listenForTransferProgress();
403 detailsFragment
.updateFileDetails(true
, false
);
405 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
406 // update the right panel
407 boolean detailsFragmentChanged
= false
;
410 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
411 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
412 startMediaPreview(mWaitingToPreview
, 0, true
);
413 detailsFragmentChanged
= true
;
415 openFile(mWaitingToPreview
);
418 mWaitingToPreview
= null
;
420 if (!detailsFragmentChanged
) {
421 detailsFragment
.updateFileDetails(false
, (success
));
429 public boolean onCreateOptionsMenu(Menu menu
) {
430 MenuInflater inflater
= getSherlock().getMenuInflater();
431 inflater
.inflate(R
.menu
.main_menu
, menu
);
436 public boolean onOptionsItemSelected(MenuItem item
) {
437 boolean retval
= true
;
438 switch (item
.getItemId()) {
439 case R
.id
.action_create_dir
: {
440 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
441 dialog
.show(getSupportFragmentManager(), "createdirdialog");
444 case R
.id
.action_sync_account
: {
445 startSynchronization();
448 case R
.id
.action_upload
: {
449 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
452 case R
.id
.action_settings
: {
453 Intent settingsIntent
= new Intent(this, Preferences
.class);
454 startActivity(settingsIntent
);
457 case android
.R
.id
.home
: {
458 FileFragment second
= getSecondFragment();
459 OCFile currentDir
= getCurrentDir();
460 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
461 (second
!= null
&& second
.getFile() != null
)) {
467 retval
= super.onOptionsItemSelected(item
);
472 private void startSynchronization() {
473 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
474 Bundle bundle
= new Bundle();
475 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
476 ContentResolver
.requestSync(
478 AccountAuthenticator
.AUTHORITY
, bundle
);
483 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
484 int i
= itemPosition
;
488 // the next operation triggers a new call to this method, but it's necessary to
489 // ensure that the name exposed in the action bar is the current directory when the
490 // user selected it in the navigation list
491 if (itemPosition
!= 0)
492 getSupportActionBar().setSelectedNavigationItem(0);
497 * Called, when the user selected something for uploading
499 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
500 super.onActivityResult(requestCode
, resultCode
, data
);
502 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
503 requestSimpleUpload(data
, resultCode
);
505 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
506 requestMultipleUpload(data
, resultCode
);
511 private void requestMultipleUpload(Intent data
, int resultCode
) {
512 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
513 if (filePaths
!= null
) {
514 String
[] remotePaths
= new String
[filePaths
.length
];
515 String remotePathBase
= "";
516 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
517 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
519 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
520 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
521 for (int j
= 0; j
< remotePaths
.length
; j
++) {
522 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
525 Intent i
= new Intent(this, FileUploader
.class);
526 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
527 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
528 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
529 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
530 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
531 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
535 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
536 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
543 private void requestSimpleUpload(Intent data
, int resultCode
) {
544 String filepath
= null
;
546 Uri selectedImageUri
= data
.getData();
548 String filemanagerstring
= selectedImageUri
.getPath();
549 String selectedImagePath
= getPath(selectedImageUri
);
551 if (selectedImagePath
!= null
)
552 filepath
= selectedImagePath
;
554 filepath
= filemanagerstring
;
556 } catch (Exception e
) {
557 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
561 if (filepath
== null
) {
562 Log_OC
.e(TAG
, "Couldnt resolve path to file");
563 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
569 Intent i
= new Intent(this, FileUploader
.class);
570 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
572 String remotepath
= new String();
573 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
574 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
576 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
577 remotepath
+= OCFile
.PATH_SEPARATOR
;
578 remotepath
+= new File(filepath
).getName();
580 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
581 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
582 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
583 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
584 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
589 public void onBackPressed() {
590 OCFileListFragment listOfFiles
= getListOfFilesFragment();
591 if (mDualPane
|| getSecondFragment() == null
) {
592 if (listOfFiles
!= null
) { // should never be null, indeed
593 if (mDirectories
.getCount() <= 1) {
598 listOfFiles
.onBrowseUp();
601 if (listOfFiles
!= null
) { // should never be null, indeed
602 setFile(listOfFiles
.getCurrentFile());
604 cleanSecondFragment();
608 protected void onSaveInstanceState(Bundle outState
) {
609 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
610 Log_OC
.e(TAG
, "onSaveInstanceState() start");
611 super.onSaveInstanceState(outState
);
612 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
613 Log_OC
.d(TAG
, "onSaveInstanceState() end");
619 protected void onResume() {
621 Log_OC
.e(TAG
, "onResume() start");
623 // Listen for sync messages
624 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
625 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
626 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
628 // Listen for upload messages
629 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
630 mUploadFinishReceiver
= new UploadFinishReceiver();
631 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
633 // Listen for download messages
634 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
635 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
636 mDownloadFinishReceiver
= new DownloadFinishReceiver();
637 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
639 Log_OC
.d(TAG
, "onResume() end");
644 protected void onPause() {
646 Log_OC
.e(TAG
, "onPause() start");
647 if (mSyncBroadcastReceiver
!= null
) {
648 unregisterReceiver(mSyncBroadcastReceiver
);
649 mSyncBroadcastReceiver
= null
;
651 if (mUploadFinishReceiver
!= null
) {
652 unregisterReceiver(mUploadFinishReceiver
);
653 mUploadFinishReceiver
= null
;
655 if (mDownloadFinishReceiver
!= null
) {
656 unregisterReceiver(mDownloadFinishReceiver
);
657 mDownloadFinishReceiver
= null
;
660 Log_OC
.d(TAG
, "onPause() end");
665 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
666 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
667 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
673 protected Dialog
onCreateDialog(int id
) {
674 Dialog dialog
= null
;
675 AlertDialog
.Builder builder
;
677 case DIALOG_SHORT_WAIT
: {
678 ProgressDialog working_dialog
= new ProgressDialog(this);
679 working_dialog
.setMessage(getResources().getString(
680 R
.string
.wait_a_moment
));
681 working_dialog
.setIndeterminate(true
);
682 working_dialog
.setCancelable(false
);
683 dialog
= working_dialog
;
686 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
688 String
[] items
= null
;
690 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
691 getString(R
.string
.actionbar_upload_from_apps
),
692 getString(R
.string
.actionbar_failed_instant_upload
) };
694 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
695 getString(R
.string
.actionbar_upload_from_apps
) };
697 if (InstantUploadActivity
.IS_ENABLED
)
702 builder
= new AlertDialog
.Builder(this);
703 builder
.setTitle(R
.string
.actionbar_upload
);
704 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
705 public void onClick(DialogInterface dialog
, int item
) {
708 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
709 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
710 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
712 // TODO create and handle new fragment
713 // LocalFileListFragment
715 } else if (item
== 1) {
716 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
717 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
718 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
719 ACTION_SELECT_CONTENT_FROM_APPS
);
720 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
721 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
722 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
723 startActivity(action
);
727 dialog
= builder
.create();
730 case DIALOG_SSL_VALIDATOR
: {
731 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
734 case DIALOG_CERT_NOT_SAVED
: {
735 builder
= new AlertDialog
.Builder(this);
736 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
737 builder
.setCancelable(false
);
738 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
740 public void onClick(DialogInterface dialog
, int which
) {
744 dialog
= builder
.create();
756 * Show loading dialog
758 public void showLoadingDialog() {
760 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
761 FragmentManager fm
= getSupportFragmentManager();
762 FragmentTransaction ft
= fm
.beginTransaction();
763 loading
.show(ft
, DIALOG_WAIT_TAG
);
768 * Dismiss loading dialog
770 public void dismissLoadingDialog(){
771 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
773 LoadingDialog loading
= (LoadingDialog
) frag
;
780 * Translates a content URI of an image to a physical path
782 * @param uri The URI to resolve
783 * @return The path to the image or null if it could not be found
785 public String
getPath(Uri uri
) {
786 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
787 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
788 if (cursor
!= null
) {
789 int column_index
= cursor
790 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
791 cursor
.moveToFirst();
792 return cursor
.getString(column_index
);
798 * Pushes a directory to the drop down list
799 * @param directory to push
800 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
802 public void pushDirname(OCFile directory
) {
803 if(!directory
.isDirectory()){
804 throw new IllegalArgumentException("Only directories may be pushed!");
806 mDirectories
.insert(directory
.getFileName(), 0);
811 * Pops a directory name from the drop down list
812 * @return True, unless the stack is empty
814 public boolean popDirname() {
815 mDirectories
.remove(mDirectories
.getItem(0));
816 return !mDirectories
.isEmpty();
819 // Custom array adapter to override text colors
820 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
822 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
826 public View
getView(int position
, View convertView
, ViewGroup parent
) {
827 View v
= super.getView(position
, convertView
, parent
);
829 ((TextView
) v
).setTextColor(getResources().getColorStateList(
830 android
.R
.color
.white
));
834 public View
getDropDownView(int position
, View convertView
,
836 View v
= super.getDropDownView(position
, convertView
, parent
);
838 ((TextView
) v
).setTextColor(getResources().getColorStateList(
839 android
.R
.color
.white
));
846 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
849 * {@link BroadcastReceiver} to enable syncing feedback in UI
852 public void onReceive(Context context
, Intent intent
) {
853 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
854 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
856 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
858 if (getAccount() != null
&& accountName
.equals(getAccount().name
)
859 && mStorageManager
!= null
862 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
864 boolean fillBlankRoot
= false
;
865 OCFile currentDir
= getCurrentDir();
866 if (currentDir
== null
) {
867 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
868 fillBlankRoot
= (currentDir
!= null
);
871 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
874 currentDir
= mStorageManager
.getFileByPath(synchFolderRemotePath
);
875 OCFileListFragment fileListFragment
= getListOfFilesFragment();
876 if (fileListFragment
!= null
) {
877 fileListFragment
.listDirectory(currentDir
);
879 if (getSecondFragment() == null
)
883 setSupportProgressBarIndeterminateVisibility(inProgress
);
884 removeStickyBroadcast(intent
);
888 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
889 if (synchResult
!= null
) {
890 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
891 mLastSslUntrustedServerResult
= synchResult
;
892 showDialog(DIALOG_SSL_VALIDATOR
);
899 private class UploadFinishReceiver
extends BroadcastReceiver
{
901 * Once the file upload has finished -> update view
902 * @author David A. Velasco
903 * {@link BroadcastReceiver} to enable upload feedback in UI
906 public void onReceive(Context context
, Intent intent
) {
907 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
908 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
909 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
910 OCFile currentDir
= getCurrentDir();
911 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
912 if (sameAccount
&& isDescendant
) {
913 refeshListOfFilesFragment();
921 * Class waiting for broadcast events from the {@link FielDownloader} service.
923 * Updates the UI when a download is started or finished, provided that it is relevant for the
926 private class DownloadFinishReceiver
extends BroadcastReceiver
{
928 public void onReceive(Context context
, Intent intent
) {
929 boolean sameAccount
= isSameAccount(context
, intent
);
930 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
931 boolean isDescendant
= isDescendant(downloadedRemotePath
);
933 if (sameAccount
&& isDescendant
) {
934 refeshListOfFilesFragment();
935 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
938 removeStickyBroadcast(intent
);
941 private boolean isDescendant(String downloadedRemotePath
) {
942 OCFile currentDir
= getCurrentDir();
943 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
946 private boolean isSameAccount(Context context
, Intent intent
) {
947 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
948 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
957 public DataStorageManager
getStorageManager() {
958 return mStorageManager
;
965 * Updates action bar and second fragment, if in dual pane mode.
968 public void onBrowsedDownTo(OCFile directory
) {
969 pushDirname(directory
);
970 cleanSecondFragment();
974 * Opens the image gallery showing the image {@link OCFile} received as parameter.
976 * @param file Image {@link OCFile} to show.
979 public void startImagePreview(OCFile file
) {
980 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
981 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
982 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
983 startActivity(showDetailsIntent
);
987 * Stars the preview of an already down media {@link OCFile}.
989 * @param file Media {@link OCFile} to preview.
990 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
991 * @param autoplay When 'true', the playback will start without user interactions.
994 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
995 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
996 setSecondFragment(mediaFragment
);
997 updateFragmentsVisibility(true
);
998 updateNavigationElementsInActionBar(file
);
1003 * Requests the download of the received {@link OCFile} , updates the UI
1004 * to monitor the download progress and prepares the activity to preview
1005 * or open the file when the download finishes.
1007 * @param file {@link OCFile} to download and preview.
1010 public void startDownloadForPreview(OCFile file
) {
1011 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1012 setSecondFragment(detailFragment
);
1013 mWaitingToPreview
= file
;
1014 requestForDownload();
1015 updateFragmentsVisibility(true
);
1016 updateNavigationElementsInActionBar(file
);
1022 * Shows the information of the {@link OCFile} received as a
1023 * parameter in the second fragment.
1025 * @param file {@link OCFile} whose details will be shown
1028 public void showDetails(OCFile file
) {
1029 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1030 setSecondFragment(detailFragment
);
1031 updateFragmentsVisibility(true
);
1032 updateNavigationElementsInActionBar(file
);
1040 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1041 ActionBar actionBar
= getSupportActionBar();
1042 if (chosenFile
== null
|| mDualPane
) {
1043 // only list of files - set for browsing through folders
1044 OCFile currentDir
= getCurrentDir();
1045 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1046 actionBar
.setDisplayShowTitleEnabled(false
);
1047 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1048 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1051 actionBar
.setDisplayHomeAsUpEnabled(true
);
1052 actionBar
.setDisplayShowTitleEnabled(true
);
1053 actionBar
.setTitle(chosenFile
.getFileName());
1054 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1063 public void onFileStateChanged() {
1064 refeshListOfFilesFragment();
1065 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1073 public FileDownloaderBinder
getFileDownloaderBinder() {
1074 return mDownloaderBinder
;
1082 public FileUploaderBinder
getFileUploaderBinder() {
1083 return mUploaderBinder
;
1087 /** Defines callbacks for service binding, passed to bindService() */
1088 private class ListServiceConnection
implements ServiceConnection
{
1091 public void onServiceConnected(ComponentName component
, IBinder service
) {
1092 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1093 Log_OC
.d(TAG
, "Download service connected");
1094 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1095 if (mWaitingToPreview
!= null
) {
1096 requestForDownload();
1099 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1100 Log_OC
.d(TAG
, "Upload service connected");
1101 mUploaderBinder
= (FileUploaderBinder
) service
;
1105 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1106 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1107 if (listOfFiles
!= null
) {
1108 listOfFiles
.listDirectory();
1110 FileFragment secondFragment
= getSecondFragment();
1111 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1112 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1113 detailFragment
.listenForTransferProgress();
1114 detailFragment
.updateFileDetails(false
, false
);
1119 public void onServiceDisconnected(ComponentName component
) {
1120 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1121 Log_OC
.d(TAG
, "Download service disconnected");
1122 mDownloaderBinder
= null
;
1123 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1124 Log_OC
.d(TAG
, "Upload service disconnected");
1125 mUploaderBinder
= null
;
1133 * Launch an intent to request the PIN code to the user before letting him use the app
1135 private void requestPinCode() {
1136 boolean pinStart
= false
;
1137 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1138 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1140 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1141 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1148 public void onSavedCertificate() {
1149 startSynchronization();
1154 public void onFailedSavingCertificate() {
1155 showDialog(DIALOG_CERT_NOT_SAVED
);
1160 * Updates the view associated to the activity after the finish of some operation over files
1161 * in the current account.
1163 * @param operation Removal operation performed.
1164 * @param result Result of the removal.
1167 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1168 if (operation
instanceof RemoveFileOperation
) {
1169 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1171 } else if (operation
instanceof RenameFileOperation
) {
1172 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1174 } else if (operation
instanceof SynchronizeFileOperation
) {
1175 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1177 } else if (operation
instanceof CreateFolderOperation
) {
1178 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1184 * Updates the view associated to the activity after the finish of an operation trying to remove a
1187 * @param operation Removal operation performed.
1188 * @param result Result of the removal.
1190 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1191 dismissLoadingDialog();
1192 if (result
.isSuccess()) {
1193 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1195 OCFile removedFile
= operation
.getFile();
1196 getSecondFragment();
1197 FileFragment second
= getSecondFragment();
1198 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1199 cleanSecondFragment();
1201 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1202 refeshListOfFilesFragment();
1206 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1208 if (result
.isSslRecoverableException()) {
1209 mLastSslUntrustedServerResult
= result
;
1210 showDialog(DIALOG_SSL_VALIDATOR
);
1216 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1218 * @param operation Creation operation performed.
1219 * @param result Result of the creation.
1221 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1222 if (result
.isSuccess()) {
1223 dismissLoadingDialog();
1224 refeshListOfFilesFragment();
1227 //dismissDialog(DIALOG_SHORT_WAIT);
1228 dismissLoadingDialog();
1230 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1233 } catch (NotFoundException e
) {
1234 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1241 * Updates the view associated to the activity after the finish of an operation trying to rename a
1244 * @param operation Renaming operation performed.
1245 * @param result Result of the renaming.
1247 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1248 dismissLoadingDialog();
1249 OCFile renamedFile
= operation
.getFile();
1250 if (result
.isSuccess()) {
1252 FileFragment details
= getSecondFragment();
1253 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1254 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1257 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1258 refeshListOfFilesFragment();
1262 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1263 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1265 // TODO throw again the new rename dialog
1267 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1269 if (result
.isSslRecoverableException()) {
1270 mLastSslUntrustedServerResult
= result
;
1271 showDialog(DIALOG_SSL_VALIDATOR
);
1278 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1279 dismissLoadingDialog();
1280 OCFile syncedFile
= operation
.getLocalFile();
1281 if (!result
.isSuccess()) {
1282 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1283 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1284 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1285 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1289 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1294 if (operation
.transferWasRequested()) {
1295 refeshListOfFilesFragment();
1296 onTransferStateChanged(syncedFile
, true
, true
);
1299 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1310 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1312 FileFragment details
= getSecondFragment();
1313 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1314 if (downloading
|| uploading
) {
1315 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1317 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1324 public void onDismiss(EditNameDialog dialog
) {
1325 if (dialog
.getResult()) {
1326 String newDirectoryName
= dialog
.getNewFilename().trim();
1327 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1328 if (newDirectoryName
.length() > 0) {
1329 String path
= getCurrentDir().getRemotePath();
1332 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1333 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1334 operation
.execute( getAccount(),
1335 FileDisplayActivity
.this,
1336 FileDisplayActivity
.this,
1338 FileDisplayActivity
.this);
1340 showLoadingDialog();
1346 private void requestForDownload() {
1347 Account account
= getAccount();
1348 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1349 Intent i
= new Intent(this, FileDownloader
.class);
1350 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1351 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1357 private OCFile
getCurrentDir() {
1358 OCFile file
= getFile();
1360 if (file
.isDirectory()) {
1362 } else if (mStorageManager
!= null
) {
1363 return mStorageManager
.getFileById(file
.getParentId());