1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
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
.Activity
;
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
.Fragment
;
53 import android
.support
.v4
.app
.FragmentTransaction
;
54 import android
.util
.Log
;
55 import android
.view
.View
;
56 import android
.view
.ViewGroup
;
57 import android
.widget
.ArrayAdapter
;
58 import android
.widget
.EditText
;
59 import android
.widget
.TextView
;
60 import android
.widget
.Toast
;
62 import com
.actionbarsherlock
.app
.ActionBar
;
63 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
64 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
65 import com
.actionbarsherlock
.view
.Menu
;
66 import com
.actionbarsherlock
.view
.MenuInflater
;
67 import com
.actionbarsherlock
.view
.MenuItem
;
68 import com
.actionbarsherlock
.view
.Window
;
69 import com
.owncloud
.android
.AccountUtils
;
70 import com
.owncloud
.android
.authenticator
.AccountAuthenticator
;
71 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
72 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
73 import com
.owncloud
.android
.datamodel
.OCFile
;
74 import com
.owncloud
.android
.files
.services
.FileDownloader
;
75 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
76 import com
.owncloud
.android
.files
.services
.FileObserverService
;
77 import com
.owncloud
.android
.files
.services
.FileUploader
;
78 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
79 import com
.owncloud
.android
.network
.OwnCloudClientUtils
;
80 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
81 import com
.owncloud
.android
.operations
.RemoteOperation
;
82 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
83 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
84 import com
.owncloud
.android
.operations
.RenameFileOperation
;
85 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
86 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
87 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
88 import com
.owncloud
.android
.ui
.dialog
.ChangelogDialog
;
89 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
90 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
91 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
92 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
93 import com
.owncloud
.android
.ui
.fragment
.FilePreviewFragment
;
94 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
96 import com
.owncloud
.android
.R
;
97 import eu
.alefzero
.webdav
.WebdavClient
;
100 * Displays, what files the user has available in his ownCloud.
102 * @author Bartek Przybylski
106 public class FileDisplayActivity
extends SherlockFragmentActivity
implements
107 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
{
109 private ArrayAdapter
<String
> mDirectories
;
110 private OCFile mCurrentDir
= null
;
111 private OCFile mCurrentFile
= null
;
113 private DataStorageManager mStorageManager
;
114 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
115 private UploadFinishReceiver mUploadFinishReceiver
;
116 private DownloadFinishReceiver mDownloadFinishReceiver
;
117 private FileDownloaderBinder mDownloaderBinder
= null
;
118 private FileUploaderBinder mUploaderBinder
= null
;
119 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
120 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
122 private OCFileListFragment mFileList
;
124 private boolean mDualPane
;
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
.action_about_app
};
143 private OCFile mWaitingToPreview
;
144 private Handler mHandler
;
148 public void onCreate(Bundle savedInstanceState
) {
149 Log
.d(getClass().toString(), "onCreate() start");
150 super.onCreate(savedInstanceState
);
152 /// Load of parameters from received intent
153 mCurrentDir
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
); // no check necessary, mCurrenDir == null if the parameter is not in the intent
154 Account account
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_ACCOUNT
);
156 AccountUtils
.setCurrentOwnCloudAccount(this, account
.name
);
158 /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
159 if(savedInstanceState
!= null
) {
160 // TODO - test if savedInstanceState should take precedence over file in the intent ALWAYS (now), NEVER, or SOME TIMES
161 mCurrentDir
= savedInstanceState
.getParcelable(FileDetailFragment
.EXTRA_FILE
);
162 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDetailActivity
.KEY_WAITING_TO_PREVIEW
);
165 mWaitingToPreview
= null
;
168 if (!AccountUtils
.accountsAreSetup(this)) {
169 /// no account available: FORCE ACCOUNT CREATION
170 mStorageManager
= null
;
171 createFirstAccount();
173 } else { /// at least an account is available
175 initDataFromCurrentAccount(); // it checks mCurrentDir and mCurrentFile with the current account
179 mUploadConnection
= new ListServiceConnection();
180 mDownloadConnection
= new ListServiceConnection();
181 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
182 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
184 // PIN CODE request ; best location is to decide, let's try this first
185 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
190 Intent observer_intent
= new Intent(this, FileObserverService
.class);
191 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
192 startService(observer_intent
);
196 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
198 // Drop-down navigation
199 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
200 OCFile currFile
= mCurrentDir
;
201 while(currFile
!= null
&& currFile
.getFileName() != OCFile
.PATH_SEPARATOR
) {
202 mDirectories
.add(currFile
.getFileName());
203 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
205 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
207 // Inflate and set the layout view
208 setContentView(R
.layout
.files
);
209 mFileList
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
210 mDualPane
= (findViewById(R
.id
.file_details_container
) != null
);
212 initFileDetailsInDualPane();
216 ActionBar actionBar
= getSupportActionBar();
217 actionBar
.setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
218 actionBar
.setDisplayHomeAsUpEnabled(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0);
219 actionBar
.setDisplayShowTitleEnabled(false
);
220 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
221 actionBar
.setListNavigationCallbacks(mDirectories
, this);
222 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to workaround bug in its implementation
225 // show changelog, if needed
228 Log
.d(getClass().toString(), "onCreate() end");
233 * Shows a dialog with the change log of the current version after each app update
235 * TODO make it permanent; by now, only to advice the workaround app for 4.1.x
237 private void showChangeLog() {
238 if (android
.os
.Build
.VERSION
.SDK_INT
== android
.os
.Build
.VERSION_CODES
.JELLY_BEAN
) {
239 final String KEY_VERSION
= "version";
240 SharedPreferences sharedPref
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
241 int currentVersionNumber
= 0;
242 int savedVersionNumber
= sharedPref
.getInt(KEY_VERSION
, 0);
244 PackageInfo pi
= getPackageManager().getPackageInfo(getPackageName(), 0);
245 currentVersionNumber
= pi
.versionCode
;
246 } catch (Exception e
) {}
248 if (currentVersionNumber
> savedVersionNumber
) {
249 ChangelogDialog
.newInstance(true
).show(getSupportFragmentManager(), DIALOG_CHANGELOG_TAG
);
250 Editor editor
= sharedPref
.edit();
251 editor
.putInt(KEY_VERSION
, currentVersionNumber
);
259 * Launches the account creation activity. To use when no ownCloud account is available
261 private void createFirstAccount() {
262 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
263 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
264 startActivity(intent
); // the new activity won't be created until this.onStart() and this.onResume() are finished;
269 * Load of state dependent of the existence of an ownCloud account
271 private void initDataFromCurrentAccount() {
272 /// Storage manager initialization - access to local database
273 mStorageManager
= new FileDataStorageManager(
274 AccountUtils
.getCurrentOwnCloudAccount(this),
275 getContentResolver());
277 /// Check if mCurrentDir is a directory
278 if(mCurrentDir
!= null
&& !mCurrentDir
.isDirectory()) {
279 mCurrentFile
= mCurrentDir
;
280 mCurrentDir
= mStorageManager
.getFileById(mCurrentDir
.getParentId());
283 /// Check if mCurrentDir and mCurrentFile are in the current account, and update them
284 if (mCurrentDir
!= null
) {
285 mCurrentDir
= mStorageManager
.getFileByPath(mCurrentDir
.getRemotePath()); // mCurrentDir == null if it is not in the current account
287 if (mCurrentFile
!= null
) {
288 if (mCurrentFile
.fileExists()) {
289 mCurrentFile
= mStorageManager
.getFileByPath(mCurrentFile
.getRemotePath()); // mCurrentFile == null if it is not in the current account
290 } // 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
293 /// Default to root if mCurrentDir was not found
294 if (mCurrentDir
== null
) {
295 mCurrentDir
= mStorageManager
.getFileByPath("/"); // will be NULL if the database was never synchronized
300 private void initFileDetailsInDualPane() {
301 if (mDualPane
&& getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
) == null
) {
302 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
303 if (mCurrentFile
!= null
) {
304 if (FilePreviewFragment
.canBePreviewed(mCurrentFile
)) {
305 if (mCurrentFile
.isDown()) {
306 transaction
.replace(R
.id
.file_details_container
, new FilePreviewFragment(mCurrentFile
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
308 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(mCurrentFile
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
309 mWaitingToPreview
= mCurrentFile
;
312 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(mCurrentFile
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
317 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
319 transaction
.commit();
325 public void onDestroy() {
327 if (mDownloadConnection
!= null
)
328 unbindService(mDownloadConnection
);
329 if (mUploadConnection
!= null
)
330 unbindService(mUploadConnection
);
335 public boolean onCreateOptionsMenu(Menu menu
) {
336 MenuInflater inflater
= getSherlock().getMenuInflater();
337 inflater
.inflate(R
.menu
.main_menu
, menu
);
339 patchHiddenAccents(menu
);
345 * 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>
347 * @param menu Menu to patch
349 private void patchHiddenAccents(Menu menu
) {
350 for (int i
= 0; i
< mMenuIdentifiersToPatch
.length
; i
++) {
351 MenuItem aboutItem
= menu
.findItem(mMenuIdentifiersToPatch
[i
]);
352 if (aboutItem
!= null
&& aboutItem
.getIcon() instanceof BitmapDrawable
) {
353 // Clip off the bottom three (density independent) pixels of transparent padding
354 Bitmap original
= ((BitmapDrawable
) aboutItem
.getIcon()).getBitmap();
355 float scale
= getResources().getDisplayMetrics().density
;
356 int clippedHeight
= (int) (original
.getHeight() - (3 * scale
));
357 Bitmap scaled
= Bitmap
.createBitmap(original
, 0, 0, original
.getWidth(), clippedHeight
);
358 aboutItem
.setIcon(new BitmapDrawable(getResources(), scaled
));
365 public boolean onOptionsItemSelected(MenuItem item
) {
366 boolean retval
= true
;
367 switch (item
.getItemId()) {
368 case R
.id
.action_create_dir
: {
369 showDialog(DIALOG_CREATE_DIR
);
372 case R
.id
.action_sync_account
: {
373 startSynchronization();
376 case R
.id
.action_upload
: {
377 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
380 case R
.id
.action_settings
: {
381 Intent settingsIntent
= new Intent(this, Preferences
.class);
382 startActivity(settingsIntent
);
385 case R
.id
.action_about_app
: {
386 showDialog(DIALOG_ABOUT_APP
);
389 case android
.R
.id
.home
: {
390 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
396 retval
= super.onOptionsItemSelected(item
);
401 private void startSynchronization() {
402 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTH_TOKEN_TYPE
); // cancel the current synchronizations of any ownCloud account
403 Bundle bundle
= new Bundle();
404 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
405 ContentResolver
.requestSync(
406 AccountUtils
.getCurrentOwnCloudAccount(this),
407 AccountAuthenticator
.AUTH_TOKEN_TYPE
, bundle
);
412 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
413 int i
= itemPosition
;
417 // the next operation triggers a new call to this method, but it's necessary to
418 // ensure that the name exposed in the action bar is the current directory when the
419 // user selected it in the navigation list
420 if (itemPosition
!= 0)
421 getSupportActionBar().setSelectedNavigationItem(0);
426 * Called, when the user selected something for uploading
428 public void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
430 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
431 requestSimpleUpload(data
, resultCode
);
433 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
434 requestMultipleUpload(data
, resultCode
);
439 private void requestMultipleUpload(Intent data
, int resultCode
) {
440 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
441 if (filePaths
!= null
) {
442 String
[] remotePaths
= new String
[filePaths
.length
];
443 String remotePathBase
= "";
444 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
445 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
447 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
448 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
449 for (int j
= 0; j
< remotePaths
.length
; j
++) {
450 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
453 Intent i
= new Intent(this, FileUploader
.class);
454 i
.putExtra(FileUploader
.KEY_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
455 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
456 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
457 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
458 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
459 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
463 Log
.d("FileDisplay", "User clicked on 'Update' with no selection");
464 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
471 private void requestSimpleUpload(Intent data
, int resultCode
) {
472 String filepath
= null
;
474 Uri selectedImageUri
= data
.getData();
476 String filemanagerstring
= selectedImageUri
.getPath();
477 String selectedImagePath
= getPath(selectedImageUri
);
479 if (selectedImagePath
!= null
)
480 filepath
= selectedImagePath
;
482 filepath
= filemanagerstring
;
484 } catch (Exception e
) {
485 Log
.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
489 if (filepath
== null
) {
490 Log
.e("FileDisplay", "Couldnt resolve path to file");
491 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
497 Intent i
= new Intent(this, FileUploader
.class);
498 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
499 AccountUtils
.getCurrentOwnCloudAccount(this));
500 String remotepath
= new String();
501 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
502 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
504 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
505 remotepath
+= OCFile
.PATH_SEPARATOR
;
506 remotepath
+= new File(filepath
).getName();
508 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
509 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
510 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
511 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
512 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
518 public void onBackPressed() {
519 if (mDirectories
.getCount() <= 1) {
524 mFileList
.onNavigateUp();
525 mCurrentDir
= mFileList
.getCurrentFile();
528 // Resets the FileDetailsFragment on Tablets so that it always displays
529 Fragment fileFragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
530 if (fileFragment
!= null
&& (fileFragment
instanceof FilePreviewFragment
|| !((FileDetailFragment
) fileFragment
).isEmpty())) {
531 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
532 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
533 transaction
.commit();
537 if(mCurrentDir
.getParentId() == 0){
538 ActionBar actionBar
= getSupportActionBar();
539 actionBar
.setDisplayHomeAsUpEnabled(false
);
544 protected void onSaveInstanceState(Bundle outState
) {
545 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
546 Log
.d(getClass().toString(), "onSaveInstanceState() start");
547 super.onSaveInstanceState(outState
);
548 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
550 FileFragment fragment
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
551 if (fragment
!= null
) {
552 OCFile file
= fragment
.getFile();
554 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, file
);
558 outState
.putParcelable(FileDetailActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
559 Log
.d(getClass().toString(), "onSaveInstanceState() end");
563 protected void onResume() {
564 Log
.d(getClass().toString(), "onResume() start");
567 if (AccountUtils
.accountsAreSetup(this)) {
569 if (mStorageManager
== null
) {
570 // this is necessary for handling the come back to FileDisplayActivity when the first ownCloud account is created
571 initDataFromCurrentAccount();
573 initFileDetailsInDualPane();
577 // Listen for sync messages
578 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
579 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
580 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
582 // Listen for upload messages
583 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
584 mUploadFinishReceiver
= new UploadFinishReceiver();
585 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
587 // Listen for download messages
588 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
589 //downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
590 mDownloadFinishReceiver
= new DownloadFinishReceiver();
591 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
593 // List current directory
594 mFileList
.listDirectory(mCurrentDir
); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
598 mStorageManager
= null
; // an invalid object will be there if all the ownCloud accounts are removed
599 showDialog(DIALOG_SETUP_ACCOUNT
);
602 Log
.d(getClass().toString(), "onResume() end");
607 protected void onPause() {
608 Log
.d(getClass().toString(), "onPause() start");
610 if (mSyncBroadcastReceiver
!= null
) {
611 unregisterReceiver(mSyncBroadcastReceiver
);
612 mSyncBroadcastReceiver
= null
;
614 if (mUploadFinishReceiver
!= null
) {
615 unregisterReceiver(mUploadFinishReceiver
);
616 mUploadFinishReceiver
= null
;
618 if (mDownloadFinishReceiver
!= null
) {
619 unregisterReceiver(mDownloadFinishReceiver
);
620 mDownloadFinishReceiver
= null
;
622 if (!AccountUtils
.accountsAreSetup(this)) {
623 dismissDialog(DIALOG_SETUP_ACCOUNT
);
626 Log
.d(getClass().toString(), "onPause() end");
631 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
632 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
633 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
639 protected Dialog
onCreateDialog(int id
) {
640 Dialog dialog
= null
;
641 AlertDialog
.Builder builder
;
643 case DIALOG_SETUP_ACCOUNT
: {
644 builder
= new AlertDialog
.Builder(this);
645 builder
.setTitle(R
.string
.main_tit_accsetup
);
646 builder
.setMessage(R
.string
.main_wrn_accsetup
);
647 builder
.setCancelable(false
);
648 builder
.setPositiveButton(android
.R
.string
.ok
, new OnClickListener() {
649 public void onClick(DialogInterface dialog
, int which
) {
650 createFirstAccount();
654 String message
= String
.format(getString(R
.string
.common_exit
), getString(R
.string
.app_name
));
655 builder
.setNegativeButton(message
, new OnClickListener() {
656 public void onClick(DialogInterface dialog
, int which
) {
661 //builder.setNegativeButton(android.R.string.cancel, this);
662 dialog
= builder
.create();
665 case DIALOG_ABOUT_APP
: {
666 builder
= new AlertDialog
.Builder(this);
667 builder
.setTitle(getString(R
.string
.about_title
));
670 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
671 builder
.setMessage(String
.format(getString(R
.string
.about_message
), getString(R
.string
.app_name
), pkg
.versionName
));
672 builder
.setIcon(android
.R
.drawable
.ic_menu_info_details
);
673 dialog
= builder
.create();
674 } catch (NameNotFoundException e
) {
677 Log
.e(TAG
, "Error while showing about dialog", e
);
681 case DIALOG_CREATE_DIR
: {
682 builder
= new Builder(this);
683 final EditText dirNameInput
= new EditText(getBaseContext());
684 builder
.setView(dirNameInput
);
685 builder
.setTitle(R
.string
.uploader_info_dirname
);
686 int typed_color
= getResources().getColor(R
.color
.setup_text_typed
);
687 dirNameInput
.setTextColor(typed_color
);
688 builder
.setPositiveButton(android
.R
.string
.ok
,
689 new OnClickListener() {
690 public void onClick(DialogInterface dialog
, int which
) {
691 String directoryName
= dirNameInput
.getText().toString();
692 if (directoryName
.trim().length() == 0) {
697 // Figure out the path where the dir needs to be created
699 if (mCurrentDir
== null
) {
700 // this is just a patch; we should ensure that mCurrentDir never is null
701 if (!mStorageManager
.fileExists(OCFile
.PATH_SEPARATOR
)) {
702 OCFile file
= new OCFile(OCFile
.PATH_SEPARATOR
);
703 mStorageManager
.saveFile(file
);
705 mCurrentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
707 path
= FileDisplayActivity
.this.mCurrentDir
.getRemotePath();
710 path
+= directoryName
+ OCFile
.PATH_SEPARATOR
;
711 Thread thread
= new Thread(new DirectoryCreator(path
, AccountUtils
.getCurrentOwnCloudAccount(FileDisplayActivity
.this), new Handler()));
716 showDialog(DIALOG_SHORT_WAIT
);
719 builder
.setNegativeButton(R
.string
.common_cancel
,
720 new OnClickListener() {
721 public void onClick(DialogInterface dialog
, int which
) {
725 dialog
= builder
.create();
728 case DIALOG_SHORT_WAIT
: {
729 ProgressDialog working_dialog
= new ProgressDialog(this);
730 working_dialog
.setMessage(getResources().getString(
731 R
.string
.wait_a_moment
));
732 working_dialog
.setIndeterminate(true
);
733 working_dialog
.setCancelable(false
);
734 dialog
= working_dialog
;
737 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
738 final String
[] items
= { getString(R
.string
.actionbar_upload_files
),
739 getString(R
.string
.actionbar_upload_from_apps
) };
740 builder
= new AlertDialog
.Builder(this);
741 builder
.setTitle(R
.string
.actionbar_upload
);
742 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
743 public void onClick(DialogInterface dialog
, int item
) {
746 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
747 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(FileDisplayActivity
.this));
748 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
750 // TODO create and handle new fragment LocalFileListFragment
752 } else if (item
== 1) {
753 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
754 action
= action
.setType("*/*")
755 .addCategory(Intent
.CATEGORY_OPENABLE
);
756 startActivityForResult(
757 Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
758 ACTION_SELECT_CONTENT_FROM_APPS
);
762 dialog
= builder
.create();
765 case DIALOG_SSL_VALIDATOR
: {
766 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
769 case DIALOG_CERT_NOT_SAVED
: {
770 builder
= new AlertDialog
.Builder(this);
771 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
772 builder
.setCancelable(false
);
773 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
775 public void onClick(DialogInterface dialog
, int which
) {
779 dialog
= builder
.create();
791 * Translates a content URI of an image to a physical path
793 * @param uri The URI to resolve
794 * @return The path to the image or null if it could not be found
796 public String
getPath(Uri uri
) {
797 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
798 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
799 if (cursor
!= null
) {
800 int column_index
= cursor
801 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
802 cursor
.moveToFirst();
803 return cursor
.getString(column_index
);
809 * Pushes a directory to the drop down list
810 * @param directory to push
811 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
813 public void pushDirname(OCFile directory
) {
814 if(!directory
.isDirectory()){
815 throw new IllegalArgumentException("Only directories may be pushed!");
817 mDirectories
.insert(directory
.getFileName(), 0);
818 mCurrentDir
= directory
;
822 * Pops a directory name from the drop down list
823 * @return True, unless the stack is empty
825 public boolean popDirname() {
826 mDirectories
.remove(mDirectories
.getItem(0));
827 return !mDirectories
.isEmpty();
830 private class DirectoryCreator
implements Runnable
{
831 private String mTargetPath
;
832 private Account mAccount
;
833 private Handler mHandler
;
835 public DirectoryCreator(String targetPath
, Account account
, Handler handler
) {
836 mTargetPath
= targetPath
;
843 WebdavClient wdc
= OwnCloudClientUtils
.createOwnCloudClient(mAccount
, getApplicationContext());
844 boolean created
= wdc
.createDirectory(mTargetPath
);
846 mHandler
.post(new Runnable() {
849 dismissDialog(DIALOG_SHORT_WAIT
);
851 // Save new directory in local database
852 OCFile newDir
= new OCFile(mTargetPath
);
853 newDir
.setMimetype("DIR");
854 newDir
.setParentId(mCurrentDir
.getFileId());
855 mStorageManager
.saveFile(newDir
);
857 // Display the new folder right away
858 mFileList
.listDirectory();
863 mHandler
.post(new Runnable() {
866 dismissDialog(DIALOG_SHORT_WAIT
);
868 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
871 } catch (NotFoundException e
) {
872 Log
.e(TAG
, "Error while trying to show fail message " , e
);
881 // Custom array adapter to override text colors
882 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
884 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
888 public View
getView(int position
, View convertView
, ViewGroup parent
) {
889 View v
= super.getView(position
, convertView
, parent
);
891 ((TextView
) v
).setTextColor(getResources().getColorStateList(
892 android
.R
.color
.white
));
896 public View
getDropDownView(int position
, View convertView
,
898 View v
= super.getDropDownView(position
, convertView
, parent
);
900 ((TextView
) v
).setTextColor(getResources().getColorStateList(
901 android
.R
.color
.white
));
908 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
911 * {@link BroadcastReceiver} to enable syncing feedback in UI
914 public void onReceive(Context context
, Intent intent
) {
915 boolean inProgress
= intent
.getBooleanExtra(
916 FileSyncService
.IN_PROGRESS
, false
);
917 String accountName
= intent
918 .getStringExtra(FileSyncService
.ACCOUNT_NAME
);
920 Log
.d("FileDisplay", "sync of account " + accountName
921 + " is in_progress: " + inProgress
);
923 if (accountName
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
)) {
925 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
927 boolean fillBlankRoot
= false
;
928 if (mCurrentDir
== null
) {
929 mCurrentDir
= mStorageManager
.getFileByPath("/");
930 fillBlankRoot
= (mCurrentDir
!= null
);
933 if ((synchFolderRemotePath
!= null
&& mCurrentDir
!= null
&& (mCurrentDir
.getRemotePath().equals(synchFolderRemotePath
)))
936 mCurrentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
937 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager()
938 .findFragmentById(R
.id
.fileList
);
939 if (fileListFragment
!= null
) {
940 fileListFragment
.listDirectory(mCurrentDir
);
944 setSupportProgressBarIndeterminateVisibility(inProgress
);
945 removeStickyBroadcast(intent
);
949 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
950 if (synchResult
!= null
) {
951 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
952 mLastSslUntrustedServerResult
= synchResult
;
953 showDialog(DIALOG_SSL_VALIDATOR
);
960 private class UploadFinishReceiver
extends BroadcastReceiver
{
962 * Once the file upload has finished -> update view
963 * @author David A. Velasco
964 * {@link BroadcastReceiver} to enable upload feedback in UI
967 public void onReceive(Context context
, Intent intent
) {
968 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
969 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
970 boolean sameAccount
= accountName
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
);
971 boolean isDescendant
= (mCurrentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(mCurrentDir
.getRemotePath()));
972 if (sameAccount
&& isDescendant
) {
973 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
974 if (fileListFragment
!= null
) {
975 fileListFragment
.listDirectory();
984 * Once the file download has finished -> update view
986 private class DownloadFinishReceiver
extends BroadcastReceiver
{
988 public void onReceive(Context context
, Intent intent
) {
989 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
990 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
991 if (accountName
!= null
&& AccountUtils
.getCurrentOwnCloudAccount(context
) != null
) {
992 boolean sameAccount
= accountName
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
);
993 boolean isDescendant
= (mCurrentDir
!= null
) && (downloadedRemotePath
!= null
) && (downloadedRemotePath
.startsWith(mCurrentDir
.getRemotePath()));
994 if (sameAccount
&& isDescendant
) {
995 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
996 if (fileListFragment
!= null
) {
997 fileListFragment
.listDirectory();
998 if ( mWaitingToPreview
!= null
&&
999 mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
) &&
1000 intent
.getAction().equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
) ) {
1002 Fragment fragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1003 if (fragment
!= null
&& fragment
instanceof FileDetailFragment
) {
1004 FileDetailFragment detailFragment
= (FileDetailFragment
) fragment
;
1005 if (detailFragment
.getFile().getRemotePath().equals(downloadedRemotePath
)) {
1006 detailFragment
.listenForTransferProgress();
1007 detailFragment
.updateFileDetails(true
);
1024 public DataStorageManager
getStorageManager() {
1025 return mStorageManager
;
1033 public void onDirectoryClick(OCFile directory
) {
1034 pushDirname(directory
);
1035 ActionBar actionBar
= getSupportActionBar();
1036 actionBar
.setDisplayHomeAsUpEnabled(true
);
1039 // Resets the FileDetailsFragment on Tablets so that it always displays
1040 Fragment fileFragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1041 if (fileFragment
!= null
&& (fileFragment
instanceof FilePreviewFragment
|| !((FileDetailFragment
) fileFragment
).isEmpty())) {
1042 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1043 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
1044 transaction
.commit();
1054 public void onFileClick(OCFile file
) {
1056 // If we are on a large device -> update fragment
1058 // 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'
1059 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1060 if (file
!= null
&& FilePreviewFragment
.canBePreviewed(file
)) {
1061 if (file
.isDown()) {
1062 transaction
.replace(R
.id
.file_details_container
, new FilePreviewFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
1064 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
1065 mWaitingToPreview
= file
;
1066 requestForDownload();
1069 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
1071 //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
1072 transaction
.commit();
1074 } else { // small or medium screen device -> new Activity
1075 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
1076 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_FILE
, file
);
1077 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
1078 startActivity(showDetailsIntent
);
1087 public OCFile
getInitialDirectory() {
1096 public void onFileStateChanged() {
1097 OCFileListFragment fileListFragment
= (OCFileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
1098 if (fileListFragment
!= null
) {
1099 fileListFragment
.listDirectory();
1108 public FileDownloaderBinder
getFileDownloaderBinder() {
1109 return mDownloaderBinder
;
1117 public FileUploaderBinder
getFileUploaderBinder() {
1118 return mUploaderBinder
;
1122 /** Defines callbacks for service binding, passed to bindService() */
1123 private class ListServiceConnection
implements ServiceConnection
{
1126 public void onServiceConnected(ComponentName component
, IBinder service
) {
1127 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1128 Log
.d(TAG
, "Download service connected");
1129 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1130 if (mWaitingToPreview
!= null
) {
1131 requestForDownload();
1134 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1135 Log
.d(TAG
, "Upload service connected");
1136 mUploaderBinder
= (FileUploaderBinder
) service
;
1140 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1141 if (mFileList
!= null
)
1142 mFileList
.listDirectory();
1144 Fragment fragment
= getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1145 if (fragment
!= null
&& fragment
instanceof FileDetailFragment
) {
1146 FileDetailFragment detailFragment
= (FileDetailFragment
)fragment
;
1147 detailFragment
.listenForTransferProgress();
1148 detailFragment
.updateFileDetails(false
);
1154 public void onServiceDisconnected(ComponentName component
) {
1155 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1156 Log
.d(TAG
, "Download service disconnected");
1157 mDownloaderBinder
= null
;
1158 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1159 Log
.d(TAG
, "Upload service disconnected");
1160 mUploaderBinder
= null
;
1168 * Launch an intent to request the PIN code to the user before letting him use the app
1170 private void requestPinCode() {
1171 boolean pinStart
= false
;
1172 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1173 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1175 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1176 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1183 public void onSavedCertificate() {
1184 startSynchronization();
1189 public void onFailedSavingCertificate() {
1190 showDialog(DIALOG_CERT_NOT_SAVED
);
1195 * Updates the view associated to the activity after the finish of some operation over files
1196 * in the current account.
1198 * @param operation Removal operation performed.
1199 * @param result Result of the removal.
1202 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1203 if (operation
instanceof RemoveFileOperation
) {
1204 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1206 } else if (operation
instanceof RenameFileOperation
) {
1207 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1209 } else if (operation
instanceof SynchronizeFileOperation
) {
1210 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1216 * Updates the view associated to the activity after the finish of an operation trying to remove a
1219 * @param operation Removal operation performed.
1220 * @param result Result of the removal.
1222 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1223 dismissDialog(DIALOG_SHORT_WAIT
);
1224 if (result
.isSuccess()) {
1225 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1227 OCFile removedFile
= operation
.getFile();
1229 FileFragment details
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1230 if (details
!= null
&& removedFile
.equals(details
.getFile())) {
1231 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1232 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
)); // empty FileDetailFragment
1233 transaction
.commit();
1236 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(mCurrentDir
)) {
1237 mFileList
.listDirectory();
1241 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1243 if (result
.isSslRecoverableException()) {
1244 mLastSslUntrustedServerResult
= result
;
1245 showDialog(DIALOG_SSL_VALIDATOR
);
1251 * Updates the view associated to the activity after the finish of an operation trying to rename a
1254 * @param operation Renaming operation performed.
1255 * @param result Result of the renaming.
1257 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1258 dismissDialog(DIALOG_SHORT_WAIT
);
1259 OCFile renamedFile
= operation
.getFile();
1260 if (result
.isSuccess()) {
1262 FileFragment details
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1263 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1264 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, AccountUtils
.getCurrentOwnCloudAccount(this));
1267 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(mCurrentDir
)) {
1268 mFileList
.listDirectory();
1272 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1273 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1275 // TODO throw again the new rename dialog
1277 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1279 if (result
.isSslRecoverableException()) {
1280 mLastSslUntrustedServerResult
= result
;
1281 showDialog(DIALOG_SSL_VALIDATOR
);
1288 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1289 dismissDialog(DIALOG_SHORT_WAIT
);
1290 OCFile syncedFile
= operation
.getLocalFile();
1291 if (!result
.isSuccess()) {
1292 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1293 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1294 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1295 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
1299 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1304 if (operation
.transferWasRequested()) {
1305 mFileList
.listDirectory();
1306 onTransferStateChanged(syncedFile
, true
, true
);
1309 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1320 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1321 /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1322 if (fileListFragment != null) {
1323 fileListFragment.listDirectory();
1326 FileFragment details
= (FileFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
1327 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1328 if (downloading
|| uploading
) {
1329 ((FileDetailFragment
)details
).updateFileDetails(file
, AccountUtils
.getCurrentOwnCloudAccount(this));
1331 ((FileDetailFragment
)details
).updateFileDetails(downloading
|| uploading
);
1339 public void showFragmentWithDetails(OCFile file
) {
1341 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1342 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
1343 transaction
.commit();
1346 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
1347 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_FILE
, file
);
1348 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
1349 showDetailsIntent
.putExtra(FileDetailActivity
.EXTRA_MODE
, FileDetailActivity
.MODE_DETAILS
);
1350 startActivity(showDetailsIntent
);
1356 public void notifySuccessfulDownload(OCFile file
, Intent intent
, boolean success
) {
1358 if (mWaitingToPreview
!= null
) {
1359 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
1360 transaction
.replace(R
.id
.file_details_container
, new FilePreviewFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
1361 transaction
.commit();
1362 mWaitingToPreview
= null
;
1365 mDownloadFinishReceiver
.onReceive(this, intent
);
1369 private void requestForDownload() {
1370 Account account
= AccountUtils
.getCurrentOwnCloudAccount(this);
1371 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1372 Intent i
= new Intent(this, FileDownloader
.class);
1373 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1374 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);