UploadPathActivity.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* ownCloud Android client application
  2. * Copyright (C) 2012-2014 ownCloud Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. package com.owncloud.android.ui.activity;
  18. import android.accounts.Account;
  19. import android.content.Intent;
  20. import android.os.Bundle;
  21. import android.view.View;
  22. import android.view.View.OnClickListener;
  23. import com.owncloud.android.datamodel.OCFile;
  24. import com.owncloud.android.ui.fragment.FileFragment;
  25. import com.owncloud.android.ui.fragment.OCFileListFragment;
  26. public class UploadPathActivity extends FolderPickerActivity implements FileFragment.ContainerActivity,
  27. OnClickListener, OnEnforceableRefreshListener {
  28. public static final String KEY_INSTANT_UPLOAD_PATH = "INSTANT_UPLOAD_PATH";
  29. public static final int RESULT_OK_SET_UPLOAD_PATH = 1;
  30. @Override
  31. protected void onCreate(Bundle savedInstanceState) {
  32. super.onCreate(savedInstanceState);
  33. String instantUploadPath = getIntent().getStringExtra(KEY_INSTANT_UPLOAD_PATH);
  34. OCFile folder = new OCFile(instantUploadPath);
  35. setFile(folder);
  36. }
  37. /**
  38. * Called when the ownCloud {@link Account} associated to the Activity was
  39. * just updated.
  40. */
  41. @Override
  42. protected void onAccountSet(boolean stateWasRecovered) {
  43. super.onAccountSet(stateWasRecovered);
  44. if (getAccount() != null) {
  45. updateFileFromDB();
  46. OCFile folder = getFile();
  47. if (folder == null || !folder.isFolder()) {
  48. // fall back to root folder
  49. setFile(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
  50. folder = getFile();
  51. }
  52. onBrowsedDownTo(folder);
  53. if (!stateWasRecovered) {
  54. OCFileListFragment listOfFolders = getListOfFilesFragment();
  55. listOfFolders.listDirectory(folder);
  56. startSyncFolderOperation(folder, false);
  57. }
  58. updateNavigationElementsInActionBar();
  59. }
  60. }
  61. @Override
  62. public void onClick(View v) {
  63. if (v == mCancelBtn) {
  64. finish();
  65. } else if (v == mChooseBtn) {
  66. Intent i = getIntent();
  67. OCFile targetFile = (OCFile) i.getParcelableExtra(UploadPathActivity.EXTRA_TARGET_FILE);
  68. Intent data = new Intent();
  69. data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder());
  70. data.putExtra(EXTRA_TARGET_FILE, targetFile);
  71. setResult(RESULT_OK_SET_UPLOAD_PATH, data);
  72. finish();
  73. }
  74. }
  75. }