UploadFilesActivity.java 25 KB

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