mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
move CreateNewItem dialog into an own file
This commit is contained in:
@ -37,13 +37,13 @@ import com.simplemobiletools.filemanager.R;
|
||||
import com.simplemobiletools.filemanager.Utils;
|
||||
import com.simplemobiletools.filemanager.adapters.ItemsAdapter;
|
||||
import com.simplemobiletools.filemanager.asynctasks.CopyTask;
|
||||
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog;
|
||||
import com.simplemobiletools.filemanager.dialogs.PropertiesDialog;
|
||||
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog;
|
||||
import com.simplemobiletools.filepicker.models.FileDirItem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -221,71 +221,14 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||
|
||||
@OnClick(R.id.items_fab)
|
||||
public void fabClicked(View view) {
|
||||
final View newItemView = getActivity().getLayoutInflater().inflate(R.layout.create_new, null);
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(getResources().getString(R.string.create_new));
|
||||
builder.setView(newItemView);
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
|
||||
final AlertDialog alertDialog = builder.create();
|
||||
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
alertDialog.show();
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
||||
new CreateNewItemDialog(getContext(), mPath, new CreateNewItemDialog.OnCreateNewItemListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final EditText itemName = (EditText) newItemView.findViewById(R.id.item_name);
|
||||
final String name = itemName.getText().toString().trim();
|
||||
if (Utils.isNameValid(name)) {
|
||||
final File file = new File(mPath, name);
|
||||
if (file.exists()) {
|
||||
Utils.showToast(getContext(), R.string.name_taken);
|
||||
return;
|
||||
}
|
||||
final RadioGroup radio = (RadioGroup) newItemView.findViewById(R.id.dialog_radio_group);
|
||||
if (radio.getCheckedRadioButtonId() == R.id.dialog_radio_directory) {
|
||||
if (!createDirectory(file, alertDialog)) {
|
||||
errorOccurred();
|
||||
}
|
||||
} else {
|
||||
if (!createFile(file, alertDialog)) {
|
||||
errorOccurred();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Utils.showToast(getContext(), R.string.invalid_name);
|
||||
}
|
||||
public void onSuccess() {
|
||||
fillItems();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean createDirectory(File file, AlertDialog alertDialog) {
|
||||
if (file.mkdirs()) {
|
||||
alertDialog.dismiss();
|
||||
fillItems();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void errorOccurred() {
|
||||
Utils.showToast(getContext(), R.string.error_occurred);
|
||||
}
|
||||
|
||||
private boolean createFile(File file, AlertDialog alertDialog) {
|
||||
try {
|
||||
if (file.createNewFile()) {
|
||||
alertDialog.dismiss();
|
||||
fillItems();
|
||||
return true;
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
fillItems();
|
||||
@ -448,7 +391,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||
alertDialog.dismiss();
|
||||
fillItems();
|
||||
} else {
|
||||
errorOccurred();
|
||||
Utils.showToast(getContext(), R.string.error_occurred);
|
||||
}
|
||||
} else {
|
||||
Utils.showToast(getContext(), R.string.invalid_name);
|
||||
|
Reference in New Issue
Block a user