UploadSourceDialogFragment.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.support.v7.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 android.support.v4.app.DialogFragment;
  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.FileDisplayActivity;
  33. import com.owncloud.android.ui.activity.UploadFilesActivity;
  34. /**
  35. * Dialog showing two options to allow the user upload files from the filesystem or from other apps.
  36. *
  37. * Assumes that its parent activity extends {@link FileActivity}
  38. */
  39. public class UploadSourceDialogFragment extends DialogFragment {
  40. private final static String TAG = UploadSourceDialogFragment.class.getSimpleName();
  41. private final static String ARG_ACCOUNT = UploadSourceDialogFragment.class.getSimpleName() +
  42. ".ARG_ACCOUNT";
  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(getActivity());
  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(getActivity(), UploadFilesActivity.class);
  66. action.putExtra(
  67. UploadFilesActivity.EXTRA_ACCOUNT,
  68. ((FileActivity)getActivity()).getAccount()
  69. );
  70. //startActivityForResult(action, REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM);
  71. // this flow seems broken;
  72. // Actionbarsherlock, maybe?
  73. getActivity().startActivityForResult(
  74. action,
  75. FileDisplayActivity.REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM
  76. );
  77. } else if (item == 1) {
  78. Intent action = new Intent(Intent.ACTION_GET_CONTENT);
  79. action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
  80. //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
  81. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
  82. action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
  83. }
  84. getActivity().startActivityForResult(
  85. Intent.createChooser(action, getString(R.string.upload_chooser_title)),
  86. FileDisplayActivity.REQUEST_CODE__SELECT_CONTENT_FROM_APPS
  87. );
  88. }
  89. }
  90. });
  91. return builder.create();
  92. }
  93. }