1 /* ownCloud Android client application
3 * @author David A. Velasco
4 * Copyright (C) 2014 ownCloud Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.ui
.dialog
;
22 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
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
.view
.LayoutInflater
;
33 import android
.view
.View
;
34 import android
.view
.WindowManager
.LayoutParams
;
35 import android
.widget
.EditText
;
36 import android
.widget
.TextView
;
37 import android
.widget
.Toast
;
40 * Dialog to input the name for a new folder to create.
42 * Triggers the folder creation when name is confirmed.
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
);