UploadFilesActivity.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2015 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.ui.activity;
  21. import android.accounts.Account;
  22. import android.app.Activity;
  23. import android.content.Intent;
  24. import android.graphics.PorterDuff;
  25. import android.os.AsyncTask;
  26. import android.os.Bundle;
  27. import android.os.Environment;
  28. import android.support.annotation.NonNull;
  29. import android.support.annotation.Nullable;
  30. import android.support.v4.app.DialogFragment;
  31. import android.support.v4.app.Fragment;
  32. import android.support.v4.app.FragmentManager;
  33. import android.support.v4.app.FragmentTransaction;
  34. import android.support.v7.app.ActionBar;
  35. import android.support.v7.widget.AppCompatButton;
  36. import android.view.Menu;
  37. import android.view.MenuItem;
  38. import android.view.View;
  39. import android.view.View.OnClickListener;
  40. import android.view.ViewGroup;
  41. import android.widget.ArrayAdapter;
  42. import android.widget.Button;
  43. import android.widget.Spinner;
  44. import android.widget.TextView;
  45. import com.owncloud.android.R;
  46. import com.owncloud.android.db.PreferenceManager;
  47. import com.owncloud.android.lib.common.utils.Log_OC;
  48. import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
  49. import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
  50. import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
  51. import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
  52. import com.owncloud.android.ui.fragment.ExtendedListFragment;
  53. import com.owncloud.android.ui.fragment.LocalFileListFragment;
  54. import com.owncloud.android.utils.AnalyticsUtils;
  55. import com.owncloud.android.utils.FileSortOrder;
  56. import com.owncloud.android.utils.FileStorageUtils;
  57. import com.owncloud.android.utils.ThemeUtils;
  58. import java.io.File;
  59. import java.util.ArrayList;
  60. import java.util.List;
  61. import static com.owncloud.android.db.PreferenceManager.getSortOrder;
  62. /**
  63. * Displays local files and let the user choose what of them wants to upload
  64. * to the current ownCloud account.
  65. */
  66. public class UploadFilesActivity extends FileActivity implements
  67. LocalFileListFragment.ContainerActivity, ActionBar.OnNavigationListener,
  68. OnClickListener, ConfirmationDialogFragmentListener, SortingOrderDialogFragment.OnSortingOrderListener {
  69. private static final String SORT_ORDER_DIALOG_TAG = "SORT_ORDER_DIALOG";
  70. private ArrayAdapter<String> mDirectories;
  71. private File mCurrentDir = null;
  72. private boolean mSelectAll = false;
  73. private boolean mLocalFolderPickerMode = false;
  74. private LocalFileListFragment mFileListFragment;
  75. protected Button mUploadBtn;
  76. private Spinner mBehaviourSpinner;
  77. private Account mAccountOnCreation;
  78. private DialogFragment mCurrentDialog;
  79. private Menu mOptionsMenu;
  80. private static final String SCREEN_NAME = "Choose local files to upload";
  81. public static final String EXTRA_CHOSEN_FILES =
  82. UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
  83. public static final String EXTRA_ACTION = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_ACTION";
  84. public final static String KEY_LOCAL_FOLDER_PICKER_MODE = UploadFilesActivity.class.getCanonicalName()
  85. + ".LOCAL_FOLDER_PICKER_MODE";
  86. public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER;
  87. public static final int RESULT_OK_AND_DO_NOTHING = 2;
  88. public static final int RESULT_OK_AND_DELETE = 3;
  89. public static final String KEY_DIRECTORY_PATH =
  90. UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH";
  91. private static final String KEY_ALL_SELECTED =
  92. UploadFilesActivity.class.getCanonicalName() + ".KEY_ALL_SELECTED";
  93. private static final String TAG = "UploadFilesActivity";
  94. private static final String WAIT_DIALOG_TAG = "WAIT";
  95. private static final String QUERY_TO_MOVE_DIALOG_TAG = "QUERY_TO_MOVE";
  96. @Override
  97. public void onCreate(Bundle savedInstanceState) {
  98. Log_OC.d(TAG, "onCreate() start");
  99. super.onCreate(savedInstanceState);
  100. Bundle extras = getIntent().getExtras();
  101. if (extras != null) {
  102. mLocalFolderPickerMode = extras.getBoolean(KEY_LOCAL_FOLDER_PICKER_MODE, false);
  103. }
  104. if(savedInstanceState != null) {
  105. mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.KEY_DIRECTORY_PATH, Environment
  106. .getExternalStorageDirectory().getAbsolutePath()));
  107. mSelectAll = savedInstanceState.getBoolean(UploadFilesActivity.KEY_ALL_SELECTED, false);
  108. } else {
  109. mCurrentDir = Environment.getExternalStorageDirectory();
  110. }
  111. mAccountOnCreation = getAccount();
  112. /// USER INTERFACE
  113. // Drop-down navigation
  114. mDirectories = new CustomArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item);
  115. File currDir = mCurrentDir;
  116. while(currDir != null && currDir.getParentFile() != null) {
  117. mDirectories.add(currDir.getName());
  118. currDir = currDir.getParentFile();
  119. }
  120. mDirectories.add(File.separator);
  121. // Inflate and set the layout view
  122. setContentView(R.layout.upload_files_layout);
  123. if (mLocalFolderPickerMode) {
  124. findViewById(R.id.upload_options).setVisibility(View.GONE);
  125. ((AppCompatButton) findViewById(R.id.upload_files_btn_upload))
  126. .setText(R.string.uploader_btn_alternative_text);
  127. }
  128. mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentById(R.id.local_files_list);
  129. // Set input controllers
  130. findViewById(R.id.upload_files_btn_cancel).setOnClickListener(this);
  131. mUploadBtn = (AppCompatButton) findViewById(R.id.upload_files_btn_upload);
  132. mUploadBtn.getBackground().setColorFilter(ThemeUtils.primaryAccentColor(this), PorterDuff.Mode.SRC_ATOP);
  133. mUploadBtn.setOnClickListener(this);
  134. int localBehaviour = PreferenceManager.getUploaderBehaviour(this);
  135. // file upload spinner
  136. mBehaviourSpinner = findViewById(R.id.upload_files_spinner_behaviour);
  137. List<String> behaviours = new ArrayList<>();
  138. behaviours.add(getString(R.string.uploader_upload_files_behaviour_move_to_nextcloud_folder,
  139. ThemeUtils.getDefaultDisplayNameForRootFolder(this)));
  140. behaviours.add(getString(R.string.uploader_upload_files_behaviour_only_upload));
  141. behaviours.add(getString(R.string.uploader_upload_files_behaviour_upload_and_delete_from_source));
  142. ArrayAdapter<String> behaviourAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
  143. behaviours);
  144. behaviourAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  145. mBehaviourSpinner.setAdapter(behaviourAdapter);
  146. mBehaviourSpinner.setSelection(localBehaviour);
  147. // setup the toolbar
  148. setupToolbar();
  149. // Action bar setup
  150. ActionBar actionBar = getSupportActionBar();
  151. actionBar.setHomeButtonEnabled(true); // mandatory since Android ICS, according to the
  152. // official documentation
  153. actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getName() != null);
  154. actionBar.setDisplayShowTitleEnabled(false);
  155. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
  156. actionBar.setListNavigationCallbacks(mDirectories, this);
  157. // wait dialog
  158. if (mCurrentDialog != null) {
  159. mCurrentDialog.dismiss();
  160. mCurrentDialog = null;
  161. }
  162. Log_OC.d(TAG, "onCreate() end");
  163. }
  164. /**
  165. * Helper to launch the UploadFilesActivity for which you would like a result when it finished.
  166. * Your onActivityResult() method will be called with the given requestCode.
  167. *
  168. * @param activity the activity which should call the upload activity for a result
  169. * @param account the account for which the upload activity is called
  170. * @param requestCode If >= 0, this code will be returned in onActivityResult()
  171. */
  172. public static void startUploadActivityForResult(Activity activity, Account account, int requestCode) {
  173. Intent action = new Intent(activity, UploadFilesActivity.class);
  174. action.putExtra(EXTRA_ACCOUNT, (account));
  175. activity.startActivityForResult(action, requestCode);
  176. }
  177. @Override
  178. public boolean onCreateOptionsMenu(Menu menu) {
  179. mOptionsMenu = menu;
  180. getMenuInflater().inflate(R.menu.upload_files_picker, menu);
  181. if(!mLocalFolderPickerMode) {
  182. MenuItem selectAll = menu.findItem(R.id.action_select_all);
  183. setSelectAllMenuItem(selectAll, mSelectAll);
  184. }
  185. MenuItem switchView = menu.findItem(R.id.action_switch_view);
  186. switchView.setTitle(isGridView() ? R.string.action_switch_list_view : R.string.action_switch_grid_view);
  187. return super.onCreateOptionsMenu(menu);
  188. }
  189. @Override
  190. public boolean onOptionsItemSelected(MenuItem item) {
  191. boolean retval = true;
  192. switch (item.getItemId()) {
  193. case android.R.id.home: {
  194. if(mCurrentDir != null && mCurrentDir.getParentFile() != null){
  195. onBackPressed();
  196. }
  197. break;
  198. }
  199. case R.id.action_select_all: {
  200. item.setChecked(!item.isChecked());
  201. mSelectAll = item.isChecked();
  202. setSelectAllMenuItem(item, mSelectAll);
  203. mFileListFragment.selectAllFiles(item.isChecked());
  204. break;
  205. }
  206. case R.id.action_sort: {
  207. FragmentManager fm = getSupportFragmentManager();
  208. FragmentTransaction ft = fm.beginTransaction();
  209. ft.addToBackStack(null);
  210. SortingOrderDialogFragment mSortingOrderDialogFragment = SortingOrderDialogFragment.newInstance(
  211. getSortOrder(this, null));
  212. mSortingOrderDialogFragment.show(ft, SORT_ORDER_DIALOG_TAG);
  213. break;
  214. }
  215. case R.id.action_switch_view: {
  216. if (isGridView()) {
  217. item.setTitle(getString(R.string.action_switch_grid_view));
  218. item.setIcon(R.drawable.ic_view_module);
  219. mFileListFragment.switchToListView();
  220. } else {
  221. item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
  222. item.setIcon(R.drawable.ic_view_list);
  223. mFileListFragment.switchToGridView();
  224. }
  225. break;
  226. }
  227. default:
  228. retval = super.onOptionsItemSelected(item);
  229. break;
  230. }
  231. return retval;
  232. }
  233. @Override
  234. public void onSortingOrderChosen(FileSortOrder selection) {
  235. mFileListFragment.sortFiles(selection);
  236. }
  237. @Override
  238. public boolean onNavigationItemSelected(int itemPosition, long itemId) {
  239. int i = itemPosition;
  240. while (i-- != 0) {
  241. onBackPressed();
  242. }
  243. // the next operation triggers a new call to this method, but it's necessary to
  244. // ensure that the name exposed in the action bar is the current directory when the
  245. // user selected it in the navigation list
  246. if (itemPosition != 0) {
  247. getSupportActionBar().setSelectedNavigationItem(0);
  248. }
  249. return true;
  250. }
  251. @Override
  252. public void onBackPressed() {
  253. if (mDirectories.getCount() <= 1) {
  254. finish();
  255. return;
  256. }
  257. popDirname();
  258. mFileListFragment.onNavigateUp();
  259. mCurrentDir = mFileListFragment.getCurrentDirectory();
  260. if (mCurrentDir.getParentFile() == null) {
  261. ActionBar actionBar = getSupportActionBar();
  262. if (actionBar != null) {
  263. actionBar.setDisplayHomeAsUpEnabled(false);
  264. }
  265. }
  266. // invalidate checked state when navigating directories
  267. if(!mLocalFolderPickerMode) {
  268. setSelectAllMenuItem(mOptionsMenu.findItem(R.id.action_select_all), false);
  269. }
  270. }
  271. @Override
  272. protected void onSaveInstanceState(Bundle outState) {
  273. // responsibility of restore is preferred in onCreate() before than in
  274. // onRestoreInstanceState when there are Fragments involved
  275. Log_OC.d(TAG, "onSaveInstanceState() start");
  276. super.onSaveInstanceState(outState);
  277. outState.putString(UploadFilesActivity.KEY_DIRECTORY_PATH, mCurrentDir.getAbsolutePath());
  278. if (mOptionsMenu != null && mOptionsMenu.findItem(R.id.action_select_all) != null) {
  279. outState.putBoolean(UploadFilesActivity.KEY_ALL_SELECTED,
  280. mOptionsMenu.findItem(R.id.action_select_all).isChecked());
  281. } else {
  282. outState.putBoolean(UploadFilesActivity.KEY_ALL_SELECTED, false);
  283. }
  284. Log_OC.d(TAG, "onSaveInstanceState() end");
  285. }
  286. @Override
  287. protected void onResume() {
  288. super.onResume();
  289. AnalyticsUtils.setCurrentScreenName(this, SCREEN_NAME, TAG);
  290. }
  291. /**
  292. * Pushes a directory to the drop down list
  293. * @param directory to push
  294. * @throws IllegalArgumentException If the {@link File#isDirectory()} returns false.
  295. */
  296. public void pushDirname(File directory) {
  297. if(!directory.isDirectory()){
  298. throw new IllegalArgumentException("Only directories may be pushed!");
  299. }
  300. mDirectories.insert(directory.getName(), 0);
  301. mCurrentDir = directory;
  302. }
  303. /**
  304. * Pops a directory name from the drop down list
  305. * @return True, unless the stack is empty
  306. */
  307. public boolean popDirname() {
  308. mDirectories.remove(mDirectories.getItem(0));
  309. return !mDirectories.isEmpty();
  310. }
  311. private void setSelectAllMenuItem(MenuItem selectAll, boolean checked) {
  312. selectAll.setChecked(checked);
  313. if(checked) {
  314. selectAll.setIcon(R.drawable.ic_select_none);
  315. } else {
  316. selectAll.setIcon(ThemeUtils.tintDrawable(R.drawable.ic_select_all, ThemeUtils.primaryColor(this)));
  317. }
  318. }
  319. /**
  320. * Custom array adapter to override text colors
  321. */
  322. private class CustomArrayAdapter<T> extends ArrayAdapter<T> {
  323. public CustomArrayAdapter(UploadFilesActivity ctx, int view) {
  324. super(ctx, view);
  325. }
  326. public @NonNull View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  327. View v = super.getView(position, convertView, parent);
  328. ((TextView) v).setTextColor(getResources().getColorStateList(
  329. android.R.color.white));
  330. return v;
  331. }
  332. public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
  333. View v = super.getDropDownView(position, convertView, parent);
  334. ((TextView) v).setTextColor(getResources().getColorStateList(
  335. android.R.color.white));
  336. return v;
  337. }
  338. }
  339. /**
  340. * {@inheritDoc}
  341. */
  342. @Override
  343. public void onDirectoryClick(File directory) {
  344. if(!mLocalFolderPickerMode) {
  345. // invalidate checked state when navigating directories
  346. MenuItem selectAll = mOptionsMenu.findItem(R.id.action_select_all);
  347. setSelectAllMenuItem(selectAll, false);
  348. }
  349. pushDirname(directory);
  350. ActionBar actionBar = getSupportActionBar();
  351. actionBar.setDisplayHomeAsUpEnabled(true);
  352. }
  353. /**
  354. * {@inheritDoc}
  355. */
  356. @Override
  357. public void onFileClick(File file) {
  358. // nothing to do
  359. }
  360. /**
  361. * {@inheritDoc}
  362. */
  363. @Override
  364. public File getInitialDirectory() {
  365. return mCurrentDir;
  366. }
  367. /**
  368. * {@inheritDoc}
  369. */
  370. @Override
  371. public boolean isFolderPickerMode() {
  372. return mLocalFolderPickerMode;
  373. }
  374. /**
  375. * Performs corresponding action when user presses 'Cancel' or 'Upload' button
  376. *
  377. * TODO Make here the real request to the Upload service ; will require to receive the account and
  378. * target folder where the upload must be done in the received intent.
  379. */
  380. @Override
  381. public void onClick(View v) {
  382. if (v.getId() == R.id.upload_files_btn_cancel) {
  383. setResult(RESULT_CANCELED);
  384. finish();
  385. } else if (v.getId() == R.id.upload_files_btn_upload) {
  386. if(mLocalFolderPickerMode) {
  387. Intent data = new Intent();
  388. if(mCurrentDir != null) {
  389. data.putExtra(EXTRA_CHOSEN_FILES, mCurrentDir.getAbsolutePath());
  390. }
  391. setResult(RESULT_OK, data);
  392. finish();
  393. } else {
  394. new CheckAvailableSpaceTask().execute(mBehaviourSpinner.getSelectedItemPosition() == 0);
  395. }
  396. }
  397. }
  398. /**
  399. * Asynchronous task checking if there is space enough to copy all the files chosen
  400. * to upload into the ownCloud local folder.
  401. *
  402. * Maybe an AsyncTask is not strictly necessary, but who really knows.
  403. */
  404. private class CheckAvailableSpaceTask extends AsyncTask<Boolean, Void, Boolean> {
  405. /**
  406. * Updates the UI before trying the movement.
  407. */
  408. @Override
  409. protected void onPreExecute () {
  410. /// progress dialog and disable 'Move' button
  411. mCurrentDialog = IndeterminateProgressDialog.newInstance(R.string.wait_a_moment, false);
  412. mCurrentDialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
  413. }
  414. /**
  415. * Checks the available space.
  416. *
  417. * @param params boolean flag if storage calculation should be done.
  418. * @return 'True' if there is space enough or doesn't have to be calculated
  419. */
  420. @Override
  421. protected Boolean doInBackground(Boolean... params) {
  422. if(params[0]) {
  423. String[] checkedFilePaths = mFileListFragment.getCheckedFilePaths();
  424. long total = 0;
  425. for (int i = 0; checkedFilePaths != null && i < checkedFilePaths.length; i++) {
  426. String localPath = checkedFilePaths[i];
  427. File localFile = new File(localPath);
  428. total += localFile.length();
  429. }
  430. return FileStorageUtils.getUsableSpace(mAccountOnCreation.name) >= total;
  431. }
  432. return true;
  433. }
  434. /**
  435. * Updates the activity UI after the check of space is done.
  436. *
  437. * If there is not space enough. shows a new dialog to query the user if wants to move the
  438. * files instead of copy them.
  439. *
  440. * @param result 'True' when there is space enough to copy all the selected files.
  441. */
  442. @Override
  443. protected void onPostExecute(Boolean result) {
  444. if(mCurrentDialog != null) {
  445. mCurrentDialog.dismiss();
  446. mCurrentDialog = null;
  447. }
  448. if (result) {
  449. // return the list of selected files (success)
  450. Intent data = new Intent();
  451. data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
  452. // set result code
  453. switch (mBehaviourSpinner.getSelectedItemPosition()) {
  454. case 0: // move to nextcloud folder
  455. setResult(RESULT_OK_AND_MOVE, data);
  456. break;
  457. case 1: // only upload
  458. setResult(RESULT_OK_AND_DO_NOTHING, data);
  459. break;
  460. case 2: // upload and delete from source
  461. setResult(RESULT_OK_AND_DELETE, data);
  462. break;
  463. }
  464. // store behaviour
  465. PreferenceManager.setUploaderBehaviour(getApplicationContext(),
  466. mBehaviourSpinner.getSelectedItemPosition());
  467. finish();
  468. } else {
  469. // show a dialog to query the user if wants to move the selected files
  470. // to the ownCloud folder instead of copying
  471. String[] args = {getString(R.string.app_name)};
  472. ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(
  473. R.string.upload_query_move_foreign_files, args, 0, R.string.common_yes, -1,
  474. R.string.common_no
  475. );
  476. dialog.setOnConfirmationListener(UploadFilesActivity.this);
  477. dialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG);
  478. }
  479. }
  480. }
  481. @Override
  482. public void onConfirmation(String callerTag) {
  483. Log_OC.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
  484. if (callerTag.equals(QUERY_TO_MOVE_DIALOG_TAG)) {
  485. // return the list of selected files to the caller activity (success),
  486. // signaling that they should be moved to the ownCloud folder, instead of copied
  487. Intent data = new Intent();
  488. data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
  489. setResult(RESULT_OK_AND_MOVE, data);
  490. finish();
  491. }
  492. }
  493. @Override
  494. public void onNeutral(String callerTag) {
  495. Log_OC.d(TAG, "Phantom neutral button in dialog was clicked; dialog tag is " + callerTag);
  496. }
  497. @Override
  498. public void onCancel(String callerTag) {
  499. /// nothing to do; don't finish, let the user change the selection
  500. Log_OC.d(TAG, "Negative button in dialog was clicked; dialog tag is " + callerTag);
  501. }
  502. @Override
  503. protected void onAccountSet(boolean stateWasRecovered) {
  504. super.onAccountSet(stateWasRecovered);
  505. if (getAccount() != null) {
  506. if (!mAccountOnCreation.equals(getAccount())) {
  507. setResult(RESULT_CANCELED);
  508. finish();
  509. }
  510. } else {
  511. setResult(RESULT_CANCELED);
  512. finish();
  513. }
  514. }
  515. private boolean isGridView() {
  516. return getListOfFilesFragment().isGridEnabled();
  517. }
  518. private ExtendedListFragment getListOfFilesFragment() {
  519. Fragment listOfFiles = mFileListFragment;
  520. if (listOfFiles != null) {
  521. return (ExtendedListFragment) listOfFiles;
  522. }
  523. Log_OC.e(TAG, "Access to unexisting list of files fragment!!");
  524. return null;
  525. }
  526. }