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
.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
.Configuration
;
37 import android
.content
.res
.Resources
.NotFoundException
;
38 import android
.database
.Cursor
;
39 import android
.net
.Uri
;
40 import android
.os
.Bundle
;
41 import android
.os
.Handler
;
42 import android
.os
.IBinder
;
43 import android
.preference
.PreferenceManager
;
44 import android
.provider
.MediaStore
;
45 import android
.support
.v4
.app
.Fragment
;
46 import android
.support
.v4
.app
.FragmentTransaction
;
47 import android
.view
.View
;
48 import android
.view
.ViewGroup
;
49 import android
.widget
.ArrayAdapter
;
50 import android
.widget
.TextView
;
51 import android
.widget
.Toast
;
53 import com
.actionbarsherlock
.app
.ActionBar
;
54 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
55 import com
.actionbarsherlock
.view
.Menu
;
56 import com
.actionbarsherlock
.view
.MenuInflater
;
57 import com
.actionbarsherlock
.view
.MenuItem
;
58 import com
.actionbarsherlock
.view
.Window
;
59 import com
.owncloud
.android
.Log_OC
;
60 import com
.owncloud
.android
.R
;
61 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
62 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
63 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
64 import com
.owncloud
.android
.datamodel
.OCFile
;
65 import com
.owncloud
.android
.files
.services
.FileDownloader
;
66 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
67 import com
.owncloud
.android
.files
.services
.FileObserverService
;
68 import com
.owncloud
.android
.files
.services
.FileUploader
;
69 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
70 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
71 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
72 import com
.owncloud
.android
.operations
.RemoteOperation
;
73 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
74 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
75 import com
.owncloud
.android
.operations
.RenameFileOperation
;
76 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
77 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
78 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
79 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
80 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
81 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
82 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
83 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
84 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
85 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
86 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
87 import com
.owncloud
.android
.ui
.preview
.PreviewImageFragment
;
88 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
89 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
92 * Displays, what files the user has available in his ownCloud.
94 * @author Bartek Przybylski
95 * @author David A. Velasco
98 public class FileDisplayActivity
extends FileActivity
implements
99 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
101 private ArrayAdapter
<String
> mDirectories
;
102 //private OCFile mCurrentDir = null;
103 private OCFile mChosenFile
= null
;
105 /** Access point to the cached database for the current ownCloud {@link Account} */
106 private DataStorageManager mStorageManager
= null
;
108 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
109 private UploadFinishReceiver mUploadFinishReceiver
;
110 private DownloadFinishReceiver mDownloadFinishReceiver
;
111 private FileDownloaderBinder mDownloaderBinder
= null
;
112 private FileUploaderBinder mUploaderBinder
= null
;
113 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
114 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
116 private OCFileListFragment mFileList
;
118 private boolean mDualPane
;
120 public static final int DIALOG_SHORT_WAIT
= 0;
121 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
122 private static final int DIALOG_SSL_VALIDATOR
= 2;
123 private static final int DIALOG_CERT_NOT_SAVED
= 3;
125 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
126 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
128 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
130 private OCFile mWaitingToPreview
;
131 private Handler mHandler
;
133 private Configuration mNewConfigurationChangeToApplyOnStart
;
134 private boolean mStarted
;
137 protected void onCreate(Bundle savedInstanceState
) {
138 Log_OC
.d(TAG
, "onCreate() start");
139 super.onCreate(savedInstanceState
);
142 mHandler
= new Handler();
144 /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
145 if(savedInstanceState
!= null
) {
146 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDetailActivity
.KEY_WAITING_TO_PREVIEW
);
149 mWaitingToPreview
= null
;
152 /// bindings to transference services
153 mUploadConnection
= new ListServiceConnection();
154 mDownloadConnection
= new ListServiceConnection();
155 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
156 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
158 // PIN CODE request ; best location is to decide, let's try this first
159 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
164 Intent observer_intent
= new Intent(this, FileObserverService
.class);
165 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
166 startService(observer_intent
);
169 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
171 // Drop-down navigation
172 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
173 OCFile currFile
= getFile();
174 while(mStorageManager
!= null
&& currFile
!= null
&& currFile
.getFileName() != OCFile
.PATH_SEPARATOR
) {
175 mDirectories
.add(currFile
.getFileName());
176 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
178 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
180 // Inflate and set the layout view
181 setContentView(R
.layout
.files
);
182 mFileList
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
183 mDualPane
= (findViewById(R
.id
.file_details_container
) != null
);
184 if (mDualPane
&& savedInstanceState
== null
) {
185 initFileDetailsInDualPane();
189 ActionBar actionBar
= getSupportActionBar();
190 actionBar
.setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
191 actionBar
.setDisplayHomeAsUpEnabled(getFile() != null
&& getFile().getParentId() != 0);
192 actionBar
.setDisplayShowTitleEnabled(false
);
193 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
194 actionBar
.setListNavigationCallbacks(mDirectories
, this);
195 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to workaround bug in its implementation
197 Log_OC
.d(TAG
, "onCreate() end");
202 public void onConfigurationChanged (Configuration newConfig
) {
203 super.onConfigurationChanged(newConfig
);
205 checkConfigurationChange(newConfig
);
207 mNewConfigurationChangeToApplyOnStart
= newConfig
;
212 private void initFileDetailsInDualPane() {
213 if (mDualPane
&& getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
) == null
) {
214 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
215 if (mChosenFile
!= null
) {
216 if (!mChosenFile
.isDown()) {
217 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(mChosenFile
, getAccount()), FileDetailFragment
.FTAG
);
218 if (getIntent().getBooleanExtra(EXTRA_WAITING_TO_PREVIEW
, false
)) {
219 mWaitingToPreview
= mChosenFile
;
221 } else if (PreviewMediaFragment
.canBePreviewed(mChosenFile
)) {
222 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
223 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
224 transaction
.replace(R
.id
.file_details_container
, new PreviewMediaFragment(mChosenFile
, getAccount(), startPlaybackPosition
, autoplay
), FileDetailFragment
.FTAG
);
229 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
231 transaction
.commit();
237 protected void onStart() {
239 if (mNewConfigurationChangeToApplyOnStart
!= null
) {
240 checkConfigurationChange(mNewConfigurationChangeToApplyOnStart
);
241 mNewConfigurationChangeToApplyOnStart
= null
;
247 protected void onStop() {
253 private void checkConfigurationChange(Configuration newConfig
) {
254 FileFragment fragment
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
256 && fragment
.getFile() != null
257 && (newConfig
.screenLayout
& Configuration
.SCREENLAYOUT_SIZE_MASK
) >= Configuration
.SCREENLAYOUT_SIZE_LARGE
258 && newConfig
.orientation
!= Configuration
.ORIENTATION_LANDSCAPE
) {
260 onFileClick(fragment
.getFile(), true
);
261 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
262 transaction
.remove((Fragment
)fragment
);
263 transaction
.commit();
267 Intent intent
= new Intent(this, FileDisplayActivity
.class);
268 intent
.putExtra(EXTRA_FILE
, getFile());
269 intent
.putExtra(EXTRA_ACCOUNT
, getAccount());
270 startActivity(intent
);
276 protected void onDestroy() {
278 if (mDownloadConnection
!= null
)
279 unbindService(mDownloadConnection
);
280 if (mUploadConnection
!= null
)
281 unbindService(mUploadConnection
);
286 public boolean onCreateOptionsMenu(Menu menu
) {
287 MenuInflater inflater
= getSherlock().getMenuInflater();
288 inflater
.inflate(R
.menu
.main_menu
, menu
);
294 public boolean onOptionsItemSelected(MenuItem item
) {
295 boolean retval
= true
;
296 switch (item
.getItemId()) {
297 case R
.id
.action_create_dir
: {
298 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
299 dialog
.show(getSupportFragmentManager(), "createdirdialog");
302 case R
.id
.action_sync_account
: {
303 startSynchronization();
306 case R
.id
.action_upload
: {
307 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
310 case R
.id
.action_settings
: {
311 Intent settingsIntent
= new Intent(this, Preferences
.class);
312 startActivity(settingsIntent
);
315 case android
.R
.id
.home
: {
316 if(getFile() != null
&& getFile().getParentId() != 0){
322 retval
= super.onOptionsItemSelected(item
);
327 private void startSynchronization() {
328 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
329 Bundle bundle
= new Bundle();
330 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
331 ContentResolver
.requestSync(
333 AccountAuthenticator
.AUTHORITY
, bundle
);
338 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
339 int i
= itemPosition
;
343 // the next operation triggers a new call to this method, but it's necessary to
344 // ensure that the name exposed in the action bar is the current directory when the
345 // user selected it in the navigation list
346 if (itemPosition
!= 0)
347 getSupportActionBar().setSelectedNavigationItem(0);
352 * Called, when the user selected something for uploading
354 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
355 super.onActivityResult(requestCode
, resultCode
, data
);
357 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
358 requestSimpleUpload(data
, resultCode
);
360 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
361 requestMultipleUpload(data
, resultCode
);
366 private void requestMultipleUpload(Intent data
, int resultCode
) {
367 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
368 if (filePaths
!= null
) {
369 String
[] remotePaths
= new String
[filePaths
.length
];
370 String remotePathBase
= "";
371 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
372 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
374 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
375 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
376 for (int j
= 0; j
< remotePaths
.length
; j
++) {
377 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
380 Intent i
= new Intent(this, FileUploader
.class);
381 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
382 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
383 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
384 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
385 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
386 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
390 Log_OC
.d("FileDisplay", "User clicked on 'Update' with no selection");
391 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
398 private void requestSimpleUpload(Intent data
, int resultCode
) {
399 String filepath
= null
;
401 Uri selectedImageUri
= data
.getData();
403 String filemanagerstring
= selectedImageUri
.getPath();
404 String selectedImagePath
= getPath(selectedImageUri
);
406 if (selectedImagePath
!= null
)
407 filepath
= selectedImagePath
;
409 filepath
= filemanagerstring
;
411 } catch (Exception e
) {
412 Log_OC
.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
416 if (filepath
== null
) {
417 Log_OC
.e("FileDisplay", "Couldnt resolve path to file");
418 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
424 Intent i
= new Intent(this, FileUploader
.class);
425 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
427 String remotepath
= new String();
428 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
429 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
431 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
432 remotepath
+= OCFile
.PATH_SEPARATOR
;
433 remotepath
+= new File(filepath
).getName();
435 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
436 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
437 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
438 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
439 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
445 public void onBackPressed() {
446 if (mDirectories
.getCount() <= 1) {
451 mFileList
.onNavigateUp();
452 setFile(mFileList
.getCurrentFile());
455 // Resets the FileDetailsFragment on Tablets so that it always displays
456 Fragment fileFragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
457 if (fileFragment
!= null
&& (fileFragment
instanceof PreviewMediaFragment
|| !((FileDetailFragment
) fileFragment
).isEmpty())) {
458 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
459 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
460 transaction
.commit();
464 if(getFile().getParentId() == 0){
465 ActionBar actionBar
= getSupportActionBar();
466 actionBar
.setDisplayHomeAsUpEnabled(false
);
471 protected void onSaveInstanceState(Bundle outState
) {
472 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
473 Log_OC
.d(TAG
, "onSaveInstanceState() start");
474 super.onSaveInstanceState(outState
);
476 FileFragment fragment
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
477 if (fragment
!= null
) {
478 OCFile file
= fragment
.getFile();
480 outState
.putParcelable(EXTRA_FILE
, file
);
484 outState
.putParcelable(FileDetailActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
485 Log_OC
.d(TAG
, "onSaveInstanceState() end");
489 protected void onResume() {
490 Log_OC
.d(TAG
, "onResume() start");
493 // Listen for sync messages
494 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
495 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
496 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
498 // Listen for upload messages
499 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
500 mUploadFinishReceiver
= new UploadFinishReceiver();
501 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
503 // Listen for download messages
504 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
505 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
506 mDownloadFinishReceiver
= new DownloadFinishReceiver();
507 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
509 // List current directory
510 mFileList
.listDirectory(getFile()); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
512 Log_OC
.d(TAG
, "onResume() end");
517 protected void onPause() {
518 Log_OC
.d(TAG
, "onPause() start");
520 if (mSyncBroadcastReceiver
!= null
) {
521 unregisterReceiver(mSyncBroadcastReceiver
);
522 mSyncBroadcastReceiver
= null
;
524 if (mUploadFinishReceiver
!= null
) {
525 unregisterReceiver(mUploadFinishReceiver
);
526 mUploadFinishReceiver
= null
;
528 if (mDownloadFinishReceiver
!= null
) {
529 unregisterReceiver(mDownloadFinishReceiver
);
530 mDownloadFinishReceiver
= null
;
533 Log_OC
.d(TAG
, "onPause() end");
538 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
539 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
540 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
546 protected Dialog
onCreateDialog(int id
) {
547 Dialog dialog
= null
;
548 AlertDialog
.Builder builder
;
550 case DIALOG_SHORT_WAIT
: {
551 ProgressDialog working_dialog
= new ProgressDialog(this);
552 working_dialog
.setMessage(getResources().getString(
553 R
.string
.wait_a_moment
));
554 working_dialog
.setIndeterminate(true
);
555 working_dialog
.setCancelable(false
);
556 dialog
= working_dialog
;
559 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
561 String
[] items
= null
;
563 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
564 getString(R
.string
.actionbar_upload_from_apps
),
565 getString(R
.string
.actionbar_failed_instant_upload
) };
567 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
568 getString(R
.string
.actionbar_upload_from_apps
) };
570 if (InstantUploadActivity
.IS_ENABLED
)
575 builder
= new AlertDialog
.Builder(this);
576 builder
.setTitle(R
.string
.actionbar_upload
);
577 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
578 public void onClick(DialogInterface dialog
, int item
) {
581 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
582 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
583 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
585 // TODO create and handle new fragment
586 // LocalFileListFragment
588 } else if (item
== 1) {
589 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
590 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
591 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
592 ACTION_SELECT_CONTENT_FROM_APPS
);
593 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
594 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
595 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
596 startActivity(action
);
600 dialog
= builder
.create();
603 case DIALOG_SSL_VALIDATOR
: {
604 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
607 case DIALOG_CERT_NOT_SAVED
: {
608 builder
= new AlertDialog
.Builder(this);
609 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
610 builder
.setCancelable(false
);
611 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
613 public void onClick(DialogInterface dialog
, int which
) {
617 dialog
= builder
.create();
629 * Translates a content URI of an image to a physical path
631 * @param uri The URI to resolve
632 * @return The path to the image or null if it could not be found
634 public String
getPath(Uri uri
) {
635 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
636 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
637 if (cursor
!= null
) {
638 int column_index
= cursor
639 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
640 cursor
.moveToFirst();
641 return cursor
.getString(column_index
);
647 * Pushes a directory to the drop down list
648 * @param directory to push
649 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
651 public void pushDirname(OCFile directory
) {
652 if(!directory
.isDirectory()){
653 throw new IllegalArgumentException("Only directories may be pushed!");
655 mDirectories
.insert(directory
.getFileName(), 0);
660 * Pops a directory name from the drop down list
661 * @return True, unless the stack is empty
663 public boolean popDirname() {
664 mDirectories
.remove(mDirectories
.getItem(0));
665 return !mDirectories
.isEmpty();
668 // Custom array adapter to override text colors
669 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
671 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
675 public View
getView(int position
, View convertView
, ViewGroup parent
) {
676 View v
= super.getView(position
, convertView
, parent
);
678 ((TextView
) v
).setTextColor(getResources().getColorStateList(
679 android
.R
.color
.white
));
683 public View
getDropDownView(int position
, View convertView
,
685 View v
= super.getDropDownView(position
, convertView
, parent
);
687 ((TextView
) v
).setTextColor(getResources().getColorStateList(
688 android
.R
.color
.white
));
695 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
698 * {@link BroadcastReceiver} to enable syncing feedback in UI
701 public void onReceive(Context context
, Intent intent
) {
702 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
703 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
705 Log_OC
.d("FileDisplay", "sync of account " + accountName
+ " is in_progress: " + inProgress
);
707 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
709 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
711 boolean fillBlankRoot
= false
;
712 OCFile currentDir
= getFile();
713 if (currentDir
== null
) {
714 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
715 fillBlankRoot
= (currentDir
!= null
);
718 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
721 currentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
722 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager()
723 .findFragmentById(R
.id
.fileList
);
724 if (fileListFragment
!= null
) {
725 fileListFragment
.listDirectory(currentDir
);
730 setSupportProgressBarIndeterminateVisibility(inProgress
);
731 removeStickyBroadcast(intent
);
735 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
736 if (synchResult
!= null
) {
737 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
738 mLastSslUntrustedServerResult
= synchResult
;
739 showDialog(DIALOG_SSL_VALIDATOR
);
746 private class UploadFinishReceiver
extends BroadcastReceiver
{
748 * Once the file upload has finished -> update view
749 * @author David A. Velasco
750 * {@link BroadcastReceiver} to enable upload feedback in UI
753 public void onReceive(Context context
, Intent intent
) {
754 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
755 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
756 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
757 boolean isDescendant
= (getFile() != null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(getFile().getRemotePath()));
758 if (sameAccount
&& isDescendant
) {
759 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
760 if (fileListFragment
!= null
) {
761 fileListFragment
.listDirectory();
770 * Class waiting for broadcast events from the {@link FielDownloader} service.
772 * Updates the UI when a download is started or finished, provided that it is relevant for the
775 private class DownloadFinishReceiver
extends BroadcastReceiver
{
777 public void onReceive(Context context
, Intent intent
) {
778 boolean sameAccount
= isSameAccount(context
, intent
);
779 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
780 boolean isDescendant
= isDescendant(downloadedRemotePath
);
782 if (sameAccount
&& isDescendant
) {
785 updateRightPanel(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
789 removeStickyBroadcast(intent
);
792 private boolean isDescendant(String downloadedRemotePath
) {
793 return (getFile() != null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(getFile().getRemotePath()));
796 private boolean isSameAccount(Context context
, Intent intent
) {
797 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
798 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
803 protected void updateLeftPanel() {
804 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
805 if (fileListFragment
!= null
) {
806 fileListFragment
.listDirectory();
810 protected void updateRightPanel(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
811 Fragment fragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
812 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
813 if (fragment
!= null
&& fragment
instanceof FileDetailFragment
) {
814 FileDetailFragment detailsFragment
= (FileDetailFragment
) fragment
;
815 OCFile fileInFragment
= detailsFragment
.getFile();
816 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
817 // the user browsed to other file ; forget the automatic preview
818 mWaitingToPreview
= null
;
820 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
821 // grant that the right panel updates the progress bar
822 detailsFragment
.listenForTransferProgress();
823 detailsFragment
.updateFileDetails(true
, false
);
825 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
826 // update the right panel
827 if (success
&& waitedPreview
) {
828 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
829 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
830 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
831 transaction
.replace(R
.id
.file_details_container
, new PreviewMediaFragment(mWaitingToPreview
, getAccount(), 0, true
), FileDetailFragment
.FTAG
);
832 transaction
.commit();
834 detailsFragment
.updateFileDetails(false
, (success
));
835 openFile(mWaitingToPreview
);
838 mWaitingToPreview
= null
;
841 detailsFragment
.updateFileDetails(false
, (success
));
852 public DataStorageManager
getStorageManager() {
853 return mStorageManager
;
861 public void onDirectoryClick(OCFile directory
) {
862 pushDirname(directory
);
863 ActionBar actionBar
= getSupportActionBar();
864 actionBar
.setDisplayHomeAsUpEnabled(true
);
867 // Resets the FileDetailsFragment on Tablets so that it always displays
868 Fragment fileFragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
869 if (fileFragment
!= null
&& (fileFragment
instanceof PreviewMediaFragment
|| !((FileDetailFragment
) fileFragment
).isEmpty())) {
870 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
871 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
872 transaction
.commit();
882 public void onFileClick(OCFile file
, boolean onOrientationChange
) {
884 if (PreviewImageFragment
.canBePreviewed(file
)) {
885 // preview image - it handles the download, if needed
886 startPreviewImage(file
);
888 } else if (PreviewMediaFragment
.canBePreviewed(file
)) {
891 if (!onOrientationChange
) {
892 startMediaPreview(file
, 0, true
, onOrientationChange
);
894 int startPlaybackPosition
= 0;
895 boolean autoplay
= true
;
896 Fragment fragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
897 if (fragment
!= null
&& file
.isVideo()) {
898 PreviewMediaFragment videoFragment
= (PreviewMediaFragment
)fragment
;
899 startPlaybackPosition
= videoFragment
.getPosition();
900 autoplay
= videoFragment
.isPlaying();
902 startMediaPreview(file
, startPlaybackPosition
, autoplay
, onOrientationChange
);
906 // automatic download, preview on finish
907 startDownloadForPreview(file
, onOrientationChange
);
911 } else if (file
.isDown() && !onOrientationChange
) {
915 startDownloadForPreview(file
, onOrientationChange
);
920 private void startPreviewImage(OCFile file
) {
921 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
922 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
923 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
924 startActivity(showDetailsIntent
);
927 private void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
, boolean onOrientationChange
) {
928 if (mDualPane
&& !onOrientationChange
) {
929 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
930 transaction
.replace(R
.id
.file_details_container
, new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
), FileDetailFragment
.FTAG
);
931 transaction
.commit();
934 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
935 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
936 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
937 showDetailsIntent
.putExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, startPlaybackPosition
);
938 showDetailsIntent
.putExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, autoplay
);
939 startActivity(showDetailsIntent
);
943 private void startDownloadForPreview(OCFile file
, boolean onOrientationChange
) {
944 if (mDualPane
&& !onOrientationChange
) {
945 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
946 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, getAccount()), FileDetailFragment
.FTAG
);
947 transaction
.commit();
948 mWaitingToPreview
= file
;
949 requestForDownload();
952 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
953 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
954 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
955 startActivity(showDetailsIntent
);
960 private void startDetails(OCFile file
, boolean onOrientationChange
) {
961 if (mDualPane
&& !file
.isImage() && !onOrientationChange
) {
962 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
963 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, getAccount()), FileDetailFragment
.FTAG
);
964 transaction
.commit();
966 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
967 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
968 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
969 startActivity(showDetailsIntent
);
978 public OCFile
getInitialDirectory() {
987 public void onFileStateChanged() {
988 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
989 if (fileListFragment
!= null
) {
990 fileListFragment
.listDirectory();
999 public FileDownloaderBinder
getFileDownloaderBinder() {
1000 return mDownloaderBinder
;
1008 public FileUploaderBinder
getFileUploaderBinder() {
1009 return mUploaderBinder
;
1013 /** Defines callbacks for service binding, passed to bindService() */
1014 private class ListServiceConnection
implements ServiceConnection
{
1017 public void onServiceConnected(ComponentName component
, IBinder service
) {
1018 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1019 Log_OC
.d(TAG
, "Download service connected");
1020 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1021 if (mWaitingToPreview
!= null
) {
1022 requestForDownload();
1025 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1026 Log_OC
.d(TAG
, "Upload service connected");
1027 mUploaderBinder
= (FileUploaderBinder
) service
;
1031 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1032 if (mFileList
!= null
)
1033 mFileList
.listDirectory();
1035 Fragment fragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1036 if (fragment
!= null
&& fragment
instanceof FileDetailFragment
) {
1037 FileDetailFragment detailFragment
= (FileDetailFragment
)fragment
;
1038 detailFragment
.listenForTransferProgress();
1039 detailFragment
.updateFileDetails(false
, false
);
1045 public void onServiceDisconnected(ComponentName component
) {
1046 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1047 Log_OC
.d(TAG
, "Download service disconnected");
1048 mDownloaderBinder
= null
;
1049 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1050 Log_OC
.d(TAG
, "Upload service disconnected");
1051 mUploaderBinder
= null
;
1059 * Launch an intent to request the PIN code to the user before letting him use the app
1061 private void requestPinCode() {
1062 boolean pinStart
= false
;
1063 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1064 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1066 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1067 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1074 public void onSavedCertificate() {
1075 startSynchronization();
1080 public void onFailedSavingCertificate() {
1081 showDialog(DIALOG_CERT_NOT_SAVED
);
1086 * Updates the view associated to the activity after the finish of some operation over files
1087 * in the current account.
1089 * @param operation Removal operation performed.
1090 * @param result Result of the removal.
1093 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1094 if (operation
instanceof RemoveFileOperation
) {
1095 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1097 } else if (operation
instanceof RenameFileOperation
) {
1098 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1100 } else if (operation
instanceof SynchronizeFileOperation
) {
1101 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1103 } else if (operation
instanceof CreateFolderOperation
) {
1104 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1110 * Updates the view associated to the activity after the finish of an operation trying to remove a
1113 * @param operation Removal operation performed.
1114 * @param result Result of the removal.
1116 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1117 dismissDialog(DIALOG_SHORT_WAIT
);
1118 if (result
.isSuccess()) {
1119 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1121 OCFile removedFile
= operation
.getFile();
1123 FileFragment details
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1124 if (details
!= null
&& removedFile
.equals(details
.getFile())) {
1125 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1126 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
)); // empty FileDetailFragment
1127 transaction
.commit();
1130 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getFile())) {
1131 mFileList
.listDirectory();
1135 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1137 if (result
.isSslRecoverableException()) {
1138 mLastSslUntrustedServerResult
= result
;
1139 showDialog(DIALOG_SSL_VALIDATOR
);
1145 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1147 * @param operation Creation operation performed.
1148 * @param result Result of the creation.
1150 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1151 if (result
.isSuccess()) {
1152 dismissDialog(DIALOG_SHORT_WAIT
);
1153 mFileList
.listDirectory();
1156 dismissDialog(DIALOG_SHORT_WAIT
);
1158 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1161 } catch (NotFoundException e
) {
1162 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1169 * Updates the view associated to the activity after the finish of an operation trying to rename a
1172 * @param operation Renaming operation performed.
1173 * @param result Result of the renaming.
1175 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1176 dismissDialog(DIALOG_SHORT_WAIT
);
1177 OCFile renamedFile
= operation
.getFile();
1178 if (result
.isSuccess()) {
1180 FileFragment details
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1181 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1182 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1185 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getFile())) {
1186 mFileList
.listDirectory();
1190 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1191 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1193 // TODO throw again the new rename dialog
1195 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1197 if (result
.isSslRecoverableException()) {
1198 mLastSslUntrustedServerResult
= result
;
1199 showDialog(DIALOG_SSL_VALIDATOR
);
1206 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1207 dismissDialog(DIALOG_SHORT_WAIT
);
1208 OCFile syncedFile
= operation
.getLocalFile();
1209 if (!result
.isSuccess()) {
1210 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1211 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1212 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1213 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1217 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1222 if (operation
.transferWasRequested()) {
1223 mFileList
.listDirectory();
1224 onTransferStateChanged(syncedFile
, true
, true
);
1227 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1238 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1239 /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1240 if (fileListFragment != null) {
1241 fileListFragment.listDirectory();
1244 FileFragment details
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1245 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1246 if (downloading
|| uploading
) {
1247 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1249 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1257 public void showFragmentWithDetails(OCFile file
) {
1259 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1260 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, getAccount()), FileDetailFragment
.FTAG
);
1261 transaction
.commit();
1264 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
1265 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
1266 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
1267 showDetailsIntent
.putExtra(FileDetailActivity
.EXTRA_MODE
, FileDetailActivity
.MODE_DETAILS
);
1268 startActivity(showDetailsIntent
);
1272 public void onDismiss(EditNameDialog dialog
) {
1273 if (dialog
.getResult()) {
1274 String newDirectoryName
= dialog
.getNewFilename().trim();
1275 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1276 if (newDirectoryName
.length() > 0) {
1278 if (getFile() == null
) {
1279 // this is just a patch; we should ensure that mCurrentDir never is null
1280 if (!mStorageManager
.fileExists(OCFile
.PATH_SEPARATOR
)) {
1281 OCFile file
= new OCFile(OCFile
.PATH_SEPARATOR
);
1282 mStorageManager
.saveFile(file
);
1284 setFile(mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
));
1286 path
= FileDisplayActivity
.this.getFile().getRemotePath();
1289 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1290 RemoteOperation operation
= new CreateFolderOperation(path
, getFile().getFileId(), mStorageManager
);
1291 operation
.execute( getAccount(),
1292 FileDisplayActivity
.this,
1293 FileDisplayActivity
.this,
1295 FileDisplayActivity
.this);
1297 showDialog(DIALOG_SHORT_WAIT
);
1303 private void requestForDownload() {
1304 Account account
= getAccount();
1305 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1306 Intent i
= new Intent(this, FileDownloader
.class);
1307 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1308 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1318 protected void onAccountChanged() {
1319 if (getAccount() != null
) {
1320 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
1322 /// Check if the 'main' @OCFile handled by the Activity is a directory
1323 OCFile currentDir
= getFile();
1324 if(currentDir
!= null
&& !currentDir
.isDirectory()) {
1325 mChosenFile
= getFile();
1326 currentDir
= mStorageManager
.getFileById(currentDir
.getParentId());
1329 /// Check if currentDir and mChosenFile are in the current account, and update them
1330 if (currentDir
!= null
) {
1331 currentDir
= mStorageManager
.getFileByPath(currentDir
.getRemotePath()); // currentDir = null if not in the current Account
1333 if (mChosenFile
!= null
) {
1334 if (mChosenFile
.fileExists()) {
1335 mChosenFile
= mStorageManager
.getFileByPath(mChosenFile
.getRemotePath()); // mChosenFile = null if not in the current Account
1336 } // else : keep mChosenFile with the received value; this is currently the case of an upload in progress, when the user presses the status notification in a landscape tablet
1339 /// Default to root if mCurrentDir was not found
1340 if (currentDir
== null
) {
1341 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
1344 setFile(currentDir
);
1347 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");