Fixed bug in File browser where Select button gets disabled when browsing into a directory
This commit is contained in:
parent
20a120a07e
commit
d9c924009d
1 changed files with 36 additions and 7 deletions
|
|
@ -9,7 +9,9 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
|
@ -34,11 +36,11 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
|
||||
/** Allow user to select destination directory and to enter filename.
|
||||
*
|
||||
/**
|
||||
* Allow user to select destination directory and to enter filename.
|
||||
* */
|
||||
public class FileBrowserDialog extends DialogFragment
|
||||
implements OnItemClickListener, DialogInterface.OnKeyListener, DialogInterface.OnClickListener{
|
||||
implements OnItemClickListener, DialogInterface.OnKeyListener, DialogInterface.OnClickListener, TextWatcher {
|
||||
public static final Logger log = Logger.getLogger(FileBrowserDialog.class);
|
||||
public static final int FOLDER_ICON = R.drawable.folder;
|
||||
public static final int FILE_ICON = R.drawable.file;
|
||||
|
|
@ -131,6 +133,7 @@ public class FileBrowserDialog extends DialogFragment
|
|||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
fileNameView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||
fileNameView.setHint("File Name");
|
||||
fileNameView.addTextChangedListener(this);
|
||||
rootView.addView(fileNameView);
|
||||
}
|
||||
|
||||
|
|
@ -148,12 +151,13 @@ public class FileBrowserDialog extends DialogFragment
|
|||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
if(mode == BrowserMode.SELECT_FILE)
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A file or folder has been clicked
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
File file = (File)fileListView.getAdapter().getItem(position);
|
||||
|
|
@ -172,6 +176,9 @@ public class FileBrowserDialog extends DialogFragment
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The "select" button has been pressed
|
||||
*/
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if(mode == BrowserMode.SELECT_FILE && selection != null)
|
||||
|
|
@ -183,6 +190,9 @@ public class FileBrowserDialog extends DialogFragment
|
|||
Toast.makeText(this.getActivity(), "No File Selected", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Back button has been pressed
|
||||
*/
|
||||
@Override
|
||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
|
|
@ -195,6 +205,23 @@ public class FileBrowserDialog extends DialogFragment
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Text input event for new file text field
|
||||
*/
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if(this.getDialog() != null) {
|
||||
if (fileNameView.getText().toString().isEmpty())
|
||||
((AlertDialog) this.getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
else
|
||||
((AlertDialog) this.getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
|
||||
private void updateFileList(File dir){
|
||||
if(!dir.isDirectory())
|
||||
|
|
@ -221,7 +248,9 @@ public class FileBrowserDialog extends DialogFragment
|
|||
|
||||
// Reset selection
|
||||
selection = null;
|
||||
if(this.getDialog() != null)
|
||||
if(this.getDialog() != null &&
|
||||
(mode == BrowserMode.SELECT_FILE ||
|
||||
mode == BrowserMode.NEW_FILE && fileNameView.getText().toString().isEmpty()))
|
||||
((AlertDialog)this.getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue