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";
50 * Public factory method to create new CreateFolderDialogFragment instances.
52 * @param file File to remove.
53 * @return Dialog ready to show.
55 public static CreateFolderDialogFragment
newInstance(OCFile parentFolder
) {
56 CreateFolderDialogFragment frag
= new CreateFolderDialogFragment();
57 Bundle args
= new Bundle();
58 args
.putParcelable(ARG_PARENT_FOLDER
, parentFolder
);
59 frag
.setArguments(args
);
64 private OCFile mParentFolder
;
68 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
69 mParentFolder
= getArguments().getParcelable(ARG_PARENT_FOLDER
);
71 // Inflate the layout for the dialog
72 LayoutInflater inflater
= getSherlockActivity().getLayoutInflater();
73 View v
= inflater
.inflate(R
.layout
.edit_box_dialog
, null
);
76 EditText inputText
= ((EditText
)v
.findViewById(R
.id
.user_input
));
77 inputText
.setText("");
78 inputText
.requestFocus();
81 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getSherlockActivity());
83 .setPositiveButton(R
.string
.common_ok
, this)
84 .setNegativeButton(R
.string
.common_cancel
, this)
85 .setTitle(R
.string
.uploader_info_dirname
);
86 Dialog d
= builder
.create();
87 d
.getWindow().setSoftInputMode(LayoutParams
.SOFT_INPUT_STATE_VISIBLE
);
93 public void onClick(DialogInterface dialog
, int which
) {
94 if (which
== AlertDialog
.BUTTON_POSITIVE
) {
95 String newFolderName
=
96 ((TextView
)(getDialog().findViewById(R
.id
.user_input
)))
97 .getText().toString().trim();
99 if (newFolderName
.length() <= 0) {
101 getSherlockActivity(),
102 R
.string
.filename_empty
,
103 Toast
.LENGTH_LONG
).show();
107 if (!FileUtils
.isValidName(newFolderName
)) {
109 getSherlockActivity(),
110 R
.string
.filename_forbidden_characters
,
111 Toast
.LENGTH_LONG
).show();
115 String path
= mParentFolder
.getRemotePath();
116 path
+= newFolderName
+ OCFile
.PATH_SEPARATOR
;
117 ((ComponentsGetter
)getSherlockActivity()).
118 getFileOperationsHelper().createFolder(path
, false
);