Merge remote-tracking branch 'remotes/upstream/master' into beta
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author Bartek Przybylski
5 * @author David A. Velasco
6 * Copyright (C) 2011 Bartek Przybylski
7 * Copyright (C) 2015 ownCloud Inc.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 package com.owncloud.android.ui.activity;
24
25 import android.accounts.Account;
26 import android.accounts.AccountManager;
27 import android.accounts.AuthenticatorException;
28 import android.annotation.TargetApi;
29 import android.os.Parcelable;
30 import android.support.v7.app.AlertDialog;
31 import android.content.BroadcastReceiver;
32 import android.content.ComponentName;
33 import android.content.ContentResolver;
34 import android.content.Context;
35 import android.content.DialogInterface;
36 import android.content.Intent;
37 import android.content.IntentFilter;
38 import android.content.ServiceConnection;
39 import android.content.SharedPreferences;
40 import android.content.SyncRequest;
41 import android.content.res.Resources.NotFoundException;
42 import android.database.Cursor;
43 import android.net.Uri;
44 import android.os.Build;
45 import android.os.Bundle;
46 import android.os.IBinder;
47 import android.preference.PreferenceManager;
48 import android.provider.OpenableColumns;
49 import android.support.v4.app.Fragment;
50 import android.support.v4.app.FragmentManager;
51 import android.support.v4.app.FragmentTransaction;
52 import android.support.v4.content.ContextCompat;
53 import android.support.v4.view.GravityCompat;
54 import android.support.v7.app.AlertDialog;
55 import android.view.Menu;
56 import android.view.MenuInflater;
57 import android.view.MenuItem;
58 import android.view.View;
59 import android.widget.ProgressBar;
60 import android.widget.RelativeLayout;
61 import android.widget.TextView;
62 import android.widget.Toast;
63
64 import com.owncloud.android.MainApp;
65 import com.owncloud.android.R;
66 import com.owncloud.android.datamodel.FileDataStorageManager;
67 import com.owncloud.android.datamodel.OCFile;
68 import com.owncloud.android.files.services.FileDownloader;
69 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
70 import com.owncloud.android.files.services.FileUploader;
71 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
72 import com.owncloud.android.lib.common.OwnCloudAccount;
73 import com.owncloud.android.lib.common.OwnCloudClient;
74 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
75 import com.owncloud.android.lib.common.OwnCloudCredentials;
76 import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
77 import com.owncloud.android.lib.common.network.CertificateCombinedException;
78 import com.owncloud.android.lib.common.operations.RemoteOperation;
79 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
80 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
81 import com.owncloud.android.lib.common.utils.Log_OC;
82 import com.owncloud.android.operations.CopyFileOperation;
83 import com.owncloud.android.operations.CreateFolderOperation;
84 import com.owncloud.android.operations.MoveFileOperation;
85 import com.owncloud.android.operations.RefreshFolderOperation;
86 import com.owncloud.android.operations.RemoveFileOperation;
87 import com.owncloud.android.operations.RenameFileOperation;
88 import com.owncloud.android.operations.SynchronizeFileOperation;
89 import com.owncloud.android.services.observer.FileObserverService;
90 import com.owncloud.android.syncadapter.FileSyncAdapter;
91 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
92 import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
93 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
94 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
95 import com.owncloud.android.ui.dialog.UploadSourceDialogFragment;
96 import com.owncloud.android.ui.fragment.FileDetailFragment;
97 import com.owncloud.android.ui.fragment.FileFragment;
98 import com.owncloud.android.ui.fragment.OCFileListFragment;
99 import com.owncloud.android.ui.preview.PreviewImageActivity;
100 import com.owncloud.android.ui.preview.PreviewImageFragment;
101 import com.owncloud.android.ui.preview.PreviewMediaFragment;
102 import com.owncloud.android.ui.preview.PreviewTextFragment;
103 import com.owncloud.android.ui.preview.PreviewVideoActivity;
104 import com.owncloud.android.utils.DisplayUtils;
105 import com.owncloud.android.utils.ErrorMessageAdapter;
106 import com.owncloud.android.utils.FileStorageUtils;
107 import com.owncloud.android.utils.UriUtils;
108
109 import java.io.File;
110 import java.util.ArrayList;
111 import java.util.Iterator;
112
113 /**
114 * Displays, what files the user has available in his ownCloud.
115 */
116
117 public class FileDisplayActivity extends HookActivity
118 implements FileFragment.ContainerActivity,
119 OnSslUntrustedCertListener, OnEnforceableRefreshListener {
120
121 private SyncBroadcastReceiver mSyncBroadcastReceiver;
122 private UploadFinishReceiver mUploadFinishReceiver;
123 private DownloadFinishReceiver mDownloadFinishReceiver;
124 private RemoteOperationResult mLastSslUntrustedServerResult = null;
125
126 private boolean mDualPane;
127 private View mLeftFragmentContainer;
128 private View mRightFragmentContainer;
129 private ProgressBar mProgressBar;
130
131 private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
132 private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
133 private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND";
134
135 public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
136
137 public static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
138 public static final int ACTION_SELECT_MULTIPLE_FILES = 2;
139 public static final int ACTION_MOVE_FILES = 3;
140 public static final int ACTION_COPY_FILES = 4;
141
142 private static final String TAG = FileDisplayActivity.class.getSimpleName();
143
144 private static final String TAG_LIST_OF_FILES = "LIST_OF_FILES";
145 private static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT";
146
147 private OCFile mWaitingToPreview;
148
149 private boolean mSyncInProgress = false;
150
151 private static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";
152 public static String DIALOG_CREATE_FOLDER = "DIALOG_CREATE_FOLDER";
153 private static String DIALOG_UPLOAD_SOURCE = "DIALOG_UPLOAD_SOURCE";
154 private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED";
155
156 private OCFile mWaitingToSend;
157 private Menu mOptionsMenu;
158
159
160 @Override
161 protected void onCreate(Bundle savedInstanceState) {
162 Log_OC.v(TAG, "onCreate() start");
163
164 super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account
165 // is valid
166
167 /// grant that FileObserverService is watching favorite files
168 if (savedInstanceState == null) {
169 Intent initObserversIntent = FileObserverService.makeInitIntent(this);
170 startService(initObserversIntent);
171 }
172
173 /// Load of saved instance state
174 if(savedInstanceState != null) {
175 mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(
176 FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
177 mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
178 mWaitingToSend = (OCFile) savedInstanceState.getParcelable(
179 FileDisplayActivity.KEY_WAITING_TO_SEND);
180 } else {
181 mWaitingToPreview = null;
182 mSyncInProgress = false;
183 mWaitingToSend = null;
184 }
185
186 /// USER INTERFACE
187
188 // Inflate and set the layout view
189 setContentView(R.layout.files);
190
191 // Navigation Drawer
192 initDrawer();
193
194 mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
195 mProgressBar.setIndeterminateDrawable(
196 ContextCompat.getDrawable(this,
197 R.drawable.actionbar_progress_indeterminate_horizontal));
198
199 mDualPane = getResources().getBoolean(R.bool.large_land_layout);
200 mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
201 mRightFragmentContainer = findViewById(R.id.right_fragment_container);
202 if (savedInstanceState == null) {
203 createMinFragments();
204 }
205
206 // Action bar setup
207 getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS,
208 // according to the official
209 // documentation
210
211 // enable ActionBar app icon to behave as action to toggle nav drawer
212 //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
213 getSupportActionBar().setHomeButtonEnabled(true);
214
215 mProgressBar.setIndeterminate(mSyncInProgress);
216 // always AFTER setContentView(...) ; to work around bug in its implementation
217
218 setBackgroundText();
219
220 Log_OC.v(TAG, "onCreate() end");
221 }
222
223 @Override
224 protected void onStart() {
225 Log_OC.v(TAG, "onStart() start");
226 super.onStart();
227 Log_OC.v(TAG, "onStart() end");
228 }
229
230 @Override
231 protected void onStop() {
232 Log_OC.v(TAG, "onStop() start");
233 super.onStop();
234 Log_OC.v(TAG, "onStop() end");
235 }
236
237 @Override
238 protected void onDestroy() {
239 Log_OC.v(TAG, "onDestroy() start");
240 super.onDestroy();
241 Log_OC.v(TAG, "onDestroy() end");
242 }
243
244 /**
245 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
246 */
247 @Override
248 protected void onAccountSet(boolean stateWasRecovered) {
249 super.onAccountSet(stateWasRecovered);
250 if (getAccount() != null) {
251 /// Check whether the 'main' OCFile handled by the Activity is contained in the
252 // current Account
253 OCFile file = getFile();
254 // get parent from path
255 String parentPath = "";
256 if (file != null) {
257 if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
258 // upload in progress - right now, files are not inserted in the local
259 // cache until the upload is successful get parent from path
260 parentPath = file.getRemotePath().substring(0,
261 file.getRemotePath().lastIndexOf(file.getFileName()));
262 if (getStorageManager().getFileByPath(parentPath) == null)
263 file = null; // not able to know the directory where the file is uploading
264 } else {
265 file = getStorageManager().getFileByPath(file.getRemotePath());
266 // currentDir = null if not in the current Account
267 }
268 }
269 if (file == null) {
270 // fall back to root folder
271 file = getStorageManager().getFileByPath(OCFile.ROOT_PATH); // never returns null
272 }
273 setFile(file);
274
275 if (mAccountWasSet) {
276 setUsernameInDrawer((RelativeLayout) findViewById(R.id.left_drawer), getAccount());
277 }
278
279 if (!stateWasRecovered) {
280 Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
281 initFragmentsWithFile();
282 if (file.isFolder()) {
283 startSyncFolderOperation(file, false);
284 }
285
286 } else {
287 updateFragmentsVisibility(!file.isFolder());
288 updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
289 }
290 }
291 }
292
293 private void createMinFragments() {
294 OCFileListFragment listOfFiles = new OCFileListFragment();
295 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
296 transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
297 transaction.commit();
298 }
299
300 private void initFragmentsWithFile() {
301 if (getAccount() != null && getFile() != null) {
302 /// First fragment
303 OCFileListFragment listOfFiles = getListOfFilesFragment();
304 if (listOfFiles != null) {
305 listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice());
306 } else {
307 Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >(");
308 }
309
310 /// Second fragment
311 OCFile file = getFile();
312 Fragment secondFragment = chooseInitialSecondFragment(file);
313 if (secondFragment != null) {
314 setSecondFragment(secondFragment);
315 updateFragmentsVisibility(true);
316 updateActionBarTitleAndHomeButton(file);
317
318 } else {
319 cleanSecondFragment();
320 if (file.isDown() && PreviewTextFragment.canBePreviewed(file))
321 startTextPreview(file);
322 }
323
324 switchLayout(getFile());
325
326 } else {
327 Log_OC.wtf(TAG, "initFragments() called with invalid NULLs!");
328 if (getAccount() == null) {
329 Log_OC.wtf(TAG, "\t account is NULL");
330 }
331 if (getFile() == null) {
332 Log_OC.wtf(TAG, "\t file is NULL");
333 }
334 }
335 }
336
337 private void switchLayout(OCFile file){
338 if (DisplayUtils.isGridView(file, getStorageManager())){
339 switchToGridView();
340 } else {
341 switchToListView();
342 }
343 }
344
345 private Fragment chooseInitialSecondFragment(OCFile file) {
346 Fragment secondFragment = null;
347 if (file != null && !file.isFolder()) {
348 if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)
349 && file.getLastSyncDateForProperties() > 0 // temporal fix
350 ) {
351 int startPlaybackPosition =
352 getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
353 boolean autoplay =
354 getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
355 secondFragment = new PreviewMediaFragment(file, getAccount(),
356 startPlaybackPosition, autoplay);
357
358 } else if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) {
359 secondFragment = null;
360 } else {
361 secondFragment = FileDetailFragment.newInstance(file, getAccount());
362 }
363 }
364 return secondFragment;
365 }
366
367
368 /**
369 * Replaces the second fragment managed by the activity with the received as
370 * a parameter.
371 * <p/>
372 * Assumes never will be more than two fragments managed at the same time.
373 *
374 * @param fragment New second Fragment to set.
375 */
376 private void setSecondFragment(Fragment fragment) {
377 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
378 transaction.replace(R.id.right_fragment_container, fragment, TAG_SECOND_FRAGMENT);
379 transaction.commit();
380 }
381
382
383 private void updateFragmentsVisibility(boolean existsSecondFragment) {
384 if (mDualPane) {
385 if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
386 mLeftFragmentContainer.setVisibility(View.VISIBLE);
387 }
388 if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
389 mRightFragmentContainer.setVisibility(View.VISIBLE);
390 }
391
392 } else if (existsSecondFragment) {
393 if (mLeftFragmentContainer.getVisibility() != View.GONE) {
394 mLeftFragmentContainer.setVisibility(View.GONE);
395 }
396 if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
397 mRightFragmentContainer.setVisibility(View.VISIBLE);
398 }
399
400 } else {
401 if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
402 mLeftFragmentContainer.setVisibility(View.VISIBLE);
403 }
404 if (mRightFragmentContainer.getVisibility() != View.GONE) {
405 mRightFragmentContainer.setVisibility(View.GONE);
406 }
407 }
408 }
409
410
411 private OCFileListFragment getListOfFilesFragment() {
412 Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(
413 FileDisplayActivity.TAG_LIST_OF_FILES);
414 if (listOfFiles != null) {
415 return (OCFileListFragment) listOfFiles;
416 }
417 Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
418 return null;
419 }
420
421 public FileFragment getSecondFragment() {
422 Fragment second = getSupportFragmentManager().findFragmentByTag(
423 FileDisplayActivity.TAG_SECOND_FRAGMENT);
424 if (second != null) {
425 return (FileFragment) second;
426 }
427 return null;
428 }
429
430 protected void cleanSecondFragment() {
431 Fragment second = getSecondFragment();
432 if (second != null) {
433 FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
434 tr.remove(second);
435 tr.commit();
436 }
437 updateFragmentsVisibility(false);
438 updateActionBarTitleAndHomeButton(null);
439 }
440
441 protected void refreshListOfFilesFragment() {
442 OCFileListFragment fileListFragment = getListOfFilesFragment();
443 if (fileListFragment != null) {
444 fileListFragment.listDirectory(MainApp.getOnlyOnDevice());
445 }
446 }
447
448 protected void refreshSecondFragment(String downloadEvent, String downloadedRemotePath,
449 boolean success) {
450 FileFragment secondFragment = getSecondFragment();
451 boolean waitedPreview = (mWaitingToPreview != null &&
452 mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
453 if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
454 FileDetailFragment detailsFragment = (FileDetailFragment) secondFragment;
455 OCFile fileInFragment = detailsFragment.getFile();
456 if (fileInFragment != null &&
457 !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
458 // the user browsed to other file ; forget the automatic preview
459 mWaitingToPreview = null;
460
461 } else if (downloadEvent.equals(FileDownloader.getDownloadAddedMessage())) {
462 // grant that the right panel updates the progress bar
463 detailsFragment.listenForTransferProgress();
464 detailsFragment.updateFileDetails(true, false);
465
466 } else if (downloadEvent.equals(FileDownloader.getDownloadFinishMessage())) {
467 // update the right panel
468 boolean detailsFragmentChanged = false;
469 if (waitedPreview) {
470 if (success) {
471 mWaitingToPreview = getStorageManager().getFileById(
472 mWaitingToPreview.getFileId()); // update the file from database,
473 // for the local storage path
474 if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
475 startMediaPreview(mWaitingToPreview, 0, true);
476 detailsFragmentChanged = true;
477 } else if (PreviewTextFragment.canBePreviewed(mWaitingToPreview)) {
478 startTextPreview(mWaitingToPreview);
479 detailsFragmentChanged = true;
480 } else {
481 getFileOperationsHelper().openFile(mWaitingToPreview);
482 }
483 }
484 mWaitingToPreview = null;
485 }
486 if (!detailsFragmentChanged) {
487 detailsFragment.updateFileDetails(false, (success));
488 }
489 }
490 }
491 }
492
493 @Override
494 public boolean onPrepareOptionsMenu(Menu menu) {
495 boolean drawerOpen = mDrawerLayout.isDrawerOpen(GravityCompat.START);
496 menu.findItem(R.id.action_sort).setVisible(!drawerOpen);
497 menu.findItem(R.id.action_sync_account).setVisible(!drawerOpen);
498 menu.findItem(R.id.action_switch_view).setVisible(!drawerOpen);
499
500 return super.onPrepareOptionsMenu(menu);
501 }
502
503 @Override
504 public boolean onCreateOptionsMenu(Menu menu) {
505 MenuInflater inflater = getMenuInflater();
506 inflater.inflate(R.menu.main_menu, menu);
507 menu.findItem(R.id.action_create_dir).setVisible(false);
508 mOptionsMenu = menu;
509
510 MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view);
511
512 changeGridIcon();
513
514 return true;
515 }
516
517
518 @Override
519 public boolean onOptionsItemSelected(MenuItem item) {
520 boolean retval = true;
521 switch (item.getItemId()) {
522 case R.id.action_sync_account: {
523 startSynchronization();
524 break;
525 }
526 case android.R.id.home: {
527 FileFragment second = getSecondFragment();
528 OCFile currentDir = getCurrentDir();
529 if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
530 mDrawerLayout.closeDrawer(GravityCompat.START);
531 } else if((currentDir != null && currentDir.getParentId() != 0) ||
532 (second != null && second.getFile() != null)) {
533 onBackPressed();
534
535 } else {
536 mDrawerLayout.openDrawer(GravityCompat.START);
537 }
538 break;
539 }
540 case R.id.action_sort: {
541 SharedPreferences appPreferences = PreferenceManager
542 .getDefaultSharedPreferences(this);
543
544 // Read sorting order, default to sort by name ascending
545 Integer sortOrder = appPreferences
546 .getInt("sortOrder", FileStorageUtils.SORT_NAME);
547
548 AlertDialog.Builder builder = new AlertDialog.Builder(this);
549 builder.setTitle(R.string.actionbar_sort_title)
550 .setSingleChoiceItems(R.array.actionbar_sortby, sortOrder ,
551 new DialogInterface.OnClickListener() {
552 public void onClick(DialogInterface dialog, int which) {
553 switch (which){
554 case 0:
555 sortByName(true);
556 break;
557 case 1:
558 sortByDate(false);
559 break;
560 }
561
562 dialog.dismiss();
563 }
564 });
565 builder.create().show();
566 break;
567 }
568 case R.id.action_switch_view:{
569 if (isGridView()){
570 item.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
571 item.setIcon(ContextCompat.getDrawable(getApplicationContext(),
572 R.drawable.ic_view_module));
573 DisplayUtils.setViewMode(getFile(), false);
574 switchToListView();
575 } else {
576 item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
577 item.setIcon(ContextCompat.getDrawable(getApplicationContext(),
578 R.drawable.ic_view_list));
579 DisplayUtils.setViewMode(getFile(), true);
580 switchToGridView();
581 }
582
583 return true;
584 }
585 default:
586 retval = super.onOptionsItemSelected(item);
587 }
588 return retval;
589 }
590
591 public void createFolder() {
592 CreateFolderDialogFragment dialog =
593 CreateFolderDialogFragment.newInstance(getCurrentDir());
594 dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER);
595 }
596
597 public void uploadLocalFilesSelected() {
598 Intent action = new Intent(this, UploadFilesActivity.class);
599 action.putExtra(
600 UploadFilesActivity.EXTRA_ACCOUNT,
601 getAccount()
602 );
603 startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
604 }
605
606 public void uploadFromOtherAppsSelected() {
607 Intent action = new Intent(Intent.ACTION_GET_CONTENT);
608 action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
609 //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
610 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
611 action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
612 }
613 startActivityForResult(
614 Intent.createChooser(action, getString(R.string.upload_chooser_title)),
615 ACTION_SELECT_CONTENT_FROM_APPS
616 );
617 }
618
619 private void startSynchronization() {
620 Log_OC.d(TAG, "Got to start sync");
621 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
622 Log_OC.d(TAG, "Canceling all syncs for " + MainApp.getAuthority());
623 ContentResolver.cancelSync(null, MainApp.getAuthority());
624 // cancel the current synchronizations of any ownCloud account
625 Bundle bundle = new Bundle();
626 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
627 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
628 Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
629 MainApp.getAuthority());
630 ContentResolver.requestSync(
631 getAccount(),
632 MainApp.getAuthority(), bundle);
633 } else {
634 Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
635 MainApp.getAuthority() + " with new API");
636 SyncRequest.Builder builder = new SyncRequest.Builder();
637 builder.setSyncAdapter(getAccount(), MainApp.getAuthority());
638 builder.setExpedited(true);
639 builder.setManual(true);
640 builder.syncOnce();
641
642 // Fix bug in Android Lollipop when you click on refresh the whole account
643 Bundle extras = new Bundle();
644 builder.setExtras(extras);
645
646 SyncRequest request = builder.build();
647 ContentResolver.requestSync(request);
648 }
649 }
650
651 /**
652 * Called, when the user selected something for uploading
653 *
654 */
655 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
656 @Override
657 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
658
659 if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK ||
660 resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
661 //getClipData is only supported on api level 16+, Jelly Bean
662 if (data.getData() == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
663 for( int i = 0; i < data.getClipData().getItemCount(); i++){
664 Intent intent = new Intent();
665 intent.setData(data.getClipData().getItemAt(i).getUri());
666 requestSimpleUpload(intent, resultCode);
667 }
668 }else {
669 requestSimpleUpload(data, resultCode);
670 }
671 } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK ||
672 resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
673 requestMultipleUpload(data, resultCode);
674
675 } else if (requestCode == ACTION_MOVE_FILES && resultCode == RESULT_OK){
676 final Intent fData = data;
677 final int fResultCode = resultCode;
678 getHandler().postDelayed(
679 new Runnable() {
680 @Override
681 public void run() {
682 requestMoveOperation(fData, fResultCode);
683 }
684 },
685 DELAY_TO_REQUEST_OPERATIONS_LATER
686 );
687
688 } else if (requestCode == ACTION_COPY_FILES && resultCode == RESULT_OK) {
689
690 final Intent fData = data;
691 final int fResultCode = resultCode;
692 getHandler().postDelayed(
693 new Runnable() {
694 @Override
695 public void run() {
696 requestCopyOperation(fData, fResultCode);
697 }
698 },
699 DELAY_TO_REQUEST_OPERATIONS_LATER
700 );
701
702 } else {
703 super.onActivityResult(requestCode, resultCode, data);
704 }
705
706 }
707
708 private void requestMultipleUpload(Intent data, int resultCode) {
709 String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
710 if (filePaths != null) {
711 String[] remotePaths = new String[filePaths.length];
712 String remotePathBase = getCurrentDir().getRemotePath();
713 for (int j = 0; j< remotePaths.length; j++) {
714 remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
715 }
716
717 Intent i = new Intent(this, FileUploader.class);
718 i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
719 i.putExtra(FileUploader.KEY_LOCAL_FILE, filePaths);
720 i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
721 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
722 if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
723 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
724 startService(i);
725
726 } else {
727 Log_OC.d(TAG, "User clicked on 'Update' with no selection");
728 Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected),
729 Toast.LENGTH_LONG);
730 t.show();
731 return;
732 }
733 }
734
735
736 private void requestSimpleUpload(Intent data, int resultCode) {
737 String filePath = null;
738 String mimeType = null;
739
740 Uri selectedImageUri = data.getData();
741
742 try {
743 mimeType = getContentResolver().getType(selectedImageUri);
744
745 String fileManagerString = selectedImageUri.getPath();
746 String selectedImagePath = UriUtils.getLocalPath(selectedImageUri, this);
747
748 if (selectedImagePath != null)
749 filePath = selectedImagePath;
750 else
751 filePath = fileManagerString;
752
753 } catch (Exception e) {
754 Log_OC.e(TAG, "Unexpected exception when trying to read the result of " +
755 "Intent.ACTION_GET_CONTENT", e);
756
757 } finally {
758 if (filePath == null) {
759 Log_OC.e(TAG, "Couldn't resolve path to file");
760 Toast t = Toast.makeText(
761 this, getString(R.string.filedisplay_unexpected_bad_get_content),
762 Toast.LENGTH_LONG
763 );
764 t.show();
765 return;
766 }
767 }
768
769 Intent i = new Intent(this, FileUploader.class);
770 i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
771 OCFile currentDir = getCurrentDir();
772 String remotePath = (currentDir != null) ? currentDir.getRemotePath() : OCFile.ROOT_PATH;
773
774 if (filePath.startsWith(UriUtils.URI_CONTENT_SCHEME)) {
775 Cursor cursor = getContentResolver().query(Uri.parse(filePath), null, null, null, null);
776 try {
777 if (cursor != null && cursor.moveToFirst()) {
778 String displayName = cursor.getString(cursor.getColumnIndex(
779 OpenableColumns.DISPLAY_NAME));
780 Log_OC.v(TAG, "Display Name: " + displayName );
781
782 displayName.replace(File.separatorChar, '_');
783 displayName.replace(File.pathSeparatorChar, '_');
784 remotePath += displayName + DisplayUtils.getComposedFileExtension(filePath);
785
786 }
787 // and what happens in case of error?; wrong target name for the upload
788 } finally {
789 cursor.close();
790 }
791
792 } else {
793 remotePath += new File(filePath).getName();
794 }
795
796 i.putExtra(FileUploader.KEY_LOCAL_FILE, filePath);
797 i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePath);
798 i.putExtra(FileUploader.KEY_MIME_TYPE, mimeType);
799 i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
800 if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
801 i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
802 startService(i);
803 }
804
805 /**
806 * Request the operation for moving the file/folder from one path to another
807 *
808 * @param data Intent received
809 * @param resultCode Result code received
810 */
811 private void requestMoveOperation(Intent data, int resultCode) {
812 OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
813
814 ArrayList<OCFile> files = data.getParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES);
815
816 for (Parcelable file : files) {
817 getFileOperationsHelper().moveFile(folderToMoveAt, (OCFile) file);
818 }
819 }
820
821 /**
822 * Request the operation for copying the file/folder from one path to another
823 *
824 * @param data Intent received
825 * @param resultCode Result code received
826 */
827 private void requestCopyOperation(Intent data, int resultCode) {
828 OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
829
830 ArrayList<OCFile> files = data.getParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES);
831
832 for (Parcelable file : files) {
833 getFileOperationsHelper().copyFile(folderToMoveAt, (OCFile) file);
834 }
835 }
836
837 @Override
838 public void onBackPressed() {
839 boolean isFabOpen = isFabOpen();
840 boolean isDrawerOpen = isDrawerOpen();
841
842 /*
843 * BackPressed priority/hierarchy:
844 * 1. close drawer if opened
845 * 2. close FAB if open (only if drawer isn't open)
846 * 3. navigate up (only if drawer and FAB aren't open)
847 */
848 if(isDrawerOpen && isFabOpen) {
849 // close drawer first
850 super.onBackPressed();
851 } else if(isDrawerOpen && !isFabOpen) {
852 // close drawer
853 super.onBackPressed();
854 } else if (!isDrawerOpen && isFabOpen) {
855 // close fab
856 getListOfFilesFragment().getFabMain().collapse();
857 } else {
858 // all closed
859 OCFileListFragment listOfFiles = getListOfFilesFragment();
860 if (mDualPane || getSecondFragment() == null) {
861 OCFile currentDir = getCurrentDir();
862 if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
863 finish();
864 return;
865 }
866 if (listOfFiles != null) { // should never be null, indeed
867 listOfFiles.onBrowseUp();
868 }
869 }
870 if (listOfFiles != null) { // should never be null, indeed
871 setFile(listOfFiles.getCurrentFile());
872 }
873 cleanSecondFragment();
874 changeGridIcon();
875 }
876 }
877
878 private void changeGridIcon(){
879 MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view);
880 if (DisplayUtils.isGridView(getFile(), getStorageManager())){
881 menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
882 menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(),
883 R.drawable.ic_view_list));
884 } else {
885 menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
886 menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(),
887 R.drawable.ic_view_module));
888 }
889 }
890
891 @Override
892 protected void onSaveInstanceState(Bundle outState) {
893 // responsibility of restore is preferred in onCreate() before than in
894 // onRestoreInstanceState when there are Fragments involved
895 Log_OC.v(TAG, "onSaveInstanceState() start");
896 super.onSaveInstanceState(outState);
897 outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
898 outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress);
899 //outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS,
900 // mRefreshSharesInProgress);
901 outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend);
902
903 Log_OC.v(TAG, "onSaveInstanceState() end");
904 }
905
906
907 @Override
908 protected void onResume() {
909 Log_OC.v(TAG, "onResume() start");
910 super.onResume();
911 // refresh Navigation Drawer account list
912 mNavigationDrawerAdapter.updateAccountList();
913
914 // refresh list of files
915 refreshListOfFilesFragment();
916
917 // Listen for sync messages
918 IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
919 syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
920 syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
921 syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
922 syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
923 mSyncBroadcastReceiver = new SyncBroadcastReceiver();
924 registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
925 //LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver,
926 // syncIntentFilter);
927
928 // Listen for upload messages
929 IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
930 mUploadFinishReceiver = new UploadFinishReceiver();
931 registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
932
933 // Listen for download messages
934 IntentFilter downloadIntentFilter = new IntentFilter(
935 FileDownloader.getDownloadAddedMessage());
936 downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
937 mDownloadFinishReceiver = new DownloadFinishReceiver();
938 registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
939
940 Log_OC.v(TAG, "onResume() end");
941
942 }
943
944
945 @Override
946 protected void onPause() {
947 Log_OC.v(TAG, "onPause() start");
948 if (mSyncBroadcastReceiver != null) {
949 unregisterReceiver(mSyncBroadcastReceiver);
950 //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
951 mSyncBroadcastReceiver = null;
952 }
953 if (mUploadFinishReceiver != null) {
954 unregisterReceiver(mUploadFinishReceiver);
955 mUploadFinishReceiver = null;
956 }
957 if (mDownloadFinishReceiver != null) {
958 unregisterReceiver(mDownloadFinishReceiver);
959 mDownloadFinishReceiver = null;
960 }
961
962 super.onPause();
963 Log_OC.v(TAG, "onPause() end");
964 }
965
966 public boolean isFabOpen() {
967 if(getListOfFilesFragment() != null && getListOfFilesFragment().getFabMain() != null && getListOfFilesFragment().getFabMain().isExpanded()) {
968 return true;
969 } else {
970 return false;
971 }
972 }
973
974
975 private class SyncBroadcastReceiver extends BroadcastReceiver {
976
977 /**
978 * {@link BroadcastReceiver} to enable syncing feedback in UI
979 */
980 @Override
981 public void onReceive(Context context, Intent intent) {
982 try {
983 String event = intent.getAction();
984 Log_OC.d(TAG, "Received broadcast " + event);
985 String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
986 String synchFolderRemotePath =
987 intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
988 RemoteOperationResult synchResult =
989 (RemoteOperationResult)intent.getSerializableExtra(
990 FileSyncAdapter.EXTRA_RESULT);
991 boolean sameAccount = (getAccount() != null &&
992 accountName.equals(getAccount().name) && getStorageManager() != null);
993
994 if (sameAccount) {
995
996 if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
997 mSyncInProgress = true;
998
999 } else {
1000 OCFile currentFile = (getFile() == null) ? null :
1001 getStorageManager().getFileByPath(getFile().getRemotePath());
1002 OCFile currentDir = (getCurrentDir() == null) ? null :
1003 getStorageManager().getFileByPath(getCurrentDir().getRemotePath());
1004
1005 if (currentDir == null) {
1006 // current folder was removed from the server
1007 Toast.makeText( FileDisplayActivity.this,
1008 String.format(
1009 getString(R.string.
1010 sync_current_folder_was_removed),
1011 synchFolderRemotePath),
1012 Toast.LENGTH_LONG)
1013 .show();
1014
1015 browseToRoot();
1016
1017 } else {
1018 if (currentFile == null && !getFile().isFolder()) {
1019 // currently selected file was removed in the server, and now we
1020 // know it
1021 cleanSecondFragment();
1022 currentFile = currentDir;
1023 }
1024
1025 if (synchFolderRemotePath != null &&
1026 currentDir.getRemotePath().equals(synchFolderRemotePath)) {
1027 OCFileListFragment fileListFragment = getListOfFilesFragment();
1028 if (fileListFragment != null) {
1029 fileListFragment.listDirectory(currentDir,
1030 MainApp.getOnlyOnDevice());
1031 }
1032 }
1033 setFile(currentFile);
1034 }
1035
1036 mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
1037 !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED
1038 .equals(event));
1039
1040 if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
1041 equals(event) &&/// TODO refactor and make common
1042
1043 synchResult != null && !synchResult.isSuccess() &&
1044 (synchResult.getCode() == ResultCode.UNAUTHORIZED ||
1045 synchResult.isIdPRedirection() ||
1046 (synchResult.isException() && synchResult.getException()
1047 instanceof AuthenticatorException))) {
1048
1049
1050 try {
1051 OwnCloudClient client;
1052 OwnCloudAccount ocAccount =
1053 new OwnCloudAccount(getAccount(), context);
1054 client = (OwnCloudClientManagerFactory.getDefaultSingleton().
1055 removeClientFor(ocAccount));
1056 if (client != null) {
1057 OwnCloudCredentials cred = client.getCredentials();
1058 if (cred != null) {
1059 AccountManager am = AccountManager.get(context);
1060 if (cred.authTokenExpires()) {
1061 am.invalidateAuthToken(
1062 getAccount().type,
1063 cred.getAuthToken()
1064 );
1065 } else {
1066 am.clearPassword(getAccount());
1067 }
1068 }
1069 }
1070 requestCredentialsUpdate();
1071
1072 } catch (AccountNotFoundException e) {
1073 Log_OC.e(TAG, "Account " + getAccount() + " was removed!", e);
1074 }
1075
1076 }
1077
1078 }
1079 removeStickyBroadcast(intent);
1080 Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
1081 mProgressBar.setIndeterminate(mSyncInProgress);
1082 //mProgressBar.setVisibility((mSyncInProgress) ? View.VISIBLE : View.INVISIBLE);
1083 //setSupportProgressBarIndeterminateVisibility(mSyncInProgress
1084 /*|| mRefreshSharesInProgress*/ //);
1085
1086 setBackgroundText();
1087
1088 }
1089
1090 if (synchResult != null) {
1091 if (synchResult.getCode().equals(
1092 RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
1093 mLastSslUntrustedServerResult = synchResult;
1094 }
1095 }
1096 } catch (RuntimeException e) {
1097 // avoid app crashes after changing the serial id of RemoteOperationResult
1098 // in owncloud library with broadcast notifications pending to process
1099 removeStickyBroadcast(intent);
1100 }
1101 }
1102 }
1103
1104 /**
1105 * Show a text message on screen view for notifying user if content is
1106 * loading or folder is empty
1107 */
1108 private void setBackgroundText() {
1109 OCFileListFragment ocFileListFragment = getListOfFilesFragment();
1110 if (ocFileListFragment != null) {
1111 int message = R.string.file_list_loading;
1112 if (!mSyncInProgress) {
1113 // In case file list is empty
1114 message = R.string.file_list_empty;
1115 }
1116 ocFileListFragment.setMessageForEmptyList(getString(message));
1117 } else {
1118 Log_OC.e(TAG, "OCFileListFragment is null");
1119 }
1120 }
1121
1122 /**
1123 * Once the file upload has finished -> update view
1124 */
1125 private class UploadFinishReceiver extends BroadcastReceiver {
1126 /**
1127 * Once the file upload has finished -> update view
1128 *
1129 * @author David A. Velasco
1130 * {@link BroadcastReceiver} to enable upload feedback in UI
1131 */
1132 @Override
1133 public void onReceive(Context context, Intent intent) {
1134 try {
1135 String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
1136 String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
1137 boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
1138 OCFile currentDir = getCurrentDir();
1139 boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) &&
1140 (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
1141
1142 if (sameAccount && isDescendant) {
1143 String linkedToRemotePath =
1144 intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
1145 if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
1146 refreshListOfFilesFragment();
1147 }
1148 }
1149
1150 boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT,
1151 false);
1152 boolean renamedInUpload = getFile().getRemotePath().
1153 equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
1154 boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
1155 renamedInUpload;
1156 FileFragment details = getSecondFragment();
1157 boolean detailFragmentIsShown = (details != null &&
1158 details instanceof FileDetailFragment);
1159
1160 if (sameAccount && sameFile && detailFragmentIsShown) {
1161 if (uploadWasFine) {
1162 setFile(getStorageManager().getFileByPath(uploadedRemotePath));
1163 }
1164 if (renamedInUpload) {
1165 String newName = (new File(uploadedRemotePath)).getName();
1166 Toast msg = Toast.makeText(
1167 context,
1168 String.format(
1169 getString(R.string.filedetails_renamed_in_upload_msg),
1170 newName),
1171 Toast.LENGTH_LONG);
1172 msg.show();
1173 }
1174 if (uploadWasFine || getFile().fileExists()) {
1175 ((FileDetailFragment) details).updateFileDetails(false, true);
1176 } else {
1177 cleanSecondFragment();
1178 }
1179
1180 // Force the preview if the file is an image or text file
1181 if (uploadWasFine) {
1182 OCFile ocFile = getFile();
1183 if (PreviewImageFragment.canBePreviewed(ocFile))
1184 startImagePreview(getFile());
1185 else if (PreviewTextFragment.canBePreviewed(ocFile))
1186 startTextPreview(ocFile);
1187 // TODO what about other kind of previews?
1188 }
1189 }
1190
1191 mProgressBar.setIndeterminate(false);
1192 } finally {
1193 if (intent != null) {
1194 removeStickyBroadcast(intent);
1195 }
1196 }
1197
1198 }
1199
1200 // TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S
1201 private boolean isAscendant(String linkedToRemotePath) {
1202 OCFile currentDir = getCurrentDir();
1203 return (
1204 currentDir != null &&
1205 currentDir.getRemotePath().startsWith(linkedToRemotePath)
1206 );
1207 }
1208
1209
1210 }
1211
1212
1213 /**
1214 * Class waiting for broadcast events from the {@link FileDownloader} service.
1215 *
1216 * Updates the UI when a download is started or finished, provided that it is relevant for the
1217 * current folder.
1218 */
1219 private class DownloadFinishReceiver extends BroadcastReceiver {
1220
1221 @Override
1222 public void onReceive(Context context, Intent intent) {
1223 try {
1224 boolean sameAccount = isSameAccount(intent);
1225 String downloadedRemotePath =
1226 intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
1227 boolean isDescendant = isDescendant(downloadedRemotePath);
1228
1229 if (sameAccount && isDescendant) {
1230 String linkedToRemotePath =
1231 intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
1232 if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
1233 refreshListOfFilesFragment();
1234 }
1235 refreshSecondFragment(
1236 intent.getAction(),
1237 downloadedRemotePath,
1238 intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)
1239 );
1240 }
1241
1242 if (mWaitingToSend != null) {
1243 mWaitingToSend =
1244 getStorageManager().getFileByPath(mWaitingToSend.getRemotePath());
1245 if (mWaitingToSend.isDown()) {
1246 sendDownloadedFile();
1247 }
1248 }
1249
1250 } finally {
1251 if (intent != null) {
1252 removeStickyBroadcast(intent);
1253 }
1254 }
1255 }
1256
1257 private boolean isDescendant(String downloadedRemotePath) {
1258 OCFile currentDir = getCurrentDir();
1259 return (
1260 currentDir != null &&
1261 downloadedRemotePath != null &&
1262 downloadedRemotePath.startsWith(currentDir.getRemotePath())
1263 );
1264 }
1265
1266 private boolean isAscendant(String linkedToRemotePath) {
1267 OCFile currentDir = getCurrentDir();
1268 return (
1269 currentDir != null &&
1270 currentDir.getRemotePath().startsWith(linkedToRemotePath)
1271 );
1272 }
1273
1274 private boolean isSameAccount(Intent intent) {
1275 String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
1276 return (accountName != null && getAccount() != null &&
1277 accountName.equals(getAccount().name));
1278 }
1279 }
1280
1281
1282 public void browseToRoot() {
1283 OCFileListFragment listOfFiles = getListOfFilesFragment();
1284 if (listOfFiles != null) { // should never be null, indeed
1285 OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
1286 listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice());
1287 setFile(listOfFiles.getCurrentFile());
1288 startSyncFolderOperation(root, false);
1289 }
1290 cleanSecondFragment();
1291 }
1292
1293
1294 /**
1295 * {@inheritDoc}
1296 * <p/>
1297 * Updates action bar and second fragment, if in dual pane mode.
1298 */
1299 @Override
1300 public void onBrowsedDownTo(OCFile directory) {
1301 setFile(directory);
1302 cleanSecondFragment();
1303 // Sync Folder
1304 startSyncFolderOperation(directory, false);
1305
1306 MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view);
1307
1308 changeGridIcon();
1309 switchLayout(directory);
1310 }
1311
1312 /**
1313 * Shows the information of the {@link OCFile} received as a
1314 * parameter in the second fragment.
1315 *
1316 * @param file {@link OCFile} whose details will be shown
1317 */
1318 @Override
1319 public void showDetails(OCFile file) {
1320 Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());
1321 setSecondFragment(detailFragment);
1322 updateFragmentsVisibility(true);
1323 updateActionBarTitleAndHomeButton(file);
1324 setFile(file);
1325 }
1326
1327 @Override
1328 protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
1329 if (mDualPane) {
1330 // in dual pane mode, keep the focus of title an action bar in the current folder
1331 super.updateActionBarTitleAndHomeButton(getCurrentDir());
1332
1333 } else {
1334 super.updateActionBarTitleAndHomeButton(chosenFile);
1335 }
1336
1337 }
1338
1339 @Override
1340 protected ServiceConnection newTransferenceServiceConnection() {
1341 return new ListServiceConnection();
1342 }
1343
1344 /**
1345 * Defines callbacks for service binding, passed to bindService()
1346 */
1347 private class ListServiceConnection implements ServiceConnection {
1348
1349 @Override
1350 public void onServiceConnected(ComponentName component, IBinder service) {
1351 if (component.equals(new ComponentName(
1352 FileDisplayActivity.this, FileDownloader.class))) {
1353 Log_OC.d(TAG, "Download service connected");
1354 mDownloaderBinder = (FileDownloaderBinder) service;
1355 if (mWaitingToPreview != null)
1356 if (getStorageManager() != null) {
1357 // update the file
1358 mWaitingToPreview =
1359 getStorageManager().getFileById(mWaitingToPreview.getFileId());
1360 if (!mWaitingToPreview.isDown()) {
1361 requestForDownload();
1362 }
1363 }
1364
1365 } else if (component.equals(new ComponentName(FileDisplayActivity.this,
1366 FileUploader.class))) {
1367 Log_OC.d(TAG, "Upload service connected");
1368 mUploaderBinder = (FileUploaderBinder) service;
1369 } else {
1370 return;
1371 }
1372 // a new chance to get the mDownloadBinder through
1373 // getFileDownloadBinder() - THIS IS A MESS
1374 OCFileListFragment listOfFiles = getListOfFilesFragment();
1375 if (listOfFiles != null) {
1376 listOfFiles.listDirectory(MainApp.getOnlyOnDevice());
1377 }
1378 FileFragment secondFragment = getSecondFragment();
1379 if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
1380 FileDetailFragment detailFragment = (FileDetailFragment) secondFragment;
1381 detailFragment.listenForTransferProgress();
1382 detailFragment.updateFileDetails(false, false);
1383 }
1384 }
1385
1386 @Override
1387 public void onServiceDisconnected(ComponentName component) {
1388 if (component.equals(new ComponentName(FileDisplayActivity.this,
1389 FileDownloader.class))) {
1390 Log_OC.d(TAG, "Download service disconnected");
1391 mDownloaderBinder = null;
1392 } else if (component.equals(new ComponentName(FileDisplayActivity.this,
1393 FileUploader.class))) {
1394 Log_OC.d(TAG, "Upload service disconnected");
1395 mUploaderBinder = null;
1396 }
1397 }
1398 }
1399
1400 @Override
1401 public void onSavedCertificate() {
1402 startSyncFolderOperation(getCurrentDir(), false);
1403 }
1404
1405
1406 @Override
1407 public void onFailedSavingCertificate() {
1408 ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(
1409 R.string.ssl_validator_not_saved, new String[]{}, R.string.common_ok, -1, -1
1410 );
1411 dialog.show(getSupportFragmentManager(), DIALOG_CERT_NOT_SAVED);
1412 }
1413
1414 @Override
1415 public void onCancelCertificate() {
1416 // nothing to do
1417 }
1418
1419 /**
1420 * Updates the view associated to the activity after the finish of some operation over files
1421 * in the current account.
1422 *
1423 * @param operation Removal operation performed.
1424 * @param result Result of the removal.
1425 */
1426 @Override
1427 public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
1428 super.onRemoteOperationFinish(operation, result);
1429
1430 if (operation instanceof RemoveFileOperation) {
1431 onRemoveFileOperationFinish((RemoveFileOperation) operation, result);
1432
1433 } else if (operation instanceof RenameFileOperation) {
1434 onRenameFileOperationFinish((RenameFileOperation) operation, result);
1435
1436 } else if (operation instanceof SynchronizeFileOperation) {
1437 onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result);
1438
1439 } else if (operation instanceof CreateFolderOperation) {
1440 onCreateFolderOperationFinish((CreateFolderOperation) operation, result);
1441
1442 } else if (operation instanceof MoveFileOperation) {
1443 onMoveFileOperationFinish((MoveFileOperation) operation, result);
1444
1445 } else if (operation instanceof CopyFileOperation) {
1446 onCopyFileOperationFinish((CopyFileOperation) operation, result);
1447 }
1448
1449 }
1450
1451 private void refreshShowDetails() {
1452 FileFragment details = getSecondFragment();
1453 if (details != null) {
1454 OCFile file = details.getFile();
1455 if (file != null) {
1456 file = getStorageManager().getFileByPath(file.getRemotePath());
1457 if (details instanceof PreviewMediaFragment) {
1458 // Refresh OCFile of the fragment
1459 ((PreviewMediaFragment) details).updateFile(file);
1460 } else if (details instanceof PreviewTextFragment) {
1461 // Refresh OCFile of the fragment
1462 ((PreviewTextFragment) details).updateFile(file);
1463 } else {
1464 showDetails(file);
1465 }
1466 }
1467 invalidateOptionsMenu();
1468 }
1469 }
1470
1471 /**
1472 * Updates the view associated to the activity after the finish of an operation trying to
1473 * remove a file.
1474 *
1475 * @param operation Removal operation performed.
1476 * @param result Result of the removal.
1477 */
1478 private void onRemoveFileOperationFinish(RemoveFileOperation operation,
1479 RemoteOperationResult result) {
1480 Toast msg = Toast.makeText(this,
1481 ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
1482 Toast.LENGTH_LONG);
1483 msg.show();
1484
1485 if (result.isSuccess()) {
1486 OCFile removedFile = operation.getFile();
1487 FileFragment second = getSecondFragment();
1488 if (second != null && removedFile.equals(second.getFile())) {
1489 if (second instanceof PreviewMediaFragment) {
1490 ((PreviewMediaFragment) second).stopPreview(true);
1491 }
1492 setFile(getStorageManager().getFileById(removedFile.getParentId()));
1493 cleanSecondFragment();
1494 }
1495 if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())){
1496 refreshListOfFilesFragment();
1497 }
1498 invalidateOptionsMenu();
1499 } else {
1500 if (result.isSslRecoverableException()) {
1501 mLastSslUntrustedServerResult = result;
1502 showUntrustedCertDialog(mLastSslUntrustedServerResult);
1503 }
1504 }
1505 }
1506
1507
1508 /**
1509 * Updates the view associated to the activity after the finish of an operation trying to move a
1510 * file.
1511 *
1512 * @param operation Move operation performed.
1513 * @param result Result of the move operation.
1514 */
1515 private void onMoveFileOperationFinish(MoveFileOperation operation,
1516 RemoteOperationResult result) {
1517 if (result.isSuccess()) {
1518 refreshListOfFilesFragment();
1519 } else {
1520 try {
1521 Toast msg = Toast.makeText(FileDisplayActivity.this,
1522 ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
1523 Toast.LENGTH_LONG);
1524 msg.show();
1525
1526 } catch (NotFoundException e) {
1527 Log_OC.e(TAG, "Error while trying to show fail message ", e);
1528 }
1529 }
1530 }
1531
1532 /**
1533 * Updates the view associated to the activity after the finish of an operation trying to copy a
1534 * file.
1535 *
1536 * @param operation Copy operation performed.
1537 * @param result Result of the copy operation.
1538 */
1539 private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) {
1540 if (result.isSuccess()) {
1541 refreshListOfFilesFragment();
1542 } else {
1543 try {
1544 Toast msg = Toast.makeText(FileDisplayActivity.this,
1545 ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
1546 Toast.LENGTH_LONG);
1547 msg.show();
1548
1549 } catch (NotFoundException e) {
1550 Log_OC.e(TAG, "Error while trying to show fail message ", e);
1551 }
1552 }
1553 }
1554
1555 /**
1556 * Updates the view associated to the activity after the finish of an operation trying to rename
1557 * a file.
1558 *
1559 * @param operation Renaming operation performed.
1560 * @param result Result of the renaming.
1561 */
1562 private void onRenameFileOperationFinish(RenameFileOperation operation,
1563 RemoteOperationResult result) {
1564 OCFile renamedFile = operation.getFile();
1565 if (result.isSuccess()) {
1566 FileFragment details = getSecondFragment();
1567 if (details != null) {
1568 if (details instanceof FileDetailFragment &&
1569 renamedFile.equals(details.getFile()) ) {
1570 ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
1571 showDetails(renamedFile);
1572
1573 } else if (details instanceof PreviewMediaFragment &&
1574 renamedFile.equals(details.getFile())) {
1575 ((PreviewMediaFragment) details).updateFile(renamedFile);
1576 if (PreviewMediaFragment.canBePreviewed(renamedFile)) {
1577 int position = ((PreviewMediaFragment) details).getPosition();
1578 startMediaPreview(renamedFile, position, true);
1579 } else {
1580 getFileOperationsHelper().openFile(renamedFile);
1581 }
1582 } else if (details instanceof PreviewTextFragment &&
1583 renamedFile.equals(details.getFile())) {
1584 ((PreviewTextFragment) details).updateFile(renamedFile);
1585 if (PreviewTextFragment.canBePreviewed(renamedFile)) {
1586 startTextPreview(renamedFile);
1587 } else {
1588 getFileOperationsHelper().openFile(renamedFile);
1589 }
1590 }
1591 }
1592
1593 if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())){
1594 refreshListOfFilesFragment();
1595 }
1596
1597 } else {
1598 Toast msg = Toast.makeText(this,
1599 ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
1600 Toast.LENGTH_LONG);
1601 msg.show();
1602
1603 if (result.isSslRecoverableException()) {
1604 mLastSslUntrustedServerResult = result;
1605 showUntrustedCertDialog(mLastSslUntrustedServerResult);
1606 }
1607 }
1608 }
1609
1610 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation,
1611 RemoteOperationResult result) {
1612 if (result.isSuccess()) {
1613 if (operation.transferWasRequested()) {
1614 OCFile syncedFile = operation.getLocalFile();
1615 onTransferStateChanged(syncedFile, true, true);
1616 invalidateOptionsMenu();
1617 refreshShowDetails();
1618 }
1619 }
1620 }
1621
1622 /**
1623 * Updates the view associated to the activity after the finish of an operation trying create a
1624 * new folder
1625 *
1626 * @param operation Creation operation performed.
1627 * @param result Result of the creation.
1628 */
1629 private void onCreateFolderOperationFinish(CreateFolderOperation operation,
1630 RemoteOperationResult result) {
1631 if (result.isSuccess()) {
1632 refreshListOfFilesFragment();
1633 } else {
1634 try {
1635 Toast msg = Toast.makeText(FileDisplayActivity.this,
1636 ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
1637 Toast.LENGTH_LONG);
1638 msg.show();
1639
1640 } catch (NotFoundException e) {
1641 Log_OC.e(TAG, "Error while trying to show fail message ", e);
1642 }
1643 }
1644 }
1645
1646
1647 /**
1648 * {@inheritDoc}
1649 */
1650 @Override
1651 public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
1652 refreshListOfFilesFragment();
1653 FileFragment details = getSecondFragment();
1654 if (details != null && details instanceof FileDetailFragment &&
1655 file.equals(details.getFile()) ) {
1656 if (downloading || uploading) {
1657 ((FileDetailFragment) details).updateFileDetails(file, getAccount());
1658 } else {
1659 if (!file.fileExists()) {
1660 cleanSecondFragment();
1661 } else {
1662 ((FileDetailFragment) details).updateFileDetails(false, true);
1663 }
1664 }
1665 }
1666
1667 }
1668
1669
1670 private void requestForDownload() {
1671 Account account = getAccount();
1672 //if (!mWaitingToPreview.isDownloading()) {
1673 if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
1674 Intent i = new Intent(this, FileDownloader.class);
1675 i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
1676 i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
1677 startService(i);
1678 }
1679 }
1680
1681
1682 private OCFile getCurrentDir() {
1683 OCFile file = getFile();
1684 if (file != null) {
1685 if (file.isFolder()) {
1686 return file;
1687 } else if (getStorageManager() != null) {
1688 String parentPath = file.getRemotePath().substring(0,
1689 file.getRemotePath().lastIndexOf(file.getFileName()));
1690 return getStorageManager().getFileByPath(parentPath);
1691 }
1692 }
1693 return null;
1694 }
1695
1696 /**
1697 * Starts an operation to refresh the requested folder.
1698 *
1699 * The operation is run in a new background thread created on the fly.
1700 *
1701 * The refresh updates is a "light sync": properties of regular files in folder are updated (including
1702 * associated shares), but not their contents. Only the contents of files marked to be kept-in-sync are
1703 * synchronized too.
1704 *
1705 * @param folder Folder to refresh.
1706 * @param ignoreETag If 'true', the data from the server will be fetched and sync'ed even if the eTag
1707 * didn't change.
1708 */
1709 public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag) {
1710
1711 // the execution is slightly delayed to allow the activity get the window focus if it's being started
1712 // or if the method is called from a dialog that is being dismissed
1713 getHandler().postDelayed(
1714 new Runnable() {
1715 @Override
1716 public void run() {
1717 if (hasWindowFocus()) {
1718 long currentSyncTime = System.currentTimeMillis();
1719 mSyncInProgress = true;
1720
1721 // perform folder synchronization
1722 RemoteOperation synchFolderOp = new RefreshFolderOperation(folder,
1723 currentSyncTime,
1724 false,
1725 getFileOperationsHelper().isSharedSupported(),
1726 ignoreETag,
1727 getStorageManager(),
1728 getAccount(),
1729 getApplicationContext()
1730 );
1731 synchFolderOp.execute(
1732 getAccount(),
1733 MainApp.getAppContext(),
1734 FileDisplayActivity.this,
1735 null,
1736 null
1737 );
1738
1739 mProgressBar.setIndeterminate(true);
1740
1741 setBackgroundText();
1742
1743 } // else: NOTHING ; lets' not refresh when the user rotates the device but there is
1744 // another window floating over
1745 }
1746 },
1747 DELAY_TO_REQUEST_OPERATIONS_LATER
1748 );
1749
1750 }
1751
1752 /**
1753 * Show untrusted cert dialog
1754 */
1755 public void showUntrustedCertDialog(RemoteOperationResult result) {
1756 // Show a dialog with the certificate info
1757 SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstanceForFullSslError(
1758 (CertificateCombinedException) result.getException());
1759 FragmentManager fm = getSupportFragmentManager();
1760 FragmentTransaction ft = fm.beginTransaction();
1761 dialog.show(ft, DIALOG_UNTRUSTED_CERT);
1762 }
1763
1764 private void requestForDownload(OCFile file) {
1765 Account account = getAccount();
1766 if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
1767 Intent i = new Intent(this, FileDownloader.class);
1768 i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
1769 i.putExtra(FileDownloader.EXTRA_FILE, file);
1770 startService(i);
1771 }
1772 }
1773
1774 private void sendDownloadedFile() {
1775 getFileOperationsHelper().sendDownloadedFile(mWaitingToSend);
1776 mWaitingToSend = null;
1777 }
1778
1779
1780 /**
1781 * Requests the download of the received {@link OCFile} , updates the UI
1782 * to monitor the download progress and prepares the activity to send the file
1783 * when the download finishes.
1784 *
1785 * @param file {@link OCFile} to download and preview.
1786 */
1787 public void startDownloadForSending(OCFile file) {
1788 mWaitingToSend = file;
1789 requestForDownload(mWaitingToSend);
1790 boolean hasSecondFragment = (getSecondFragment() != null);
1791 updateFragmentsVisibility(hasSecondFragment);
1792 }
1793
1794 /**
1795 * Opens the image gallery showing the image {@link OCFile} received as parameter.
1796 *
1797 * @param file Image {@link OCFile} to show.
1798 */
1799 public void startImagePreview(OCFile file) {
1800 Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
1801 showDetailsIntent.putExtra(EXTRA_FILE, file);
1802 showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
1803 startActivity(showDetailsIntent);
1804 }
1805
1806 /**
1807 * Stars the preview of an already down media {@link OCFile}.
1808 *
1809 * @param file Media {@link OCFile} to preview.
1810 * @param startPlaybackPosition Media position where the playback will be started,
1811 * in milliseconds.
1812 * @param autoplay When 'true', the playback will start without user
1813 * interactions.
1814 */
1815 public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
1816 Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition,
1817 autoplay);
1818 setSecondFragment(mediaFragment);
1819 updateFragmentsVisibility(true);
1820 updateActionBarTitleAndHomeButton(file);
1821 setFile(file);
1822 }
1823
1824 /**
1825 * Stars the preview of a text file {@link OCFile}.
1826 *
1827 * @param file Text {@link OCFile} to preview.
1828 */
1829 public void startTextPreview(OCFile file) {
1830 Bundle args = new Bundle();
1831 args.putParcelable(EXTRA_FILE, file);
1832 args.putParcelable(EXTRA_ACCOUNT, getAccount());
1833 Fragment textPreviewFragment = Fragment.instantiate(getApplicationContext(),
1834 PreviewTextFragment.class.getName(), args);
1835 setSecondFragment(textPreviewFragment);
1836 updateFragmentsVisibility(true);
1837 //updateNavigationElementsInActionBar(file);
1838 setFile(file);
1839 }
1840
1841 /**
1842 * Requests the download of the received {@link OCFile} , updates the UI
1843 * to monitor the download progress and prepares the activity to preview
1844 * or open the file when the download finishes.
1845 *
1846 * @param file {@link OCFile} to download and preview.
1847 */
1848 public void startDownloadForPreview(OCFile file) {
1849 Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());
1850 setSecondFragment(detailFragment);
1851 mWaitingToPreview = file;
1852 requestForDownload();
1853 updateFragmentsVisibility(true);
1854 updateActionBarTitleAndHomeButton(file);
1855 setFile(file);
1856 }
1857
1858
1859 public void cancelTransference(OCFile file) {
1860 getFileOperationsHelper().cancelTransference(file);
1861 if (mWaitingToPreview != null &&
1862 mWaitingToPreview.getRemotePath().equals(file.getRemotePath())) {
1863 mWaitingToPreview = null;
1864 }
1865 if (mWaitingToSend != null &&
1866 mWaitingToSend.getRemotePath().equals(file.getRemotePath())) {
1867 mWaitingToSend = null;
1868 }
1869 onTransferStateChanged(file, false, false);
1870 }
1871
1872 @Override
1873 public void onRefresh(boolean ignoreETag) {
1874 refreshList(ignoreETag);
1875 }
1876
1877 @Override
1878 public void onRefresh() {
1879 refreshList(true);
1880 }
1881
1882 private void refreshList(boolean ignoreETag) {
1883 OCFileListFragment listOfFiles = getListOfFilesFragment();
1884 if (listOfFiles != null) {
1885 OCFile folder = listOfFiles.getCurrentFile();
1886 if (folder != null) {
1887 /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
1888 listDirectory(mFile);*/
1889 startSyncFolderOperation(folder, ignoreETag);
1890 }
1891 }
1892 }
1893
1894 private void sortByDate(boolean ascending) {
1895 getListOfFilesFragment().sortByDate(ascending);
1896 }
1897
1898 private void sortBySize(boolean ascending) {
1899 getListOfFilesFragment().sortBySize(ascending);
1900 }
1901
1902 private void sortByName(boolean ascending) {
1903 getListOfFilesFragment().sortByName(ascending);
1904 }
1905 private boolean isGridView(){ return getListOfFilesFragment().isGridView(); }
1906 private void switchToGridView() {
1907 getListOfFilesFragment().switchToGridView();
1908 }
1909 private void switchToListView() {
1910 getListOfFilesFragment().switchToListView();
1911 }
1912
1913 public void allFilesOption() {
1914 browseToRoot();
1915 }
1916
1917 public void refreshDirectory(){
1918 getListOfFilesFragment().refreshDirectory();
1919 }
1920 }