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
.DataStorageManager
;
64 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
65 import com
.owncloud
.android
.datamodel
.OCFile
;
66 import com
.owncloud
.android
.files
.services
.FileDownloader
;
67 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
68 import com
.owncloud
.android
.files
.services
.FileObserverService
;
69 import com
.owncloud
.android
.files
.services
.FileUploader
;
70 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
71 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
72 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
73 import com
.owncloud
.android
.operations
.RemoteOperation
;
74 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
75 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
76 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
77 import com
.owncloud
.android
.operations
.RenameFileOperation
;
78 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
79 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
80 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
81 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
82 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
83 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
84 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
85 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
86 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
87 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
88 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
89 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
90 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
91 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
94 * Displays, what files the user has available in his ownCloud.
96 * @author Bartek Przybylski
97 * @author David A. Velasco
100 public class FileDisplayActivity
extends FileActivity
implements
101 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
103 private ArrayAdapter
<String
> mDirectories
;
105 /** Access point to the cached database for the current ownCloud {@link Account} */
106 private DataStorageManager mStorageManager
= null
;
108 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
109 private UploadFinishReceiver mUploadFinishReceiver
;
110 private DownloadFinishReceiver mDownloadFinishReceiver
;
111 private FileDownloaderBinder mDownloaderBinder
= null
;
112 private FileUploaderBinder mUploaderBinder
= null
;
113 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
114 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
116 private boolean mDualPane
;
117 private View mLeftFragmentContainer
;
118 private View mRightFragmentContainer
;
120 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
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();
221 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
222 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
223 if (mStorageManager
.getFileById(file
.getParentId()) == null
) {
224 file
= null
; // not able to know the directory where the file is uploading
227 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
231 // fall back to root folder
232 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
235 setNavigationListWithFolder(file
);
236 if (!stateWasRecovered
) {
237 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
238 initFragmentsWithFile();
241 updateFragmentsVisibility(!file
.isDirectory());
242 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
247 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
252 private void setNavigationListWithFolder(OCFile file
) {
253 mDirectories
.clear();
254 OCFile fileIt
= file
;
255 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
256 if (fileIt
.isDirectory()) {
257 mDirectories
.add(fileIt
.getFileName());
259 fileIt
= mStorageManager
.getFileById(fileIt
.getParentId());
261 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
265 private void createMinFragments() {
266 OCFileListFragment listOfFiles
= new OCFileListFragment();
267 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
268 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
269 transaction
.commit();
272 private void initFragmentsWithFile() {
273 if (getAccount() != null
&& getFile() != null
) {
275 OCFileListFragment listOfFiles
= getListOfFilesFragment();
276 if (listOfFiles
!= null
) {
277 listOfFiles
.listDirectory(getCurrentDir());
279 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
283 OCFile file
= getFile();
284 Fragment secondFragment
= chooseInitialSecondFragment(file
);
285 if (secondFragment
!= null
) {
286 setSecondFragment(secondFragment
);
287 updateFragmentsVisibility(true
);
288 updateNavigationElementsInActionBar(file
);
291 cleanSecondFragment();
295 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
296 if (getAccount() == null
) {
297 Log
.wtf(TAG
, "\t account is NULL");
299 if (getFile() == null
) {
300 Log
.wtf(TAG
, "\t file is NULL");
305 private Fragment
chooseInitialSecondFragment(OCFile file
) {
306 Fragment secondFragment
= null
;
307 if (file
!= null
&& !file
.isDirectory()) {
308 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
309 && file
.getLastSyncDateForProperties() > 0 // temporal fix
311 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
312 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
313 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
316 secondFragment
= new FileDetailFragment(file
, getAccount());
319 return secondFragment
;
324 * Replaces the second fragment managed by the activity with the received as
327 * Assumes never will be more than two fragments managed at the same time.
329 * @param fragment New second Fragment to set.
331 private void setSecondFragment(Fragment fragment
) {
332 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
333 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
334 transaction
.commit();
338 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
340 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
341 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
343 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
344 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
347 } else if (existsSecondFragment
) {
348 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
349 mLeftFragmentContainer
.setVisibility(View
.GONE
);
351 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
352 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
356 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
357 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
359 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
360 mRightFragmentContainer
.setVisibility(View
.GONE
);
366 private OCFileListFragment
getListOfFilesFragment() {
367 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
368 if (listOfFiles
!= null
) {
369 return (OCFileListFragment
)listOfFiles
;
371 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
375 protected FileFragment
getSecondFragment() {
376 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
377 if (second
!= null
) {
378 return (FileFragment
)second
;
383 public void cleanSecondFragment() {
384 Fragment second
= getSecondFragment();
385 if (second
!= null
) {
386 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
390 updateFragmentsVisibility(false
);
391 updateNavigationElementsInActionBar(null
);
394 protected void refeshListOfFilesFragment() {
395 OCFileListFragment fileListFragment
= getListOfFilesFragment();
396 if (fileListFragment
!= null
) {
397 fileListFragment
.listDirectory();
401 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
402 FileFragment secondFragment
= getSecondFragment();
403 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
404 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
405 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
406 OCFile fileInFragment
= detailsFragment
.getFile();
407 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
408 // the user browsed to other file ; forget the automatic preview
409 mWaitingToPreview
= null
;
411 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
412 // grant that the right panel updates the progress bar
413 detailsFragment
.listenForTransferProgress();
414 detailsFragment
.updateFileDetails(true
, false
);
416 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
417 // update the right panel
418 boolean detailsFragmentChanged
= false
;
421 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
422 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
423 startMediaPreview(mWaitingToPreview
, 0, true
);
424 detailsFragmentChanged
= true
;
426 openFile(mWaitingToPreview
);
429 mWaitingToPreview
= null
;
431 if (!detailsFragmentChanged
) {
432 detailsFragment
.updateFileDetails(false
, (success
));
440 public boolean onCreateOptionsMenu(Menu menu
) {
441 MenuInflater inflater
= getSherlock().getMenuInflater();
442 inflater
.inflate(R
.menu
.main_menu
, menu
);
447 public boolean onOptionsItemSelected(MenuItem item
) {
448 boolean retval
= true
;
449 switch (item
.getItemId()) {
450 case R
.id
.action_create_dir
: {
451 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
452 dialog
.show(getSupportFragmentManager(), "createdirdialog");
455 case R
.id
.action_sync_account
: {
456 startSynchronization();
459 case R
.id
.action_upload
: {
460 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
463 case R
.id
.action_settings
: {
464 Intent settingsIntent
= new Intent(this, Preferences
.class);
465 startActivity(settingsIntent
);
468 case android
.R
.id
.home
: {
469 FileFragment second
= getSecondFragment();
470 OCFile currentDir
= getCurrentDir();
471 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
472 (second
!= null
&& second
.getFile() != null
)) {
479 retval
= super.onOptionsItemSelected(item
);
484 private void startSynchronization() {
485 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
486 Bundle bundle
= new Bundle();
487 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
488 ContentResolver
.requestSync(
490 AccountAuthenticator
.AUTHORITY
, bundle
);
495 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
496 if (itemPosition
!= 0) {
497 String targetPath
= "";
498 for (int i
=itemPosition
; i
< mDirectories
.getCount() - 1; i
++) {
499 targetPath
= mDirectories
.getItem(i
) + OCFile
.PATH_SEPARATOR
+ targetPath
;
501 targetPath
= OCFile
.PATH_SEPARATOR
+ targetPath
;
502 OCFile targetFolder
= mStorageManager
.getFileByPath(targetPath
);
503 if (targetFolder
!= null
) {
504 browseTo(targetFolder
);
507 // the next operation triggers a new call to this method, but it's necessary to
508 // ensure that the name exposed in the action bar is the current directory when the
509 // user selected it in the navigation list
510 getSupportActionBar().setSelectedNavigationItem(0);
516 * Called, when the user selected something for uploading
518 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
519 super.onActivityResult(requestCode
, resultCode
, data
);
521 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
522 requestSimpleUpload(data
, resultCode
);
524 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
525 requestMultipleUpload(data
, resultCode
);
530 private void requestMultipleUpload(Intent data
, int resultCode
) {
531 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
532 if (filePaths
!= null
) {
533 String
[] remotePaths
= new String
[filePaths
.length
];
534 String remotePathBase
= "";
535 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
536 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
538 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
539 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
540 for (int j
= 0; j
< remotePaths
.length
; j
++) {
541 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
544 Intent i
= new Intent(this, FileUploader
.class);
545 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
546 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
547 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
548 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
549 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
550 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
554 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
555 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
562 private void requestSimpleUpload(Intent data
, int resultCode
) {
563 String filepath
= null
;
565 Uri selectedImageUri
= data
.getData();
567 String filemanagerstring
= selectedImageUri
.getPath();
568 String selectedImagePath
= getPath(selectedImageUri
);
570 if (selectedImagePath
!= null
)
571 filepath
= selectedImagePath
;
573 filepath
= filemanagerstring
;
575 } catch (Exception e
) {
576 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
580 if (filepath
== null
) {
581 Log_OC
.e(TAG
, "Couldnt resolve path to file");
582 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
588 Intent i
= new Intent(this, FileUploader
.class);
589 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
591 String remotepath
= new String();
592 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
593 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
595 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
596 remotepath
+= OCFile
.PATH_SEPARATOR
;
597 remotepath
+= new File(filepath
).getName();
599 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
600 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
601 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
602 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
603 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
608 public void onBackPressed() {
609 OCFileListFragment listOfFiles
= getListOfFilesFragment();
610 if (mDualPane
|| getSecondFragment() == null
) {
611 if (listOfFiles
!= null
) { // should never be null, indeed
612 if (mDirectories
.getCount() <= 1) {
616 int levelsUp
= listOfFiles
.onBrowseUp();
617 for (int i
=0; i
< levelsUp
&& mDirectories
.getCount() > 1 ; i
++) {
622 if (listOfFiles
!= null
) { // should never be null, indeed
623 setFile(listOfFiles
.getCurrentFile());
625 cleanSecondFragment();
630 protected void onSaveInstanceState(Bundle outState
) {
631 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
632 Log_OC
.e(TAG
, "onSaveInstanceState() start");
633 super.onSaveInstanceState(outState
);
634 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
635 outState
.putBoolean(FileDisplayActivity
.KEY_SYNC_IN_PROGRESS
, mSyncInProgress
);
637 Log_OC
.d(TAG
, "onSaveInstanceState() end");
643 protected void onResume() {
645 Log_OC
.e(TAG
, "onResume() start");
647 // Listen for sync messages
648 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
649 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
650 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
652 // Listen for upload messages
653 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
654 mUploadFinishReceiver
= new UploadFinishReceiver();
655 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
657 // Listen for download messages
658 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
659 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
660 mDownloadFinishReceiver
= new DownloadFinishReceiver();
661 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
663 Log_OC
.d(TAG
, "onResume() end");
668 protected void onPause() {
670 Log_OC
.e(TAG
, "onPause() start");
671 if (mSyncBroadcastReceiver
!= null
) {
672 unregisterReceiver(mSyncBroadcastReceiver
);
673 mSyncBroadcastReceiver
= null
;
675 if (mUploadFinishReceiver
!= null
) {
676 unregisterReceiver(mUploadFinishReceiver
);
677 mUploadFinishReceiver
= null
;
679 if (mDownloadFinishReceiver
!= null
) {
680 unregisterReceiver(mDownloadFinishReceiver
);
681 mDownloadFinishReceiver
= null
;
684 Log_OC
.d(TAG
, "onPause() end");
689 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
690 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
691 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
697 protected Dialog
onCreateDialog(int id
) {
698 Dialog dialog
= null
;
699 AlertDialog
.Builder builder
;
701 case DIALOG_SHORT_WAIT
: {
702 ProgressDialog working_dialog
= new ProgressDialog(this);
703 working_dialog
.setMessage(getResources().getString(
704 R
.string
.wait_a_moment
));
705 working_dialog
.setIndeterminate(true
);
706 working_dialog
.setCancelable(false
);
707 dialog
= working_dialog
;
710 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
712 String
[] items
= null
;
714 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
715 getString(R
.string
.actionbar_upload_from_apps
),
716 getString(R
.string
.actionbar_failed_instant_upload
) };
718 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
719 getString(R
.string
.actionbar_upload_from_apps
) };
721 if (InstantUploadActivity
.IS_ENABLED
)
726 builder
= new AlertDialog
.Builder(this);
727 builder
.setTitle(R
.string
.actionbar_upload
);
728 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
729 public void onClick(DialogInterface dialog
, int item
) {
732 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
733 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
734 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
736 // TODO create and handle new fragment
737 // LocalFileListFragment
739 } else if (item
== 1) {
740 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
741 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
742 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
743 ACTION_SELECT_CONTENT_FROM_APPS
);
744 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
745 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
746 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
747 startActivity(action
);
751 dialog
= builder
.create();
754 case DIALOG_SSL_VALIDATOR
: {
755 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
758 case DIALOG_CERT_NOT_SAVED
: {
759 builder
= new AlertDialog
.Builder(this);
760 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
761 builder
.setCancelable(false
);
762 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
764 public void onClick(DialogInterface dialog
, int which
) {
768 dialog
= builder
.create();
780 * Show loading dialog
782 public void showLoadingDialog() {
784 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
785 FragmentManager fm
= getSupportFragmentManager();
786 FragmentTransaction ft
= fm
.beginTransaction();
787 loading
.show(ft
, DIALOG_WAIT_TAG
);
792 * Dismiss loading dialog
794 public void dismissLoadingDialog(){
795 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
797 LoadingDialog loading
= (LoadingDialog
) frag
;
804 * Translates a content URI of an image to a physical path
806 * @param uri The URI to resolve
807 * @return The path to the image or null if it could not be found
809 public String
getPath(Uri uri
) {
810 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
811 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
812 if (cursor
!= null
) {
813 int column_index
= cursor
814 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
815 cursor
.moveToFirst();
816 return cursor
.getString(column_index
);
822 * Pushes a directory to the drop down list
823 * @param directory to push
824 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
826 public void pushDirname(OCFile directory
) {
827 if(!directory
.isDirectory()){
828 throw new IllegalArgumentException("Only directories may be pushed!");
830 mDirectories
.insert(directory
.getFileName(), 0);
835 * Pops a directory name from the drop down list
836 * @return True, unless the stack is empty
838 public boolean popDirname() {
839 mDirectories
.remove(mDirectories
.getItem(0));
840 return !mDirectories
.isEmpty();
843 // Custom array adapter to override text colors
844 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
846 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
850 public View
getView(int position
, View convertView
, ViewGroup parent
) {
851 View v
= super.getView(position
, convertView
, parent
);
853 ((TextView
) v
).setTextColor(getResources().getColorStateList(
854 android
.R
.color
.white
));
858 public View
getDropDownView(int position
, View convertView
,
860 View v
= super.getDropDownView(position
, convertView
, parent
);
862 ((TextView
) v
).setTextColor(getResources().getColorStateList(
863 android
.R
.color
.white
));
870 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
873 * {@link BroadcastReceiver} to enable syncing feedback in UI
876 public void onReceive(Context context
, Intent intent
) {
877 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
878 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
879 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
881 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
883 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
885 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
887 OCFile currentFile
= (getFile() == null
) ? null
: mStorageManager
.getFileByPath(getFile().getRemotePath());
888 OCFile currentDir
= (getCurrentDir() == null
) ? null
: mStorageManager
.getFileByPath(getCurrentDir().getRemotePath());
890 if (currentDir
== null
) {
891 // current folder was removed from the server
892 Toast
.makeText( FileDisplayActivity
.this,
893 String
.format(getString(R
.string
.sync_current_folder_was_removed
), mDirectories
.getItem(0)),
899 if (currentFile
== null
&& !getFile().isDirectory()) {
900 // currently selected file was removed in the server, and now we know it
901 cleanSecondFragment();
902 currentFile
= currentDir
;
905 if (synchFolderRemotePath
!= null
&& currentDir
.getRemotePath().equals(synchFolderRemotePath
)) {
906 OCFileListFragment fileListFragment
= getListOfFilesFragment();
907 if (fileListFragment
!= null
) {
908 fileListFragment
.listDirectory(currentDir
);
911 setFile(currentFile
);
914 setSupportProgressBarIndeterminateVisibility(inProgress
);
915 removeStickyBroadcast(intent
);
916 mSyncInProgress
= inProgress
;
920 if (synchResult
!= null
) {
921 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
922 mLastSslUntrustedServerResult
= synchResult
;
923 showDialog(DIALOG_SSL_VALIDATOR
);
930 private class UploadFinishReceiver
extends BroadcastReceiver
{
932 * Once the file upload has finished -> update view
933 * @author David A. Velasco
934 * {@link BroadcastReceiver} to enable upload feedback in UI
937 public void onReceive(Context context
, Intent intent
) {
938 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
939 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
940 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
941 OCFile currentDir
= getCurrentDir();
942 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
943 if (sameAccount
&& isDescendant
) {
944 refeshListOfFilesFragment();
952 * Class waiting for broadcast events from the {@link FielDownloader} service.
954 * Updates the UI when a download is started or finished, provided that it is relevant for the
957 private class DownloadFinishReceiver
extends BroadcastReceiver
{
959 public void onReceive(Context context
, Intent intent
) {
960 boolean sameAccount
= isSameAccount(context
, intent
);
961 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
962 boolean isDescendant
= isDescendant(downloadedRemotePath
);
964 if (sameAccount
&& isDescendant
) {
965 refeshListOfFilesFragment();
966 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
969 removeStickyBroadcast(intent
);
972 private boolean isDescendant(String downloadedRemotePath
) {
973 OCFile currentDir
= getCurrentDir();
974 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
977 private boolean isSameAccount(Context context
, Intent intent
) {
978 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
979 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
988 public DataStorageManager
getStorageManager() {
989 return mStorageManager
;
993 public void browseToRoot() {
994 OCFileListFragment listOfFiles
= getListOfFilesFragment();
995 if (listOfFiles
!= null
) { // should never be null, indeed
996 while (mDirectories
.getCount() > 1) {
999 OCFile root
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
1000 listOfFiles
.listDirectory(root
);
1001 setFile(listOfFiles
.getCurrentFile());
1002 startSyncFolderOperation(root
);
1004 cleanSecondFragment();
1008 public void browseTo(OCFile folder
) {
1009 if (folder
== null
|| !folder
.isDirectory()) {
1010 throw new IllegalArgumentException("Trying to browse to invalid folder " + folder
);
1012 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1013 if (listOfFiles
!= null
) {
1014 setNavigationListWithFolder(folder
);
1015 listOfFiles
.listDirectory(folder
);
1016 setFile(listOfFiles
.getCurrentFile());
1017 startSyncFolderOperation(folder
);
1019 Log_OC
.e(TAG
, "Unexpected null when accessing list fragment");
1021 cleanSecondFragment();
1028 * Updates action bar and second fragment, if in dual pane mode.
1031 public void onBrowsedDownTo(OCFile directory
) {
1032 pushDirname(directory
);
1033 cleanSecondFragment();
1036 startSyncFolderOperation(directory
);
1041 * Opens the image gallery showing the image {@link OCFile} received as parameter.
1043 * @param file Image {@link OCFile} to show.
1046 public void startImagePreview(OCFile file
) {
1047 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
1048 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
1049 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
1050 startActivity(showDetailsIntent
);
1054 * Stars the preview of an already down media {@link OCFile}.
1056 * @param file Media {@link OCFile} to preview.
1057 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
1058 * @param autoplay When 'true', the playback will start without user interactions.
1061 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1062 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1063 setSecondFragment(mediaFragment
);
1064 updateFragmentsVisibility(true
);
1065 updateNavigationElementsInActionBar(file
);
1070 * Requests the download of the received {@link OCFile} , updates the UI
1071 * to monitor the download progress and prepares the activity to preview
1072 * or open the file when the download finishes.
1074 * @param file {@link OCFile} to download and preview.
1077 public void startDownloadForPreview(OCFile file
) {
1078 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1079 setSecondFragment(detailFragment
);
1080 mWaitingToPreview
= file
;
1081 requestForDownload();
1082 updateFragmentsVisibility(true
);
1083 updateNavigationElementsInActionBar(file
);
1089 * Shows the information of the {@link OCFile} received as a
1090 * parameter in the second fragment.
1092 * @param file {@link OCFile} whose details will be shown
1095 public void showDetails(OCFile file
) {
1096 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1097 setSecondFragment(detailFragment
);
1098 updateFragmentsVisibility(true
);
1099 updateNavigationElementsInActionBar(file
);
1107 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1108 ActionBar actionBar
= getSupportActionBar();
1109 if (chosenFile
== null
|| mDualPane
) {
1110 // only list of files - set for browsing through folders
1111 OCFile currentDir
= getCurrentDir();
1112 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1113 actionBar
.setDisplayShowTitleEnabled(false
);
1114 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1115 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1118 actionBar
.setDisplayHomeAsUpEnabled(true
);
1119 actionBar
.setDisplayShowTitleEnabled(true
);
1120 actionBar
.setTitle(chosenFile
.getFileName());
1121 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1126 // private void updateDisplayHomeAtSync(){
1127 // ActionBar actionBar = getSupportActionBar();
1128 // OCFile currentDir = getCurrentDir();
1129 // if (currentDir.getParentId() != DataStorageManager.ROOT_PARENT_ID) {
1130 // actionBar.setHomeButtonEnabled(!mSyncInProgress);
1131 // actionBar.setDisplayHomeAsUpEnabled(!mSyncInProgress);
1134 // actionBar.setHomeButtonEnabled(true);
1135 // actionBar.setDisplayHomeAsUpEnabled(false);
1143 public void onFileStateChanged() {
1144 refeshListOfFilesFragment();
1145 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1153 public FileDownloaderBinder
getFileDownloaderBinder() {
1154 return mDownloaderBinder
;
1162 public FileUploaderBinder
getFileUploaderBinder() {
1163 return mUploaderBinder
;
1167 /** Defines callbacks for service binding, passed to bindService() */
1168 private class ListServiceConnection
implements ServiceConnection
{
1171 public void onServiceConnected(ComponentName component
, IBinder service
) {
1172 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1173 Log_OC
.d(TAG
, "Download service connected");
1174 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1175 if (mWaitingToPreview
!= null
) {
1176 requestForDownload();
1179 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1180 Log_OC
.d(TAG
, "Upload service connected");
1181 mUploaderBinder
= (FileUploaderBinder
) service
;
1185 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1186 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1187 if (listOfFiles
!= null
) {
1188 listOfFiles
.listDirectory();
1190 FileFragment secondFragment
= getSecondFragment();
1191 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1192 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1193 detailFragment
.listenForTransferProgress();
1194 detailFragment
.updateFileDetails(false
, false
);
1199 public void onServiceDisconnected(ComponentName component
) {
1200 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1201 Log_OC
.d(TAG
, "Download service disconnected");
1202 mDownloaderBinder
= null
;
1203 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1204 Log_OC
.d(TAG
, "Upload service disconnected");
1205 mUploaderBinder
= null
;
1213 * Launch an intent to request the PIN code to the user before letting him use the app
1215 private void requestPinCode() {
1216 boolean pinStart
= false
;
1217 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1218 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1220 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1221 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1228 public void onSavedCertificate() {
1229 startSynchronization();
1234 public void onFailedSavingCertificate() {
1235 showDialog(DIALOG_CERT_NOT_SAVED
);
1240 * Updates the view associated to the activity after the finish of some operation over files
1241 * in the current account.
1243 * @param operation Removal operation performed.
1244 * @param result Result of the removal.
1247 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1248 if (operation
instanceof RemoveFileOperation
) {
1249 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1251 } else if (operation
instanceof RenameFileOperation
) {
1252 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1254 } else if (operation
instanceof SynchronizeFileOperation
) {
1255 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1257 } else if (operation
instanceof CreateFolderOperation
) {
1258 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1265 * Updates the view associated to the activity after the finish of an operation trying to remove a
1268 * @param operation Removal operation performed.
1269 * @param result Result of the removal.
1271 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1272 dismissLoadingDialog();
1273 if (result
.isSuccess()) {
1274 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1276 OCFile removedFile
= operation
.getFile();
1277 getSecondFragment();
1278 FileFragment second
= getSecondFragment();
1279 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1280 cleanSecondFragment();
1282 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1283 refeshListOfFilesFragment();
1287 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1289 if (result
.isSslRecoverableException()) {
1290 mLastSslUntrustedServerResult
= result
;
1291 showDialog(DIALOG_SSL_VALIDATOR
);
1297 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1299 * @param operation Creation operation performed.
1300 * @param result Result of the creation.
1302 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1303 if (result
.isSuccess()) {
1304 dismissLoadingDialog();
1305 refeshListOfFilesFragment();
1308 dismissLoadingDialog();
1310 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1313 } catch (NotFoundException e
) {
1314 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1321 * Updates the view associated to the activity after the finish of an operation trying to rename a
1324 * @param operation Renaming operation performed.
1325 * @param result Result of the renaming.
1327 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1328 dismissLoadingDialog();
1329 OCFile renamedFile
= operation
.getFile();
1330 if (result
.isSuccess()) {
1332 FileFragment details
= getSecondFragment();
1333 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1334 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1337 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1338 refeshListOfFilesFragment();
1342 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1343 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1345 // TODO throw again the new rename dialog
1347 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1349 if (result
.isSslRecoverableException()) {
1350 mLastSslUntrustedServerResult
= result
;
1351 showDialog(DIALOG_SSL_VALIDATOR
);
1358 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1359 dismissLoadingDialog();
1360 OCFile syncedFile
= operation
.getLocalFile();
1361 if (!result
.isSuccess()) {
1362 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1363 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1364 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1365 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1371 if (operation
.transferWasRequested()) {
1372 refeshListOfFilesFragment();
1373 onTransferStateChanged(syncedFile
, true
, true
);
1376 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1387 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1389 FileFragment details
= getSecondFragment();
1390 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1391 if (downloading
|| uploading
) {
1392 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1394 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1401 public void onDismiss(EditNameDialog dialog
) {
1402 if (dialog
.getResult()) {
1403 String newDirectoryName
= dialog
.getNewFilename().trim();
1404 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1405 if (newDirectoryName
.length() > 0) {
1406 String path
= getCurrentDir().getRemotePath();
1409 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1410 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1411 operation
.execute( getAccount(),
1412 FileDisplayActivity
.this,
1413 FileDisplayActivity
.this,
1415 FileDisplayActivity
.this);
1417 showLoadingDialog();
1423 private void requestForDownload() {
1424 Account account
= getAccount();
1425 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1426 Intent i
= new Intent(this, FileDownloader
.class);
1427 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1428 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1434 private OCFile
getCurrentDir() {
1435 OCFile file
= getFile();
1437 if (file
.isDirectory()) {
1439 } else if (mStorageManager
!= null
) {
1440 return mStorageManager
.getFileById(file
.getParentId());
1446 public void startSyncFolderOperation(OCFile folder
) {
1447 long currentSyncTime
= System
.currentTimeMillis();
1449 mSyncInProgress
= true
;
1451 // perform folder synchronization
1452 RemoteOperation synchFolderOp
= new SynchronizeFolderOperation( folder
,
1456 getStorageManager(),
1458 getApplicationContext()
1460 synchFolderOp
.execute(getAccount(), this, null
, null
, this);
1462 setSupportProgressBarIndeterminateVisibility(true
);
1466 // public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
1467 // int childCount = viewGroup.getChildCount();
1468 // for (int i = 0; i < childCount; i++) {
1469 // View view = viewGroup.getChildAt(i);
1470 // view.setEnabled(enabled);
1471 // view.setClickable(!enabled);
1472 // if (view instanceof ViewGroup) {
1473 // enableDisableViewGroup((ViewGroup) view, enabled);