1 /* ownCloud Android client application
2 * Copyright (C) 2014 ownCloud Inc.
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.
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.
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/>.
18 package com
.owncloud
.android
.ui
.dialog
;
20 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
21 import com
.owncloud
.android
.R
;
22 import com
.owncloud
.android
.datamodel
.OCFile
;
23 import com
.owncloud
.android
.lib
.resources
.files
.FileUtils
;
24 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
26 import android
.app
.AlertDialog
;
27 import android
.app
.Dialog
;
28 import android
.content
.DialogInterface
;
29 import android
.os
.Bundle
;
30 import android
.view
.LayoutInflater
;
31 import android
.view
.View
;
32 import android
.view
.WindowManager
.LayoutParams
;
33 import android
.widget
.EditText
;
34 import android
.widget
.TextView
;
35 import android
.widget
.Toast
;
38 * Dialog to input the name for a new folder to create.
40 * Triggers the folder creation when name is confirmed.
42 * @author David A. Velasco
44 public class CreateFolderDialogFragment
45 extends SherlockDialogFragment
implements DialogInterface
.OnClickListener
{
47 private static final String ARG_PARENT_FOLDER
= "PARENT_FOLDER";
49 public static final String CREATE_FOLDER_FRAGMENT
= "CREATE_FOLDER_FRAGMENT";
52 * Public factory method to create new CreateFolderDialogFragment instances.
54 * @param file File to remove.
55 * @return Dialog ready to show.
57 public static CreateFolderDialogFragment
newInstance(OCFile parentFolder
) {
58 CreateFolderDialogFragment frag
= new CreateFolderDialogFragment();
59 Bundle args
= new Bundle();
60 args
.putParcelable(ARG_PARENT_FOLDER
, parentFolder
);
61 frag
.setArguments(args
);
66 private OCFile mParentFolder
;
70 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
71 mParentFolder
= getArguments().getParcelable(ARG_PARENT_FOLDER
);
73 // Inflate the layout for the dialog
74 LayoutInflater inflater
= getSherlockActivity().getLayoutInflater();
75 View v
= inflater
.inflate(R
.layout
.edit_box_dialog
, null
);
78 EditText inputText
= ((EditText
)v
.findViewById(R
.id
.user_input
));
79 inputText
.setText("");
80 inputText
.requestFocus();
83 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getSherlockActivity());
85 .setPositiveButton(R
.string
.common_ok
, this)
86 .setNegativeButton(R
.string
.common_cancel
, this)
87 .setTitle(R
.string
.uploader_info_dirname
);
88 Dialog d
= builder
.create();
89 d
.getWindow().setSoftInputMode(LayoutParams
.SOFT_INPUT_STATE_VISIBLE
);
95 public void onClick(DialogInterface dialog
, int which
) {
96 if (which
== AlertDialog
.BUTTON_POSITIVE
) {
97 String newFolderName
=
98 ((TextView
)(getDialog().findViewById(R
.id
.user_input
)))
99 .getText().toString().trim();
101 if (newFolderName
.length() <= 0) {
103 getSherlockActivity(),
104 R
.string
.filename_empty
,
105 Toast
.LENGTH_LONG
).show();
109 if (!FileUtils
.isValidName(newFolderName
)) {
111 getSherlockActivity(),
112 R
.string
.filename_forbidden_characters
,
113 Toast
.LENGTH_LONG
).show();
117 String path
= mParentFolder
.getRemotePath();
118 path
+= newFolderName
+ OCFile
.PATH_SEPARATOR
;
119 ((ComponentsGetter
)getSherlockActivity()).
120 getFileOperationsHelper().createFolder(path
, false
);