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
;
22 import java
.io
.IOException
;
24 import android
.accounts
.Account
;
25 import android
.accounts
.AuthenticatorException
;
26 import android
.accounts
.OperationCanceledException
;
27 import android
.app
.AlertDialog
;
28 import android
.app
.ProgressDialog
;
29 import android
.app
.Dialog
;
30 import android
.content
.BroadcastReceiver
;
31 import android
.content
.ComponentName
;
32 import android
.content
.ContentResolver
;
33 import android
.content
.Context
;
34 import android
.content
.DialogInterface
;
35 import android
.content
.Intent
;
36 import android
.content
.IntentFilter
;
37 import android
.content
.ServiceConnection
;
38 import android
.content
.SharedPreferences
;
39 import android
.content
.res
.Resources
.NotFoundException
;
40 import android
.database
.Cursor
;
41 import android
.net
.Uri
;
42 import android
.os
.Bundle
;
43 import android
.os
.Handler
;
44 import android
.os
.IBinder
;
45 import android
.preference
.PreferenceManager
;
46 import android
.provider
.MediaStore
;
47 import android
.support
.v4
.app
.Fragment
;
48 import android
.support
.v4
.app
.FragmentManager
;
49 import android
.support
.v4
.app
.FragmentTransaction
;
50 import android
.util
.Log
;
51 import android
.view
.View
;
52 import android
.view
.ViewGroup
;
53 import android
.widget
.ArrayAdapter
;
54 import android
.widget
.TextView
;
55 import android
.widget
.Toast
;
57 import com
.actionbarsherlock
.app
.ActionBar
;
58 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
59 import com
.actionbarsherlock
.view
.Menu
;
60 import com
.actionbarsherlock
.view
.MenuInflater
;
61 import com
.actionbarsherlock
.view
.MenuItem
;
62 import com
.actionbarsherlock
.view
.Window
;
63 import com
.owncloud
.android
.Log_OC
;
64 import com
.owncloud
.android
.R
;
65 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
66 import com
.owncloud
.android
.authentication
.AccountUtils
;
67 import com
.owncloud
.android
.authentication
.AccountUtils
.AccountNotFoundException
;
68 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
69 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
70 import com
.owncloud
.android
.datamodel
.OCFile
;
71 import com
.owncloud
.android
.files
.services
.FileDownloader
;
72 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
73 import com
.owncloud
.android
.files
.services
.FileObserverService
;
74 import com
.owncloud
.android
.files
.services
.FileUploader
;
75 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
76 import com
.owncloud
.android
.network
.OwnCloudClientUtils
;
77 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
78 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
79 import com
.owncloud
.android
.operations
.RemoteOperation
;
80 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
81 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
82 import com
.owncloud
.android
.operations
.RenameFileOperation
;
83 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
84 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
85 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
86 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
87 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
88 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
89 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
90 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
91 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
92 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
93 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
94 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
95 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
96 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
97 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
99 import eu
.alefzero
.webdav
.WebdavClient
;
102 * Displays, what files the user has available in his ownCloud.
104 * @author Bartek Przybylski
105 * @author David A. Velasco
108 public class FileDisplayActivity
extends FileActivity
implements
109 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
111 private ArrayAdapter
<String
> mDirectories
;
113 /** Access point to the cached database for the current ownCloud {@link Account} */
114 private DataStorageManager mStorageManager
= null
;
116 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
117 private UploadFinishReceiver mUploadFinishReceiver
;
118 private DownloadFinishReceiver mDownloadFinishReceiver
;
119 private FileDownloaderBinder mDownloaderBinder
= null
;
120 private FileUploaderBinder mUploaderBinder
= null
;
121 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
122 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
124 private boolean mDualPane
;
125 private View mLeftFragmentContainer
;
126 private View mRightFragmentContainer
;
128 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
130 public static final int DIALOG_SHORT_WAIT
= 0;
131 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
132 private static final int DIALOG_SSL_VALIDATOR
= 2;
133 private static final int DIALOG_CERT_NOT_SAVED
= 3;
135 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
137 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
139 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
140 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
142 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
144 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
145 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
147 private OCFile mWaitingToPreview
;
148 private Handler mHandler
;
151 protected void onCreate(Bundle savedInstanceState
) {
152 Log_OC
.d(TAG
, "onCreate() start");
153 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
155 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
157 mHandler
= new Handler();
159 /// bindings to transference services
160 mUploadConnection
= new ListServiceConnection();
161 mDownloadConnection
= new ListServiceConnection();
162 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
163 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
165 // PIN CODE request ; best location is to decide, let's try this first
166 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
171 Intent observer_intent
= new Intent(this, FileObserverService
.class);
172 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
173 startService(observer_intent
);
175 /// Load of saved instance state
176 if(savedInstanceState
!= null
) {
177 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
180 mWaitingToPreview
= null
;
185 // Inflate and set the layout view
186 setContentView(R
.layout
.files
);
187 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
188 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
189 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
190 if (savedInstanceState
== null
) {
191 createMinFragments();
195 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
196 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
197 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to work around bug in its implementation
199 Log_OC
.d(TAG
, "onCreate() end");
204 protected void onDestroy() {
206 if (mDownloadConnection
!= null
)
207 unbindService(mDownloadConnection
);
208 if (mUploadConnection
!= null
)
209 unbindService(mUploadConnection
);
214 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
217 protected void onAccountSet(boolean stateWasRecovered
) {
218 if (getAccount() != null
) {
219 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
221 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
222 OCFile file
= getFile();
224 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
225 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
226 if (mStorageManager
.getFileById(file
.getParentId()) == null
) {
227 file
= null
; // not able to know the directory where the file is uploading
230 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
234 // fall back to root folder
235 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
238 mDirectories
.clear();
239 OCFile fileIt
= file
;
240 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
241 if (fileIt
.isDirectory()) {
242 mDirectories
.add(fileIt
.getFileName());
244 fileIt
= mStorageManager
.getFileById(fileIt
.getParentId());
246 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
247 if (!stateWasRecovered
) {
248 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
249 initFragmentsWithFile();
252 updateFragmentsVisibility(!file
.isDirectory());
253 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
258 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
263 private void createMinFragments() {
264 OCFileListFragment listOfFiles
= new OCFileListFragment();
265 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
266 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
267 transaction
.commit();
270 private void initFragmentsWithFile() {
271 if (getAccount() != null
&& getFile() != null
) {
273 OCFileListFragment listOfFiles
= getListOfFilesFragment();
274 if (listOfFiles
!= null
) {
275 listOfFiles
.listDirectory(getCurrentDir());
277 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
281 OCFile file
= getFile();
282 Fragment secondFragment
= chooseInitialSecondFragment(file
);
283 if (secondFragment
!= null
) {
284 setSecondFragment(secondFragment
);
285 updateFragmentsVisibility(true
);
286 updateNavigationElementsInActionBar(file
);
289 cleanSecondFragment();
293 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
294 if (getAccount() == null
) {
295 Log
.wtf(TAG
, "\t account is NULL");
297 if (getFile() == null
) {
298 Log
.wtf(TAG
, "\t file is NULL");
303 private Fragment
chooseInitialSecondFragment(OCFile file
) {
304 Fragment secondFragment
= null
;
305 if (file
!= null
&& !file
.isDirectory()) {
306 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
307 && file
.getLastSyncDateForProperties() > 0 // temporal fix
309 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
310 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
311 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
314 secondFragment
= new FileDetailFragment(file
, getAccount());
317 return secondFragment
;
322 * Replaces the second fragment managed by the activity with the received as
325 * Assumes never will be more than two fragments managed at the same time.
327 * @param fragment New second Fragment to set.
329 private void setSecondFragment(Fragment fragment
) {
330 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
331 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
332 transaction
.commit();
336 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
338 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
339 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
341 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
342 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
345 } else if (existsSecondFragment
) {
346 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
347 mLeftFragmentContainer
.setVisibility(View
.GONE
);
349 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
350 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
354 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
355 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
357 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
358 mRightFragmentContainer
.setVisibility(View
.GONE
);
364 private OCFileListFragment
getListOfFilesFragment() {
365 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
366 if (listOfFiles
!= null
) {
367 return (OCFileListFragment
)listOfFiles
;
369 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
373 protected FileFragment
getSecondFragment() {
374 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
375 if (second
!= null
) {
376 return (FileFragment
)second
;
381 public void cleanSecondFragment() {
382 Fragment second
= getSecondFragment();
383 if (second
!= null
) {
384 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
388 updateFragmentsVisibility(false
);
389 updateNavigationElementsInActionBar(null
);
392 protected void refeshListOfFilesFragment() {
393 OCFileListFragment fileListFragment
= getListOfFilesFragment();
394 if (fileListFragment
!= null
) {
395 fileListFragment
.listDirectory();
399 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
400 FileFragment secondFragment
= getSecondFragment();
401 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
402 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
403 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
404 OCFile fileInFragment
= detailsFragment
.getFile();
405 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
406 // the user browsed to other file ; forget the automatic preview
407 mWaitingToPreview
= null
;
409 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
410 // grant that the right panel updates the progress bar
411 detailsFragment
.listenForTransferProgress();
412 detailsFragment
.updateFileDetails(true
, false
);
414 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
415 // update the right panel
416 boolean detailsFragmentChanged
= false
;
419 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
420 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
421 startMediaPreview(mWaitingToPreview
, 0, true
);
422 detailsFragmentChanged
= true
;
424 openFile(mWaitingToPreview
);
427 mWaitingToPreview
= null
;
429 if (!detailsFragmentChanged
) {
430 detailsFragment
.updateFileDetails(false
, (success
));
438 public boolean onCreateOptionsMenu(Menu menu
) {
439 MenuInflater inflater
= getSherlock().getMenuInflater();
440 inflater
.inflate(R
.menu
.main_menu
, menu
);
445 public boolean onOptionsItemSelected(MenuItem item
) {
446 boolean retval
= true
;
447 switch (item
.getItemId()) {
448 case R
.id
.action_create_dir
: {
449 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
450 dialog
.show(getSupportFragmentManager(), "createdirdialog");
453 case R
.id
.action_sync_account
: {
454 startSynchronization();
457 case R
.id
.action_upload
: {
458 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
461 case R
.id
.action_settings
: {
462 Intent settingsIntent
= new Intent(this, Preferences
.class);
463 startActivity(settingsIntent
);
466 case android
.R
.id
.home
: {
467 FileFragment second
= getSecondFragment();
468 OCFile currentDir
= getCurrentDir();
469 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
470 (second
!= null
&& second
.getFile() != null
)) {
477 retval
= super.onOptionsItemSelected(item
);
482 private void startSynchronization() {
483 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
484 Bundle bundle
= new Bundle();
485 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
486 ContentResolver
.requestSync(
488 AccountAuthenticator
.AUTHORITY
, bundle
);
493 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
494 int i
= itemPosition
;
498 // the next operation triggers a new call to this method, but it's necessary to
499 // ensure that the name exposed in the action bar is the current directory when the
500 // user selected it in the navigation list
501 if (itemPosition
!= 0)
502 getSupportActionBar().setSelectedNavigationItem(0);
507 * Called, when the user selected something for uploading
509 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
510 super.onActivityResult(requestCode
, resultCode
, data
);
512 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
513 requestSimpleUpload(data
, resultCode
);
515 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
516 requestMultipleUpload(data
, resultCode
);
521 private void requestMultipleUpload(Intent data
, int resultCode
) {
522 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
523 if (filePaths
!= null
) {
524 String
[] remotePaths
= new String
[filePaths
.length
];
525 String remotePathBase
= "";
526 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
527 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
529 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
530 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
531 for (int j
= 0; j
< remotePaths
.length
; j
++) {
532 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
535 Intent i
= new Intent(this, FileUploader
.class);
536 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
537 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
538 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
539 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
540 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
541 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
545 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
546 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
553 private void requestSimpleUpload(Intent data
, int resultCode
) {
554 String filepath
= null
;
556 Uri selectedImageUri
= data
.getData();
558 String filemanagerstring
= selectedImageUri
.getPath();
559 String selectedImagePath
= getPath(selectedImageUri
);
561 if (selectedImagePath
!= null
)
562 filepath
= selectedImagePath
;
564 filepath
= filemanagerstring
;
566 } catch (Exception e
) {
567 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
571 if (filepath
== null
) {
572 Log_OC
.e(TAG
, "Couldnt resolve path to file");
573 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
579 Intent i
= new Intent(this, FileUploader
.class);
580 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
582 String remotepath
= new String();
583 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
584 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
586 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
587 remotepath
+= OCFile
.PATH_SEPARATOR
;
588 remotepath
+= new File(filepath
).getName();
590 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
591 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
592 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
593 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
594 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
599 public void onBackPressed() {
600 OCFileListFragment listOfFiles
= getListOfFilesFragment();
601 if (mDualPane
|| getSecondFragment() == null
) {
602 if (listOfFiles
!= null
) { // should never be null, indeed
603 if (mDirectories
.getCount() <= 1) {
608 listOfFiles
.onBrowseUp();
611 if (listOfFiles
!= null
) { // should never be null, indeed
612 setFile(listOfFiles
.getCurrentFile());
614 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 Log_OC
.d(TAG
, "onSaveInstanceState() end");
629 protected void onResume() {
631 Log_OC
.e(TAG
, "onResume() start");
633 // Listen for sync messages
634 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
635 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
636 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
638 // Listen for upload messages
639 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
640 mUploadFinishReceiver
= new UploadFinishReceiver();
641 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
643 // Listen for download messages
644 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
645 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
646 mDownloadFinishReceiver
= new DownloadFinishReceiver();
647 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
649 Log_OC
.d(TAG
, "onResume() end");
654 protected void onPause() {
656 Log_OC
.e(TAG
, "onPause() start");
657 if (mSyncBroadcastReceiver
!= null
) {
658 unregisterReceiver(mSyncBroadcastReceiver
);
659 mSyncBroadcastReceiver
= null
;
661 if (mUploadFinishReceiver
!= null
) {
662 unregisterReceiver(mUploadFinishReceiver
);
663 mUploadFinishReceiver
= null
;
665 if (mDownloadFinishReceiver
!= null
) {
666 unregisterReceiver(mDownloadFinishReceiver
);
667 mDownloadFinishReceiver
= null
;
670 Log_OC
.d(TAG
, "onPause() end");
675 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
676 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
677 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
683 protected Dialog
onCreateDialog(int id
) {
684 Dialog dialog
= null
;
685 AlertDialog
.Builder builder
;
687 case DIALOG_SHORT_WAIT
: {
688 ProgressDialog working_dialog
= new ProgressDialog(this);
689 working_dialog
.setMessage(getResources().getString(
690 R
.string
.wait_a_moment
));
691 working_dialog
.setIndeterminate(true
);
692 working_dialog
.setCancelable(false
);
693 dialog
= working_dialog
;
696 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
698 String
[] items
= null
;
700 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
701 getString(R
.string
.actionbar_upload_from_apps
),
702 getString(R
.string
.actionbar_failed_instant_upload
) };
704 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
705 getString(R
.string
.actionbar_upload_from_apps
) };
707 if (InstantUploadActivity
.IS_ENABLED
)
712 builder
= new AlertDialog
.Builder(this);
713 builder
.setTitle(R
.string
.actionbar_upload
);
714 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
715 public void onClick(DialogInterface dialog
, int item
) {
718 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
719 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
720 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
722 // TODO create and handle new fragment
723 // LocalFileListFragment
725 } else if (item
== 1) {
726 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
727 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
728 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
729 ACTION_SELECT_CONTENT_FROM_APPS
);
730 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
731 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
732 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
733 startActivity(action
);
737 dialog
= builder
.create();
740 case DIALOG_SSL_VALIDATOR
: {
741 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
744 case DIALOG_CERT_NOT_SAVED
: {
745 builder
= new AlertDialog
.Builder(this);
746 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
747 builder
.setCancelable(false
);
748 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
750 public void onClick(DialogInterface dialog
, int which
) {
754 dialog
= builder
.create();
766 * Show loading dialog
768 public void showLoadingDialog() {
770 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
771 FragmentManager fm
= getSupportFragmentManager();
772 FragmentTransaction ft
= fm
.beginTransaction();
773 loading
.show(ft
, DIALOG_WAIT_TAG
);
778 * Dismiss loading dialog
780 public void dismissLoadingDialog(){
781 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
783 LoadingDialog loading
= (LoadingDialog
) frag
;
790 * Translates a content URI of an image to a physical path
792 * @param uri The URI to resolve
793 * @return The path to the image or null if it could not be found
795 public String
getPath(Uri uri
) {
796 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
797 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
798 if (cursor
!= null
) {
799 int column_index
= cursor
800 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
801 cursor
.moveToFirst();
802 return cursor
.getString(column_index
);
808 * Pushes a directory to the drop down list
809 * @param directory to push
810 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
812 public void pushDirname(OCFile directory
) {
813 if(!directory
.isDirectory()){
814 throw new IllegalArgumentException("Only directories may be pushed!");
816 mDirectories
.insert(directory
.getFileName(), 0);
821 * Pops a directory name from the drop down list
822 * @return True, unless the stack is empty
824 public boolean popDirname() {
825 mDirectories
.remove(mDirectories
.getItem(0));
826 return !mDirectories
.isEmpty();
829 // Custom array adapter to override text colors
830 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
832 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
836 public View
getView(int position
, View convertView
, ViewGroup parent
) {
837 View v
= super.getView(position
, convertView
, parent
);
839 ((TextView
) v
).setTextColor(getResources().getColorStateList(
840 android
.R
.color
.white
));
844 public View
getDropDownView(int position
, View convertView
,
846 View v
= super.getDropDownView(position
, convertView
, parent
);
848 ((TextView
) v
).setTextColor(getResources().getColorStateList(
849 android
.R
.color
.white
));
856 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
859 * {@link BroadcastReceiver} to enable syncing feedback in UI
862 public void onReceive(Context context
, Intent intent
) {
863 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
864 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
866 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
868 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
870 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
872 boolean fillBlankRoot
= false
;
873 OCFile currentDir
= getCurrentDir();
874 if (currentDir
== null
) {
875 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
876 fillBlankRoot
= (currentDir
!= null
);
879 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
882 currentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
883 OCFileListFragment fileListFragment
= getListOfFilesFragment();
884 if (fileListFragment
!= null
) {
885 fileListFragment
.listDirectory(currentDir
);
887 if (getSecondFragment() == null
)
891 setSupportProgressBarIndeterminateVisibility(inProgress
);
892 removeStickyBroadcast(intent
);
896 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
897 if (synchResult
!= null
) {
898 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
899 mLastSslUntrustedServerResult
= synchResult
;
900 showDialog(DIALOG_SSL_VALIDATOR
);
907 private class UploadFinishReceiver
extends BroadcastReceiver
{
909 * Once the file upload has finished -> update view
910 * @author David A. Velasco
911 * {@link BroadcastReceiver} to enable upload feedback in UI
914 public void onReceive(Context context
, Intent intent
) {
915 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
916 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
917 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
918 OCFile currentDir
= getCurrentDir();
919 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
920 if (sameAccount
&& isDescendant
) {
921 refeshListOfFilesFragment();
929 * Class waiting for broadcast events from the {@link FielDownloader} service.
931 * Updates the UI when a download is started or finished, provided that it is relevant for the
934 private class DownloadFinishReceiver
extends BroadcastReceiver
{
936 public void onReceive(Context context
, Intent intent
) {
937 boolean sameAccount
= isSameAccount(context
, intent
);
938 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
939 boolean isDescendant
= isDescendant(downloadedRemotePath
);
941 if (sameAccount
&& isDescendant
) {
942 refeshListOfFilesFragment();
943 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
946 removeStickyBroadcast(intent
);
949 private boolean isDescendant(String downloadedRemotePath
) {
950 OCFile currentDir
= getCurrentDir();
951 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
954 private boolean isSameAccount(Context context
, Intent intent
) {
955 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
956 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
965 public DataStorageManager
getStorageManager() {
966 return mStorageManager
;
973 * Updates action bar and second fragment, if in dual pane mode.
976 public void onBrowsedDownTo(OCFile directory
) {
977 pushDirname(directory
);
978 cleanSecondFragment();
981 startSyncFolderOperation(directory
.getRemotePath(), directory
.getFileId());
982 // // Update folder size on DB
983 // getStorageManager().calculateFolderSize(directory.getParentId());
988 * Opens the image gallery showing the image {@link OCFile} received as parameter.
990 * @param file Image {@link OCFile} to show.
993 public void startImagePreview(OCFile file
) {
994 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
995 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
996 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
997 startActivity(showDetailsIntent
);
1001 * Stars the preview of an already down media {@link OCFile}.
1003 * @param file Media {@link OCFile} to preview.
1004 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
1005 * @param autoplay When 'true', the playback will start without user interactions.
1008 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1009 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1010 setSecondFragment(mediaFragment
);
1011 updateFragmentsVisibility(true
);
1012 updateNavigationElementsInActionBar(file
);
1017 * Requests the download of the received {@link OCFile} , updates the UI
1018 * to monitor the download progress and prepares the activity to preview
1019 * or open the file when the download finishes.
1021 * @param file {@link OCFile} to download and preview.
1024 public void startDownloadForPreview(OCFile file
) {
1025 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1026 setSecondFragment(detailFragment
);
1027 mWaitingToPreview
= file
;
1028 requestForDownload();
1029 updateFragmentsVisibility(true
);
1030 updateNavigationElementsInActionBar(file
);
1036 * Shows the information of the {@link OCFile} received as a
1037 * parameter in the second fragment.
1039 * @param file {@link OCFile} whose details will be shown
1042 public void showDetails(OCFile file
) {
1043 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1044 setSecondFragment(detailFragment
);
1045 updateFragmentsVisibility(true
);
1046 updateNavigationElementsInActionBar(file
);
1054 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1055 ActionBar actionBar
= getSupportActionBar();
1056 if (chosenFile
== null
|| mDualPane
) {
1057 // only list of files - set for browsing through folders
1058 OCFile currentDir
= getCurrentDir();
1059 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1060 actionBar
.setDisplayShowTitleEnabled(false
);
1061 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1062 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1065 actionBar
.setDisplayHomeAsUpEnabled(true
);
1066 actionBar
.setDisplayShowTitleEnabled(true
);
1067 actionBar
.setTitle(chosenFile
.getFileName());
1068 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1077 public void onFileStateChanged() {
1078 refeshListOfFilesFragment();
1079 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1087 public FileDownloaderBinder
getFileDownloaderBinder() {
1088 return mDownloaderBinder
;
1096 public FileUploaderBinder
getFileUploaderBinder() {
1097 return mUploaderBinder
;
1101 /** Defines callbacks for service binding, passed to bindService() */
1102 private class ListServiceConnection
implements ServiceConnection
{
1105 public void onServiceConnected(ComponentName component
, IBinder service
) {
1106 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1107 Log_OC
.d(TAG
, "Download service connected");
1108 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1109 if (mWaitingToPreview
!= null
) {
1110 requestForDownload();
1113 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1114 Log_OC
.d(TAG
, "Upload service connected");
1115 mUploaderBinder
= (FileUploaderBinder
) service
;
1119 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1120 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1121 if (listOfFiles
!= null
) {
1122 listOfFiles
.listDirectory();
1124 FileFragment secondFragment
= getSecondFragment();
1125 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1126 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1127 detailFragment
.listenForTransferProgress();
1128 detailFragment
.updateFileDetails(false
, false
);
1133 public void onServiceDisconnected(ComponentName component
) {
1134 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1135 Log_OC
.d(TAG
, "Download service disconnected");
1136 mDownloaderBinder
= null
;
1137 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1138 Log_OC
.d(TAG
, "Upload service disconnected");
1139 mUploaderBinder
= null
;
1147 * Launch an intent to request the PIN code to the user before letting him use the app
1149 private void requestPinCode() {
1150 boolean pinStart
= false
;
1151 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1152 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1154 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1155 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1162 public void onSavedCertificate() {
1163 startSynchronization();
1168 public void onFailedSavingCertificate() {
1169 showDialog(DIALOG_CERT_NOT_SAVED
);
1174 * Updates the view associated to the activity after the finish of some operation over files
1175 * in the current account.
1177 * @param operation Removal operation performed.
1178 * @param result Result of the removal.
1181 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1182 if (operation
instanceof RemoveFileOperation
) {
1183 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1185 } else if (operation
instanceof RenameFileOperation
) {
1186 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1188 } else if (operation
instanceof SynchronizeFileOperation
) {
1189 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1191 } else if (operation
instanceof CreateFolderOperation
) {
1192 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1194 } else if (operation
instanceof SynchronizeFolderOperation
) {
1195 onSynchronizeFolderOperationFinish((SynchronizeFolderOperation
)operation
, result
);
1201 * Updates the view associated to the activity after the finish of an operation trying to synchronize a folder.
1203 * @param operation Synchronize operation performed.
1204 * @param result Result of the synchronization.
1206 private void onSynchronizeFolderOperationFinish(SynchronizeFolderOperation operation
, RemoteOperationResult result
) {
1208 OCFileListFragment list
= getListOfFilesFragment();
1209 enableDisableViewGroup(list
.getListView(), true
);
1211 setSupportProgressBarIndeterminateVisibility(false
);
1212 if (result
.isSuccess()) {
1213 if (result
.getCode() != ResultCode
.OK_NO_CHANGES_ON_DIR
) {
1214 DataStorageManager storageManager
= getStorageManager();
1215 OCFile parentDir
= storageManager
.getFileByPath(operation
.getRemotePath());
1217 // Update folder size on DB
1218 getStorageManager().calculateFolderSize(parentDir
.getFileId());
1221 refreshListOfFilesFragment(parentDir
);
1225 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1228 } catch (NotFoundException e
) {
1229 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1235 private void refreshListOfFilesFragment(OCFile parentDir
) {
1236 OCFileListFragment fileListFragment
= getListOfFilesFragment();
1237 if (fileListFragment
!= null
) {
1238 fileListFragment
.listDirectory(parentDir
);
1244 * Updates the view associated to the activity after the finish of an operation trying to remove a
1247 * @param operation Removal operation performed.
1248 * @param result Result of the removal.
1250 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1251 dismissLoadingDialog();
1252 if (result
.isSuccess()) {
1253 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1255 OCFile removedFile
= operation
.getFile();
1256 getSecondFragment();
1257 FileFragment second
= getSecondFragment();
1258 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1259 cleanSecondFragment();
1261 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1262 refeshListOfFilesFragment();
1266 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1268 if (result
.isSslRecoverableException()) {
1269 mLastSslUntrustedServerResult
= result
;
1270 showDialog(DIALOG_SSL_VALIDATOR
);
1276 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1278 * @param operation Creation operation performed.
1279 * @param result Result of the creation.
1281 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1282 if (result
.isSuccess()) {
1283 dismissLoadingDialog();
1284 refeshListOfFilesFragment();
1287 //dismissDialog(DIALOG_SHORT_WAIT);
1288 dismissLoadingDialog();
1290 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1293 } catch (NotFoundException e
) {
1294 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1301 * Updates the view associated to the activity after the finish of an operation trying to rename a
1304 * @param operation Renaming operation performed.
1305 * @param result Result of the renaming.
1307 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1308 dismissLoadingDialog();
1309 OCFile renamedFile
= operation
.getFile();
1310 if (result
.isSuccess()) {
1312 FileFragment details
= getSecondFragment();
1313 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1314 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1317 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1318 refeshListOfFilesFragment();
1322 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1323 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1325 // TODO throw again the new rename dialog
1327 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1329 if (result
.isSslRecoverableException()) {
1330 mLastSslUntrustedServerResult
= result
;
1331 showDialog(DIALOG_SSL_VALIDATOR
);
1338 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1339 dismissLoadingDialog();
1340 OCFile syncedFile
= operation
.getLocalFile();
1341 if (!result
.isSuccess()) {
1342 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1343 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1344 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1345 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1349 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1354 if (operation
.transferWasRequested()) {
1355 refeshListOfFilesFragment();
1356 onTransferStateChanged(syncedFile
, true
, true
);
1359 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1370 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1372 FileFragment details
= getSecondFragment();
1373 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1374 if (downloading
|| uploading
) {
1375 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1377 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1384 public void onDismiss(EditNameDialog dialog
) {
1385 if (dialog
.getResult()) {
1386 String newDirectoryName
= dialog
.getNewFilename().trim();
1387 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1388 if (newDirectoryName
.length() > 0) {
1389 String path
= getCurrentDir().getRemotePath();
1392 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1393 RemoteOperation operation
= new CreateFolderOperation(path
, getCurrentDir().getFileId(), mStorageManager
);
1394 operation
.execute( getAccount(),
1395 FileDisplayActivity
.this,
1396 FileDisplayActivity
.this,
1398 FileDisplayActivity
.this);
1400 showLoadingDialog();
1406 private void requestForDownload() {
1407 Account account
= getAccount();
1408 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1409 Intent i
= new Intent(this, FileDownloader
.class);
1410 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1411 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1417 private OCFile
getCurrentDir() {
1418 OCFile file
= getFile();
1420 if (file
.isDirectory()) {
1422 } else if (mStorageManager
!= null
) {
1423 return mStorageManager
.getFileById(file
.getParentId());
1429 public void startSyncFolderOperation(String remotePath
, long parentId
) {
1430 long currentSyncTime
= System
.currentTimeMillis();
1432 OCFileListFragment list
= getListOfFilesFragment();
1433 enableDisableViewGroup(list
.getListView(), false
);
1435 // perform folder synchronization
1436 RemoteOperation synchFolderOp
= new SynchronizeFolderOperation( remotePath
,
1439 getStorageManager(),
1441 getApplicationContext()
1443 synchFolderOp
.execute(getAccount(), this, this, mHandler
, this);
1445 setSupportProgressBarIndeterminateVisibility(true
);
1449 public void enableDisableViewGroup(ViewGroup viewGroup
, boolean enabled
) {
1450 int childCount
= viewGroup
.getChildCount();
1451 for (int i
= 0; i
< childCount
; i
++) {
1452 View view
= viewGroup
.getChildAt(i
);
1453 view
.setEnabled(enabled
);
1454 view
.setClickable(!enabled
);
1455 if (view
instanceof ViewGroup
) {
1456 enableDisableViewGroup((ViewGroup
) view
, enabled
);