gui: Implement route deletion
Change-Id: I8b08a1545c22095894f7285500adfde94d99830c
Refs: #3442
diff --git a/app/src/main/java/net/named_data/nfd/RouteListFragment.java b/app/src/main/java/net/named_data/nfd/RouteListFragment.java
index 0d326b0..1b666cc 100644
--- a/app/src/main/java/net/named_data/nfd/RouteListFragment.java
+++ b/app/src/main/java/net/named_data/nfd/RouteListFragment.java
@@ -38,6 +38,10 @@
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
+import android.widget.AdapterView.OnItemLongClickListener;
+import android.widget.AdapterView;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import com.intel.jndn.management.types.RibEntry;
import com.intel.jndn.management.types.Route;
@@ -98,6 +102,33 @@
// Get progress bar spinner view
m_reloadingListProgressBar = (ProgressBar)v.findViewById(R.id.route_list_reloading_list_progress_bar);
+
+ getListView().setLongClickable(true);
+ getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
+ public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
+ final RibEntry entry = (RibEntry)parent.getItemAtPosition(position);;
+ new AlertDialog.Builder(v.getContext())
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setTitle("Deleting route")
+ .setMessage("Are you sure you want to delete " + entry.getName().toUri() + "?")
+ .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ List<Integer> faceList = new ArrayList<>();
+ for (Route r : entry.getRoutes()) {
+ faceList.add(r.getFaceId());
+ }
+ removeRoute(entry.getName(), faceList);
+ Toast.makeText(getActivity(), "Route Deleted", Toast.LENGTH_LONG).show();
+ }
+ })
+ .setNegativeButton("No", null)
+ .show();
+
+
+ return true;
+ }
+ });
}
@Override
@@ -178,6 +209,12 @@
m_routeCreateAsyncTask.execute();
}
+ public void
+ removeRoute(Name prefix, List<Integer> faceIds)
+ {
+ m_routeRemoveAsyncTask = new RouteRemoveAsyncTask(prefix, faceIds);
+ m_routeRemoveAsyncTask.execute();
+ }
/////////////////////////////////////////////////////////////////////////
@@ -349,7 +386,6 @@
}
}
-
private class RouteCreateAsyncTask extends AsyncTask<Void, Void, String> {
public
RouteCreateAsyncTask(Name prefix, String faceUri)
@@ -416,6 +452,74 @@
private String m_faceUri;
}
+ private class RouteRemoveAsyncTask extends AsyncTask<Void, Void, String> {
+ public
+ RouteRemoveAsyncTask(Name prefix, List<Integer> faceIds)
+ {
+ m_prefix = prefix;
+ m_faceList = faceIds;
+ }
+
+ @Override
+ protected String
+ doInBackground(Void... params)
+ {
+ NfdcHelper nfdcHelper = new NfdcHelper();
+ try {
+ for (int faceId : m_faceList) {
+ nfdcHelper.ribUnregisterPrefix(m_prefix, faceId);
+ }
+
+ nfdcHelper.shutdown();
+ return "OK";
+ }
+ catch (FaceUri.CanonizeError e) {
+ return "Error Destroying dace (" + e.getMessage() + ")";
+ }
+ catch (FaceUri.Error e) {
+ return "Error destroying face (" + e.getMessage() + ")";
+ }
+ catch (Exception e) {
+ return "Error communicating with NFD (" + e.getMessage() + ")";
+ }
+ finally {
+ nfdcHelper.shutdown();
+ }
+ }
+
+ @Override
+ protected void
+ onPreExecute()
+ {
+ // Display progress bar
+ m_reloadingListProgressBar.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ protected void
+ onPostExecute(String status)
+ {
+ // Display progress bar
+ m_reloadingListProgressBar.setVisibility(View.VISIBLE);
+ Toast.makeText(getActivity(), status, Toast.LENGTH_LONG).show();
+
+ retrieveRouteList();
+ }
+
+ @Override
+ protected void
+ onCancelled()
+ {
+ // Remove progress bar
+ m_reloadingListProgressBar.setVisibility(View.GONE);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ private Name m_prefix;
+ private List<Integer> m_faceList;
+ }
+
/////////////////////////////////////////////////////////////////////////////
/** Callback handler of the hosting activity */
@@ -432,6 +536,7 @@
/** Reference to the most recent AsyncTask that was created for creating a route */
private RouteCreateAsyncTask m_routeCreateAsyncTask;
+ private RouteRemoveAsyncTask m_routeRemoveAsyncTask;
private RouteListAdapter m_routeListAdapter;
-}
\ No newline at end of file
+}
diff --git a/build.gradle b/build.gradle
index b510b10..9c1a198 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@
}
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.0'
+ classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'net.named-data.playground:play-publisher:1.2.0-2-SNAPSHOT'
// NOTE: Do not place your application dependencies here; they belong