mirror of
https://github.com/nextcloud/android.git
synced 2024-11-21 20:55:31 +03:00
Select name of file in the 'rename' dialog, excluding extension
Conflicts: src/com/owncloud/android/ui/activity/FileDisplayActivity.java
This commit is contained in:
parent
5a25a6a698
commit
5bcfed8eae
4 changed files with 28 additions and 11 deletions
|
@ -357,7 +357,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
||||||
boolean retval = true;
|
boolean retval = true;
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_create_dir: {
|
case R.id.action_create_dir: {
|
||||||
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.uploader_info_dirname), "", this);
|
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.uploader_info_dirname), "", -1, -1, this);
|
||||||
dialog.show(getSupportFragmentManager(), "createdirdialog");
|
dialog.show(getSupportFragmentManager(), "createdirdialog");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager.LayoutParams;
|
import android.view.WindowManager.LayoutParams;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockDialogFragment;
|
import com.actionbarsherlock.app.SherlockDialogFragment;
|
||||||
|
@ -42,8 +43,10 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte
|
||||||
|
|
||||||
public static final String TAG = EditNameDialog.class.getSimpleName();
|
public static final String TAG = EditNameDialog.class.getSimpleName();
|
||||||
|
|
||||||
protected static final String ARG_TITLE = "title";
|
protected static final String ARG_TITLE = "TITLE";
|
||||||
protected static final String ARG_NAME = "name";
|
protected static final String ARG_NAME = "NAME";
|
||||||
|
protected static final String ARG_SELECTION_START = "SELECTION_START";
|
||||||
|
protected static final String ARG_SELECTION_END = "SELECTION_END";
|
||||||
|
|
||||||
private String mNewFilename;
|
private String mNewFilename;
|
||||||
private boolean mResult;
|
private boolean mResult;
|
||||||
|
@ -52,16 +55,20 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte
|
||||||
/**
|
/**
|
||||||
* Public factory method to get dialog instances.
|
* Public factory method to get dialog instances.
|
||||||
*
|
*
|
||||||
* @param title Text to show as title in the dialog.
|
* @param title Text to show as title in the dialog.
|
||||||
* @param name Optional text to include in the text input field when the dialog is shown.
|
* @param name Optional text to include in the text input field when the dialog is shown.
|
||||||
* @param listener Instance to notify when the dialog is dismissed.
|
* @param listener Instance to notify when the dialog is dismissed.
|
||||||
|
* @param selectionStart Index to the first character to be selected in the input field; negative value for none
|
||||||
|
* @param selectionEnd Index to the last character to be selected in the input field; negative value for none
|
||||||
* @return New dialog instance, ready to show.
|
* @return New dialog instance, ready to show.
|
||||||
*/
|
*/
|
||||||
static public EditNameDialog newInstance(String title, String name, EditNameDialogListener listener) {
|
static public EditNameDialog newInstance(String title, String name, int selectionStart, int selectionEnd, EditNameDialogListener listener) {
|
||||||
EditNameDialog f = new EditNameDialog();
|
EditNameDialog f = new EditNameDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_TITLE, title);
|
args.putString(ARG_TITLE, title);
|
||||||
args.putString(ARG_NAME, name);
|
args.putString(ARG_NAME, name);
|
||||||
|
args.putInt(ARG_SELECTION_START, selectionStart);
|
||||||
|
args.putInt(ARG_SELECTION_END, selectionEnd);
|
||||||
f.setArguments(args);
|
f.setArguments(args);
|
||||||
f.setOnDismissListener(listener);
|
f.setOnDismissListener(listener);
|
||||||
return f;
|
return f;
|
||||||
|
@ -81,7 +88,7 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte
|
||||||
// Inflate the layout for the dialog
|
// Inflate the layout for the dialog
|
||||||
LayoutInflater inflater = getSherlockActivity().getLayoutInflater();
|
LayoutInflater inflater = getSherlockActivity().getLayoutInflater();
|
||||||
View v = inflater.inflate(R.layout.edit_box_dialog, null); // null parent view because it will go in the dialog layout
|
View v = inflater.inflate(R.layout.edit_box_dialog, null); // null parent view because it will go in the dialog layout
|
||||||
TextView inputText = ((TextView)v.findViewById(R.id.user_input));
|
EditText inputText = ((EditText)v.findViewById(R.id.user_input));
|
||||||
inputText.setText(currentName);
|
inputText.setText(currentName);
|
||||||
|
|
||||||
// Set it to the dialog
|
// Set it to the dialog
|
||||||
|
@ -99,6 +106,11 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte
|
||||||
Dialog d = builder.create();
|
Dialog d = builder.create();
|
||||||
|
|
||||||
inputText.requestFocus();
|
inputText.requestFocus();
|
||||||
|
int selectionStart = getArguments().getInt(ARG_SELECTION_START, -1);
|
||||||
|
int selectionEnd = getArguments().getInt(ARG_SELECTION_END, -1);
|
||||||
|
if (selectionStart >= 0 && selectionEnd >= 0) {
|
||||||
|
inputText.setSelection(Math.min(selectionStart, selectionEnd), Math.max(selectionStart, selectionEnd));
|
||||||
|
}
|
||||||
d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -364,7 +364,10 @@ public class FileDetailFragment extends SherlockFragment implements
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.fdRenameBtn: {
|
case R.id.fdRenameBtn: {
|
||||||
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this);
|
String fileName = mFile.getFileName();
|
||||||
|
int extensionStart = mFile.isDirectory() ? -1 : fileName.lastIndexOf(".");
|
||||||
|
int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
|
||||||
|
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
|
||||||
dialog.show(getFragmentManager(), "nameeditdialog");
|
dialog.show(getFragmentManager(), "nameeditdialog");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v4.app.DialogFragment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
@ -241,7 +240,10 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
|
||||||
mTargetFile = (OCFile) mAdapter.getItem(info.position);
|
mTargetFile = (OCFile) mAdapter.getItem(info.position);
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_rename_file: {
|
case R.id.action_rename_file: {
|
||||||
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mTargetFile.getFileName(), this);
|
String fileName = mTargetFile.getFileName();
|
||||||
|
int extensionStart = mTargetFile.isDirectory() ? -1 : fileName.lastIndexOf(".");
|
||||||
|
int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
|
||||||
|
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
|
||||||
dialog.show(getFragmentManager(), EditNameDialog.TAG);
|
dialog.show(getFragmentManager(), EditNameDialog.TAG);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue