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
.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
;
141 private String mDownloadAddedMessage
;
142 private String mDownloadFinishMessage
;
145 protected void onCreate(Bundle savedInstanceState
) {
146 Log_OC
.d(TAG
, "onCreate() start");
147 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
149 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
151 mHandler
= new Handler();
153 FileDownloader downloader
= new FileDownloader();
154 mDownloadAddedMessage
= downloader
.getDownloadAddedMessage();
155 mDownloadFinishMessage
= downloader
.getDownloadFinishMessage();
157 /// bindings to transference services
158 mUploadConnection
= new ListServiceConnection();
159 mDownloadConnection
= new ListServiceConnection();
160 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
161 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
163 // PIN CODE request ; best location is to decide, let's try this first
164 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
169 Intent observer_intent
= new Intent(this, FileObserverService
.class);
170 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
171 startService(observer_intent
);
173 /// Load of saved instance state
174 if(savedInstanceState
!= null
) {
175 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
178 mWaitingToPreview
= null
;
183 // Inflate and set the layout view
184 setContentView(R
.layout
.files
);
185 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
186 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
187 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
188 if (savedInstanceState
== null
) {
189 createMinFragments();
193 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
194 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
195 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to work around bug in its implementation
199 Log_OC
.d(TAG
, "onCreate() end");
204 protected void onDestroy() {
206 if (mDownloadConnection
!= null
)
207 unbindService(mDownloadConnection
);
208 if (mUploadConnection
!= null
)
209 unbindService(mUploadConnection
);
214 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
217 protected void onAccountSet(boolean stateWasRecovered
) {
218 if (getAccount() != null
) {
219 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
221 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
222 OCFile file
= getFile();
224 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
225 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
226 if (mStorageManager
.getFileById(file
.getParentId()) == null
) {
227 file
= null
; // not able to know the directory where the file is uploading
230 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
234 // fall back to root folder
235 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
238 mDirectories
.clear();
239 OCFile fileIt
= file
;
240 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
241 if (fileIt
.isDirectory()) {
242 mDirectories
.add(fileIt
.getFileName());
244 fileIt
= mStorageManager
.getFileById(fileIt
.getParentId());
246 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
247 if (!stateWasRecovered
) {
248 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
249 initFragmentsWithFile();
252 updateFragmentsVisibility(!file
.isDirectory());
253 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
258 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
263 private void createMinFragments() {
264 OCFileListFragment listOfFiles
= new OCFileListFragment();
265 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
266 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
267 transaction
.commit();
270 private void initFragmentsWithFile() {
271 if (getAccount() != null
&& getFile() != null
) {
273 OCFileListFragment listOfFiles
= getListOfFilesFragment();
274 if (listOfFiles
!= null
) {
275 listOfFiles
.listDirectory(getCurrentDir());
277 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
281 OCFile file
= getFile();
282 Fragment secondFragment
= chooseInitialSecondFragment(file
);
283 if (secondFragment
!= null
) {
284 setSecondFragment(secondFragment
);
285 updateFragmentsVisibility(true
);
286 updateNavigationElementsInActionBar(file
);
289 cleanSecondFragment();
293 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
294 if (getAccount() == null
) {
295 Log
.wtf(TAG
, "\t account is NULL");
297 if (getFile() == null
) {
298 Log
.wtf(TAG
, "\t file is NULL");
303 private Fragment
chooseInitialSecondFragment(OCFile file
) {
304 Fragment secondFragment
= null
;
305 if (file
!= null
&& !file
.isDirectory()) {
306 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
307 && file
.getLastSyncDateForProperties() > 0 // temporal fix
309 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
310 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
311 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
314 secondFragment
= new FileDetailFragment(file
, getAccount());
317 return secondFragment
;
322 * Replaces the second fragment managed by the activity with the received as
325 * Assumes never will be more than two fragments managed at the same time.
327 * @param fragment New second Fragment to set.
329 private void setSecondFragment(Fragment fragment
) {
330 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
331 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
332 transaction
.commit();
336 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
338 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
339 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
341 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
342 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
345 } else if (existsSecondFragment
) {
346 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
347 mLeftFragmentContainer
.setVisibility(View
.GONE
);
349 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
350 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
354 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
355 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
357 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
358 mRightFragmentContainer
.setVisibility(View
.GONE
);
364 private OCFileListFragment
getListOfFilesFragment() {
365 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
366 if (listOfFiles
!= null
) {
367 return (OCFileListFragment
)listOfFiles
;
369 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
373 protected FileFragment
getSecondFragment() {
374 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
375 if (second
!= null
) {
376 return (FileFragment
)second
;
381 public void cleanSecondFragment() {
382 Fragment second
= getSecondFragment();
383 if (second
!= null
) {
384 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
388 updateFragmentsVisibility(false
);
389 updateNavigationElementsInActionBar(null
);
392 protected void refeshListOfFilesFragment() {
393 OCFileListFragment fileListFragment
= getListOfFilesFragment();
394 if (fileListFragment
!= null
) {
395 fileListFragment
.listDirectory();
399 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
400 FileFragment secondFragment
= getSecondFragment();
401 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
402 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
403 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
404 OCFile fileInFragment
= detailsFragment
.getFile();
405 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
406 // the user browsed to other file ; forget the automatic preview
407 mWaitingToPreview
= null
;
409 } else if (downloadEvent
.equals(mDownloadAddedMessage
)) {
410 // grant that the right panel updates the progress bar
411 detailsFragment
.listenForTransferProgress();
412 detailsFragment
.updateFileDetails(true
, false
);
414 } else if (downloadEvent
.equals(mDownloadFinishMessage
)) {
415 // update the right panel
416 boolean detailsFragmentChanged
= false
;
419 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
420 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
421 startMediaPreview(mWaitingToPreview
, 0, true
);
422 detailsFragmentChanged
= true
;
424 openFile(mWaitingToPreview
);
427 mWaitingToPreview
= null
;
429 if (!detailsFragmentChanged
) {
430 detailsFragment
.updateFileDetails(false
, (success
));
438 public boolean onCreateOptionsMenu(Menu menu
) {
439 MenuInflater inflater
= getSherlock().getMenuInflater();
440 inflater
.inflate(R
.menu
.main_menu
, menu
);
445 public boolean onOptionsItemSelected(MenuItem item
) {
446 boolean retval
= true
;
447 switch (item
.getItemId()) {
448 case R
.id
.action_create_dir
: {
449 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
450 dialog
.show(getSupportFragmentManager(), "createdirdialog");
453 case R
.id
.action_sync_account
: {
454 startSynchronization();
457 case R
.id
.action_upload
: {
458 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
461 case R
.id
.action_settings
: {
462 Intent settingsIntent
= new Intent(this, Preferences
.class);
463 startActivity(settingsIntent
);
466 case android
.R
.id
.home
: {
467 FileFragment second
= getSecondFragment();
468 OCFile currentDir
= getCurrentDir();
469 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
470 (second
!= null
&& second
.getFile() != null
)) {
476 retval
= super.onOptionsItemSelected(item
);
481 private void startSynchronization() {
482 ContentResolver
.cancelSync(null
, MainApp
.getAuthTokenType()); // cancel the current synchronizations of any ownCloud account
483 Bundle bundle
= new Bundle();
484 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
485 ContentResolver
.requestSync(
487 MainApp
.getAuthTokenType(), bundle
);
492 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
493 int i
= itemPosition
;
497 // the next operation triggers a new call to this method, but it's necessary to
498 // ensure that the name exposed in the action bar is the current directory when the
499 // user selected it in the navigation list
500 if (itemPosition
!= 0)
501 getSupportActionBar().setSelectedNavigationItem(0);
506 * Called, when the user selected something for uploading
508 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
509 super.onActivityResult(requestCode
, resultCode
, data
);
511 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
512 requestSimpleUpload(data
, resultCode
);
514 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
515 requestMultipleUpload(data
, resultCode
);
520 private void requestMultipleUpload(Intent data
, int resultCode
) {
521 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
522 if (filePaths
!= null
) {
523 String
[] remotePaths
= new String
[filePaths
.length
];
524 String remotePathBase
= "";
525 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
526 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
528 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
529 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
530 for (int j
= 0; j
< remotePaths
.length
; j
++) {
531 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
534 Intent i
= new Intent(this, FileUploader
.class);
535 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
536 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
537 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
538 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
539 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
540 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
544 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
545 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
552 private void requestSimpleUpload(Intent data
, int resultCode
) {
553 String filepath
= null
;
555 Uri selectedImageUri
= data
.getData();
557 String filemanagerstring
= selectedImageUri
.getPath();
558 String selectedImagePath
= getPath(selectedImageUri
);
560 if (selectedImagePath
!= null
)
561 filepath
= selectedImagePath
;
563 filepath
= filemanagerstring
;
565 } catch (Exception e
) {
566 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
570 if (filepath
== null
) {
571 Log_OC
.e(TAG
, "Couldnt resolve path to file");
572 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
578 Intent i
= new Intent(this, FileUploader
.class);
579 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
581 String remotepath
= new String();
582 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
583 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
585 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
586 remotepath
+= OCFile
.PATH_SEPARATOR
;
587 remotepath
+= new File(filepath
).getName();
589 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
590 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
591 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
592 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
593 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
598 public void onBackPressed() {
599 OCFileListFragment listOfFiles
= getListOfFilesFragment();
600 if (mDualPane
|| getSecondFragment() == null
) {
601 if (listOfFiles
!= null
) { // should never be null, indeed
602 if (mDirectories
.getCount() <= 1) {
607 listOfFiles
.onBrowseUp();
610 if (listOfFiles
!= null
) { // should never be null, indeed
611 setFile(listOfFiles
.getCurrentFile());
613 cleanSecondFragment();
617 protected void onSaveInstanceState(Bundle outState
) {
618 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
619 Log_OC
.e(TAG
, "onSaveInstanceState() start");
620 super.onSaveInstanceState(outState
);
621 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
622 Log_OC
.d(TAG
, "onSaveInstanceState() end");
628 protected void onResume() {
630 Log_OC
.e(TAG
, "onResume() start");
632 FileUploader fileUploader
= new FileUploader();
633 FileSyncService fileSyncService
= new FileSyncService();
635 // Listen for sync messages
636 IntentFilter syncIntentFilter
= new IntentFilter(fileSyncService
.getSyncMessage());
637 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
638 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
640 // Listen for upload messages
641 IntentFilter uploadIntentFilter
= new IntentFilter(fileUploader
.getUploadFinishMessage());
642 mUploadFinishReceiver
= new UploadFinishReceiver();
643 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
645 // Listen for download messages
646 IntentFilter downloadIntentFilter
= new IntentFilter(mDownloadAddedMessage
);
647 downloadIntentFilter
.addAction(mDownloadFinishMessage
);
648 mDownloadFinishReceiver
= new DownloadFinishReceiver();
649 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
651 Log_OC
.d(TAG
, "onResume() end");
656 protected void onPause() {
658 Log_OC
.e(TAG
, "onPause() start");
659 if (mSyncBroadcastReceiver
!= null
) {
660 unregisterReceiver(mSyncBroadcastReceiver
);
661 mSyncBroadcastReceiver
= null
;
663 if (mUploadFinishReceiver
!= null
) {
664 unregisterReceiver(mUploadFinishReceiver
);
665 mUploadFinishReceiver
= null
;
667 if (mDownloadFinishReceiver
!= null
) {
668 unregisterReceiver(mDownloadFinishReceiver
);
669 mDownloadFinishReceiver
= null
;
672 Log_OC
.d(TAG
, "onPause() end");
677 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
678 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
679 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
685 protected Dialog
onCreateDialog(int id
) {
686 Dialog dialog
= null
;
687 AlertDialog
.Builder builder
;
689 case DIALOG_SHORT_WAIT
: {
690 ProgressDialog working_dialog
= new ProgressDialog(this);
691 working_dialog
.setMessage(getResources().getString(
692 R
.string
.wait_a_moment
));
693 working_dialog
.setIndeterminate(true
);
694 working_dialog
.setCancelable(false
);
695 dialog
= working_dialog
;
698 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
700 String
[] items
= null
;
702 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
703 getString(R
.string
.actionbar_upload_from_apps
),
704 getString(R
.string
.actionbar_failed_instant_upload
) };
706 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
707 getString(R
.string
.actionbar_upload_from_apps
) };
709 if (InstantUploadActivity
.IS_ENABLED
)
714 builder
= new AlertDialog
.Builder(this);
715 builder
.setTitle(R
.string
.actionbar_upload
);
716 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
717 public void onClick(DialogInterface dialog
, int item
) {
720 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
721 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
722 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
724 // TODO create and handle new fragment
725 // LocalFileListFragment
727 } else if (item
== 1) {
728 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
729 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
730 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
731 ACTION_SELECT_CONTENT_FROM_APPS
);
732 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
733 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
734 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
735 startActivity(action
);
739 dialog
= builder
.create();
742 case DIALOG_SSL_VALIDATOR
: {
743 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
746 case DIALOG_CERT_NOT_SAVED
: {
747 builder
= new AlertDialog
.Builder(this);
748 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
749 builder
.setCancelable(false
);
750 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
752 public void onClick(DialogInterface dialog
, int which
) {
756 dialog
= builder
.create();
768 * Show loading dialog
770 public void showLoadingDialog() {
772 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
773 FragmentManager fm
= getSupportFragmentManager();
774 FragmentTransaction ft
= fm
.beginTransaction();
775 loading
.show(ft
, DIALOG_WAIT_TAG
);
780 * Dismiss loading dialog
782 public void dismissLoadingDialog(){
783 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
785 LoadingDialog loading
= (LoadingDialog
) frag
;
792 * Translates a content URI of an image to a physical path
794 * @param uri The URI to resolve
795 * @return The path to the image or null if it could not be found
797 public String
getPath(Uri uri
) {
798 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
799 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
800 if (cursor
!= null
) {
801 int column_index
= cursor
802 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
803 cursor
.moveToFirst();
804 return cursor
.getString(column_index
);
810 * Pushes a directory to the drop down list
811 * @param directory to push
812 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
814 public void pushDirname(OCFile directory
) {
815 if(!directory
.isDirectory()){
816 throw new IllegalArgumentException("Only directories may be pushed!");
818 mDirectories
.insert(directory
.getFileName(), 0);
823 * Pops a directory name from the drop down list
824 * @return True, unless the stack is empty
826 public boolean popDirname() {
827 mDirectories
.remove(mDirectories
.getItem(0));
828 return !mDirectories
.isEmpty();
831 // Custom array adapter to override text colors
832 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
834 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
838 public View
getView(int position
, View convertView
, ViewGroup parent
) {
839 View v
= super.getView(position
, convertView
, parent
);
841 ((TextView
) v
).setTextColor(getResources().getColorStateList(
842 android
.R
.color
.white
));
846 public View
getDropDownView(int position
, View convertView
,
848 View v
= super.getDropDownView(position
, convertView
, parent
);
850 ((TextView
) v
).setTextColor(getResources().getColorStateList(
851 android
.R
.color
.white
));
858 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
861 * {@link BroadcastReceiver} to enable syncing feedback in UI
864 public void onReceive(Context context
, Intent intent
) {
865 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
866 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
868 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
870 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
872 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
874 boolean fillBlankRoot
= false
;
875 OCFile currentDir
= getCurrentDir();
876 if (currentDir
== null
) {
877 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
878 fillBlankRoot
= (currentDir
!= null
);
881 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
884 currentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
885 OCFileListFragment fileListFragment
= getListOfFilesFragment();
886 if (fileListFragment
!= null
) {
887 fileListFragment
.listDirectory(currentDir
);
889 if (getSecondFragment() == null
)
893 setSupportProgressBarIndeterminateVisibility(inProgress
);
894 removeStickyBroadcast(intent
);
898 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
899 if (synchResult
!= null
) {
900 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
901 mLastSslUntrustedServerResult
= synchResult
;
902 showDialog(DIALOG_SSL_VALIDATOR
);
909 private class UploadFinishReceiver
extends BroadcastReceiver
{
911 * Once the file upload has finished -> update view
912 * @author David A. Velasco
913 * {@link BroadcastReceiver} to enable upload feedback in UI
916 public void onReceive(Context context
, Intent intent
) {
917 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
918 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
919 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
920 OCFile currentDir
= getCurrentDir();
921 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
922 if (sameAccount
&& isDescendant
) {
923 refeshListOfFilesFragment();
931 * Class waiting for broadcast events from the {@link FielDownloader} service.
933 * Updates the UI when a download is started or finished, provided that it is relevant for the
936 private class DownloadFinishReceiver
extends BroadcastReceiver
{
938 public void onReceive(Context context
, Intent intent
) {
939 boolean sameAccount
= isSameAccount(context
, intent
);
940 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
941 boolean isDescendant
= isDescendant(downloadedRemotePath
);
943 if (sameAccount
&& isDescendant
) {
944 refeshListOfFilesFragment();
945 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
948 removeStickyBroadcast(intent
);
951 private boolean isDescendant(String downloadedRemotePath
) {
952 OCFile currentDir
= getCurrentDir();
953 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
956 private boolean isSameAccount(Context context
, Intent intent
) {
957 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
958 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
967 public DataStorageManager
getStorageManager() {
968 return mStorageManager
;
975 * Updates action bar and second fragment, if in dual pane mode.
978 public void onBrowsedDownTo(OCFile directory
) {
979 pushDirname(directory
);
980 cleanSecondFragment();
984 * Opens the image gallery showing the image {@link OCFile} received as parameter.
986 * @param file Image {@link OCFile} to show.
989 public void startImagePreview(OCFile file
) {
990 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
991 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
992 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
993 startActivity(showDetailsIntent
);
997 * Stars the preview of an already down media {@link OCFile}.
999 * @param file Media {@link OCFile} to preview.
1000 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
1001 * @param autoplay When 'true', the playback will start without user interactions.
1004 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1005 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1006 setSecondFragment(mediaFragment
);
1007 updateFragmentsVisibility(true
);
1008 updateNavigationElementsInActionBar(file
);
1013 * Requests the download of the received {@link OCFile} , updates the UI
1014 * to monitor the download progress and prepares the activity to preview
1015 * or open the file when the download finishes.
1017 * @param file {@link OCFile} to download and preview.
1020 public void startDownloadForPreview(OCFile file
) {
1021 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1022 setSecondFragment(detailFragment
);
1023 mWaitingToPreview
= file
;
1024 requestForDownload();
1025 updateFragmentsVisibility(true
);
1026 updateNavigationElementsInActionBar(file
);
1032 * Shows the information of the {@link OCFile} received as a
1033 * parameter in the second fragment.
1035 * @param file {@link OCFile} whose details will be shown
1038 public void showDetails(OCFile file
) {
1039 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1040 setSecondFragment(detailFragment
);
1041 updateFragmentsVisibility(true
);
1042 updateNavigationElementsInActionBar(file
);
1050 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1051 ActionBar actionBar
= getSupportActionBar();
1052 if (chosenFile
== null
|| mDualPane
) {
1053 // only list of files - set for browsing through folders
1054 OCFile currentDir
= getCurrentDir();
1055 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1056 actionBar
.setDisplayShowTitleEnabled(false
);
1057 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1058 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1061 actionBar
.setDisplayHomeAsUpEnabled(true
);
1062 actionBar
.setDisplayShowTitleEnabled(true
);
1063 actionBar
.setTitle(chosenFile
.getFileName());
1064 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1073 public void onFileStateChanged() {
1074 refeshListOfFilesFragment();
1075 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1083 public FileDownloaderBinder
getFileDownloaderBinder() {
1084 return mDownloaderBinder
;
1092 public FileUploaderBinder
getFileUploaderBinder() {
1093 return mUploaderBinder
;
1097 /** Defines callbacks for service binding, passed to bindService() */
1098 private class ListServiceConnection
implements ServiceConnection
{
1101 public void onServiceConnected(ComponentName component
, IBinder service
) {
1102 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1103 Log_OC
.d(TAG
, "Download service connected");
1104 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1105 if (mWaitingToPreview
!= null
) {
1106 requestForDownload();
1109 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1110 Log_OC
.d(TAG
, "Upload service connected");
1111 mUploaderBinder
= (FileUploaderBinder
) service
;
1115 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1116 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1117 if (listOfFiles
!= null
) {
1118 listOfFiles
.listDirectory();
1120 FileFragment secondFragment
= getSecondFragment();
1121 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1122 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1123 detailFragment
.listenForTransferProgress();
1124 detailFragment
.updateFileDetails(false
, false
);
1129 public void onServiceDisconnected(ComponentName component
) {
1130 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1131 Log_OC
.d(TAG
, "Download service disconnected");
1132 mDownloaderBinder
= null
;
1133 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1134 Log_OC
.d(TAG
, "Upload service disconnected");
1135 mUploaderBinder
= null
;
1143 * Launch an intent to request the PIN code to the user before letting him use the app
1145 private void requestPinCode() {
1146 boolean pinStart
= false
;
1147 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1148 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1150 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1151 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1158 public void onSavedCertificate() {
1159 startSynchronization();
1164 public void onFailedSavingCertificate() {
1165 showDialog(DIALOG_CERT_NOT_SAVED
);
1170 * Updates the view associated to the activity after the finish of some operation over files
1171 * in the current account.
1173 * @param operation Removal operation performed.
1174 * @param result Result of the removal.
1177 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1178 if (operation
instanceof RemoveFileOperation
) {
1179 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1181 } else if (operation
instanceof RenameFileOperation
) {
1182 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1184 } else if (operation
instanceof SynchronizeFileOperation
) {
1185 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1187 } else if (operation
instanceof CreateFolderOperation
) {
1188 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1194 * Updates the view associated to the activity after the finish of an operation trying to remove a
1197 * @param operation Removal operation performed.
1198 * @param result Result of the removal.
1200 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1201 dismissLoadingDialog();
1202 if (result
.isSuccess()) {
1203 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1205 OCFile removedFile
= operation
.getFile();
1206 getSecondFragment();
1207 FileFragment second
= getSecondFragment();
1208 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1209 cleanSecondFragment();
1211 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1212 refeshListOfFilesFragment();
1216 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1218 if (result
.isSslRecoverableException()) {
1219 mLastSslUntrustedServerResult
= result
;
1220 showDialog(DIALOG_SSL_VALIDATOR
);
1226 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1228 * @param operation Creation operation performed.
1229 * @param result Result of the creation.
1231 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1232 if (result
.isSuccess()) {
1233 dismissLoadingDialog();
1234 refeshListOfFilesFragment();
1237 //dismissDialog(DIALOG_SHORT_WAIT);
1238 dismissLoadingDialog();
1240 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1243 } catch (NotFoundException e
) {
1244 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1251 * Updates the view associated to the activity after the finish of an operation trying to rename a
1254 * @param operation Renaming operation performed.
1255 * @param result Result of the renaming.
1257 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1258 dismissLoadingDialog();
1259 OCFile renamedFile
= operation
.getFile();
1260 if (result
.isSuccess()) {
1262 FileFragment details
= getSecondFragment();
1263 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1264 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1267 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1268 refeshListOfFilesFragment();
1272 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1273 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1275 // TODO throw again the new rename dialog
1277 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1279 if (result
.isSslRecoverableException()) {
1280 mLastSslUntrustedServerResult
= result
;
1281 showDialog(DIALOG_SSL_VALIDATOR
);
1288 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1289 dismissLoadingDialog();
1290 OCFile syncedFile
= operation
.getLocalFile();
1291 if (!result
.isSuccess()) {
1292 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1293 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1294 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1295 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1299 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1304 if (operation
.transferWasRequested()) {
1305 refeshListOfFilesFragment();
1306 onTransferStateChanged(syncedFile
, true
, true
);
1309 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1320 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1322 FileFragment details
= getSecondFragment();
1323 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1324 if (downloading
|| uploading
) {
1325 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1327 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1334 public void onDismiss(EditNameDialog dialog
) {
1335 if (dialog
.getResult()) {
1336 String newDirectoryName
= dialog
.getNewFilename().trim();
1337 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1338 if (newDirectoryName
.length() > 0) {
1339 String path
= getCurrentDir().getRemotePath();
1342 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1343 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1344 operation
.execute( getAccount(),
1345 FileDisplayActivity
.this,
1346 FileDisplayActivity
.this,
1348 FileDisplayActivity
.this);
1350 showLoadingDialog();
1356 private void requestForDownload() {
1357 Account account
= getAccount();
1358 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1359 Intent i
= new Intent(this, FileDownloader
.class);
1360 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1361 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1367 private OCFile
getCurrentDir() {
1368 OCFile file
= getFile();
1370 if (file
.isDirectory()) {
1372 } else if (mStorageManager
!= null
) {
1373 return mStorageManager
.getFileById(file
.getParentId());