UploadSourceDialogFragment.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.dialog;
  21. import android.accounts.Account;
  22. import android.app.AlertDialog;
  23. import android.app.Dialog;
  24. import android.content.DialogInterface;
  25. import android.content.Intent;
  26. import android.os.Build;
  27. import android.os.Bundle;
  28. import com.actionbarsherlock.app.SherlockDialogFragment;
  29. import com.owncloud.android.R;
  30. import com.owncloud.android.lib.common.utils.Log_OC;
  31. import com.owncloud.android.ui.activity.FileActivity;
  32. import com.owncloud.android.ui.activity.UploadFilesActivity;
  33. /**
  34. * Dialog showing two options to allow the user upload files from the filesystem or from other apps.
  35. *
  36. * Assumes that its parent activity extends {@link FileActivity}
  37. */
  38. public class UploadSourceDialogFragment extends SherlockDialogFragment {
  39. private final static String TAG = UploadSourceDialogFragment.class.getSimpleName();
  40. private final static String ARG_ACCOUNT = UploadSourceDialogFragment.class.getSimpleName() + ".ARG_ACCOUNT";
  41. public static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
  42. public static final int ACTION_SELECT_MULTIPLE_FILES = 2;
  43. public static UploadSourceDialogFragment newInstance(Account account) {
  44. UploadSourceDialogFragment f = new UploadSourceDialogFragment();
  45. Bundle args = new Bundle();
  46. args.putParcelable(ARG_ACCOUNT, account);
  47. f.setArguments(args);
  48. return f;
  49. }
  50. public UploadSourceDialogFragment() {
  51. super();
  52. Log_OC.v(TAG, "constructor");
  53. }
  54. @Override
  55. public Dialog onCreateDialog(Bundle savedInstanceState) {
  56. String[] allTheItems = {
  57. getString(R.string.actionbar_upload_files),
  58. getString(R.string.actionbar_upload_from_apps)
  59. };
  60. AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());
  61. builder.setTitle(R.string.actionbar_upload);
  62. builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
  63. public void onClick(DialogInterface dialog, int item) {
  64. if (item == 0) {
  65. Intent action = new Intent(getSherlockActivity(), UploadFilesActivity.class);
  66. action.putExtra(
  67. UploadFilesActivity.EXTRA_ACCOUNT,
  68. ((FileActivity)getSherlockActivity()).getAccount()
  69. );
  70. //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); // this flow seems broken;
  71. // Actionbarsherlock, maybe?
  72. getSherlockActivity().startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
  73. } else if (item == 1) {
  74. Intent action = new Intent(Intent.ACTION_GET_CONTENT);
  75. action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
  76. //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
  77. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
  78. action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
  79. }
  80. //startActivityForResult( // this flow seems broken;
  81. // Actionbarsherlock, maybe?
  82. getSherlockActivity().startActivityForResult(
  83. Intent.createChooser(action, getString(R.string.upload_chooser_title)),
  84. ACTION_SELECT_CONTENT_FROM_APPS
  85. );
  86. }
  87. }
  88. });
  89. return builder.create();
  90. }
  91. }