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