UploadFilesActivity.java 25 KB

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