Added warning before remove entry
This commit is contained in:
parent
7bcbe46d91
commit
93c8d65cfa
2 changed files with 52 additions and 15 deletions
app/src/main
|
@ -60,23 +60,57 @@ public class ElementFragment extends Fragment implements AsyncDatabaseConnector.
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void actionSave(){
|
||||||
|
List<String> fields = listAdapter.getFieldArray();
|
||||||
|
Static.asyncDatabaseConnector.setStringReturnListener(this);
|
||||||
|
if(getArguments().getBoolean(EDIT_ELEMENT))
|
||||||
|
Static.asyncDatabaseConnector.updateElement(tableName, fields, values, getNewValues());
|
||||||
|
else
|
||||||
|
Static.asyncDatabaseConnector.addNewElement(tableName, fields, getNewValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void actionRemove(){
|
||||||
|
final List<String> fields = listAdapter.getFieldArray();
|
||||||
|
Static.asyncDatabaseConnector.setStringReturnListener(this);
|
||||||
|
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setMessage(R.string.error_remove);
|
||||||
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
Static.asyncDatabaseConnector.removeElement(tableName, fields, values);
|
||||||
|
// getActivity().finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
// Nothing to do just get back
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setTitle(R.string.warning);
|
||||||
|
builder.setIcon(R.drawable.ic_action_warning);
|
||||||
|
builder.setCancelable(false); // There is no exit
|
||||||
|
builder.create();
|
||||||
|
builder.show();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
List<String> fields = listAdapter.getFieldArray();
|
switch (item.getItemId()){
|
||||||
if(item.getItemId() == R.id.action_save ){
|
case R.id.action_save:
|
||||||
Static.asyncDatabaseConnector.setStringReturnListener(this);
|
actionSave();
|
||||||
if(getArguments().getBoolean(EDIT_ELEMENT))
|
break;
|
||||||
Static.asyncDatabaseConnector.updateElement(tableName, fields, values, getNewValues());
|
case R.id.action_remove:
|
||||||
else
|
actionRemove();
|
||||||
Static.asyncDatabaseConnector.addNewElement(tableName, fields, getNewValues());
|
break;
|
||||||
return true;
|
default:
|
||||||
} else if(item.getItemId() == R.id.action_remove) {
|
return super.onOptionsItemSelected(item);
|
||||||
Static.asyncDatabaseConnector.setStringReturnListener(this);
|
|
||||||
Static.asyncDatabaseConnector.removeElement(tableName, fields, values);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initArguments() {
|
private void initArguments() {
|
||||||
|
@ -152,9 +186,10 @@ public class ElementFragment extends Fragment implements AsyncDatabaseConnector.
|
||||||
}
|
}
|
||||||
});*/
|
});*/
|
||||||
builder.setTitle(R.string.status);
|
builder.setTitle(R.string.status);
|
||||||
builder.setIcon(R.drawable.ic_action_warning); //TODO Change Icon
|
builder.setIcon(R.drawable.ic_action_warning);
|
||||||
builder.setCancelable(false); // There is no exit
|
builder.setCancelable(false); // There is no exit
|
||||||
builder.create();
|
builder.create();
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
<string name="status">Status</string>
|
<string name="status">Status</string>
|
||||||
<string name="back">Back</string>
|
<string name="back">Back</string>
|
||||||
<string name="action_remove">Remove</string>
|
<string name="action_remove">Remove</string>
|
||||||
|
<string name="error_remove">This entry will be removed from database. This action <b>CAN NOT</b> be reversed! Would you like to continue?</string>
|
||||||
|
<string name="no">No</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue