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
.actionbarsherlock
.app
.SherlockDialogFragment
;
24 import com
.owncloud
.android
.MainApp
;
25 import com
.owncloud
.android
.R
;
26 import com
.owncloud
.android
.datamodel
.OCFile
;
27 import com
.owncloud
.android
.lib
.resources
.files
.FileUtils
;
28 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
30 import android
.app
.AlertDialog
;
31 import android
.app
.Dialog
;
32 import android
.content
.DialogInterface
;
33 import android
.os
.Bundle
;
34 import android
.view
.LayoutInflater
;
35 import android
.view
.View
;
36 import android
.view
.WindowManager
.LayoutParams
;
37 import android
.widget
.EditText
;
38 import android
.widget
.TextView
;
39 import android
.widget
.Toast
;
42 * Dialog to input the name for a new folder to create.
44 * Triggers the folder creation when name is confirmed.
46 public class CreateFolderDialogFragment
47 extends SherlockDialogFragment
implements DialogInterface
.OnClickListener
{
49 private static final String ARG_PARENT_FOLDER
= "PARENT_FOLDER";
51 public static final String CREATE_FOLDER_FRAGMENT
= "CREATE_FOLDER_FRAGMENT";
54 * Public factory method to create new CreateFolderDialogFragment instances.
56 * @param parentFolder Folder to create
57 * @return Dialog ready to show.
59 public static CreateFolderDialogFragment
newInstance(OCFile parentFolder
) {
60 CreateFolderDialogFragment frag
= new CreateFolderDialogFragment();
61 Bundle args
= new Bundle();
62 args
.putParcelable(ARG_PARENT_FOLDER
, parentFolder
);
63 frag
.setArguments(args
);
68 private OCFile mParentFolder
;
72 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
73 mParentFolder
= getArguments().getParcelable(ARG_PARENT_FOLDER
);
75 // Inflate the layout for the dialog
76 LayoutInflater inflater
= getSherlockActivity().getLayoutInflater();
77 View v
= inflater
.inflate(R
.layout
.edit_box_dialog
, null
);
80 EditText inputText
= ((EditText
)v
.findViewById(R
.id
.user_input
));
81 inputText
.setText("");
82 inputText
.requestFocus();
85 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getSherlockActivity());
87 .setPositiveButton(R
.string
.common_ok
, this)
88 .setNegativeButton(R
.string
.common_cancel
, this)
89 .setTitle(R
.string
.uploader_info_dirname
);
90 Dialog d
= builder
.create();
91 d
.getWindow().setSoftInputMode(LayoutParams
.SOFT_INPUT_STATE_VISIBLE
);
97 public void onClick(DialogInterface dialog
, int which
) {
98 if (which
== AlertDialog
.BUTTON_POSITIVE
) {
99 String newFolderName
=
100 ((TextView
)(getDialog().findViewById(R
.id
.user_input
)))
101 .getText().toString().trim();
103 if (newFolderName
.length() <= 0) {
105 getSherlockActivity(),
106 R
.string
.filename_empty
,
107 Toast
.LENGTH_LONG
).show();
112 if (!FileUtils
.isValidName(newFolderName
,
113 ((ComponentsGetter
)getSherlockActivity()).
114 getFileOperationsHelper().isVersionWithForbiddenCharacters())) {
116 getSherlockActivity(),
117 R
.string
.filename_forbidden_characters
,
118 Toast
.LENGTH_LONG
).show();
122 String path
= mParentFolder
.getRemotePath();
123 path
+= newFolderName
+ OCFile
.PATH_SEPARATOR
;
124 ((ComponentsGetter
)getSherlockActivity()).
125 getFileOperationsHelper().createFolder(path
, false
);