Fixed bug: toast message infinitely repeated
[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 String message = String.format(getString(R.string.common_exit), getString(R.string.app_name));
595 builder.setNegativeButton(message, new OnClickListener() {
596 public void onClick(DialogInterface dialog, int which) {
597 dialog.dismiss();
598 finish();
599 }
600 });
601 //builder.setNegativeButton(android.R.string.cancel, this);
602 dialog = builder.create();
603 break;
604 }
605 case DIALOG_ABOUT_APP: {
606 builder = new AlertDialog.Builder(this);
607 builder.setTitle(getString(R.string.about_title));
608 PackageInfo pkg;
609 try {
610 pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
611 builder.setMessage(String.format(getString(R.string.about_message), getString(R.string.app_name), pkg.versionName));
612 builder.setIcon(android.R.drawable.ic_menu_info_details);
613 dialog = builder.create();
614 } catch (NameNotFoundException e) {
615 builder = null;
616 dialog = null;
617 Log.e(TAG, "Error while showing about dialog", e);
618 }
619 break;
620 }
621 case DIALOG_CREATE_DIR: {
622 builder = new Builder(this);
623 final EditText dirNameInput = new EditText(getBaseContext());
624 builder.setView(dirNameInput);
625 builder.setTitle(R.string.uploader_info_dirname);
626 int typed_color = getResources().getColor(R.color.setup_text_typed);
627 dirNameInput.setTextColor(typed_color);
628 builder.setPositiveButton(android.R.string.ok,
629 new OnClickListener() {
630 public void onClick(DialogInterface dialog, int which) {
631 String directoryName = dirNameInput.getText().toString();
632 if (directoryName.trim().length() == 0) {
633 dialog.cancel();
634 return;
635 }
636
637 // Figure out the path where the dir needs to be created
638 String path;
639 if (mCurrentDir == null) {
640 // this is just a patch; we should ensure that mCurrentDir never is null
641 if (!mStorageManager.fileExists(OCFile.PATH_SEPARATOR)) {
642 OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
643 mStorageManager.saveFile(file);
644 }
645 mCurrentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
646 }
647 path = FileDisplayActivity.this.mCurrentDir.getRemotePath();
648
649 // Create directory
650 path += directoryName + OCFile.PATH_SEPARATOR;
651 Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));
652 thread.start();
653
654 dialog.dismiss();
655
656 showDialog(DIALOG_SHORT_WAIT);
657 }
658 });
659 builder.setNegativeButton(R.string.common_cancel,
660 new OnClickListener() {
661 public void onClick(DialogInterface dialog, int which) {
662 dialog.cancel();
663 }
664 });
665 dialog = builder.create();
666 break;
667 }
668 case DIALOG_SHORT_WAIT: {
669 ProgressDialog working_dialog = new ProgressDialog(this);
670 working_dialog.setMessage(getResources().getString(
671 R.string.wait_a_moment));
672 working_dialog.setIndeterminate(true);
673 working_dialog.setCancelable(false);
674 dialog = working_dialog;
675 break;
676 }
677 case DIALOG_CHOOSE_UPLOAD_SOURCE: {
678 final String [] items = { getString(R.string.actionbar_upload_files),
679 getString(R.string.actionbar_upload_from_apps) };
680 builder = new AlertDialog.Builder(this);
681 builder.setTitle(R.string.actionbar_upload);
682 builder.setItems(items, new DialogInterface.OnClickListener() {
683 public void onClick(DialogInterface dialog, int item) {
684 if (item == 0) {
685 //if (!mDualPane) {
686 Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
687 startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
688 //} else {
689 // TODO create and handle new fragment LocalFileListFragment
690 //}
691 } else if (item == 1) {
692 Intent action = new Intent(Intent.ACTION_GET_CONTENT);
693 action = action.setType("*/*")
694 .addCategory(Intent.CATEGORY_OPENABLE);
695 startActivityForResult(
696 Intent.createChooser(action, getString(R.string.upload_chooser_title)),
697 ACTION_SELECT_CONTENT_FROM_APPS);
698 }
699 }
700 });
701 dialog = builder.create();
702 break;
703 }
704 case DIALOG_SSL_VALIDATOR: {
705 dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
706 break;
707 }
708 case DIALOG_CERT_NOT_SAVED: {
709 builder = new AlertDialog.Builder(this);
710 builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
711 builder.setCancelable(false);
712 builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
713 @Override
714 public void onClick(DialogInterface dialog, int which) {
715 dialog.dismiss();
716 };
717 });
718 dialog = builder.create();
719 break;
720 }
721 default:
722 dialog = null;
723 }
724
725 return dialog;
726 }
727
728
729 /**
730 * Translates a content URI of an image to a physical path
731 * on the disk
732 * @param uri The URI to resolve
733 * @return The path to the image or null if it could not be found
734 */
735 public String getPath(Uri uri) {
736 String[] projection = { MediaStore.Images.Media.DATA };
737 Cursor cursor = managedQuery(uri, projection, null, null, null);
738 if (cursor != null) {
739 int column_index = cursor
740 .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
741 cursor.moveToFirst();
742 return cursor.getString(column_index);
743 }
744 return null;
745 }
746
747 /**
748 * Pushes a directory to the drop down list
749 * @param directory to push
750 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
751 */
752 public void pushDirname(OCFile directory) {
753 if(!directory.isDirectory()){
754 throw new IllegalArgumentException("Only directories may be pushed!");
755 }
756 mDirectories.insert(directory.getFileName(), 0);
757 mCurrentDir = directory;
758 }
759
760 /**
761 * Pops a directory name from the drop down list
762 * @return True, unless the stack is empty
763 */
764 public boolean popDirname() {
765 mDirectories.remove(mDirectories.getItem(0));
766 return !mDirectories.isEmpty();
767 }
768
769 private class DirectoryCreator implements Runnable {
770 private String mTargetPath;
771 private Account mAccount;
772 private Handler mHandler;
773
774 public DirectoryCreator(String targetPath, Account account, Handler handler) {
775 mTargetPath = targetPath;
776 mAccount = account;
777 mHandler = handler;
778 }
779
780 @Override
781 public void run() {
782 WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
783 boolean created = wdc.createDirectory(mTargetPath);
784 if (created) {
785 mHandler.post(new Runnable() {
786 @Override
787 public void run() {
788 dismissDialog(DIALOG_SHORT_WAIT);
789
790 // Save new directory in local database
791 OCFile newDir = new OCFile(mTargetPath);
792 newDir.setMimetype("DIR");
793 newDir.setParentId(mCurrentDir.getFileId());
794 mStorageManager.saveFile(newDir);
795
796 // Display the new folder right away
797 mFileList.listDirectory();
798 }
799 });
800
801 } else {
802 mHandler.post(new Runnable() {
803 @Override
804 public void run() {
805 dismissDialog(DIALOG_SHORT_WAIT);
806 try {
807 Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG);
808 msg.show();
809
810 } catch (NotFoundException e) {
811 Log.e(TAG, "Error while trying to show fail message " , e);
812 }
813 }
814 });
815 }
816 }
817
818 }
819
820 // Custom array adapter to override text colors
821 private class CustomArrayAdapter<T> extends ArrayAdapter<T> {
822
823 public CustomArrayAdapter(FileDisplayActivity ctx, int view) {
824 super(ctx, view);
825 }
826
827 public View getView(int position, View convertView, ViewGroup parent) {
828 View v = super.getView(position, convertView, parent);
829
830 ((TextView) v).setTextColor(getResources().getColorStateList(
831 android.R.color.white));
832 return v;
833 }
834
835 public View getDropDownView(int position, View convertView,
836 ViewGroup parent) {
837 View v = super.getDropDownView(position, convertView, parent);
838
839 ((TextView) v).setTextColor(getResources().getColorStateList(
840 android.R.color.white));
841
842 return v;
843 }
844
845 }
846
847 private class SyncBroadcastReceiver extends BroadcastReceiver {
848
849 /**
850 * {@link BroadcastReceiver} to enable syncing feedback in UI
851 */
852 @Override
853 public void onReceive(Context context, Intent intent) {
854 boolean inProgress = intent.getBooleanExtra(
855 FileSyncService.IN_PROGRESS, false);
856 String accountName = intent
857 .getStringExtra(FileSyncService.ACCOUNT_NAME);
858
859 Log.d("FileDisplay", "sync of account " + accountName
860 + " is in_progress: " + inProgress);
861
862 if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) {
863
864 String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH);
865
866 boolean fillBlankRoot = false;
867 if (mCurrentDir == null) {
868 mCurrentDir = mStorageManager.getFileByPath("/");
869 fillBlankRoot = (mCurrentDir != null);
870 }
871
872 if ((synchFolderRemotePath != null && mCurrentDir != null && (mCurrentDir.getRemotePath().equals(synchFolderRemotePath)))
873 || fillBlankRoot ) {
874 if (!fillBlankRoot)
875 mCurrentDir = getStorageManager().getFileByPath(synchFolderRemotePath);
876 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()
877 .findFragmentById(R.id.fileList);
878 if (fileListFragment != null) {
879 fileListFragment.listDirectory(mCurrentDir);
880 }
881 }
882
883 setSupportProgressBarIndeterminateVisibility(inProgress);
884 removeStickyBroadcast(intent);
885
886 }
887
888 RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);
889 if (synchResult != null) {
890 if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
891 mLastSslUntrustedServerResult = synchResult;
892 showDialog(DIALOG_SSL_VALIDATOR);
893 }
894 }
895 }
896 }
897
898
899 private class UploadFinishReceiver extends BroadcastReceiver {
900 /**
901 * Once the file upload has finished -> update view
902 * @author David A. Velasco
903 * {@link BroadcastReceiver} to enable upload feedback in UI
904 */
905 @Override
906 public void onReceive(Context context, Intent intent) {
907 String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
908 String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
909 boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);
910 boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath()));
911 if (sameAccount && isDescendant) {
912 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
913 if (fileListFragment != null) {
914 fileListFragment.listDirectory();
915 }
916 }
917 }
918
919 }
920
921
922 /**
923 * Once the file download has finished -> update view
924 */
925 private class DownloadFinishReceiver extends BroadcastReceiver {
926 @Override
927 public void onReceive(Context context, Intent intent) {
928 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
929 String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
930 boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);
931 boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath()));
932 if (sameAccount && isDescendant) {
933 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
934 if (fileListFragment != null) {
935 fileListFragment.listDirectory();
936 }
937 }
938 }
939 }
940
941
942
943
944 /**
945 * {@inheritDoc}
946 */
947 @Override
948 public DataStorageManager getStorageManager() {
949 return mStorageManager;
950 }
951
952
953 /**
954 * {@inheritDoc}
955 */
956 @Override
957 public void onDirectoryClick(OCFile directory) {
958 pushDirname(directory);
959 ActionBar actionBar = getSupportActionBar();
960 actionBar.setDisplayHomeAsUpEnabled(true);
961
962 if (mDualPane) {
963 // Resets the FileDetailsFragment on Tablets so that it always displays
964 FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
965 if (fileDetails != null && !fileDetails.isEmpty()) {
966 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
967 transaction.remove(fileDetails);
968 transaction.add(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG);
969 transaction.commit();
970 }
971 }
972 }
973
974
975 /**
976 * {@inheritDoc}
977 */
978 @Override
979 public void onFileClick(OCFile file) {
980
981 // If we are on a large device -> update fragment
982 if (mDualPane) {
983 // 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'
984 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
985 transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);
986 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
987 transaction.commit();
988
989 } else { // small or medium screen device -> new Activity
990 Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
991 showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
992 showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
993 startActivity(showDetailsIntent);
994 }
995 }
996
997
998 /**
999 * {@inheritDoc}
1000 */
1001 @Override
1002 public OCFile getInitialDirectory() {
1003 return mCurrentDir;
1004 }
1005
1006
1007 /**
1008 * {@inheritDoc}
1009 */
1010 @Override
1011 public void onFileStateChanged() {
1012 OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1013 if (fileListFragment != null) {
1014 fileListFragment.listDirectory();
1015 }
1016 }
1017
1018
1019 /**
1020 * {@inheritDoc}
1021 */
1022 @Override
1023 public FileDownloaderBinder getFileDownloaderBinder() {
1024 return mDownloaderBinder;
1025 }
1026
1027
1028 /**
1029 * {@inheritDoc}
1030 */
1031 @Override
1032 public FileUploaderBinder getFileUploaderBinder() {
1033 return mUploaderBinder;
1034 }
1035
1036
1037 /** Defines callbacks for service binding, passed to bindService() */
1038 private class ListServiceConnection implements ServiceConnection {
1039
1040 @Override
1041 public void onServiceConnected(ComponentName component, IBinder service) {
1042 if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
1043 Log.d(TAG, "Download service connected");
1044 mDownloaderBinder = (FileDownloaderBinder) service;
1045 } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
1046 Log.d(TAG, "Upload service connected");
1047 mUploaderBinder = (FileUploaderBinder) service;
1048 } else {
1049 return;
1050 }
1051 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1052 if (mFileList != null)
1053 mFileList.listDirectory();
1054 if (mDualPane) {
1055 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1056 if (fragment != null)
1057 fragment.updateFileDetails(false);
1058 }
1059 }
1060
1061 @Override
1062 public void onServiceDisconnected(ComponentName component) {
1063 if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
1064 Log.d(TAG, "Download service disconnected");
1065 mDownloaderBinder = null;
1066 } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
1067 Log.d(TAG, "Upload service disconnected");
1068 mUploaderBinder = null;
1069 }
1070 }
1071 };
1072
1073
1074
1075 /**
1076 * Launch an intent to request the PIN code to the user before letting him use the app
1077 */
1078 private void requestPinCode() {
1079 boolean pinStart = false;
1080 SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
1081 pinStart = appPrefs.getBoolean("set_pincode", false);
1082 if (pinStart) {
1083 Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);
1084 i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");
1085 startActivity(i);
1086 }
1087 }
1088
1089
1090 @Override
1091 public void onSavedCertificate() {
1092 startSynchronization();
1093 }
1094
1095
1096 @Override
1097 public void onFailedSavingCertificate() {
1098 showDialog(DIALOG_CERT_NOT_SAVED);
1099 }
1100
1101
1102 /**
1103 * Updates the view associated to the activity after the finish of some operation over files
1104 * in the current account.
1105 *
1106 * @param operation Removal operation performed.
1107 * @param result Result of the removal.
1108 */
1109 @Override
1110 public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
1111 if (operation instanceof RemoveFileOperation) {
1112 onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
1113
1114 } else if (operation instanceof RenameFileOperation) {
1115 onRenameFileOperationFinish((RenameFileOperation)operation, result);
1116
1117 } else if (operation instanceof SynchronizeFileOperation) {
1118 onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
1119 }
1120 }
1121
1122
1123 /**
1124 * Updates the view associated to the activity after the finish of an operation trying to remove a
1125 * file.
1126 *
1127 * @param operation Removal operation performed.
1128 * @param result Result of the removal.
1129 */
1130 private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
1131 dismissDialog(DIALOG_SHORT_WAIT);
1132 if (result.isSuccess()) {
1133 Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
1134 msg.show();
1135 OCFile removedFile = operation.getFile();
1136 if (mDualPane) {
1137 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1138 if (details != null && removedFile.equals(details.getDisplayedFile()) ) {
1139 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
1140 transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
1141 transaction.commit();
1142 }
1143 }
1144 if (mStorageManager.getFileById(removedFile.getParentId()).equals(mCurrentDir)) {
1145 mFileList.listDirectory();
1146 }
1147
1148 } else {
1149 Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG);
1150 msg.show();
1151 if (result.isSslRecoverableException()) {
1152 mLastSslUntrustedServerResult = result;
1153 showDialog(DIALOG_SSL_VALIDATOR);
1154 }
1155 }
1156 }
1157
1158 /**
1159 * Updates the view associated to the activity after the finish of an operation trying to rename a
1160 * file.
1161 *
1162 * @param operation Renaming operation performed.
1163 * @param result Result of the renaming.
1164 */
1165 private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
1166 dismissDialog(DIALOG_SHORT_WAIT);
1167 OCFile renamedFile = operation.getFile();
1168 if (result.isSuccess()) {
1169 if (mDualPane) {
1170 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1171 if (details != null && renamedFile.equals(details.getDisplayedFile()) ) {
1172 details.updateFileDetails(renamedFile, AccountUtils.getCurrentOwnCloudAccount(this));
1173 }
1174 }
1175 if (mStorageManager.getFileById(renamedFile.getParentId()).equals(mCurrentDir)) {
1176 mFileList.listDirectory();
1177 }
1178
1179 } else {
1180 if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
1181 Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
1182 msg.show();
1183 // TODO throw again the new rename dialog
1184 } else {
1185 Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
1186 msg.show();
1187 if (result.isSslRecoverableException()) {
1188 mLastSslUntrustedServerResult = result;
1189 showDialog(DIALOG_SSL_VALIDATOR);
1190 }
1191 }
1192 }
1193 }
1194
1195
1196 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
1197 dismissDialog(DIALOG_SHORT_WAIT);
1198 OCFile syncedFile = operation.getLocalFile();
1199 if (!result.isSuccess()) {
1200 if (result.getCode() == ResultCode.SYNC_CONFLICT) {
1201 Intent i = new Intent(this, ConflictsResolveActivity.class);
1202 i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);
1203 i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
1204 startActivity(i);
1205
1206 } else {
1207 Toast msg = Toast.makeText(this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG);
1208 msg.show();
1209 }
1210
1211 } else {
1212 if (operation.transferWasRequested()) {
1213 mFileList.listDirectory();
1214 onTransferStateChanged(syncedFile, true, true);
1215
1216 } else {
1217 Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
1218 msg.show();
1219 }
1220 }
1221 }
1222
1223
1224 /**
1225 * {@inheritDoc}
1226 */
1227 @Override
1228 public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
1229 /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
1230 if (fileListFragment != null) {
1231 fileListFragment.listDirectory();
1232 }*/
1233 if (mDualPane) {
1234 FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
1235 if (details != null && file.equals(details.getDisplayedFile()) ) {
1236 if (downloading || uploading) {
1237 details.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));
1238 } else {
1239 details.updateFileDetails(downloading || uploading);
1240 }
1241 }
1242 }
1243 }
1244
1245
1246
1247
1248
1249 }