FileDisplayActivity.java 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  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. package com.owncloud.android.ui.activity;
  23. import android.accounts.Account;
  24. import android.accounts.AccountManager;
  25. import android.accounts.AuthenticatorException;
  26. import android.annotation.TargetApi;
  27. import android.app.AlertDialog;
  28. import android.content.BroadcastReceiver;
  29. import android.content.ComponentName;
  30. import android.content.ContentResolver;
  31. import android.content.Context;
  32. import android.content.DialogInterface;
  33. import android.content.Intent;
  34. import android.content.IntentFilter;
  35. import android.content.ServiceConnection;
  36. import android.content.SharedPreferences;
  37. import android.content.SyncRequest;
  38. import android.content.res.Resources.NotFoundException;
  39. import android.database.Cursor;
  40. import android.net.Uri;
  41. import android.os.Build;
  42. import android.os.Bundle;
  43. import android.os.IBinder;
  44. import android.preference.PreferenceManager;
  45. import android.provider.OpenableColumns;
  46. import android.support.v4.app.Fragment;
  47. import android.support.v4.app.FragmentManager;
  48. import android.support.v4.app.FragmentTransaction;
  49. import android.support.v4.view.GravityCompat;
  50. import android.support.v7.app.ActionBar;
  51. import android.view.Menu;
  52. import android.view.MenuInflater;
  53. import android.view.MenuItem;
  54. import android.view.View;
  55. import android.view.Window;
  56. import android.widget.Toast;
  57. import com.owncloud.android.MainApp;
  58. import com.owncloud.android.R;
  59. import com.owncloud.android.datamodel.OCFile;
  60. import com.owncloud.android.files.services.FileDownloader;
  61. import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
  62. import com.owncloud.android.files.services.FileUploader;
  63. import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
  64. import com.owncloud.android.lib.common.OwnCloudAccount;
  65. import com.owncloud.android.lib.common.OwnCloudClient;
  66. import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
  67. import com.owncloud.android.lib.common.OwnCloudCredentials;
  68. import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
  69. import com.owncloud.android.lib.common.network.CertificateCombinedException;
  70. import com.owncloud.android.lib.common.operations.RemoteOperation;
  71. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  72. import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
  73. import com.owncloud.android.lib.common.utils.Log_OC;
  74. import com.owncloud.android.operations.CreateFolderOperation;
  75. import com.owncloud.android.operations.CreateShareOperation;
  76. import com.owncloud.android.operations.MoveFileOperation;
  77. import com.owncloud.android.operations.RefreshFolderOperation;
  78. import com.owncloud.android.operations.RemoveFileOperation;
  79. import com.owncloud.android.operations.RenameFileOperation;
  80. import com.owncloud.android.operations.SynchronizeFileOperation;
  81. import com.owncloud.android.operations.UnshareLinkOperation;
  82. import com.owncloud.android.services.observer.FileObserverService;
  83. import com.owncloud.android.syncadapter.FileSyncAdapter;
  84. import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
  85. import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
  86. import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
  87. import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
  88. import com.owncloud.android.ui.dialog.UploadSourceDialogFragment;
  89. import com.owncloud.android.ui.fragment.FileDetailFragment;
  90. import com.owncloud.android.ui.fragment.FileFragment;
  91. import com.owncloud.android.ui.fragment.OCFileListFragment;
  92. import com.owncloud.android.ui.preview.PreviewImageActivity;
  93. import com.owncloud.android.ui.preview.PreviewImageFragment;
  94. import com.owncloud.android.ui.preview.PreviewMediaFragment;
  95. import com.owncloud.android.ui.preview.PreviewVideoActivity;
  96. import com.owncloud.android.utils.DisplayUtils;
  97. import com.owncloud.android.utils.ErrorMessageAdapter;
  98. import com.owncloud.android.utils.FileStorageUtils;
  99. import com.owncloud.android.utils.UriUtils;
  100. import java.io.File;
  101. /**
  102. * Displays, what files the user has available in his ownCloud.
  103. */
  104. public class FileDisplayActivity extends HookActivity
  105. implements FileFragment.ContainerActivity,
  106. OnSslUntrustedCertListener, OnEnforceableRefreshListener {
  107. private SyncBroadcastReceiver mSyncBroadcastReceiver;
  108. private UploadFinishReceiver mUploadFinishReceiver;
  109. private DownloadFinishReceiver mDownloadFinishReceiver;
  110. private RemoteOperationResult mLastSslUntrustedServerResult = null;
  111. private boolean mDualPane;
  112. private View mLeftFragmentContainer;
  113. private View mRightFragmentContainer;
  114. private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
  115. private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
  116. private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND";
  117. public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
  118. public static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
  119. public static final int ACTION_SELECT_MULTIPLE_FILES = 2;
  120. public static final int ACTION_MOVE_FILES = 3;
  121. private static final String TAG = FileDisplayActivity.class.getSimpleName();
  122. private static final String TAG_LIST_OF_FILES = "LIST_OF_FILES";
  123. private static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT";
  124. private OCFile mWaitingToPreview;
  125. private boolean mSyncInProgress = false;
  126. private static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";
  127. private static String DIALOG_CREATE_FOLDER = "DIALOG_CREATE_FOLDER";
  128. private static String DIALOG_UPLOAD_SOURCE = "DIALOG_UPLOAD_SOURCE";
  129. private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED";
  130. private OCFile mWaitingToSend;
  131. @Override
  132. protected void onCreate(Bundle savedInstanceState) {
  133. Log_OC.v(TAG, "onCreate() start");
  134. requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  135. super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account
  136. // is valid
  137. /// grant that FileObserverService is watching favorite files
  138. if (savedInstanceState == null) {
  139. Intent initObserversIntent = FileObserverService.makeInitIntent(this);
  140. startService(initObserversIntent);
  141. }
  142. /// Load of saved instance state
  143. if(savedInstanceState != null) {
  144. mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(
  145. FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
  146. mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
  147. mWaitingToSend = (OCFile) savedInstanceState.getParcelable(
  148. FileDisplayActivity.KEY_WAITING_TO_SEND);
  149. } else {
  150. mWaitingToPreview = null;
  151. mSyncInProgress = false;
  152. mWaitingToSend = null;
  153. }
  154. /// USER INTERFACE
  155. // Inflate and set the layout view
  156. setContentView(R.layout.files);
  157. // Navigation Drawer
  158. initDrawer();
  159. mDualPane = getResources().getBoolean(R.bool.large_land_layout);
  160. mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
  161. mRightFragmentContainer = findViewById(R.id.right_fragment_container);
  162. if (savedInstanceState == null) {
  163. createMinFragments();
  164. }
  165. // Action bar setup
  166. getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS,
  167. // according to the official
  168. // documentation
  169. setSupportProgressBarIndeterminateVisibility(mSyncInProgress
  170. /*|| mRefreshSharesInProgress*/);
  171. // always AFTER setContentView(...) ; to work around bug in its implementation
  172. setBackgroundText();
  173. Log_OC.v(TAG, "onCreate() end");
  174. }
  175. @Override
  176. protected void onStart() {
  177. Log_OC.v(TAG, "onStart() start");
  178. super.onStart();
  179. getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
  180. Log_OC.v(TAG, "onStart() end");
  181. }
  182. @Override
  183. protected void onDestroy() {
  184. Log_OC.v(TAG, "onDestroy() start");
  185. super.onDestroy();
  186. Log_OC.v(TAG, "onDestroy() end");
  187. }
  188. /**
  189. * Called when the ownCloud {@link Account} associated to the Activity was just updated.
  190. */
  191. @Override
  192. protected void onAccountSet(boolean stateWasRecovered) {
  193. super.onAccountSet(stateWasRecovered);
  194. if (getAccount() != null) {
  195. /// Check whether the 'main' OCFile handled by the Activity is contained in the
  196. // current Account
  197. OCFile file = getFile();
  198. // get parent from path
  199. String parentPath = "";
  200. if (file != null) {
  201. if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
  202. // upload in progress - right now, files are not inserted in the local
  203. // cache until the upload is successful get parent from path
  204. parentPath = file.getRemotePath().substring(0,
  205. file.getRemotePath().lastIndexOf(file.getFileName()));
  206. if (getStorageManager().getFileByPath(parentPath) == null)
  207. file = null; // not able to know the directory where the file is uploading
  208. } else {
  209. file = getStorageManager().getFileByPath(file.getRemotePath());
  210. // currentDir = null if not in the current Account
  211. }
  212. }
  213. if (file == null) {
  214. // fall back to root folder
  215. file = getStorageManager().getFileByPath(OCFile.ROOT_PATH); // never returns null
  216. }
  217. setFile(file);
  218. if (!stateWasRecovered) {
  219. Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
  220. initFragmentsWithFile();
  221. if (file.isFolder()) {
  222. startSyncFolderOperation(file, false);
  223. }
  224. } else {
  225. updateFragmentsVisibility(!file.isFolder());
  226. updateNavigationElementsInActionBar(file.isFolder() ? null : file);
  227. }
  228. }
  229. }
  230. private void createMinFragments() {
  231. OCFileListFragment listOfFiles = new OCFileListFragment();
  232. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  233. transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
  234. transaction.commit();
  235. }
  236. private void initFragmentsWithFile() {
  237. if (getAccount() != null && getFile() != null) {
  238. /// First fragment
  239. OCFileListFragment listOfFiles = getListOfFilesFragment();
  240. if (listOfFiles != null) {
  241. listOfFiles.listDirectory(getCurrentDir());
  242. // TODO Enable when "On Device" is recovered
  243. // listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice());
  244. } else {
  245. Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >(");
  246. }
  247. /// Second fragment
  248. OCFile file = getFile();
  249. Fragment secondFragment = chooseInitialSecondFragment(file);
  250. if (secondFragment != null) {
  251. setSecondFragment(secondFragment);
  252. updateFragmentsVisibility(true);
  253. updateNavigationElementsInActionBar(file);
  254. } else {
  255. cleanSecondFragment();
  256. }
  257. } else {
  258. Log_OC.wtf(TAG, "initFragments() called with invalid NULLs!");
  259. if (getAccount() == null) {
  260. Log_OC.wtf(TAG, "\t account is NULL");
  261. }
  262. if (getFile() == null) {
  263. Log_OC.wtf(TAG, "\t file is NULL");
  264. }
  265. }
  266. }
  267. private Fragment chooseInitialSecondFragment(OCFile file) {
  268. Fragment secondFragment = null;
  269. if (file != null && !file.isFolder()) {
  270. if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)
  271. && file.getLastSyncDateForProperties() > 0 // temporal fix
  272. ) {
  273. int startPlaybackPosition =
  274. getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
  275. boolean autoplay =
  276. getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
  277. secondFragment = new PreviewMediaFragment(file, getAccount(),
  278. startPlaybackPosition, autoplay);
  279. } else {
  280. secondFragment = new FileDetailFragment(file, getAccount());
  281. }
  282. }
  283. return secondFragment;
  284. }
  285. /**
  286. * Replaces the second fragment managed by the activity with the received as
  287. * a parameter.
  288. *
  289. * Assumes never will be more than two fragments managed at the same time.
  290. *
  291. * @param fragment New second Fragment to set.
  292. */
  293. private void setSecondFragment(Fragment fragment) {
  294. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  295. transaction.replace(R.id.right_fragment_container, fragment, TAG_SECOND_FRAGMENT);
  296. transaction.commit();
  297. }
  298. private void updateFragmentsVisibility(boolean existsSecondFragment) {
  299. if (mDualPane) {
  300. if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
  301. mLeftFragmentContainer.setVisibility(View.VISIBLE);
  302. }
  303. if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
  304. mRightFragmentContainer.setVisibility(View.VISIBLE);
  305. }
  306. } else if (existsSecondFragment) {
  307. if (mLeftFragmentContainer.getVisibility() != View.GONE) {
  308. mLeftFragmentContainer.setVisibility(View.GONE);
  309. }
  310. if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
  311. mRightFragmentContainer.setVisibility(View.VISIBLE);
  312. }
  313. } else {
  314. if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
  315. mLeftFragmentContainer.setVisibility(View.VISIBLE);
  316. }
  317. if (mRightFragmentContainer.getVisibility() != View.GONE) {
  318. mRightFragmentContainer.setVisibility(View.GONE);
  319. }
  320. }
  321. }
  322. private OCFileListFragment getListOfFilesFragment() {
  323. Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(
  324. FileDisplayActivity.TAG_LIST_OF_FILES);
  325. if (listOfFiles != null) {
  326. return (OCFileListFragment)listOfFiles;
  327. }
  328. Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
  329. return null;
  330. }
  331. public FileFragment getSecondFragment() {
  332. Fragment second = getSupportFragmentManager().findFragmentByTag(
  333. FileDisplayActivity.TAG_SECOND_FRAGMENT);
  334. if (second != null) {
  335. return (FileFragment)second;
  336. }
  337. return null;
  338. }
  339. protected void cleanSecondFragment() {
  340. Fragment second = getSecondFragment();
  341. if (second != null) {
  342. FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
  343. tr.remove(second);
  344. tr.commit();
  345. }
  346. updateFragmentsVisibility(false);
  347. updateNavigationElementsInActionBar(null);
  348. }
  349. protected void refreshListOfFilesFragment() {
  350. OCFileListFragment fileListFragment = getListOfFilesFragment();
  351. if (fileListFragment != null) {
  352. fileListFragment.listDirectory();
  353. // TODO Enable when "On Device" is recovered ?
  354. // fileListFragment.listDirectory(MainApp.getOnlyOnDevice());
  355. }
  356. }
  357. protected void refreshSecondFragment(String downloadEvent, String downloadedRemotePath,
  358. boolean success) {
  359. FileFragment secondFragment = getSecondFragment();
  360. boolean waitedPreview = (mWaitingToPreview != null &&
  361. mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
  362. if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
  363. FileDetailFragment detailsFragment = (FileDetailFragment) secondFragment;
  364. OCFile fileInFragment = detailsFragment.getFile();
  365. if (fileInFragment != null &&
  366. !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
  367. // the user browsed to other file ; forget the automatic preview
  368. mWaitingToPreview = null;
  369. } else if (downloadEvent.equals(FileDownloader.getDownloadAddedMessage())) {
  370. // grant that the right panel updates the progress bar
  371. detailsFragment.listenForTransferProgress();
  372. detailsFragment.updateFileDetails(true, false);
  373. } else if (downloadEvent.equals(FileDownloader.getDownloadFinishMessage())) {
  374. // update the right panel
  375. boolean detailsFragmentChanged = false;
  376. if (waitedPreview) {
  377. if (success) {
  378. mWaitingToPreview = getStorageManager().getFileById(
  379. mWaitingToPreview.getFileId()); // update the file from database,
  380. // for the local storage path
  381. if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
  382. startMediaPreview(mWaitingToPreview, 0, true);
  383. detailsFragmentChanged = true;
  384. } else {
  385. getFileOperationsHelper().openFile(mWaitingToPreview);
  386. }
  387. }
  388. mWaitingToPreview = null;
  389. }
  390. if (!detailsFragmentChanged) {
  391. detailsFragment.updateFileDetails(false, (success));
  392. }
  393. }
  394. }
  395. }
  396. @Override
  397. public boolean onPrepareOptionsMenu(Menu menu) {
  398. boolean drawerOpen = mDrawerLayout.isDrawerOpen(GravityCompat.START);
  399. menu.findItem(R.id.action_upload).setVisible(!drawerOpen);
  400. menu.findItem(R.id.action_create_dir).setVisible(!drawerOpen);
  401. menu.findItem(R.id.action_sort).setVisible(!drawerOpen);
  402. menu.findItem(R.id.action_sync_account).setVisible(!drawerOpen);
  403. return super.onPrepareOptionsMenu(menu);
  404. }
  405. @Override
  406. public boolean onCreateOptionsMenu(Menu menu) {
  407. MenuInflater inflater = getMenuInflater();
  408. inflater.inflate(R.menu.main_menu, menu);
  409. return true;
  410. }
  411. @Override
  412. public boolean onOptionsItemSelected(MenuItem item) {
  413. boolean retval = true;
  414. switch (item.getItemId()) {
  415. case R.id.action_create_dir: {
  416. CreateFolderDialogFragment dialog =
  417. CreateFolderDialogFragment.newInstance(getCurrentDir());
  418. dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER);
  419. break;
  420. }
  421. case R.id.action_sync_account: {
  422. startSynchronization();
  423. break;
  424. }
  425. case R.id.action_upload: {
  426. UploadSourceDialogFragment dialog =
  427. UploadSourceDialogFragment.newInstance(getAccount());
  428. dialog.show(getSupportFragmentManager(), DIALOG_UPLOAD_SOURCE);
  429. break;
  430. }
  431. case android.R.id.home: {
  432. FileFragment second = getSecondFragment();
  433. OCFile currentDir = getCurrentDir();
  434. if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
  435. mDrawerLayout.closeDrawer(GravityCompat.START);
  436. } else if((currentDir != null && currentDir.getParentId() != 0) ||
  437. (second != null && second.getFile() != null)) {
  438. onBackPressed();
  439. } else {
  440. mDrawerLayout.openDrawer(GravityCompat.START);
  441. }
  442. break;
  443. }
  444. case R.id.action_sort: {
  445. SharedPreferences appPreferences = PreferenceManager
  446. .getDefaultSharedPreferences(this);
  447. // Read sorting order, default to sort by name ascending
  448. Integer sortOrder = appPreferences
  449. .getInt("sortOrder", FileStorageUtils.SORT_NAME);
  450. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  451. builder.setTitle(R.string.actionbar_sort_title)
  452. .setSingleChoiceItems(R.array.actionbar_sortby, sortOrder ,
  453. new DialogInterface.OnClickListener() {
  454. public void onClick(DialogInterface dialog, int which) {
  455. switch (which){
  456. case 0:
  457. sortByName(true);
  458. break;
  459. case 1:
  460. sortByDate(false);
  461. break;
  462. }
  463. dialog.dismiss();
  464. }
  465. });
  466. builder.create().show();
  467. break;
  468. }
  469. default:
  470. retval = super.onOptionsItemSelected(item);
  471. }
  472. return retval;
  473. }
  474. private void startSynchronization() {
  475. Log_OC.d(TAG, "Got to start sync");
  476. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
  477. Log_OC.d(TAG, "Canceling all syncs for " + MainApp.getAuthority());
  478. ContentResolver.cancelSync(null, MainApp.getAuthority());
  479. // cancel the current synchronizations of any ownCloud account
  480. Bundle bundle = new Bundle();
  481. bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
  482. bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
  483. Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
  484. MainApp.getAuthority());
  485. ContentResolver.requestSync(
  486. getAccount(),
  487. MainApp.getAuthority(), bundle);
  488. } else {
  489. Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
  490. MainApp.getAuthority() + " with new API");
  491. SyncRequest.Builder builder = new SyncRequest.Builder();
  492. builder.setSyncAdapter(getAccount(), MainApp.getAuthority());
  493. builder.setExpedited(true);
  494. builder.setManual(true);
  495. builder.syncOnce();
  496. // Fix bug in Android Lollipop when you click on refresh the whole account
  497. Bundle extras = new Bundle();
  498. builder.setExtras(extras);
  499. SyncRequest request = builder.build();
  500. ContentResolver.requestSync(request);
  501. }
  502. }
  503. /**
  504. * Called, when the user selected something for uploading
  505. *
  506. */
  507. @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  508. @Override
  509. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  510. if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK ||
  511. resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
  512. //getClipData is only supported on api level 16+, Jelly Bean
  513. if (data.getData() == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
  514. for( int i = 0; i < data.getClipData().getItemCount(); i++){
  515. Intent intent = new Intent();
  516. intent.setData(data.getClipData().getItemAt(i).getUri());
  517. requestSimpleUpload(intent, resultCode);
  518. }
  519. }else {
  520. requestSimpleUpload(data, resultCode);
  521. }
  522. } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK ||
  523. resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
  524. requestMultipleUpload(data, resultCode);
  525. } else if (requestCode == ACTION_MOVE_FILES && resultCode == RESULT_OK){
  526. final Intent fData = data;
  527. final int fResultCode = resultCode;
  528. getHandler().postDelayed(
  529. new Runnable() {
  530. @Override
  531. public void run() {
  532. requestMoveOperation(fData, fResultCode);
  533. }
  534. },
  535. DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
  536. );
  537. } else {
  538. super.onActivityResult(requestCode, resultCode, data);
  539. }
  540. }
  541. private void requestMultipleUpload(Intent data, int resultCode) {
  542. String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
  543. if (filePaths != null) {
  544. String[] remotePaths = new String[filePaths.length];
  545. String remotePathBase = "";
  546. if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR))
  547. remotePathBase += OCFile.PATH_SEPARATOR;
  548. for (int j = 0; j< remotePaths.length; j++) {
  549. remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
  550. }
  551. Intent i = new Intent(this, FileUploader.class);
  552. i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
  553. i.putExtra(FileUploader.KEY_LOCAL_FILE, filePaths);
  554. i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
  555. i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
  556. if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
  557. i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
  558. startService(i);
  559. } else {
  560. Log_OC.d(TAG, "User clicked on 'Update' with no selection");
  561. Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected),
  562. Toast.LENGTH_LONG);
  563. t.show();
  564. return;
  565. }
  566. }
  567. private void requestSimpleUpload(Intent data, int resultCode) {
  568. String filePath = null;
  569. String mimeType = null;
  570. Uri selectedImageUri = data.getData();
  571. try {
  572. mimeType = getContentResolver().getType(selectedImageUri);
  573. String fileManagerString = selectedImageUri.getPath();
  574. String selectedImagePath = UriUtils.getLocalPath(selectedImageUri, this);
  575. if (selectedImagePath != null)
  576. filePath = selectedImagePath;
  577. else
  578. filePath = fileManagerString;
  579. } catch (Exception e) {
  580. Log_OC.e(TAG, "Unexpected exception when trying to read the result of " +
  581. "Intent.ACTION_GET_CONTENT", e);
  582. } finally {
  583. if (filePath == null) {
  584. Log_OC.e(TAG, "Couldn't resolve path to file");
  585. Toast t = Toast.makeText(
  586. this, getString(R.string.filedisplay_unexpected_bad_get_content),
  587. Toast.LENGTH_LONG
  588. );
  589. t.show();
  590. return;
  591. }
  592. }
  593. Intent i = new Intent(this, FileUploader.class);
  594. i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
  595. OCFile currentDir = getCurrentDir();
  596. String remotePath = (currentDir != null) ? currentDir.getRemotePath() : OCFile.ROOT_PATH;
  597. if (filePath.startsWith(UriUtils.URI_CONTENT_SCHEME)) {
  598. Cursor cursor = getContentResolver().query(Uri.parse(filePath), null, null, null, null);
  599. try {
  600. if (cursor != null && cursor.moveToFirst()) {
  601. String displayName = cursor.getString(cursor.getColumnIndex(
  602. OpenableColumns.DISPLAY_NAME));
  603. Log_OC.v(TAG, "Display Name: " + displayName );
  604. displayName.replace(File.separatorChar, '_');
  605. displayName.replace(File.pathSeparatorChar, '_');
  606. remotePath += displayName + DisplayUtils.getComposedFileExtension(filePath);
  607. }
  608. // and what happens in case of error?; wrong target name for the upload
  609. } finally {
  610. cursor.close();
  611. }
  612. } else {
  613. remotePath += new File(filePath).getName();
  614. }
  615. i.putExtra(FileUploader.KEY_LOCAL_FILE, filePath);
  616. i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePath);
  617. i.putExtra(FileUploader.KEY_MIME_TYPE, mimeType);
  618. i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
  619. if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
  620. i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
  621. startService(i);
  622. }
  623. /**
  624. * Request the operation for moving the file/folder from one path to another
  625. *
  626. * @param data Intent received
  627. * @param resultCode Result code received
  628. */
  629. private void requestMoveOperation(Intent data, int resultCode) {
  630. OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
  631. OCFile targetFile = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FILE);
  632. getFileOperationsHelper().moveFile(folderToMoveAt, targetFile);
  633. }
  634. @Override
  635. public void onBackPressed() {
  636. OCFileListFragment listOfFiles = getListOfFilesFragment();
  637. if (mDualPane || getSecondFragment() == null) {
  638. if (listOfFiles != null) { // should never be null, indeed
  639. listOfFiles.onBrowseUp();
  640. }
  641. }
  642. if (listOfFiles != null) { // should never be null, indeed
  643. setFile(listOfFiles.getCurrentFile());
  644. }
  645. updateActionBarTitle();
  646. cleanSecondFragment();
  647. }
  648. @Override
  649. protected void onSaveInstanceState(Bundle outState) {
  650. // responsibility of restore is preferred in onCreate() before than in
  651. // onRestoreInstanceState when there are Fragments involved
  652. Log_OC.v(TAG, "onSaveInstanceState() start");
  653. super.onSaveInstanceState(outState);
  654. outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
  655. outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress);
  656. //outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS,
  657. // mRefreshSharesInProgress);
  658. outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend);
  659. Log_OC.v(TAG, "onSaveInstanceState() end");
  660. }
  661. @Override
  662. protected void onResume() {
  663. Log_OC.v(TAG, "onResume() start");
  664. super.onResume();
  665. // refresh Navigation Drawer account list
  666. mNavigationDrawerAdapter.updateAccountList();
  667. // refresh list of files
  668. refreshListOfFilesFragment();
  669. // Listen for sync messages
  670. IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
  671. syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
  672. syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
  673. syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
  674. syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
  675. mSyncBroadcastReceiver = new SyncBroadcastReceiver();
  676. registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
  677. //LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver,
  678. // syncIntentFilter);
  679. // Listen for upload messages
  680. IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
  681. mUploadFinishReceiver = new UploadFinishReceiver();
  682. registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
  683. // Listen for download messages
  684. IntentFilter downloadIntentFilter = new IntentFilter(
  685. FileDownloader.getDownloadAddedMessage());
  686. downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
  687. mDownloadFinishReceiver = new DownloadFinishReceiver();
  688. registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
  689. Log_OC.v(TAG, "onResume() end");
  690. }
  691. @Override
  692. protected void onPause() {
  693. Log_OC.v(TAG, "onPause() start");
  694. if (mSyncBroadcastReceiver != null) {
  695. unregisterReceiver(mSyncBroadcastReceiver);
  696. //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
  697. mSyncBroadcastReceiver = null;
  698. }
  699. if (mUploadFinishReceiver != null) {
  700. unregisterReceiver(mUploadFinishReceiver);
  701. mUploadFinishReceiver = null;
  702. }
  703. if (mDownloadFinishReceiver != null) {
  704. unregisterReceiver(mDownloadFinishReceiver);
  705. mDownloadFinishReceiver = null;
  706. }
  707. super.onPause();
  708. Log_OC.v(TAG, "onPause() end");
  709. }
  710. private class SyncBroadcastReceiver extends BroadcastReceiver {
  711. /**
  712. * {@link BroadcastReceiver} to enable syncing feedback in UI
  713. */
  714. @Override
  715. public void onReceive(Context context, Intent intent) {
  716. try {
  717. String event = intent.getAction();
  718. Log_OC.d(TAG, "Received broadcast " + event);
  719. String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
  720. String synchFolderRemotePath =
  721. intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
  722. RemoteOperationResult synchResult =
  723. (RemoteOperationResult)intent.getSerializableExtra(
  724. FileSyncAdapter.EXTRA_RESULT);
  725. boolean sameAccount = (getAccount() != null &&
  726. accountName.equals(getAccount().name) && getStorageManager() != null);
  727. if (sameAccount) {
  728. if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
  729. mSyncInProgress = true;
  730. } else {
  731. OCFile currentFile = (getFile() == null) ? null :
  732. getStorageManager().getFileByPath(getFile().getRemotePath());
  733. OCFile currentDir = (getCurrentDir() == null) ? null :
  734. getStorageManager().getFileByPath(getCurrentDir().getRemotePath());
  735. if (currentDir == null) {
  736. // current folder was removed from the server
  737. Toast.makeText( FileDisplayActivity.this,
  738. String.format(
  739. getString(R.string.
  740. sync_current_folder_was_removed),
  741. synchFolderRemotePath),
  742. Toast.LENGTH_LONG)
  743. .show();
  744. browseToRoot();
  745. } else {
  746. if (currentFile == null && !getFile().isFolder()) {
  747. // currently selected file was removed in the server, and now we
  748. // know it
  749. cleanSecondFragment();
  750. currentFile = currentDir;
  751. }
  752. if (synchFolderRemotePath != null &&
  753. currentDir.getRemotePath().equals(synchFolderRemotePath)) {
  754. OCFileListFragment fileListFragment = getListOfFilesFragment();
  755. if (fileListFragment != null) {
  756. fileListFragment.listDirectory();
  757. // TODO Enable when "On Device" is recovered ?
  758. // fileListFragment.listDirectory(currentDir,
  759. // MainApp.getOnlyOnDevice());
  760. }
  761. }
  762. setFile(currentFile);
  763. }
  764. mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
  765. !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED
  766. .equals(event));
  767. if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
  768. equals(event) &&
  769. /// TODO refactor and make common
  770. synchResult != null && !synchResult.isSuccess() &&
  771. (synchResult.getCode() == ResultCode.UNAUTHORIZED ||
  772. synchResult.isIdPRedirection() ||
  773. (synchResult.isException() && synchResult.getException()
  774. instanceof AuthenticatorException))) {
  775. try {
  776. OwnCloudClient client;
  777. OwnCloudAccount ocAccount =
  778. new OwnCloudAccount(getAccount(), context);
  779. client = (OwnCloudClientManagerFactory.getDefaultSingleton().
  780. removeClientFor(ocAccount));
  781. if (client != null) {
  782. OwnCloudCredentials cred = client.getCredentials();
  783. if (cred != null) {
  784. AccountManager am = AccountManager.get(context);
  785. if (cred.authTokenExpires()) {
  786. am.invalidateAuthToken(
  787. getAccount().type,
  788. cred.getAuthToken()
  789. );
  790. } else {
  791. am.clearPassword(getAccount());
  792. }
  793. }
  794. }
  795. requestCredentialsUpdate();
  796. } catch (AccountNotFoundException e) {
  797. Log_OC.e(TAG, "Account " + getAccount() + " was removed!", e);
  798. }
  799. }
  800. }
  801. removeStickyBroadcast(intent);
  802. Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
  803. setSupportProgressBarIndeterminateVisibility(mSyncInProgress
  804. /*|| mRefreshSharesInProgress*/);
  805. setBackgroundText();
  806. }
  807. if (synchResult != null) {
  808. if (synchResult.getCode().equals(
  809. RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
  810. mLastSslUntrustedServerResult = synchResult;
  811. }
  812. }
  813. } catch (RuntimeException e) {
  814. // avoid app crashes after changing the serial id of RemoteOperationResult
  815. // in owncloud library with broadcast notifications pending to process
  816. removeStickyBroadcast(intent);
  817. }
  818. }
  819. }
  820. /**
  821. * Show a text message on screen view for notifying user if content is
  822. * loading or folder is empty
  823. */
  824. private void setBackgroundText() {
  825. OCFileListFragment ocFileListFragment = getListOfFilesFragment();
  826. if (ocFileListFragment != null) {
  827. int message = R.string.file_list_loading;
  828. if (!mSyncInProgress) {
  829. // In case file list is empty
  830. message = R.string.file_list_empty;
  831. }
  832. ocFileListFragment.setMessageForEmptyList(getString(message));
  833. } else {
  834. Log_OC.e(TAG, "OCFileListFragment is null");
  835. }
  836. }
  837. /**
  838. * Once the file upload has finished -> update view
  839. */
  840. private class UploadFinishReceiver extends BroadcastReceiver {
  841. /**
  842. * Once the file upload has finished -> update view
  843. * @author David A. Velasco
  844. * {@link BroadcastReceiver} to enable upload feedback in UI
  845. */
  846. @Override
  847. public void onReceive(Context context, Intent intent) {
  848. try {
  849. String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
  850. String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
  851. boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
  852. OCFile currentDir = getCurrentDir();
  853. boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) &&
  854. (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
  855. if (sameAccount && isDescendant) {
  856. refreshListOfFilesFragment();
  857. }
  858. boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT,
  859. false);
  860. boolean renamedInUpload = getFile().getRemotePath().
  861. equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
  862. boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
  863. renamedInUpload;
  864. FileFragment details = getSecondFragment();
  865. boolean detailFragmentIsShown = (details != null &&
  866. details instanceof FileDetailFragment);
  867. if (sameAccount && sameFile && detailFragmentIsShown) {
  868. if (uploadWasFine) {
  869. setFile(getStorageManager().getFileByPath(uploadedRemotePath));
  870. }
  871. if (renamedInUpload) {
  872. String newName = (new File(uploadedRemotePath)).getName();
  873. Toast msg = Toast.makeText(
  874. context,
  875. String.format(
  876. getString(R.string.filedetails_renamed_in_upload_msg),
  877. newName),
  878. Toast.LENGTH_LONG);
  879. msg.show();
  880. }
  881. if (uploadWasFine || getFile().fileExists()) {
  882. ((FileDetailFragment)details).updateFileDetails(false, true);
  883. } else {
  884. cleanSecondFragment();
  885. }
  886. // Force the preview if the file is an image
  887. if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
  888. startImagePreview(getFile());
  889. } // TODO what about other kind of previews?
  890. }
  891. } finally {
  892. if (intent != null) {
  893. removeStickyBroadcast(intent);
  894. }
  895. }
  896. }
  897. }
  898. /**
  899. * Class waiting for broadcast events from the {@link FileDownloader} service.
  900. *
  901. * Updates the UI when a download is started or finished, provided that it is relevant for the
  902. * current folder.
  903. */
  904. private class DownloadFinishReceiver extends BroadcastReceiver {
  905. //int refreshCounter = 0;
  906. @Override
  907. public void onReceive(Context context, Intent intent) {
  908. try {
  909. boolean sameAccount = isSameAccount(context, intent);
  910. String downloadedRemotePath =
  911. intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
  912. boolean isDescendant = isDescendant(downloadedRemotePath);
  913. if (sameAccount && isDescendant) {
  914. String linkedToRemotePath =
  915. intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
  916. if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
  917. //Log_OC.v(TAG, "refresh #" + ++refreshCounter);
  918. refreshListOfFilesFragment();
  919. }
  920. refreshSecondFragment(
  921. intent.getAction(),
  922. downloadedRemotePath,
  923. intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)
  924. );
  925. }
  926. if (mWaitingToSend != null) {
  927. mWaitingToSend =
  928. getStorageManager().getFileByPath(mWaitingToSend.getRemotePath());
  929. if (mWaitingToSend.isDown()) {
  930. sendDownloadedFile();
  931. }
  932. }
  933. } finally {
  934. if (intent != null) {
  935. removeStickyBroadcast(intent);
  936. }
  937. }
  938. }
  939. private boolean isDescendant(String downloadedRemotePath) {
  940. OCFile currentDir = getCurrentDir();
  941. return (
  942. currentDir != null &&
  943. downloadedRemotePath != null &&
  944. downloadedRemotePath.startsWith(currentDir.getRemotePath())
  945. );
  946. }
  947. private boolean isAscendant(String linkedToRemotePath) {
  948. OCFile currentDir = getCurrentDir();
  949. return (
  950. currentDir != null &&
  951. currentDir.getRemotePath().startsWith(linkedToRemotePath)
  952. );
  953. }
  954. private boolean isSameAccount(Context context, Intent intent) {
  955. String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
  956. return (accountName != null && getAccount() != null &&
  957. accountName.equals(getAccount().name));
  958. }
  959. }
  960. public void browseToRoot() {
  961. OCFileListFragment listOfFiles = getListOfFilesFragment();
  962. if (listOfFiles != null) { // should never be null, indeed
  963. OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
  964. listOfFiles.listDirectory(root);
  965. // TODO Enable when "On Device" is recovered ?
  966. // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice());
  967. setFile(listOfFiles.getCurrentFile());
  968. startSyncFolderOperation(root, false);
  969. updateActionBarTitle();
  970. }
  971. cleanSecondFragment();
  972. }
  973. /**
  974. * {@inheritDoc}
  975. *
  976. * Updates action bar and second fragment, if in dual pane mode.
  977. */
  978. @Override
  979. public void onBrowsedDownTo(OCFile directory) {
  980. cleanSecondFragment();
  981. setFile(directory);
  982. updateActionBarTitle();
  983. // Sync Folder
  984. startSyncFolderOperation(directory, false);
  985. }
  986. /**
  987. * Shows the information of the {@link OCFile} received as a
  988. * parameter in the second fragment.
  989. *
  990. * @param file {@link OCFile} whose details will be shown
  991. */
  992. @Override
  993. public void showDetails(OCFile file) {
  994. Fragment detailFragment = new FileDetailFragment(file, getAccount());
  995. setSecondFragment(detailFragment);
  996. updateFragmentsVisibility(true);
  997. updateNavigationElementsInActionBar(file);
  998. setFile(file);
  999. }
  1000. /**
  1001. * TODO
  1002. */
  1003. private void updateNavigationElementsInActionBar(OCFile chosenFile) {
  1004. ActionBar actionBar = getSupportActionBar();
  1005. // For adding content description tag to a title field in the action bar
  1006. int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
  1007. if (chosenFile == null || mDualPane) {
  1008. // only list of files - set for browsing through folders
  1009. OCFile currentDir = getCurrentDir();
  1010. boolean noRoot = (currentDir != null && currentDir.getParentId() != 0);
  1011. // actionBar.setDisplayHomeAsUpEnabled(noRoot);
  1012. // actionBar.setDisplayShowTitleEnabled(!noRoot);
  1013. actionBar.setDisplayHomeAsUpEnabled(true);
  1014. actionBar.setDisplayShowTitleEnabled(true);
  1015. if (!noRoot) {
  1016. actionBar.setTitle(getString(R.string.default_display_name_for_root_folder));
  1017. View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
  1018. if (actionBarTitleView != null) { // it's null in Android 2.x
  1019. actionBarTitleView.setContentDescription(
  1020. getString(R.string.default_display_name_for_root_folder));
  1021. }
  1022. }
  1023. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
  1024. } else {
  1025. actionBar.setDisplayHomeAsUpEnabled(true);
  1026. actionBar.setDisplayShowTitleEnabled(true);
  1027. actionBar.setTitle(chosenFile.getFileName());
  1028. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
  1029. View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
  1030. if (actionBarTitleView != null) { // it's null in Android 2.x
  1031. getWindow().getDecorView().findViewById(actionBarTitleId).
  1032. setContentDescription(chosenFile.getFileName());
  1033. }
  1034. }
  1035. }
  1036. @Override
  1037. protected ServiceConnection newTransferenceServiceConnection() {
  1038. return new ListServiceConnection();
  1039. }
  1040. /** Defines callbacks for service binding, passed to bindService() */
  1041. private class ListServiceConnection implements ServiceConnection {
  1042. @Override
  1043. public void onServiceConnected(ComponentName component, IBinder service) {
  1044. if (component.equals(new ComponentName(
  1045. FileDisplayActivity.this, FileDownloader.class))) {
  1046. Log_OC.d(TAG, "Download service connected");
  1047. mDownloaderBinder = (FileDownloaderBinder) service;
  1048. if (mWaitingToPreview != null)
  1049. if (getStorageManager() != null) {
  1050. // update the file
  1051. mWaitingToPreview =
  1052. getStorageManager().getFileById(mWaitingToPreview.getFileId());
  1053. if (!mWaitingToPreview.isDown()) {
  1054. requestForDownload();
  1055. }
  1056. }
  1057. } else if (component.equals(new ComponentName(FileDisplayActivity.this,
  1058. FileUploader.class))) {
  1059. Log_OC.d(TAG, "Upload service connected");
  1060. mUploaderBinder = (FileUploaderBinder) service;
  1061. } else {
  1062. return;
  1063. }
  1064. // a new chance to get the mDownloadBinder through
  1065. // getFileDownloadBinder() - THIS IS A MESS
  1066. OCFileListFragment listOfFiles = getListOfFilesFragment();
  1067. if (listOfFiles != null) {
  1068. listOfFiles.listDirectory();
  1069. // TODO Enable when "On Device" is recovered ?
  1070. // listOfFiles.listDirectory(MainApp.getOnlyOnDevice());
  1071. }
  1072. FileFragment secondFragment = getSecondFragment();
  1073. if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
  1074. FileDetailFragment detailFragment = (FileDetailFragment)secondFragment;
  1075. detailFragment.listenForTransferProgress();
  1076. detailFragment.updateFileDetails(false, false);
  1077. }
  1078. }
  1079. @Override
  1080. public void onServiceDisconnected(ComponentName component) {
  1081. if (component.equals(new ComponentName(FileDisplayActivity.this,
  1082. FileDownloader.class))) {
  1083. Log_OC.d(TAG, "Download service disconnected");
  1084. mDownloaderBinder = null;
  1085. } else if (component.equals(new ComponentName(FileDisplayActivity.this,
  1086. FileUploader.class))) {
  1087. Log_OC.d(TAG, "Upload service disconnected");
  1088. mUploaderBinder = null;
  1089. }
  1090. }
  1091. };
  1092. @Override
  1093. public void onSavedCertificate() {
  1094. startSyncFolderOperation(getCurrentDir(), false);
  1095. }
  1096. @Override
  1097. public void onFailedSavingCertificate() {
  1098. ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(
  1099. R.string.ssl_validator_not_saved, new String[]{}, R.string.common_ok, -1, -1
  1100. );
  1101. dialog.show(getSupportFragmentManager(), DIALOG_CERT_NOT_SAVED);
  1102. }
  1103. @Override
  1104. public void onCancelCertificate() {
  1105. // nothing to do
  1106. }
  1107. /**
  1108. * Updates the view associated to the activity after the finish of some operation over files
  1109. * in the current account.
  1110. *
  1111. * @param operation Removal operation performed.
  1112. * @param result Result of the removal.
  1113. */
  1114. @Override
  1115. public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
  1116. super.onRemoteOperationFinish(operation, result);
  1117. if (operation instanceof RemoveFileOperation) {
  1118. onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
  1119. } else if (operation instanceof RenameFileOperation) {
  1120. onRenameFileOperationFinish((RenameFileOperation)operation, result);
  1121. } else if (operation instanceof SynchronizeFileOperation) {
  1122. onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
  1123. } else if (operation instanceof CreateFolderOperation) {
  1124. onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
  1125. } else if (operation instanceof CreateShareOperation) {
  1126. onCreateShareOperationFinish((CreateShareOperation) operation, result);
  1127. } else if (operation instanceof UnshareLinkOperation) {
  1128. onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
  1129. } else if (operation instanceof MoveFileOperation) {
  1130. onMoveFileOperationFinish((MoveFileOperation)operation, result);
  1131. }
  1132. }
  1133. private void onCreateShareOperationFinish(CreateShareOperation operation,
  1134. RemoteOperationResult result) {
  1135. if (result.isSuccess()) {
  1136. refreshShowDetails();
  1137. refreshListOfFilesFragment();
  1138. }
  1139. }
  1140. private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
  1141. RemoteOperationResult result) {
  1142. if (result.isSuccess()) {
  1143. refreshShowDetails();
  1144. refreshListOfFilesFragment();
  1145. } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
  1146. cleanSecondFragment();
  1147. refreshListOfFilesFragment();
  1148. }
  1149. }
  1150. private void refreshShowDetails() {
  1151. FileFragment details = getSecondFragment();
  1152. if (details != null) {
  1153. OCFile file = details.getFile();
  1154. if (file != null) {
  1155. file = getStorageManager().getFileByPath(file.getRemotePath());
  1156. if (details instanceof PreviewMediaFragment) {
  1157. // Refresh OCFile of the fragment
  1158. ((PreviewMediaFragment) details).updateFile(file);
  1159. } else {
  1160. showDetails(file);
  1161. }
  1162. }
  1163. invalidateOptionsMenu();
  1164. }
  1165. }
  1166. /**
  1167. * Updates the view associated to the activity after the finish of an operation trying to
  1168. * remove a file.
  1169. *
  1170. * @param operation Removal operation performed.
  1171. * @param result Result of the removal.
  1172. */
  1173. private void onRemoveFileOperationFinish(RemoveFileOperation operation,
  1174. RemoteOperationResult result) {
  1175. dismissLoadingDialog();
  1176. Toast msg = Toast.makeText(this,
  1177. ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
  1178. Toast.LENGTH_LONG);
  1179. msg.show();
  1180. if (result.isSuccess()) {
  1181. OCFile removedFile = operation.getFile();
  1182. FileFragment second = getSecondFragment();
  1183. if (second != null && removedFile.equals(second.getFile())) {
  1184. if (second instanceof PreviewMediaFragment) {
  1185. ((PreviewMediaFragment)second).stopPreview(true);
  1186. }
  1187. setFile(getStorageManager().getFileById(removedFile.getParentId()));
  1188. cleanSecondFragment();
  1189. }
  1190. if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) {
  1191. refreshListOfFilesFragment();
  1192. }
  1193. invalidateOptionsMenu();
  1194. } else {
  1195. if (result.isSslRecoverableException()) {
  1196. mLastSslUntrustedServerResult = result;
  1197. showUntrustedCertDialog(mLastSslUntrustedServerResult);
  1198. }
  1199. }
  1200. }
  1201. /**
  1202. * Updates the view associated to the activity after the finish of an operation trying to move a
  1203. * file.
  1204. *
  1205. * @param operation Move operation performed.
  1206. * @param result Result of the move operation.
  1207. */
  1208. private void onMoveFileOperationFinish(MoveFileOperation operation,
  1209. RemoteOperationResult result) {
  1210. if (result.isSuccess()) {
  1211. dismissLoadingDialog();
  1212. refreshListOfFilesFragment();
  1213. } else {
  1214. dismissLoadingDialog();
  1215. try {
  1216. Toast msg = Toast.makeText(FileDisplayActivity.this,
  1217. ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
  1218. Toast.LENGTH_LONG);
  1219. msg.show();
  1220. } catch (NotFoundException e) {
  1221. Log_OC.e(TAG, "Error while trying to show fail message " , e);
  1222. }
  1223. }
  1224. }
  1225. /**
  1226. * Updates the view associated to the activity after the finish of an operation trying to rename
  1227. * a file.
  1228. *
  1229. * @param operation Renaming operation performed.
  1230. * @param result Result of the renaming.
  1231. */
  1232. private void onRenameFileOperationFinish(RenameFileOperation operation,
  1233. RemoteOperationResult result) {
  1234. dismissLoadingDialog();
  1235. OCFile renamedFile = operation.getFile();
  1236. if (result.isSuccess()) {
  1237. FileFragment details = getSecondFragment();
  1238. if (details != null) {
  1239. if (details instanceof FileDetailFragment &&
  1240. renamedFile.equals(details.getFile()) ) {
  1241. ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
  1242. showDetails(renamedFile);
  1243. } else if (details instanceof PreviewMediaFragment &&
  1244. renamedFile.equals(details.getFile())) {
  1245. ((PreviewMediaFragment) details).updateFile(renamedFile);
  1246. if (PreviewMediaFragment.canBePreviewed(renamedFile)) {
  1247. int position = ((PreviewMediaFragment)details).getPosition();
  1248. startMediaPreview(renamedFile, position, true);
  1249. } else {
  1250. getFileOperationsHelper().openFile(renamedFile);
  1251. }
  1252. }
  1253. }
  1254. if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())){
  1255. refreshListOfFilesFragment();
  1256. }
  1257. } else {
  1258. Toast msg = Toast.makeText(this,
  1259. ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
  1260. Toast.LENGTH_LONG);
  1261. msg.show();
  1262. if (result.isSslRecoverableException()) {
  1263. mLastSslUntrustedServerResult = result;
  1264. showUntrustedCertDialog(mLastSslUntrustedServerResult);
  1265. }
  1266. }
  1267. }
  1268. private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation,
  1269. RemoteOperationResult result) {
  1270. dismissLoadingDialog();
  1271. OCFile syncedFile = operation.getLocalFile();
  1272. if (!result.isSuccess()) {
  1273. if (result.getCode() == ResultCode.SYNC_CONFLICT) {
  1274. Intent i = new Intent(this, ConflictsResolveActivity.class);
  1275. i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);
  1276. i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, getAccount());
  1277. startActivity(i);
  1278. }
  1279. } else {
  1280. if (operation.transferWasRequested()) {
  1281. onTransferStateChanged(syncedFile, true, true);
  1282. } else {
  1283. Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
  1284. operation, getResources()), Toast.LENGTH_LONG);
  1285. msg.show();
  1286. }
  1287. }
  1288. }
  1289. /**
  1290. * Updates the view associated to the activity after the finish of an operation trying create a
  1291. * new folder
  1292. *
  1293. * @param operation Creation operation performed.
  1294. * @param result Result of the creation.
  1295. */
  1296. private void onCreateFolderOperationFinish(CreateFolderOperation operation,
  1297. RemoteOperationResult result) {
  1298. if (result.isSuccess()) {
  1299. dismissLoadingDialog();
  1300. refreshListOfFilesFragment();
  1301. } else {
  1302. dismissLoadingDialog();
  1303. try {
  1304. Toast msg = Toast.makeText(FileDisplayActivity.this,
  1305. ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
  1306. Toast.LENGTH_LONG);
  1307. msg.show();
  1308. } catch (NotFoundException e) {
  1309. Log_OC.e(TAG, "Error while trying to show fail message " , e);
  1310. }
  1311. }
  1312. }
  1313. /**
  1314. * {@inheritDoc}
  1315. */
  1316. @Override
  1317. public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
  1318. refreshListOfFilesFragment();
  1319. FileFragment details = getSecondFragment();
  1320. if (details != null && details instanceof FileDetailFragment &&
  1321. file.equals(details.getFile()) ) {
  1322. if (downloading || uploading) {
  1323. ((FileDetailFragment)details).updateFileDetails(file, getAccount());
  1324. } else {
  1325. if (!file.fileExists()) {
  1326. cleanSecondFragment();
  1327. } else {
  1328. ((FileDetailFragment)details).updateFileDetails(false, true);
  1329. }
  1330. }
  1331. }
  1332. }
  1333. private void requestForDownload() {
  1334. Account account = getAccount();
  1335. //if (!mWaitingToPreview.isDownloading()) {
  1336. if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
  1337. Intent i = new Intent(this, FileDownloader.class);
  1338. i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
  1339. i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
  1340. startService(i);
  1341. }
  1342. }
  1343. private OCFile getCurrentDir() {
  1344. OCFile file = getFile();
  1345. if (file != null) {
  1346. if (file.isFolder()) {
  1347. return file;
  1348. } else if (getStorageManager() != null) {
  1349. String parentPath = file.getRemotePath().substring(0,
  1350. file.getRemotePath().lastIndexOf(file.getFileName()));
  1351. return getStorageManager().getFileByPath(parentPath);
  1352. }
  1353. }
  1354. return null;
  1355. }
  1356. public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
  1357. long currentSyncTime = System.currentTimeMillis();
  1358. mSyncInProgress = true;
  1359. // perform folder synchronization
  1360. RemoteOperation synchFolderOp = new RefreshFolderOperation( folder,
  1361. currentSyncTime,
  1362. false,
  1363. getFileOperationsHelper().isSharedSupported(),
  1364. ignoreETag,
  1365. getStorageManager(),
  1366. getAccount(),
  1367. getApplicationContext()
  1368. );
  1369. synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null);
  1370. setSupportProgressBarIndeterminateVisibility(true);
  1371. setBackgroundText();
  1372. }
  1373. /**
  1374. * Show untrusted cert dialog
  1375. */
  1376. public void showUntrustedCertDialog(RemoteOperationResult result) {
  1377. // Show a dialog with the certificate info
  1378. SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstanceForFullSslError(
  1379. (CertificateCombinedException) result.getException());
  1380. FragmentManager fm = getSupportFragmentManager();
  1381. FragmentTransaction ft = fm.beginTransaction();
  1382. dialog.show(ft, DIALOG_UNTRUSTED_CERT);
  1383. }
  1384. private void requestForDownload(OCFile file) {
  1385. Account account = getAccount();
  1386. if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
  1387. Intent i = new Intent(this, FileDownloader.class);
  1388. i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
  1389. i.putExtra(FileDownloader.EXTRA_FILE, file);
  1390. startService(i);
  1391. }
  1392. }
  1393. private void sendDownloadedFile(){
  1394. getFileOperationsHelper().sendDownloadedFile(mWaitingToSend);
  1395. mWaitingToSend = null;
  1396. }
  1397. /**
  1398. * Requests the download of the received {@link OCFile} , updates the UI
  1399. * to monitor the download progress and prepares the activity to send the file
  1400. * when the download finishes.
  1401. *
  1402. * @param file {@link OCFile} to download and preview.
  1403. */
  1404. public void startDownloadForSending(OCFile file) {
  1405. mWaitingToSend = file;
  1406. requestForDownload(mWaitingToSend);
  1407. boolean hasSecondFragment = (getSecondFragment()!= null);
  1408. updateFragmentsVisibility(hasSecondFragment);
  1409. }
  1410. /**
  1411. * Opens the image gallery showing the image {@link OCFile} received as parameter.
  1412. *
  1413. * @param file Image {@link OCFile} to show.
  1414. */
  1415. public void startImagePreview(OCFile file) {
  1416. Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
  1417. showDetailsIntent.putExtra(EXTRA_FILE, file);
  1418. showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
  1419. startActivity(showDetailsIntent);
  1420. }
  1421. /**
  1422. * Stars the preview of an already down media {@link OCFile}.
  1423. *
  1424. * @param file Media {@link OCFile} to preview.
  1425. * @param startPlaybackPosition Media position where the playback will be started,
  1426. * in milliseconds.
  1427. * @param autoplay When 'true', the playback will start without user
  1428. * interactions.
  1429. */
  1430. public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
  1431. Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition,
  1432. autoplay);
  1433. setSecondFragment(mediaFragment);
  1434. updateFragmentsVisibility(true);
  1435. updateNavigationElementsInActionBar(file);
  1436. setFile(file);
  1437. }
  1438. /**
  1439. * Requests the download of the received {@link OCFile} , updates the UI
  1440. * to monitor the download progress and prepares the activity to preview
  1441. * or open the file when the download finishes.
  1442. *
  1443. * @param file {@link OCFile} to download and preview.
  1444. */
  1445. public void startDownloadForPreview(OCFile file) {
  1446. Fragment detailFragment = new FileDetailFragment(file, getAccount());
  1447. setSecondFragment(detailFragment);
  1448. mWaitingToPreview = file;
  1449. requestForDownload();
  1450. updateFragmentsVisibility(true);
  1451. updateNavigationElementsInActionBar(file);
  1452. setFile(file);
  1453. }
  1454. public void cancelTransference(OCFile file) {
  1455. getFileOperationsHelper().cancelTransference(file);
  1456. if (mWaitingToPreview != null &&
  1457. mWaitingToPreview.getRemotePath().equals(file.getRemotePath())) {
  1458. mWaitingToPreview = null;
  1459. }
  1460. if (mWaitingToSend != null &&
  1461. mWaitingToSend.getRemotePath().equals(file.getRemotePath())) {
  1462. mWaitingToSend = null;
  1463. }
  1464. onTransferStateChanged(file, false, false);
  1465. }
  1466. @Override
  1467. public void onRefresh(boolean ignoreETag) {
  1468. refreshList(ignoreETag);
  1469. }
  1470. @Override
  1471. public void onRefresh() {
  1472. refreshList(true);
  1473. }
  1474. private void refreshList(boolean ignoreETag) {
  1475. OCFileListFragment listOfFiles = getListOfFilesFragment();
  1476. if (listOfFiles != null) {
  1477. OCFile folder = listOfFiles.getCurrentFile();
  1478. if (folder != null) {
  1479. /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
  1480. listDirectory(mFile);*/
  1481. startSyncFolderOperation(folder, ignoreETag);
  1482. }
  1483. }
  1484. }
  1485. private void sortByDate(boolean ascending){
  1486. getListOfFilesFragment().sortByDate(ascending);
  1487. }
  1488. private void sortBySize(boolean ascending){
  1489. getListOfFilesFragment().sortBySize(ascending);
  1490. }
  1491. private void sortByName(boolean ascending){
  1492. getListOfFilesFragment().sortByName(ascending);
  1493. }
  1494. public void allFilesOption() {
  1495. browseToRoot();
  1496. }
  1497. }