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
.Dialog
;
26 import android
.app
.ProgressDialog
;
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
.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
.RemoteOperationResult
.ResultCode
;
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
.SynchronizeFolderOperation
;
79 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
80 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
81 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
82 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
83 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
84 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
85 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
86 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
87 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
88 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
89 import com
.owncloud
.android
.ui
.preview
.PreviewImageFragment
;
90 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
91 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
94 * Displays, what files the user has available in his ownCloud.
96 * @author Bartek Przybylski
97 * @author David A. Velasco
100 public class FileDisplayActivity
extends FileActivity
implements
101 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
103 private ArrayAdapter
<String
> mDirectories
;
105 /** Access point to the cached database for the current ownCloud {@link Account} */
106 private FileDataStorageManager mStorageManager
= null
;
108 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
109 private UploadFinishReceiver mUploadFinishReceiver
;
110 private DownloadFinishReceiver mDownloadFinishReceiver
;
111 private FileDownloaderBinder mDownloaderBinder
= null
;
112 private FileUploaderBinder mUploaderBinder
= null
;
113 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
114 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
116 private boolean mDualPane
;
117 private View mLeftFragmentContainer
;
118 private View mRightFragmentContainer
;
120 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
121 private static final String KEY_SYNC_IN_PROGRESS
= "SYNC_IN_PROGRESS";
123 public static final int DIALOG_SHORT_WAIT
= 0;
124 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
125 private static final int DIALOG_SSL_VALIDATOR
= 2;
126 private static final int DIALOG_CERT_NOT_SAVED
= 3;
128 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
130 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
132 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
133 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
135 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
137 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
138 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
140 private OCFile mWaitingToPreview
;
141 private Handler mHandler
;
143 private boolean mSyncInProgress
= false
;
146 protected void onCreate(Bundle savedInstanceState
) {
147 Log_OC
.d(TAG
, "onCreate() start");
148 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
150 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
152 mHandler
= new Handler();
154 /// bindings to transference services
155 mUploadConnection
= new ListServiceConnection();
156 mDownloadConnection
= new ListServiceConnection();
157 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
158 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
160 // PIN CODE request ; best location is to decide, let's try this first
161 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
166 Intent observer_intent
= new Intent(this, FileObserverService
.class);
167 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
168 startService(observer_intent
);
170 /// Load of saved instance state
171 if(savedInstanceState
!= null
) {
172 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
173 mSyncInProgress
= savedInstanceState
.getBoolean(KEY_SYNC_IN_PROGRESS
);
176 mWaitingToPreview
= null
;
177 mSyncInProgress
= false
;
182 // Inflate and set the layout view
183 setContentView(R
.layout
.files
);
184 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
185 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
186 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
187 if (savedInstanceState
== null
) {
188 createMinFragments();
192 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
193 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
194 setSupportProgressBarIndeterminateVisibility(mSyncInProgress
); // always AFTER setContentView(...) ; to work around bug in its implementation
196 Log_OC
.d(TAG
, "onCreate() end");
201 protected void onDestroy() {
203 if (mDownloadConnection
!= null
)
204 unbindService(mDownloadConnection
);
205 if (mUploadConnection
!= null
)
206 unbindService(mUploadConnection
);
211 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
214 protected void onAccountSet(boolean stateWasRecovered
) {
215 if (getAccount() != null
) {
216 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
218 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
219 OCFile file
= getFile();
220 // get parent from path
221 String parentPath
= "";
223 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
224 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
225 // get parent from path
226 parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
227 if (mStorageManager
.getFileByPath(parentPath
) == null
)
228 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
.ROOT_PATH
); // never returns null
238 setNavigationListWithFolder(file
);
239 if (!stateWasRecovered
) {
240 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
241 initFragmentsWithFile();
242 if (file
.isFolder()) {
243 startSyncFolderOperation(file
);
247 updateFragmentsVisibility(!file
.isFolder());
248 updateNavigationElementsInActionBar(file
.isFolder() ? null
: file
);
253 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
258 private void setNavigationListWithFolder(OCFile file
) {
259 mDirectories
.clear();
260 OCFile fileIt
= file
;
262 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.ROOT_PATH
) {
263 if (fileIt
.isFolder()) {
264 mDirectories
.add(fileIt
.getFileName());
266 //fileIt = mStorageManager.getFileById(fileIt.getParentId());
267 // get parent from path
268 parentPath
= fileIt
.getRemotePath().substring(0, fileIt
.getRemotePath().lastIndexOf(fileIt
.getFileName()));
269 fileIt
= mStorageManager
.getFileByPath(parentPath
);
271 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
275 private void createMinFragments() {
276 OCFileListFragment listOfFiles
= new OCFileListFragment();
277 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
278 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
279 transaction
.commit();
282 private void initFragmentsWithFile() {
283 if (getAccount() != null
&& getFile() != null
) {
285 OCFileListFragment listOfFiles
= getListOfFilesFragment();
286 if (listOfFiles
!= null
) {
287 listOfFiles
.listDirectory(getCurrentDir());
289 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
293 OCFile file
= getFile();
294 Fragment secondFragment
= chooseInitialSecondFragment(file
);
295 if (secondFragment
!= null
) {
296 setSecondFragment(secondFragment
);
297 updateFragmentsVisibility(true
);
298 updateNavigationElementsInActionBar(file
);
301 cleanSecondFragment();
305 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
306 if (getAccount() == null
) {
307 Log
.wtf(TAG
, "\t account is NULL");
309 if (getFile() == null
) {
310 Log
.wtf(TAG
, "\t file is NULL");
315 private Fragment
chooseInitialSecondFragment(OCFile file
) {
316 Fragment secondFragment
= null
;
317 if (file
!= null
&& !file
.isFolder()) {
318 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
319 && file
.getLastSyncDateForProperties() > 0 // temporal fix
321 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
322 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
323 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
326 secondFragment
= new FileDetailFragment(file
, getAccount());
329 return secondFragment
;
334 * Replaces the second fragment managed by the activity with the received as
337 * Assumes never will be more than two fragments managed at the same time.
339 * @param fragment New second Fragment to set.
341 private void setSecondFragment(Fragment fragment
) {
342 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
343 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
344 transaction
.commit();
348 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
350 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
351 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
353 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
354 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
357 } else if (existsSecondFragment
) {
358 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
359 mLeftFragmentContainer
.setVisibility(View
.GONE
);
361 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
362 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
366 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
367 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
369 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
370 mRightFragmentContainer
.setVisibility(View
.GONE
);
376 private OCFileListFragment
getListOfFilesFragment() {
377 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
378 if (listOfFiles
!= null
) {
379 return (OCFileListFragment
)listOfFiles
;
381 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
385 protected FileFragment
getSecondFragment() {
386 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
387 if (second
!= null
) {
388 return (FileFragment
)second
;
393 public void cleanSecondFragment() {
394 Fragment second
= getSecondFragment();
395 if (second
!= null
) {
396 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
400 updateFragmentsVisibility(false
);
401 updateNavigationElementsInActionBar(null
);
404 protected void refeshListOfFilesFragment() {
405 OCFileListFragment fileListFragment
= getListOfFilesFragment();
406 if (fileListFragment
!= null
) {
407 fileListFragment
.listDirectory();
411 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
412 FileFragment secondFragment
= getSecondFragment();
413 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
414 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
415 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
416 OCFile fileInFragment
= detailsFragment
.getFile();
417 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
418 // the user browsed to other file ; forget the automatic preview
419 mWaitingToPreview
= null
;
421 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
422 // grant that the right panel updates the progress bar
423 detailsFragment
.listenForTransferProgress();
424 detailsFragment
.updateFileDetails(true
, false
);
426 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
427 // update the right panel
428 boolean detailsFragmentChanged
= false
;
431 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
432 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
433 startMediaPreview(mWaitingToPreview
, 0, true
);
434 detailsFragmentChanged
= true
;
436 openFile(mWaitingToPreview
);
439 mWaitingToPreview
= null
;
441 if (!detailsFragmentChanged
) {
442 detailsFragment
.updateFileDetails(false
, (success
));
450 public boolean onCreateOptionsMenu(Menu menu
) {
451 MenuInflater inflater
= getSherlock().getMenuInflater();
452 inflater
.inflate(R
.menu
.main_menu
, menu
);
457 public boolean onOptionsItemSelected(MenuItem item
) {
458 boolean retval
= true
;
459 switch (item
.getItemId()) {
460 case R
.id
.action_create_dir
: {
461 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
462 dialog
.show(getSupportFragmentManager(), "createdirdialog");
465 case R
.id
.action_sync_account
: {
466 startSynchronization();
469 case R
.id
.action_upload
: {
470 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
473 case R
.id
.action_settings
: {
474 Intent settingsIntent
= new Intent(this, Preferences
.class);
475 startActivity(settingsIntent
);
478 case android
.R
.id
.home
: {
479 FileFragment second
= getSecondFragment();
480 OCFile currentDir
= getCurrentDir();
481 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
482 (second
!= null
&& second
.getFile() != null
)) {
489 retval
= super.onOptionsItemSelected(item
);
494 private void startSynchronization() {
495 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
496 Bundle bundle
= new Bundle();
497 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
498 ContentResolver
.requestSync(
500 AccountAuthenticator
.AUTHORITY
, bundle
);
505 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
506 if (itemPosition
!= 0) {
507 String targetPath
= "";
508 for (int i
=itemPosition
; i
< mDirectories
.getCount() - 1; i
++) {
509 targetPath
= mDirectories
.getItem(i
) + OCFile
.PATH_SEPARATOR
+ targetPath
;
511 targetPath
= OCFile
.PATH_SEPARATOR
+ targetPath
;
512 OCFile targetFolder
= mStorageManager
.getFileByPath(targetPath
);
513 if (targetFolder
!= null
) {
514 browseTo(targetFolder
);
517 // the next operation triggers a new call to this method, but it's necessary to
518 // ensure that the name exposed in the action bar is the current directory when the
519 // user selected it in the navigation list
520 getSupportActionBar().setSelectedNavigationItem(0);
526 * Called, when the user selected something for uploading
528 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
529 super.onActivityResult(requestCode
, resultCode
, data
);
531 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
532 requestSimpleUpload(data
, resultCode
);
534 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
535 requestMultipleUpload(data
, resultCode
);
540 private void requestMultipleUpload(Intent data
, int resultCode
) {
541 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
542 if (filePaths
!= null
) {
543 String
[] remotePaths
= new String
[filePaths
.length
];
544 String remotePathBase
= "";
545 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
546 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
548 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
549 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
550 for (int j
= 0; j
< remotePaths
.length
; j
++) {
551 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
554 Intent i
= new Intent(this, FileUploader
.class);
555 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
556 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
557 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
558 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
559 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
560 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
564 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
565 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
572 private void requestSimpleUpload(Intent data
, int resultCode
) {
573 String filepath
= null
;
575 Uri selectedImageUri
= data
.getData();
577 String filemanagerstring
= selectedImageUri
.getPath();
578 String selectedImagePath
= getPath(selectedImageUri
);
580 if (selectedImagePath
!= null
)
581 filepath
= selectedImagePath
;
583 filepath
= filemanagerstring
;
585 } catch (Exception e
) {
586 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
590 if (filepath
== null
) {
591 Log_OC
.e(TAG
, "Couldnt resolve path to file");
592 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
598 Intent i
= new Intent(this, FileUploader
.class);
599 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
601 String remotepath
= new String();
602 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
603 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
605 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
606 remotepath
+= OCFile
.PATH_SEPARATOR
;
607 remotepath
+= new File(filepath
).getName();
609 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
610 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
611 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
612 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
613 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
618 public void onBackPressed() {
619 OCFileListFragment listOfFiles
= getListOfFilesFragment();
620 if (mDualPane
|| getSecondFragment() == null
) {
621 if (listOfFiles
!= null
) { // should never be null, indeed
622 if (mDirectories
.getCount() <= 1) {
626 int levelsUp
= listOfFiles
.onBrowseUp();
627 for (int i
=0; i
< levelsUp
&& mDirectories
.getCount() > 1 ; i
++) {
632 if (listOfFiles
!= null
) { // should never be null, indeed
633 setFile(listOfFiles
.getCurrentFile());
635 cleanSecondFragment();
640 protected void onSaveInstanceState(Bundle outState
) {
641 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
642 Log_OC
.e(TAG
, "onSaveInstanceState() start");
643 super.onSaveInstanceState(outState
);
644 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
645 outState
.putBoolean(FileDisplayActivity
.KEY_SYNC_IN_PROGRESS
, mSyncInProgress
);
647 Log_OC
.d(TAG
, "onSaveInstanceState() end");
653 protected void onResume() {
655 Log_OC
.e(TAG
, "onResume() start");
657 // Listen for sync messages
658 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
659 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
660 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
662 // Listen for upload messages
663 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
664 mUploadFinishReceiver
= new UploadFinishReceiver();
665 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
667 // Listen for download messages
668 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
669 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
670 mDownloadFinishReceiver
= new DownloadFinishReceiver();
671 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
673 Log_OC
.d(TAG
, "onResume() end");
678 protected void onPause() {
680 Log_OC
.e(TAG
, "onPause() start");
681 if (mSyncBroadcastReceiver
!= null
) {
682 unregisterReceiver(mSyncBroadcastReceiver
);
683 mSyncBroadcastReceiver
= null
;
685 if (mUploadFinishReceiver
!= null
) {
686 unregisterReceiver(mUploadFinishReceiver
);
687 mUploadFinishReceiver
= null
;
689 if (mDownloadFinishReceiver
!= null
) {
690 unregisterReceiver(mDownloadFinishReceiver
);
691 mDownloadFinishReceiver
= null
;
694 Log_OC
.d(TAG
, "onPause() end");
699 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
700 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
701 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
707 protected Dialog
onCreateDialog(int id
) {
708 Dialog dialog
= null
;
709 AlertDialog
.Builder builder
;
711 case DIALOG_SHORT_WAIT
: {
712 ProgressDialog working_dialog
= new ProgressDialog(this);
713 working_dialog
.setMessage(getResources().getString(
714 R
.string
.wait_a_moment
));
715 working_dialog
.setIndeterminate(true
);
716 working_dialog
.setCancelable(false
);
717 dialog
= working_dialog
;
720 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
722 String
[] items
= null
;
724 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
725 getString(R
.string
.actionbar_upload_from_apps
),
726 getString(R
.string
.actionbar_failed_instant_upload
) };
728 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
729 getString(R
.string
.actionbar_upload_from_apps
) };
731 if (InstantUploadActivity
.IS_ENABLED
)
736 builder
= new AlertDialog
.Builder(this);
737 builder
.setTitle(R
.string
.actionbar_upload
);
738 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
739 public void onClick(DialogInterface dialog
, int item
) {
742 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
743 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
744 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
746 // TODO create and handle new fragment
747 // LocalFileListFragment
749 } else if (item
== 1) {
750 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
751 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
752 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
753 ACTION_SELECT_CONTENT_FROM_APPS
);
754 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
755 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
756 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
757 startActivity(action
);
761 dialog
= builder
.create();
764 case DIALOG_SSL_VALIDATOR
: {
765 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
768 case DIALOG_CERT_NOT_SAVED
: {
769 builder
= new AlertDialog
.Builder(this);
770 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
771 builder
.setCancelable(false
);
772 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
774 public void onClick(DialogInterface dialog
, int which
) {
778 dialog
= builder
.create();
790 * Show loading dialog
792 public void showLoadingDialog() {
794 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
795 FragmentManager fm
= getSupportFragmentManager();
796 FragmentTransaction ft
= fm
.beginTransaction();
797 loading
.show(ft
, DIALOG_WAIT_TAG
);
802 * Dismiss loading dialog
804 public void dismissLoadingDialog(){
805 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
807 LoadingDialog loading
= (LoadingDialog
) frag
;
814 * Translates a content URI of an image to a physical path
816 * @param uri The URI to resolve
817 * @return The path to the image or null if it could not be found
819 public String
getPath(Uri uri
) {
820 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
821 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
822 if (cursor
!= null
) {
823 int column_index
= cursor
824 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
825 cursor
.moveToFirst();
826 return cursor
.getString(column_index
);
832 * Pushes a directory to the drop down list
833 * @param directory to push
834 * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false.
836 public void pushDirname(OCFile directory
) {
837 if(!directory
.isFolder()){
838 throw new IllegalArgumentException("Only directories may be pushed!");
840 mDirectories
.insert(directory
.getFileName(), 0);
845 * Pops a directory name from the drop down list
846 * @return True, unless the stack is empty
848 public boolean popDirname() {
849 mDirectories
.remove(mDirectories
.getItem(0));
850 return !mDirectories
.isEmpty();
853 // Custom array adapter to override text colors
854 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
856 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
860 public View
getView(int position
, View convertView
, ViewGroup parent
) {
861 View v
= super.getView(position
, convertView
, parent
);
863 ((TextView
) v
).setTextColor(getResources().getColorStateList(
864 android
.R
.color
.white
));
868 public View
getDropDownView(int position
, View convertView
,
870 View v
= super.getDropDownView(position
, convertView
, parent
);
872 ((TextView
) v
).setTextColor(getResources().getColorStateList(
873 android
.R
.color
.white
));
880 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
883 * {@link BroadcastReceiver} to enable syncing feedback in UI
886 public void onReceive(Context context
, Intent intent
) {
887 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
888 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
889 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
891 if (getAccount() != null
&& accountName
.equals(getAccount().name
)
892 && mStorageManager
!= null
895 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
897 OCFile currentFile
= (getFile() == null
) ? null
: mStorageManager
.getFileByPath(getFile().getRemotePath());
898 OCFile currentDir
= (getCurrentDir() == null
) ? null
: mStorageManager
.getFileByPath(getCurrentDir().getRemotePath());
900 if (currentDir
== null
) {
901 // current folder was removed from the server
902 Toast
.makeText( FileDisplayActivity
.this,
903 String
.format(getString(R
.string
.sync_current_folder_was_removed
), mDirectories
.getItem(0)),
909 if (currentFile
== null
&& !getFile().isFolder()) {
910 // currently selected file was removed in the server, and now we know it
911 cleanSecondFragment();
912 currentFile
= currentDir
;
915 if (synchFolderRemotePath
!= null
&& currentDir
.getRemotePath().equals(synchFolderRemotePath
)) {
916 OCFileListFragment fileListFragment
= getListOfFilesFragment();
917 if (fileListFragment
!= null
) {
918 fileListFragment
.listDirectory(currentDir
);
921 setFile(currentFile
);
924 setSupportProgressBarIndeterminateVisibility(inProgress
);
925 removeStickyBroadcast(intent
);
926 mSyncInProgress
= inProgress
;
930 if (synchResult
!= null
) {
931 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
932 mLastSslUntrustedServerResult
= synchResult
;
933 showDialog(DIALOG_SSL_VALIDATOR
);
940 private class UploadFinishReceiver
extends BroadcastReceiver
{
942 * Once the file upload has finished -> update view
943 * @author David A. Velasco
944 * {@link BroadcastReceiver} to enable upload feedback in UI
947 public void onReceive(Context context
, Intent intent
) {
948 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
949 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
950 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
951 OCFile currentDir
= getCurrentDir();
952 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
953 if (sameAccount
&& isDescendant
) {
954 refeshListOfFilesFragment();
962 * Class waiting for broadcast events from the {@link FielDownloader} service.
964 * Updates the UI when a download is started or finished, provided that it is relevant for the
967 private class DownloadFinishReceiver
extends BroadcastReceiver
{
969 public void onReceive(Context context
, Intent intent
) {
970 boolean sameAccount
= isSameAccount(context
, intent
);
971 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
972 boolean isDescendant
= isDescendant(downloadedRemotePath
);
974 if (sameAccount
&& isDescendant
) {
975 refeshListOfFilesFragment();
976 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
979 removeStickyBroadcast(intent
);
982 private boolean isDescendant(String downloadedRemotePath
) {
983 OCFile currentDir
= getCurrentDir();
984 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
987 private boolean isSameAccount(Context context
, Intent intent
) {
988 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
989 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
998 public FileDataStorageManager
getStorageManager() {
999 return mStorageManager
;
1003 public void browseToRoot() {
1004 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1005 if (listOfFiles
!= null
) { // should never be null, indeed
1006 while (mDirectories
.getCount() > 1) {
1009 OCFile root
= mStorageManager
.getFileByPath(OCFile
.ROOT_PATH
);
1010 listOfFiles
.listDirectory(root
);
1011 setFile(listOfFiles
.getCurrentFile());
1012 startSyncFolderOperation(root
);
1014 cleanSecondFragment();
1018 public void browseTo(OCFile folder
) {
1019 if (folder
== null
|| !folder
.isFolder()) {
1020 throw new IllegalArgumentException("Trying to browse to invalid folder " + folder
);
1022 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1023 if (listOfFiles
!= null
) {
1024 setNavigationListWithFolder(folder
);
1025 listOfFiles
.listDirectory(folder
);
1026 setFile(listOfFiles
.getCurrentFile());
1027 startSyncFolderOperation(folder
);
1029 Log_OC
.e(TAG
, "Unexpected null when accessing list fragment");
1031 cleanSecondFragment();
1038 * Updates action bar and second fragment, if in dual pane mode.
1041 public void onBrowsedDownTo(OCFile directory
) {
1042 pushDirname(directory
);
1043 cleanSecondFragment();
1046 startSyncFolderOperation(directory
);
1051 * Opens the image gallery showing the image {@link OCFile} received as parameter.
1053 * @param file Image {@link OCFile} to show.
1056 public void startImagePreview(OCFile file
) {
1057 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
1058 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
1059 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
1060 startActivity(showDetailsIntent
);
1064 * Stars the preview of an already down media {@link OCFile}.
1066 * @param file Media {@link OCFile} to preview.
1067 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
1068 * @param autoplay When 'true', the playback will start without user interactions.
1071 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1072 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1073 setSecondFragment(mediaFragment
);
1074 updateFragmentsVisibility(true
);
1075 updateNavigationElementsInActionBar(file
);
1080 * Requests the download of the received {@link OCFile} , updates the UI
1081 * to monitor the download progress and prepares the activity to preview
1082 * or open the file when the download finishes.
1084 * @param file {@link OCFile} to download and preview.
1087 public void startDownloadForPreview(OCFile file
) {
1088 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1089 setSecondFragment(detailFragment
);
1090 mWaitingToPreview
= file
;
1091 requestForDownload();
1092 updateFragmentsVisibility(true
);
1093 updateNavigationElementsInActionBar(file
);
1099 * Shows the information of the {@link OCFile} received as a
1100 * parameter in the second fragment.
1102 * @param file {@link OCFile} whose details will be shown
1105 public void showDetails(OCFile file
) {
1106 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1107 setSecondFragment(detailFragment
);
1108 updateFragmentsVisibility(true
);
1109 updateNavigationElementsInActionBar(file
);
1117 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1118 ActionBar actionBar
= getSupportActionBar();
1119 if (chosenFile
== null
|| mDualPane
) {
1120 // only list of files - set for browsing through folders
1121 OCFile currentDir
= getCurrentDir();
1122 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1123 actionBar
.setDisplayShowTitleEnabled(false
);
1124 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1125 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1128 actionBar
.setDisplayHomeAsUpEnabled(true
);
1129 actionBar
.setDisplayShowTitleEnabled(true
);
1130 actionBar
.setTitle(chosenFile
.getFileName());
1131 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1136 // private void updateDisplayHomeAtSync(){
1137 // ActionBar actionBar = getSupportActionBar();
1138 // OCFile currentDir = getCurrentDir();
1139 // if (currentDir.getParentId() != DataStorageManager.ROOT_PARENT_ID) {
1140 // actionBar.setHomeButtonEnabled(!mSyncInProgress);
1141 // actionBar.setDisplayHomeAsUpEnabled(!mSyncInProgress);
1144 // actionBar.setHomeButtonEnabled(true);
1145 // actionBar.setDisplayHomeAsUpEnabled(false);
1153 public void onFileStateChanged() {
1154 refeshListOfFilesFragment();
1155 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1163 public FileDownloaderBinder
getFileDownloaderBinder() {
1164 return mDownloaderBinder
;
1172 public FileUploaderBinder
getFileUploaderBinder() {
1173 return mUploaderBinder
;
1177 /** Defines callbacks for service binding, passed to bindService() */
1178 private class ListServiceConnection
implements ServiceConnection
{
1181 public void onServiceConnected(ComponentName component
, IBinder service
) {
1182 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1183 Log_OC
.d(TAG
, "Download service connected");
1184 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1185 if (mWaitingToPreview
!= null
) {
1186 requestForDownload();
1189 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1190 Log_OC
.d(TAG
, "Upload service connected");
1191 mUploaderBinder
= (FileUploaderBinder
) service
;
1195 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1196 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1197 if (listOfFiles
!= null
) {
1198 listOfFiles
.listDirectory();
1200 FileFragment secondFragment
= getSecondFragment();
1201 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1202 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1203 detailFragment
.listenForTransferProgress();
1204 detailFragment
.updateFileDetails(false
, false
);
1209 public void onServiceDisconnected(ComponentName component
) {
1210 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1211 Log_OC
.d(TAG
, "Download service disconnected");
1212 mDownloaderBinder
= null
;
1213 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1214 Log_OC
.d(TAG
, "Upload service disconnected");
1215 mUploaderBinder
= null
;
1223 * Launch an intent to request the PIN code to the user before letting him use the app
1225 private void requestPinCode() {
1226 boolean pinStart
= false
;
1227 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1228 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1230 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1231 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1238 public void onSavedCertificate() {
1239 startSynchronization();
1244 public void onFailedSavingCertificate() {
1245 showDialog(DIALOG_CERT_NOT_SAVED
);
1250 * Updates the view associated to the activity after the finish of some operation over files
1251 * in the current account.
1253 * @param operation Removal operation performed.
1254 * @param result Result of the removal.
1257 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1258 if (operation
instanceof RemoveFileOperation
) {
1259 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1261 } else if (operation
instanceof RenameFileOperation
) {
1262 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1264 } else if (operation
instanceof SynchronizeFileOperation
) {
1265 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1267 } else if (operation
instanceof CreateFolderOperation
) {
1268 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1275 * Updates the view associated to the activity after the finish of an operation trying to remove a
1278 * @param operation Removal operation performed.
1279 * @param result Result of the removal.
1281 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1282 dismissLoadingDialog();
1283 if (result
.isSuccess()) {
1284 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1286 OCFile removedFile
= operation
.getFile();
1287 getSecondFragment();
1288 FileFragment second
= getSecondFragment();
1289 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1290 cleanSecondFragment();
1292 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1293 refeshListOfFilesFragment();
1297 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1299 if (result
.isSslRecoverableException()) {
1300 mLastSslUntrustedServerResult
= result
;
1301 showDialog(DIALOG_SSL_VALIDATOR
);
1307 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1309 * @param operation Creation operation performed.
1310 * @param result Result of the creation.
1312 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1313 if (result
.isSuccess()) {
1314 dismissLoadingDialog();
1315 refeshListOfFilesFragment();
1318 dismissLoadingDialog();
1320 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1323 } catch (NotFoundException e
) {
1324 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1331 * Updates the view associated to the activity after the finish of an operation trying to rename a
1334 * @param operation Renaming operation performed.
1335 * @param result Result of the renaming.
1337 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1338 dismissLoadingDialog();
1339 OCFile renamedFile
= operation
.getFile();
1340 if (result
.isSuccess()) {
1342 FileFragment details
= getSecondFragment();
1343 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1344 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1347 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1348 refeshListOfFilesFragment();
1352 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1353 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1355 // TODO throw again the new rename dialog
1357 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1359 if (result
.isSslRecoverableException()) {
1360 mLastSslUntrustedServerResult
= result
;
1361 showDialog(DIALOG_SSL_VALIDATOR
);
1368 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1369 dismissLoadingDialog();
1370 OCFile syncedFile
= operation
.getLocalFile();
1371 if (!result
.isSuccess()) {
1372 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1373 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1374 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1375 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1381 if (operation
.transferWasRequested()) {
1382 refeshListOfFilesFragment();
1383 onTransferStateChanged(syncedFile
, true
, true
);
1386 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1397 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1399 FileFragment details
= getSecondFragment();
1400 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1401 if (downloading
|| uploading
) {
1402 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1404 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1411 public void onDismiss(EditNameDialog dialog
) {
1412 if (dialog
.getResult()) {
1413 String newDirectoryName
= dialog
.getNewFilename().trim();
1414 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1415 if (newDirectoryName
.length() > 0) {
1416 String path
= getCurrentDir().getRemotePath();
1419 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1420 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1421 operation
.execute( getAccount(),
1422 FileDisplayActivity
.this,
1423 FileDisplayActivity
.this,
1425 FileDisplayActivity
.this);
1427 showLoadingDialog();
1433 private void requestForDownload() {
1434 Account account
= getAccount();
1435 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1436 Intent i
= new Intent(this, FileDownloader
.class);
1437 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1438 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1444 private OCFile
getCurrentDir() {
1445 OCFile file
= getFile();
1447 if (file
.isFolder()) {
1449 } else if (mStorageManager
!= null
) {
1450 String parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
1451 return mStorageManager
.getFileByPath(parentPath
);
1457 public void startSyncFolderOperation(OCFile folder
) {
1458 long currentSyncTime
= System
.currentTimeMillis();
1460 mSyncInProgress
= true
;
1462 // perform folder synchronization
1463 RemoteOperation synchFolderOp
= new SynchronizeFolderOperation( folder
,
1466 getStorageManager(),
1468 getApplicationContext()
1470 synchFolderOp
.execute(getAccount(), this, null
, null
, this);
1472 setSupportProgressBarIndeterminateVisibility(true
);
1476 // public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
1477 // int childCount = viewGroup.getChildCount();
1478 // for (int i = 0; i < childCount; i++) {
1479 // View view = viewGroup.getChildAt(i);
1480 // view.setEnabled(enabled);
1481 // view.setClickable(!enabled);
1482 // if (view instanceof ViewGroup) {
1483 // enableDisableViewGroup((ViewGroup) view, enabled);