mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Added title to rename dialog; and some cleaning
This commit is contained in:
parent
ccb796173b
commit
d49bfd0c77
5 changed files with 85 additions and 52 deletions
|
@ -26,29 +26,10 @@
|
||||||
android:id="@+id/user_input"
|
android:id="@+id/user_input"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ems="10" >
|
android:ems="10"
|
||||||
|
android:inputType="textNoSuggestions"
|
||||||
|
>
|
||||||
|
|
||||||
<requestFocus />
|
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:gravity="center_horizontal" >
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/cancel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/common_cancel" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/ok"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/common_ok" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -181,6 +181,7 @@
|
||||||
<string name="remove_success_msg">"Successful removal"</string>
|
<string name="remove_success_msg">"Successful removal"</string>
|
||||||
<string name="remove_fail_msg">"Removal could not be completed"</string>
|
<string name="remove_fail_msg">"Removal could not be completed"</string>
|
||||||
|
|
||||||
|
<string name="rename_dialog_title">Enter a new name</string>
|
||||||
<string name="rename_local_fail_msg">"Local copy could not be renamed; try a differente new name"</string>
|
<string name="rename_local_fail_msg">"Local copy could not be renamed; try a differente new name"</string>
|
||||||
<string name="rename_server_fail_msg">"Rename could not be completed"</string>
|
<string name="rename_server_fail_msg">"Rename could not be completed"</string>
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
|
|
||||||
package com.owncloud.android.ui.dialog;
|
package com.owncloud.android.ui.dialog;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.WindowManager.LayoutParams;
|
import android.view.WindowManager.LayoutParams;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockDialogFragment;
|
import com.actionbarsherlock.app.SherlockDialogFragment;
|
||||||
|
@ -33,52 +33,93 @@ import com.owncloud.android.R;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialog to request the user about a certificate that could not be validated with the certificates store in the system.
|
* Dialog to request the user to input a name, optionally initialized with a former name.
|
||||||
*
|
*
|
||||||
* @author Bartek Przybylski
|
* @author Bartek Przybylski
|
||||||
|
* @author David A. Velasco
|
||||||
*/
|
*/
|
||||||
public class EditNameDialog extends SherlockDialogFragment implements OnClickListener {
|
public class EditNameDialog extends SherlockDialogFragment implements DialogInterface.OnClickListener {
|
||||||
|
|
||||||
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_NAME = "name";
|
||||||
|
|
||||||
private String mNewFilename;
|
private String mNewFilename;
|
||||||
private boolean mResult;
|
private boolean mResult;
|
||||||
private EditNameDialogListener mListener;
|
private EditNameDialogListener mListener;
|
||||||
|
|
||||||
static public EditNameDialog newInstance(String filename) {
|
/**
|
||||||
|
* Public factory method to get dialog instances.
|
||||||
|
*
|
||||||
|
* @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 listener Instance to notify when the dialog is dismissed.
|
||||||
|
* @return New dialog instance, ready to show.
|
||||||
|
*/
|
||||||
|
static public EditNameDialog newInstance(String title, String name, EditNameDialogListener listener) {
|
||||||
EditNameDialog f = new EditNameDialog();
|
EditNameDialog f = new EditNameDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("filename", filename);
|
args.putString(ARG_TITLE, title);
|
||||||
|
args.putString(ARG_NAME, name);
|
||||||
f.setArguments(args);
|
f.setArguments(args);
|
||||||
|
f.setOnDismissListener(listener);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
View v = inflater.inflate(R.layout.edit_box_dialog, container, false);
|
|
||||||
|
|
||||||
String currentName = getArguments().getString("filename");
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
String currentName = getArguments().getString(ARG_NAME);
|
||||||
if (currentName == null)
|
if (currentName == null)
|
||||||
currentName = "";
|
currentName = "";
|
||||||
|
String title = getArguments().getString(ARG_TITLE);
|
||||||
|
|
||||||
((Button)v.findViewById(R.id.cancel)).setOnClickListener(this);
|
// Inflate the layout for the dialog
|
||||||
((Button)v.findViewById(R.id.ok)).setOnClickListener(this);
|
LayoutInflater inflater = getSherlockActivity().getLayoutInflater();
|
||||||
((TextView)v.findViewById(R.id.user_input)).setText(currentName);
|
View v = inflater.inflate(R.layout.edit_box_dialog, null); // null parent view because it will go in the dialog layout
|
||||||
((TextView)v.findViewById(R.id.user_input)).requestFocus();
|
TextView inputText = ((TextView)v.findViewById(R.id.user_input));
|
||||||
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
inputText.setText(currentName);
|
||||||
|
|
||||||
|
// Set it to the dialog
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());
|
||||||
|
builder.setView(v)
|
||||||
|
.setPositiveButton(R.string.common_ok, this)
|
||||||
|
.setNegativeButton(R.string.common_cancel, this);
|
||||||
|
|
||||||
|
if (title != null) {
|
||||||
|
builder.setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
mResult = false;
|
mResult = false;
|
||||||
return v;
|
|
||||||
|
Dialog d = builder.create();
|
||||||
|
|
||||||
|
inputText.requestFocus();
|
||||||
|
d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the corresponding action when a dialog button is clicked.
|
||||||
|
*
|
||||||
|
* Saves the text in the input field to be accessed through {@link #getNewFilename()} when the positive
|
||||||
|
* button is clicked.
|
||||||
|
*
|
||||||
|
* Notify the current listener in any case.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
switch (view.getId()) {
|
switch (which) {
|
||||||
case R.id.ok: {
|
case AlertDialog.BUTTON_POSITIVE: {
|
||||||
mNewFilename = ((TextView)getView().findViewById(R.id.user_input)).getText().toString();
|
mNewFilename = ((TextView)(getDialog().findViewById(R.id.user_input))).getText().toString();
|
||||||
mResult = true;
|
mResult = true;
|
||||||
}
|
}
|
||||||
case R.id.cancel: { // fallthought
|
case AlertDialog.BUTTON_NEGATIVE: { // fall through
|
||||||
dismiss();
|
dismiss();
|
||||||
if (mListener != null)
|
if (mListener != null)
|
||||||
mListener.onDismiss(this);
|
mListener.onDismiss(this);
|
||||||
|
@ -86,23 +127,35 @@ public class EditNameDialog extends SherlockDialogFragment implements OnClickLis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnDismissListener(EditNameDialogListener listener) {
|
protected void setOnDismissListener(EditNameDialogListener listener) {
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the text in the input field after the user clicked the positive button.
|
||||||
|
*
|
||||||
|
* @return Text in the input field.
|
||||||
|
*/
|
||||||
public String getNewFilename() {
|
public String getNewFilename() {
|
||||||
return mNewFilename;
|
return mNewFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// true if user clicked ok
|
/**
|
||||||
|
*
|
||||||
|
* @return True when the user clicked the positive button.
|
||||||
|
*/
|
||||||
public boolean getResult() {
|
public boolean getResult() {
|
||||||
return mResult;
|
return mResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface to receive a notification when any button in the dialog is clicked.
|
||||||
|
*/
|
||||||
public interface EditNameDialogListener {
|
public interface EditNameDialogListener {
|
||||||
public void onDismiss(EditNameDialog dialog);
|
public void onDismiss(EditNameDialog dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,8 +328,7 @@ public class FileDetailFragment extends SherlockFragment implements
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.fdRenameBtn: {
|
case R.id.fdRenameBtn: {
|
||||||
EditNameDialog dialog = EditNameDialog.newInstance(mFile.getFileName());
|
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this);
|
||||||
dialog.setOnDismissListener(this);
|
|
||||||
dialog.show(getFragmentManager(), "nameeditdialog");
|
dialog.show(getFragmentManager(), "nameeditdialog");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,8 +203,7 @@ 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.rename_file_item: {
|
case R.id.rename_file_item: {
|
||||||
EditNameDialog dialog = EditNameDialog.newInstance(mTargetFile.getFileName());
|
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mTargetFile.getFileName(), this);
|
||||||
dialog.setOnDismissListener(this);
|
|
||||||
dialog.show(getFragmentManager(), EditNameDialog.TAG);
|
dialog.show(getFragmentManager(), EditNameDialog.TAG);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue