FileDisplayActivity.java 70 KB

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