From 5b7452ff90c1de93e3d156487bd4b3fa11cecb3d Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Tue, 27 Aug 2013 11:12:47 +0000
Subject: [PATCH] Fixed two-pane tunnel deletion

---
 .../i2ptunnel/activity/TunnelDetailActivity.java |  2 +-
 .../i2ptunnel/activity/TunnelListActivity.java   | 16 ++++++++++++++--
 .../i2ptunnel/fragment/TunnelDetailFragment.java |  5 +++--
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/net/i2p/android/i2ptunnel/activity/TunnelDetailActivity.java b/src/net/i2p/android/i2ptunnel/activity/TunnelDetailActivity.java
index 9cdbae024..8965506a1 100644
--- a/src/net/i2p/android/i2ptunnel/activity/TunnelDetailActivity.java
+++ b/src/net/i2p/android/i2ptunnel/activity/TunnelDetailActivity.java
@@ -22,7 +22,7 @@ public class TunnelDetailActivity extends I2PActivityBase implements
 
     // TunnelDetailFragment.OnTunnelDeletedListener
 
-    public void onTunnelDeleted() {
+    public void onTunnelDeleted(int tunnelId, int numTunnelsLeft) {
         finish();
     }
 }
diff --git a/src/net/i2p/android/i2ptunnel/activity/TunnelListActivity.java b/src/net/i2p/android/i2ptunnel/activity/TunnelListActivity.java
index b57a2c498..c8d318daa 100644
--- a/src/net/i2p/android/i2ptunnel/activity/TunnelListActivity.java
+++ b/src/net/i2p/android/i2ptunnel/activity/TunnelListActivity.java
@@ -86,7 +86,19 @@ public class TunnelListActivity extends I2PActivityBase implements
 
     // TunnelDetailFragment.OnTunnelDeletedListener
 
-    public void onTunnelDeleted() {
-        getSupportFragmentManager().popBackStack();
+    public void onTunnelDeleted(int tunnelId, int numTunnelsLeft) {
+        // Should only get here in two-pane mode, but just to be safe:
+        if (mTwoPane) {
+            if (numTunnelsLeft > 0) {
+                TunnelDetailFragment detailFrag = TunnelDetailFragment.newInstance(
+                        (tunnelId > 0 ? tunnelId - 1 : 0));
+                getSupportFragmentManager().beginTransaction()
+                    .replace(R.id.detail_fragment, detailFrag).commit();
+            } else {
+                TunnelDetailFragment detailFrag = (TunnelDetailFragment) getSupportFragmentManager().findFragmentById(R.id.detail_fragment);
+                getSupportFragmentManager().beginTransaction()
+                    .remove(detailFrag).commit();
+            }
+        }
     }
 }
diff --git a/src/net/i2p/android/i2ptunnel/fragment/TunnelDetailFragment.java b/src/net/i2p/android/i2ptunnel/fragment/TunnelDetailFragment.java
index c618b9dc8..b5e1dbefc 100644
--- a/src/net/i2p/android/i2ptunnel/fragment/TunnelDetailFragment.java
+++ b/src/net/i2p/android/i2ptunnel/fragment/TunnelDetailFragment.java
@@ -42,7 +42,7 @@ public class TunnelDetailFragment extends Fragment {
 
     // Container Activity must implement this interface
     public interface OnTunnelDeletedListener {
-        public void onTunnelDeleted();
+        public void onTunnelDeleted(int tunnelId, int numTunnelsLeft);
     }
 
     @Override
@@ -133,7 +133,8 @@ public class TunnelDetailFragment extends Fragment {
                                             dialog.dismiss();
                                             Toast.makeText(getActivity().getApplicationContext(),
                                                     msgs.get(0), Toast.LENGTH_LONG).show();
-                                            mCallback.onTunnelDeleted();
+                                            mCallback.onTunnelDeleted(mTunnel.getId(),
+                                                    mGroup.getControllers().size());
                                         }
                                     })
                             .setNegativeButton(android.R.string.cancel, null)
-- 
GitLab