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 de
.mobilcom
.debitel
.cloud
.android
.ui
.activity
;
23 import android
.accounts
.Account
;
24 import android
.app
.AlertDialog
;
25 import android
.app
.ProgressDialog
;
26 import android
.app
.Dialog
;
27 import android
.content
.BroadcastReceiver
;
28 import android
.content
.ComponentName
;
29 import android
.content
.ContentResolver
;
30 import android
.content
.Context
;
31 import android
.content
.DialogInterface
;
32 import android
.content
.Intent
;
33 import android
.content
.IntentFilter
;
34 import android
.content
.ServiceConnection
;
35 import android
.content
.SharedPreferences
;
36 import android
.content
.res
.Resources
.NotFoundException
;
37 import android
.database
.Cursor
;
38 import android
.net
.Uri
;
39 import android
.os
.Bundle
;
40 import android
.os
.Handler
;
41 import android
.os
.IBinder
;
42 import android
.preference
.PreferenceManager
;
43 import android
.provider
.MediaStore
;
44 import android
.support
.v4
.app
.Fragment
;
45 import android
.support
.v4
.app
.FragmentManager
;
46 import android
.support
.v4
.app
.FragmentTransaction
;
47 import android
.util
.Log
;
48 import android
.view
.View
;
49 import android
.view
.ViewGroup
;
50 import android
.widget
.ArrayAdapter
;
51 import android
.widget
.TextView
;
52 import android
.widget
.Toast
;
54 import com
.actionbarsherlock
.app
.ActionBar
;
55 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
56 import com
.actionbarsherlock
.view
.Menu
;
57 import com
.actionbarsherlock
.view
.MenuInflater
;
58 import com
.actionbarsherlock
.view
.MenuItem
;
59 import com
.actionbarsherlock
.view
.Window
;
61 import de
.mobilcom
.debitel
.cloud
.android
.Log_OC
;
62 import de
.mobilcom
.debitel
.cloud
.android
.MainApp
;
63 import de
.mobilcom
.debitel
.cloud
.android
.R
;
64 import de
.mobilcom
.debitel
.cloud
.android
.datamodel
.DataStorageManager
;
65 import de
.mobilcom
.debitel
.cloud
.android
.datamodel
.FileDataStorageManager
;
66 import de
.mobilcom
.debitel
.cloud
.android
.datamodel
.OCFile
;
67 import de
.mobilcom
.debitel
.cloud
.android
.files
.services
.FileDownloader
;
68 import de
.mobilcom
.debitel
.cloud
.android
.files
.services
.FileObserverService
;
69 import de
.mobilcom
.debitel
.cloud
.android
.files
.services
.FileUploader
;
70 import de
.mobilcom
.debitel
.cloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
71 import de
.mobilcom
.debitel
.cloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
72 import de
.mobilcom
.debitel
.cloud
.android
.operations
.CreateFolderOperation
;
73 import de
.mobilcom
.debitel
.cloud
.android
.operations
.OnRemoteOperationListener
;
74 import de
.mobilcom
.debitel
.cloud
.android
.operations
.RemoteOperation
;
75 import de
.mobilcom
.debitel
.cloud
.android
.operations
.RemoteOperationResult
;
76 import de
.mobilcom
.debitel
.cloud
.android
.operations
.RemoveFileOperation
;
77 import de
.mobilcom
.debitel
.cloud
.android
.operations
.RenameFileOperation
;
78 import de
.mobilcom
.debitel
.cloud
.android
.operations
.SynchronizeFileOperation
;
79 import de
.mobilcom
.debitel
.cloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
80 import de
.mobilcom
.debitel
.cloud
.android
.syncadapter
.FileSyncService
;
81 import de
.mobilcom
.debitel
.cloud
.android
.ui
.dialog
.EditNameDialog
;
82 import de
.mobilcom
.debitel
.cloud
.android
.ui
.dialog
.LoadingDialog
;
83 import de
.mobilcom
.debitel
.cloud
.android
.ui
.dialog
.SslValidatorDialog
;
84 import de
.mobilcom
.debitel
.cloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
85 import de
.mobilcom
.debitel
.cloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
86 import de
.mobilcom
.debitel
.cloud
.android
.ui
.fragment
.FileDetailFragment
;
87 import de
.mobilcom
.debitel
.cloud
.android
.ui
.fragment
.FileFragment
;
88 import de
.mobilcom
.debitel
.cloud
.android
.ui
.fragment
.OCFileListFragment
;
89 import de
.mobilcom
.debitel
.cloud
.android
.ui
.preview
.PreviewImageActivity
;
90 import de
.mobilcom
.debitel
.cloud
.android
.ui
.preview
.PreviewImageFragment
;
91 import de
.mobilcom
.debitel
.cloud
.android
.ui
.preview
.PreviewMediaFragment
;
92 import de
.mobilcom
.debitel
.cloud
.android
.ui
.preview
.PreviewVideoActivity
;
95 * Displays, what files the user has available in his ownCloud.
97 * @author Bartek Przybylski
98 * @author David A. Velasco
101 public class FileDisplayActivity
extends FileActivity
implements
102 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
104 private ArrayAdapter
<String
> mDirectories
;
106 /** Access point to the cached database for the current ownCloud {@link Account} */
107 private DataStorageManager mStorageManager
= null
;
109 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
110 private UploadFinishReceiver mUploadFinishReceiver
;
111 private DownloadFinishReceiver mDownloadFinishReceiver
;
112 private FileDownloaderBinder mDownloaderBinder
= null
;
113 private FileUploaderBinder mUploaderBinder
= null
;
114 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
115 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
117 private boolean mDualPane
;
118 private View mLeftFragmentContainer
;
119 private View mRightFragmentContainer
;
121 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
123 public static final int DIALOG_SHORT_WAIT
= 0;
124 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
125 private static final int DIALOG_SSL_VALIDATOR
= 2;
126 private static final int DIALOG_CERT_NOT_SAVED
= 3;
128 private static final String DIALOG_WAIT_TAG
= "DIALOG_WAIT";
130 public static final String ACTION_DETAILS
= "de.mobilcom.debitel.cloud.android.ui.activity.action.DETAILS";
132 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
133 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
135 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
137 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
138 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
140 private OCFile mWaitingToPreview
;
141 private Handler mHandler
;
143 private String mDownloadAddedMessage
;
144 private String mDownloadFinishMessage
;
147 protected void onCreate(Bundle savedInstanceState
) {
148 Log_OC
.d(TAG
, "onCreate() start");
149 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
151 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
153 mHandler
= new Handler();
155 FileDownloader downloader
= new FileDownloader();
156 mDownloadAddedMessage
= downloader
.getDownloadAddedMessage();
157 mDownloadFinishMessage
= downloader
.getDownloadFinishMessage();
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
201 Log_OC
.d(TAG
, "onCreate() end");
206 protected void onDestroy() {
208 if (mDownloadConnection
!= null
)
209 unbindService(mDownloadConnection
);
210 if (mUploadConnection
!= null
)
211 unbindService(mUploadConnection
);
216 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
219 protected void onAccountSet(boolean stateWasRecovered
) {
220 if (getAccount() != null
) {
221 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
223 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
224 OCFile file
= getFile();
225 // get parent from path
226 String parentPath
= "";
228 if (file
.isDown() && file
.getLastSyncDateForProperties() == 0) {
229 // upload in progress - right now, files are not inserted in the local cache until the upload is successful
230 // get parent from path
231 parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
232 if (mStorageManager
.getFileByPath(parentPath
) == null
)
233 file
= null
; // not able to know the directory where the file is uploading
235 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
239 // fall back to root folder
240 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
243 mDirectories
.clear();
244 OCFile fileIt
= file
;
245 while(fileIt
!= null
&& fileIt
.getFileName() != OCFile
.PATH_SEPARATOR
) {
246 if (fileIt
.isDirectory()) {
247 mDirectories
.add(fileIt
.getFileName());
249 // get parent from path
250 parentPath
= fileIt
.getRemotePath().substring(0, fileIt
.getRemotePath().lastIndexOf(fileIt
.getFileName()));
251 fileIt
= mStorageManager
.getFileByPath(parentPath
);
253 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
254 if (!stateWasRecovered
) {
255 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
256 initFragmentsWithFile();
259 updateFragmentsVisibility(!file
.isDirectory());
260 updateNavigationElementsInActionBar(file
.isDirectory() ? null
: file
);
265 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
270 private void createMinFragments() {
271 OCFileListFragment listOfFiles
= new OCFileListFragment();
272 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
273 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
274 transaction
.commit();
277 private void initFragmentsWithFile() {
278 if (getAccount() != null
&& getFile() != null
) {
280 OCFileListFragment listOfFiles
= getListOfFilesFragment();
281 if (listOfFiles
!= null
) {
282 listOfFiles
.listDirectory(getCurrentDir());
284 Log
.e(TAG
, "Still have a chance to lose the initializacion of list fragment >(");
288 OCFile file
= getFile();
289 Fragment secondFragment
= chooseInitialSecondFragment(file
);
290 if (secondFragment
!= null
) {
291 setSecondFragment(secondFragment
);
292 updateFragmentsVisibility(true
);
293 updateNavigationElementsInActionBar(file
);
296 cleanSecondFragment();
300 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
301 if (getAccount() == null
) {
302 Log
.wtf(TAG
, "\t account is NULL");
304 if (getFile() == null
) {
305 Log
.wtf(TAG
, "\t file is NULL");
310 private Fragment
chooseInitialSecondFragment(OCFile file
) {
311 Fragment secondFragment
= null
;
312 if (file
!= null
&& !file
.isDirectory()) {
313 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)
314 && file
.getLastSyncDateForProperties() > 0 // temporal fix
316 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
317 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
318 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
321 secondFragment
= new FileDetailFragment(file
, getAccount());
324 return secondFragment
;
329 * Replaces the second fragment managed by the activity with the received as
332 * Assumes never will be more than two fragments managed at the same time.
334 * @param fragment New second Fragment to set.
336 private void setSecondFragment(Fragment fragment
) {
337 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
338 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
339 transaction
.commit();
343 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
345 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
346 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
348 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
349 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
352 } else if (existsSecondFragment
) {
353 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
354 mLeftFragmentContainer
.setVisibility(View
.GONE
);
356 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
357 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
361 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
362 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
364 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
365 mRightFragmentContainer
.setVisibility(View
.GONE
);
371 private OCFileListFragment
getListOfFilesFragment() {
372 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
373 if (listOfFiles
!= null
) {
374 return (OCFileListFragment
)listOfFiles
;
376 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
380 protected FileFragment
getSecondFragment() {
381 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
382 if (second
!= null
) {
383 return (FileFragment
)second
;
388 public void cleanSecondFragment() {
389 Fragment second
= getSecondFragment();
390 if (second
!= null
) {
391 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
395 updateFragmentsVisibility(false
);
396 updateNavigationElementsInActionBar(null
);
399 protected void refeshListOfFilesFragment() {
400 OCFileListFragment fileListFragment
= getListOfFilesFragment();
401 if (fileListFragment
!= null
) {
402 fileListFragment
.listDirectory();
406 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
407 FileFragment secondFragment
= getSecondFragment();
408 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
409 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
410 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
411 OCFile fileInFragment
= detailsFragment
.getFile();
412 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
413 // the user browsed to other file ; forget the automatic preview
414 mWaitingToPreview
= null
;
416 } else if (downloadEvent
.equals(mDownloadAddedMessage
)) {
417 // grant that the right panel updates the progress bar
418 detailsFragment
.listenForTransferProgress();
419 detailsFragment
.updateFileDetails(true
, false
);
421 } else if (downloadEvent
.equals(mDownloadFinishMessage
)) {
422 // update the right panel
423 boolean detailsFragmentChanged
= false
;
426 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
427 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
428 startMediaPreview(mWaitingToPreview
, 0, true
);
429 detailsFragmentChanged
= true
;
431 openFile(mWaitingToPreview
);
434 mWaitingToPreview
= null
;
436 if (!detailsFragmentChanged
) {
437 detailsFragment
.updateFileDetails(false
, (success
));
445 public boolean onCreateOptionsMenu(Menu menu
) {
446 MenuInflater inflater
= getSherlock().getMenuInflater();
447 inflater
.inflate(R
.menu
.main_menu
, menu
);
452 public boolean onOptionsItemSelected(MenuItem item
) {
453 boolean retval
= true
;
454 switch (item
.getItemId()) {
455 case R
.id
.action_create_dir
: {
456 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
457 dialog
.show(getSupportFragmentManager(), "createdirdialog");
460 case R
.id
.action_sync_account
: {
461 startSynchronization();
464 case R
.id
.action_upload
: {
465 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
468 case R
.id
.action_settings
: {
469 Intent settingsIntent
= new Intent(this, Preferences
.class);
470 startActivity(settingsIntent
);
473 case android
.R
.id
.home
: {
474 FileFragment second
= getSecondFragment();
475 OCFile currentDir
= getCurrentDir();
476 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
477 (second
!= null
&& second
.getFile() != null
)) {
483 retval
= super.onOptionsItemSelected(item
);
488 private void startSynchronization() {
489 ContentResolver
.cancelSync(null
, MainApp
.getAuthTokenType()); // cancel the current synchronizations of any ownCloud account
490 Bundle bundle
= new Bundle();
491 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
492 ContentResolver
.requestSync(
494 MainApp
.getAuthTokenType(), bundle
);
499 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
500 int i
= itemPosition
;
504 // the next operation triggers a new call to this method, but it's necessary to
505 // ensure that the name exposed in the action bar is the current directory when the
506 // user selected it in the navigation list
507 if (itemPosition
!= 0)
508 getSupportActionBar().setSelectedNavigationItem(0);
513 * Called, when the user selected something for uploading
515 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
516 super.onActivityResult(requestCode
, resultCode
, data
);
518 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
519 requestSimpleUpload(data
, resultCode
);
521 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
522 requestMultipleUpload(data
, resultCode
);
527 private void requestMultipleUpload(Intent data
, int resultCode
) {
528 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
529 if (filePaths
!= null
) {
530 String
[] remotePaths
= new String
[filePaths
.length
];
531 String remotePathBase
= "";
532 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
533 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
535 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
536 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
537 for (int j
= 0; j
< remotePaths
.length
; j
++) {
538 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
541 Intent i
= new Intent(this, FileUploader
.class);
542 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
543 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
544 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
545 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
546 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
547 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
551 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
552 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
559 private void requestSimpleUpload(Intent data
, int resultCode
) {
560 String filepath
= null
;
562 Uri selectedImageUri
= data
.getData();
564 String filemanagerstring
= selectedImageUri
.getPath();
565 String selectedImagePath
= getPath(selectedImageUri
);
567 if (selectedImagePath
!= null
)
568 filepath
= selectedImagePath
;
570 filepath
= filemanagerstring
;
572 } catch (Exception e
) {
573 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
577 if (filepath
== null
) {
578 Log_OC
.e(TAG
, "Couldnt resolve path to file");
579 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
585 Intent i
= new Intent(this, FileUploader
.class);
586 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
588 String remotepath
= new String();
589 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
590 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
592 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
593 remotepath
+= OCFile
.PATH_SEPARATOR
;
594 remotepath
+= new File(filepath
).getName();
596 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
597 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
598 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
599 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
600 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
605 public void onBackPressed() {
606 OCFileListFragment listOfFiles
= getListOfFilesFragment();
607 if (mDualPane
|| getSecondFragment() == null
) {
608 if (listOfFiles
!= null
) { // should never be null, indeed
609 if (mDirectories
.getCount() <= 1) {
614 listOfFiles
.onBrowseUp();
617 if (listOfFiles
!= null
) { // should never be null, indeed
618 setFile(listOfFiles
.getCurrentFile());
620 cleanSecondFragment();
624 protected void onSaveInstanceState(Bundle outState
) {
625 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
626 Log_OC
.e(TAG
, "onSaveInstanceState() start");
627 super.onSaveInstanceState(outState
);
628 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
629 Log_OC
.d(TAG
, "onSaveInstanceState() end");
635 protected void onResume() {
637 Log_OC
.e(TAG
, "onResume() start");
639 FileUploader fileUploader
= new FileUploader();
640 FileSyncService fileSyncService
= new FileSyncService();
642 // Listen for sync messages
643 IntentFilter syncIntentFilter
= new IntentFilter(fileSyncService
.getSyncMessage());
644 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
645 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
647 // Listen for upload messages
648 IntentFilter uploadIntentFilter
= new IntentFilter(fileUploader
.getUploadFinishMessage());
649 mUploadFinishReceiver
= new UploadFinishReceiver();
650 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
652 // Listen for download messages
653 IntentFilter downloadIntentFilter
= new IntentFilter(mDownloadAddedMessage
);
654 downloadIntentFilter
.addAction(mDownloadFinishMessage
);
655 mDownloadFinishReceiver
= new DownloadFinishReceiver();
656 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
658 Log_OC
.d(TAG
, "onResume() end");
663 protected void onPause() {
665 Log_OC
.e(TAG
, "onPause() start");
666 if (mSyncBroadcastReceiver
!= null
) {
667 unregisterReceiver(mSyncBroadcastReceiver
);
668 mSyncBroadcastReceiver
= null
;
670 if (mUploadFinishReceiver
!= null
) {
671 unregisterReceiver(mUploadFinishReceiver
);
672 mUploadFinishReceiver
= null
;
674 if (mDownloadFinishReceiver
!= null
) {
675 unregisterReceiver(mDownloadFinishReceiver
);
676 mDownloadFinishReceiver
= null
;
679 Log_OC
.d(TAG
, "onPause() end");
684 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
685 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
686 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
692 protected Dialog
onCreateDialog(int id
) {
693 Dialog dialog
= null
;
694 AlertDialog
.Builder builder
;
696 case DIALOG_SHORT_WAIT
: {
697 ProgressDialog working_dialog
= new ProgressDialog(this);
698 working_dialog
.setMessage(getResources().getString(
699 R
.string
.wait_a_moment
));
700 working_dialog
.setIndeterminate(true
);
701 working_dialog
.setCancelable(false
);
702 dialog
= working_dialog
;
705 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
707 String
[] items
= null
;
709 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
710 getString(R
.string
.actionbar_upload_from_apps
),
711 getString(R
.string
.actionbar_failed_instant_upload
) };
713 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
714 getString(R
.string
.actionbar_upload_from_apps
) };
716 if (InstantUploadActivity
.IS_ENABLED
)
721 builder
= new AlertDialog
.Builder(this);
722 builder
.setTitle(R
.string
.actionbar_upload
);
723 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
724 public void onClick(DialogInterface dialog
, int item
) {
727 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
728 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
729 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
731 // TODO create and handle new fragment
732 // LocalFileListFragment
734 } else if (item
== 1) {
735 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
736 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
737 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
738 ACTION_SELECT_CONTENT_FROM_APPS
);
739 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
740 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
741 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
742 startActivity(action
);
746 dialog
= builder
.create();
749 case DIALOG_SSL_VALIDATOR
: {
750 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
753 case DIALOG_CERT_NOT_SAVED
: {
754 builder
= new AlertDialog
.Builder(this);
755 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
756 builder
.setCancelable(false
);
757 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
759 public void onClick(DialogInterface dialog
, int which
) {
763 dialog
= builder
.create();
775 * Show loading dialog
777 public void showLoadingDialog() {
779 LoadingDialog loading
= new LoadingDialog(getResources().getString(R
.string
.wait_a_moment
));
780 FragmentManager fm
= getSupportFragmentManager();
781 FragmentTransaction ft
= fm
.beginTransaction();
782 loading
.show(ft
, DIALOG_WAIT_TAG
);
787 * Dismiss loading dialog
789 public void dismissLoadingDialog(){
790 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG
);
792 LoadingDialog loading
= (LoadingDialog
) frag
;
799 * Translates a content URI of an image to a physical path
801 * @param uri The URI to resolve
802 * @return The path to the image or null if it could not be found
804 public String
getPath(Uri uri
) {
805 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
806 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
807 if (cursor
!= null
) {
808 int column_index
= cursor
809 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
810 cursor
.moveToFirst();
811 return cursor
.getString(column_index
);
817 * Pushes a directory to the drop down list
818 * @param directory to push
819 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
821 public void pushDirname(OCFile directory
) {
822 if(!directory
.isDirectory()){
823 throw new IllegalArgumentException("Only directories may be pushed!");
825 mDirectories
.insert(directory
.getFileName(), 0);
830 * Pops a directory name from the drop down list
831 * @return True, unless the stack is empty
833 public boolean popDirname() {
834 mDirectories
.remove(mDirectories
.getItem(0));
835 return !mDirectories
.isEmpty();
838 // Custom array adapter to override text colors
839 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
841 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
845 public View
getView(int position
, View convertView
, ViewGroup parent
) {
846 View v
= super.getView(position
, convertView
, parent
);
848 ((TextView
) v
).setTextColor(getResources().getColorStateList(
849 android
.R
.color
.white
));
853 public View
getDropDownView(int position
, View convertView
,
855 View v
= super.getDropDownView(position
, convertView
, parent
);
857 ((TextView
) v
).setTextColor(getResources().getColorStateList(
858 android
.R
.color
.white
));
865 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
868 * {@link BroadcastReceiver} to enable syncing feedback in UI
871 public void onReceive(Context context
, Intent intent
) {
872 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
873 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
875 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
877 if (getAccount() != null
&& accountName
.equals(getAccount().name
)
878 && mStorageManager
!= null
881 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
883 boolean fillBlankRoot
= false
;
884 OCFile currentDir
= getCurrentDir();
885 if (currentDir
== null
) {
886 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
887 fillBlankRoot
= (currentDir
!= null
);
890 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
893 currentDir
= mStorageManager
.getFileByPath(synchFolderRemotePath
);
894 OCFileListFragment fileListFragment
= getListOfFilesFragment();
895 if (fileListFragment
!= null
) {
896 fileListFragment
.listDirectory(currentDir
);
898 if (getSecondFragment() == null
)
902 setSupportProgressBarIndeterminateVisibility(inProgress
);
903 removeStickyBroadcast(intent
);
907 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
908 if (synchResult
!= null
) {
909 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
910 mLastSslUntrustedServerResult
= synchResult
;
911 showDialog(DIALOG_SSL_VALIDATOR
);
918 private class UploadFinishReceiver
extends BroadcastReceiver
{
920 * Once the file upload has finished -> update view
921 * @author David A. Velasco
922 * {@link BroadcastReceiver} to enable upload feedback in UI
925 public void onReceive(Context context
, Intent intent
) {
926 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
927 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
928 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
929 OCFile currentDir
= getCurrentDir();
930 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
931 if (sameAccount
&& isDescendant
) {
932 refeshListOfFilesFragment();
940 * Class waiting for broadcast events from the {@link FielDownloader} service.
942 * Updates the UI when a download is started or finished, provided that it is relevant for the
945 private class DownloadFinishReceiver
extends BroadcastReceiver
{
947 public void onReceive(Context context
, Intent intent
) {
948 boolean sameAccount
= isSameAccount(context
, intent
);
949 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
950 boolean isDescendant
= isDescendant(downloadedRemotePath
);
952 if (sameAccount
&& isDescendant
) {
953 refeshListOfFilesFragment();
954 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
957 removeStickyBroadcast(intent
);
960 private boolean isDescendant(String downloadedRemotePath
) {
961 OCFile currentDir
= getCurrentDir();
962 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
965 private boolean isSameAccount(Context context
, Intent intent
) {
966 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
967 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
976 public DataStorageManager
getStorageManager() {
977 return mStorageManager
;
984 * Updates action bar and second fragment, if in dual pane mode.
987 public void onBrowsedDownTo(OCFile directory
) {
988 pushDirname(directory
);
989 cleanSecondFragment();
993 * Opens the image gallery showing the image {@link OCFile} received as parameter.
995 * @param file Image {@link OCFile} to show.
998 public void startImagePreview(OCFile file
) {
999 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
1000 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
1001 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
1002 startActivity(showDetailsIntent
);
1006 * Stars the preview of an already down media {@link OCFile}.
1008 * @param file Media {@link OCFile} to preview.
1009 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
1010 * @param autoplay When 'true', the playback will start without user interactions.
1013 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
1014 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
1015 setSecondFragment(mediaFragment
);
1016 updateFragmentsVisibility(true
);
1017 updateNavigationElementsInActionBar(file
);
1022 * Requests the download of the received {@link OCFile} , updates the UI
1023 * to monitor the download progress and prepares the activity to preview
1024 * or open the file when the download finishes.
1026 * @param file {@link OCFile} to download and preview.
1029 public void startDownloadForPreview(OCFile file
) {
1030 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1031 setSecondFragment(detailFragment
);
1032 mWaitingToPreview
= file
;
1033 requestForDownload();
1034 updateFragmentsVisibility(true
);
1035 updateNavigationElementsInActionBar(file
);
1041 * Shows the information of the {@link OCFile} received as a
1042 * parameter in the second fragment.
1044 * @param file {@link OCFile} whose details will be shown
1047 public void showDetails(OCFile file
) {
1048 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
1049 setSecondFragment(detailFragment
);
1050 updateFragmentsVisibility(true
);
1051 updateNavigationElementsInActionBar(file
);
1059 private void updateNavigationElementsInActionBar(OCFile chosenFile
) {
1060 ActionBar actionBar
= getSupportActionBar();
1061 if (chosenFile
== null
|| mDualPane
) {
1062 // only list of files - set for browsing through folders
1063 OCFile currentDir
= getCurrentDir();
1064 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1065 actionBar
.setDisplayShowTitleEnabled(false
);
1066 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1067 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1070 actionBar
.setDisplayHomeAsUpEnabled(true
);
1071 actionBar
.setDisplayShowTitleEnabled(true
);
1072 actionBar
.setTitle(chosenFile
.getFileName());
1073 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1082 public void onFileStateChanged() {
1083 refeshListOfFilesFragment();
1084 updateNavigationElementsInActionBar(getSecondFragment().getFile());
1092 public FileDownloaderBinder
getFileDownloaderBinder() {
1093 return mDownloaderBinder
;
1101 public FileUploaderBinder
getFileUploaderBinder() {
1102 return mUploaderBinder
;
1106 /** Defines callbacks for service binding, passed to bindService() */
1107 private class ListServiceConnection
implements ServiceConnection
{
1110 public void onServiceConnected(ComponentName component
, IBinder service
) {
1111 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1112 Log_OC
.d(TAG
, "Download service connected");
1113 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1114 if (mWaitingToPreview
!= null
) {
1115 requestForDownload();
1118 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1119 Log_OC
.d(TAG
, "Upload service connected");
1120 mUploaderBinder
= (FileUploaderBinder
) service
;
1124 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1125 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1126 if (listOfFiles
!= null
) {
1127 listOfFiles
.listDirectory();
1129 FileFragment secondFragment
= getSecondFragment();
1130 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1131 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1132 detailFragment
.listenForTransferProgress();
1133 detailFragment
.updateFileDetails(false
, false
);
1138 public void onServiceDisconnected(ComponentName component
) {
1139 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1140 Log_OC
.d(TAG
, "Download service disconnected");
1141 mDownloaderBinder
= null
;
1142 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1143 Log_OC
.d(TAG
, "Upload service disconnected");
1144 mUploaderBinder
= null
;
1152 * Launch an intent to request the PIN code to the user before letting him use the app
1154 private void requestPinCode() {
1155 boolean pinStart
= false
;
1156 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1157 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1159 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1160 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1167 public void onSavedCertificate() {
1168 startSynchronization();
1173 public void onFailedSavingCertificate() {
1174 showDialog(DIALOG_CERT_NOT_SAVED
);
1179 * Updates the view associated to the activity after the finish of some operation over files
1180 * in the current account.
1182 * @param operation Removal operation performed.
1183 * @param result Result of the removal.
1186 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1187 if (operation
instanceof RemoveFileOperation
) {
1188 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1190 } else if (operation
instanceof RenameFileOperation
) {
1191 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1193 } else if (operation
instanceof SynchronizeFileOperation
) {
1194 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1196 } else if (operation
instanceof CreateFolderOperation
) {
1197 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1203 * Updates the view associated to the activity after the finish of an operation trying to remove a
1206 * @param operation Removal operation performed.
1207 * @param result Result of the removal.
1209 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1210 dismissLoadingDialog();
1211 if (result
.isSuccess()) {
1212 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1214 OCFile removedFile
= operation
.getFile();
1215 getSecondFragment();
1216 FileFragment second
= getSecondFragment();
1217 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1218 cleanSecondFragment();
1220 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1221 refeshListOfFilesFragment();
1225 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1227 if (result
.isSslRecoverableException()) {
1228 mLastSslUntrustedServerResult
= result
;
1229 showDialog(DIALOG_SSL_VALIDATOR
);
1235 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1237 * @param operation Creation operation performed.
1238 * @param result Result of the creation.
1240 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1241 if (result
.isSuccess()) {
1242 dismissLoadingDialog();
1243 refeshListOfFilesFragment();
1246 //dismissDialog(DIALOG_SHORT_WAIT);
1247 dismissLoadingDialog();
1249 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1252 } catch (NotFoundException e
) {
1253 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1260 * Updates the view associated to the activity after the finish of an operation trying to rename a
1263 * @param operation Renaming operation performed.
1264 * @param result Result of the renaming.
1266 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1267 dismissLoadingDialog();
1268 OCFile renamedFile
= operation
.getFile();
1269 if (result
.isSuccess()) {
1271 FileFragment details
= getSecondFragment();
1272 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1273 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1276 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1277 refeshListOfFilesFragment();
1281 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1282 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1284 // TODO throw again the new rename dialog
1286 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1288 if (result
.isSslRecoverableException()) {
1289 mLastSslUntrustedServerResult
= result
;
1290 showDialog(DIALOG_SSL_VALIDATOR
);
1297 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1298 dismissLoadingDialog();
1299 OCFile syncedFile
= operation
.getLocalFile();
1300 if (!result
.isSuccess()) {
1301 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1302 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1303 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1304 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1308 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1313 if (operation
.transferWasRequested()) {
1314 refeshListOfFilesFragment();
1315 onTransferStateChanged(syncedFile
, true
, true
);
1318 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1329 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1331 FileFragment details
= getSecondFragment();
1332 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1333 if (downloading
|| uploading
) {
1334 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1336 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1343 public void onDismiss(EditNameDialog dialog
) {
1344 if (dialog
.getResult()) {
1345 String newDirectoryName
= dialog
.getNewFilename().trim();
1346 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1347 if (newDirectoryName
.length() > 0) {
1348 String path
= getCurrentDir().getRemotePath();
1351 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1352 RemoteOperation operation
= new CreateFolderOperation(path
, false
, mStorageManager
);
1353 operation
.execute( getAccount(),
1354 FileDisplayActivity
.this,
1355 FileDisplayActivity
.this,
1357 FileDisplayActivity
.this);
1359 showLoadingDialog();
1365 private void requestForDownload() {
1366 Account account
= getAccount();
1367 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1368 Intent i
= new Intent(this, FileDownloader
.class);
1369 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1370 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1376 private OCFile
getCurrentDir() {
1377 OCFile file
= getFile();
1379 if (file
.isDirectory()) {
1381 } else if (mStorageManager
!= null
) {
1382 String parentPath
= file
.getRemotePath().substring(0, file
.getRemotePath().lastIndexOf(file
.getFileName()));
1383 return mStorageManager
.getFileByPath(parentPath
);