UploadFilesActivity.java 25 KB

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