FileDisplayActivity.java 71 KB

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