2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
21 package com
.owncloud
.android
.ui
.dialog
;
23 import com
.owncloud
.android
.R
;
24 import com
.owncloud
.android
.datamodel
.OCFile
;
25 import com
.owncloud
.android
.lib
.resources
.files
.FileUtils
;
26 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
28 import android
.app
.AlertDialog
;
29 import android
.app
.Dialog
;
30 import android
.content
.DialogInterface
;
31 import android
.os
.Bundle
;
32 import android
.support
.v4
.app
.DialogFragment
;
33 import android
.view
.LayoutInflater
;
34 import android
.view
.View
;
35 import android
.view
.WindowManager
.LayoutParams
;
36 import android
.widget
.EditText
;
37 import android
.widget
.TextView
;
38 import android
.widget
.Toast
;
41 * Dialog to input the name for a new folder to create.
43 * Triggers the folder creation when name is confirmed.
45 public class CreateFolderDialogFragment
46 extends DialogFragment
implements DialogInterface
.OnClickListener
{
48 private static final String ARG_PARENT_FOLDER
= "PARENT_FOLDER";
50 public static final String CREATE_FOLDER_FRAGMENT
= "CREATE_FOLDER_FRAGMENT";
53 * Public factory method to create new CreateFolderDialogFragment instances.
55 * @param parentFolder Folder to create
56 * @return Dialog ready to show.
58 public static CreateFolderDialogFragment
newInstance(OCFile parentFolder
) {
59 CreateFolderDialogFragment frag
= new CreateFolderDialogFragment();
60 Bundle args
= new Bundle();
61 args
.putParcelable(ARG_PARENT_FOLDER
, parentFolder
);
62 frag
.setArguments(args
);
67 private OCFile mParentFolder
;
71 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
72 mParentFolder
= getArguments().getParcelable(ARG_PARENT_FOLDER
);
74 // Inflate the layout for the dialog
75 LayoutInflater inflater
= getActivity().getLayoutInflater();
76 View v
= inflater
.inflate(R
.layout
.edit_box_dialog
, null
);
79 EditText inputText
= ((EditText
)v
.findViewById(R
.id
.user_input
));
80 inputText
.setText("");
81 inputText
.requestFocus();
84 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity());
86 .setPositiveButton(R
.string
.common_ok
, this)
87 .setNegativeButton(R
.string
.common_cancel
, this)
88 .setTitle(R
.string
.uploader_info_dirname
);
89 Dialog d
= builder
.create();
90 d
.getWindow().setSoftInputMode(LayoutParams
.SOFT_INPUT_STATE_VISIBLE
);
96 public void onClick(DialogInterface dialog
, int which
) {
97 if (which
== AlertDialog
.BUTTON_POSITIVE
) {
98 String newFolderName
=
99 ((TextView
)(getDialog().findViewById(R
.id
.user_input
)))
100 .getText().toString().trim();
102 if (newFolderName
.length() <= 0) {
105 R
.string
.filename_empty
,
106 Toast
.LENGTH_LONG
).show();
110 if (!FileUtils
.isValidName(newFolderName
)) {
113 R
.string
.filename_forbidden_characters
,
114 Toast
.LENGTH_LONG
).show();
118 String path
= mParentFolder
.getRemotePath();
119 path
+= newFolderName
+ OCFile
.PATH_SEPARATOR
;
120 ((ComponentsGetter
)getActivity()).
121 getFileOperationsHelper().createFolder(path
, false
);