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