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
.FragmentTransaction
;
46 import android
.util
.Log
;
47 import android
.view
.View
;
48 import android
.view
.ViewGroup
;
49 import android
.widget
.ArrayAdapter
;
50 import android
.widget
.TextView
;
51 import android
.widget
.Toast
;
53 import com
.actionbarsherlock
.app
.ActionBar
;
54 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
55 import com
.actionbarsherlock
.view
.Menu
;
56 import com
.actionbarsherlock
.view
.MenuInflater
;
57 import com
.actionbarsherlock
.view
.MenuItem
;
58 import com
.actionbarsherlock
.view
.Window
;
59 import com
.owncloud
.android
.Log_OC
;
60 import com
.owncloud
.android
.R
;
61 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
62 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
63 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
64 import com
.owncloud
.android
.datamodel
.OCFile
;
65 import com
.owncloud
.android
.files
.services
.FileDownloader
;
66 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
67 import com
.owncloud
.android
.files
.services
.FileObserverService
;
68 import com
.owncloud
.android
.files
.services
.FileUploader
;
69 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
70 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
71 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
72 import com
.owncloud
.android
.operations
.RemoteOperation
;
73 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
74 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
75 import com
.owncloud
.android
.operations
.RenameFileOperation
;
76 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
77 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
78 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
79 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
80 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
81 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
82 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
83 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
84 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
85 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
86 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
87 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
88 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
91 * Displays, what files the user has available in his ownCloud.
93 * @author Bartek Przybylski
94 * @author David A. Velasco
97 public class FileDisplayActivity
extends FileActivity
implements
98 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
100 private ArrayAdapter
<String
> mDirectories
;
102 /** Access point to the cached database for the current ownCloud {@link Account} */
103 private DataStorageManager mStorageManager
= null
;
105 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
106 private UploadFinishReceiver mUploadFinishReceiver
;
107 private DownloadFinishReceiver mDownloadFinishReceiver
;
108 private FileDownloaderBinder mDownloaderBinder
= null
;
109 private FileUploaderBinder mUploaderBinder
= null
;
110 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
111 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
113 private boolean mDualPane
;
114 private View mLeftFragmentContainer
;
115 private View mRightFragmentContainer
;
117 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
119 public static final int DIALOG_SHORT_WAIT
= 0;
120 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
121 private static final int DIALOG_SSL_VALIDATOR
= 2;
122 private static final int DIALOG_CERT_NOT_SAVED
= 3;
124 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
126 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
127 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
129 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
131 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
132 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
134 private OCFile mWaitingToPreview
;
135 private Handler mHandler
;
138 protected void onCreate(Bundle savedInstanceState
) {
139 Log_OC
.d(TAG
, "onCreate() start");
140 super.onCreate(savedInstanceState
);
142 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
144 mHandler
= new Handler();
146 /// bindings to transference services
147 mUploadConnection
= new ListServiceConnection();
148 mDownloadConnection
= new ListServiceConnection();
149 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
150 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
152 // PIN CODE request ; best location is to decide, let's try this first
153 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
158 Intent observer_intent
= new Intent(this, FileObserverService
.class);
159 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
160 startService(observer_intent
);
162 /// Load of saved instance state
163 if(savedInstanceState
!= null
) {
164 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
167 mWaitingToPreview
= null
;
172 // Inflate and set the layout view
173 setContentView(R
.layout
.files
);
174 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
175 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
176 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
177 if (savedInstanceState
== null
) {
178 createMinFragments();
182 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
183 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
184 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to work around bug in its implementation
186 Log_OC
.d(TAG
, "onCreate() end");
191 protected void onDestroy() {
193 if (mDownloadConnection
!= null
)
194 unbindService(mDownloadConnection
);
195 if (mUploadConnection
!= null
)
196 unbindService(mUploadConnection
);
201 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
204 protected void onAccountSet(boolean stateWasRecovered
) {
205 if (getAccount() != null
) {
206 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
208 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
209 OCFile file
= getFile();
211 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
214 // fall back to root folder
215 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
218 mDirectories
.clear();
219 OCFile fileIt
= file
;
220 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
221 if (fileIt
.isDirectory()) {
222 mDirectories
.add(fileIt
.getFileName());
224 fileIt
= mStorageManager
.getFileById(fileIt
.getParentId());
226 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
227 if (!stateWasRecovered
) {
228 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
229 initFragmentsWithFile();
232 updateFragmentsVisibility(!file
.isDirectory());
233 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
238 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
243 private void createMinFragments() {
244 OCFileListFragment listOfFiles
= new OCFileListFragment();
245 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
246 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
247 transaction
.commit();
250 private void initFragmentsWithFile() {
251 if (getAccount() != null
&& getFile() != null
) {
253 OCFileListFragment listOfFiles
= getListOfFilesFragment();
254 if (listOfFiles
!= null
) {
255 listOfFiles
.listDirectory(getCurrentDir());
257 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
261 OCFile file
= getFile();
262 Fragment secondFragment
= chooseInitialSecondFragment(file
);
263 if (secondFragment
!= null
) {
264 setSecondFragment(secondFragment
);
265 updateFragmentsVisibility(true
);
266 updateNavigationElementsInActionBar(file
);
269 cleanSecondFragment();
273 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
274 if (getAccount() == null
) {
275 Log
.wtf(TAG
, "\t account is NULL");
277 if (getFile() == null
) {
278 Log
.wtf(TAG
, "\t file is NULL");
283 private Fragment
chooseInitialSecondFragment(OCFile file
) {
284 Fragment secondFragment
= null
;
285 if (file
!= null
&& !file
.isDirectory()) {
286 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)) {
287 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
288 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
289 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
292 secondFragment
= new FileDetailFragment(file
, getAccount());
295 return secondFragment
;
300 * Replaces the second fragment managed by the activity with the received as
303 * Assumes never will be more than two fragments managed at the same time.
305 * @param fragment New second Fragment to set.
307 private void setSecondFragment(Fragment fragment
) {
308 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
309 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
310 transaction
.commit();
314 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
316 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
317 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
319 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
320 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
323 } else if (existsSecondFragment
) {
324 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
325 mLeftFragmentContainer
.setVisibility(View
.GONE
);
327 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
328 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
332 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
333 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
335 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
336 mRightFragmentContainer
.setVisibility(View
.GONE
);
342 private OCFileListFragment
getListOfFilesFragment() {
343 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
344 if (listOfFiles
!= null
) {
345 return (OCFileListFragment
)listOfFiles
;
347 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
351 protected FileFragment
getSecondFragment() {
352 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
353 if (second
!= null
) {
354 return (FileFragment
)second
;
359 public void cleanSecondFragment() {
360 Fragment second
= getSecondFragment();
361 if (second
!= null
) {
362 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
366 updateFragmentsVisibility(false
);
367 updateNavigationElementsInActionBar(null
);
370 protected void refeshListOfFilesFragment() {
371 OCFileListFragment fileListFragment
= getListOfFilesFragment();
372 if (fileListFragment
!= null
) {
373 fileListFragment
.listDirectory();
377 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
378 FileFragment secondFragment
= getSecondFragment();
379 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
380 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
381 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
382 OCFile fileInFragment
= detailsFragment
.getFile();
383 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
384 // the user browsed to other file ; forget the automatic preview
385 mWaitingToPreview
= null
;
387 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
388 // grant that the right panel updates the progress bar
389 detailsFragment
.listenForTransferProgress();
390 detailsFragment
.updateFileDetails(true
, false
);
392 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
393 // update the right panel
394 boolean detailsFragmentChanged
= false
;
397 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
398 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
399 startMediaPreview(mWaitingToPreview
, 0, true
);
400 detailsFragmentChanged
= true
;
402 openFile(mWaitingToPreview
);
405 mWaitingToPreview
= null
;
407 if (!detailsFragmentChanged
) {
408 detailsFragment
.updateFileDetails(false
, (success
));
416 public boolean onCreateOptionsMenu(Menu menu
) {
417 MenuInflater inflater
= getSherlock().getMenuInflater();
418 inflater
.inflate(R
.menu
.main_menu
, menu
);
423 public boolean onOptionsItemSelected(MenuItem item
) {
424 boolean retval
= true
;
425 switch (item
.getItemId()) {
426 case R
.id
.action_create_dir
: {
427 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
428 dialog
.show(getSupportFragmentManager(), "createdirdialog");
431 case R
.id
.action_sync_account
: {
432 startSynchronization();
435 case R
.id
.action_upload
: {
436 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
439 case R
.id
.action_settings
: {
440 Intent settingsIntent
= new Intent(this, Preferences
.class);
441 startActivity(settingsIntent
);
444 case android
.R
.id
.home
: {
445 FileFragment second
= getSecondFragment();
446 OCFile currentDir
= getCurrentDir();
447 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
448 (second
!= null
&& second
.getFile() != null
)) {
454 retval
= super.onOptionsItemSelected(item
);
459 private void startSynchronization() {
460 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
461 Bundle bundle
= new Bundle();
462 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
463 ContentResolver
.requestSync(
465 AccountAuthenticator
.AUTHORITY
, bundle
);
470 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
471 int i
= itemPosition
;
475 // the next operation triggers a new call to this method, but it's necessary to
476 // ensure that the name exposed in the action bar is the current directory when the
477 // user selected it in the navigation list
478 if (itemPosition
!= 0)
479 getSupportActionBar().setSelectedNavigationItem(0);
484 * Called, when the user selected something for uploading
486 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
487 super.onActivityResult(requestCode
, resultCode
, data
);
489 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
490 requestSimpleUpload(data
, resultCode
);
492 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
493 requestMultipleUpload(data
, resultCode
);
498 private void requestMultipleUpload(Intent data
, int resultCode
) {
499 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
500 if (filePaths
!= null
) {
501 String
[] remotePaths
= new String
[filePaths
.length
];
502 String remotePathBase
= "";
503 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
504 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
506 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
507 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
508 for (int j
= 0; j
< remotePaths
.length
; j
++) {
509 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
512 Intent i
= new Intent(this, FileUploader
.class);
513 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
514 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
515 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
516 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
517 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
518 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
522 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
523 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
530 private void requestSimpleUpload(Intent data
, int resultCode
) {
531 String filepath
= null
;
533 Uri selectedImageUri
= data
.getData();
535 String filemanagerstring
= selectedImageUri
.getPath();
536 String selectedImagePath
= getPath(selectedImageUri
);
538 if (selectedImagePath
!= null
)
539 filepath
= selectedImagePath
;
541 filepath
= filemanagerstring
;
543 } catch (Exception e
) {
544 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
548 if (filepath
== null
) {
549 Log_OC
.e(TAG
, "Couldnt resolve path to file");
550 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
556 Intent i
= new Intent(this, FileUploader
.class);
557 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
559 String remotepath
= new String();
560 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
561 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
563 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
564 remotepath
+= OCFile
.PATH_SEPARATOR
;
565 remotepath
+= new File(filepath
).getName();
567 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
568 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
569 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
570 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
571 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
576 public void onBackPressed() {
577 OCFileListFragment listOfFiles
= getListOfFilesFragment();
578 if (mDualPane
|| getSecondFragment() == null
) {
579 if (listOfFiles
!= null
) { // should never be null, indeed
580 if (mDirectories
.getCount() <= 1) {
585 listOfFiles
.onBrowseUp();
588 if (listOfFiles
!= null
) { // should never be null, indeed
589 setFile(listOfFiles
.getCurrentFile());
591 cleanSecondFragment();
595 protected void onSaveInstanceState(Bundle outState
) {
596 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
597 Log_OC
.e(TAG
, "onSaveInstanceState() start");
598 super.onSaveInstanceState(outState
);
599 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
600 Log_OC
.d(TAG
, "onSaveInstanceState() end");
605 protected void onResume() {
607 Log_OC
.e(TAG
, "onResume() start");
609 // Listen for sync messages
610 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
611 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
612 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
614 // Listen for upload messages
615 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
616 mUploadFinishReceiver
= new UploadFinishReceiver();
617 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
619 // Listen for download messages
620 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
621 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
622 mDownloadFinishReceiver
= new DownloadFinishReceiver();
623 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
625 Log_OC
.d(TAG
, "onResume() end");
630 protected void onPause() {
632 Log_OC
.e(TAG
, "onPause() start");
633 if (mSyncBroadcastReceiver
!= null
) {
634 unregisterReceiver(mSyncBroadcastReceiver
);
635 mSyncBroadcastReceiver
= null
;
637 if (mUploadFinishReceiver
!= null
) {
638 unregisterReceiver(mUploadFinishReceiver
);
639 mUploadFinishReceiver
= null
;
641 if (mDownloadFinishReceiver
!= null
) {
642 unregisterReceiver(mDownloadFinishReceiver
);
643 mDownloadFinishReceiver
= null
;
646 Log_OC
.d(TAG
, "onPause() end");
651 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
652 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
653 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
659 protected Dialog
onCreateDialog(int id
) {
660 Dialog dialog
= null
;
661 AlertDialog
.Builder builder
;
663 case DIALOG_SHORT_WAIT
: {
664 ProgressDialog working_dialog
= new ProgressDialog(this);
665 working_dialog
.setMessage(getResources().getString(
666 R
.string
.wait_a_moment
));
667 working_dialog
.setIndeterminate(true
);
668 working_dialog
.setCancelable(false
);
669 dialog
= working_dialog
;
672 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
674 String
[] items
= null
;
676 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
677 getString(R
.string
.actionbar_upload_from_apps
),
678 getString(R
.string
.actionbar_failed_instant_upload
) };
680 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
681 getString(R
.string
.actionbar_upload_from_apps
) };
683 if (InstantUploadActivity
.IS_ENABLED
)
688 builder
= new AlertDialog
.Builder(this);
689 builder
.setTitle(R
.string
.actionbar_upload
);
690 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
691 public void onClick(DialogInterface dialog
, int item
) {
694 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
695 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
696 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
698 // TODO create and handle new fragment
699 // LocalFileListFragment
701 } else if (item
== 1) {
702 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
703 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
704 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
705 ACTION_SELECT_CONTENT_FROM_APPS
);
706 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
707 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
708 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
709 startActivity(action
);
713 dialog
= builder
.create();
716 case DIALOG_SSL_VALIDATOR
: {
717 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
720 case DIALOG_CERT_NOT_SAVED
: {
721 builder
= new AlertDialog
.Builder(this);
722 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
723 builder
.setCancelable(false
);
724 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
726 public void onClick(DialogInterface dialog
, int which
) {
730 dialog
= builder
.create();
742 * Translates a content URI of an image to a physical path
744 * @param uri The URI to resolve
745 * @return The path to the image or null if it could not be found
747 public String
getPath(Uri uri
) {
748 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
749 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
750 if (cursor
!= null
) {
751 int column_index
= cursor
752 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
753 cursor
.moveToFirst();
754 return cursor
.getString(column_index
);
760 * Pushes a directory to the drop down list
761 * @param directory to push
762 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
764 public void pushDirname(OCFile directory
) {
765 if(!directory
.isDirectory()){
766 throw new IllegalArgumentException("Only directories may be pushed!");
768 mDirectories
.insert(directory
.getFileName(), 0);
773 * Pops a directory name from the drop down list
774 * @return True, unless the stack is empty
776 public boolean popDirname() {
777 mDirectories
.remove(mDirectories
.getItem(0));
778 return !mDirectories
.isEmpty();
781 // Custom array adapter to override text colors
782 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
784 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
788 public View
getView(int position
, View convertView
, ViewGroup parent
) {
789 View v
= super.getView(position
, convertView
, parent
);
791 ((TextView
) v
).setTextColor(getResources().getColorStateList(
792 android
.R
.color
.white
));
796 public View
getDropDownView(int position
, View convertView
,
798 View v
= super.getDropDownView(position
, convertView
, parent
);
800 ((TextView
) v
).setTextColor(getResources().getColorStateList(
801 android
.R
.color
.white
));
808 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
811 * {@link BroadcastReceiver} to enable syncing feedback in UI
814 public void onReceive(Context context
, Intent intent
) {
815 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
816 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
818 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
820 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
822 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
824 boolean fillBlankRoot
= false
;
825 OCFile currentDir
= getCurrentDir();
826 if (currentDir
== null
) {
827 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
828 fillBlankRoot
= (currentDir
!= null
);
831 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
834 currentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
835 OCFileListFragment fileListFragment
= getListOfFilesFragment();
836 if (fileListFragment
!= null
) {
837 fileListFragment
.listDirectory(currentDir
);
842 setSupportProgressBarIndeterminateVisibility(inProgress
);
843 removeStickyBroadcast(intent
);
847 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
848 if (synchResult
!= null
) {
849 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
850 mLastSslUntrustedServerResult
= synchResult
;
851 showDialog(DIALOG_SSL_VALIDATOR
);
858 private class UploadFinishReceiver
extends BroadcastReceiver
{
860 * Once the file upload has finished -> update view
861 * @author David A. Velasco
862 * {@link BroadcastReceiver} to enable upload feedback in UI
865 public void onReceive(Context context
, Intent intent
) {
866 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
867 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
868 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
869 OCFile currentDir
= getCurrentDir();
870 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
871 if (sameAccount
&& isDescendant
) {
872 refeshListOfFilesFragment();
880 * Class waiting for broadcast events from the {@link FielDownloader} service.
882 * Updates the UI when a download is started or finished, provided that it is relevant for the
885 private class DownloadFinishReceiver
extends BroadcastReceiver
{
887 public void onReceive(Context context
, Intent intent
) {
888 boolean sameAccount
= isSameAccount(context
, intent
);
889 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
890 boolean isDescendant
= isDescendant(downloadedRemotePath
);
892 if (sameAccount
&& isDescendant
) {
893 refeshListOfFilesFragment();
894 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
897 removeStickyBroadcast(intent
);
900 private boolean isDescendant(String downloadedRemotePath
) {
901 OCFile currentDir
= getCurrentDir();
902 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
905 private boolean isSameAccount(Context context
, Intent intent
) {
906 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
907 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
916 public DataStorageManager
getStorageManager() {
917 return mStorageManager
;
924 * Updates action bar and second fragment, if in dual pane mode.
927 public void onBrowsedDownTo(OCFile directory
) {
928 pushDirname(directory
);
929 cleanSecondFragment();
933 * Opens the image gallery showing the image {@link OCFile} received as parameter.
935 * @param file Image {@link OCFile} to show.
938 public void startImagePreview(OCFile file
) {
939 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
940 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
941 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
942 startActivity(showDetailsIntent
);
946 * Stars the preview of an already down media {@link OCFile}.
948 * @param file Media {@link OCFile} to preview.
949 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
950 * @param autoplay When 'true', the playback will start without user interactions.
953 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
954 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
955 setSecondFragment(mediaFragment
);
956 updateFragmentsVisibility(true
);
957 updateNavigationElementsInActionBar(file
);
962 * Requests the download of the received {@link OCFile} , updates the UI
963 * to monitor the download progress and prepares the activity to preview
964 * or open the file when the download finishes.
966 * @param file {@link OCFile} to download and preview.
969 public void startDownloadForPreview(OCFile file
) {
970 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
971 setSecondFragment(detailFragment
);
972 mWaitingToPreview
= file
;
973 requestForDownload();
974 updateFragmentsVisibility(true
);
975 updateNavigationElementsInActionBar(file
);
981 * Shows the information of the {@link OCFile} received as a
982 * parameter in the second fragment.
984 * @param file {@link OCFile} whose details will be shown
987 public void showDetails(OCFile file
) {
988 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
989 setSecondFragment(detailFragment
);
990 updateFragmentsVisibility(true
);
991 updateNavigationElementsInActionBar(file
);
999 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1000 ActionBar actionBar
= getSupportActionBar();
1001 if (chosenFile
== null
|| mDualPane
) {
1002 // only list of files - set for browsing through folders
1003 OCFile currentDir
= getCurrentDir();
1004 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1005 actionBar
.setDisplayShowTitleEnabled(false
);
1006 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1007 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1010 actionBar
.setDisplayHomeAsUpEnabled(true
);
1011 actionBar
.setDisplayShowTitleEnabled(true
);
1012 actionBar
.setTitle(chosenFile
.getFileName());
1013 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1022 public void onFileStateChanged() {
1023 refeshListOfFilesFragment();
1031 public FileDownloaderBinder
getFileDownloaderBinder() {
1032 return mDownloaderBinder
;
1040 public FileUploaderBinder
getFileUploaderBinder() {
1041 return mUploaderBinder
;
1045 /** Defines callbacks for service binding, passed to bindService() */
1046 private class ListServiceConnection
implements ServiceConnection
{
1049 public void onServiceConnected(ComponentName component
, IBinder service
) {
1050 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1051 Log_OC
.d(TAG
, "Download service connected");
1052 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1053 if (mWaitingToPreview
!= null
) {
1054 requestForDownload();
1057 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1058 Log_OC
.d(TAG
, "Upload service connected");
1059 mUploaderBinder
= (FileUploaderBinder
) service
;
1063 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1064 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1065 if (listOfFiles
!= null
) {
1066 listOfFiles
.listDirectory();
1068 FileFragment secondFragment
= getSecondFragment();
1069 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1070 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1071 detailFragment
.listenForTransferProgress();
1072 detailFragment
.updateFileDetails(false
, false
);
1077 public void onServiceDisconnected(ComponentName component
) {
1078 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1079 Log_OC
.d(TAG
, "Download service disconnected");
1080 mDownloaderBinder
= null
;
1081 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1082 Log_OC
.d(TAG
, "Upload service disconnected");
1083 mUploaderBinder
= null
;
1091 * Launch an intent to request the PIN code to the user before letting him use the app
1093 private void requestPinCode() {
1094 boolean pinStart
= false
;
1095 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1096 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1098 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1099 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1106 public void onSavedCertificate() {
1107 startSynchronization();
1112 public void onFailedSavingCertificate() {
1113 showDialog(DIALOG_CERT_NOT_SAVED
);
1118 * Updates the view associated to the activity after the finish of some operation over files
1119 * in the current account.
1121 * @param operation Removal operation performed.
1122 * @param result Result of the removal.
1125 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1126 if (operation
instanceof RemoveFileOperation
) {
1127 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1129 } else if (operation
instanceof RenameFileOperation
) {
1130 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1132 } else if (operation
instanceof SynchronizeFileOperation
) {
1133 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1135 } else if (operation
instanceof CreateFolderOperation
) {
1136 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1142 * Updates the view associated to the activity after the finish of an operation trying to remove a
1145 * @param operation Removal operation performed.
1146 * @param result Result of the removal.
1148 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1149 dismissDialog(DIALOG_SHORT_WAIT
);
1150 if (result
.isSuccess()) {
1151 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1153 OCFile removedFile
= operation
.getFile();
1154 getSecondFragment();
1155 FileFragment second
= getSecondFragment();
1156 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1157 cleanSecondFragment();
1159 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1160 refeshListOfFilesFragment();
1164 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1166 if (result
.isSslRecoverableException()) {
1167 mLastSslUntrustedServerResult
= result
;
1168 showDialog(DIALOG_SSL_VALIDATOR
);
1174 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1176 * @param operation Creation operation performed.
1177 * @param result Result of the creation.
1179 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1180 if (result
.isSuccess()) {
1181 dismissDialog(DIALOG_SHORT_WAIT
);
1182 refeshListOfFilesFragment();
1185 dismissDialog(DIALOG_SHORT_WAIT
);
1187 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1190 } catch (NotFoundException e
) {
1191 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1198 * Updates the view associated to the activity after the finish of an operation trying to rename a
1201 * @param operation Renaming operation performed.
1202 * @param result Result of the renaming.
1204 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1205 dismissDialog(DIALOG_SHORT_WAIT
);
1206 OCFile renamedFile
= operation
.getFile();
1207 if (result
.isSuccess()) {
1209 FileFragment details
= getSecondFragment();
1210 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1211 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1214 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1215 refeshListOfFilesFragment();
1219 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1220 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1222 // TODO throw again the new rename dialog
1224 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1226 if (result
.isSslRecoverableException()) {
1227 mLastSslUntrustedServerResult
= result
;
1228 showDialog(DIALOG_SSL_VALIDATOR
);
1235 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1236 dismissDialog(DIALOG_SHORT_WAIT
);
1237 OCFile syncedFile
= operation
.getLocalFile();
1238 if (!result
.isSuccess()) {
1239 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1240 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1241 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1242 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1246 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1251 if (operation
.transferWasRequested()) {
1252 refeshListOfFilesFragment();
1253 onTransferStateChanged(syncedFile
, true
, true
);
1256 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1267 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1269 FileFragment details
= getSecondFragment();
1270 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1271 if (downloading
|| uploading
) {
1272 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1274 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1281 public void onDismiss(EditNameDialog dialog
) {
1282 if (dialog
.getResult()) {
1283 String newDirectoryName
= dialog
.getNewFilename().trim();
1284 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1285 if (newDirectoryName
.length() > 0) {
1286 String path
= getCurrentDir().getRemotePath();
1289 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1290 RemoteOperation operation
= new CreateFolderOperation(path
, getCurrentDir().getFileId(), mStorageManager
);
1291 operation
.execute( getAccount(),
1292 FileDisplayActivity
.this,
1293 FileDisplayActivity
.this,
1295 FileDisplayActivity
.this);
1297 showDialog(DIALOG_SHORT_WAIT
);
1303 private void requestForDownload() {
1304 Account account
= getAccount();
1305 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1306 Intent i
= new Intent(this, FileDownloader
.class);
1307 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1308 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1314 private OCFile
getCurrentDir() {
1315 OCFile file
= getFile();
1317 if (file
.isDirectory()) {
1319 } else if (mStorageManager
!= null
) {
1320 return mStorageManager
.getFileById(file
.getParentId());