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 as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.ui
.activity
;
24 import android
.accounts
.Account
;
25 import android
.app
.AlertDialog
;
26 import android
.app
.ProgressDialog
;
27 import android
.app
.AlertDialog
.Builder
;
28 import android
.app
.Dialog
;
29 import android
.content
.BroadcastReceiver
;
30 import android
.content
.ComponentName
;
31 import android
.content
.ContentResolver
;
32 import android
.content
.Context
;
33 import android
.content
.DialogInterface
;
34 import android
.content
.DialogInterface
.OnClickListener
;
35 import android
.content
.Intent
;
36 import android
.content
.IntentFilter
;
37 import android
.content
.ServiceConnection
;
38 import android
.content
.SharedPreferences
;
39 import android
.content
.SharedPreferences
.Editor
;
40 import android
.content
.pm
.PackageInfo
;
41 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
42 import android
.content
.res
.Resources
.NotFoundException
;
43 import android
.database
.Cursor
;
44 import android
.graphics
.Bitmap
;
45 import android
.graphics
.drawable
.BitmapDrawable
;
46 import android
.net
.Uri
;
47 import android
.os
.Bundle
;
48 import android
.os
.Handler
;
49 import android
.os
.IBinder
;
50 import android
.preference
.PreferenceManager
;
51 import android
.provider
.MediaStore
;
52 import android
.support
.v4
.app
.FragmentTransaction
;
53 import android
.util
.Log
;
54 import android
.view
.View
;
55 import android
.view
.ViewGroup
;
56 import android
.widget
.ArrayAdapter
;
57 import android
.widget
.EditText
;
58 import android
.widget
.TextView
;
59 import android
.widget
.Toast
;
61 import com
.actionbarsherlock
.app
.ActionBar
;
62 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
63 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
64 import com
.actionbarsherlock
.view
.Menu
;
65 import com
.actionbarsherlock
.view
.MenuInflater
;
66 import com
.actionbarsherlock
.view
.MenuItem
;
67 import com
.actionbarsherlock
.view
.Window
;
68 import com
.owncloud
.android
.AccountUtils
;
69 import com
.owncloud
.android
.authenticator
.AccountAuthenticator
;
70 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
71 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
72 import com
.owncloud
.android
.datamodel
.OCFile
;
73 import com
.owncloud
.android
.files
.services
.FileDownloader
;
74 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
75 import com
.owncloud
.android
.files
.services
.FileObserverService
;
76 import com
.owncloud
.android
.files
.services
.FileUploader
;
77 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
78 import com
.owncloud
.android
.network
.OwnCloudClientUtils
;
79 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
80 import com
.owncloud
.android
.operations
.RemoteOperation
;
81 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
82 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
83 import com
.owncloud
.android
.operations
.RenameFileOperation
;
84 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
85 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
86 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
87 import com
.owncloud
.android
.ui
.dialog
.ChangelogDialog
;
88 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
89 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
90 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
91 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
92 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
93 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
95 import com
.owncloud
.android
.R
;
96 import eu
.alefzero
.webdav
.WebdavClient
;
99 * Displays, what files the user has available in his ownCloud.
101 * @author Bartek Przybylski
105 public class FileDisplayActivity
extends SherlockFragmentActivity
implements
106 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
108 private ArrayAdapter
<String
> mDirectories
;
109 private OCFile mCurrentDir
= null
;
110 private OCFile mCurrentFile
= null
;
112 private DataStorageManager mStorageManager
;
113 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
114 private UploadFinishReceiver mUploadFinishReceiver
;
115 private DownloadFinishReceiver mDownloadFinishReceiver
;
116 private FileDownloaderBinder mDownloaderBinder
= null
;
117 private FileUploaderBinder mUploaderBinder
= null
;
118 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
119 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
121 private OCFileListFragment mFileList
;
123 private boolean mDualPane
;
124 private boolean mBackFromCreatingFirstAccount
;
126 private static final int DIALOG_SETUP_ACCOUNT
= 0;
127 private static final int DIALOG_CREATE_DIR
= 1;
128 private static final int DIALOG_ABOUT_APP
= 2;
129 public static final int DIALOG_SHORT_WAIT
= 3;
130 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 4;
131 private static final int DIALOG_SSL_VALIDATOR
= 5;
132 private static final int DIALOG_CERT_NOT_SAVED
= 6;
133 private static final String DIALOG_CHANGELOG_TAG
= "DIALOG_CHANGELOG";
136 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
137 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
139 private static final String TAG
= "FileDisplayActivity";
141 private static int[] mMenuIdentifiersToPatch
= {R
.id
.about_app
};
144 public void onCreate(Bundle savedInstanceState
) {
145 Log
.d(getClass().toString(), "onCreate() start");
146 super.onCreate(savedInstanceState
);
148 /// Load of parameters from received intent
149 Account account
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_ACCOUNT
);
150 if (account
!= null
&& AccountUtils
.setCurrentOwnCloudAccount(this, account
.name
)) {
151 mCurrentDir
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
);
154 /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
155 if(savedInstanceState
!= null
) {
156 // TODO - test if savedInstanceState should take precedence over file in the intent ALWAYS (now), NEVER, or SOME TIMES
157 mCurrentDir
= savedInstanceState
.getParcelable(FileDetailFragment
.EXTRA_FILE
);
160 if (!AccountUtils
.accountsAreSetup(this)) {
161 /// no account available: FORCE ACCOUNT CREATION
162 mStorageManager
= null
;
163 createFirstAccount();
165 } else { /// at least an account is available
167 initDataFromCurrentAccount(); // it checks mCurrentDir and mCurrentFile with the current account
171 mUploadConnection
= new ListServiceConnection();
172 mDownloadConnection
= new ListServiceConnection();
173 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
174 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
176 // PIN CODE request ; best location is to decide, let's try this first
177 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
182 Intent observer_intent
= new Intent(this, FileObserverService
.class);
183 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
184 startService(observer_intent
);
188 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
190 // Drop-down navigation
191 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
192 OCFile currFile
= mCurrentDir
;
193 while(mStorageManager
!= null
&& currFile
!= null
&& currFile
.getFileName() != OCFile
.PATH_SEPARATOR
) {
194 mDirectories
.add(currFile
.getFileName());
195 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
197 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
199 // Inflate and set the layout view
200 setContentView(R
.layout
.files
);
201 mFileList
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
202 mDualPane
= (findViewById(R
.id
.file_details_container
) != null
);
204 initFileDetailsInDualPane();
208 ActionBar actionBar
= getSupportActionBar();
209 actionBar
.setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
210 actionBar
.setDisplayHomeAsUpEnabled(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0);
211 actionBar
.setDisplayShowTitleEnabled(false
);
212 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
213 actionBar
.setListNavigationCallbacks(mDirectories
, this);
214 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to workaround bug in its implementation
217 // show changelog, if needed
219 mBackFromCreatingFirstAccount
= false
;
221 Log
.d(getClass().toString(), "onCreate() end");
226 * Shows a dialog with the change log of the current version after each app update
228 * TODO make it permanent; by now, only to advice the workaround app for 4.1.x
230 private void showChangeLog() {
231 if (android
.os
.Build
.VERSION
.SDK_INT
== android
.os
.Build
.VERSION_CODES
.JELLY_BEAN
) {
232 final String KEY_VERSION
= "version";
233 SharedPreferences sharedPref
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
234 int currentVersionNumber
= 0;
235 int savedVersionNumber
= sharedPref
.getInt(KEY_VERSION
, 0);
237 PackageInfo pi
= getPackageManager().getPackageInfo(getPackageName(), 0);
238 currentVersionNumber
= pi
.versionCode
;
239 } catch (Exception e
) {}
241 if (currentVersionNumber
> savedVersionNumber
) {
242 ChangelogDialog
.newInstance(true
).show(getSupportFragmentManager(), DIALOG_CHANGELOG_TAG
);
243 Editor editor
= sharedPref
.edit();
244 editor
.putInt(KEY_VERSION
, currentVersionNumber
);
252 * Launches the account creation activity. To use when no ownCloud account is available
254 private void createFirstAccount() {
255 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
256 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
257 startActivity(intent
); // the new activity won't be created until this.onStart() and this.onResume() are finished;
262 * Load of state dependent of the existence of an ownCloud account
264 private void initDataFromCurrentAccount() {
265 /// Storage manager initialization - access to local database
266 mStorageManager
= new FileDataStorageManager(
267 AccountUtils
.getCurrentOwnCloudAccount(this),
268 getContentResolver());
270 /// Check if mCurrentDir is a directory
271 if(mCurrentDir
!= null
&& !mCurrentDir
.isDirectory()) {
272 mCurrentFile
= mCurrentDir
;
273 mCurrentDir
= mStorageManager
.getFileById(mCurrentDir
.getParentId());
276 /// Check if mCurrentDir and mCurrentFile are in the current account, and update them
277 if (mCurrentDir
!= null
) {
278 mCurrentDir
= mStorageManager
.getFileByPath(mCurrentDir
.getRemotePath()); // mCurrentDir == null if it is not in the current account
280 if (mCurrentFile
!= null
) {
281 if (mCurrentFile
.fileExists()) {
282 mCurrentFile
= mStorageManager
.getFileByPath(mCurrentFile
.getRemotePath()); // mCurrentFile == null if it is not in the current account
283 } // else : keep mCurrentFile 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
286 /// Default to root if mCurrentDir was not found
287 if (mCurrentDir
== null
) {
288 mCurrentDir
= mStorageManager
.getFileByPath("/"); // will be NULL if the database was never synchronized
293 private void initFileDetailsInDualPane() {
294 if (mDualPane
&& getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
) == null
) {
295 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
296 if (mCurrentFile
!= null
) {
297 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(mCurrentFile
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
); // empty FileDetailFragment
300 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
302 transaction
.commit();
308 public void onDestroy() {
310 if (mDownloadConnection
!= null
)
311 unbindService(mDownloadConnection
);
312 if (mUploadConnection
!= null
)
313 unbindService(mUploadConnection
);
318 public boolean onCreateOptionsMenu(Menu menu
) {
319 MenuInflater inflater
= getSherlock().getMenuInflater();
320 inflater
.inflate(R
.menu
.menu
, menu
);
322 patchHiddenAccents(menu
);
328 * Workaround for this: <a href="http://code.google.com/p/android/issues/detail?id=3974">http://code.google.com/p/android/issues/detail?id=3974</a>
330 * @param menu Menu to patch
332 private void patchHiddenAccents(Menu menu
) {
333 for (int i
= 0; i
< mMenuIdentifiersToPatch
.length
; i
++) {
334 MenuItem aboutItem
= menu
.findItem(mMenuIdentifiersToPatch
[i
]);
335 if (aboutItem
!= null
&& aboutItem
.getIcon() instanceof BitmapDrawable
) {
336 // Clip off the bottom three (density independent) pixels of transparent padding
337 Bitmap original
= ((BitmapDrawable
) aboutItem
.getIcon()).getBitmap();
338 float scale
= getResources().getDisplayMetrics().density
;
339 int clippedHeight
= (int) (original
.getHeight() - (3 * scale
));
340 Bitmap scaled
= Bitmap
.createBitmap(original
, 0, 0, original
.getWidth(), clippedHeight
);
341 aboutItem
.setIcon(new BitmapDrawable(getResources(), scaled
));
348 public boolean onOptionsItemSelected(MenuItem item
) {
349 boolean retval
= true
;
350 switch (item
.getItemId()) {
351 case R
.id
.createDirectoryItem
: {
352 //showDialog(DIALOG_CREATE_DIR);
353 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", this);
354 dialog
.show(getSupportFragmentManager(), "createdirdialog");
356 case R
.id
.startSync
: {
357 startSynchronization();
360 case R
.id
.action_upload
: {
361 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
364 case R
.id
.action_settings
: {
365 Intent settingsIntent
= new Intent(this, Preferences
.class);
366 startActivity(settingsIntent
);
369 case R
.id
.about_app
: {
370 showDialog(DIALOG_ABOUT_APP
);
373 case android
.R
.id
.home
: {
374 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
380 retval
= super.onOptionsItemSelected(item
);
385 private void startSynchronization() {
386 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTH_TOKEN_TYPE
); // cancel the current synchronizations of any ownCloud account
387 Bundle bundle
= new Bundle();
388 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
389 ContentResolver
.requestSync(
390 AccountUtils
.getCurrentOwnCloudAccount(this),
391 AccountAuthenticator
.AUTH_TOKEN_TYPE
, bundle
);
396 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
397 int i
= itemPosition
;
401 // the next operation triggers a new call to this method, but it's necessary to
402 // ensure that the name exposed in the action bar is the current directory when the
403 // user selected it in the navigation list
404 if (itemPosition
!= 0)
405 getSupportActionBar().setSelectedNavigationItem(0);
410 * Called, when the user selected something for uploading
412 public void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
414 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
415 requestSimpleUpload(data
, resultCode
);
417 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
418 requestMultipleUpload(data
, resultCode
);
423 private void requestMultipleUpload(Intent data
, int resultCode
) {
424 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
425 if (filePaths
!= null
) {
426 String
[] remotePaths
= new String
[filePaths
.length
];
427 String remotePathBase
= "";
428 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
429 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
431 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
432 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
433 for (int j
= 0; j
< remotePaths
.length
; j
++) {
434 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
437 Intent i
= new Intent(this, FileUploader
.class);
438 i
.putExtra(FileUploader
.KEY_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
439 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
440 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
441 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
442 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
443 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
447 Log
.d("FileDisplay", "User clicked on 'Update' with no selection");
448 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
455 private void requestSimpleUpload(Intent data
, int resultCode
) {
456 String filepath
= null
;
458 Uri selectedImageUri
= data
.getData();
460 String filemanagerstring
= selectedImageUri
.getPath();
461 String selectedImagePath
= getPath(selectedImageUri
);
463 if (selectedImagePath
!= null
)
464 filepath
= selectedImagePath
;
466 filepath
= filemanagerstring
;
468 } catch (Exception e
) {
469 Log
.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
473 if (filepath
== null
) {
474 Log
.e("FileDisplay", "Couldnt resolve path to file");
475 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
481 Intent i
= new Intent(this, FileUploader
.class);
482 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
483 AccountUtils
.getCurrentOwnCloudAccount(this));
484 String remotepath
= new String();
485 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
486 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
488 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
489 remotepath
+= OCFile
.PATH_SEPARATOR
;
490 remotepath
+= new File(filepath
).getName();
492 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
493 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
494 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
495 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
496 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
502 public void onBackPressed() {
503 if (mDirectories
.getCount() <= 1) {
508 mFileList
.onNavigateUp();
509 mCurrentDir
= mFileList
.getCurrentFile();
512 // Resets the FileDetailsFragment on Tablets so that it always displays
513 FileDetailFragment fileDetails
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
514 if (fileDetails
!= null
&& !fileDetails
.isEmpty()) {
515 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
516 transaction
.remove(fileDetails
);
517 transaction
.add(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
);
518 transaction
.commit();
522 if(mCurrentDir
.getParentId() == 0){
523 ActionBar actionBar
= getSupportActionBar();
524 actionBar
.setDisplayHomeAsUpEnabled(false
);
529 protected void onSaveInstanceState(Bundle outState
) {
530 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
531 Log
.d(getClass().toString(), "onSaveInstanceState() start");
532 super.onSaveInstanceState(outState
);
533 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
535 FileDetailFragment fragment
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
536 if (fragment
!= null
) {
537 OCFile file
= fragment
.getDisplayedFile();
539 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, file
);
543 Log
.d(getClass().toString(), "onSaveInstanceState() end");
547 protected void onResume() {
548 Log
.d(getClass().toString(), "onResume() start");
551 if (AccountUtils
.accountsAreSetup(this)) {
553 if (mStorageManager
== null
) {
554 // this is necessary for handling the come back to FileDisplayActivity when the first ownCloud account is created
555 initDataFromCurrentAccount();
557 initFileDetailsInDualPane();
559 mBackFromCreatingFirstAccount
= true
;
562 // Listen for sync messages
563 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
564 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
565 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
567 // Listen for upload messages
568 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
569 mUploadFinishReceiver
= new UploadFinishReceiver();
570 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
572 // Listen for download messages
573 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
574 mDownloadFinishReceiver
= new DownloadFinishReceiver();
575 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
577 // List current directory
578 mFileList
.listDirectory(mCurrentDir
); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
582 mStorageManager
= null
; // an invalid object will be there if all the ownCloud accounts are removed
583 showDialog(DIALOG_SETUP_ACCOUNT
);
586 Log
.d(getClass().toString(), "onResume() end");
591 protected void onPause() {
592 Log
.d(getClass().toString(), "onPause() start");
594 if (mSyncBroadcastReceiver
!= null
) {
595 unregisterReceiver(mSyncBroadcastReceiver
);
596 mSyncBroadcastReceiver
= null
;
598 if (mUploadFinishReceiver
!= null
) {
599 unregisterReceiver(mUploadFinishReceiver
);
600 mUploadFinishReceiver
= null
;
602 if (mDownloadFinishReceiver
!= null
) {
603 unregisterReceiver(mDownloadFinishReceiver
);
604 mDownloadFinishReceiver
= null
;
606 if (!AccountUtils
.accountsAreSetup(this)) {
607 dismissDialog(DIALOG_SETUP_ACCOUNT
);
610 Log
.d(getClass().toString(), "onPause() end");
615 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
616 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
617 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
623 protected Dialog
onCreateDialog(int id
) {
624 Dialog dialog
= null
;
625 AlertDialog
.Builder builder
;
627 case DIALOG_SETUP_ACCOUNT
: {
628 builder
= new AlertDialog
.Builder(this);
629 builder
.setTitle(R
.string
.main_tit_accsetup
);
630 builder
.setMessage(R
.string
.main_wrn_accsetup
);
631 builder
.setCancelable(false
);
632 builder
.setPositiveButton(android
.R
.string
.ok
, new OnClickListener() {
633 public void onClick(DialogInterface dialog
, int which
) {
634 createFirstAccount();
638 String message
= String
.format(getString(R
.string
.common_exit
), getString(R
.string
.app_name
));
639 builder
.setNegativeButton(message
, new OnClickListener() {
640 public void onClick(DialogInterface dialog
, int which
) {
645 //builder.setNegativeButton(android.R.string.cancel, this);
646 dialog
= builder
.create();
649 case DIALOG_ABOUT_APP
: {
650 builder
= new AlertDialog
.Builder(this);
651 builder
.setTitle(getString(R
.string
.about_title
));
654 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
655 builder
.setMessage(String
.format(getString(R
.string
.about_message
), getString(R
.string
.app_name
), pkg
.versionName
));
656 builder
.setIcon(android
.R
.drawable
.ic_menu_info_details
);
657 dialog
= builder
.create();
658 } catch (NameNotFoundException e
) {
661 Log
.e(TAG
, "Error while showing about dialog", e
);
665 case DIALOG_CREATE_DIR
: {
666 builder
= new Builder(this);
667 final EditText dirNameInput
= new EditText(getBaseContext());
668 builder
.setView(dirNameInput
);
669 builder
.setTitle(R
.string
.uploader_info_dirname
);
670 int typed_color
= getResources().getColor(R
.color
.setup_text_typed
);
671 dirNameInput
.setTextColor(typed_color
);
672 builder
.setPositiveButton(android
.R
.string
.ok
,
673 new OnClickListener() {
674 public void onClick(DialogInterface dialog
, int which
) {
675 String directoryName
= dirNameInput
.getText().toString();
676 if (directoryName
.trim().length() == 0) {
681 // Figure out the path where the dir needs to be created
683 if (mCurrentDir
== null
) {
684 // this is just a patch; we should ensure that mCurrentDir never is null
685 if (!mStorageManager
.fileExists(OCFile
.PATH_SEPARATOR
)) {
686 OCFile file
= new OCFile(OCFile
.PATH_SEPARATOR
);
687 mStorageManager
.saveFile(file
);
689 mCurrentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
691 path
= FileDisplayActivity
.this.mCurrentDir
.getRemotePath();
694 path
+= directoryName
+ OCFile
.PATH_SEPARATOR
;
695 Thread thread
= new Thread(new DirectoryCreator(path
, AccountUtils
.getCurrentOwnCloudAccount(FileDisplayActivity
.this), new Handler()));
700 showDialog(DIALOG_SHORT_WAIT
);
703 builder
.setNegativeButton(R
.string
.common_cancel
,
704 new OnClickListener() {
705 public void onClick(DialogInterface dialog
, int which
) {
709 dialog
= builder
.create();
712 case DIALOG_SHORT_WAIT
: {
713 ProgressDialog working_dialog
= new ProgressDialog(this);
714 working_dialog
.setMessage(getResources().getString(
715 R
.string
.wait_a_moment
));
716 working_dialog
.setIndeterminate(true
);
717 working_dialog
.setCancelable(false
);
718 dialog
= working_dialog
;
721 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
722 final String
[] items
= { getString(R
.string
.actionbar_upload_files
),
723 getString(R
.string
.actionbar_upload_from_apps
) };
724 builder
= new AlertDialog
.Builder(this);
725 builder
.setTitle(R
.string
.actionbar_upload
);
726 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
727 public void onClick(DialogInterface dialog
, int item
) {
730 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
731 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(FileDisplayActivity
.this));
732 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
734 // TODO create and handle new fragment LocalFileListFragment
736 } else if (item
== 1) {
737 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
738 action
= action
.setType("*/*")
739 .addCategory(Intent
.CATEGORY_OPENABLE
);
740 startActivityForResult(
741 Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
742 ACTION_SELECT_CONTENT_FROM_APPS
);
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 * Translates a content URI of an image to a physical path
777 * @param uri The URI to resolve
778 * @return The path to the image or null if it could not be found
780 public String
getPath(Uri uri
) {
781 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
782 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
783 if (cursor
!= null
) {
784 int column_index
= cursor
785 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
786 cursor
.moveToFirst();
787 return cursor
.getString(column_index
);
793 * Pushes a directory to the drop down list
794 * @param directory to push
795 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
797 public void pushDirname(OCFile directory
) {
798 if(!directory
.isDirectory()){
799 throw new IllegalArgumentException("Only directories may be pushed!");
801 mDirectories
.insert(directory
.getFileName(), 0);
802 mCurrentDir
= directory
;
806 * Pops a directory name from the drop down list
807 * @return True, unless the stack is empty
809 public boolean popDirname() {
810 mDirectories
.remove(mDirectories
.getItem(0));
811 return !mDirectories
.isEmpty();
814 private class DirectoryCreator
implements Runnable
{
815 private String mTargetPath
;
816 private Account mAccount
;
817 private Handler mHandler
;
819 public DirectoryCreator(String targetPath
, Account account
, Handler handler
) {
820 mTargetPath
= targetPath
;
827 WebdavClient wdc
= OwnCloudClientUtils
.createOwnCloudClient(mAccount
, getApplicationContext());
828 boolean created
= wdc
.createDirectory(mTargetPath
);
830 mHandler
.post(new Runnable() {
833 dismissDialog(DIALOG_SHORT_WAIT
);
835 // Save new directory in local database
836 OCFile newDir
= new OCFile(mTargetPath
);
837 newDir
.setMimetype("DIR");
838 newDir
.setParentId(mCurrentDir
.getFileId());
839 mStorageManager
.saveFile(newDir
);
841 // Display the new folder right away
842 mFileList
.listDirectory();
847 mHandler
.post(new Runnable() {
850 dismissDialog(DIALOG_SHORT_WAIT
);
852 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
855 } catch (NotFoundException e
) {
856 Log
.e(TAG
, "Error while trying to show fail message " , e
);
865 // Custom array adapter to override text colors
866 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
868 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
872 public View
getView(int position
, View convertView
, ViewGroup parent
) {
873 View v
= super.getView(position
, convertView
, parent
);
875 ((TextView
) v
).setTextColor(getResources().getColorStateList(
876 android
.R
.color
.white
));
880 public View
getDropDownView(int position
, View convertView
,
882 View v
= super.getDropDownView(position
, convertView
, parent
);
884 ((TextView
) v
).setTextColor(getResources().getColorStateList(
885 android
.R
.color
.white
));
892 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
895 * {@link BroadcastReceiver} to enable syncing feedback in UI
898 public void onReceive(Context context
, Intent intent
) {
899 boolean inProgress
= intent
.getBooleanExtra(
900 FileSyncService
.IN_PROGRESS
, false
);
901 String accountName
= intent
902 .getStringExtra(FileSyncService
.ACCOUNT_NAME
);
904 Log
.d("FileDisplay", "sync of account " + accountName
905 + " is in_progress: " + inProgress
);
907 if (accountName
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
)) {
909 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
911 boolean fillBlankRoot
= false
;
912 if (mCurrentDir
== null
) {
913 mCurrentDir
= mStorageManager
.getFileByPath("/");
914 fillBlankRoot
= (mCurrentDir
!= null
);
917 if ((synchFolderRemotePath
!= null
&& mCurrentDir
!= null
&& (mCurrentDir
.getRemotePath().equals(synchFolderRemotePath
)))
920 mCurrentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
921 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager()
922 .findFragmentById(R
.id
.fileList
);
923 if (fileListFragment
!= null
) {
924 fileListFragment
.listDirectory(mCurrentDir
);
928 setSupportProgressBarIndeterminateVisibility(inProgress
);
929 if (mBackFromCreatingFirstAccount
) {
930 // awful patch to fix problem with visibility of progress circle with the first refresh of the first account
931 // TODO - kill this Activity when the first account has to be created instead of stack the account creation on it
932 getSupportActionBar().hide();
933 getSupportActionBar().show();
934 mBackFromCreatingFirstAccount
= false
;
936 removeStickyBroadcast(intent
);
940 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
941 if (synchResult
!= null
) {
942 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
943 mLastSslUntrustedServerResult
= synchResult
;
944 showDialog(DIALOG_SSL_VALIDATOR
);
951 private class UploadFinishReceiver
extends BroadcastReceiver
{
953 * Once the file upload has finished -> update view
954 * @author David A. Velasco
955 * {@link BroadcastReceiver} to enable upload feedback in UI
958 public void onReceive(Context context
, Intent intent
) {
959 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
960 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
961 boolean sameAccount
= accountName
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
);
962 boolean isDescendant
= (mCurrentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(mCurrentDir
.getRemotePath()));
963 if (sameAccount
&& isDescendant
) {
964 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
965 if (fileListFragment
!= null
) {
966 fileListFragment
.listDirectory();
975 * Once the file download has finished -> update view
977 private class DownloadFinishReceiver
extends BroadcastReceiver
{
979 public void onReceive(Context context
, Intent intent
) {
980 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
981 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
982 boolean sameAccount
= accountName
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
);
983 boolean isDescendant
= (mCurrentDir
!= null
) && (downloadedRemotePath
!= null
) && (downloadedRemotePath
.startsWith(mCurrentDir
.getRemotePath()));
984 if (sameAccount
&& isDescendant
) {
985 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
986 if (fileListFragment
!= null
) {
987 fileListFragment
.listDirectory();
1000 public DataStorageManager
getStorageManager() {
1001 return mStorageManager
;
1009 public void onDirectoryClick(OCFile directory
) {
1010 pushDirname(directory
);
1011 ActionBar actionBar
= getSupportActionBar();
1012 actionBar
.setDisplayHomeAsUpEnabled(true
);
1015 // Resets the FileDetailsFragment on Tablets so that it always displays
1016 FileDetailFragment fileDetails
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1017 if (fileDetails
!= null
&& !fileDetails
.isEmpty()) {
1018 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1019 transaction
.remove(fileDetails
);
1020 transaction
.add(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
);
1021 transaction
.commit();
1031 public void onFileClick(OCFile file
) {
1033 // If we are on a large device -> update fragment
1035 // buttons in the details view are problematic when trying to reuse an existing fragment; create always a new one solves some of them, BUT no all; downloads are 'dangerous'
1036 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1037 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
1038 transaction
.setTransition(FragmentTransaction
.TRANSIT_FRAGMENT_FADE
);
1039 transaction
.commit();
1041 } else { // small or medium screen device -> new Activity
1042 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
1043 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_FILE
, file
);
1044 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
1045 startActivity(showDetailsIntent
);
1054 public OCFile
getInitialDirectory() {
1063 public void onFileStateChanged() {
1064 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
1065 if (fileListFragment
!= null
) {
1066 fileListFragment
.listDirectory();
1075 public FileDownloaderBinder
getFileDownloaderBinder() {
1076 return mDownloaderBinder
;
1084 public FileUploaderBinder
getFileUploaderBinder() {
1085 return mUploaderBinder
;
1089 /** Defines callbacks for service binding, passed to bindService() */
1090 private class ListServiceConnection
implements ServiceConnection
{
1093 public void onServiceConnected(ComponentName component
, IBinder service
) {
1094 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1095 Log
.d(TAG
, "Download service connected");
1096 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1097 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1098 Log
.d(TAG
, "Upload service connected");
1099 mUploaderBinder
= (FileUploaderBinder
) service
;
1103 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1104 if (mFileList
!= null
)
1105 mFileList
.listDirectory();
1107 FileDetailFragment fragment
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1108 if (fragment
!= null
)
1109 fragment
.updateFileDetails(false
);
1114 public void onServiceDisconnected(ComponentName component
) {
1115 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1116 Log
.d(TAG
, "Download service disconnected");
1117 mDownloaderBinder
= null
;
1118 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1119 Log
.d(TAG
, "Upload service disconnected");
1120 mUploaderBinder
= null
;
1128 * Launch an intent to request the PIN code to the user before letting him use the app
1130 private void requestPinCode() {
1131 boolean pinStart
= false
;
1132 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1133 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1135 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1136 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1143 public void onSavedCertificate() {
1144 startSynchronization();
1149 public void onFailedSavingCertificate() {
1150 showDialog(DIALOG_CERT_NOT_SAVED
);
1155 * Updates the view associated to the activity after the finish of some operation over files
1156 * in the current account.
1158 * @param operation Removal operation performed.
1159 * @param result Result of the removal.
1162 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1163 if (operation
instanceof RemoveFileOperation
) {
1164 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1166 } else if (operation
instanceof RenameFileOperation
) {
1167 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1169 } else if (operation
instanceof SynchronizeFileOperation
) {
1170 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1176 * Updates the view associated to the activity after the finish of an operation trying to remove a
1179 * @param operation Removal operation performed.
1180 * @param result Result of the removal.
1182 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1183 dismissDialog(DIALOG_SHORT_WAIT
);
1184 if (result
.isSuccess()) {
1185 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1187 OCFile removedFile
= operation
.getFile();
1189 FileDetailFragment details
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1190 if (details
!= null
&& removedFile
.equals(details
.getDisplayedFile()) ) {
1191 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1192 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
)); // empty FileDetailFragment
1193 transaction
.commit();
1196 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(mCurrentDir
)) {
1197 mFileList
.listDirectory();
1201 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1203 if (result
.isSslRecoverableException()) {
1204 mLastSslUntrustedServerResult
= result
;
1205 showDialog(DIALOG_SSL_VALIDATOR
);
1211 * Updates the view associated to the activity after the finish of an operation trying to rename a
1214 * @param operation Renaming operation performed.
1215 * @param result Result of the renaming.
1217 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1218 dismissDialog(DIALOG_SHORT_WAIT
);
1219 OCFile renamedFile
= operation
.getFile();
1220 if (result
.isSuccess()) {
1222 FileDetailFragment details
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1223 if (details
!= null
&& renamedFile
.equals(details
.getDisplayedFile()) ) {
1224 details
.updateFileDetails(renamedFile
, AccountUtils
.getCurrentOwnCloudAccount(this));
1227 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(mCurrentDir
)) {
1228 mFileList
.listDirectory();
1232 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1233 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1235 // TODO throw again the new rename dialog
1237 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1239 if (result
.isSslRecoverableException()) {
1240 mLastSslUntrustedServerResult
= result
;
1241 showDialog(DIALOG_SSL_VALIDATOR
);
1248 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1249 dismissDialog(DIALOG_SHORT_WAIT
);
1250 OCFile syncedFile
= operation
.getLocalFile();
1251 if (!result
.isSuccess()) {
1252 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1253 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1254 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1255 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
1259 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1264 if (operation
.transferWasRequested()) {
1265 mFileList
.listDirectory();
1266 onTransferStateChanged(syncedFile
, true
, true
);
1269 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1280 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1281 /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1282 if (fileListFragment != null) {
1283 fileListFragment.listDirectory();
1286 FileDetailFragment details
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1287 if (details
!= null
&& file
.equals(details
.getDisplayedFile()) ) {
1288 if (downloading
|| uploading
) {
1289 details
.updateFileDetails(file
, AccountUtils
.getCurrentOwnCloudAccount(this));
1291 details
.updateFileDetails(downloading
|| uploading
);
1299 public void onDismiss(EditNameDialog dialog
) {
1301 if (dialog
.getResult()) {
1302 String newDirectoryName
= dialog
.getNewFilename().trim();
1303 Log
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1304 if (newDirectoryName
.length() > 0) {
1306 if (mCurrentDir
== null
) {
1307 // this is just a patch; we should ensure that mCurrentDir never is null
1308 if (!mStorageManager
.fileExists(OCFile
.PATH_SEPARATOR
)) {
1309 OCFile file
= new OCFile(OCFile
.PATH_SEPARATOR
);
1310 mStorageManager
.saveFile(file
);
1312 mCurrentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
1314 path
= FileDisplayActivity
.this.mCurrentDir
.getRemotePath();
1317 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1318 Thread thread
= new Thread(new DirectoryCreator(path
, AccountUtils
.getCurrentOwnCloudAccount(FileDisplayActivity
.this), new Handler()));
1321 showDialog(DIALOG_SHORT_WAIT
);