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
.IntentFilter
.AuthorityEntry
;
35 import android
.content
.ServiceConnection
;
36 import android
.content
.SharedPreferences
;
37 import android
.content
.SyncRequest
;
38 import android
.content
.res
.Resources
.NotFoundException
;
39 import android
.database
.Cursor
;
40 import android
.net
.Uri
;
41 import android
.os
.Bundle
;
42 import android
.os
.Handler
;
43 import android
.os
.IBinder
;
44 import android
.preference
.PreferenceManager
;
45 import android
.provider
.MediaStore
;
46 import android
.support
.v4
.app
.Fragment
;
47 import android
.support
.v4
.app
.FragmentManager
;
48 import android
.support
.v4
.app
.FragmentTransaction
;
49 import android
.util
.Log
;
50 import android
.view
.View
;
51 import android
.view
.ViewGroup
;
52 import android
.widget
.ArrayAdapter
;
53 import android
.widget
.TextView
;
54 import android
.widget
.Toast
;
56 import com
.actionbarsherlock
.app
.ActionBar
;
57 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
58 import com
.actionbarsherlock
.view
.Menu
;
59 import com
.actionbarsherlock
.view
.MenuInflater
;
60 import com
.actionbarsherlock
.view
.MenuItem
;
61 import com
.actionbarsherlock
.view
.Window
;
62 import com
.owncloud
.android
.Log_OC
;
63 import com
.owncloud
.android
.MainApp
;
64 import com
.owncloud
.android
.R
;
65 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
66 import com
.owncloud
.android
.datamodel
.OCFile
;
67 import com
.owncloud
.android
.files
.services
.FileDownloader
;
68 import com
.owncloud
.android
.files
.services
.FileObserverService
;
69 import com
.owncloud
.android
.files
.services
.FileUploader
;
70 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
71 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
72 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
73 import com
.owncloud
.android
.oc_framework
.operations
.OnRemoteOperationListener
;
74 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
75 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
76 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
.ResultCode
;
77 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
78 import com
.owncloud
.android
.operations
.RenameFileOperation
;
79 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
80 import com
.owncloud
.android
.operations
.SynchronizeFolderOperation
;
81 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
82 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
83 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
84 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
85 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
86 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
87 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
88 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
89 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
90 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
91 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
92 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
96 * Displays, what files the user has available in his ownCloud.
98 * @author Bartek Przybylski
99 * @author David A. Velasco
102 public class FileDisplayActivity
extends FileActivity
implements
103 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
105 private ArrayAdapter
<String
> mDirectories
;
107 /** Access point to the cached database for the current ownCloud {@link Account} */
108 private FileDataStorageManager mStorageManager
= null
;
110 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
111 private UploadFinishReceiver mUploadFinishReceiver
;
112 private DownloadFinishReceiver mDownloadFinishReceiver
;
113 private FileDownloaderBinder mDownloaderBinder
= null
;
114 private FileUploaderBinder mUploaderBinder
= null
;
115 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
116 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
118 private boolean mDualPane
;
119 private View mLeftFragmentContainer
;
120 private View mRightFragmentContainer
;
122 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
123 private static final String KEY_SYNC_IN_PROGRESS
= "SYNC_IN_PROGRESS";
125 public static final int DIALOG_SHORT_WAIT
= 0;
126 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
127 private static final int DIALOG_SSL_VALIDATOR
= 2;
128 private static final int DIALOG_CERT_NOT_SAVED
= 3;
130 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
132 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
134 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
135 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
137 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
139 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
140 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
142 private OCFile mWaitingToPreview
;
143 private Handler mHandler
;
145 private boolean mSyncInProgress
= false
;
148 protected void onCreate(Bundle savedInstanceState
) {
149 Log_OC
.d(TAG
, "onCreate() start");
150 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
152 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
154 mHandler
= new Handler();
156 /// bindings to transference services
157 mUploadConnection
= new ListServiceConnection();
158 mDownloadConnection
= new ListServiceConnection();
159 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
160 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
162 // PIN CODE request ; best location is to decide, let's try this first
163 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
168 Intent observer_intent
= new Intent(this, FileObserverService
.class);
169 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
170 startService(observer_intent
);
172 /// Load of saved instance state
173 if(savedInstanceState
!= null
) {
174 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
175 mSyncInProgress
= savedInstanceState
.getBoolean(KEY_SYNC_IN_PROGRESS
);
178 mWaitingToPreview
= null
;
179 mSyncInProgress
= false
;
184 // Inflate and set the layout view
185 setContentView(R
.layout
.files
);
186 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
187 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
188 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
189 if (savedInstanceState
== null
) {
190 createMinFragments();
194 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
195 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
196 setSupportProgressBarIndeterminateVisibility(mSyncInProgress
); // always AFTER setContentView(...) ; to work around bug in its implementation
200 Log_OC
.d(TAG
, "onCreate() end");
205 protected void onDestroy() {
207 if (mDownloadConnection
!= null
)
208 unbindService(mDownloadConnection
);
209 if (mUploadConnection
!= null
)
210 unbindService(mUploadConnection
);
215 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
218 protected void onAccountSet(boolean stateWasRecovered
) {
219 if (getAccount() != null
) {
220 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
222 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
223 OCFile file
= getFile();
224 // get parent from path
225 String parentPath
= "";
227 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
228 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
229 // get parent from path
230 parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
231 if (mStorageManager
.getFileByPath(parentPath
) == null
)
232 file
= null
; // not able to know the directory where the file is uploading
234 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
238 // fall back to root folder
239 file
= mStorageManager
.getFileByPath(OCFile
.ROOT_PATH
); // never returns null
242 setNavigationListWithFolder(file
);
243 if (!stateWasRecovered
) {
244 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
245 initFragmentsWithFile();
246 if (file
.isFolder()) {
247 startSyncFolderOperation(file
);
251 updateFragmentsVisibility(!file
.isFolder());
252 updateNavigationElementsInActionBar(file
.isFolder() ? null
: file
);
257 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
262 private void setNavigationListWithFolder(OCFile file
) {
263 mDirectories
.clear();
264 OCFile fileIt
= file
;
266 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.ROOT_PATH
) {
267 if (fileIt
.isFolder()) {
268 mDirectories
.add(fileIt
.getFileName());
270 //fileIt = mStorageManager.getFileById(fileIt.getParentId());
271 // get parent from path
272 parentPath
= fileIt
.getRemotePath().substring(0, fileIt
.getRemotePath().lastIndexOf(fileIt
.getFileName()));
273 fileIt
= mStorageManager
.getFileByPath(parentPath
);
275 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
279 private void createMinFragments() {
280 OCFileListFragment listOfFiles
= new OCFileListFragment();
281 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
282 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
283 transaction
.commit();
286 private void initFragmentsWithFile() {
287 if (getAccount() != null
&& getFile() != null
) {
289 OCFileListFragment listOfFiles
= getListOfFilesFragment();
290 if (listOfFiles
!= null
) {
291 listOfFiles
.listDirectory(getCurrentDir());
293 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
297 OCFile file
= getFile();
298 Fragment secondFragment
= chooseInitialSecondFragment(file
);
299 if (secondFragment
!= null
) {
300 setSecondFragment(secondFragment
);
301 updateFragmentsVisibility(true
);
302 updateNavigationElementsInActionBar(file
);
305 cleanSecondFragment();
309 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
310 if (getAccount() == null
) {
311 Log
.wtf(TAG
, "\t account is NULL");
313 if (getFile() == null
) {
314 Log
.wtf(TAG
, "\t file is NULL");
319 private Fragment
chooseInitialSecondFragment(OCFile file
) {
320 Fragment secondFragment
= null
;
321 if (file
!= null
&& !file
.isFolder()) {
322 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
323 && file
.getLastSyncDateForProperties() > 0 // temporal fix
325 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
326 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
327 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
330 secondFragment
= new FileDetailFragment(file
, getAccount());
333 return secondFragment
;
338 * Replaces the second fragment managed by the activity with the received as
341 * Assumes never will be more than two fragments managed at the same time.
343 * @param fragment New second Fragment to set.
345 private void setSecondFragment(Fragment fragment
) {
346 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
347 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
348 transaction
.commit();
352 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
354 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
355 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
357 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
358 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
361 } else if (existsSecondFragment
) {
362 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
363 mLeftFragmentContainer
.setVisibility(View
.GONE
);
365 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
366 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
370 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
371 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
373 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
374 mRightFragmentContainer
.setVisibility(View
.GONE
);
380 private OCFileListFragment
getListOfFilesFragment() {
381 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
382 if (listOfFiles
!= null
) {
383 return (OCFileListFragment
)listOfFiles
;
385 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
389 protected FileFragment
getSecondFragment() {
390 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
391 if (second
!= null
) {
392 return (FileFragment
)second
;
397 public void cleanSecondFragment() {
398 Fragment second
= getSecondFragment();
399 if (second
!= null
) {
400 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
404 updateFragmentsVisibility(false
);
405 updateNavigationElementsInActionBar(null
);
408 protected void refeshListOfFilesFragment() {
409 OCFileListFragment fileListFragment
= getListOfFilesFragment();
410 if (fileListFragment
!= null
) {
411 fileListFragment
.listDirectory();
415 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
416 FileFragment secondFragment
= getSecondFragment();
417 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
418 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
419 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
420 OCFile fileInFragment
= detailsFragment
.getFile();
421 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
422 // the user browsed to other file ; forget the automatic preview
423 mWaitingToPreview
= null
;
425 } else if (downloadEvent
.equals(FileDownloader
.getDownloadAddedMessage())) {
426 // grant that the right panel updates the progress bar
427 detailsFragment
.listenForTransferProgress();
428 detailsFragment
.updateFileDetails(true
, false
);
430 } else if (downloadEvent
.equals(FileDownloader
.getDownloadFinishMessage())) {
431 // update the right panel
432 boolean detailsFragmentChanged
= false
;
435 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
436 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
437 startMediaPreview(mWaitingToPreview
, 0, true
);
438 detailsFragmentChanged
= true
;
440 openFile(mWaitingToPreview
);
443 mWaitingToPreview
= null
;
445 if (!detailsFragmentChanged
) {
446 detailsFragment
.updateFileDetails(false
, (success
));
454 public boolean onCreateOptionsMenu(Menu menu
) {
455 MenuInflater inflater
= getSherlock().getMenuInflater();
456 inflater
.inflate(R
.menu
.main_menu
, menu
);
461 public boolean onOptionsItemSelected(MenuItem item
) {
462 boolean retval
= true
;
463 switch (item
.getItemId()) {
464 case R
.id
.action_create_dir
: {
465 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
466 dialog
.show(getSupportFragmentManager(), "createdirdialog");
469 case R
.id
.action_sync_account
: {
470 startSynchronization();
473 case R
.id
.action_upload
: {
474 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
477 case R
.id
.action_settings
: {
478 Intent settingsIntent
= new Intent(this, Preferences
.class);
479 startActivity(settingsIntent
);
482 case android
.R
.id
.home
: {
483 FileFragment second
= getSecondFragment();
484 OCFile currentDir
= getCurrentDir();
485 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
486 (second
!= null
&& second
.getFile() != null
)) {
493 retval
= super.onOptionsItemSelected(item
);
498 private void startSynchronization() {
499 Log_OC
.e(TAG
, "Got to start sync");
500 if (android
.os
.Build
.VERSION
.SDK_INT
< android
.os
.Build
.VERSION_CODES
.KITKAT
) {
501 Log_OC
.e(TAG
, "Canceling all syncs for " + MainApp
.getAuthority());
502 ContentResolver
.cancelSync(null
, MainApp
.getAuthority()); // cancel the current synchronizations of any ownCloud account
503 Bundle bundle
= new Bundle();
504 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
505 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_EXPEDITED
, true
);
506 Log_OC
.e(TAG
, "Requesting sync for " + getAccount().name
+ " at " + MainApp
.getAuthority());
507 ContentResolver
.requestSync(
509 MainApp
.getAuthority(), bundle
);
511 Log_OC
.e(TAG
, "Requesting sync for " + getAccount().name
+ " at " + MainApp
.getAuthority() + " with new API");
512 SyncRequest
.Builder builder
= new SyncRequest
.Builder();
513 builder
.setSyncAdapter(getAccount(), MainApp
.getAuthority());
514 builder
.setExpedited(true
);
515 builder
.setManual(true
);
517 SyncRequest request
= builder
.build();
518 ContentResolver
.requestSync(request
);
524 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
525 if (itemPosition
!= 0) {
526 String targetPath
= "";
527 for (int i
=itemPosition
; i
< mDirectories
.getCount() - 1; i
++) {
528 targetPath
= mDirectories
.getItem(i
) + OCFile
.PATH_SEPARATOR
+ targetPath
;
530 targetPath
= OCFile
.PATH_SEPARATOR
+ targetPath
;
531 OCFile targetFolder
= mStorageManager
.getFileByPath(targetPath
);
532 if (targetFolder
!= null
) {
533 browseTo(targetFolder
);
536 // the next operation triggers a new call to this method, but it's necessary to
537 // ensure that the name exposed in the action bar is the current directory when the
538 // user selected it in the navigation list
539 getSupportActionBar().setSelectedNavigationItem(0);
545 * Called, when the user selected something for uploading
547 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
548 super.onActivityResult(requestCode
, resultCode
, data
);
550 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
551 requestSimpleUpload(data
, resultCode
);
553 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
554 requestMultipleUpload(data
, resultCode
);
559 private void requestMultipleUpload(Intent data
, int resultCode
) {
560 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
561 if (filePaths
!= null
) {
562 String
[] remotePaths
= new String
[filePaths
.length
];
563 String remotePathBase
= "";
564 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
565 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
567 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
568 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
569 for (int j
= 0; j
< remotePaths
.length
; j
++) {
570 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
573 Intent i
= new Intent(this, FileUploader
.class);
574 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
575 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
576 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
577 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
578 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
579 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
583 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
584 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
591 private void requestSimpleUpload(Intent data
, int resultCode
) {
592 String filepath
= null
;
594 Uri selectedImageUri
= data
.getData();
596 String filemanagerstring
= selectedImageUri
.getPath();
597 String selectedImagePath
= getPath(selectedImageUri
);
599 if (selectedImagePath
!= null
)
600 filepath
= selectedImagePath
;
602 filepath
= filemanagerstring
;
604 } catch (Exception e
) {
605 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
609 if (filepath
== null
) {
610 Log_OC
.e(TAG
, "Couldnt resolve path to file");
611 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
617 Intent i
= new Intent(this, FileUploader
.class);
618 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
620 String remotepath
= new String();
621 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
622 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
624 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
625 remotepath
+= OCFile
.PATH_SEPARATOR
;
626 remotepath
+= new File(filepath
).getName();
628 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
629 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
630 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
631 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
632 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
637 public void onBackPressed() {
638 OCFileListFragment listOfFiles
= getListOfFilesFragment();
639 if (mDualPane
|| getSecondFragment() == null
) {
640 if (listOfFiles
!= null
) { // should never be null, indeed
641 if (mDirectories
.getCount() <= 1) {
645 int levelsUp
= listOfFiles
.onBrowseUp();
646 for (int i
=0; i
< levelsUp
&& mDirectories
.getCount() > 1 ; i
++) {
651 if (listOfFiles
!= null
) { // should never be null, indeed
652 setFile(listOfFiles
.getCurrentFile());
654 cleanSecondFragment();
659 protected void onSaveInstanceState(Bundle outState
) {
660 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
661 Log_OC
.e(TAG
, "onSaveInstanceState() start");
662 super.onSaveInstanceState(outState
);
663 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
664 outState
.putBoolean(FileDisplayActivity
.KEY_SYNC_IN_PROGRESS
, mSyncInProgress
);
666 Log_OC
.d(TAG
, "onSaveInstanceState() end");
672 protected void onResume() {
674 Log_OC
.e(TAG
, "onResume() start");
676 // Listen for sync messages
677 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.getSyncMessage());
678 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
679 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
681 // Listen for upload messages
682 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.getUploadFinishMessage());
683 mUploadFinishReceiver
= new UploadFinishReceiver();
684 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
686 // Listen for download messages
687 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.getDownloadAddedMessage());
688 downloadIntentFilter
.addAction(FileDownloader
.getDownloadFinishMessage());
689 mDownloadFinishReceiver
= new DownloadFinishReceiver();
690 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
692 Log_OC
.d(TAG
, "onResume() end");
697 protected void onPause() {
699 Log_OC
.e(TAG
, "onPause() start");
700 if (mSyncBroadcastReceiver
!= null
) {
701 unregisterReceiver(mSyncBroadcastReceiver
);
702 mSyncBroadcastReceiver
= null
;
704 if (mUploadFinishReceiver
!= null
) {
705 unregisterReceiver(mUploadFinishReceiver
);
706 mUploadFinishReceiver
= null
;
708 if (mDownloadFinishReceiver
!= null
) {
709 unregisterReceiver(mDownloadFinishReceiver
);
710 mDownloadFinishReceiver
= null
;
713 Log_OC
.d(TAG
, "onPause() end");
718 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
719 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
720 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
726 protected Dialog
onCreateDialog(int id
) {
727 Dialog dialog
= null
;
728 AlertDialog
.Builder builder
;
730 case DIALOG_SHORT_WAIT
: {
731 ProgressDialog working_dialog
= new ProgressDialog(this);
732 working_dialog
.setMessage(getResources().getString(
733 R
.string
.wait_a_moment
));
734 working_dialog
.setIndeterminate(true
);
735 working_dialog
.setCancelable(false
);
736 dialog
= working_dialog
;
739 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
741 String
[] items
= null
;
743 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
744 getString(R
.string
.actionbar_upload_from_apps
),
745 getString(R
.string
.actionbar_failed_instant_upload
) };
747 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
748 getString(R
.string
.actionbar_upload_from_apps
) };
750 if (InstantUploadActivity
.IS_ENABLED
)
755 builder
= new AlertDialog
.Builder(this);
756 builder
.setTitle(R
.string
.actionbar_upload
);
757 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
758 public void onClick(DialogInterface dialog
, int item
) {
761 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
762 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
763 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
765 // TODO create and handle new fragment
766 // LocalFileListFragment
768 } else if (item
== 1) {
769 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
770 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
771 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
772 ACTION_SELECT_CONTENT_FROM_APPS
);
773 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
774 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
775 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
776 startActivity(action
);
780 dialog
= builder
.create();
783 case DIALOG_SSL_VALIDATOR
: {
784 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
787 case DIALOG_CERT_NOT_SAVED
: {
788 builder
= new AlertDialog
.Builder(this);
789 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
790 builder
.setCancelable(false
);
791 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
793 public void onClick(DialogInterface dialog
, int which
) {
797 dialog
= builder
.create();
809 * Show loading dialog
811 public void showLoadingDialog() {
813 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
814 FragmentManager fm
= getSupportFragmentManager();
815 FragmentTransaction ft
= fm
.beginTransaction();
816 loading
.show(ft
, DIALOG_WAIT_TAG
);
821 * Dismiss loading dialog
823 public void dismissLoadingDialog(){
824 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
826 LoadingDialog loading
= (LoadingDialog
) frag
;
833 * Translates a content URI of an image to a physical path
835 * @param uri The URI to resolve
836 * @return The path to the image or null if it could not be found
838 public String
getPath(Uri uri
) {
839 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
840 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
841 if (cursor
!= null
) {
842 int column_index
= cursor
843 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
844 cursor
.moveToFirst();
845 return cursor
.getString(column_index
);
851 * Pushes a directory to the drop down list
852 * @param directory to push
853 * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false.
855 public void pushDirname(OCFile directory
) {
856 if(!directory
.isFolder()){
857 throw new IllegalArgumentException("Only directories may be pushed!");
859 mDirectories
.insert(directory
.getFileName(), 0);
864 * Pops a directory name from the drop down list
865 * @return True, unless the stack is empty
867 public boolean popDirname() {
868 mDirectories
.remove(mDirectories
.getItem(0));
869 return !mDirectories
.isEmpty();
872 // Custom array adapter to override text colors
873 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
875 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
879 public View
getView(int position
, View convertView
, ViewGroup parent
) {
880 View v
= super.getView(position
, convertView
, parent
);
882 ((TextView
) v
).setTextColor(getResources().getColorStateList(
883 android
.R
.color
.white
));
887 public View
getDropDownView(int position
, View convertView
,
889 View v
= super.getDropDownView(position
, convertView
, parent
);
891 ((TextView
) v
).setTextColor(getResources().getColorStateList(
892 android
.R
.color
.white
));
899 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
902 * {@link BroadcastReceiver} to enable syncing feedback in UI
905 public void onReceive(Context context
, Intent intent
) {
906 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
907 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
908 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
910 if (getAccount() != null
&& accountName
.equals(getAccount().name
)
911 && mStorageManager
!= null
914 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
916 OCFile currentFile
= (getFile() == null
) ? null
: mStorageManager
.getFileByPath(getFile().getRemotePath());
917 OCFile currentDir
= (getCurrentDir() == null
) ? null
: mStorageManager
.getFileByPath(getCurrentDir().getRemotePath());
919 if (currentDir
== null
) {
920 // current folder was removed from the server
921 Toast
.makeText( FileDisplayActivity
.this,
922 String
.format(getString(R
.string
.sync_current_folder_was_removed
), mDirectories
.getItem(0)),
928 if (currentFile
== null
&& !getFile().isFolder()) {
929 // currently selected file was removed in the server, and now we know it
930 cleanSecondFragment();
931 currentFile
= currentDir
;
934 if (synchFolderRemotePath
!= null
&& currentDir
.getRemotePath().equals(synchFolderRemotePath
)) {
935 OCFileListFragment fileListFragment
= getListOfFilesFragment();
936 if (fileListFragment
!= null
) {
937 fileListFragment
.listDirectory(currentDir
);
940 setFile(currentFile
);
943 setSupportProgressBarIndeterminateVisibility(inProgress
);
944 removeStickyBroadcast(intent
);
945 mSyncInProgress
= inProgress
;
949 if (synchResult
!= null
) {
950 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
951 mLastSslUntrustedServerResult
= synchResult
;
952 showDialog(DIALOG_SSL_VALIDATOR
);
959 private class UploadFinishReceiver
extends BroadcastReceiver
{
961 * Once the file upload has finished -> update view
962 * @author David A. Velasco
963 * {@link BroadcastReceiver} to enable upload feedback in UI
966 public void onReceive(Context context
, Intent intent
) {
967 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
968 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
969 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
970 OCFile currentDir
= getCurrentDir();
971 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
972 if (sameAccount
&& isDescendant
) {
973 refeshListOfFilesFragment();
981 * Class waiting for broadcast events from the {@link FielDownloader} service.
983 * Updates the UI when a download is started or finished, provided that it is relevant for the
986 private class DownloadFinishReceiver
extends BroadcastReceiver
{
988 public void onReceive(Context context
, Intent intent
) {
989 boolean sameAccount
= isSameAccount(context
, intent
);
990 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
991 boolean isDescendant
= isDescendant(downloadedRemotePath
);
993 if (sameAccount
&& isDescendant
) {
994 refeshListOfFilesFragment();
995 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
998 removeStickyBroadcast(intent
);
1001 private boolean isDescendant(String downloadedRemotePath
) {
1002 OCFile currentDir
= getCurrentDir();
1003 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
1006 private boolean isSameAccount(Context context
, Intent intent
) {
1007 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
1008 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
1017 public FileDataStorageManager
getStorageManager() {
1018 return mStorageManager
;
1022 public void browseToRoot() {
1023 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1024 if (listOfFiles
!= null
) { // should never be null, indeed
1025 while (mDirectories
.getCount() > 1) {
1028 OCFile root
= mStorageManager
.getFileByPath(OCFile
.ROOT_PATH
);
1029 listOfFiles
.listDirectory(root
);
1030 setFile(listOfFiles
.getCurrentFile());
1031 startSyncFolderOperation(root
);
1033 cleanSecondFragment();
1037 public void browseTo(OCFile folder
) {
1038 if (folder
== null
|| !folder
.isFolder()) {
1039 throw new IllegalArgumentException("Trying to browse to invalid folder " + folder
);
1041 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1042 if (listOfFiles
!= null
) {
1043 setNavigationListWithFolder(folder
);
1044 listOfFiles
.listDirectory(folder
);
1045 setFile(listOfFiles
.getCurrentFile());
1046 startSyncFolderOperation(folder
);
1048 Log_OC
.e(TAG
, "Unexpected null when accessing list fragment");
1050 cleanSecondFragment();
1057 * Updates action bar and second fragment, if in dual pane mode.
1060 public void onBrowsedDownTo(OCFile directory
) {
1061 pushDirname(directory
);
1062 cleanSecondFragment();
1065 startSyncFolderOperation(directory
);
1070 * Opens the image gallery showing the image {@link OCFile} received as parameter.
1072 * @param file Image {@link OCFile} to show.
1075 public void startImagePreview(OCFile file
) {
1076 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
1077 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
1078 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
1079 startActivity(showDetailsIntent
);
1083 * Stars the preview of an already down media {@link OCFile}.
1085 * @param file Media {@link OCFile} to preview.
1086 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
1087 * @param autoplay When 'true', the playback will start without user interactions.
1090 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1091 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1092 setSecondFragment(mediaFragment
);
1093 updateFragmentsVisibility(true
);
1094 updateNavigationElementsInActionBar(file
);
1099 * Requests the download of the received {@link OCFile} , updates the UI
1100 * to monitor the download progress and prepares the activity to preview
1101 * or open the file when the download finishes.
1103 * @param file {@link OCFile} to download and preview.
1106 public void startDownloadForPreview(OCFile file
) {
1107 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1108 setSecondFragment(detailFragment
);
1109 mWaitingToPreview
= file
;
1110 requestForDownload();
1111 updateFragmentsVisibility(true
);
1112 updateNavigationElementsInActionBar(file
);
1118 * Shows the information of the {@link OCFile} received as a
1119 * parameter in the second fragment.
1121 * @param file {@link OCFile} whose details will be shown
1124 public void showDetails(OCFile file
) {
1125 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1126 setSecondFragment(detailFragment
);
1127 updateFragmentsVisibility(true
);
1128 updateNavigationElementsInActionBar(file
);
1136 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1137 ActionBar actionBar
= getSupportActionBar();
1138 if (chosenFile
== null
|| mDualPane
) {
1139 // only list of files - set for browsing through folders
1140 OCFile currentDir
= getCurrentDir();
1141 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1142 actionBar
.setDisplayShowTitleEnabled(false
);
1143 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1144 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1147 actionBar
.setDisplayHomeAsUpEnabled(true
);
1148 actionBar
.setDisplayShowTitleEnabled(true
);
1149 actionBar
.setTitle(chosenFile
.getFileName());
1150 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1155 // private void updateDisplayHomeAtSync(){
1156 // ActionBar actionBar = getSupportActionBar();
1157 // OCFile currentDir = getCurrentDir();
1158 // if (currentDir.getParentId() != DataStorageManager.ROOT_PARENT_ID) {
1159 // actionBar.setHomeButtonEnabled(!mSyncInProgress);
1160 // actionBar.setDisplayHomeAsUpEnabled(!mSyncInProgress);
1163 // actionBar.setHomeButtonEnabled(true);
1164 // actionBar.setDisplayHomeAsUpEnabled(false);
1172 public void onFileStateChanged() {
1173 refeshListOfFilesFragment();
1174 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1182 public FileDownloaderBinder
getFileDownloaderBinder() {
1183 return mDownloaderBinder
;
1191 public FileUploaderBinder
getFileUploaderBinder() {
1192 return mUploaderBinder
;
1196 /** Defines callbacks for service binding, passed to bindService() */
1197 private class ListServiceConnection
implements ServiceConnection
{
1200 public void onServiceConnected(ComponentName component
, IBinder service
) {
1201 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1202 Log_OC
.d(TAG
, "Download service connected");
1203 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1204 if (mWaitingToPreview
!= null
) {
1205 requestForDownload();
1208 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1209 Log_OC
.d(TAG
, "Upload service connected");
1210 mUploaderBinder
= (FileUploaderBinder
) service
;
1214 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1215 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1216 if (listOfFiles
!= null
) {
1217 listOfFiles
.listDirectory();
1219 FileFragment secondFragment
= getSecondFragment();
1220 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1221 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1222 detailFragment
.listenForTransferProgress();
1223 detailFragment
.updateFileDetails(false
, false
);
1228 public void onServiceDisconnected(ComponentName component
) {
1229 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1230 Log_OC
.d(TAG
, "Download service disconnected");
1231 mDownloaderBinder
= null
;
1232 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1233 Log_OC
.d(TAG
, "Upload service disconnected");
1234 mUploaderBinder
= null
;
1242 * Launch an intent to request the PIN code to the user before letting him use the app
1244 private void requestPinCode() {
1245 boolean pinStart
= false
;
1246 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1247 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1249 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1250 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1257 public void onSavedCertificate() {
1258 startSyncFolderOperation(getCurrentDir());
1263 public void onFailedSavingCertificate() {
1264 showDialog(DIALOG_CERT_NOT_SAVED
);
1269 * Updates the view associated to the activity after the finish of some operation over files
1270 * in the current account.
1272 * @param operation Removal operation performed.
1273 * @param result Result of the removal.
1276 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1277 if (operation
instanceof RemoveFileOperation
) {
1278 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1280 } else if (operation
instanceof RenameFileOperation
) {
1281 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1283 } else if (operation
instanceof SynchronizeFileOperation
) {
1284 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1286 } else if (operation
instanceof CreateFolderOperation
) {
1287 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1294 * Updates the view associated to the activity after the finish of an operation trying to remove a
1297 * @param operation Removal operation performed.
1298 * @param result Result of the removal.
1300 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1301 dismissLoadingDialog();
1302 if (result
.isSuccess()) {
1303 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1305 OCFile removedFile
= operation
.getFile();
1306 getSecondFragment();
1307 FileFragment second
= getSecondFragment();
1308 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1309 cleanSecondFragment();
1311 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1312 refeshListOfFilesFragment();
1316 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1318 if (result
.isSslRecoverableException()) {
1319 mLastSslUntrustedServerResult
= result
;
1320 showDialog(DIALOG_SSL_VALIDATOR
);
1326 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1328 * @param operation Creation operation performed.
1329 * @param result Result of the creation.
1331 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1332 if (result
.isSuccess()) {
1333 dismissLoadingDialog();
1334 refeshListOfFilesFragment();
1337 dismissLoadingDialog();
1339 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1342 } catch (NotFoundException e
) {
1343 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1350 * Updates the view associated to the activity after the finish of an operation trying to rename a
1353 * @param operation Renaming operation performed.
1354 * @param result Result of the renaming.
1356 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1357 dismissLoadingDialog();
1358 OCFile renamedFile
= operation
.getFile();
1359 if (result
.isSuccess()) {
1361 FileFragment details
= getSecondFragment();
1362 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1363 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1366 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1367 refeshListOfFilesFragment();
1371 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1372 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1374 // TODO throw again the new rename dialog
1376 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1378 if (result
.isSslRecoverableException()) {
1379 mLastSslUntrustedServerResult
= result
;
1380 showDialog(DIALOG_SSL_VALIDATOR
);
1387 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1388 dismissLoadingDialog();
1389 OCFile syncedFile
= operation
.getLocalFile();
1390 if (!result
.isSuccess()) {
1391 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1392 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1393 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1394 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1400 if (operation
.transferWasRequested()) {
1401 refeshListOfFilesFragment();
1402 onTransferStateChanged(syncedFile
, true
, true
);
1405 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1416 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1418 FileFragment details
= getSecondFragment();
1419 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1420 if (downloading
|| uploading
) {
1421 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1423 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1430 public void onDismiss(EditNameDialog dialog
) {
1431 if (dialog
.getResult()) {
1432 String newDirectoryName
= dialog
.getNewFilename().trim();
1433 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1434 if (newDirectoryName
.length() > 0) {
1435 String path
= getCurrentDir().getRemotePath();
1438 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1439 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1440 operation
.execute( getAccount(),
1441 FileDisplayActivity
.this,
1442 FileDisplayActivity
.this,
1444 FileDisplayActivity
.this);
1446 showLoadingDialog();
1452 private void requestForDownload() {
1453 Account account
= getAccount();
1454 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1455 Intent i
= new Intent(this, FileDownloader
.class);
1456 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1457 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1463 private OCFile
getCurrentDir() {
1464 OCFile file
= getFile();
1466 if (file
.isFolder()) {
1468 } else if (mStorageManager
!= null
) {
1469 String parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
1470 return mStorageManager
.getFileByPath(parentPath
);
1476 public void startSyncFolderOperation(OCFile folder
) {
1477 long currentSyncTime
= System
.currentTimeMillis();
1479 mSyncInProgress
= true
;
1481 // perform folder synchronization
1482 RemoteOperation synchFolderOp
= new SynchronizeFolderOperation( folder
,
1485 getStorageManager(),
1487 getApplicationContext()
1489 synchFolderOp
.execute(getAccount(), this, null
, null
, this);
1491 setSupportProgressBarIndeterminateVisibility(true
);
1495 // public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
1496 // int childCount = viewGroup.getChildCount();
1497 // for (int i = 0; i < childCount; i++) {
1498 // View view = viewGroup.getChildAt(i);
1499 // view.setEnabled(enabled);
1500 // view.setClickable(!enabled);
1501 // if (view instanceof ViewGroup) {
1502 // enableDisableViewGroup((ViewGroup) view, enabled);