UploadFilesActivity.java 24 KB

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