delete by id

This commit is contained in:
arrase 2016-11-28 23:32:35 +01:00
parent 07044f7748
commit f742b270e3
2 changed files with 11 additions and 3 deletions

View File

@ -73,6 +73,10 @@ public class HiddenServicesActivity extends AppCompatActivity {
Cursor item = (Cursor) parent.getItemAtPosition(position); Cursor item = (Cursor) parent.getItemAtPosition(position);
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
arguments.putInt(
"_id", item.getInt(item.getColumnIndex(HSContentProvider.HiddenService._ID))
);
arguments.putString( arguments.putString(
"port", item.getString(item.getColumnIndex(HSContentProvider.HiddenService.PORT)) "port", item.getString(item.getColumnIndex(HSContentProvider.HiddenService.PORT))
); );

View File

@ -2,6 +2,7 @@ package org.torproject.android.ui.hiddenservices.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -17,14 +18,17 @@ public class HSDeleteDialog extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final Bundle arguments = getArguments(); final Bundle arguments = getArguments();
final Context context = getContext();
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { switch (which) {
case DialogInterface.BUTTON_POSITIVE: case DialogInterface.BUTTON_POSITIVE:
getActivity().getContentResolver().delete( context.getContentResolver().delete(
HSContentProvider.CONTENT_URI, "port=" + arguments.getString("port"), null HSContentProvider.CONTENT_URI,
HSContentProvider.HiddenService._ID + "=" + arguments.getInt("_id"),
null
); );
break; break;
@ -35,7 +39,7 @@ public class HSDeleteDialog extends DialogFragment {
} }
}; };
return new AlertDialog.Builder(getActivity()) return new AlertDialog.Builder(context)
.setMessage(R.string.confirm_service_deletion) .setMessage(R.string.confirm_service_deletion)
.setPositiveButton(R.string.btn_okay, dialogClickListener) .setPositiveButton(R.string.btn_okay, dialogClickListener)
.setNegativeButton(R.string.btn_cancel, dialogClickListener) .setNegativeButton(R.string.btn_cancel, dialogClickListener)