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 mDirectories
.clear();
236 OCFile fileIt
= file
;
237 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
238 if (fileIt
.isDirectory()) {
239 mDirectories
.add(fileIt
.getFileName());
241 fileIt
= mStorageManager
.getFileById(fileIt
.getParentId());
243 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
244 if (!stateWasRecovered
) {
245 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
246 initFragmentsWithFile();
249 updateFragmentsVisibility(!file
.isDirectory());
250 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
255 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
260 private void createMinFragments() {
261 OCFileListFragment listOfFiles
= new OCFileListFragment();
262 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
263 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
264 transaction
.commit();
267 private void initFragmentsWithFile() {
268 if (getAccount() != null
&& getFile() != null
) {
270 OCFileListFragment listOfFiles
= getListOfFilesFragment();
271 if (listOfFiles
!= null
) {
272 listOfFiles
.listDirectory(getCurrentDir());
274 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
278 OCFile file
= getFile();
279 Fragment secondFragment
= chooseInitialSecondFragment(file
);
280 if (secondFragment
!= null
) {
281 setSecondFragment(secondFragment
);
282 updateFragmentsVisibility(true
);
283 updateNavigationElementsInActionBar(file
);
286 cleanSecondFragment();
290 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
291 if (getAccount() == null
) {
292 Log
.wtf(TAG
, "\t account is NULL");
294 if (getFile() == null
) {
295 Log
.wtf(TAG
, "\t file is NULL");
300 private Fragment
chooseInitialSecondFragment(OCFile file
) {
301 Fragment secondFragment
= null
;
302 if (file
!= null
&& !file
.isDirectory()) {
303 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
304 && file
.getLastSyncDateForProperties() > 0 // temporal fix
306 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
307 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
308 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
311 secondFragment
= new FileDetailFragment(file
, getAccount());
314 return secondFragment
;
319 * Replaces the second fragment managed by the activity with the received as
322 * Assumes never will be more than two fragments managed at the same time.
324 * @param fragment New second Fragment to set.
326 private void setSecondFragment(Fragment fragment
) {
327 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
328 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
329 transaction
.commit();
333 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
335 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
336 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
338 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
339 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
342 } else if (existsSecondFragment
) {
343 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
344 mLeftFragmentContainer
.setVisibility(View
.GONE
);
346 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
347 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
351 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
352 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
354 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
355 mRightFragmentContainer
.setVisibility(View
.GONE
);
361 private OCFileListFragment
getListOfFilesFragment() {
362 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
363 if (listOfFiles
!= null
) {
364 return (OCFileListFragment
)listOfFiles
;
366 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
370 protected FileFragment
getSecondFragment() {
371 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
372 if (second
!= null
) {
373 return (FileFragment
)second
;
378 public void cleanSecondFragment() {
379 Fragment second
= getSecondFragment();
380 if (second
!= null
) {
381 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
385 updateFragmentsVisibility(false
);
386 updateNavigationElementsInActionBar(null
);
389 protected void refeshListOfFilesFragment() {
390 OCFileListFragment fileListFragment
= getListOfFilesFragment();
391 if (fileListFragment
!= null
) {
392 fileListFragment
.listDirectory();
396 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
397 FileFragment secondFragment
= getSecondFragment();
398 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
399 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
400 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
401 OCFile fileInFragment
= detailsFragment
.getFile();
402 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
403 // the user browsed to other file ; forget the automatic preview
404 mWaitingToPreview
= null
;
406 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
407 // grant that the right panel updates the progress bar
408 detailsFragment
.listenForTransferProgress();
409 detailsFragment
.updateFileDetails(true
, false
);
411 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
412 // update the right panel
413 boolean detailsFragmentChanged
= false
;
416 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
417 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
418 startMediaPreview(mWaitingToPreview
, 0, true
);
419 detailsFragmentChanged
= true
;
421 openFile(mWaitingToPreview
);
424 mWaitingToPreview
= null
;
426 if (!detailsFragmentChanged
) {
427 detailsFragment
.updateFileDetails(false
, (success
));
435 public boolean onCreateOptionsMenu(Menu menu
) {
436 MenuInflater inflater
= getSherlock().getMenuInflater();
437 inflater
.inflate(R
.menu
.main_menu
, menu
);
442 public boolean onOptionsItemSelected(MenuItem item
) {
443 boolean retval
= true
;
444 switch (item
.getItemId()) {
445 case R
.id
.action_create_dir
: {
446 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
447 dialog
.show(getSupportFragmentManager(), "createdirdialog");
450 case R
.id
.action_sync_account
: {
451 startSynchronization();
454 case R
.id
.action_upload
: {
455 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
458 case R
.id
.action_settings
: {
459 Intent settingsIntent
= new Intent(this, Preferences
.class);
460 startActivity(settingsIntent
);
463 case android
.R
.id
.home
: {
464 FileFragment second
= getSecondFragment();
465 OCFile currentDir
= getCurrentDir();
466 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
467 (second
!= null
&& second
.getFile() != null
)) {
474 retval
= super.onOptionsItemSelected(item
);
479 private void startSynchronization() {
480 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
481 Bundle bundle
= new Bundle();
482 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
483 ContentResolver
.requestSync(
485 AccountAuthenticator
.AUTHORITY
, bundle
);
490 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
491 int i
= itemPosition
;
495 // the next operation triggers a new call to this method, but it's necessary to
496 // ensure that the name exposed in the action bar is the current directory when the
497 // user selected it in the navigation list
498 if (itemPosition
!= 0)
499 getSupportActionBar().setSelectedNavigationItem(0);
504 * Called, when the user selected something for uploading
506 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
507 super.onActivityResult(requestCode
, resultCode
, data
);
509 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
510 requestSimpleUpload(data
, resultCode
);
512 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
513 requestMultipleUpload(data
, resultCode
);
518 private void requestMultipleUpload(Intent data
, int resultCode
) {
519 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
520 if (filePaths
!= null
) {
521 String
[] remotePaths
= new String
[filePaths
.length
];
522 String remotePathBase
= "";
523 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
524 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
526 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
527 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
528 for (int j
= 0; j
< remotePaths
.length
; j
++) {
529 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
532 Intent i
= new Intent(this, FileUploader
.class);
533 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
534 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
535 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
536 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
537 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
538 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
542 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
543 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
550 private void requestSimpleUpload(Intent data
, int resultCode
) {
551 String filepath
= null
;
553 Uri selectedImageUri
= data
.getData();
555 String filemanagerstring
= selectedImageUri
.getPath();
556 String selectedImagePath
= getPath(selectedImageUri
);
558 if (selectedImagePath
!= null
)
559 filepath
= selectedImagePath
;
561 filepath
= filemanagerstring
;
563 } catch (Exception e
) {
564 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
568 if (filepath
== null
) {
569 Log_OC
.e(TAG
, "Couldnt resolve path to file");
570 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
576 Intent i
= new Intent(this, FileUploader
.class);
577 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
579 String remotepath
= new String();
580 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
581 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
583 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
584 remotepath
+= OCFile
.PATH_SEPARATOR
;
585 remotepath
+= new File(filepath
).getName();
587 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
588 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
589 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
590 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
591 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
596 public void onBackPressed() {
597 OCFileListFragment listOfFiles
= getListOfFilesFragment();
598 if (mDualPane
|| getSecondFragment() == null
) {
599 if (listOfFiles
!= null
) { // should never be null, indeed
600 if (mDirectories
.getCount() <= 1) {
604 int levelsUp
= listOfFiles
.onBrowseUp();
605 for (int i
=0; i
< levelsUp
&& mDirectories
.getCount() > 1 ; i
++) {
610 if (listOfFiles
!= null
) { // should never be null, indeed
611 setFile(listOfFiles
.getCurrentFile());
613 cleanSecondFragment();
618 protected void onSaveInstanceState(Bundle outState
) {
619 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
620 Log_OC
.e(TAG
, "onSaveInstanceState() start");
621 super.onSaveInstanceState(outState
);
622 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
623 outState
.putBoolean(FileDisplayActivity
.KEY_SYNC_IN_PROGRESS
, mSyncInProgress
);
625 Log_OC
.d(TAG
, "onSaveInstanceState() end");
631 protected void onResume() {
633 Log_OC
.e(TAG
, "onResume() start");
635 // Listen for sync messages
636 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
637 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
638 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
640 // Listen for upload messages
641 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
642 mUploadFinishReceiver
= new UploadFinishReceiver();
643 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
645 // Listen for download messages
646 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
647 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
648 mDownloadFinishReceiver
= new DownloadFinishReceiver();
649 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
651 Log_OC
.d(TAG
, "onResume() end");
656 protected void onPause() {
658 Log_OC
.e(TAG
, "onPause() start");
659 if (mSyncBroadcastReceiver
!= null
) {
660 unregisterReceiver(mSyncBroadcastReceiver
);
661 mSyncBroadcastReceiver
= null
;
663 if (mUploadFinishReceiver
!= null
) {
664 unregisterReceiver(mUploadFinishReceiver
);
665 mUploadFinishReceiver
= null
;
667 if (mDownloadFinishReceiver
!= null
) {
668 unregisterReceiver(mDownloadFinishReceiver
);
669 mDownloadFinishReceiver
= null
;
672 Log_OC
.d(TAG
, "onPause() end");
677 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
678 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
679 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
685 protected Dialog
onCreateDialog(int id
) {
686 Dialog dialog
= null
;
687 AlertDialog
.Builder builder
;
689 case DIALOG_SHORT_WAIT
: {
690 ProgressDialog working_dialog
= new ProgressDialog(this);
691 working_dialog
.setMessage(getResources().getString(
692 R
.string
.wait_a_moment
));
693 working_dialog
.setIndeterminate(true
);
694 working_dialog
.setCancelable(false
);
695 dialog
= working_dialog
;
698 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
700 String
[] items
= null
;
702 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
703 getString(R
.string
.actionbar_upload_from_apps
),
704 getString(R
.string
.actionbar_failed_instant_upload
) };
706 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
707 getString(R
.string
.actionbar_upload_from_apps
) };
709 if (InstantUploadActivity
.IS_ENABLED
)
714 builder
= new AlertDialog
.Builder(this);
715 builder
.setTitle(R
.string
.actionbar_upload
);
716 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
717 public void onClick(DialogInterface dialog
, int item
) {
720 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
721 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
722 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
724 // TODO create and handle new fragment
725 // LocalFileListFragment
727 } else if (item
== 1) {
728 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
729 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
730 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
731 ACTION_SELECT_CONTENT_FROM_APPS
);
732 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
733 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
734 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
735 startActivity(action
);
739 dialog
= builder
.create();
742 case DIALOG_SSL_VALIDATOR
: {
743 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
746 case DIALOG_CERT_NOT_SAVED
: {
747 builder
= new AlertDialog
.Builder(this);
748 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
749 builder
.setCancelable(false
);
750 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
752 public void onClick(DialogInterface dialog
, int which
) {
756 dialog
= builder
.create();
768 * Show loading dialog
770 public void showLoadingDialog() {
772 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
773 FragmentManager fm
= getSupportFragmentManager();
774 FragmentTransaction ft
= fm
.beginTransaction();
775 loading
.show(ft
, DIALOG_WAIT_TAG
);
780 * Dismiss loading dialog
782 public void dismissLoadingDialog(){
783 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
785 LoadingDialog loading
= (LoadingDialog
) frag
;
792 * Translates a content URI of an image to a physical path
794 * @param uri The URI to resolve
795 * @return The path to the image or null if it could not be found
797 public String
getPath(Uri uri
) {
798 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
799 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
800 if (cursor
!= null
) {
801 int column_index
= cursor
802 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
803 cursor
.moveToFirst();
804 return cursor
.getString(column_index
);
810 * Pushes a directory to the drop down list
811 * @param directory to push
812 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
814 public void pushDirname(OCFile directory
) {
815 if(!directory
.isDirectory()){
816 throw new IllegalArgumentException("Only directories may be pushed!");
818 mDirectories
.insert(directory
.getFileName(), 0);
823 * Pops a directory name from the drop down list
824 * @return True, unless the stack is empty
826 public boolean popDirname() {
827 mDirectories
.remove(mDirectories
.getItem(0));
828 return !mDirectories
.isEmpty();
831 // Custom array adapter to override text colors
832 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
834 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
838 public View
getView(int position
, View convertView
, ViewGroup parent
) {
839 View v
= super.getView(position
, convertView
, parent
);
841 ((TextView
) v
).setTextColor(getResources().getColorStateList(
842 android
.R
.color
.white
));
846 public View
getDropDownView(int position
, View convertView
,
848 View v
= super.getDropDownView(position
, convertView
, parent
);
850 ((TextView
) v
).setTextColor(getResources().getColorStateList(
851 android
.R
.color
.white
));
858 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
861 * {@link BroadcastReceiver} to enable syncing feedback in UI
864 public void onReceive(Context context
, Intent intent
) {
865 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
866 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
867 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
869 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
871 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
873 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
875 OCFile currentFile
= (getFile() == null
) ? null
: mStorageManager
.getFileByPath(getFile().getRemotePath());
876 OCFile currentDir
= (getCurrentDir() == null
) ? null
: mStorageManager
.getFileByPath(getCurrentDir().getRemotePath());
878 if (currentDir
== null
) {
879 // current folder was removed from the server
880 Toast
.makeText(FileDisplayActivity
.this, getString(R
.string
.sync_current_folder_was_removed
), Toast
.LENGTH_LONG
)
885 if (currentFile
== null
&& !getFile().isDirectory()) {
886 // currently selected file was removed in the server, and now we know it
887 cleanSecondFragment();
888 currentFile
= currentDir
;
891 if (synchFolderRemotePath
!= null
&& currentDir
.getRemotePath().equals(synchFolderRemotePath
)) {
892 OCFileListFragment fileListFragment
= getListOfFilesFragment();
893 if (fileListFragment
!= null
) {
894 fileListFragment
.listDirectory(currentDir
);
897 setFile(currentFile
);
900 setSupportProgressBarIndeterminateVisibility(inProgress
);
901 removeStickyBroadcast(intent
);
902 mSyncInProgress
= inProgress
;
906 if (synchResult
!= null
) {
907 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
908 mLastSslUntrustedServerResult
= synchResult
;
909 showDialog(DIALOG_SSL_VALIDATOR
);
916 private class UploadFinishReceiver
extends BroadcastReceiver
{
918 * Once the file upload has finished -> update view
919 * @author David A. Velasco
920 * {@link BroadcastReceiver} to enable upload feedback in UI
923 public void onReceive(Context context
, Intent intent
) {
924 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
925 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
926 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
927 OCFile currentDir
= getCurrentDir();
928 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
929 if (sameAccount
&& isDescendant
) {
930 refeshListOfFilesFragment();
938 * Class waiting for broadcast events from the {@link FielDownloader} service.
940 * Updates the UI when a download is started or finished, provided that it is relevant for the
943 private class DownloadFinishReceiver
extends BroadcastReceiver
{
945 public void onReceive(Context context
, Intent intent
) {
946 boolean sameAccount
= isSameAccount(context
, intent
);
947 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
948 boolean isDescendant
= isDescendant(downloadedRemotePath
);
950 if (sameAccount
&& isDescendant
) {
951 refeshListOfFilesFragment();
952 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
955 removeStickyBroadcast(intent
);
958 private boolean isDescendant(String downloadedRemotePath
) {
959 OCFile currentDir
= getCurrentDir();
960 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
963 private boolean isSameAccount(Context context
, Intent intent
) {
964 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
965 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
974 public DataStorageManager
getStorageManager() {
975 return mStorageManager
;
982 * Updates action bar and second fragment, if in dual pane mode.
985 public void onBrowsedDownTo(OCFile directory
) {
986 pushDirname(directory
);
987 cleanSecondFragment();
990 startSyncFolderOperation(directory
);
995 * Opens the image gallery showing the image {@link OCFile} received as parameter.
997 * @param file Image {@link OCFile} to show.
1000 public void startImagePreview(OCFile file
) {
1001 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
1002 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
1003 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
1004 startActivity(showDetailsIntent
);
1008 * Stars the preview of an already down media {@link OCFile}.
1010 * @param file Media {@link OCFile} to preview.
1011 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
1012 * @param autoplay When 'true', the playback will start without user interactions.
1015 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1016 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1017 setSecondFragment(mediaFragment
);
1018 updateFragmentsVisibility(true
);
1019 updateNavigationElementsInActionBar(file
);
1024 * Requests the download of the received {@link OCFile} , updates the UI
1025 * to monitor the download progress and prepares the activity to preview
1026 * or open the file when the download finishes.
1028 * @param file {@link OCFile} to download and preview.
1031 public void startDownloadForPreview(OCFile file
) {
1032 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1033 setSecondFragment(detailFragment
);
1034 mWaitingToPreview
= file
;
1035 requestForDownload();
1036 updateFragmentsVisibility(true
);
1037 updateNavigationElementsInActionBar(file
);
1043 * Shows the information of the {@link OCFile} received as a
1044 * parameter in the second fragment.
1046 * @param file {@link OCFile} whose details will be shown
1049 public void showDetails(OCFile file
) {
1050 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1051 setSecondFragment(detailFragment
);
1052 updateFragmentsVisibility(true
);
1053 updateNavigationElementsInActionBar(file
);
1061 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1062 ActionBar actionBar
= getSupportActionBar();
1063 if (chosenFile
== null
|| mDualPane
) {
1064 // only list of files - set for browsing through folders
1065 OCFile currentDir
= getCurrentDir();
1066 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1067 actionBar
.setDisplayShowTitleEnabled(false
);
1068 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1069 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1072 actionBar
.setDisplayHomeAsUpEnabled(true
);
1073 actionBar
.setDisplayShowTitleEnabled(true
);
1074 actionBar
.setTitle(chosenFile
.getFileName());
1075 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1080 // private void updateDisplayHomeAtSync(){
1081 // ActionBar actionBar = getSupportActionBar();
1082 // OCFile currentDir = getCurrentDir();
1083 // if (currentDir.getParentId() != DataStorageManager.ROOT_PARENT_ID) {
1084 // actionBar.setHomeButtonEnabled(!mSyncInProgress);
1085 // actionBar.setDisplayHomeAsUpEnabled(!mSyncInProgress);
1088 // actionBar.setHomeButtonEnabled(true);
1089 // actionBar.setDisplayHomeAsUpEnabled(false);
1097 public void onFileStateChanged() {
1098 refeshListOfFilesFragment();
1099 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1107 public FileDownloaderBinder
getFileDownloaderBinder() {
1108 return mDownloaderBinder
;
1116 public FileUploaderBinder
getFileUploaderBinder() {
1117 return mUploaderBinder
;
1121 /** Defines callbacks for service binding, passed to bindService() */
1122 private class ListServiceConnection
implements ServiceConnection
{
1125 public void onServiceConnected(ComponentName component
, IBinder service
) {
1126 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1127 Log_OC
.d(TAG
, "Download service connected");
1128 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1129 if (mWaitingToPreview
!= null
) {
1130 requestForDownload();
1133 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1134 Log_OC
.d(TAG
, "Upload service connected");
1135 mUploaderBinder
= (FileUploaderBinder
) service
;
1139 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1140 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1141 if (listOfFiles
!= null
) {
1142 listOfFiles
.listDirectory();
1144 FileFragment secondFragment
= getSecondFragment();
1145 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1146 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1147 detailFragment
.listenForTransferProgress();
1148 detailFragment
.updateFileDetails(false
, false
);
1153 public void onServiceDisconnected(ComponentName component
) {
1154 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1155 Log_OC
.d(TAG
, "Download service disconnected");
1156 mDownloaderBinder
= null
;
1157 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1158 Log_OC
.d(TAG
, "Upload service disconnected");
1159 mUploaderBinder
= null
;
1167 * Launch an intent to request the PIN code to the user before letting him use the app
1169 private void requestPinCode() {
1170 boolean pinStart
= false
;
1171 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1172 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1174 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1175 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1182 public void onSavedCertificate() {
1183 startSynchronization();
1188 public void onFailedSavingCertificate() {
1189 showDialog(DIALOG_CERT_NOT_SAVED
);
1194 * Updates the view associated to the activity after the finish of some operation over files
1195 * in the current account.
1197 * @param operation Removal operation performed.
1198 * @param result Result of the removal.
1201 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1202 if (operation
instanceof RemoveFileOperation
) {
1203 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1205 } else if (operation
instanceof RenameFileOperation
) {
1206 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1208 } else if (operation
instanceof SynchronizeFileOperation
) {
1209 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1211 } else if (operation
instanceof CreateFolderOperation
) {
1212 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1219 * Updates the view associated to the activity after the finish of an operation trying to remove a
1222 * @param operation Removal operation performed.
1223 * @param result Result of the removal.
1225 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1226 dismissLoadingDialog();
1227 if (result
.isSuccess()) {
1228 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1230 OCFile removedFile
= operation
.getFile();
1231 getSecondFragment();
1232 FileFragment second
= getSecondFragment();
1233 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1234 cleanSecondFragment();
1236 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1237 refeshListOfFilesFragment();
1241 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1243 if (result
.isSslRecoverableException()) {
1244 mLastSslUntrustedServerResult
= result
;
1245 showDialog(DIALOG_SSL_VALIDATOR
);
1251 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1253 * @param operation Creation operation performed.
1254 * @param result Result of the creation.
1256 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1257 if (result
.isSuccess()) {
1258 dismissLoadingDialog();
1259 refeshListOfFilesFragment();
1262 dismissLoadingDialog();
1264 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1267 } catch (NotFoundException e
) {
1268 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1275 * Updates the view associated to the activity after the finish of an operation trying to rename a
1278 * @param operation Renaming operation performed.
1279 * @param result Result of the renaming.
1281 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1282 dismissLoadingDialog();
1283 OCFile renamedFile
= operation
.getFile();
1284 if (result
.isSuccess()) {
1286 FileFragment details
= getSecondFragment();
1287 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1288 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1291 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1292 refeshListOfFilesFragment();
1296 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1297 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1299 // TODO throw again the new rename dialog
1301 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1303 if (result
.isSslRecoverableException()) {
1304 mLastSslUntrustedServerResult
= result
;
1305 showDialog(DIALOG_SSL_VALIDATOR
);
1312 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1313 dismissLoadingDialog();
1314 OCFile syncedFile
= operation
.getLocalFile();
1315 if (!result
.isSuccess()) {
1316 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1317 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1318 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1319 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1325 if (operation
.transferWasRequested()) {
1326 refeshListOfFilesFragment();
1327 onTransferStateChanged(syncedFile
, true
, true
);
1330 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1341 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1343 FileFragment details
= getSecondFragment();
1344 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1345 if (downloading
|| uploading
) {
1346 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1348 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1355 public void onDismiss(EditNameDialog dialog
) {
1356 if (dialog
.getResult()) {
1357 String newDirectoryName
= dialog
.getNewFilename().trim();
1358 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1359 if (newDirectoryName
.length() > 0) {
1360 String path
= getCurrentDir().getRemotePath();
1363 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1364 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1365 operation
.execute( getAccount(),
1366 FileDisplayActivity
.this,
1367 FileDisplayActivity
.this,
1369 FileDisplayActivity
.this);
1371 showLoadingDialog();
1377 private void requestForDownload() {
1378 Account account
= getAccount();
1379 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1380 Intent i
= new Intent(this, FileDownloader
.class);
1381 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1382 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1388 private OCFile
getCurrentDir() {
1389 OCFile file
= getFile();
1391 if (file
.isDirectory()) {
1393 } else if (mStorageManager
!= null
) {
1394 return mStorageManager
.getFileById(file
.getParentId());
1400 public void startSyncFolderOperation(OCFile folder
) {
1401 long currentSyncTime
= System
.currentTimeMillis();
1403 mSyncInProgress
= true
;
1405 // perform folder synchronization
1406 RemoteOperation synchFolderOp
= new SynchronizeFolderOperation( folder
,
1410 getStorageManager(),
1412 getApplicationContext()
1414 synchFolderOp
.execute(getAccount(), this, null
, null
, this);
1416 setSupportProgressBarIndeterminateVisibility(true
);
1420 // public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
1421 // int childCount = viewGroup.getChildCount();
1422 // for (int i = 0; i < childCount; i++) {
1423 // View view = viewGroup.getChildAt(i);
1424 // view.setEnabled(enabled);
1425 // view.setClickable(!enabled);
1426 // if (view instanceof ViewGroup) {
1427 // enableDisableViewGroup((ViewGroup) view, enabled);