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