Merge pull request #7 from Mic92/master
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
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.
8 *
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.
13 *
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/>.
16 *
17 */
18
19 package com.owncloud.android.ui.activity;
20
21 import java.io.File;
22
23 import android.accounts.Account;
24 import android.app.AlertDialog;
25 import android.app.ProgressDialog;
26 import android.app.AlertDialog.Builder;
27 import android.app.Dialog;
28 import android.content.BroadcastReceiver;
29 import android.content.ComponentName;
30 import android.content.ContentResolver;
31 import android.content.Context;
32 import android.content.DialogInterface;
33 import android.content.DialogInterface.OnClickListener;
34 import android.content.Intent;
35 import android.content.IntentFilter;
36 import android.content.ServiceConnection;
37 import android.content.SharedPreferences;
38 import android.content.pm.PackageInfo;
39 import android.content.pm.PackageManager.NameNotFoundException;
40 import android.content.res.Resources.NotFoundException;
41 import android.database.Cursor;
42 import android.graphics.Bitmap;
43 import android.graphics.drawable.BitmapDrawable;
44 import android.net.Uri;
45 import android.os.Bundle;
46 import android.os.Handler;
47 import android.os.IBinder;
48 import android.preference.PreferenceManager;
49 import android.provider.MediaStore;
50 import android.support.v4.app.FragmentTransaction;
51 import android.util.Log;
52 import android.view.View;
53 import android.view.ViewGroup;
54 import android.widget.ArrayAdapter;
55 import android.widget.EditText;
56 import android.widget.TextView;
57 import android.widget.Toast;
58
59 import com.actionbarsherlock.app.ActionBar;
60 import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
61 import com.actionbarsherlock.app.SherlockFragmentActivity;
62 import com.actionbarsherlock.view.Menu;
63 import com.actionbarsherlock.view.MenuInflater;
64 import com.actionbarsherlock.view.MenuItem;
65 import com.actionbarsherlock.view.Window;
66 import com.owncloud.android.AccountUtils;
67 import com.owncloud.android.authenticator.AccountAuthenticator;
68 import com.owncloud.android.datamodel.DataStorageManager;
69 import com.owncloud.android.datamodel.FileDataStorageManager;
70 import com.owncloud.android.datamodel.OCFile;
71 import com.owncloud.android.files.services.FileDownloader;
72 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
73 import com.owncloud.android.files.services.FileObserverService;
74 import com.owncloud.android.files.services.FileUploader;
75 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
76 import com.owncloud.android.network.OwnCloudClientUtils;
77 import com.owncloud.android.operations.OnRemoteOperationListener;
78 import com.owncloud.android.operations.RemoteOperation;
79 import com.owncloud.android.operations.RemoteOperationResult;
80 import com.owncloud.android.operations.RemoveFileOperation;
81 import com.owncloud.android.operations.RenameFileOperation;
82 import com.owncloud.android.operations.SynchronizeFileOperation;
83 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
84 import com.owncloud.android.syncadapter.FileSyncService;
85 import com.owncloud.android.ui.dialog.SslValidatorDialog;
86 import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;
87 import com.owncloud.android.ui.fragment.FileDetailFragment;
88 import com.owncloud.android.ui.fragment.OCFileListFragment;
89
90 import com.owncloud.android.R;
91 import eu.alefzero.webdav.WebdavClient;
92
93 /**
94 * Displays, what files the user has available in his ownCloud.
95 *
96 * @author Bartek Przybylski
97 *
98 */
99
100 public class FileDisplayActivity extends SherlockFragmentActivity implements
101 OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener {
102
103 private ArrayAdapter<String> mDirectories;
104 private OCFile mCurrentDir = null;
105 private OCFile mCurrentFile = null;
106
107 private DataStorageManager mStorageManager;
108 private SyncBroadcastReceiver mSyncBroadcastReceiver;
109 private UploadFinishReceiver mUploadFinishReceiver;
110 private DownloadFinishReceiver mDownloadFinishReceiver;
111 private FileDownloaderBinder mDownloaderBinder = null;
112 private FileUploaderBinder mUploaderBinder = null;
113 private ServiceConnection mDownloadConnection = null, mUploadConnection = null;
114 private RemoteOperationResult mLastSslUntrustedServerResult = null;
115
116 private OCFileListFragment mFileList;
117
118 private boolean mDualPane;
119
120 private static final int DIALOG_SETUP_ACCOUNT = 0;
121 private static final int DIALOG_CREATE_DIR = 1;
122 private static final int DIALOG_ABOUT_APP = 2;
123 public static final int DIALOG_SHORT_WAIT = 3;
124 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 4;
125 private static final int DIALOG_SSL_VALIDATOR = 5;
126 private static final int DIALOG_CERT_NOT_SAVED = 6;
127
128
129 private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
130 private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
131
132 private static final String TAG = "FileDisplayActivity";
133
134 private static int[] mMenuIdentifiersToPatch = {R.id.about_app};
135
136 @Override
137 public void onCreate(Bundle savedInstanceState) {
138 Log.d(getClass().toString(), "onCreate() start");
139 super.onCreate(savedInstanceState);
140
141 /// Load of parameters from received intent
142 mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent
143 Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);
144 if (account != null)
145 AccountUtils.setCurrentOwnCloudAccount(this, account.name);
146
147 /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
148 if(savedInstanceState != null) {
149 // TODO - test if savedInstanceState should take precedence over file in the intent ALWAYS (now), NEVER, or SOME TIMES
150 mCurrentDir = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);
151 }
152
153 if (!AccountUtils.accountsAreSetup(this)) {
154 /// no account available: FORCE ACCOUNT CREATION
155 mStorageManager = null;
156 createFirstAccount();
157
158 } else { /// at least an account is available
159
160 initDataFromCurrentAccount(); // it checks mCurrentDir and mCurrentFile with the current account
161
162 }
163
164 mUploadConnection = new ListServiceConnection();
165 mDownloadConnection = new ListServiceConnection();
166 bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);
167 bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
168
169 // PIN CODE request ; best location is to decide, let's try this first
170 if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {
171 requestPinCode();
172 }
173
174 // file observer
175 Intent observer_intent = new Intent(this, FileObserverService.class);
176 observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST);
177 startService(observer_intent);
178
179
180 /// USER INTERFACE
181 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
182
183 // Drop-down navigation
184 mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
185 OCFile currFile = mCurrentDir;
186 while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
187 mDirectories.add(currFile.getFileName());
188 currFile = mStorageManager.getFileById(currFile.getParentId());
189 }
190 mDirectories.add(OCFile.PATH_SEPARATOR);
191
192 // Inflate and set the layout view
193 setContentView(R.layout.files);
194 mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
195 mDualPane = (findViewById(R.id.file_details_container) != null);
196 if (mDualPane) {
197 initFileDetailsInDualPane();
198 }
199
200 // Action bar setup
201 ActionBar actionBar = getSupportActionBar();
202 actionBar.setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation
203 actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getParentId() != 0);
204 actionBar.setDisplayShowTitleEnabled(false);
205 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
206 actionBar.setListNavigationCallbacks(mDirectories, this);
207 setSupportProgressBarIndeterminateVisibility(false); // always AFTER setContentView(...) ; to workaround bug in its implementation
208
209 Log.d(getClass().toString(), "onCreate() end");
210 }
211
212
213 /**
214 * Launches the account creation activity. To use when no ownCloud account is available
215 */
216 private void createFirstAccount() {
217 Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
218 intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });
219 startActivity(intent); // the new activity won't be created until this.onStart() and this.onResume() are finished;
220 }
221
222
223 /**
224 * Load of state dependent of the existence of an ownCloud account
225 */
226 private void initDataFromCurrentAccount() {
227 /// Storage manager initialization - access to local database
228 mStorageManager = new FileDataStorageManager(
229 AccountUtils.getCurrentOwnCloudAccount(this),
230 getContentResolver());
231
232 /// Check if mCurrentDir is a directory
233 if(mCurrentDir != null && !mCurrentDir.isDirectory()) {
234 mCurrentFile = mCurrentDir;
235 mCurrentDir = mStorageManager.getFileById(mCurrentDir.getParentId());
236 }
237
238 /// Check if mCurrentDir and mCurrentFile are in the current account, and update them
239 if (mCurrentDir != null) {
240 mCurrentDir = mStorageManager.getFileByPath(mCurrentDir.getRemotePath()); // mCurrentDir == null if it is not in the current account
241 }
242 if (mCurrentFile != null) {
243 if (mCurrentFile.fileExists()) {
244 mCurrentFile = mStorageManager.getFileByPath(mCurrentFile.getRemotePath()); // mCurrentFile == null if it is not in the current account
245 } // 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
246 }
247
248 /// Default to root if mCurrentDir was not found
249 if (mCurrentDir == null) {
250 mCurrentDir = mStorageManager.getFileByPath("/"); // will be NULL if the database was never synchronized
251 }
252 }
253
254
255 private void initFileDetailsInDualPane() {
256 if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {
257 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
258 if (mCurrentFile != null) {
259 transaction.replace(R.id.file_details_container, new FileDetailFragment(mCurrentFile, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG); // empty FileDetailFragment
260 mCurrentFile = null;
261 } else {
262 transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
263 }
264 transaction.commit();
265 }
266 }
267
268
269 @Override
270 public void onDestroy() {
271 super.onDestroy();
272 if (mDownloadConnection != null)
273 unbindService(mDownloadConnection);
274 if (mUploadConnection != null)
275 unbindService(mUploadConnection);
276 }
277
278
279 @Override
280 public boolean onCreateOptionsMenu(Menu menu) {
281 MenuInflater inflater = getSherlock().getMenuInflater();
282 inflater.inflate(R.menu.menu, menu);
283
284 patchHiddenAccents(menu);
285
286 return true;
287 }
288
289 /**
290 * 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>
291 *
292 * @param menu Menu to patch
293 */
294 private void patchHiddenAccents(Menu menu) {
295 for (int i = 0; i < mMenuIdentifiersToPatch.length ; i++) {
296 MenuItem aboutItem = menu.findItem(mMenuIdentifiersToPatch[i]);
297 if (aboutItem != null && aboutItem.getIcon() instanceof BitmapDrawable) {
298 // Clip off the bottom three (density independent) pixels of transparent padding
299 Bitmap original = ((BitmapDrawable) aboutItem.getIcon()).getBitmap();
300 float scale = getResources().getDisplayMetrics().density;
301 int clippedHeight = (int) (original.getHeight() - (3 * scale));
302 Bitmap scaled = Bitmap.createBitmap(original, 0, 0, original.getWidth(), clippedHeight);
303 aboutItem.setIcon(new BitmapDrawable(getResources(), scaled));
304 }
305 }
306 }
307
308
309 @Override
310 public boolean onOptionsItemSelected(MenuItem item) {
311 boolean retval = true;
312 switch (item.getItemId()) {
313 case R.id.createDirectoryItem: {
314 showDialog(DIALOG_CREATE_DIR);
315 break;
316 }
317 case R.id.startSync: {
318 startSynchronization();
319 break;
320 }
321 case R.id.action_upload: {
322 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE);
323 break;
324 }
325 case R.id.action_settings: {
326 Intent settingsIntent = new Intent(this, Preferences.class);
327 startActivity(settingsIntent);
328 break;
329 }
330 case R.id.about_app : {
331 showDialog(DIALOG_ABOUT_APP);
332 break;
333 }
334 case android.R.id.home: {
335 if(mCurrentDir != null && mCurrentDir.getParentId() != 0){
336 onBackPressed();
337 }
338 break;
339 }
340 default:
341 retval = super.onOptionsItemSelected(item);
342 }
343 return retval;
344 }
345
346 private void startSynchronization() {
347 ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account
348 Bundle bundle = new Bundle();
349 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
350 ContentResolver.requestSync(
351 AccountUtils.getCurrentOwnCloudAccount(this),
352 AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);
353 }
354
355
356 @Override
357 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
358 int i = itemPosition;
359 while (i-- != 0) {
360 onBackPressed();
361 }
362 // the next operation triggers a new call to this method, but it's necessary to
363 // ensure that the name exposed in the action bar is the current directory when the
364 // user selected it in the navigation list
365 if (itemPosition != 0)
366 getSupportActionBar().setSelectedNavigationItem(0);
367 return true;
368 }
369
370 /**
371 * Called, when the user selected something for uploading
372 */
373 public void onActivityResult(int requestCode, int resultCode, Intent data) {
374
375 if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && resultCode == RESULT_OK) {
376 requestSimpleUpload(data);
377
378 } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && resultCode == RESULT_OK) {
379 requestMultipleUpload(data);
380
381 }
382 }
383
384 private void requestMultipleUpload(Intent data) {
385 String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
386 if (filePaths != null) {
387 String[] remotePaths = new String[filePaths.length];
388 String remotePathBase = "";
389 for (int j = mDirectories.getCount() - 2; j >= 0; --j) {
390 remotePathBase += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);
391 }
392 if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR))
393 remotePathBase += OCFile.PATH_SEPARATOR;
394 for (int j = 0; j< remotePaths.length; j++) {
395 remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
396 }
397
398 Intent i = new Intent(this, FileUploader.class);
399 i.putExtra(FileUploader.KEY_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
400 i.putExtra(FileUploader.KEY_LOCAL_FILE, filePaths);
401 i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
402 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
403 startService(i);
404
405 } else {
406 Log.d("FileDisplay", "User clicked on 'Update' with no selection");
407 Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected), Toast.LENGTH_LONG);
408 t.show();
409 return;
410 }
411 }
412
413
414 private void requestSimpleUpload(Intent data) {
415 String filepath = null;
416 try {
417 Uri selectedImageUri = data.getData();
418
419 String filemanagerstring = selectedImageUri.getPath();
420 String selectedImagePath = getPath(selectedImageUri);
421
422 if (selectedImagePath != null)
423 filepath = selectedImagePath;
424 else
425 filepath = filemanagerstring;
426
427 } catch (Exception e) {
428 Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);
429 e.printStackTrace();
430
431 } finally {
432 if (filepath == null) {
433 Log.e("FileDisplay", "Couldnt resolve path to file");
434 Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);
435 t.show();
436 return;
437 }
438 }
439
440 Intent i = new Intent(this, FileUploader.class);
441 i.putExtra(FileUploader.KEY_ACCOUNT,
442 AccountUtils.getCurrentOwnCloudAccount(this));
443 String remotepath = new String();
444 for (int j = mDirectories.getCount() - 2; j >= 0; --j) {
445 remotepath += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);
446 }
447 if (!remotepath.endsWith(OCFile.PATH_SEPARATOR))
448 remotepath += OCFile.PATH_SEPARATOR;
449 remotepath += new File(filepath).getName();
450
451 i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);
452 i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);
453 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
454 startService(i);
455 }
456
457
458 @Override
459 public void onBackPressed() {
460 if (mDirectories.getCount() <= 1) {
461 finish();
462 return;
463 }
464 popDirname();
465 mFileList.onNavigateUp();
466 mCurrentDir = mFileList.getCurrentFile();
467
468 if (mDualPane) {
469 // Resets the FileDetailsFragment on Tablets so that it always displays
470 FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
471 if (fileDetails != null && !fileDetails.isEmpty()) {
472 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
473 transaction.remove(fileDetails);
474 transaction.add(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG);
475 transaction.commit();
476 }
477 }
478
479 if(mCurrentDir.getParentId() == 0){
480 ActionBar actionBar = getSupportActionBar();
481 actionBar.setDisplayHomeAsUpEnabled(false);
482 }
483 }
484
485 @Override
486 protected void onSaveInstanceState(Bundle outState) {
487 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
488 Log.d(getClass().toString(), "onSaveInstanceState() start");
489 super.onSaveInstanceState(outState);
490 outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir);
491 if (mDualPane) {
492 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
493 if (fragment != null) {
494 OCFile file = fragment.getDisplayedFile();
495 if (file != null) {
496 outState.putParcelable(FileDetailFragment.EXTRA_FILE, file);
497 }
498 }
499 }
500 Log.d(getClass().toString(), "onSaveInstanceState() end");
501 }
502
503 @Override
504 protected void onResume() {
505 Log.d(getClass().toString(), "onResume() start");
506 super.onResume();
507
508 if (AccountUtils.accountsAreSetup(this)) {
509
510 if (mStorageManager == null) {
511 // this is necessary for handling the come back to FileDisplayActivity when the first ownCloud account is created
512 initDataFromCurrentAccount();
513 if (mDualPane) {
514 initFileDetailsInDualPane();
515 }
516 }
517
518 // Listen for sync messages
519 IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);
520 mSyncBroadcastReceiver = new SyncBroadcastReceiver();
521 registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
522
523 // Listen for upload messages
524 IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);
525 mUploadFinishReceiver = new UploadFinishReceiver();
526 registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
527
528 // Listen for download messages
529 IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
530 mDownloadFinishReceiver = new DownloadFinishReceiver();
531 registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
532
533 // List current directory
534 mFileList.listDirectory(mCurrentDir); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
535
536 } else {
537
538 mStorageManager = null; // an invalid object will be there if all the ownCloud accounts are removed
539 showDialog(DIALOG_SETUP_ACCOUNT);
540
541 }
542 Log.d(getClass().toString(), "onResume() end");
543 }
544
545
546 @Override
547 protected void onPause() {
548 Log.d(getClass().toString(), "onPause() start");
549 super.onPause();
550 if (mSyncBroadcastReceiver != null) {
551 unregisterReceiver(mSyncBroadcastReceiver);
552 mSyncBroadcastReceiver = null;
553 }
554 if (mUploadFinishReceiver != null) {
555 unregisterReceiver(mUploadFinishReceiver);
556 mUploadFinishReceiver = null;
557 }
558 if (mDownloadFinishReceiver != null) {
559 unregisterReceiver(mDownloadFinishReceiver);
560 mDownloadFinishReceiver = null;
561 }
562 if (!AccountUtils.accountsAreSetup(this)) {
563 dismissDialog(DIALOG_SETUP_ACCOUNT);
564 }
565
566 Log.d(getClass().toString(), "onPause() end");
567 }
568
569
570 @Override
571 protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
572 if (id == DIALOG_SSL_VALIDATOR && mLastSslUntrustedServerResult != null) {
573 ((SslValidatorDialog)dialog).updateResult(mLastSslUntrustedServerResult);
574 }
575 }
576
577
578 @Override
579 protected Dialog onCreateDialog(int id) {
580 Dialog dialog = null;
581 AlertDialog.Builder builder;
582 switch (id) {
583 case DIALOG_SETUP_ACCOUNT: {
584 builder = new AlertDialog.Builder(this);
585 builder.setTitle(R.string.main_tit_accsetup);
586 builder.setMessage(R.string.main_wrn_accsetup);
587 builder.setCancelable(false);
588 builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
589 public void onClick(DialogInterface dialog, int which) {
590 createFirstAccount();
591 dialog.dismiss();
592 }
593 });
594 builder.setNegativeButton(R.string.common_exit, new OnClickListener() {
595 public void onClick(DialogInterface dialog, int which) {
596 dialog.dismiss();
597 finish();
598 }
599 });
600 //builder.setNegativeButton(android.R.string.cancel, this);
601 dialog = builder.create();
602 break;
603 }
604 case DIALOG_ABOUT_APP: {
605 builder = new AlertDialog.Builder(this);
606 builder.setTitle(getString(R.string.about_title));
607 PackageInfo pkg;
608 try {
609 pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
610 builder.setMessage(String.format(getString(R.string.about_message), pkg.versionName));
611 builder.setIcon(android.R.drawable.ic_menu_info_details);
612 dialog = builder.create();
613 } catch (NameNotFoundException e) {
614 builder = null;
615 dialog = null;
616 Log.e(TAG, "Error while showing about dialog", e);
617 }
618 break;
619 }
620 case DIALOG_CREATE_DIR: {
621 builder = new Builder(this);
622 final EditText dirNameInput = new EditText(getBaseContext());
623 builder.setView(dirNameInput);
624 builder.setTitle(R.string.uploader_info_dirname);
625 int typed_color = getResources().getColor(R.color.setup_text_typed);
626 dirNameInput.setTextColor(typed_color);
627 builder.setPositiveButton(android.R.string.ok,
628 new OnClickListener() {
629 public void onClick(DialogInterface dialog, int which) {
630 String directoryName = dirNameInput.getText().toString();
631 if (directoryName.trim().length() == 0) {
632 dialog.cancel();
633 return;
634 }
635
636 // Figure out the path where the dir needs to be created
637 String path;
638 if (mCurrentDir == null) {
639 // this is just a patch; we should ensure that mCurrentDir never is null
640 if (!mStorageManager.fileExists(OCFile.PATH_SEPARATOR)) {
641 OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
642 mStorageManager.saveFile(file);
643 }
644 mCurrentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
645 }
646 path = FileDisplayActivity.this.mCurrentDir.getRemotePath();
647
648 // Create directory
649 path += directoryName + OCFile.PATH_SEPARATOR;
650 Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));
651 thread.start();
652
653 dialog.dismiss();
654
655 showDialog(DIALOG_SHORT_WAIT);
656 }
657 });
658 builder.setNegativeButton(R.string.common_cancel,
659 new OnClickListener() {
660 public void onClick(DialogInterface dialog, int which) {
661 dialog.cancel();
662 }
663 });
664 dialog = builder.create();
665 break;
666 }
667 case DIALOG_SHORT_WAIT: {
668 ProgressDialog working_dialog = new ProgressDialog(this);
669 working_dialog.setMessage(getResources().getString(
670 R.string.wait_a_moment));
671 working_dialog.setIndeterminate(true);
672 working_dialog.setCancelable(false);
673 dialog = working_dialog;
674 break;
675 }
676 case DIALOG_CHOOSE_UPLOAD_SOURCE: {
677 final String [] items = { getString(R.string.actionbar_upload_files),
678 getString(R.string.actionbar_upload_from_apps) };
679 builder = new AlertDialog.Builder(this);
680 builder.setTitle(R.string.actionbar_upload);
681 builder.setItems(items, new DialogInterface.OnClickListener() {
682 public void onClick(DialogInterface dialog, int item) {
683 if (item == 0) {
684 //if (!mDualPane) {
685 Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
686 startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
687 //} else {
688 // TODO create and handle new fragment LocalFileListFragment
689 //}
690 } else if (item == 1) {
691 Intent action = new Intent(Intent.ACTION_GET_CONTENT);
692 action = action.setType("*/*")
693 .addCategory(Intent.CATEGORY_OPENABLE);
694 startActivityForResult(
695 Intent.createChooser(action, getString(R.string.upload_chooser_title)),
696 ACTION_SELECT_CONTENT_FROM_APPS);
697 }
698 }
699 });
700 dialog = builder.create();
701 break;
702 }
703 case DIALOG_SSL_VALIDATOR: {
704 dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
705 break;
706 }
707 case DIALOG_CERT_NOT_SAVED: {
708 builder = new AlertDialog.Builder(this);
709 builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
710 builder.setCancelable(false);
711 builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
712 @Override
713 public void onClick(DialogInterface dialog, int which) {
714 dialog.dismiss();
715 };
716 });
717 dialog = builder.create();
718 break;
719 }
720 default:
721 dialog = null;
722 }
723
724 return dialog;
725 }
726
727
728 /**
729 * Translates a content URI of an image to a physical path
730 * on the disk
731 * @param uri The URI to resolve
732 * @return The path to the image or null if it could not be found
733 */
734 public String getPath(Uri uri) {
735 String[] projection = { MediaStore.Images.Media.DATA };
736 Cursor cursor = managedQuery(uri, projection, null, null, null);
737 if (cursor != null) {
738 int column_index = cursor
739 .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
740 cursor.moveToFirst();
741 return cursor.getString(column_index);
742 }
743 return null;
744 }
745
746 /**
747 * Pushes a directory to the drop down list
748 * @param directory to push
749 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
750 */
751 public void pushDirname(OCFile directory) {
752 if(!directory.isDirectory()){
753 throw new IllegalArgumentException("Only directories may be pushed!");
754 }
755 mDirectories.insert(directory.getFileName(), 0);
756 mCurrentDir = directory;
757 }
758
759 /**
760 * Pops a directory name from the drop down list
761 * @return True, unless the stack is empty
762 */
763 public boolean popDirname() {
764 mDirectories.remove(mDirectories.getItem(0));
765 return !mDirectories.isEmpty();
766 }
767
768 private class DirectoryCreator implements Runnable {
769 private String mTargetPath;
770 private Account mAccount;
771 private Handler mHandler;
772
773 public DirectoryCreator(String targetPath, Account account, Handler handler) {
774 mTargetPath = targetPath;
775 mAccount = account;
776 mHandler = handler;
777 }
778
779 @Override
780 public void run() {
781 WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
782 boolean created = wdc.createDirectory(mTargetPath);
783 if (created) {
784 mHandler.post(new Runnable() {
785 @Override
786 public void run() {
787 dismissDialog(DIALOG_SHORT_WAIT);
788
789 // Save new directory in local database
790 OCFile newDir = new OCFile(mTargetPath);
791 newDir.setMimetype("DIR");
792 newDir.setParentId(mCurrentDir.getFileId());
793 mStorageManager.saveFile(newDir);
794
795 // Display the new folder right away
796 mFileList.listDirectory();
797 }
798 });
799
800 } else {
801 mHandler.post(new Runnable() {
802 @Override
803 public void run() {
804 dismissDialog(DIALOG_SHORT_WAIT);
805 try {
806 Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG);
807 msg.show();
808
809 } catch (NotFoundException e) {
810 Log.e(TAG, "Error while trying to show fail message " , e);
811 }
812 }
813 });
814 }
815 }
816
817 }
818
819 // Custom array adapter to override text colors
820 private class CustomArrayAdapter<T> extends ArrayAdapter<T> {
821
822 public CustomArrayAdapter(FileDisplayActivity ctx, int view) {
823 super(ctx, view);
824 }
825
826 public View getView(int position, View convertView, ViewGroup parent) {
827 View v = super.getView(position, convertView, parent);
828
829 ((TextView) v).setTextColor(getResources().getColorStateList(
830 android.R.color.white));
831 return v;
832 }
833
834 public View getDropDownView(int position, View convertView,
835 ViewGroup parent) {
836 View v = super.getDropDownView(position, convertView, parent);
837
838 ((TextView) v).setTextColor(getResources().getColorStateList(
839 android.R.color.white));
840
841 return v;
842 }
843
844 }
845
846 private class SyncBroadcastReceiver extends BroadcastReceiver {
847
848 /**
849 * {@link BroadcastReceiver} to enable syncing feedback in UI
850 */
851 @Override
852 public void onReceive(Context context, Intent intent) {
853 boolean inProgress = intent.getBooleanExtra(
854 FileSyncService.IN_PROGRESS, false);
855 String accountName = intent
856 .getStringExtra(FileSyncService.ACCOUNT_NAME);
857
858 Log.d("FileDisplay", "sync of account " + accountName
859 + " is in_progress: " + inProgress);
860
861 if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) {
862
863 String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH);
864
865 boolean fillBlankRoot = false;
866 if (mCurrentDir == null) {
867 mCurrentDir = mStorageManager.getFileByPath("/");
868 fillBlankRoot = (mCurrentDir != null);
869 }
870
871 if ((synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath)))
872 || fillBlankRoot ) {
873 if (!fillBlankRoot)
874 mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath);
875 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()
876 .findFragmentById(R.id.fileList);
877 if (fileListFragment != null) {
878 fileListFragment.listDirectory(mCurrentDir);
879 }
880 }
881
882 setSupportProgressBarIndeterminateVisibility(inProgress);
883
884 }
885
886 RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);
887 if (synchResult != null) {
888 if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
889 mLastSslUntrustedServerResult = synchResult;
890 showDialog(DIALOG_SSL_VALIDATOR);
891 }
892 }
893 }
894 }
895
896
897 private class UploadFinishReceiver extends BroadcastReceiver {
898 /**
899 * Once the file upload has finished -> update view
900 * @author David A. Velasco
901 * {@link BroadcastReceiver} to enable upload feedback in UI
902 */
903 @Override
904 public void onReceive(Context context, Intent intent) {
905 String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
906 String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
907 boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);
908 boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath()));
909 if (sameAccount && isDescendant) {
910 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
911 if (fileListFragment != null) {
912 fileListFragment.listDirectory();
913 }
914 }
915 }
916
917 }
918
919
920 /**
921 * Once the file download has finished -> update view
922 */
923 private class DownloadFinishReceiver extends BroadcastReceiver {
924 @Override
925 public void onReceive(Context context, Intent intent) {
926 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
927 String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
928 boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);
929 boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath()));
930 if (sameAccount && isDescendant) {
931 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
932 if (fileListFragment != null) {
933 fileListFragment.listDirectory();
934 }
935 }
936 }
937 }
938
939
940
941
942 /**
943 * {@inheritDoc}
944 */
945 @Override
946 public DataStorageManager getStorageManager() {
947 return mStorageManager;
948 }
949
950
951 /**
952 * {@inheritDoc}
953 */
954 @Override
955 public void onDirectoryClick(OCFile directory) {
956 pushDirname(directory);
957 ActionBar actionBar = getSupportActionBar();
958 actionBar.setDisplayHomeAsUpEnabled(true);
959
960 if (mDualPane) {
961 // Resets the FileDetailsFragment on Tablets so that it always displays
962 FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
963 if (fileDetails != null && !fileDetails.isEmpty()) {
964 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
965 transaction.remove(fileDetails);
966 transaction.add(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG);
967 transaction.commit();
968 }
969 }
970 }
971
972
973 /**
974 * {@inheritDoc}
975 */
976 @Override
977 public void onFileClick(OCFile file) {
978
979 // If we are on a large device -> update fragment
980 if (mDualPane) {
981 // 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'
982 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
983 transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);
984 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
985 transaction.commit();
986
987 } else { // small or medium screen device -> new Activity
988 Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
989 showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
990 showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
991 startActivity(showDetailsIntent);
992 }
993 }
994
995
996 /**
997 * {@inheritDoc}
998 */
999 @Override
1000 public OCFile getInitialDirectory() {
1001 return mCurrentDir;
1002 }
1003
1004
1005 /**
1006 * {@inheritDoc}
1007 */
1008 @Override
1009 public void onFileStateChanged() {
1010 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1011 if (fileListFragment != null) {
1012 fileListFragment.listDirectory();
1013 }
1014 }
1015
1016
1017 /**
1018 * {@inheritDoc}
1019 */
1020 @Override
1021 public FileDownloaderBinder getFileDownloaderBinder() {
1022 return mDownloaderBinder;
1023 }
1024
1025
1026 /**
1027 * {@inheritDoc}
1028 */
1029 @Override
1030 public FileUploaderBinder getFileUploaderBinder() {
1031 return mUploaderBinder;
1032 }
1033
1034
1035 /** Defines callbacks for service binding, passed to bindService() */
1036 private class ListServiceConnection implements ServiceConnection {
1037
1038 @Override
1039 public void onServiceConnected(ComponentName component, IBinder service) {
1040 if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
1041 Log.d(TAG, "Download service connected");
1042 mDownloaderBinder = (FileDownloaderBinder) service;
1043 } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
1044 Log.d(TAG, "Upload service connected");
1045 mUploaderBinder = (FileUploaderBinder) service;
1046 } else {
1047 return;
1048 }
1049 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1050 if (mFileList != null)
1051 mFileList.listDirectory();
1052 if (mDualPane) {
1053 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1054 if (fragment != null)
1055 fragment.updateFileDetails(false);
1056 }
1057 }
1058
1059 @Override
1060 public void onServiceDisconnected(ComponentName component) {
1061 if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
1062 Log.d(TAG, "Download service disconnected");
1063 mDownloaderBinder = null;
1064 } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
1065 Log.d(TAG, "Upload service disconnected");
1066 mUploaderBinder = null;
1067 }
1068 }
1069 };
1070
1071
1072
1073 /**
1074 * Launch an intent to request the PIN code to the user before letting him use the app
1075 */
1076 private void requestPinCode() {
1077 boolean pinStart = false;
1078 SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
1079 pinStart = appPrefs.getBoolean("set_pincode", false);
1080 if (pinStart) {
1081 Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);
1082 i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
1083 startActivity(i);
1084 }
1085 }
1086
1087
1088 @Override
1089 public void onSavedCertificate() {
1090 startSynchronization();
1091 }
1092
1093
1094 @Override
1095 public void onFailedSavingCertificate() {
1096 showDialog(DIALOG_CERT_NOT_SAVED);
1097 }
1098
1099
1100 /**
1101 * Updates the view associated to the activity after the finish of some operation over files
1102 * in the current account.
1103 *
1104 * @param operation Removal operation performed.
1105 * @param result Result of the removal.
1106 */
1107 @Override
1108 public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
1109 if (operation instanceof RemoveFileOperation) {
1110 onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
1111
1112 } else if (operation instanceof RenameFileOperation) {
1113 onRenameFileOperationFinish((RenameFileOperation)operation, result);
1114
1115 } else if (operation instanceof SynchronizeFileOperation) {
1116 onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
1117 }
1118 }
1119
1120
1121 /**
1122 * Updates the view associated to the activity after the finish of an operation trying to remove a
1123 * file.
1124 *
1125 * @param operation Removal operation performed.
1126 * @param result Result of the removal.
1127 */
1128 private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
1129 dismissDialog(DIALOG_SHORT_WAIT);
1130 if (result.isSuccess()) {
1131 Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
1132 msg.show();
1133 OCFile removedFile = operation.getFile();
1134 if (mDualPane) {
1135 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1136 if (details != null && removedFile.equals(details.getDisplayedFile()) ) {
1137 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
1138 transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
1139 transaction.commit();
1140 }
1141 }
1142 if (mStorageManager.getFileById(removedFile.getParentId()).equals(mCurrentDir)) {
1143 mFileList.listDirectory();
1144 }
1145
1146 } else {
1147 Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG);
1148 msg.show();
1149 if (result.isSslRecoverableException()) {
1150 mLastSslUntrustedServerResult = result;
1151 showDialog(DIALOG_SSL_VALIDATOR);
1152 }
1153 }
1154 }
1155
1156 /**
1157 * Updates the view associated to the activity after the finish of an operation trying to rename a
1158 * file.
1159 *
1160 * @param operation Renaming operation performed.
1161 * @param result Result of the renaming.
1162 */
1163 private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
1164 dismissDialog(DIALOG_SHORT_WAIT);
1165 OCFile renamedFile = operation.getFile();
1166 if (result.isSuccess()) {
1167 if (mDualPane) {
1168 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1169 if (details != null && renamedFile.equals(details.getDisplayedFile()) ) {
1170 details.updateFileDetails(renamedFile, AccountUtils.getCurrentOwnCloudAccount(this));
1171 }
1172 }
1173 if (mStorageManager.getFileById(renamedFile.getParentId()).equals(mCurrentDir)) {
1174 mFileList.listDirectory();
1175 }
1176
1177 } else {
1178 if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
1179 Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
1180 msg.show();
1181 // TODO throw again the new rename dialog
1182 } else {
1183 Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
1184 msg.show();
1185 if (result.isSslRecoverableException()) {
1186 mLastSslUntrustedServerResult = result;
1187 showDialog(DIALOG_SSL_VALIDATOR);
1188 }
1189 }
1190 }
1191 }
1192
1193
1194 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
1195 dismissDialog(DIALOG_SHORT_WAIT);
1196 OCFile syncedFile = operation.getLocalFile();
1197 if (!result.isSuccess()) {
1198 if (result.getCode() == ResultCode.SYNC_CONFLICT) {
1199 Intent i = new Intent(this, ConflictsResolveActivity.class);
1200 i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);
1201 i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
1202 startActivity(i);
1203
1204 } else {
1205 Toast msg = Toast.makeText(this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG);
1206 msg.show();
1207 }
1208
1209 } else {
1210 if (operation.transferWasRequested()) {
1211 mFileList.listDirectory();
1212 onTransferStateChanged(syncedFile, true, true);
1213
1214 } else {
1215 Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
1216 msg.show();
1217 }
1218 }
1219 }
1220
1221
1222 /**
1223 * {@inheritDoc}
1224 */
1225 @Override
1226 public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
1227 /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1228 if (fileListFragment != null) {
1229 fileListFragment.listDirectory();
1230 }*/
1231 if (mDualPane) {
1232 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1233 if (details != null && file.equals(details.getDisplayedFile()) ) {
1234 if (downloading || uploading) {
1235 details.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));
1236 } else {
1237 details.updateFileDetails(downloading || uploading);
1238 }
1239 }
1240 }
1241 }
1242
1243
1244
1245
1246
1247 }